This commit is contained in:
Denis Molony 2020-02-05 14:26:39 +10:00
parent 644540668c
commit 135c946047
3 changed files with 55 additions and 1 deletions

View File

@ -9,7 +9,9 @@ import java.util.TreeMap;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
class Grammar extends InfocomAbstractFile
// -----------------------------------------------------------------------------------//
{
private static final int SENTENCE_LENGTH = 8;
private final Header header;
@ -28,7 +30,9 @@ class Grammar extends InfocomAbstractFile
private final List<Integer> actionRoutines = new ArrayList<> ();
private final List<Integer> preActionRoutines = new ArrayList<> ();
// ---------------------------------------------------------------------------------//
Grammar (String name, byte[] buffer, Header header)
// ---------------------------------------------------------------------------------//
{
super (name, buffer);
this.header = header;
@ -90,7 +94,7 @@ class Grammar extends InfocomAbstractFile
{
// add to hashmap
if (!actionList.containsKey (sentence.actionId))
actionList.put (sentence.actionId, new ArrayList<Sentence> ());
actionList.put (sentence.actionId, new ArrayList<> ());
actionList.get (sentence.actionId).add (sentence);
// add to pre-action routine list
@ -108,7 +112,9 @@ class Grammar extends InfocomAbstractFile
Collections.sort (preActionRoutines);
}
// ---------------------------------------------------------------------------------//
private int getPadding ()
// ---------------------------------------------------------------------------------//
{
// calculate record padding size (Zork has 1 byte padding, Planetfall has 0)
int r1 = header.getWord (indexPtr);
@ -117,12 +123,16 @@ class Grammar extends InfocomAbstractFile
return r2 - r1 - (sentences * SENTENCE_LENGTH) - 1;
}
// ---------------------------------------------------------------------------------//
private int getRecordLength (int recordPtr)
// ---------------------------------------------------------------------------------//
{
return (buffer[recordPtr] & 0xFF) * SENTENCE_LENGTH + padding + 1;
}
// ---------------------------------------------------------------------------------//
private int getTotalActions ()
// ---------------------------------------------------------------------------------//
{
// loop through each record in each index entry, and find the highest action number
int ptr = tablePtr;
@ -150,8 +160,10 @@ class Grammar extends InfocomAbstractFile
// return routines;
// }
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
String line = "-----------------------------------------------------"
+ "-----------------------------------------------------------\n";
@ -209,12 +221,16 @@ class Grammar extends InfocomAbstractFile
return text.toString ();
}
// ---------------------------------------------------------------------------------//
List<SentenceGroup> getSentenceGroups ()
// ---------------------------------------------------------------------------------//
{
return sentenceGroups;
}
// ---------------------------------------------------------------------------------//
private List<Sentence> getSentences (int routine)
// ---------------------------------------------------------------------------------//
{
List<Sentence> sentences = new ArrayList<> ();
@ -226,7 +242,9 @@ class Grammar extends InfocomAbstractFile
return sentences;
}
// ---------------------------------------------------------------------------------//
private String makeWordBlock (List<String> words)
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ("[");
if (words.size () > 0)
@ -242,7 +260,9 @@ class Grammar extends InfocomAbstractFile
return text.toString ();
}
// ---------------------------------------------------------------------------------//
class SentenceGroup implements Iterable<Sentence>
// ---------------------------------------------------------------------------------//
{
int startPtr;
int id;
@ -278,7 +298,9 @@ class Grammar extends InfocomAbstractFile
}
}
// ---------------------------------------------------------------------------------//
class Sentence
// ---------------------------------------------------------------------------------//
{
int startPtr;
SentenceGroup parent;

View File

@ -4,7 +4,9 @@ import java.io.File;
import com.bytezone.diskbrowser.disk.Disk;
// -----------------------------------------------------------------------------------//
class Header extends InfocomAbstractFile
// -----------------------------------------------------------------------------------//
{
final String[] propertyNames = new String[32];
@ -29,7 +31,9 @@ class Header extends InfocomAbstractFile
final CodeManager codeManager;
final StringManager stringManager;
// ---------------------------------------------------------------------------------//
public Header (String name, byte[] buffer, Disk disk)
// ---------------------------------------------------------------------------------//
{
super (name, buffer);
this.file = disk.getFile ();
@ -79,28 +83,38 @@ class Header extends InfocomAbstractFile
hexBlocks.add (new HexBlock (0, 64, "Header data:"));
}
// ---------------------------------------------------------------------------------//
String getPropertyName (int id)
// ---------------------------------------------------------------------------------//
{
return propertyNames[id];
}
// ---------------------------------------------------------------------------------//
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 ();
@ -141,7 +155,9 @@ class Header extends InfocomAbstractFile
return text.toString ();
}
// ---------------------------------------------------------------------------------//
private String getAlternate ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ("\n\n");
@ -161,7 +177,9 @@ class Header extends InfocomAbstractFile
return text.toString ();
}
// ---------------------------------------------------------------------------------//
private String getLine (int offset, int size, String description)
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
text.append (String.format ("%04X - %04X ", offset, offset + size - 1));
@ -174,17 +192,23 @@ class Header extends InfocomAbstractFile
return text.toString ();
}
// ---------------------------------------------------------------------------------//
ZObject getObject (int index)
// ---------------------------------------------------------------------------------//
{
return objectManager.getObject (index);
}
// ---------------------------------------------------------------------------------//
int getByte (int offset)
// ---------------------------------------------------------------------------------//
{
return buffer[offset] & 0xFF;
}
// ---------------------------------------------------------------------------------//
int getWord (int offset)
// ---------------------------------------------------------------------------------//
{
return ((buffer[offset] << 8) & 0xFF00) | ((buffer[offset + 1]) & 0xFF);
}

View File

@ -6,17 +6,23 @@ import java.util.List;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class InfocomAbstractFile extends AbstractFile
// -----------------------------------------------------------------------------------//
{
protected List<HexBlock> hexBlocks = new ArrayList<> ();
// ---------------------------------------------------------------------------------//
public InfocomAbstractFile (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{
super (name, buffer);
}
// ---------------------------------------------------------------------------------//
@Override
public String getHexDump ()
// ---------------------------------------------------------------------------------//
{
if (hexBlocks.size () > 0)
{
@ -44,7 +50,9 @@ public class InfocomAbstractFile extends AbstractFile
return HexFormatter.format (buffer, 0, 99999);
}
// ---------------------------------------------------------------------------------//
protected class HexBlock
// ---------------------------------------------------------------------------------//
{
public int ptr;
public int size;