From 467f5db1104ad736fdf67f9e67d27a279bbb4278 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Fri, 7 Feb 2020 21:44:51 +1000 Subject: [PATCH] method header lines --- .../diskbrowser/applefile/HiResImage.java | 3 + .../diskbrowser/applefile/SimpleText2.java | 314 +++++------ .../applefile/StoredVariables.java | 504 +++++++++--------- .../diskbrowser/applefile/TextBuffer.java | 6 + .../diskbrowser/applefile/TextFile.java | 396 +++++++------- .../diskbrowser/applefile/VisicalcFile.java | 12 + .../diskbrowser/applefile/WizardryTitle.java | 102 ++-- 7 files changed, 704 insertions(+), 633 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/HiResImage.java b/src/com/bytezone/diskbrowser/applefile/HiResImage.java index 0f08e40..57186ec 100644 --- a/src/com/bytezone/diskbrowser/applefile/HiResImage.java +++ b/src/com/bytezone/diskbrowser/applefile/HiResImage.java @@ -101,6 +101,9 @@ public abstract class HiResImage extends AbstractFile // 4 System Addons.hdv // + // see also - https://docs.google.com/spreadsheets/d + // /1rKR6A_bVniSCtIP_rrv8QLWJdj4h6jEU1jJj0AebWwg/edit#gid=0 + static PaletteFactory paletteFactory = new PaletteFactory (); static final byte[] pngHeader = diff --git a/src/com/bytezone/diskbrowser/applefile/SimpleText2.java b/src/com/bytezone/diskbrowser/applefile/SimpleText2.java index 8a69995..1108e7c 100755 --- a/src/com/bytezone/diskbrowser/applefile/SimpleText2.java +++ b/src/com/bytezone/diskbrowser/applefile/SimpleText2.java @@ -1,154 +1,162 @@ -package com.bytezone.diskbrowser.applefile; - -import java.util.ArrayList; -import java.util.List; - -import com.bytezone.diskbrowser.utilities.HexFormatter; - -public class SimpleText2 extends AbstractFile -{ - List lineStarts = new ArrayList<> (); - int loadAddress; - boolean showByte = false; - - public SimpleText2 (String name, byte[] buffer, int loadAddress) - { - super (name, buffer); - this.loadAddress = loadAddress; - - // store a pointer to each new line - int ptr = 0; - while (ptr < buffer.length && buffer[ptr] != -1) - { - int length = buffer[ptr] & 0xFF; - lineStarts.add (ptr); - ptr += length + 1; - } - } - - @Override - public String getText () - { - StringBuilder text = new StringBuilder (); - - text.append ("Name : " + name + "\n"); - text.append (String.format ("Length : $%04X (%d)%n", buffer.length, buffer.length)); - text.append (String.format ("Load at : $%04X%n%n", loadAddress)); - - for (Integer i : lineStarts) - text.append (String.format ("%05X %s%n", i, getLine (i))); - if (text.charAt (text.length () - 1) == '\n') - text.deleteCharAt (text.length () - 1); - return text.toString (); - } - - @Override - public String getHexDump () - { - StringBuilder text = new StringBuilder (); - - for (Integer i : lineStarts) - text.append ( - HexFormatter.formatNoHeader (buffer, i, (buffer[i] & 0xFF) + 1) + "\n"); - text.append (HexFormatter.formatNoHeader (buffer, buffer.length - 2, 2) + "\n"); - - return text.toString (); - } - - // convert buffer to text, ignore line-break at the end - private String getLine (int ptr) - { - StringBuilder line = new StringBuilder (); - int length = buffer[ptr] & 0xFF; - while (--length > 0) - { - int val = buffer[++ptr] & 0xFF; - if (val == 0xBB) - { - while (line.length () < 35) - line.append (' '); - line.append (';'); - } - else if (val >= 0x80) - { - while (line.length () < 10) - line.append (' '); - if (val == 0xDC) - line.append (String.format ("EQU %02X", val)); - else if (val == 0xD0) - line.append (String.format ("STA %02X", val)); - else if (val == 0xD2) - line.append (String.format ("STY %02X", val)); - else if (val == 0xD4) - line.append (String.format ("LSR %02X", val)); - else if (val == 0xD5) - line.append (String.format ("ROR %02X", val)); - else if (val == 0xD7) - line.append (String.format ("ASL %02X", val)); - else if (val == 0xD9) - line.append (String.format ("EQ %02X", val)); - else if (val == 0xDB) - line.append (String.format ("TGT %02X", val)); - else if (val == 0xDA) - line.append (String.format ("ORG %02X", val)); - else if (val == 0xB1) - line.append (String.format ("TYA %02X", val)); - else if (val == 0xC1) - line.append (String.format ("AND %02X", val)); - else if (val == 0xC4) - line.append (String.format ("CMP %02X", val)); - else if (val == 0xC8) - line.append (String.format ("EOR %02X", val)); - else if (val == 0xCA) - line.append (String.format ("JMP %02X", val)); - else if (val == 0xCB) - line.append (String.format ("JSR %02X", val)); - else if (val == 0xCD) - line.append (String.format ("LDA %02X", val)); - else if (val == 0xCE) - line.append (String.format ("LDX %02X", val)); - else if (val == 0xCF) - line.append (String.format ("LDY %02X", val)); - else if (val == 0xA1) - line.append (String.format ("PHA %02X", val)); - else if (val == 0xA2) - line.append (String.format ("PLA %02X", val)); - else if (val == 0xA5) - line.append (String.format ("RTS %02X", val)); - else if (val == 0xA9) - line.append (String.format ("SEC %02X", val)); - else if (val == 0xAD) - line.append (String.format ("TAY %02X", val)); - else if (val == 0x82) - line.append (String.format ("BMI %02X", val)); - else if (val == 0x84) - line.append (String.format ("BCS %02X", val)); - else if (val == 0x85) - line.append (String.format ("BPL %02X", val)); - else if (val == 0x86) - line.append (String.format ("BNE %02X", val)); - else if (val == 0x87) - line.append (String.format ("BEQ %02X", val)); - else if (val == 0x99) - line.append (String.format ("CLC %02X", val)); - else if (val == 0x9C) - line.append (String.format ("DEX %02X", val)); - else if (val == 0x9F) - line.append (String.format ("INY %02X", val)); - else - line.append (String.format (".%02X.", val)); - - line.append (' '); - ++ptr; - if (buffer[ptr] < 0x20 && showByte) - { - val = buffer[ptr] & 0xFF; - line.append (String.format (".%02X. ", val)); - } - } - else - line.append ((char) val); - } - return line.toString (); - } +package com.bytezone.diskbrowser.applefile; + +import java.util.ArrayList; +import java.util.List; + +import com.bytezone.diskbrowser.utilities.HexFormatter; + +// -----------------------------------------------------------------------------------// +public class SimpleText2 extends AbstractFile +// -----------------------------------------------------------------------------------// +{ + List lineStarts = new ArrayList<> (); + int loadAddress; + boolean showByte = false; + + public SimpleText2 (String name, byte[] buffer, int loadAddress) + { + super (name, buffer); + this.loadAddress = loadAddress; + + // store a pointer to each new line + int ptr = 0; + while (ptr < buffer.length && buffer[ptr] != -1) + { + int length = buffer[ptr] & 0xFF; + lineStarts.add (ptr); + ptr += length + 1; + } + } + + // ---------------------------------------------------------------------------------// + @Override + public String getText () + // ---------------------------------------------------------------------------------// + { + StringBuilder text = new StringBuilder (); + + text.append ("Name : " + name + "\n"); + text.append (String.format ("Length : $%04X (%d)%n", buffer.length, buffer.length)); + text.append (String.format ("Load at : $%04X%n%n", loadAddress)); + + for (Integer i : lineStarts) + text.append (String.format ("%05X %s%n", i, getLine (i))); + if (text.charAt (text.length () - 1) == '\n') + text.deleteCharAt (text.length () - 1); + return text.toString (); + } + + // ---------------------------------------------------------------------------------// + @Override + public String getHexDump () + // ---------------------------------------------------------------------------------// + { + StringBuilder text = new StringBuilder (); + + for (Integer i : lineStarts) + text.append ( + HexFormatter.formatNoHeader (buffer, i, (buffer[i] & 0xFF) + 1) + "\n"); + text.append (HexFormatter.formatNoHeader (buffer, buffer.length - 2, 2) + "\n"); + + return text.toString (); + } + + // convert buffer to text, ignore line-break at the end + // ---------------------------------------------------------------------------------// + private String getLine (int ptr) + // ---------------------------------------------------------------------------------// + { + StringBuilder line = new StringBuilder (); + int length = buffer[ptr] & 0xFF; + while (--length > 0) + { + int val = buffer[++ptr] & 0xFF; + if (val == 0xBB) + { + while (line.length () < 35) + line.append (' '); + line.append (';'); + } + else if (val >= 0x80) + { + while (line.length () < 10) + line.append (' '); + if (val == 0xDC) + line.append (String.format ("EQU %02X", val)); + else if (val == 0xD0) + line.append (String.format ("STA %02X", val)); + else if (val == 0xD2) + line.append (String.format ("STY %02X", val)); + else if (val == 0xD4) + line.append (String.format ("LSR %02X", val)); + else if (val == 0xD5) + line.append (String.format ("ROR %02X", val)); + else if (val == 0xD7) + line.append (String.format ("ASL %02X", val)); + else if (val == 0xD9) + line.append (String.format ("EQ %02X", val)); + else if (val == 0xDB) + line.append (String.format ("TGT %02X", val)); + else if (val == 0xDA) + line.append (String.format ("ORG %02X", val)); + else if (val == 0xB1) + line.append (String.format ("TYA %02X", val)); + else if (val == 0xC1) + line.append (String.format ("AND %02X", val)); + else if (val == 0xC4) + line.append (String.format ("CMP %02X", val)); + else if (val == 0xC8) + line.append (String.format ("EOR %02X", val)); + else if (val == 0xCA) + line.append (String.format ("JMP %02X", val)); + else if (val == 0xCB) + line.append (String.format ("JSR %02X", val)); + else if (val == 0xCD) + line.append (String.format ("LDA %02X", val)); + else if (val == 0xCE) + line.append (String.format ("LDX %02X", val)); + else if (val == 0xCF) + line.append (String.format ("LDY %02X", val)); + else if (val == 0xA1) + line.append (String.format ("PHA %02X", val)); + else if (val == 0xA2) + line.append (String.format ("PLA %02X", val)); + else if (val == 0xA5) + line.append (String.format ("RTS %02X", val)); + else if (val == 0xA9) + line.append (String.format ("SEC %02X", val)); + else if (val == 0xAD) + line.append (String.format ("TAY %02X", val)); + else if (val == 0x82) + line.append (String.format ("BMI %02X", val)); + else if (val == 0x84) + line.append (String.format ("BCS %02X", val)); + else if (val == 0x85) + line.append (String.format ("BPL %02X", val)); + else if (val == 0x86) + line.append (String.format ("BNE %02X", val)); + else if (val == 0x87) + line.append (String.format ("BEQ %02X", val)); + else if (val == 0x99) + line.append (String.format ("CLC %02X", val)); + else if (val == 0x9C) + line.append (String.format ("DEX %02X", val)); + else if (val == 0x9F) + line.append (String.format ("INY %02X", val)); + else + line.append (String.format (".%02X.", val)); + + line.append (' '); + ++ptr; + if (buffer[ptr] < 0x20 && showByte) + { + val = buffer[ptr] & 0xFF; + line.append (String.format (".%02X. ", val)); + } + } + else + line.append ((char) val); + } + return line.toString (); + } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/applefile/StoredVariables.java b/src/com/bytezone/diskbrowser/applefile/StoredVariables.java index b82a4c1..c8e2465 100755 --- a/src/com/bytezone/diskbrowser/applefile/StoredVariables.java +++ b/src/com/bytezone/diskbrowser/applefile/StoredVariables.java @@ -1,245 +1,261 @@ -package com.bytezone.diskbrowser.applefile; - -import com.bytezone.diskbrowser.utilities.HexFormatter; - -public class StoredVariables extends AbstractFile -{ - public StoredVariables (String name, byte[] buffer) - { - super (name, buffer); - } - - @Override - public String getText () - { - StringBuilder text = new StringBuilder (); - String strValue = null; - int intValue = 0; - // double doubleValue = 0.0; - int strPtr = buffer.length; - - text.append ("File length : " + HexFormatter.format4 (buffer.length)); - int totalLength = HexFormatter.intValue (buffer[0], buffer[1]); - text.append ("\nTotal length : " + HexFormatter.format4 (totalLength)); - - int varLength = HexFormatter.intValue (buffer[2], buffer[3]); - text.append ("\nVar length : " + HexFormatter.format4 (varLength)); - text.append ("\n\n"); - - // list simple variables - - int ptr = 5; - while (ptr < varLength + 5) - { - String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]); - text.append (variableName); - - char suffix = variableName.charAt (variableName.length () - 1); - if (suffix == '$') - { - int strLength = buffer[ptr + 2] & 0xFF; - strPtr -= strLength; - strValue = HexFormatter.getString (buffer, strPtr, strLength); - text.append (" = " + strValue); - } - else if (suffix == '%') - { - intValue = HexFormatter.intValue (buffer[ptr + 3], buffer[ptr + 2]); - if ((buffer[ptr + 2] & 0x80) > 0) - intValue -= 65536; - text.append (" = " + intValue); - } - else - { - if (hasValue (ptr + 2)) - { - String value = HexFormatter.floatValue (buffer, ptr + 2) + ""; - if (value.endsWith (".0")) - text.append (" = " + value.substring (0, value.length () - 2)); - else - text.append (" = " + value); - } - } - - text.append ("\n"); - ptr += 7; - } - listArrays (text, ptr, totalLength, strPtr); - - return text.toString (); - } - - private String getVariableName (byte b1, byte b2) - { - char c1, c2, suffix; - - if ((b1 & 0x80) > 0) // integer - { - c1 = (char) (b1 & 0x7F); - c2 = (char) (b2 & 0x7F); - suffix = '%'; - } - else if ((b2 & 0x80) > 0) // string - { - c1 = (char) b1; - c2 = (char) (b2 & 0x7F); - suffix = '$'; - } - else - { - c1 = (char) b1; - c2 = (char) b2; - suffix = ' '; - } - - StringBuffer variableName = new StringBuffer (); - variableName.append (c1); - if (c2 > 32) - variableName.append (c2); - if (suffix != ' ') - variableName.append (suffix); - - return variableName.toString (); - } - - private String getDimensionText (int[] values) - { - StringBuilder text = new StringBuilder ("("); - for (int i = 0; i < values.length; i++) - { - text.append (values[i]); - if (i < values.length - 1) - text.append (','); - } - return text.append (')').toString (); - } - - private void listArrays (StringBuilder text, int ptr, int totalLength, int strPtr) - { - while (ptr < totalLength + 5) - { - String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]); - text.append ("\n"); - int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]); - int dimensions = buffer[ptr + 4] & 0xFF; - int[] dimensionSizes = new int[dimensions]; - int totalElements = 0; - for (int i = 0; i < dimensions; i++) - { - int p = i * 2 + 5 + ptr; - int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]); - dimensionSizes[dimensions - i - 1] = elements - 1; - if (totalElements == 0) - totalElements = elements; - else - totalElements *= elements; - } - - int headerSize = 5 + dimensions * 2; - int elementSize = (offset - headerSize) / totalElements; - - int p = ptr + headerSize; - int[] values = new int[dimensions]; - for (int i = 0; i < values.length; i++) - values[i] = 0; - out: while (true) - { - text.append (variableName + " " + getDimensionText (values) + " = "); - if (elementSize == 2) - { - int intValue = HexFormatter.intValue (buffer[p + 1], buffer[p]); - if ((buffer[p] & 0x80) > 0) - intValue -= 65536; - text.append (intValue + "\n"); - } - else if (elementSize == 3) - { - int strLength = buffer[p] & 0xFF; - if (strLength > 0) - { - strPtr -= strLength; - text.append (HexFormatter.getString (buffer, strPtr, strLength)); - } - text.append ("\n"); - } - else if (elementSize == 5) - { - if (hasValue (p)) - text.append (HexFormatter.floatValue (buffer, p)); - text.append ("\n"); - } - p += elementSize; - int cp = 0; - while (++values[cp] > dimensionSizes[cp]) - { - values[cp++] = 0; - if (cp >= values.length) - break out; - } - } - ptr += offset; - } - } - - private boolean hasValue (int p) - { - for (int i = 0; i < 5; i++) - if (buffer[p + i] != 0) - return true; - return false; - } - - @Override - public String getHexDump () - { - StringBuffer text = new StringBuffer (); - - text.append ("File length : " + HexFormatter.format4 (buffer.length)); - int totalLength = HexFormatter.intValue (buffer[0], buffer[1]); - text.append ("\nTotal length : " + HexFormatter.format4 (totalLength)); - - int varLength = HexFormatter.intValue (buffer[2], buffer[3]); - text.append ("\nVar length : " + HexFormatter.format4 (varLength)); - - int unknown = buffer[4] & 0xFF; - text.append ("\nUnknown : " + HexFormatter.format2 (unknown)); - text.append ("\n\n"); - - int ptr = 5; - text.append ("Simple variables : \n\n"); - while (ptr < varLength + 5) - { - text.append (HexFormatter.format (buffer, ptr, 7, false, 0) + "\n"); - ptr += 7; - } - text.append ("\nArrays : \n\n"); - while (ptr < totalLength + 5) - { - int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]); - int dimensions = buffer[ptr + 4] & 0xFF; - int[] dimensionSizes = new int[dimensions]; - int totalElements = 0; - for (int i = 0; i < dimensions; i++) - { - int p = i * 2 + 5 + ptr; - int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]); - dimensionSizes[dimensions - i - 1] = elements; - if (totalElements == 0) - totalElements = elements; - else - totalElements *= elements; - } - int headerSize = 5 + dimensions * 2; - text.append (HexFormatter.format (buffer, ptr, headerSize, false, 0) + "\n\n"); - text.append ( - HexFormatter.format (buffer, ptr + headerSize, offset - headerSize, false, 0) - + "\n\n"); - ptr += offset; - } - text.append ("Strings : \n\n"); - int length = buffer.length - ptr; - text.append (HexFormatter.format (buffer, ptr, length, false, 0) + "\n\n"); - - return text.toString (); - } +package com.bytezone.diskbrowser.applefile; + +import com.bytezone.diskbrowser.utilities.HexFormatter; + +// -----------------------------------------------------------------------------------// +public class StoredVariables extends AbstractFile +// -----------------------------------------------------------------------------------// +{ + // ---------------------------------------------------------------------------------// + public StoredVariables (String name, byte[] buffer) + // ---------------------------------------------------------------------------------// + { + super (name, buffer); + } + + // ---------------------------------------------------------------------------------// + @Override + public String getText () + // ---------------------------------------------------------------------------------// + { + StringBuilder text = new StringBuilder (); + String strValue = null; + int intValue = 0; + // double doubleValue = 0.0; + int strPtr = buffer.length; + + text.append ("File length : " + HexFormatter.format4 (buffer.length)); + int totalLength = HexFormatter.intValue (buffer[0], buffer[1]); + text.append ("\nTotal length : " + HexFormatter.format4 (totalLength)); + + int varLength = HexFormatter.intValue (buffer[2], buffer[3]); + text.append ("\nVar length : " + HexFormatter.format4 (varLength)); + text.append ("\n\n"); + + // list simple variables + + int ptr = 5; + while (ptr < varLength + 5) + { + String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]); + text.append (variableName); + + char suffix = variableName.charAt (variableName.length () - 1); + if (suffix == '$') + { + int strLength = buffer[ptr + 2] & 0xFF; + strPtr -= strLength; + strValue = HexFormatter.getString (buffer, strPtr, strLength); + text.append (" = " + strValue); + } + else if (suffix == '%') + { + intValue = HexFormatter.intValue (buffer[ptr + 3], buffer[ptr + 2]); + if ((buffer[ptr + 2] & 0x80) > 0) + intValue -= 65536; + text.append (" = " + intValue); + } + else + { + if (hasValue (ptr + 2)) + { + String value = HexFormatter.floatValue (buffer, ptr + 2) + ""; + if (value.endsWith (".0")) + text.append (" = " + value.substring (0, value.length () - 2)); + else + text.append (" = " + value); + } + } + + text.append ("\n"); + ptr += 7; + } + listArrays (text, ptr, totalLength, strPtr); + + return text.toString (); + } + + // ---------------------------------------------------------------------------------// + private String getVariableName (byte b1, byte b2) + // ---------------------------------------------------------------------------------// + { + char c1, c2, suffix; + + if ((b1 & 0x80) > 0) // integer + { + c1 = (char) (b1 & 0x7F); + c2 = (char) (b2 & 0x7F); + suffix = '%'; + } + else if ((b2 & 0x80) > 0) // string + { + c1 = (char) b1; + c2 = (char) (b2 & 0x7F); + suffix = '$'; + } + else + { + c1 = (char) b1; + c2 = (char) b2; + suffix = ' '; + } + + StringBuffer variableName = new StringBuffer (); + variableName.append (c1); + if (c2 > 32) + variableName.append (c2); + if (suffix != ' ') + variableName.append (suffix); + + return variableName.toString (); + } + + // ---------------------------------------------------------------------------------// + private String getDimensionText (int[] values) + // ---------------------------------------------------------------------------------// + { + StringBuilder text = new StringBuilder ("("); + for (int i = 0; i < values.length; i++) + { + text.append (values[i]); + if (i < values.length - 1) + text.append (','); + } + return text.append (')').toString (); + } + + // ---------------------------------------------------------------------------------// + private void listArrays (StringBuilder text, int ptr, int totalLength, int strPtr) + // ---------------------------------------------------------------------------------// + { + while (ptr < totalLength + 5) + { + String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]); + text.append ("\n"); + int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]); + int dimensions = buffer[ptr + 4] & 0xFF; + int[] dimensionSizes = new int[dimensions]; + int totalElements = 0; + for (int i = 0; i < dimensions; i++) + { + int p = i * 2 + 5 + ptr; + int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]); + dimensionSizes[dimensions - i - 1] = elements - 1; + if (totalElements == 0) + totalElements = elements; + else + totalElements *= elements; + } + + int headerSize = 5 + dimensions * 2; + int elementSize = (offset - headerSize) / totalElements; + + int p = ptr + headerSize; + int[] values = new int[dimensions]; + for (int i = 0; i < values.length; i++) + values[i] = 0; + out: while (true) + { + text.append (variableName + " " + getDimensionText (values) + " = "); + if (elementSize == 2) + { + int intValue = HexFormatter.intValue (buffer[p + 1], buffer[p]); + if ((buffer[p] & 0x80) > 0) + intValue -= 65536; + text.append (intValue + "\n"); + } + else if (elementSize == 3) + { + int strLength = buffer[p] & 0xFF; + if (strLength > 0) + { + strPtr -= strLength; + text.append (HexFormatter.getString (buffer, strPtr, strLength)); + } + text.append ("\n"); + } + else if (elementSize == 5) + { + if (hasValue (p)) + text.append (HexFormatter.floatValue (buffer, p)); + text.append ("\n"); + } + p += elementSize; + int cp = 0; + while (++values[cp] > dimensionSizes[cp]) + { + values[cp++] = 0; + if (cp >= values.length) + break out; + } + } + ptr += offset; + } + } + + // ---------------------------------------------------------------------------------// + private boolean hasValue (int p) + // ---------------------------------------------------------------------------------// + { + for (int i = 0; i < 5; i++) + if (buffer[p + i] != 0) + return true; + return false; + } + + // ---------------------------------------------------------------------------------// + @Override + public String getHexDump () + // ---------------------------------------------------------------------------------// + { + StringBuffer text = new StringBuffer (); + + text.append ("File length : " + HexFormatter.format4 (buffer.length)); + int totalLength = HexFormatter.intValue (buffer[0], buffer[1]); + text.append ("\nTotal length : " + HexFormatter.format4 (totalLength)); + + int varLength = HexFormatter.intValue (buffer[2], buffer[3]); + text.append ("\nVar length : " + HexFormatter.format4 (varLength)); + + int unknown = buffer[4] & 0xFF; + text.append ("\nUnknown : " + HexFormatter.format2 (unknown)); + text.append ("\n\n"); + + int ptr = 5; + text.append ("Simple variables : \n\n"); + while (ptr < varLength + 5) + { + text.append (HexFormatter.format (buffer, ptr, 7, false, 0) + "\n"); + ptr += 7; + } + text.append ("\nArrays : \n\n"); + while (ptr < totalLength + 5) + { + int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]); + int dimensions = buffer[ptr + 4] & 0xFF; + int[] dimensionSizes = new int[dimensions]; + int totalElements = 0; + for (int i = 0; i < dimensions; i++) + { + int p = i * 2 + 5 + ptr; + int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]); + dimensionSizes[dimensions - i - 1] = elements; + if (totalElements == 0) + totalElements = elements; + else + totalElements *= elements; + } + int headerSize = 5 + dimensions * 2; + text.append (HexFormatter.format (buffer, ptr, headerSize, false, 0) + "\n\n"); + text.append ( + HexFormatter.format (buffer, ptr + headerSize, offset - headerSize, false, 0) + + "\n\n"); + ptr += offset; + } + text.append ("Strings : \n\n"); + int length = buffer.length - ptr; + text.append (HexFormatter.format (buffer, ptr, length, false, 0) + "\n\n"); + + return text.toString (); + } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/applefile/TextBuffer.java b/src/com/bytezone/diskbrowser/applefile/TextBuffer.java index a4acbd9..3fcc30d 100644 --- a/src/com/bytezone/diskbrowser/applefile/TextBuffer.java +++ b/src/com/bytezone/diskbrowser/applefile/TextBuffer.java @@ -3,13 +3,17 @@ package com.bytezone.diskbrowser.applefile; import com.bytezone.diskbrowser.utilities.HexFormatter; // only used by Prodos text files - note the fixed block size of 512 - bad! +// -----------------------------------------------------------------------------------// public class TextBuffer +// -----------------------------------------------------------------------------------// { public final byte[] buffer; public final int reclen; public final int firstRecNo; + // ---------------------------------------------------------------------------------// public TextBuffer (byte[] tempBuffer, int reclen, int firstBlock) + // ---------------------------------------------------------------------------------// { this.reclen = reclen; @@ -34,8 +38,10 @@ public class TextBuffer System.arraycopy (tempBuffer, offset, buffer, 0, copyBytes); } + // ---------------------------------------------------------------------------------// @Override public String toString () + // ---------------------------------------------------------------------------------// { StringBuilder text = new StringBuilder (); diff --git a/src/com/bytezone/diskbrowser/applefile/TextFile.java b/src/com/bytezone/diskbrowser/applefile/TextFile.java index 1ccc2f3..aebb857 100755 --- a/src/com/bytezone/diskbrowser/applefile/TextFile.java +++ b/src/com/bytezone/diskbrowser/applefile/TextFile.java @@ -1,189 +1,209 @@ -package com.bytezone.diskbrowser.applefile; - -import java.util.List; - -import com.bytezone.diskbrowser.utilities.HexFormatter; - -public class TextFile extends AbstractFile -{ - private int recordLength; // prodos aux - private List buffers; // only used if it is a Prodos text file - private int eof; - private boolean prodosFile; - - public TextFile (String name, byte[] buffer) - { - super (name, buffer); - } - - public TextFile (String name, byte[] buffer, int auxType, int eof) - { - this (name, buffer); - this.eof = eof; - recordLength = auxType; - prodosFile = true; - } - - public TextFile (String name, List buffers, int auxType, int eof) - { - super (name, null); - this.buffers = buffers; - this.eof = eof; - recordLength = auxType; - prodosFile = true; - } - - @Override - public String getHexDump () - { - if (buffers == null) - return (super.getHexDump ()); - - StringBuilder text = new StringBuilder (); - for (TextBuffer tb : buffers) - { - for (int i = 0, rec = 0; i < tb.buffer.length; i += tb.reclen, rec++) - { - text.append ("\nRecord #" + (tb.firstRecNo + rec) + "\n"); - text.append (HexFormatter.format (tb.buffer, i, tb.reclen) + "\n"); - } - } - return text.toString (); - } - - @Override - public String getText () - { - StringBuilder text = new StringBuilder (); - - text.append ("Name : " + name + "\n"); - if (prodosFile) - { - text.append (String.format ("Record length : %,8d%n", recordLength)); - text.append (String.format ("End of file : %,8d%n", eof)); - } - else - text.append (String.format ("End of file : %,8d%n", buffer.length)); - text.append ("\n"); - - // check whether file is spread over multiple buffers - if (buffers != null) - return treeFileText (text); // calls knownLength() - - // check whether the record length is known - if (recordLength == 0) - return unknownLength (text); - - text.append ("Offset Record# Text values\n"); - text.append ( - "------ ------- -------------------------------------------------------\n"); - return knownLength (text, 0).toString (); - } - - private String treeFileText (StringBuilder text) - { - text.append (" Offset Record# Text values\n"); - text.append ( - "---------- ------- -------------------------------------------------------\n"); - for (TextBuffer tb : buffers) - { - buffer = tb.buffer; - text = knownLength (text, tb.firstRecNo); - } - return text.toString (); - } - - private StringBuilder knownLength (StringBuilder text, int recNo) - { - for (int ptr = 0; ptr < buffer.length; ptr += recordLength) - { - if (buffer[ptr] == 0) - { - recNo++; - continue; - } - - int len = buffer.length - ptr; - int bytes = len < recordLength ? len : recordLength; - - while (buffer[ptr + bytes - 1] == 0) - bytes--; - - if ((buffer[ptr + bytes - 1] & 0x7F) == 0x0D) // ignore CR - bytes--; - - String line = HexFormatter.getString (buffer, ptr, bytes); - line = line.replaceAll ("\\n", "\n "); - text.append ( - String.format ("%,10d %,8d %s%n", recNo * recordLength, recNo++, line)); - } - - return text; - } - - private String unknownLength (StringBuilder text) - { - int nulls = 0; - int ptr = 0; - int size = buffer.length; - int lastVal = 0; - boolean newFormat = true; - boolean showAllOffsets = true; - - if (newFormat) - { - text.append (" Offset Text values\n"); - text.append ("---------- -------------------------------------------------------" - + "-------------------\n"); - if (buffer.length == 0) - return text.toString (); - - if (buffer[0] != 0) - text.append (String.format ("%,10d ", ptr)); - } - - int gcd = 0; - - while (ptr < size) - { - int val = buffer[ptr++] & 0x7F; // strip hi-order bit - if (val == 0) - ++nulls; - else if (val == 0x0D) // carriage return - text.append ("\n"); - else - { - if (nulls > 0) - { - if (newFormat) - text.append (String.format ("%,10d ", ptr - 1)); - else - text.append ("\nNew record at : " + (ptr - 1) + "\n"); - nulls = 0; - - gcd = gcd == 0 ? ptr - 1 : gcd (gcd, ptr - 1); - } - else if (lastVal == 0x0D && newFormat) - if (showAllOffsets) - text.append (String.format ("%,10d ", ptr - 1)); - else - text.append (" "); - - text.append ((char) val); - } - lastVal = val; - } - - if (gcd > 0) - text.append (String.format ("%nGCD: %,d", gcd)); - else if (text.length () > 0 && text.charAt (text.length () - 1) == '\n') - text.deleteCharAt (text.length () - 1); - - return text.toString (); - } - - private int gcd (int a, int b) - { - return a == 0 ? b : gcd (b % a, a); - } +package com.bytezone.diskbrowser.applefile; + +import java.util.List; + +import com.bytezone.diskbrowser.utilities.HexFormatter; + +// -----------------------------------------------------------------------------------// +public class TextFile extends AbstractFile +// -----------------------------------------------------------------------------------// +{ + private int recordLength; // prodos aux + private List buffers; // only used if it is a Prodos text file + private int eof; + private boolean prodosFile; + + // ---------------------------------------------------------------------------------// + public TextFile (String name, byte[] buffer) + // ---------------------------------------------------------------------------------// + { + super (name, buffer); + } + + // ---------------------------------------------------------------------------------// + public TextFile (String name, byte[] buffer, int auxType, int eof) + // ---------------------------------------------------------------------------------// + { + this (name, buffer); + this.eof = eof; + recordLength = auxType; + prodosFile = true; + } + + // ---------------------------------------------------------------------------------// + public TextFile (String name, List buffers, int auxType, int eof) + // ---------------------------------------------------------------------------------// + { + super (name, null); + this.buffers = buffers; + this.eof = eof; + recordLength = auxType; + prodosFile = true; + } + + // ---------------------------------------------------------------------------------// + @Override + public String getHexDump () + // ---------------------------------------------------------------------------------// + { + if (buffers == null) + return (super.getHexDump ()); + + StringBuilder text = new StringBuilder (); + for (TextBuffer tb : buffers) + { + for (int i = 0, rec = 0; i < tb.buffer.length; i += tb.reclen, rec++) + { + text.append ("\nRecord #" + (tb.firstRecNo + rec) + "\n"); + text.append (HexFormatter.format (tb.buffer, i, tb.reclen) + "\n"); + } + } + return text.toString (); + } + + // ---------------------------------------------------------------------------------// + @Override + public String getText () + // ---------------------------------------------------------------------------------// + { + StringBuilder text = new StringBuilder (); + + text.append ("Name : " + name + "\n"); + if (prodosFile) + { + text.append (String.format ("Record length : %,8d%n", recordLength)); + text.append (String.format ("End of file : %,8d%n", eof)); + } + else + text.append (String.format ("End of file : %,8d%n", buffer.length)); + text.append ("\n"); + + // check whether file is spread over multiple buffers + if (buffers != null) + return treeFileText (text); // calls knownLength() + + // check whether the record length is known + if (recordLength == 0) + return unknownLength (text); + + text.append ("Offset Record# Text values\n"); + text.append ( + "------ ------- -------------------------------------------------------\n"); + return knownLength (text, 0).toString (); + } + + // ---------------------------------------------------------------------------------// + private String treeFileText (StringBuilder text) + // ---------------------------------------------------------------------------------// + { + text.append (" Offset Record# Text values\n"); + text.append ( + "---------- ------- -------------------------------------------------------\n"); + for (TextBuffer tb : buffers) + { + buffer = tb.buffer; + text = knownLength (text, tb.firstRecNo); + } + return text.toString (); + } + + // ---------------------------------------------------------------------------------// + private StringBuilder knownLength (StringBuilder text, int recNo) + // ---------------------------------------------------------------------------------// + { + for (int ptr = 0; ptr < buffer.length; ptr += recordLength) + { + if (buffer[ptr] == 0) + { + recNo++; + continue; + } + + int len = buffer.length - ptr; + int bytes = len < recordLength ? len : recordLength; + + while (buffer[ptr + bytes - 1] == 0) + bytes--; + + if ((buffer[ptr + bytes - 1] & 0x7F) == 0x0D) // ignore CR + bytes--; + + String line = HexFormatter.getString (buffer, ptr, bytes); + line = line.replaceAll ("\\n", "\n "); + text.append ( + String.format ("%,10d %,8d %s%n", recNo * recordLength, recNo++, line)); + } + + return text; + } + + // ---------------------------------------------------------------------------------// + private String unknownLength (StringBuilder text) + // ---------------------------------------------------------------------------------// + { + int nulls = 0; + int ptr = 0; + int size = buffer.length; + int lastVal = 0; + boolean newFormat = true; + boolean showAllOffsets = true; + + if (newFormat) + { + text.append (" Offset Text values\n"); + text.append ("---------- -------------------------------------------------------" + + "-------------------\n"); + if (buffer.length == 0) + return text.toString (); + + if (buffer[0] != 0) + text.append (String.format ("%,10d ", ptr)); + } + + int gcd = 0; + + while (ptr < size) + { + int val = buffer[ptr++] & 0x7F; // strip hi-order bit + if (val == 0) + ++nulls; + else if (val == 0x0D) // carriage return + text.append ("\n"); + else + { + if (nulls > 0) + { + if (newFormat) + text.append (String.format ("%,10d ", ptr - 1)); + else + text.append ("\nNew record at : " + (ptr - 1) + "\n"); + nulls = 0; + + gcd = gcd == 0 ? ptr - 1 : gcd (gcd, ptr - 1); + } + else if (lastVal == 0x0D && newFormat) + if (showAllOffsets) + text.append (String.format ("%,10d ", ptr - 1)); + else + text.append (" "); + + text.append ((char) val); + } + lastVal = val; + } + + if (gcd > 0) + text.append (String.format ("%nGCD: %,d", gcd)); + else if (text.length () > 0 && text.charAt (text.length () - 1) == '\n') + text.deleteCharAt (text.length () - 1); + + return text.toString (); + } + + // ---------------------------------------------------------------------------------// + private int gcd (int a, int b) + // ---------------------------------------------------------------------------------// + { + return a == 0 ? b : gcd (b % a, a); + } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java b/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java index b42d5cf..7ada3c7 100644 --- a/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java +++ b/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java @@ -2,18 +2,24 @@ package com.bytezone.diskbrowser.applefile; import com.bytezone.diskbrowser.visicalc.Sheet; +// -----------------------------------------------------------------------------------// public class VisicalcFile extends AbstractFile +// -----------------------------------------------------------------------------------// { private static boolean debug; private Sheet sheet; + // ---------------------------------------------------------------------------------// public VisicalcFile (String name, byte[] buffer) + // ---------------------------------------------------------------------------------// { super (name, buffer); } + // ---------------------------------------------------------------------------------// @Override public String getText () + // ---------------------------------------------------------------------------------// { if (sheet == null) sheet = new Sheet (buffer); @@ -26,17 +32,23 @@ public class VisicalcFile extends AbstractFile return text.toString (); } + // ---------------------------------------------------------------------------------// public static void setDefaultDebug (boolean value) + // ---------------------------------------------------------------------------------// { debug = value; } + // ---------------------------------------------------------------------------------// public static void setDebug (boolean value) + // ---------------------------------------------------------------------------------// { debug = value; } + // ---------------------------------------------------------------------------------// public static boolean isVisicalcFile (byte[] buffer) + // ---------------------------------------------------------------------------------// { int firstByte = buffer[0] & 0xFF; if (firstByte != 0xBE && firstByte != 0xAF) diff --git a/src/com/bytezone/diskbrowser/applefile/WizardryTitle.java b/src/com/bytezone/diskbrowser/applefile/WizardryTitle.java index 962c9bd..4b4c40d 100755 --- a/src/com/bytezone/diskbrowser/applefile/WizardryTitle.java +++ b/src/com/bytezone/diskbrowser/applefile/WizardryTitle.java @@ -1,49 +1,55 @@ -package com.bytezone.diskbrowser.applefile; - -public class WizardryTitle extends AbstractFile -{ - public WizardryTitle (String name, byte[] buffer) - { - super (name, buffer); - } - - @Override - public String getText () - { - int size = 20; - StringBuilder text = new StringBuilder (); - for (int i = 0; i < buffer.length; i += size) - { - for (int line = 0; line < size; line++) - { - int p = i + line; - if (p >= buffer.length) - break; - int value = buffer[p] & 0xFF; - text = decode2 (value, text); - } - text.append ("\n"); - } - return text.toString (); - } - - // private StringBuilder decode (int value, StringBuilder text) - // { - // for (int bit = 0; bit < 8; bit++) - // { - // text.append ((value & 0x01) == 1 ? "X" : " "); - // value >>= 1; - // } - // return text; - // } - - private StringBuilder decode2 (int value, StringBuilder text) - { - for (int bit = 7; bit >= 0; bit--) - { - text.append ((value & 0x01) == 1 ? "X" : " "); - value >>= 1; - } - return text; - } +package com.bytezone.diskbrowser.applefile; + +// -----------------------------------------------------------------------------------// +public class WizardryTitle extends AbstractFile +// -----------------------------------------------------------------------------------// +{ + public WizardryTitle (String name, byte[] buffer) + { + super (name, buffer); + } + + // ---------------------------------------------------------------------------------// + @Override + public String getText () + // ---------------------------------------------------------------------------------// + { + int size = 20; + StringBuilder text = new StringBuilder (); + for (int i = 0; i < buffer.length; i += size) + { + for (int line = 0; line < size; line++) + { + int p = i + line; + if (p >= buffer.length) + break; + int value = buffer[p] & 0xFF; + text = decode2 (value, text); + } + text.append ("\n"); + } + return text.toString (); + } + + // private StringBuilder decode (int value, StringBuilder text) + // { + // for (int bit = 0; bit < 8; bit++) + // { + // text.append ((value & 0x01) == 1 ? "X" : " "); + // value >>= 1; + // } + // return text; + // } + + // ---------------------------------------------------------------------------------// + private StringBuilder decode2 (int value, StringBuilder text) + // ---------------------------------------------------------------------------------// + { + for (int bit = 7; bit >= 0; bit--) + { + text.append ((value & 0x01) == 1 ? "X" : " "); + value >>= 1; + } + return text; + } } \ No newline at end of file