added sectors to Node

This commit is contained in:
Denis Molony 2016-07-19 17:44:42 +10:00
parent edaa7954c7
commit 0108938fe7
4 changed files with 262 additions and 231 deletions

View File

@ -10,12 +10,12 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
class Dictionary extends AbstractFile
{
Map<Integer, ZString> dictionary;
int totalEntries;
int totalSeparators;
int dictionaryPtr, dictionarySize;
int entryLength;
Header header;
private final Map<Integer, ZString> dictionary;
private final int totalEntries;
private final int totalSeparators;
private final int dictionaryPtr, dictionarySize;
private final int entryLength;
private final Header header;
// this could be a Google Multimap
Map<Integer, List<WordEntry>> synonymList = new TreeMap<Integer, List<WordEntry>> ();
@ -93,7 +93,8 @@ class Dictionary extends AbstractFile
int b2 = buffer[ptr + 5] & 0xFF;
int b3 = buffer[ptr + 6] & 0xFF;
// mask seems to be 0x40
if ((b1 == 0x41 && b2 == value) || ((b1 == 0x62 || b1 == 0xC0 || b1 == 0x44) && b3 == value))
if ((b1 == 0x41 && b2 == value)
|| ((b1 == 0x62 || b1 == 0xC0 || b1 == 0x44) && b3 == value))
words.add (word.value);
ptr += entryLength;
}
@ -141,8 +142,9 @@ class Dictionary extends AbstractFile
for (ZString word : dictionary.values ())
{
text.append (String.format ("%04X %3d %-6s %s", ptr, count++, word.value, HexFormatter
.getHexString (buffer, ptr + 4, entryLength - 4)));
text.append (String
.format ("%04X %3d %-6s %s", ptr, count++, word.value,
HexFormatter.getHexString (buffer, ptr + 4, entryLength - 4)));
int b1 = buffer[ptr + 4] & 0xFF;
int b2 = buffer[ptr + 5] & 0xFF;
int b3 = buffer[ptr + 6] & 0xFF;
@ -233,8 +235,10 @@ class Dictionary extends AbstractFile
StringBuilder text = new StringBuilder ();
text.append (String.format ("%04X %3d %-6s %s %s %s", word.startPtr, seq,
word.value, bits, HexFormatter
.getHexString (buffer, word.startPtr + 4, entryLength - 4), list.toString ()));
word.value, bits,
HexFormatter.getHexString (buffer, word.startPtr + 4,
entryLength - 4),
list.toString ()));
return text.toString ();
}
}

View File

