From 135c94604705f053af2d73955b4f31c95048ce78 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Wed, 5 Feb 2020 14:26:39 +1000 Subject: [PATCH] tidying --- .../bytezone/diskbrowser/infocom/Grammar.java | 24 ++++++++++++++++++- .../bytezone/diskbrowser/infocom/Header.java | 24 +++++++++++++++++++ .../infocom/InfocomAbstractFile.java | 8 +++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/com/bytezone/diskbrowser/infocom/Grammar.java b/src/com/bytezone/diskbrowser/infocom/Grammar.java index c53ee2c..2bcedce 100644 --- a/src/com/bytezone/diskbrowser/infocom/Grammar.java +++ b/src/com/bytezone/diskbrowser/infocom/Grammar.java @@ -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 actionRoutines = new ArrayList<> (); private final List 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 ()); + 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 getSentenceGroups () + // ---------------------------------------------------------------------------------// { return sentenceGroups; } + // ---------------------------------------------------------------------------------// private List getSentences (int routine) + // ---------------------------------------------------------------------------------// { List sentences = new ArrayList<> (); @@ -226,7 +242,9 @@ class Grammar extends InfocomAbstractFile return sentences; } + // ---------------------------------------------------------------------------------// private String makeWordBlock (List words) + // ---------------------------------------------------------------------------------// { StringBuilder text = new StringBuilder ("["); if (words.size () > 0) @@ -242,7 +260,9 @@ class Grammar extends InfocomAbstractFile return text.toString (); } + // ---------------------------------------------------------------------------------// class SentenceGroup implements Iterable + // ---------------------------------------------------------------------------------// { int startPtr; int id; @@ -278,7 +298,9 @@ class Grammar extends InfocomAbstractFile } } + // ---------------------------------------------------------------------------------// class Sentence + // ---------------------------------------------------------------------------------// { int startPtr; SentenceGroup parent; diff --git a/src/com/bytezone/diskbrowser/infocom/Header.java b/src/com/bytezone/diskbrowser/infocom/Header.java index 4241c2e..90b6703 100755 --- a/src/com/bytezone/diskbrowser/infocom/Header.java +++ b/src/com/bytezone/diskbrowser/infocom/Header.java @@ -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); } diff --git a/src/com/bytezone/diskbrowser/infocom/InfocomAbstractFile.java b/src/com/bytezone/diskbrowser/infocom/InfocomAbstractFile.java index 7659624..b3c087e 100644 --- a/src/com/bytezone/diskbrowser/infocom/InfocomAbstractFile.java +++ b/src/com/bytezone/diskbrowser/infocom/InfocomAbstractFile.java @@ -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 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;