From 7bb9fbf2e32c827c20febadfe022ae33f5f935bd Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Fri, 29 Jul 2016 22:28:11 +1000 Subject: [PATCH] merge after laptop repair --- .../diskbrowser/applefile/BasicProgram.java | 222 ++++++++++++------ .../applefile/IntegerBasicProgram.java | 42 ++-- .../diskbrowser/applefile/PascalSegment.java | 36 ++- .../bytezone/diskbrowser/disk/AppleDisk.java | 28 +-- .../diskbrowser/disk/DiskFactory.java | 23 +- .../bytezone/diskbrowser/gui/DataPanel.java | 2 +- .../bytezone/diskbrowser/gui/DiskBrowser.java | 5 +- .../diskbrowser/gui/DiskLayoutImage.java | 22 +- .../diskbrowser/gui/DiskLayoutPanel.java | 63 +++-- .../diskbrowser/gui/DiskLegendPanel.java | 19 +- .../bytezone/diskbrowser/gui/MenuHandler.java | 2 + .../diskbrowser/gui/RetinaAction.java | 27 +++ .../bytezone/diskbrowser/gui/ScrollRuler.java | 25 +- .../diskbrowser/pascal/PascalDisk.java | 22 +- .../diskbrowser/utilities/Utility.java | 19 ++ .../wizardry/WizardryScenarioDisk.java | 48 ++-- 16 files changed, 383 insertions(+), 222 deletions(-) create mode 100644 src/com/bytezone/diskbrowser/gui/RetinaAction.java create mode 100644 src/com/bytezone/diskbrowser/utilities/Utility.java diff --git a/src/com/bytezone/diskbrowser/applefile/BasicProgram.java b/src/com/bytezone/diskbrowser/applefile/BasicProgram.java index dfdf1be..5fe4dab 100644 --- a/src/com/bytezone/diskbrowser/applefile/BasicProgram.java +++ b/src/com/bytezone/diskbrowser/applefile/BasicProgram.java @@ -13,9 +13,11 @@ public class BasicProgram extends AbstractFile private static final byte ASCII_QUOTE = 0x22; private static final byte ASCII_COLON = 0x3A; private static final byte ASCII_SEMI_COLON = 0x3B; + private static final byte ASCII_CARET = 0x5E; private static final byte TOKEN_FOR = (byte) 0x81; private static final byte TOKEN_NEXT = (byte) 0x82; + private static final byte TOKEN_INPUT = (byte) 0x84; private static final byte TOKEN_LET = (byte) 0xAA; private static final byte TOKEN_GOTO = (byte) 0xAB; private static final byte TOKEN_IF = (byte) 0xAD; @@ -30,13 +32,13 @@ public class BasicProgram extends AbstractFile private final Set gotoLines = new HashSet (); private final Set gosubLines = new HashSet (); - boolean splitRem = false; // should be a user preference - boolean alignAssign = true; // should be a user preference - boolean showTargets = true; // should be a user preference - boolean showHeader = true; // should be a user preference - boolean onlyShowTargetLineNumbers = false; // should be a user preference - int wrapPrintAt = 40; - int wrapRemAt = 60; + private final boolean splitRem = false; // should be a user preference + private final boolean alignAssign = true; // should be a user preference + private final boolean showTargets = true; // should be a user preference + private final boolean showHeader = true; // should be a user preference + private final boolean onlyShowTargetLineNumbers = false; // should be a user preference + private final int wrapPrintAt = 40; + private final int wrapRemAt = 60; public BasicProgram (String name, byte[] buffer) { @@ -110,8 +112,7 @@ public class BasicProgram extends AbstractFile fullText.deleteCharAt (fullText.length () - 1); // remove newline fullText.append (" "); } - // ... otherwise do all the indenting and showing of targets etc. - else + else // ... otherwise do all the indenting and showing of targets etc. { // Prepare target indicators for subsequent sublines (ie no line number) if (showTargets && !subline.isFirst ()) @@ -133,41 +134,69 @@ public class BasicProgram extends AbstractFile int pos = subline.is (TOKEN_REM) ? 0 : alignPos; String lineText = subline.getAlignedText (pos); - // if (subline.is (TOKEN_REM) && lineText.length () > wrapRemAt + 4) - // { - // System.out.println (subline.getAlignedText (pos)); - // String copy = lineText.substring (4); - // text.append ("REM "); - // int inset = text.length (); - // System.out.println (inset); - // List remarks = splitRemark (copy, wrapRemAt); - // for (String remark : remarks) - // text.append (" ".substring (0, inset) + remark); - // } - // else - text.append (lineText); - - // Check for a wrapable PRINT statement (see FROM MACHINE LANGUAGE TO BASIC on DOSToolkit2eB.dsk) - if (subline.is (TOKEN_PRINT) && wrapPrintAt > 0 - && countChars (text, ASCII_QUOTE) == 2 - && countChars (text, ASCII_SEMI_COLON) == 0) + // Check for a wrappable REM statement + // (see SEA BATTLE on DISK283.DSK) + if (subline.is (TOKEN_REM) && lineText.length () > wrapRemAt + 4) { - int first = text.indexOf ("\""); - int last = text.indexOf ("\"", first + 1); - if ((last - first) > wrapPrintAt) + // System.out.println (subline.getAlignedText (pos)); + String copy = lineText.substring (4); + text.append ("REM "); + int inset = text.length (); + // System.out.println (inset); + List remarks = splitRemark (copy, wrapRemAt); + for (String remark : remarks) + text.append (" ".substring (0, inset) + remark); + } + else + text.append (lineText); + + // Check for a wrappable PRINT statement + // (see FROM MACHINE LANGUAGE TO BASIC on DOSToolkit2eB.dsk) + if (wrapPrintAt > 0 && (subline.is (TOKEN_PRINT) || subline.is (TOKEN_INPUT)) + && countChars (text, ASCII_QUOTE) == 2 // just start and end quotes + && countChars (text, ASCII_CARET) == 0) // no control characters + // && countChars (text, ASCII_SEMI_COLON) == 0) + { + if (true) // new method { - int ptr = first + wrapPrintAt; - do + List lines = splitPrint (lineText); + if (lines != null) { - fullText.append (text.substring (0, ptr) - + "\n ".substring (0, first + 1)); - text.delete (0, ptr); - ptr = wrapPrintAt; - } while (text.length () > wrapPrintAt); + int offset = text.indexOf ("PRINT"); + if (offset < 0) + offset = text.indexOf ("INPUT"); + String fmt = "%-" + offset + "." + offset + "s%s%n"; + String padding = text.substring (0, offset); + for (String s : lines) + { + fullText.append (String.format (fmt, padding, s)); + padding = ""; + } + } + else + fullText.append (text + "\n"); + } + else // old method + { + int first = text.indexOf ("\"") + 1; + int last = text.indexOf ("\"", first + 1) - 1; + if ((last - first) > wrapPrintAt) + { + int ptr = first + wrapPrintAt; + do + { + fullText.append (text.substring (0, ptr) + + "\n ".substring (0, first + 1)); + text.delete (0, ptr); + ptr = wrapPrintAt; + } while (text.length () > wrapPrintAt); + } + fullText.append (text + "\n"); } } + else + fullText.append (text + "\n"); - fullText.append (text + "\n"); text.setLength (0); // Calculate indent changes that take effect after the current subline @@ -180,15 +209,58 @@ public class BasicProgram extends AbstractFile } } - // Reset the alignment value if we just left an IF - the indentation will be different now. + // Reset alignment value if we just left an IF - the indentation will be different now. if (ifIndent > 0) alignPos = 0; } - fullText.deleteCharAt (fullText.length () - 1); // remove last newline + fullText.deleteCharAt (fullText.length () - 1); // remove last newline return fullText.toString (); } + private List splitPrint (String line) + { + int first = line.indexOf ("\"") + 1; + int last = line.indexOf ("\"", first + 1) - 1; + + if (first != 7 || (last - first) <= wrapPrintAt) + return null; + + int charsLeft = last - first + 1; + + List lines = new ArrayList (); + String padding = line.substring (0, 7); + line = line.substring (7); + String sub; + while (true) + { + if (line.length () >= wrapPrintAt) + { + sub = line.substring (0, wrapPrintAt); + line = line.substring (wrapPrintAt); + } + else + { + sub = line; + line = ""; + } + + String subline = padding + sub; + charsLeft -= wrapPrintAt; + + if (charsLeft > 0) + lines.add (subline); + else + { + lines.add (subline + line); + break; + } + padding = " "; + } + + return lines; + } + private List splitRemark (String remark, int wrapLength) { List remarks = new ArrayList (); @@ -197,14 +269,14 @@ public class BasicProgram extends AbstractFile int max = Math.min (wrapLength, remark.length () - 1); while (max > 0 && remark.charAt (max) != ' ') --max; - System.out.println (remark.substring (0, max)); + // System.out.println (remark.substring (0, max)); remarks.add (remark.substring (0, max) + "\n"); if (max == 0) break; remark = remark.substring (max + 1); } remarks.add (remark); - System.out.println (remark); + // System.out.println (remark); return remarks; } @@ -252,7 +324,7 @@ public class BasicProgram extends AbstractFile currentAlignPosition = findHighest (subline); // examine following sublines for alignment return currentAlignPosition; } - return 0; // reset it + return 0; // reset it } // The IF processing is so that any assignment that is being aligned doesn't continue @@ -409,44 +481,56 @@ public class BasicProgram extends AbstractFile while ((b = buffer[ptr++]) != 0) { + if (inRemark) // cannot terminate a REM + continue; + + if (inString) + { + if (b == ASCII_QUOTE) // terminate string + inString = false; + continue; + } + switch (b) { // break IF statements into two sublines (allows for easier line indenting) case TOKEN_IF: - if (!inString && !inRemark) - { - // skip to THEN or GOTO - if not found then it's an error - while (buffer[ptr] != TOKEN_THEN && buffer[ptr] != TOKEN_GOTO - && buffer[ptr] != 0) - ptr++; + // skip to THEN or GOTO - if not found then it's an error + while (buffer[ptr] != TOKEN_THEN && buffer[ptr] != TOKEN_GOTO + && buffer[ptr] != 0) + ptr++; - // keep THEN with the IF - if (buffer[ptr] == TOKEN_THEN) - ++ptr; + // keep THEN with the IF + if (buffer[ptr] == TOKEN_THEN) + ++ptr; + + // create subline from the condition (and THEN if it exists) + sublines.add (new SubLine (this, startPtr, ptr - startPtr)); + startPtr = ptr; - // create subline from the condition (and THEN if it exists) - sublines.add (new SubLine (this, startPtr, ptr - startPtr)); - startPtr = ptr; - } break; // end of subline, so add it, advance startPtr and continue case ASCII_COLON: - if (!inString && !inRemark) - { - sublines.add (new SubLine (this, startPtr, ptr - startPtr)); - startPtr = ptr; - } + sublines.add (new SubLine (this, startPtr, ptr - startPtr)); + startPtr = ptr; break; case TOKEN_REM: - if (!inString && !inRemark) + if (ptr != startPtr + 1) // REM appears mid-line (should follow a colon) + { + System.out.println ("mid-line REM token"); + // System.out.println (HexFormatter.format (buffer, startPtr, 10)); + sublines.add (new SubLine (this, startPtr, (ptr - startPtr) - 1)); + startPtr = ptr - 1; + } + else inRemark = true; + break; case ASCII_QUOTE: - if (!inRemark) - inString = !inString; + inString = true; break; } } @@ -476,7 +560,7 @@ public class BasicProgram extends AbstractFile this.length = length; byte b = buffer[startPtr]; - if ((b & 0x80) > 0) // token + if ((b & 0x80) > 0) // token { switch (b) { @@ -487,7 +571,7 @@ public class BasicProgram extends AbstractFile break; case TOKEN_NEXT: - if (length == 2) // no variables + if (length == 2) // no variables nextVariables = new String[0]; else { @@ -521,6 +605,7 @@ public class BasicProgram extends AbstractFile } catch (NumberFormatException e) { + System.out.println (HexFormatter.format (buffer, startPtr + 1, length - 2)); System.out.println ("Error parsing : GOSUB " + target2 + " in " + parent.lineNumber); } @@ -539,9 +624,12 @@ public class BasicProgram extends AbstractFile } catch (NumberFormatException e) { + System.out.printf ("b: %d, start: %d, length: %d%n", b, startPtr, + (length - 1)); System.out.println (target); System.out.println (HexFormatter.format (buffer, startPtr, length - 1)); - System.out.println (e.toString ()); + System.out.println (e); + assert false; } } else if (alignAssign) diff --git a/src/com/bytezone/diskbrowser/applefile/IntegerBasicProgram.java b/src/com/bytezone/diskbrowser/applefile/IntegerBasicProgram.java index c7308f7..e073e04 100755 --- a/src/com/bytezone/diskbrowser/applefile/IntegerBasicProgram.java +++ b/src/com/bytezone/diskbrowser/applefile/IntegerBasicProgram.java @@ -5,18 +5,17 @@ import com.bytezone.diskbrowser.utilities.HexFormatter; public class IntegerBasicProgram extends AbstractFile { private static String[] tokens = - { "?", "?", "?", " : ", "?", "?", "?", "?", "?", "?", "?", "?", "CLR", "?", "?", - "?", "HIMEM: ", "LOMEM: ", " + ", " - ", " * ", " / ", " = ", " # ", " >= ", - " > ", " <= ", " <> ", " < ", " AND ", " OR ", " MOD ", "^", "+", "(", ",", - " THEN ", " THEN ", ",", ",", "\"", "\"", "(", "!", "!", "(", "PEEK ", "RND ", - "SGN", "ABS", "PDL", "RNDX", "(", "+", "-", "NOT ", "(", "=", "#", "LEN(", "ASC(", - "SCRN(", ",", "(", "$", "$", "(", ", ", ",", ";", ";", ";", ",", ",", ",", "TEXT", - "GR ", "CALL ", "DIM ", "DIM ", "TAB ", "END", "INPUT ", "INPUT ", "INPUT ", - "FOR ", " = ", " TO ", " STEP ", "NEXT ", ",", "RETURN", "GOSUB ", "REM ", "LET ", - "GOTO ", "IF ", "PRINT ", "PRINT ", "PRINT", "POKE ", ",", "COLOR=", "PLOT", ",", - "HLIN", ",", " AT ", "VLIN ", ",", " AT ", "VTAB ", " = ", " = ", ")", ")", - "LIST ", ",", "LIST ", "POP ", "NODSP ", "NODSP ", "NOTRACE ", "DSP ", "DSP ", - "TRACE ", "PR#", "IN#", }; + { "?", "?", "?", " : ", "?", "?", "?", "?", "?", "?", "?", "?", "CLR", "?", "?", "?", + "HIMEM: ", "LOMEM: ", " + ", " - ", " * ", " / ", " = ", " # ", " >= ", " > ", + " <= ", " <> ", " < ", " AND ", " OR ", " MOD ", "^", "+", "(", ",", " THEN ", + " THEN ", ",", ",", "\"", "\"", "(", "!", "!", "(", "PEEK ", "RND ", "SGN", "ABS", + "PDL", "RNDX", "(", "+", "-", "NOT ", "(", "=", "#", "LEN(", "ASC(", "SCRN(", ",", + "(", "$", "$", "(", ", ", ",", ";", ";", ";", ",", ",", ",", "TEXT", "GR ", "CALL ", + "DIM ", "DIM ", "TAB ", "END", "INPUT ", "INPUT ", "INPUT ", "FOR ", " = ", " TO ", + " STEP ", "NEXT ", ",", "RETURN", "GOSUB ", "REM ", "LET ", "GOTO ", "IF ", "PRINT ", + "PRINT ", "PRINT", "POKE ", ",", "COLOR=", "PLOT", ",", "HLIN", ",", " AT ", "VLIN ", + ",", " AT ", "VTAB ", " = ", " = ", ")", ")", "LIST ", ",", "LIST ", "POP ", + "NODSP ", "NODSP ", "NOTRACE ", "DSP ", "DSP ", "TRACE ", "PR#", "IN#", }; public IntegerBasicProgram (String name, byte[] buffer) { @@ -28,8 +27,8 @@ public class IntegerBasicProgram extends AbstractFile { StringBuilder pgm = new StringBuilder (); pgm.append ("Name : " + name + "\n"); - pgm.append ("Length : $" + HexFormatter.format4 (buffer.length) + " (" - + buffer.length + ")\n\n"); + pgm.append ("Length : $" + HexFormatter.format4 (buffer.length) + " (" + buffer.length + + ")\n\n"); int ptr = 0; boolean looksLikeAssembler = checkForAssembler (); // this can probably go @@ -118,6 +117,11 @@ public class IntegerBasicProgram extends AbstractFile private boolean checkForSCAssembler () { + if (buffer.length == 0) + { + System.out.println ("Empty buffer array"); + return false; + } int lineLength = HexFormatter.intValue (buffer[0]); if (lineLength <= 0) return false; @@ -127,7 +131,7 @@ public class IntegerBasicProgram extends AbstractFile private void appendSCAssembler (StringBuilder pgm, int ptr, int lineLength) { int lineNumber = HexFormatter.intValue (buffer[ptr + 2]) * 256 - + HexFormatter.intValue (buffer[ptr + 1]); + + HexFormatter.intValue (buffer[ptr + 1]); pgm.append (String.format ("%4d: ", lineNumber)); int p2 = ptr + 3; while (buffer[p2] != 0) @@ -167,15 +171,15 @@ public class IntegerBasicProgram extends AbstractFile int b = HexFormatter.intValue (buffer[p]); if (b == 0x03 // token for colon (:) - && !inString && !inRemark && buffer[p + 1] != 1) // not end of line + && !inString && !inRemark && buffer[p + 1] != 1) // not end of line { pgm.append (":\n" + " ".substring (0, lineTab)); continue; } if (b >= 0xB0 && b <= 0xB9 // numeric literal - && (buffer[p - 1] & 0x80) == 0 // not a variable name - && !inString && !inRemark) + && (buffer[p - 1] & 0x80) == 0 // not a variable name + && !inString && !inRemark) { pgm.append (HexFormatter.intValue (buffer[p + 1], buffer[p + 2])); p += 2; @@ -213,7 +217,7 @@ public class IntegerBasicProgram extends AbstractFile pgm.append ("Name : " + name + "\n"); pgm.append ("Length : $" + HexFormatter.format4 (buffer.length) + " (" + buffer.length - + ")\n\n"); + + ")\n\n"); int ptr = 0; diff --git a/src/com/bytezone/diskbrowser/applefile/PascalSegment.java b/src/com/bytezone/diskbrowser/applefile/PascalSegment.java index ebf101b..90ce86c 100755 --- a/src/com/bytezone/diskbrowser/applefile/PascalSegment.java +++ b/src/com/bytezone/diskbrowser/applefile/PascalSegment.java @@ -33,15 +33,15 @@ public class PascalSegment extends AbstractFile implements PascalConstants 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]); + segKind = + HexFormatter.intValue (fullBuffer[0xC0 + seq * 2], fullBuffer[0xC0 + seq * 2 + 1]); + textAddress = + HexFormatter.intValue (fullBuffer[0xE0 + seq * 2], fullBuffer[0xE0 + seq * 2 + 1]); int flags = fullBuffer[0x101 + seq * 2] & 0xFF; machineType = flags & 0x0F; version = (flags & 0xD0) >> 5; - intrinsSegs1 = HexFormatter.intValue (fullBuffer[0x120 + seq * 4], - fullBuffer[0x120 + seq * 4 + 1]); + intrinsSegs1 = + HexFormatter.intValue (fullBuffer[0x120 + seq * 4], fullBuffer[0x120 + seq * 4 + 1]); intrinsSegs2 = HexFormatter.intValue (fullBuffer[0x120 + seq * 4 + 2], fullBuffer[0x120 + seq * 4 + 3]); @@ -57,7 +57,7 @@ public class PascalSegment extends AbstractFile implements PascalConstants System.out.printf ("Zero segment header in %s seq %d%n", name, seq); else if (segmentNoBody != segmentNoHeader) System.out.println ("Segment number mismatch : " + segmentNoBody + " / " - + segmentNoHeader); + + segmentNoHeader); } else { @@ -76,10 +76,10 @@ 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", - slot, blockNo, size, size, name, SegmentKind[segKind], textAddress, - segmentNoHeader, machineType, version, intrinsSegs1, intrinsSegs2); + return String.format ( + " %2d %02X %04X %,6d %-8s %-15s %3d %3d %d %d %d %d", + slot, blockNo, size, size, name, SegmentKind[segKind], textAddress, + segmentNoHeader, machineType, version, intrinsSegs1, intrinsSegs2); } @Override @@ -91,9 +91,9 @@ public class PascalSegment extends AbstractFile implements PascalConstants StringBuilder text = new StringBuilder (); String title = "Segment - " + name; text.append (title + "\n" - + "===============================".substring (0, title.length ()) + "\n\n"); + + "===============================".substring (0, title.length ()) + "\n\n"); String warning = - segmentNoBody == segmentNoHeader ? "" : " (" + segmentNoHeader + " in header)"; + segmentNoBody == segmentNoHeader ? "" : " (" + segmentNoHeader + " in header)"; 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)); @@ -116,12 +116,11 @@ public class PascalSegment extends AbstractFile implements PascalConstants int address = size - procedure.slot * 2 - 2; text.append (String.format ( " %2d %04X %3d %04X %04X %04X " - + "%04X (%04X - %04X = %04X)%n", + + "%04X (%04X - %04X = %04X)%n", procedure.procedureNo, procedure.offset, procedure.procLevel, procedure.codeStart, - procedure.codeEnd, procedure.parmSize, - procedure.dataSize, address, procedure.offset, - procedure.procOffset)); + procedure.codeEnd, procedure.parmSize, procedure.dataSize, + address, procedure.offset, procedure.procOffset)); } else text.append (String.format (" %2d %04X%n", procedure.slot, procedure.offset)); @@ -132,8 +131,7 @@ public class PascalSegment extends AbstractFile implements PascalConstants { List strings = pp.extractStrings (); for (PascalCodeStatement cs : strings) - text.append (String.format (" %2d %04X %s%n", pp.procedureNo, cs.ptr, - cs.text)); + text.append (String.format (" %2d %04X %s%n", pp.procedureNo, cs.ptr, cs.text)); } for (PascalProcedure procedure : procedures) diff --git a/src/com/bytezone/diskbrowser/disk/AppleDisk.java b/src/com/bytezone/diskbrowser/disk/AppleDisk.java index bb376bb..f307634 100755 --- a/src/com/bytezone/diskbrowser/disk/AppleDisk.java +++ b/src/com/bytezone/diskbrowser/disk/AppleDisk.java @@ -35,10 +35,10 @@ public class AppleDisk implements Disk private int interleave = 0; private static int[][] interleaveSector = // - { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // Dos - { 0, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15 }, // Prodos - { 0, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2, 15 }, // Infocom - { 0, 6, 12, 3, 9, 15, 14, 5, 11, 2, 8, 7, 13, 4, 10, 1 } }; // CPM + { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // Dos + { 0, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15 }, // Prodos + { 0, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2, 15 }, // Infocom + { 0, 6, 12, 3, 9, 15, 14, 5, 11, 2, 8, 7, 13, 4, 10, 1 } }; // CPM // Info from http://www.applelogic.org/TheAppleIIEGettingStarted.html // Block: 0 1 2 3 4 5 6 7 8 9 A B C D E F @@ -82,7 +82,7 @@ public class AppleDisk implements Disk int skip = 0; if ((pos > 0 && name.substring (pos + 1).equalsIgnoreCase ("2mg")) - || "2IMG".equals (prefix)) + || "2IMG".equals (prefix)) // if ("2IMG".equals (prefix)) { if (debug) @@ -368,11 +368,12 @@ public class AppleDisk implements Disk @Override public DiskAddress getDiskAddress (int block) { + // assert (isValidAddress (block)) : "Invalid address : " + block; if (!isValidAddress (block)) { System.out.println ("Invalid block : " + block); - // return null; - return new AppleDiskAddress (this, 0); + return null; + // return new AppleDiskAddress (this, 0); this was looping 26/07/2016 } return new AppleDiskAddress (this, block); } @@ -394,8 +395,7 @@ public class AppleDisk implements Disk public DiskAddress getDiskAddress (int track, int sector) { // should this return null for invalid addresses? - assert (isValidAddress (track, sector)) : "Invalid address : " + track + ", " - + sector; + assert (isValidAddress (track, sector)) : "Invalid address : " + track + ", " + sector; return new AppleDiskAddress (this, track, sector); } @@ -438,22 +438,22 @@ public class AppleDisk implements Disk assert da.getDisk () == this : "Disk address not applicable to this disk"; assert sectorSize == 256 || sectorSize == 512 : "Invalid sector size : " + sectorSize; assert interleave >= 0 && interleave <= MAX_INTERLEAVE : "Invalid interleave : " - + interleave; + + interleave; if (sectorSize == 256) { int diskOffset = da.getTrack () * trackSize - + interleaveSector[interleave][da.getSector ()] * sectorSize; + + interleaveSector[interleave][da.getSector ()] * sectorSize; System.arraycopy (diskBuffer, diskOffset, buffer, bufferOffset, sectorSize); } else if (sectorSize == 512) { int diskOffset = da.getTrack () * trackSize - + interleaveSector[interleave][da.getSector () * 2] * 256; + + interleaveSector[interleave][da.getSector () * 2] * 256; System.arraycopy (diskBuffer, diskOffset, buffer, bufferOffset, 256); diskOffset = da.getTrack () * trackSize - + interleaveSector[interleave][da.getSector () * 2 + 1] * 256; + + interleaveSector[interleave][da.getSector () * 2 + 1] * 256; System.arraycopy (diskBuffer, diskOffset, buffer, bufferOffset + 256, 256); } } @@ -474,7 +474,7 @@ public class AppleDisk implements Disk { if (actionListenerList != null) actionListenerList - .actionPerformed (new ActionEvent (this, ActionEvent.ACTION_PERFORMED, text)); + .actionPerformed (new ActionEvent (this, ActionEvent.ACTION_PERFORMED, text)); } public AppleFileSource getDetails () diff --git a/src/com/bytezone/diskbrowser/disk/DiskFactory.java b/src/com/bytezone/diskbrowser/disk/DiskFactory.java index 161e16b..9cc3b9c 100755 --- a/src/com/bytezone/diskbrowser/disk/DiskFactory.java +++ b/src/com/bytezone/diskbrowser/disk/DiskFactory.java @@ -1,10 +1,6 @@ package com.bytezone.diskbrowser.disk; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.nio.file.Path; import java.nio.file.Paths; import java.util.zip.GZIPInputStream; @@ -155,8 +151,7 @@ public class DiskFactory long length = file.length (); if (length != 143360 && length != 116480) { - System.out.printf ("%s: invalid file length : %,d%n", file.getName (), - file.length ()); + System.out.printf ("%s: invalid file length : %,d%n", file.getName (), file.length ()); return null; } @@ -167,9 +162,9 @@ public class DiskFactory long checksum = appleDisk.getBootChecksum (); if (checksum == 3176296590L || checksum == 108825457L || checksum == 1439356606L - || checksum == 1550012074L || checksum == 1614602459L || checksum == 940889336L - || checksum == 990032697 || checksum == 2936955085L || checksum == 1348415927L - || checksum == 3340889101L || checksum == 18315788L || checksum == 993895235L) + || checksum == 1550012074L || checksum == 1614602459L || checksum == 940889336L + || checksum == 990032697 || checksum == 2936955085L || checksum == 1348415927L + || checksum == 3340889101L || checksum == 18315788L || checksum == 993895235L) { disk = checkDos (file); disk2 = checkProdos (file); @@ -185,8 +180,8 @@ public class DiskFactory disk = new DualDosDisk (disk, disk2); } - else if (checksum == 2803644711L || checksum == 3317783349L - || checksum == 1728863694L || checksum == 198094178L) + else if (checksum == 2803644711L || checksum == 3317783349L || checksum == 1728863694L + || checksum == 198094178L) disk = checkPascalDisk (file); else if (checksum == 3028642627L || checksum == 2070151659L) @@ -248,8 +243,8 @@ public class DiskFactory disk = new DataDisk (new AppleDisk (file, 35, 16)); if (debug) - System.out.println (" Factory creating disk : " - + disk.getDisk ().getFile ().getAbsolutePath ()); + System.out.println ("Factory creating disk : " + + disk.getDisk ().getFile ().getAbsolutePath ()); if (disk != null && compressed) disk.setOriginalPath (p); diff --git a/src/com/bytezone/diskbrowser/gui/DataPanel.java b/src/com/bytezone/diskbrowser/gui/DataPanel.java index a55af0a..d611843 100755 --- a/src/com/bytezone/diskbrowser/gui/DataPanel.java +++ b/src/com/bytezone/diskbrowser/gui/DataPanel.java @@ -155,7 +155,7 @@ class DataPanel extends JTabbedPane if (currentDataSource instanceof VisicalcFile) { VisicalcFile visicalcFile = (VisicalcFile) currentDataSource; - visicalcFile.setDebug (value); + VisicalcFile.setDebug (value); setText (formattedText, visicalcFile.getText ()); } } diff --git a/src/com/bytezone/diskbrowser/gui/DiskBrowser.java b/src/com/bytezone/diskbrowser/gui/DiskBrowser.java index 9209afe..7a72c6f 100755 --- a/src/com/bytezone/diskbrowser/gui/DiskBrowser.java +++ b/src/com/bytezone/diskbrowser/gui/DiskBrowser.java @@ -49,7 +49,7 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi addPanel (dataPanel, "Output", BorderLayout.CENTER); // create and add the right-hand disk layout panel - DiskLayoutPanel diskLayoutPanel = new DiskLayoutPanel (); + DiskLayoutPanel diskLayoutPanel = new DiskLayoutPanel (menuHandler, prefs); JPanel layoutBorderPanel = addPanel (diskLayoutPanel, "Disk layout", BorderLayout.EAST); @@ -100,7 +100,7 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi menuHandler.fontAction.addFontChangeListener (dataPanel); menuHandler.fontAction.addFontChangeListener (catalogPanel); - menuHandler.fontAction.addFontChangeListener (diskLayoutPanel); + // menuHandler.fontAction.addFontChangeListener (diskLayoutPanel); // set the MenuItem Actions menuHandler.printItem.setAction (print); @@ -119,6 +119,7 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi quitAction.addQuitListener (menuHandler); quitAction.addQuitListener (menuHandler.fontAction); quitAction.addQuitListener (catalogPanel); + quitAction.addQuitListener (diskLayoutPanel); quitAction.addQuitListener (this); catalogPanel.setDuplicateAction (duplicateAction); diff --git a/src/com/bytezone/diskbrowser/gui/DiskLayoutImage.java b/src/com/bytezone/diskbrowser/gui/DiskLayoutImage.java index 84a80f5..e284a46 100644 --- a/src/com/bytezone/diskbrowser/gui/DiskLayoutImage.java +++ b/src/com/bytezone/diskbrowser/gui/DiskLayoutImage.java @@ -38,6 +38,8 @@ class DiskLayoutImage extends JPanel implements Scrollable, RedoListener private int gw = 8; private int gh = 35; + private boolean retina; + public DiskLayoutImage () { setPreferredSize (new Dimension (240 + 1, 525 + 1)); @@ -76,6 +78,12 @@ class DiskLayoutImage extends JPanel implements Scrollable, RedoListener repaint (); } + public void setRetina (boolean value) + { + retina = value; + repaint (); + } + void setSelection (List sectors) { selectionHandler.setSelection (sectors); @@ -109,6 +117,8 @@ class DiskLayoutImage extends JPanel implements Scrollable, RedoListener // maxBlock = d.getTotalBlocks (); // the index error is caused by not recalculating the grid layout + Graphics2D g2d = (Graphics2D) g; + for (int y = p1.y; y <= p2.y; y += bh) for (int x = p1.x; x <= p2.x; x += bw) { @@ -116,9 +126,9 @@ class DiskLayoutImage extends JPanel implements Scrollable, RedoListener if (blockNo < maxBlock) { DiskAddress da = d.getDiskAddress (blockNo); - boolean flag = showFreeSectors && disk.isSectorFree (da); - drawBlock ((Graphics2D) g, blockNo, x, y, flag, - selectionHandler.isSelected (da)); + boolean free = showFreeSectors && disk.isSectorFree (da); + boolean selected = selectionHandler.isSelected (da); + drawBlock (g2d, blockNo, x, y, free, selected); } } } @@ -145,10 +155,10 @@ class DiskLayoutImage extends JPanel implements Scrollable, RedoListener g.setColor (type.colour); // this is weird, the retina OSX screen needs the second fillRect // see also DiskLegendPanel.paint() - if (false) - g.fillRect (rect.x + 2, rect.y + 2, rect.width - 3, rect.height - 3); - else + if (retina) g.fillRect (rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2); + else + g.fillRect (rect.x + 2, rect.y + 2, rect.width - 3, rect.height - 3); } // draw an indicator in free blocks diff --git a/src/com/bytezone/diskbrowser/gui/DiskLayoutPanel.java b/src/com/bytezone/diskbrowser/gui/DiskLayoutPanel.java index c4ff49b..8432b88 100644 --- a/src/com/bytezone/diskbrowser/gui/DiskLayoutPanel.java +++ b/src/com/bytezone/diskbrowser/gui/DiskLayoutPanel.java @@ -12,13 +12,13 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.prefs.Preferences; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JScrollPane; -import com.bytezone.common.FontAction.FontChangeEvent; -import com.bytezone.common.FontAction.FontChangeListener; +import com.bytezone.common.QuitAction.QuitListener; import com.bytezone.diskbrowser.disk.Disk; import com.bytezone.diskbrowser.disk.DiskAddress; import com.bytezone.diskbrowser.disk.DualDosDisk; @@ -26,10 +26,15 @@ import com.bytezone.diskbrowser.disk.FormattedDisk; import com.bytezone.diskbrowser.gui.RedoHandler.RedoEvent; import com.bytezone.diskbrowser.gui.RedoHandler.RedoListener; -class DiskLayoutPanel extends JPanel implements DiskSelectionListener, - FileSelectionListener, RedoListener, FontChangeListener +class DiskLayoutPanel extends JPanel + implements DiskSelectionListener, FileSelectionListener, RedoListener, QuitListener +//, FontChangeListener { - private static final int SIZE = 15; // basic unit of a display block + private static final int SIZE = 15; // basic unit of a display block + private static final String PREFS_RETINA = "retina"; + + private final Preferences prefs; + private final MenuHandler mh; private final DiskLayoutImage image; private final ScrollRuler verticalRuler; @@ -38,10 +43,13 @@ class DiskLayoutPanel extends JPanel implements DiskSelectionListener, private final JScrollPane sp; private LayoutDetails layout; - public DiskLayoutPanel () + public DiskLayoutPanel (MenuHandler mh, Preferences prefs) { super (new BorderLayout ()); + this.prefs = prefs; + this.mh = mh; + image = new DiskLayoutImage (); verticalRuler = new ScrollRuler (image, ScrollRuler.VERTICAL); horizontalRuler = new ScrollRuler (image, ScrollRuler.HORIZONTAL); @@ -64,13 +72,15 @@ class DiskLayoutPanel extends JPanel implements DiskSelectionListener, // this is just so the pack is correct add (sp, BorderLayout.CENTER); add (legendPanel, BorderLayout.SOUTH); + + mh.retinaItem.setAction (new RetinaAction (this)); } - public DiskLayoutPanel (FormattedDisk disk) - { - this (); - setDisk (disk); - } + // public DiskLayoutPanel (FormattedDisk disk) + // { + // this (); + // setDisk (disk); + // } public void setDisk (final FormattedDisk disk) { @@ -113,6 +123,12 @@ class DiskLayoutPanel extends JPanel implements DiskSelectionListener, repaint (); } + public void setRetina (boolean value) + { + image.setRetina (value); + legendPanel.setRetina (value); + } + public void setHex (boolean hex) { verticalRuler.setHex (hex); @@ -192,9 +208,9 @@ class DiskLayoutPanel extends JPanel implements DiskSelectionListener, Color backgroundColor = Color.WHITE; boolean showHex = true; - public Corner (boolean click) + public Corner (boolean allowClick) { - if (click) + if (allowClick) addMouseListener (new MouseAdapter () { @Override @@ -240,10 +256,23 @@ class DiskLayoutPanel extends JPanel implements DiskSelectionListener, } @Override - public void changeFont (FontChangeEvent e) + public void quit (Preferences arg0) { - verticalRuler.changeFont (e.font); - horizontalRuler.changeFont (e.font); - legendPanel.changeFont (e.font); + prefs.putBoolean (PREFS_RETINA, mh.retinaItem.isSelected ()); } + + @Override + public void restore (Preferences arg0) + { + mh.retinaItem.setSelected (prefs.getBoolean (PREFS_RETINA, false)); + setRetina (mh.retinaItem.isSelected ()); + } + + // @Override + // public void changeFont (FontChangeEvent e) + // { + // // verticalRuler.changeFont (e.font); + // // horizontalRuler.changeFont (e.font); + // // legendPanel.changeFont (e.font); + // } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/gui/DiskLegendPanel.java b/src/com/bytezone/diskbrowser/gui/DiskLegendPanel.java index cb57363..a2831ac 100644 --- a/src/com/bytezone/diskbrowser/gui/DiskLegendPanel.java +++ b/src/com/bytezone/diskbrowser/gui/DiskLegendPanel.java @@ -22,6 +22,7 @@ class DiskLegendPanel extends JPanel FormattedDisk disk; LayoutDetails layoutDetails; Font font; + private boolean retina; public DiskLegendPanel () { @@ -37,12 +38,18 @@ class DiskLegendPanel extends JPanel repaint (); } - void changeFont (Font font) + public void setRetina (boolean value) { - this.font = font; + retina = value; repaint (); } + // void changeFont (Font font) + // { + // this.font = font; + // repaint (); + // } + @Override public Dimension getPreferredSize () { @@ -73,12 +80,12 @@ class DiskLegendPanel extends JPanel // draw the colour g.setColor (type.colour); - if (false) - g.fillRect (x + 2, y + 2, layoutDetails.block.width - 3, - layoutDetails.block.height - 3); - else + if (retina) g.fillRect (x + 1, y + 1, layoutDetails.block.width - 2, layoutDetails.block.height - 2); + else + g.fillRect (x + 2, y + 2, layoutDetails.block.width - 3, + layoutDetails.block.height - 3); // draw the text g.setColor (Color.BLACK); diff --git a/src/com/bytezone/diskbrowser/gui/MenuHandler.java b/src/com/bytezone/diskbrowser/gui/MenuHandler.java index d179ce8..36f4b55 100755 --- a/src/com/bytezone/diskbrowser/gui/MenuHandler.java +++ b/src/com/bytezone/diskbrowser/gui/MenuHandler.java @@ -64,6 +64,7 @@ public class MenuHandler JMenuItem colourQuirksItem = new JCheckBoxMenuItem ("Colour quirks"); JMenuItem monochromeItem = new JCheckBoxMenuItem ("Monochrome"); JMenuItem debuggingItem = new JCheckBoxMenuItem ("Debugging"); + JMenuItem retinaItem = new JCheckBoxMenuItem ("Retina display"); public MenuHandler (Preferences prefs) { @@ -122,6 +123,7 @@ public class MenuHandler formatMenu.add (colourQuirksItem); formatMenu.add (monochromeItem); formatMenu.add (debuggingItem); + formatMenu.add (retinaItem); helpMenu.add (new JMenuItem (new EnvironmentAction ())); diff --git a/src/com/bytezone/diskbrowser/gui/RetinaAction.java b/src/com/bytezone/diskbrowser/gui/RetinaAction.java new file mode 100644 index 0000000..6584efd --- /dev/null +++ b/src/com/bytezone/diskbrowser/gui/RetinaAction.java @@ -0,0 +1,27 @@ +package com.bytezone.diskbrowser.gui; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JMenuItem; + +public class RetinaAction extends AbstractAction +{ + private final DiskLayoutPanel owner; + + public RetinaAction (DiskLayoutPanel owner) + { + super ("Retina display"); + putValue (Action.SHORT_DESCRIPTION, "use hi resolution graphics"); + // putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt G")); + // putValue (Action.MNEMONIC_KEY, KeyEvent.VK_G); + this.owner = owner; + } + + @Override + public void actionPerformed (ActionEvent e) + { + owner.setRetina (((JMenuItem) e.getSource ()).isSelected ()); + } +} \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/gui/ScrollRuler.java b/src/com/bytezone/diskbrowser/gui/ScrollRuler.java index 4e7c4d6..2b71a1c 100644 --- a/src/com/bytezone/diskbrowser/gui/ScrollRuler.java +++ b/src/com/bytezone/diskbrowser/gui/ScrollRuler.java @@ -1,10 +1,6 @@ package com.bytezone.diskbrowser.gui; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Rectangle; +import java.awt.*; import javax.swing.JComponent; @@ -22,7 +18,7 @@ class ScrollRuler extends JComponent public static final int HORIZONTAL = 0; public static final int VERTICAL = 1; - private Font font = Platform.getFont (FontType.SANS_SERIF, FontSize.BASE); + private final Font font = Platform.getFont (FontType.SANS_SERIF, FontSize.BASE); private final int orientation; private boolean isHex = true; private boolean isTrackMode = true; @@ -47,11 +43,9 @@ class ScrollRuler extends JComponent // Must match the preferred size of DiskLayoutImage if (orientation == HORIZONTAL) - setPreferredSize (new Dimension (layout.block.width * layout.grid.width + 1, - HEIGHT)); // width/height + setPreferredSize (new Dimension (layout.block.width * layout.grid.width + 1, HEIGHT)); else - setPreferredSize (new Dimension (WIDTH, - layout.block.height * layout.grid.height + 1)); + setPreferredSize (new Dimension (WIDTH, layout.block.height * layout.grid.height + 1)); setTrackMode (layout.grid.width == 16 || layout.grid.width == 13); } @@ -62,11 +56,12 @@ class ScrollRuler extends JComponent repaint (); } - public void changeFont (Font font) - { - this.font = font; - repaint (); - } + // public void changeFont (Font font) + // { + // System.out.println (font); + // this.font = font; + // repaint (); + // } public void setHex (boolean hex) { diff --git a/src/com/bytezone/diskbrowser/pascal/PascalDisk.java b/src/com/bytezone/diskbrowser/pascal/PascalDisk.java index 632e920..f6ee376 100755 --- a/src/com/bytezone/diskbrowser/pascal/PascalDisk.java +++ b/src/com/bytezone/diskbrowser/pascal/PascalDisk.java @@ -23,7 +23,7 @@ public class PascalDisk extends AbstractFormattedDisk private final PascalCatalogSector diskCatalogSector; final String[] fileTypes = - { "Volume", "Xdsk", "Code", "Text", "Info", "Data", "Graf", "Foto", "SecureDir" }; + { "Volume", "Xdsk", "Code", "Text", "Info", "Data", "Graf", "Foto", "SecureDir" }; SectorType diskBootSector = new SectorType ("Boot", Color.lightGray); SectorType catalogSector = new SectorType ("Catalog", Color.magenta); @@ -109,7 +109,7 @@ public class PascalDisk extends AbstractFormattedDisk for (PascalSegment ps : pc) { DefaultMutableTreeNode segmentNode = - new DefaultMutableTreeNode (new PascalCodeObject (this, ps, fe.firstBlock)); + new DefaultMutableTreeNode (new PascalCodeObject (this, ps, fe.firstBlock)); node.add (segmentNode); segmentNode.setAllowsChildren (false); } @@ -204,7 +204,7 @@ public class PascalDisk extends AbstractFormattedDisk if (blocks > 280) { if (debug) - System.out.printf ("Blocks: %d%n", blocks); + System.out.printf ("Blocks > 280: %d%n", blocks); return false; } @@ -254,15 +254,13 @@ public class PascalDisk extends AbstractFormattedDisk { String newLine = String.format ("%n"); String newLine2 = newLine + newLine; - String line = - "---- --------------- ---- -------- ------- ---- ----" + newLine; + String line = "---- --------------- ---- -------- ------- ---- ----" + newLine; String date = volume.date == null ? "--" : df.format (volume.date.getTime ()); StringBuilder text = new StringBuilder (); text.append ("Disk : " + disk.getFile ().getAbsolutePath () + newLine2); text.append ("Volume : " + volume.name + newLine); text.append ("Date : " + date + newLine2); - text.append ("Blks Name Type Date Length Frst Last" - + newLine); + text.append ("Blks Name Type Date Length Frst Last" + newLine); text.append (line); int usedBlocks = 6; @@ -274,13 +272,13 @@ public class PascalDisk extends AbstractFormattedDisk date = ce.date == null ? "--" : df.format (ce.date.getTime ()); int bytes = (size - 1) * 512 + ce.bytesUsedInLastBlock; text.append (String.format (" %3d %-15s %s %8s %,8d $%03X $%03X%n", size, - ce.name, fileTypes[ce.fileType], date, bytes, - ce.firstBlock, ce.lastBlock)); + ce.name, fileTypes[ce.fileType], date, bytes, ce.firstBlock, + ce.lastBlock)); } text.append (line); - text.append (String - .format ("Blocks free : %3d Blocks used : %3d Total blocks : %3d%n", - (volume.totalBlocks - usedBlocks), usedBlocks, volume.totalBlocks)); + text.append (String.format ("Blocks free : %3d Blocks used : %3d Total blocks : %3d%n", + (volume.totalBlocks - usedBlocks), usedBlocks, + volume.totalBlocks)); return new DefaultAppleFileSource (volume.name, text.toString (), this); } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/utilities/Utility.java b/src/com/bytezone/diskbrowser/utilities/Utility.java new file mode 100644 index 0000000..c59a655 --- /dev/null +++ b/src/com/bytezone/diskbrowser/utilities/Utility.java @@ -0,0 +1,19 @@ +package com.bytezone.diskbrowser.utilities; + +import java.awt.Toolkit; + +public class Utility +{ + public static boolean hasRetinaDisplay () + { + Object obj = + Toolkit.getDefaultToolkit ().getDesktopProperty ("apple.awt.contentScaleFactor"); + if (obj instanceof Float) + { + Float f = (Float) obj; + int scale = f.intValue (); + return (scale == 2); // 1 indicates a regular mac display. + } + return false; + } +} \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/wizardry/WizardryScenarioDisk.java b/src/com/bytezone/diskbrowser/wizardry/WizardryScenarioDisk.java index 1cb1335..a541a44 100755 --- a/src/com/bytezone/diskbrowser/wizardry/WizardryScenarioDisk.java +++ b/src/com/bytezone/diskbrowser/wizardry/WizardryScenarioDisk.java @@ -9,11 +9,7 @@ import javax.swing.tree.DefaultTreeModel; import com.bytezone.diskbrowser.applefile.AbstractFile; import com.bytezone.diskbrowser.applefile.AppleFileSource; -import com.bytezone.diskbrowser.disk.DefaultAppleFileSource; -import com.bytezone.diskbrowser.disk.DefaultDataSource; -import com.bytezone.diskbrowser.disk.Disk; -import com.bytezone.diskbrowser.disk.DiskAddress; -import com.bytezone.diskbrowser.disk.SectorType; +import com.bytezone.diskbrowser.disk.*; import com.bytezone.diskbrowser.gui.DataSource; import com.bytezone.diskbrowser.pascal.PascalDisk; import com.bytezone.diskbrowser.utilities.HexFormatter; @@ -97,8 +93,7 @@ public class WizardryScenarioDisk extends PascalDisk extractMonsters (linkNode ("Monsters", "Monsters string", dataNode), sectors); extractCharacters (linkNode ("Characters", "Characters string", dataNode), sectors); extractImages (linkNode ("Images", "Images string", dataNode), sectors); - extractExperienceLevels (linkNode ("Experience", "Experience string", dataNode), - sectors); + extractExperienceLevels (linkNode ("Experience", "Experience string", dataNode), sectors); // node = linkNode ("Spells", "Spells string", dataNode); node = null; extractSpells (node, sectors); @@ -117,7 +112,7 @@ public class WizardryScenarioDisk extends PascalDisk } private DefaultMutableTreeNode linkNode (String name, String text, - DefaultMutableTreeNode parent) + DefaultMutableTreeNode parent) { DefaultAppleFileSource afs = new DefaultAppleFileSource (name, text, this); DefaultMutableTreeNode node = new DefaultMutableTreeNode (afs); @@ -127,8 +122,6 @@ public class WizardryScenarioDisk extends PascalDisk public static boolean isWizardryFormat (Disk disk, boolean debug) { - if (false) - return false; byte[] buffer = disk.readSector (2); int totalFiles = HexFormatter.intValue (buffer[16], buffer[17]); if (totalFiles != 3) @@ -138,7 +131,7 @@ public class WizardryScenarioDisk extends PascalDisk { String text = HexFormatter.getPascalString (buffer, ptr); if (!text.equals ("SCENARIO.DATA") && !text.equals ("SCENARIO.MESGS") - && !text.equals ("WIZARDRY.CODE")) + && !text.equals ("WIZARDRY.CODE")) return false; } return true; @@ -194,8 +187,8 @@ public class WizardryScenarioDisk extends PascalDisk dds.text = text.toString (); } - private int addReward (byte[] buffer, List blocks, - DefaultMutableTreeNode node, int seq) + private int addReward (byte[] buffer, List blocks, DefaultMutableTreeNode node, + int seq) { int recLen = 168; for (int ptr = 0; ptr < 1008; ptr += recLen) @@ -229,9 +222,9 @@ public class WizardryScenarioDisk extends PascalDisk StringBuilder text = new StringBuilder (); text.append ("Name Age Align Race Type " - + "HP St In Pi Vi Ag Lu Status\n"); + + "HP St In Pi Vi Ag Lu Status\n"); text.append ("------------- ---- -------- -------- ---------- " - + "-- -- -- -- -- -- -- ------\n"); + + "-- -- -- -- -- -- -- ------\n"); for (Character ch : characters) { Statistics stats = ch.getStatistics (); @@ -242,8 +235,7 @@ public class WizardryScenarioDisk extends PascalDisk text.append (String.format (" %2d %2d %2d %2d %2d %2d", att.strength, att.intelligence, att.piety, att.vitality, att.agility, att.luck)); - text.append (String.format (" %5s %s%n", stats.status, - ch.isOut () ? "* OUT *" : "")); + text.append (String.format (" %5s %s%n", stats.status, ch.isOut () ? "* OUT *" : "")); } DefaultAppleFileSource afs = (DefaultAppleFileSource) node.getUserObject (); @@ -253,7 +245,7 @@ public class WizardryScenarioDisk extends PascalDisk } private void addCharacters (byte[] buffer, List blocks, - DefaultMutableTreeNode node) + DefaultMutableTreeNode node) { int recLen = 208; for (int ptr = 0; ptr < 832; ptr += recLen) @@ -306,7 +298,7 @@ public class WizardryScenarioDisk extends PascalDisk } private void addMonsters (byte[] buffer, List blocks, - DefaultMutableTreeNode node) + DefaultMutableTreeNode node) { int recLen = 158; for (int ptr = 0; ptr < 948; ptr += recLen) @@ -358,8 +350,7 @@ public class WizardryScenarioDisk extends PascalDisk dds.text = text.toString (); } - private void addItems (byte[] buffer, List blocks, - DefaultMutableTreeNode node) + private void addItems (byte[] buffer, List blocks, DefaultMutableTreeNode node) { int recLen = 78; for (int ptr = 0; ptr < 1014; ptr += recLen) @@ -532,7 +523,7 @@ public class WizardryScenarioDisk extends PascalDisk } AbstractImage mi = scenarioHeader.scenarioID < 3 ? new Image (name, buffer) - : new ImageV2 (name, exactBuffer); + : new ImageV2 (name, exactBuffer); images.add (mi); addToNode (mi, node, da, imageSector); } @@ -547,8 +538,7 @@ public class WizardryScenarioDisk extends PascalDisk dds.text = text.toString (); } - private void extractExperienceLevels (DefaultMutableTreeNode node, - List sectors) + private void extractExperienceLevels (DefaultMutableTreeNode node, List sectors) { List nodeSectors = new ArrayList (); ScenarioData sd = scenarioHeader.data.get (Header.EXPERIENCE_AREA); @@ -579,7 +569,7 @@ public class WizardryScenarioDisk extends PascalDisk } private void addToNode (AbstractFile af, DefaultMutableTreeNode node, DiskAddress block, - SectorType type) + SectorType type) { ArrayList blocks = new ArrayList (1); blocks.add (block); @@ -587,17 +577,15 @@ public class WizardryScenarioDisk extends PascalDisk } private void addToNode (AbstractFile af, DefaultMutableTreeNode node, - List blocks, SectorType type) + List blocks, SectorType type) { - DefaultAppleFileSource dafs = - new DefaultAppleFileSource (af.getName (), af, this, blocks); + DefaultAppleFileSource dafs = new DefaultAppleFileSource (af.getName (), af, this, blocks); DefaultMutableTreeNode childNode = new DefaultMutableTreeNode (dafs); node.add (childNode); childNode.setAllowsChildren (false); } - private List getTwoBlocks (ScenarioData sd, int i, - List sectors) + private List getTwoBlocks (ScenarioData sd, int i, List sectors) { ArrayList blocks = new ArrayList (2); blocks.add (sectors.get (sd.dataOffset + i * 2));