From 0b13adbee955b5f5ac4f64bbdc06d13cb92106b3 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Sun, 20 Dec 2020 11:34:42 +1000 Subject: [PATCH] fixed some infocom bugs --- .../diskbrowser/applefile/AbstractFile.java | 6 +++--- .../applefile/ApplesoftBasicProgram.java | 2 +- .../diskbrowser/applefile/VisicalcFile.java | 2 +- .../bytezone/diskbrowser/gui/DataPanel.java | 20 ++++--------------- .../diskbrowser/infocom/CodeManager.java | 5 ++++- .../diskbrowser/infocom/Dictionary.java | 7 ++++++- .../bytezone/diskbrowser/infocom/Header.java | 2 ++ .../diskbrowser/infocom/InfocomDisk.java | 2 +- .../bytezone/diskbrowser/infocom/ZObject.java | 11 ++++++---- 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/AbstractFile.java b/src/com/bytezone/diskbrowser/applefile/AbstractFile.java index ec71647..93ec273 100755 --- a/src/com/bytezone/diskbrowser/applefile/AbstractFile.java +++ b/src/com/bytezone/diskbrowser/applefile/AbstractFile.java @@ -12,7 +12,7 @@ import com.bytezone.diskbrowser.utilities.HexFormatter; public abstract class AbstractFile implements DataSource // -----------------------------------------------------------------------------------// { - static boolean debug; + static boolean showDebugText; protected String name; public byte[] buffer; @@ -40,14 +40,14 @@ public abstract class AbstractFile implements DataSource public static void setDefaultDebug (boolean value) // ---------------------------------------------------------------------------------// { - debug = value; + showDebugText = value; } // ---------------------------------------------------------------------------------// public static void setDebug (boolean value) // ---------------------------------------------------------------------------------// { - debug = value; + showDebugText = value; } // ---------------------------------------------------------------------------------// diff --git a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java index e88a350..1cf67ed 100644 --- a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java +++ b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java @@ -60,7 +60,7 @@ public class ApplesoftBasicProgram extends BasicProgram public String getText () // ---------------------------------------------------------------------------------// { - return debug ? getHexText () : getProgramText (); + return showDebugText ? getHexText () : getProgramText (); } // ---------------------------------------------------------------------------------// diff --git a/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java b/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java index 8522757..f878891 100644 --- a/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java +++ b/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java @@ -26,7 +26,7 @@ public class VisicalcFile extends AbstractFile StringBuilder text = new StringBuilder (); text.append ("Visicalc : " + name + "\n\n"); - text.append (sheet.getTextDisplay (debug)); + text.append (sheet.getTextDisplay (showDebugText)); return text.toString (); } diff --git a/src/com/bytezone/diskbrowser/gui/DataPanel.java b/src/com/bytezone/diskbrowser/gui/DataPanel.java index c69c7c1..fabd2f6 100755 --- a/src/com/bytezone/diskbrowser/gui/DataPanel.java +++ b/src/com/bytezone/diskbrowser/gui/DataPanel.java @@ -262,25 +262,10 @@ public class DataPanel extends JTabbedPane AbstractFile.setDebug (value); setText (formattedText, currentDataSource.getText ()); - // if (currentDataSource instanceof VisicalcFile) - // { - // VisicalcFile visicalcFile = (VisicalcFile) currentDataSource; - // VisicalcFile.setDebug (value); - // setText (formattedText, visicalcFile.getText ()); - // } - // else if (currentDataSource instanceof ApplesoftBasicProgram) - // { - // ApplesoftBasicProgram basicProgram = (ApplesoftBasicProgram) currentDataSource; - // ApplesoftBasicProgram.setDebug (value); - // setText (formattedText, basicProgram.getText ()); - // } - // // should implement an interface for this - // else + if (currentDataSource instanceof HiResImage || currentDataSource instanceof QuickDrawFont) - { setDataSource (currentDataSource); // toggles text/image - } } // ---------------------------------------------------------------------------------// @@ -359,6 +344,9 @@ public class DataPanel extends JTabbedPane hexTextValid = false; formattedTextValid = false; break; + + default: + System.out.println ("Unexpected Tab #" + getSelectedIndex ()); } BufferedImage image = dataSource.getImage (); diff --git a/src/com/bytezone/diskbrowser/infocom/CodeManager.java b/src/com/bytezone/diskbrowser/infocom/CodeManager.java index 16e7279..d7986bf 100644 --- a/src/com/bytezone/diskbrowser/infocom/CodeManager.java +++ b/src/com/bytezone/diskbrowser/infocom/CodeManager.java @@ -151,7 +151,10 @@ class CodeManager extends AbstractFile if (routines.containsKey (ptr)) { - ptr += getRoutine (ptr).length; + int length = getRoutine (ptr).length; + if (length == 0) + break; + ptr += length; continue; } diff --git a/src/com/bytezone/diskbrowser/infocom/Dictionary.java b/src/com/bytezone/diskbrowser/infocom/Dictionary.java index 6c6398a..922a1ef 100755 --- a/src/com/bytezone/diskbrowser/infocom/Dictionary.java +++ b/src/com/bytezone/diskbrowser/infocom/Dictionary.java @@ -65,8 +65,13 @@ class Dictionary extends AbstractFile int b1 = buffer[ptr + 5] & 0xFF; int b2 = buffer[ptr + 6] & 0xFF; int property = b2 == 0 ? b1 : b2; + property &= 0x1F; String propertyName = header.getPropertyName (property); + System.out.printf ("%02X %s%n", property, string.value); + // if (property >= header.propertyNames.length) + // System.out.println ("Illegal property"); + // else if (propertyName == null || propertyName.length () > string.value.length ()) header.propertyNames[property] = string.value; } @@ -80,7 +85,7 @@ class Dictionary extends AbstractFile header.propertyNames[i] = i + ""; // testing (only works in Zork 1) - if (true) + if (false) { if (header.propertyNames[4].equals ("4")) header.propertyNames[4] = "PSEUDO"; diff --git a/src/com/bytezone/diskbrowser/infocom/Header.java b/src/com/bytezone/diskbrowser/infocom/Header.java index 4bd524d..4f09a3c 100755 --- a/src/com/bytezone/diskbrowser/infocom/Header.java +++ b/src/com/bytezone/diskbrowser/infocom/Header.java @@ -87,6 +87,8 @@ class Header extends InfocomAbstractFile String getPropertyName (int id) // ---------------------------------------------------------------------------------// { + if (id >= propertyNames.length) + return "Bad id : " + id; return propertyNames[id]; } diff --git a/src/com/bytezone/diskbrowser/infocom/InfocomDisk.java b/src/com/bytezone/diskbrowser/infocom/InfocomDisk.java index b8b32c2..231dc74 100755 --- a/src/com/bytezone/diskbrowser/infocom/InfocomDisk.java +++ b/src/com/bytezone/diskbrowser/infocom/InfocomDisk.java @@ -54,7 +54,7 @@ public class InfocomDisk extends AbstractFormattedDisk setInfocomSectorTypes (); - data = disk.readBlock (3, 0); // read first sector to get file size + data = disk.readBlock (3, 0); // read first sector to get file size data = getBuffer (getWord (26) * 2); // read entire file into data buffer if (false) diff --git a/src/com/bytezone/diskbrowser/infocom/ZObject.java b/src/com/bytezone/diskbrowser/infocom/ZObject.java index 840871a..077bb96 100755 --- a/src/com/bytezone/diskbrowser/infocom/ZObject.java +++ b/src/com/bytezone/diskbrowser/infocom/ZObject.java @@ -199,10 +199,13 @@ class ZObject extends AbstractFile implements Comparable if (propertyNumber >= 19) // directions { + ZObject object = getObject (); + String objectName = object == null ? "no object" : object.name; + switch (length) { case 1: // UEXIT - unconditional exit - text.append (getObject ().name); + text.append (objectName); break; case 2: text.append ("\"" + header.stringManager.stringAt (offset) + "\""); @@ -213,15 +216,15 @@ class ZObject extends AbstractFile implements Comparable appendRoutine (text, address); break; case 4: - text.append (String.format ("%s : IF G%02X ELSE ", getObject ().name, + text.append (String.format ("%s : IF G%02X ELSE ", objectName, header.getByte (ptr + 2))); address = header.getWord (ptr + 3) * 2; if (address > 0) text.append ("\"" + header.stringManager.stringAt (address) + "\""); break; case 5: - text.append (String.format ("%s : IF G%02X ", getObject ().name, - header.getByte (ptr + 2))); + text.append ( + String.format ("%s : IF G%02X ", objectName, header.getByte (ptr + 2))); break; default: break;