dmolony-DiskBrowser/src/com/bytezone/diskbrowser/infocom/Header.java

142 lines
4.5 KiB
Java
Raw Normal View History

2015-06-01 09:35:51 +00:00
package com.bytezone.diskbrowser.infocom;
import java.io.File;
2016-07-20 05:22:33 +00:00
import com.bytezone.diskbrowser.disk.Disk;
2016-02-05 07:18:23 +00:00
class Header extends InfocomAbstractFile
2015-06-01 09:35:51 +00:00
{
2016-02-05 07:18:23 +00:00
final String[] propertyNames = new String[32];
2016-07-19 07:44:42 +00:00
private final File file;
2018-04-25 20:41:03 +00:00
// private final Disk disk;
2016-02-05 07:18:23 +00:00
int version;
int highMemory;
int programCounter;
int dictionaryOffset;
int objectTable;
int globalsOffset;
int staticMemory;
int abbreviationsTable;
int fileLength;
int checksum;
int stringPointer;
2016-07-20 10:35:13 +00:00
final Abbreviations abbreviations;
final Dictionary dictionary;
final ObjectManager objectManager;
final StringManager stringManager;
final CodeManager codeManager;
final Globals globals;
final Grammar grammar;
2016-02-05 07:18:23 +00:00
2016-07-20 05:22:33 +00:00
public Header (String name, byte[] buffer, Disk disk)
2016-02-05 07:18:23 +00:00
{
super (name, buffer);
2018-04-25 20:41:03 +00:00
// this.disk = disk;
2016-07-20 05:22:33 +00:00
this.file = disk.getFile ();
2016-02-05 07:18:23 +00:00
version = getByte (0);
highMemory = getWord (4);
programCounter = getWord (6);
dictionaryOffset = getWord (8);
objectTable = getWord (10);
globalsOffset = getWord (12);
staticMemory = getWord (14);
abbreviationsTable = getWord (24);
checksum = getWord (28);
fileLength = getWord (26) * 2;
if (fileLength == 0)
fileLength = buffer.length;
// do the basic managers
abbreviations = new Abbreviations (this);
dictionary = new Dictionary (this);
2016-07-19 07:44:42 +00:00
globals = new Globals (this); // may display ZStrings
2016-02-05 07:18:23 +00:00
// set up an empty object to store Routines in
codeManager = new CodeManager (this);
grammar = new Grammar ("Grammar", buffer, this);
// add all the ZObjects, and analyse them to find stringPtr, DICT etc.
objectManager = new ObjectManager (this);
// add all the ZStrings
stringManager = new StringManager ("Strings", buffer, this);
codeManager.addRoutine (programCounter - 1, 0);
2016-07-19 07:44:42 +00:00
codeManager.addActionRoutines (); // obtained from Grammar
codeManager.addCodeRoutines (); // obtained from Object properties
codeManager.addMissingRoutines (); // requires stringPtr to be set
2016-02-05 07:18:23 +00:00
// add entries for AbstractFile.getHexDump ()
hexBlocks.add (new HexBlock (0, 64, "Header data:"));
}
public String getAbbreviation (int index)
{
return abbreviations.getAbbreviation (index);
}
public boolean containsWordAt (int address)
{
return dictionary.containsWordAt (address);
}
public String wordAt (int address)
{
return dictionary.wordAt (address);
}
@Override
public String getText ()
{
StringBuilder text = new StringBuilder ();
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",
2016-12-04 02:33:21 +00:00
abbreviationsTable, abbreviationsTable));
2016-02-05 07:18:23 +00:00
text.append (String.format (" Objects table %04X %,6d%n", objectTable,
2016-12-04 02:33:21 +00:00
objectTable));
2016-02-05 07:18:23 +00:00
text.append (String.format (" Global variables %04X %,6d%n", globalsOffset,
2016-12-04 02:33:21 +00:00
globalsOffset));
2016-02-05 07:18:23 +00:00
text.append ("\nStatic memory:\n");
text.append (String.format (" Grammar table etc %04X %,6d%n", staticMemory,
2016-12-04 02:33:21 +00:00
staticMemory));
2016-02-05 07:18:23 +00:00
text.append (String.format (" Dictionary %04X %,6d%n", dictionaryOffset,
2016-12-04 02:33:21 +00:00
dictionaryOffset));
2016-02-05 07:18:23 +00:00
text.append ("\nHigh memory:\n");
2016-12-04 02:33:21 +00:00
text.append (
String.format (" ZCode %04X %,6d%n", highMemory, highMemory));
2016-02-05 07:18:23 +00:00
text.append (String.format (" Program counter %04X %,6d%n", programCounter,
2016-12-04 02:33:21 +00:00
programCounter));
text.append (
String.format ("\nFile length %05X %,7d%n", fileLength, fileLength));
text.append (
String.format ("Checksum %04X %,6d%n", checksum, checksum));
text.append (String.format ("%nZString offset %05X %,7d%n", stringPointer,
stringPointer));
2016-02-05 07:18:23 +00:00
text.append (String.format ("Total strings %d%n",
2016-12-04 02:33:21 +00:00
stringManager.strings.size ()));
2016-02-05 07:18:23 +00:00
text.append (String.format ("Total objects %d%n",
2016-12-04 02:33:21 +00:00
objectManager.list.size ()));
2016-02-05 07:18:23 +00:00
return text.toString ();
}
int getByte (int offset)
{
return buffer[offset] & 0xFF;
}
int getWord (int offset)
{
return ((buffer[offset] << 8) & 0xFF00) | ((buffer[offset + 1]) & 0xFF);
}
2015-06-01 09:35:51 +00:00
}