From 3062189ee8559c6bde7df346d066c5d3872629eb Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Wed, 3 Aug 2016 21:32:47 +1000 Subject: [PATCH] wizardry 4 changes --- .../diskbrowser/applefile/PascalCode.java | 19 +++++++---- .../applefile/PascalCodeStatement.java | 18 ++++++++++- .../applefile/PascalProcedure.java | 2 +- .../diskbrowser/applefile/PascalSegment.java | 32 +++++++++---------- .../diskbrowser/applefile/Relocator.java | 4 +-- .../diskbrowser/disk/DiskFactory.java | 2 +- .../bytezone/diskbrowser/gui/DiskBrowser.java | 2 +- .../bytezone/diskbrowser/gui/WindowSaver.java | 10 +++--- .../diskbrowser/pascal/CatalogEntry.java | 2 +- .../pascal/PascalCatalogSector.java | 4 +-- .../diskbrowser/pascal/PascalDisk.java | 12 +++---- .../diskbrowser/utilities/Utility.java | 32 +++++++++++++++++++ 12 files changed, 97 insertions(+), 42 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/PascalCode.java b/src/com/bytezone/diskbrowser/applefile/PascalCode.java index 91d0151..595c975 100755 --- a/src/com/bytezone/diskbrowser/applefile/PascalCode.java +++ b/src/com/bytezone/diskbrowser/applefile/PascalCode.java @@ -6,6 +6,7 @@ import java.util.List; import com.bytezone.diskbrowser.utilities.FileFormatException; import com.bytezone.diskbrowser.utilities.HexFormatter; +import com.bytezone.diskbrowser.utilities.Utility; public class PascalCode extends AbstractFile implements PascalConstants, Iterable @@ -25,25 +26,31 @@ public class PascalCode extends AbstractFile { super (name, buffer); int nonameCounter = 0; + if (false) + { + System.out.println (name); + byte[] key = new byte[] { 0x38, 0x00, 0x0C, 0x1C }; + Utility.find (buffer, key); + } - // Build segment list (up to 16 segments) + // Create segment list (up to 16 segments) for (int i = 0; i < 16; i++) { codeName = HexFormatter.getString (buffer, 0x40 + i * 8, 8).trim (); + if (codeName.length () == 0) + codeName = ""; int size = HexFormatter.intValue (buffer[i * 4 + 2], buffer[i * 4 + 3]); - System.out.printf ("%s %s %d %n", HexFormatter.getHexString (buffer, i * 4, 4), - codeName, size); + // System.out.printf ("%s %s %d %n", HexFormatter.getHexString (buffer, i * 4, 4), + // codeName, size); if (size > 0) { - if (codeName.length () == 0) - codeName = ""; try { segments.add (new PascalSegment (codeName, buffer, i)); } catch (FileFormatException e) { - System.out.println ("Bad segment"); + System.out.printf ("Bad segment: %d%n", i); } } } diff --git a/src/com/bytezone/diskbrowser/applefile/PascalCodeStatement.java b/src/com/bytezone/diskbrowser/applefile/PascalCodeStatement.java index f3dbb7b..139579b 100755 --- a/src/com/bytezone/diskbrowser/applefile/PascalCodeStatement.java +++ b/src/com/bytezone/diskbrowser/applefile/PascalCodeStatement.java @@ -334,4 +334,20 @@ public class PascalCodeStatement implements PascalConstants return String.format ("%04X", addressTo); } } -} \ No newline at end of file +} + +/* from Wizardry info 1.txt + +LDC instruction +--------------- +Earlier today I noticed the LDC pcode instruction seems to display +differently at times. Then I realized that it is operating with WORD +values and needs to have them aligned on an even BYTE boundary. For +example: + +5004 B3 02 8C 3F CD CC + LDC. PUSH 02 WORDS + +5017 B3 02 (02)8C 3F CD CC + LDC. PUSH 02 WORDS +*/ \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/applefile/PascalProcedure.java b/src/com/bytezone/diskbrowser/applefile/PascalProcedure.java index bac1641..ef9177d 100755 --- a/src/com/bytezone/diskbrowser/applefile/PascalProcedure.java +++ b/src/com/bytezone/diskbrowser/applefile/PascalProcedure.java @@ -38,7 +38,7 @@ public class PascalProcedure if (valid) { procedureNo = buffer[procOffset] & 0xFF; - procLevel = buffer[procOffset + 1]; + procLevel = buffer[procOffset + 1] & 0xFF; codeStart = HexFormatter.intValue (buffer[procOffset - 2], buffer[procOffset - 1]); codeEnd = HexFormatter.intValue (buffer[procOffset - 4], buffer[procOffset - 3]); parmSize = HexFormatter.intValue (buffer[procOffset - 6], buffer[procOffset - 5]); diff --git a/src/com/bytezone/diskbrowser/applefile/PascalSegment.java b/src/com/bytezone/diskbrowser/applefile/PascalSegment.java index 8331db2..55a85b8 100755 --- a/src/com/bytezone/diskbrowser/applefile/PascalSegment.java +++ b/src/com/bytezone/diskbrowser/applefile/PascalSegment.java @@ -31,12 +31,14 @@ public class PascalSegment extends AbstractFile implements PascalConstants this.slot = seq; this.blockNo = HexFormatter.intValue (fullBuffer[seq * 4], fullBuffer[seq * 4 + 1]); this.size = HexFormatter.intValue (fullBuffer[seq * 4 + 2], fullBuffer[seq * 4 + 3]); - this.segmentNoHeader = fullBuffer[0x100 + seq * 2]; segKind = HexFormatter.intValue (fullBuffer[0xC0 + seq * 2], fullBuffer[0xC0 + seq * 2 + 1]); + textAddress = HexFormatter.intValue (fullBuffer[0xE0 + seq * 2], fullBuffer[0xE0 + seq * 2 + 1]); + + this.segmentNoHeader = fullBuffer[0x100 + seq * 2] & 0xFF; int flags = fullBuffer[0x101 + seq * 2] & 0xFF; machineType = flags & 0x0F; version = (flags & 0xD0) >> 5; @@ -64,8 +66,8 @@ public class PascalSegment extends AbstractFile implements PascalConstants } else { - System.out.printf ("Error in blocksize %,d > %,d for pascal disk%n", offset, - fullBuffer.length); + // System.out.printf ("Error in blocksize %,d > %,d for pascal disk%n", offset, + // fullBuffer.length); throw new FileFormatException ("Error in PascalSegment"); } } @@ -81,7 +83,7 @@ public class PascalSegment extends AbstractFile implements PascalConstants public String toText () { return String - .format (" %2d %02X %04X %,6d %-8s %-15s %3d %3d %d %d %d %d", + .format (" %2d %02X %04X %,6d %-8s %-15s %3d %02X %d %d %d %d", slot, blockNo, size, size, name, SegmentKind[segKind], textAddress, segmentNoHeader, machineType, version, intrinsSegs1, intrinsSegs2); } @@ -96,13 +98,13 @@ public class PascalSegment extends AbstractFile implements PascalConstants String title = "Segment - " + name; text.append (title + "\n" + "===============================".substring (0, title.length ()) + "\n\n"); - String warning = - segmentNoBody == segmentNoHeader ? "" : " (" + segmentNoHeader + " in header)"; + String warning = segmentNoBody == segmentNoHeader ? "" + : String.format (" (%02X in header)", segmentNoHeader); text.append (String.format ("Address........ %02X%n", blockNo)); text.append (String.format ("Length......... %04X%n", buffer.length)); text.append (String.format ("Machine type... %d%n", machineType)); text.append (String.format ("Version........ %d%n", version)); - text.append (String.format ("Segment........ %d%s%n", segmentNoBody, warning)); + text.append (String.format ("Segment........ %02X%s%n", segmentNoBody, warning)); text.append (String.format ("Total procs.... %d%n", procedures.size ())); text.append ("\nProcedure Dictionary\n====================\n\n"); @@ -118,17 +120,15 @@ public class PascalSegment extends AbstractFile implements PascalConstants if (procedure.valid) { int address = size - procedure.slot * 2 - 2; - text.append (String.format ( - " %2d %04X %3d %04X %04X %04X " - + "%04X (%04X - %04X = %04X)%n", - procedure.procedureNo, procedure.offset, - procedure.procLevel, procedure.codeStart, - procedure.codeEnd, procedure.parmSize, - procedure.dataSize, address, procedure.offset, - procedure.procOffset)); + text.append (String + .format (" %3d %04X %3d %04X %04X %04X %04X (%04X - %04X = %04X)%n", + procedure.procedureNo, procedure.offset, procedure.procLevel, + procedure.codeStart, procedure.codeEnd, procedure.parmSize, + procedure.dataSize, address, procedure.offset, + procedure.procOffset)); } else - text.append (String.format (" %2d %04X%n", procedure.slot, procedure.offset)); + text.append (String.format (" %3d %04X%n", procedure.slot, procedure.offset)); } text.append ("\nStrings\n=======\n"); diff --git a/src/com/bytezone/diskbrowser/applefile/Relocator.java b/src/com/bytezone/diskbrowser/applefile/Relocator.java index 3362eb0..6957d15 100644 --- a/src/com/bytezone/diskbrowser/applefile/Relocator.java +++ b/src/com/bytezone/diskbrowser/applefile/Relocator.java @@ -100,8 +100,8 @@ public class Relocator extends AbstractFile @Override public String toString () { - return String.format (" %04X %04X %04X", logicalBlock, physicalBlock, - segmentLength); + return String.format (" %04X %04X %04X %04X", logicalBlock, + physicalBlock, segmentLength, (physicalBlock - 0x46)); } } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/disk/DiskFactory.java b/src/com/bytezone/diskbrowser/disk/DiskFactory.java index 5daeac7..a7fe6b0 100755 --- a/src/com/bytezone/diskbrowser/disk/DiskFactory.java +++ b/src/com/bytezone/diskbrowser/disk/DiskFactory.java @@ -20,7 +20,7 @@ import com.bytezone.diskbrowser.wizardry.WizardryScenarioDisk; public class DiskFactory { - private static boolean debug = true; + private static boolean debug = false; private DiskFactory () { diff --git a/src/com/bytezone/diskbrowser/gui/DiskBrowser.java b/src/com/bytezone/diskbrowser/gui/DiskBrowser.java index 0c230c3..73c9eff 100755 --- a/src/com/bytezone/diskbrowser/gui/DiskBrowser.java +++ b/src/com/bytezone/diskbrowser/gui/DiskBrowser.java @@ -160,7 +160,7 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi @Override public void quit (Preferences preferences) { - windowSaver = new WindowSaver (prefs, this, "DiskBrowser"); + // windowSaver = new WindowSaver (prefs, this, "DiskBrowser"); windowSaver.saveWindow (); } diff --git a/src/com/bytezone/diskbrowser/gui/WindowSaver.java b/src/com/bytezone/diskbrowser/gui/WindowSaver.java index 51aa26a..f9e3bda 100644 --- a/src/com/bytezone/diskbrowser/gui/WindowSaver.java +++ b/src/com/bytezone/diskbrowser/gui/WindowSaver.java @@ -24,8 +24,8 @@ public class WindowSaver prefs.putInt (key + "Y", frame.getY ()); prefs.putInt (key + "Height", frame.getHeight ()); prefs.putInt (key + "Width", frame.getWidth ()); - System.out.printf ("Saving x:%d, y:%d, w:%d, h:%d%n", frame.getX (), frame.getY (), - frame.getWidth (), frame.getHeight ()); + // System.out.printf ("Saving x:%d, y:%d, w:%d, h:%d%n", frame.getX (), frame.getY (), + // frame.getWidth (), frame.getHeight ()); } public boolean restoreWindow () @@ -42,17 +42,17 @@ public class WindowSaver frame.setLocation (100, 100); frame.setSize (1000, 600); frame.setLocationRelativeTo (null); // centre - System.out.printf ("Creating x:%d, y:%d, w:%d, h:%d%n", x, y, width, height); + // System.out.printf ("Creating x:%d, y:%d, w:%d, h:%d%n", x, y, width, height); return false; } - System.out.printf ("w:%d, sw:%f%n", width, screen.getWidth ()); + // System.out.printf ("w:%d, sw:%f%n", width, screen.getWidth ()); if (width > screen.getWidth () - 15) width = (int) (screen.getWidth () - 15); frame.setSize (width, height); frame.setLocation (x, y); - System.out.printf ("Restoring x:%d, y:%d, w:%d, h:%d%n", x, y, width, height); + // System.out.printf ("Restoring x:%d, y:%d, w:%d, h:%d%n", x, y, width, height); return true; } diff --git a/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java b/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java index 32fe787..af79c55 100644 --- a/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java +++ b/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java @@ -39,7 +39,7 @@ abstract class CatalogEntry implements AppleFileSource { if (i >= 280) { - System.out.printf ("CatalogEntry: block >= 280%n"); + System.out.printf ("CatalogEntry: block %04X >= 280%n", i); break; } blocks.add (disk.getDiskAddress (i)); diff --git a/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java b/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java index 3680d84..b0f1533 100644 --- a/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java +++ b/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java @@ -54,9 +54,9 @@ class PascalCatalogSector extends AbstractSector addTextAndDecimal (text, buffer, ptr + 2, 2, "File's last block"); int type = buffer[ptr + 4] & 0x0F; if (type < fileTypes.length) - addText (text, buffer, ptr + 4, 2, "File type : " + fileTypes[type]); + addText (text, buffer, ptr + 4, 1, "File type : " + fileTypes[type]); int wildcard = buffer[ptr + 4] & 0xC0; - addText (text, buffer, ptr + 4, 2, "Wildcard : " + wildcard); + addText (text, buffer, ptr + 5, 1, "Wildcard : " + wildcard); name = HexFormatter.getPascalString (buffer, ptr + 6); addText (text, buffer, ptr + 6, 4, ""); addText (text, buffer, ptr + 10, 4, ""); diff --git a/src/com/bytezone/diskbrowser/pascal/PascalDisk.java b/src/com/bytezone/diskbrowser/pascal/PascalDisk.java index 4815c6f..293dbfc 100755 --- a/src/com/bytezone/diskbrowser/pascal/PascalDisk.java +++ b/src/com/bytezone/diskbrowser/pascal/PascalDisk.java @@ -132,12 +132,12 @@ public class PascalDisk extends AbstractFormattedDisk disk.setInterleave (1); // should only ever be Prodos if (checkFormat (disk, debug)) return true; - - disk.setInterleave (0); - if (checkFormat (disk, debug)) - return true; - disk.setInterleave (3); - return checkFormat (disk, debug); + return false; + // disk.setInterleave (0); + // if (checkFormat (disk, debug)) + // return true; + // disk.setInterleave (3); + // return checkFormat (disk, debug); } public static boolean checkFormat (AppleDisk disk, boolean debug) diff --git a/src/com/bytezone/diskbrowser/utilities/Utility.java b/src/com/bytezone/diskbrowser/utilities/Utility.java index f38cb47..d2cbf99 100644 --- a/src/com/bytezone/diskbrowser/utilities/Utility.java +++ b/src/com/bytezone/diskbrowser/utilities/Utility.java @@ -25,4 +25,36 @@ public class Utility return g.getFontRenderContext ().getTransform () .equals (AffineTransform.getScaleInstance (2.0, 2.0)); } + + public static void find (byte[] buffer, byte[] key) + { + System.out.println ("*********** searching ************"); + // System.out.println (HexFormatter.format (buffer)); + for (int i = 0; i < buffer.length; i++) + { + // System.out.printf ("%02X %02X%n", buffer[i], key[0]); + if (buffer[i] == key[0]) + { + // System.out.println ("**** checking first ****"); + if (matches (buffer, i, key)) + System.out.printf ("Matches at %04X%n", i); + } + } + } + + private static boolean matches (byte[] buffer, int offset, byte[] key) + { + int ptr = 0; + while (offset < buffer.length && ptr < key.length) + { + if (buffer[offset++] != key[ptr++]) + { + // System.out.printf ("%04X: %02X != %02X%n", offset, buffer[offset], key[ptr]); + return false; + } + // System.out.printf ("%04X: %02X == %02X%n", offset, buffer[offset - 1], + // key[ptr - 1]); + } + return true; + } } \ No newline at end of file