mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-11-29 11:49:29 +00:00
tidying
This commit is contained in:
parent
644540668c
commit
135c946047
@ -9,7 +9,9 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
class Grammar extends InfocomAbstractFile
|
class Grammar extends InfocomAbstractFile
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
private static final int SENTENCE_LENGTH = 8;
|
private static final int SENTENCE_LENGTH = 8;
|
||||||
private final Header header;
|
private final Header header;
|
||||||
@ -28,7 +30,9 @@ class Grammar extends InfocomAbstractFile
|
|||||||
private final List<Integer> actionRoutines = new ArrayList<> ();
|
private final List<Integer> actionRoutines = new ArrayList<> ();
|
||||||
private final List<Integer> preActionRoutines = new ArrayList<> ();
|
private final List<Integer> preActionRoutines = new ArrayList<> ();
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
Grammar (String name, byte[] buffer, Header header)
|
Grammar (String name, byte[] buffer, Header header)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
super (name, buffer);
|
super (name, buffer);
|
||||||
this.header = header;
|
this.header = header;
|
||||||
@ -90,7 +94,7 @@ class Grammar extends InfocomAbstractFile
|
|||||||
{
|
{
|
||||||
// add to hashmap
|
// add to hashmap
|
||||||
if (!actionList.containsKey (sentence.actionId))
|
if (!actionList.containsKey (sentence.actionId))
|
||||||
actionList.put (sentence.actionId, new ArrayList<Sentence> ());
|
actionList.put (sentence.actionId, new ArrayList<> ());
|
||||||
actionList.get (sentence.actionId).add (sentence);
|
actionList.get (sentence.actionId).add (sentence);
|
||||||
|
|
||||||
// add to pre-action routine list
|
// add to pre-action routine list
|
||||||
@ -108,7 +112,9 @@ class Grammar extends InfocomAbstractFile
|
|||||||
Collections.sort (preActionRoutines);
|
Collections.sort (preActionRoutines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
private int getPadding ()
|
private int getPadding ()
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
// calculate record padding size (Zork has 1 byte padding, Planetfall has 0)
|
// calculate record padding size (Zork has 1 byte padding, Planetfall has 0)
|
||||||
int r1 = header.getWord (indexPtr);
|
int r1 = header.getWord (indexPtr);
|
||||||
@ -117,12 +123,16 @@ class Grammar extends InfocomAbstractFile
|
|||||||
return r2 - r1 - (sentences * SENTENCE_LENGTH) - 1;
|
return r2 - r1 - (sentences * SENTENCE_LENGTH) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
private int getRecordLength (int recordPtr)
|
private int getRecordLength (int recordPtr)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return (buffer[recordPtr] & 0xFF) * SENTENCE_LENGTH + padding + 1;
|
return (buffer[recordPtr] & 0xFF) * SENTENCE_LENGTH + padding + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
private int getTotalActions ()
|
private int getTotalActions ()
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
// loop through each record in each index entry, and find the highest action number
|
// loop through each record in each index entry, and find the highest action number
|
||||||
int ptr = tablePtr;
|
int ptr = tablePtr;
|
||||||
@ -150,8 +160,10 @@ class Grammar extends InfocomAbstractFile
|
|||||||
// return routines;
|
// return routines;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public String getText ()
|
public String getText ()
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
String line = "-----------------------------------------------------"
|
String line = "-----------------------------------------------------"
|
||||||
+ "-----------------------------------------------------------\n";
|
+ "-----------------------------------------------------------\n";
|
||||||
@ -209,12 +221,16 @@ class Grammar extends InfocomAbstractFile
|
|||||||
return text.toString ();
|
return text.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
List<SentenceGroup> getSentenceGroups ()
|
List<SentenceGroup> getSentenceGroups ()
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return sentenceGroups;
|
return sentenceGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
private List<Sentence> getSentences (int routine)
|
private List<Sentence> getSentences (int routine)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
List<Sentence> sentences = new ArrayList<> ();
|
List<Sentence> sentences = new ArrayList<> ();
|
||||||
|
|
||||||
@ -226,7 +242,9 @@ class Grammar extends InfocomAbstractFile
|
|||||||
return sentences;
|
return sentences;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
private String makeWordBlock (List<String> words)
|
private String makeWordBlock (List<String> words)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
StringBuilder text = new StringBuilder ("[");
|
StringBuilder text = new StringBuilder ("[");
|
||||||
if (words.size () > 0)
|
if (words.size () > 0)
|
||||||
@ -242,7 +260,9 @@ class Grammar extends InfocomAbstractFile
|
|||||||
return text.toString ();
|
return text.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
class SentenceGroup implements Iterable<Sentence>
|
class SentenceGroup implements Iterable<Sentence>
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
int startPtr;
|
int startPtr;
|
||||||
int id;
|
int id;
|
||||||
@ -278,7 +298,9 @@ class Grammar extends InfocomAbstractFile
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
class Sentence
|
class Sentence
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
int startPtr;
|
int startPtr;
|
||||||
SentenceGroup parent;
|
SentenceGroup parent;
|
||||||
|
@ -4,7 +4,9 @@ import java.io.File;
|
|||||||
|
|
||||||
import com.bytezone.diskbrowser.disk.Disk;
|
import com.bytezone.diskbrowser.disk.Disk;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
class Header extends InfocomAbstractFile
|
class Header extends InfocomAbstractFile
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
final String[] propertyNames = new String[32];
|
final String[] propertyNames = new String[32];
|
||||||
|
|
||||||
@ -29,7 +31,9 @@ class Header extends InfocomAbstractFile
|
|||||||
final CodeManager codeManager;
|
final CodeManager codeManager;
|
||||||
final StringManager stringManager;
|
final StringManager stringManager;
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
public Header (String name, byte[] buffer, Disk disk)
|
public Header (String name, byte[] buffer, Disk disk)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
super (name, buffer);
|
super (name, buffer);
|
||||||
this.file = disk.getFile ();
|
this.file = disk.getFile ();
|
||||||
@ -79,28 +83,38 @@ class Header extends InfocomAbstractFile
|
|||||||
hexBlocks.add (new HexBlock (0, 64, "Header data:"));
|
hexBlocks.add (new HexBlock (0, 64, "Header data:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
String getPropertyName (int id)
|
String getPropertyName (int id)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return propertyNames[id];
|
return propertyNames[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
public String getAbbreviation (int index)
|
public String getAbbreviation (int index)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return abbreviations.getAbbreviation (index);
|
return abbreviations.getAbbreviation (index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
public boolean containsWordAt (int address)
|
public boolean containsWordAt (int address)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return dictionary.containsWordAt (address);
|
return dictionary.containsWordAt (address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
public String wordAt (int address)
|
public String wordAt (int address)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return dictionary.wordAt (address);
|
return dictionary.wordAt (address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public String getText ()
|
public String getText ()
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
StringBuilder text = new StringBuilder ();
|
StringBuilder text = new StringBuilder ();
|
||||||
|
|
||||||
@ -141,7 +155,9 @@ class Header extends InfocomAbstractFile
|
|||||||
return text.toString ();
|
return text.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
private String getAlternate ()
|
private String getAlternate ()
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
StringBuilder text = new StringBuilder ("\n\n");
|
StringBuilder text = new StringBuilder ("\n\n");
|
||||||
|
|
||||||
@ -161,7 +177,9 @@ class Header extends InfocomAbstractFile
|
|||||||
return text.toString ();
|
return text.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
private String getLine (int offset, int size, String description)
|
private String getLine (int offset, int size, String description)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
StringBuilder text = new StringBuilder ();
|
StringBuilder text = new StringBuilder ();
|
||||||
text.append (String.format ("%04X - %04X ", offset, offset + size - 1));
|
text.append (String.format ("%04X - %04X ", offset, offset + size - 1));
|
||||||
@ -174,17 +192,23 @@ class Header extends InfocomAbstractFile
|
|||||||
return text.toString ();
|
return text.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
ZObject getObject (int index)
|
ZObject getObject (int index)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return objectManager.getObject (index);
|
return objectManager.getObject (index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
int getByte (int offset)
|
int getByte (int offset)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return buffer[offset] & 0xFF;
|
return buffer[offset] & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
int getWord (int offset)
|
int getWord (int offset)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return ((buffer[offset] << 8) & 0xFF00) | ((buffer[offset + 1]) & 0xFF);
|
return ((buffer[offset] << 8) & 0xFF00) | ((buffer[offset + 1]) & 0xFF);
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,23 @@ import java.util.List;
|
|||||||
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
import com.bytezone.diskbrowser.applefile.AbstractFile;
|
||||||
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
public class InfocomAbstractFile extends AbstractFile
|
public class InfocomAbstractFile extends AbstractFile
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
protected List<HexBlock> hexBlocks = new ArrayList<> ();
|
protected List<HexBlock> hexBlocks = new ArrayList<> ();
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
public InfocomAbstractFile (String name, byte[] buffer)
|
public InfocomAbstractFile (String name, byte[] buffer)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
super (name, buffer);
|
super (name, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public String getHexDump ()
|
public String getHexDump ()
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
if (hexBlocks.size () > 0)
|
if (hexBlocks.size () > 0)
|
||||||
{
|
{
|
||||||
@ -44,7 +50,9 @@ public class InfocomAbstractFile extends AbstractFile
|
|||||||
return HexFormatter.format (buffer, 0, 99999);
|
return HexFormatter.format (buffer, 0, 99999);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
protected class HexBlock
|
protected class HexBlock
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
public int ptr;
|
public int ptr;
|
||||||
public int size;
|
public int size;
|
||||||
|
Loading…
Reference in New Issue
Block a user