mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-02-16 23:30:52 +00:00
moved HexBlock to Infocom package
This commit is contained in:
parent
4ba53dd1b0
commit
c4b086a096
@ -1,8 +1,6 @@
|
||||
package com.bytezone.diskbrowser.applefile;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
@ -16,7 +14,6 @@ public abstract class AbstractFile implements DataSource
|
||||
public byte[] buffer;
|
||||
AssemblerProgram assembler;
|
||||
protected BufferedImage image;
|
||||
protected List<HexBlock> hexBlocks = new ArrayList<HexBlock> ();
|
||||
|
||||
public AbstractFile (String name, byte[] buffer)
|
||||
{
|
||||
@ -35,31 +32,16 @@ public abstract class AbstractFile implements DataSource
|
||||
{
|
||||
if (buffer == null)
|
||||
return "No buffer";
|
||||
|
||||
if (assembler == null)
|
||||
this.assembler = new AssemblerProgram (name, buffer, 0);
|
||||
|
||||
return assembler.getText ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHexDump ()
|
||||
{
|
||||
if (hexBlocks.size () > 0)
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
for (HexBlock hb : hexBlocks)
|
||||
{
|
||||
if (hb.title != null)
|
||||
text.append (hb.title + "\n\n");
|
||||
text.append (HexFormatter.format (buffer, hb.ptr, hb.size) + "\n\n");
|
||||
}
|
||||
|
||||
text.deleteCharAt (text.length () - 1);
|
||||
text.deleteCharAt (text.length () - 1);
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
if (buffer == null || buffer.length == 0)
|
||||
return "No buffer";
|
||||
|
||||
@ -82,18 +64,4 @@ public abstract class AbstractFile implements DataSource
|
||||
JPanel panel = new JPanel ();
|
||||
return panel;
|
||||
}
|
||||
|
||||
protected class HexBlock
|
||||
{
|
||||
public int ptr;
|
||||
public int size;
|
||||
public String title;
|
||||
|
||||
public HexBlock (int ptr, int size, String title)
|
||||
{
|
||||
this.ptr = ptr;
|
||||
this.size = size;
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
}
|
@ -45,28 +45,34 @@ public class AssemblerProgram extends AbstractFile
|
||||
@Override
|
||||
public String getHexDump ()
|
||||
{
|
||||
String text = super.getHexDump ();
|
||||
// String text = super.getHexDump ();
|
||||
String text = HexFormatter.format (buffer, 0, buffer.length, loadAddress);
|
||||
|
||||
if (extraBuffer.length == 0)
|
||||
return text;
|
||||
|
||||
return text + "\n\n"
|
||||
+ HexFormatter.format (extraBuffer, 0, extraBuffer.length, buffer.length);
|
||||
return text + "\n\n" + HexFormatter.format (extraBuffer, 0, extraBuffer.length,
|
||||
loadAddress + buffer.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAssembler ()
|
||||
{
|
||||
String text = super.getAssembler ();
|
||||
// String text = super.getAssembler ();
|
||||
if (buffer == null)
|
||||
return "No buffer";
|
||||
if (assembler == null)
|
||||
this.assembler = new AssemblerProgram (name, buffer, loadAddress);
|
||||
// return assembler.getText ();
|
||||
|
||||
if (extraBuffer.length == 0)
|
||||
return text;
|
||||
return assembler.getText ();
|
||||
|
||||
String extraName = String.format ("%s (extra)", name);
|
||||
AssemblerProgram assemblerProgram =
|
||||
new AssemblerProgram (extraName, extraBuffer, buffer.length);
|
||||
new AssemblerProgram (extraName, extraBuffer, loadAddress + buffer.length);
|
||||
|
||||
return text + "\n\n" + assemblerProgram.getText ();
|
||||
return assembler.getText () + "\n\n" + assemblerProgram.getText ();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,9 +3,7 @@ package com.bytezone.diskbrowser.infocom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
||||
|
||||
class Abbreviations extends AbstractFile
|
||||
class Abbreviations extends InfocomAbstractFile
|
||||
{
|
||||
List<ZString> list;
|
||||
Header header;
|
||||
@ -57,11 +55,11 @@ class Abbreviations extends AbstractFile
|
||||
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
// text.append (String.format ("Data address....%04X %d%n", dataPtr, dataPtr));
|
||||
// text.append (String.format ("Data size.......%04X %d%n", dataSize, dataSize));
|
||||
// text.append (String.format ("Table address...%04X %d%n", tablePtr, tablePtr));
|
||||
// text.append (String.format ("Table size......%04X %d (%d words)%n%n", tableSize, tableSize,
|
||||
// (tableSize / 2)));
|
||||
// text.append (String.format ("Data address....%04X %d%n", dataPtr, dataPtr));
|
||||
// text.append (String.format ("Data size.......%04X %d%n", dataSize, dataSize));
|
||||
// text.append (String.format ("Table address...%04X %d%n", tablePtr, tablePtr));
|
||||
// text.append (String.format ("Table size......%04X %d (%d words)%n%n", tableSize, tableSize,
|
||||
// (tableSize / 2)));
|
||||
|
||||
int count = 0;
|
||||
for (ZString word : list)
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.bytezone.diskbrowser.infocom;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
||||
|
||||
class Globals extends AbstractFile
|
||||
class Globals extends InfocomAbstractFile
|
||||
{
|
||||
static final int TOTAL_GLOBALS = 240;
|
||||
Header header;
|
||||
|
@ -1,16 +1,10 @@
|
||||
package com.bytezone.diskbrowser.infocom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
|
||||
import com.bytezone.diskbrowser.HexFormatter;
|
||||
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
||||
|
||||
class Grammar extends AbstractFile
|
||||
class Grammar extends InfocomAbstractFile
|
||||
{
|
||||
private static final int SENTENCE_LENGTH = 8;
|
||||
Header header;
|
||||
@ -95,7 +89,8 @@ class Grammar extends AbstractFile
|
||||
&& !preActionRoutines.contains (sentence.preActionRoutine))
|
||||
preActionRoutines.add (sentence.preActionRoutine);
|
||||
// add to action routine list
|
||||
if (sentence.actionRoutine > 0 && !actionRoutines.contains (sentence.actionRoutine))
|
||||
if (sentence.actionRoutine > 0
|
||||
&& !actionRoutines.contains (sentence.actionRoutine))
|
||||
actionRoutines.add (sentence.actionRoutine);
|
||||
}
|
||||
}
|
||||
@ -148,11 +143,10 @@ class Grammar extends AbstractFile
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
String line =
|
||||
"-----------------------------------------------------"
|
||||
String line = "-----------------------------------------------------"
|
||||
+ "-----------------------------------------------------------\n";
|
||||
StringBuilder text =
|
||||
new StringBuilder (sentenceGroups.size () + " Grammar tables\n==================\n\n");
|
||||
StringBuilder text = new StringBuilder (
|
||||
sentenceGroups.size () + " Grammar tables\n==================\n\n");
|
||||
|
||||
// add the sentences in their original SentenceGroup sequence
|
||||
for (SentenceGroup sg : sentenceGroups)
|
||||
@ -179,7 +173,8 @@ class Grammar extends AbstractFile
|
||||
text.append (line);
|
||||
}
|
||||
|
||||
text.append ("\n" + actionRoutines.size () + " Action routines\n===================\n\n");
|
||||
text.append ("\n" + actionRoutines.size ()
|
||||
+ " Action routines\n===================\n\n");
|
||||
|
||||
// add sentences in action routine sequence
|
||||
for (Integer routine : actionRoutines)
|
||||
@ -321,7 +316,8 @@ class Grammar extends AbstractFile
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
StringBuilder text = new StringBuilder (String.format ("%3d %04X ", parent.id, startPtr));
|
||||
StringBuilder text =
|
||||
new StringBuilder (String.format ("%3d %04X ", parent.id, startPtr));
|
||||
text.append (HexFormatter.getHexString (buffer, startPtr, SENTENCE_LENGTH));
|
||||
String r1 = preActionRoutine == 0 ? "" : String.format ("R:%05X", preActionRoutine);
|
||||
text.append (String.format (" %-7s R:%05X %s", r1, actionRoutine, getText ()));
|
||||
|
@ -2,9 +2,7 @@ package com.bytezone.diskbrowser.infocom;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
||||
|
||||
class Header extends AbstractFile
|
||||
class Header extends InfocomAbstractFile
|
||||
{
|
||||
final String[] propertyNames = new String[32];
|
||||
|
||||
@ -96,30 +94,34 @@ class Header extends AbstractFile
|
||||
text.append (String.format ("Disk name %s%n", file.getName ()));
|
||||
text.append (String.format ("Version %d%n", version));
|
||||
text.append ("\nDynamic memory:\n");
|
||||
text.append (String.format (" Abbreviation table %04X %,6d%n", abbreviationsTable,
|
||||
abbreviationsTable));
|
||||
text.append (String.format (" Objects table %04X %,6d%n", objectTable, objectTable));
|
||||
text.append (String.format (" Abbreviation table %04X %,6d%n",
|
||||
abbreviationsTable, abbreviationsTable));
|
||||
text.append (String.format (" Objects table %04X %,6d%n", objectTable,
|
||||
objectTable));
|
||||
text.append (String.format (" Global variables %04X %,6d%n", globalsOffset,
|
||||
globalsOffset));
|
||||
|
||||
text.append ("\nStatic memory:\n");
|
||||
text.append (String
|
||||
.format (" Grammar table etc %04X %,6d%n", staticMemory, staticMemory));
|
||||
text.append (String.format (" Grammar table etc %04X %,6d%n", staticMemory,
|
||||
staticMemory));
|
||||
text.append (String.format (" Dictionary %04X %,6d%n", dictionaryOffset,
|
||||
dictionaryOffset));
|
||||
text.append ("\nHigh memory:\n");
|
||||
text.append (String.format (" ZCode %04X %,6d%n", highMemory, highMemory));
|
||||
text.append (String.format (" ZCode %04X %,6d%n", highMemory,
|
||||
highMemory));
|
||||
text.append (String.format (" Program counter %04X %,6d%n", programCounter,
|
||||
programCounter));
|
||||
text.append (String.format ("\nFile length %05X %,6d%n", fileLength, fileLength));
|
||||
text.append (String.format ("Checksum %04X %,6d%n", checksum, checksum));
|
||||
text.append (String.format ("\nFile length %05X %,6d%n", fileLength,
|
||||
fileLength));
|
||||
text.append (String.format ("Checksum %04X %,6d%n", checksum,
|
||||
checksum));
|
||||
text.append (String.format ("%nZString offset %05X %,6d%n", stringPointer,
|
||||
stringPointer));
|
||||
|
||||
text.append (String.format ("Total strings %d%n", stringManager.strings
|
||||
.size ()));
|
||||
text.append (String.format ("Total objects %d%n", objectManager.list
|
||||
.size ()));
|
||||
text.append (String.format ("Total strings %d%n",
|
||||
stringManager.strings.size ()));
|
||||
text.append (String.format ("Total objects %d%n",
|
||||
objectManager.list.size ()));
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
package com.bytezone.diskbrowser.infocom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.bytezone.diskbrowser.HexFormatter;
|
||||
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
||||
|
||||
public class InfocomAbstractFile extends AbstractFile
|
||||
{
|
||||
protected List<HexBlock> hexBlocks = new ArrayList<HexBlock> ();
|
||||
|
||||
public InfocomAbstractFile (String name, byte[] buffer)
|
||||
{
|
||||
super (name, buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHexDump ()
|
||||
{
|
||||
if (hexBlocks.size () > 0)
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
for (HexBlock hb : hexBlocks)
|
||||
{
|
||||
if (hb.title != null)
|
||||
text.append (hb.title + "\n\n");
|
||||
text.append (HexFormatter.format (buffer, hb.ptr, hb.size) + "\n\n");
|
||||
}
|
||||
|
||||
text.deleteCharAt (text.length () - 1);
|
||||
text.deleteCharAt (text.length () - 1);
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
if (buffer == null || buffer.length == 0)
|
||||
return "No buffer";
|
||||
|
||||
if (buffer.length <= 99999)
|
||||
return HexFormatter.format (buffer, 0, buffer.length);
|
||||
|
||||
return HexFormatter.format (buffer, 0, 99999);
|
||||
}
|
||||
|
||||
protected class HexBlock
|
||||
{
|
||||
public int ptr;
|
||||
public int size;
|
||||
public String title;
|
||||
|
||||
public HexBlock (int ptr, int size, String title)
|
||||
{
|
||||
this.ptr = ptr;
|
||||
this.size = size;
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,11 +6,10 @@ import java.util.List;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
||||
import com.bytezone.diskbrowser.disk.DefaultAppleFileSource;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
|
||||
class ObjectManager extends AbstractFile implements Iterable<ZObject>
|
||||
class ObjectManager extends InfocomAbstractFile implements Iterable<ZObject>
|
||||
{
|
||||
Header header;
|
||||
List<ZObject> list;
|
||||
@ -34,8 +33,8 @@ class ObjectManager extends AbstractFile implements Iterable<ZObject>
|
||||
list = new ArrayList<ZObject> (tableSize);
|
||||
|
||||
for (int objectNo = 0; objectNo < totalObjects; objectNo++)
|
||||
list.add (new ZObject (null, buffer, tablePtr + objectNo * ZObject.HEADER_SIZE, objectNo + 1,
|
||||
header));
|
||||
list.add (new ZObject (null, buffer, tablePtr + objectNo * ZObject.HEADER_SIZE,
|
||||
objectNo + 1, header));
|
||||
|
||||
// analyse objects - set stringPtr etc.
|
||||
analyser = new ObjectAnalyser (header, this);
|
||||
@ -58,11 +57,12 @@ class ObjectManager extends AbstractFile implements Iterable<ZObject>
|
||||
private void buildObjectTree (ZObject object, DefaultMutableTreeNode parentNode,
|
||||
FormattedDisk disk)
|
||||
{
|
||||
DefaultMutableTreeNode child =
|
||||
new DefaultMutableTreeNode (new DefaultAppleFileSource (object.name, object, disk));
|
||||
DefaultMutableTreeNode child = new DefaultMutableTreeNode (
|
||||
new DefaultAppleFileSource (object.name, object, disk));
|
||||
parentNode.add (child);
|
||||
if (object.sibling > 0)
|
||||
buildObjectTree (header.objectManager.list.get (object.sibling - 1), parentNode, disk);
|
||||
buildObjectTree (header.objectManager.list.get (object.sibling - 1), parentNode,
|
||||
disk);
|
||||
if (object.child > 0)
|
||||
buildObjectTree (header.objectManager.list.get (object.child - 1), child, disk);
|
||||
else
|
||||
|
@ -4,9 +4,8 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
||||
|
||||
class Routine extends AbstractFile implements Iterable<Instruction>, Comparable<Routine>
|
||||
class Routine extends InfocomAbstractFile
|
||||
implements Iterable<Instruction>, Comparable<Routine>
|
||||
{
|
||||
int startPtr, length, strings, locals;
|
||||
Header header;
|
||||
@ -73,8 +72,7 @@ class Routine extends AbstractFile implements Iterable<Instruction>, Comparable<
|
||||
int endPtr = startPtr + length;
|
||||
for (Instruction ins : instructions)
|
||||
{
|
||||
int target =
|
||||
ins.target () > 256 ? ins.target ()
|
||||
int target = ins.target () > 256 ? ins.target ()
|
||||
: ins.opcode.jumpTarget > 256 ? ins.opcode.jumpTarget : 0;
|
||||
if (target == 0)
|
||||
continue;
|
||||
@ -134,8 +132,8 @@ class Routine extends AbstractFile implements Iterable<Instruction>, Comparable<
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
return String.format ("%05X : L%02d : %d", (startPtr + (sequence - 1) * 2 + 1), sequence,
|
||||
value);
|
||||
return String.format ("%05X : L%02d : %d", (startPtr + (sequence - 1) * 2 + 1),
|
||||
sequence, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user