@ -80,14 +80,14 @@ class Grammar extends InfocomAbstractFile
sentenceGroups.add (sg);
for (Sentence sentence : sg)
{
// add to hashmap
if (!actionList.containsKey (sentence.actionId))
if (!actionList.containsKey (sentence.actionId)) // add to hashmap
actionList.put (sentence.actionId, new ArrayList<Sentence> ());
actionList.get (sentence.actionId).add (sentence);
// add to pre-action routine list
if (sentence.preActionRoutine > 0
if (sentence.preActionRoutine > 0 // add to pre-action routine list
&& !preActionRoutines.contains (sentence.preActionRoutine))
preActionRoutines.add (sentence.preActionRoutine);
// add to action routine list
if (sentence.actionRoutine > 0
&& !actionRoutines.contains (sentence.actionRoutine))

View File

@ -6,7 +6,7 @@ class Header extends InfocomAbstractFile
{
final String[] propertyNames = new String[32];
File file;
private final File file;
int version;
int highMemory;
int programCounter;

View File

@ -4,6 +4,7 @@ import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
@ -48,23 +49,37 @@ public class InfocomDisk extends AbstractFormattedDisk
createStoryFile ("Zork1.sf");
DefaultMutableTreeNode root = getCatalogTreeRoot ();
DefaultMutableTreeNode headerNode = null;
DefaultMutableTreeNode abbreviationsNode = null;
DefaultMutableTreeNode codeNode = null;
DefaultMutableTreeNode objectNode = null;
DefaultMutableTreeNode globalsNode = null;
DefaultMutableTreeNode grammarNode = null;
DefaultMutableTreeNode dictionaryNode = null;
DefaultMutableTreeNode stringsNode = null;
header = new Header ("Header", data, disk.getFile ());
addToTree (root, "Header", header, TYPE_LEAF);
headerNode = addToTree (root, "Header", header, TYPE_LEAF);
DefaultAppleFileSource dafs = (DefaultAppleFileSource) headerNode.getUserObject ();
List<DiskAddress> blocks = new ArrayList<DiskAddress> ();
blocks.add (disk.getDiskAddress (3, 0));
dafs.setSectors (blocks);
abbreviationsNode =
addToTree (root, "Abbreviations", header.abbreviations, TYPE_LEAF);
objectNode = addToTree (root, "Objects", header.objectManager, TYPE_NODE);
header.objectManager.addNodes (objectNode, this);
addToTree (root, "Globals", header.globals, TYPE_LEAF);
addToTree (root, "Grammar", header.grammar, TYPE_LEAF);
addToTree (root, "Dictionary", header.dictionary, TYPE_LEAF);
globalsNode = addToTree (root, "Globals", header.globals, TYPE_LEAF);
grammarNode = addToTree (root, "Grammar", header.grammar, TYPE_LEAF);
dictionaryNode = addToTree (root, "Dictionary", header.dictionary, TYPE_LEAF);
codeNode = addToTree (root, "Code", header.codeManager, TYPE_NODE);
header.codeManager.addNodes (codeNode, this);
addToTree (root, "Strings", header.stringManager, TYPE_LEAF);
stringsNode = addToTree (root, "Strings", header.stringManager, TYPE_LEAF);
PropertyManager pm = new PropertyManager ("Properties", data, header);
pm.addNodes (addToTree (objectNode, "Properties", pm, TYPE_NODE), this);
@ -74,13 +89,17 @@ public class InfocomDisk extends AbstractFormattedDisk
sectorTypes[48] = headerSector;
setSectors (header.abbreviationsTable, header.objectTable, abbreviationsSector);
setSectors (header.objectTable, header.globalsOffset, objectsSector);
setSectors (header.globalsOffset, header.staticMemory, globalsSector);
setSectors (header.staticMemory, header.dictionaryOffset, grammarSector);
setSectors (header.dictionaryOffset, header.highMemory, dictionarySector);
setSectors (header.highMemory, header.stringPointer, codeSector);
setSectors (header.stringPointer, header.fileLength, stringsSector);
setSectorTypes (header.abbreviationsTable, header.objectTable, abbreviationsSector,
abbreviationsNode);
setSectorTypes (header.objectTable, header.globalsOffset, objectsSector, objectNode);
setSectorTypes (header.globalsOffset, header.staticMemory, globalsSector,
globalsNode);
setSectorTypes (header.staticMemory, header.dictionaryOffset, grammarSector,
grammarNode);
setSectorTypes (header.dictionaryOffset, header.highMemory, dictionarySector,
dictionaryNode);
setSectorTypes (header.highMemory, header.stringPointer, codeSector, codeNode);
setSectorTypes (header.stringPointer, header.fileLength, stringsSector, stringsNode);
}
protected void setInfocomSectorTypes ()
@ -101,16 +120,22 @@ public class InfocomDisk extends AbstractFormattedDisk
sectorTypes[track * 16 + sector] = bootSector;
}
private void setSectors (int sectorFrom, int sectorTo, SectorType type)
private void setSectorTypes (int sectorFrom, int sectorTo, SectorType type,
DefaultMutableTreeNode node)
{
DefaultAppleFileSource dafs = (DefaultAppleFileSource) node.getUserObject ();
List<DiskAddress> blocks = new ArrayList<DiskAddress> ();
int blockNo = sectorFrom / disk.getBlockSize () + 48;
int blockTo = sectorTo / disk.getBlockSize () + 48;
while (blockNo <= blockTo)
{
blocks.add (disk.getDiskAddress (blockNo));
if (!disk.isSectorEmpty (blockNo))
sectorTypes[blockNo] = type;
blockNo++;
}
dafs.setSectors (blocks);
}
private int getFileSize ()
@ -162,8 +187,10 @@ public class InfocomDisk extends AbstractFormattedDisk
private DefaultMutableTreeNode addToTree (DefaultMutableTreeNode root, String title,
DataSource af, boolean allowsChildren)
{
DefaultMutableTreeNode node =
new DefaultMutableTreeNode (new DefaultAppleFileSource (title, af, this));
DefaultAppleFileSource dafs = new DefaultAppleFileSource (title, af, this);
// dafs.setSectors (blocks);
DefaultMutableTreeNode node = new DefaultMutableTreeNode (dafs);
node.setAllowsChildren (allowsChildren);
root.add (node);
return node;