From f782427d7445b7ef04a12f3d1c305c1cd591b07c Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Mon, 12 Jun 2017 19:09:19 +1000 Subject: [PATCH] tidying --- .../diskbrowser/applefile/BasicProgram.java | 20 ++++++--- .../applefile/OriginalHiResImage.java | 8 ++-- .../diskbrowser/disk/AbstractSector.java | 19 ++++---- .../diskbrowser/disk/DiskFactory.java | 3 +- .../diskbrowser/dos/DosVTOCSector.java | 8 ++++ .../diskbrowser/gui/DiskLegendPanel.java | 4 +- .../diskbrowser/pascal/PascalDisk.java | 3 ++ .../diskbrowser/prodos/FileEntry.java | 44 ++++++++++++------- 8 files changed, 69 insertions(+), 40 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/BasicProgram.java b/src/com/bytezone/diskbrowser/applefile/BasicProgram.java index 4db2fe1..858a44e 100644 --- a/src/com/bytezone/diskbrowser/applefile/BasicProgram.java +++ b/src/com/bytezone/diskbrowser/applefile/BasicProgram.java @@ -139,12 +139,22 @@ public class BasicProgram extends AbstractFile // (see SEA BATTLE on DISK283.DSK) if (subline.is (TOKEN_REM) && lineText.length () > wrapRemAt + 4) { + // System.out.println (lineText.length ()); String copy = lineText.substring (4); text.append ("REM "); - int inset = text.length (); + int inset = text.length () + 1; List remarks = splitRemark (copy, wrapRemAt); + boolean first = true; for (String remark : remarks) - text.append (" ".substring (0, inset) + remark); + { + if (first) + { + first = false; + text.append (remark); + } + else + text.append ("\n ".substring (0, inset) + remark); + } } else text.append (lineText); @@ -268,14 +278,12 @@ 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)); - remarks.add (remark.substring (0, max) + "\n"); if (max == 0) break; - remark = remark.substring (max + 1); + remarks.add (remark.substring (0, max)); + remark = remark.substring (max); } remarks.add (remark); - // System.out.println (remark); return remarks; } diff --git a/src/com/bytezone/diskbrowser/applefile/OriginalHiResImage.java b/src/com/bytezone/diskbrowser/applefile/OriginalHiResImage.java index 736eeef..6398581 100755 --- a/src/com/bytezone/diskbrowser/applefile/OriginalHiResImage.java +++ b/src/com/bytezone/diskbrowser/applefile/OriginalHiResImage.java @@ -7,11 +7,6 @@ public class OriginalHiResImage extends HiResImage { private static final int WHITE = 0xFFFFFF; private static final int BLACK = 0x000000; - // private static final int RED = 0xFF0000; - // private static final int GREEN = 0x00CC00; - // private static final int BLUE = 0x0000FF; - // private static final int VIOLET = 0xBB66FF; - // private static final int[][] palette = { { VIOLET, GREEN }, { BLUE, RED } }; private static final int[][] paletteTable = { { 9, 6 }, { 12, 3 } }; private static boolean matchColourBits = false; @@ -42,6 +37,9 @@ public class OriginalHiResImage extends HiResImage // createImage (); } + // https://github.com/Michaelangel007/apple2_hgr_font_tutorial + // hgr[ y ] = 0x2000 + (y/64)*0x28 + (y%8)*0x400 + ((y/8)&7)*0x80; + @Override protected void createMonochromeImage () { diff --git a/src/com/bytezone/diskbrowser/disk/AbstractSector.java b/src/com/bytezone/diskbrowser/disk/AbstractSector.java index 2c06894..4ce11e0 100755 --- a/src/com/bytezone/diskbrowser/disk/AbstractSector.java +++ b/src/com/bytezone/diskbrowser/disk/AbstractSector.java @@ -83,31 +83,30 @@ public abstract class AbstractSector implements DataSource return panel; } - protected void addText (StringBuilder text, byte[] b, int offset, int size, String desc) + protected void addText (StringBuilder text, byte[] buffer, int offset, int size, + String desc) { - if ((offset + size - 1) > b.length) - { - // System.out.printf ("Offset : %d, Size : %d, Buffer : %d%n", offset, size, buffer.length); + if ((offset + size - 1) > buffer.length) return; - } switch (size) { case 1: - text.append ( - String.format ("%03X %02X %s%n", offset, b[offset], desc)); + text.append (String.format ("%03X %02X %s%n", offset, + buffer[offset], desc)); break; case 2: text.append (String.format ("%03X-%03X %02X %02X %s%n", offset, - offset + 1, b[offset], b[offset + 1], desc)); + offset + 1, buffer[offset], buffer[offset + 1], desc)); break; case 3: text.append (String.format ("%03X-%03X %02X %02X %02X %s%n", offset, - offset + 2, b[offset], b[offset + 1], b[offset + 2], desc)); + offset + 2, buffer[offset], buffer[offset + 1], buffer[offset + 2], desc)); break; case 4: text.append (String.format ("%03X-%03X %02X %02X %02X %02X %s%n", offset, - offset + 3, b[offset], b[offset + 1], b[offset + 2], b[offset + 3], desc)); + offset + 3, buffer[offset], buffer[offset + 1], buffer[offset + 2], + buffer[offset + 3], desc)); break; default: System.out.println ("Invalid length : " + size); diff --git a/src/com/bytezone/diskbrowser/disk/DiskFactory.java b/src/com/bytezone/diskbrowser/disk/DiskFactory.java index 8a894ea..9ed502d 100755 --- a/src/com/bytezone/diskbrowser/disk/DiskFactory.java +++ b/src/com/bytezone/diskbrowser/disk/DiskFactory.java @@ -533,13 +533,14 @@ public class DiskFactory private static FormattedDisk check2mgDisk (File file) { if (debug) - System.out.println ("Checking Prodos 2mg disk"); + System.out.println ("Checking 2mg disk"); try { AppleDisk disk = new AppleDisk (file, 0, 0); if (disk.getTotalBlocks () > 0 && ProdosDisk.isCorrectFormat (disk)) return new ProdosDisk (disk); + // should check for DOS, but AppleDisk assumes 2mg has 512 byte blocks } catch (Exception e) { diff --git a/src/com/bytezone/diskbrowser/dos/DosVTOCSector.java b/src/com/bytezone/diskbrowser/dos/DosVTOCSector.java index 9dce6da..5c68f6f 100755 --- a/src/com/bytezone/diskbrowser/dos/DosVTOCSector.java +++ b/src/com/bytezone/diskbrowser/dos/DosVTOCSector.java @@ -45,6 +45,14 @@ class DosVTOCSector extends AbstractSector addText (text, buffer, 3, 1, "DOS release number"); addText (text, buffer, 4, 2, "Not used"); addTextAndDecimal (text, buffer, 6, 1, "Diskette volume"); + addText (text, buffer, 7, 4, "Not used"); + addText (text, buffer, 11, 4, "Not used"); + addText (text, buffer, 15, 4, "Not used"); + addText (text, buffer, 19, 4, "Not used"); + addText (text, buffer, 23, 4, "Not used"); + addText (text, buffer, 27, 4, "Not used"); + addText (text, buffer, 31, 4, "Not used"); + addText (text, buffer, 35, 4, "Not used"); addTextAndDecimal (text, buffer, 39, 1, "Maximum TS pairs"); addText (text, buffer, 40, 4, "Not used"); addText (text, buffer, 44, 4, "Not used"); diff --git a/src/com/bytezone/diskbrowser/gui/DiskLegendPanel.java b/src/com/bytezone/diskbrowser/gui/DiskLegendPanel.java index fbf471e..ae93196 100644 --- a/src/com/bytezone/diskbrowser/gui/DiskLegendPanel.java +++ b/src/com/bytezone/diskbrowser/gui/DiskLegendPanel.java @@ -18,7 +18,7 @@ import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails; class DiskLegendPanel extends JPanel { - private static final int LEFT = 10; + private static final int LEFT = 3; private static final int TOP = 10; private FormattedDisk disk; @@ -69,7 +69,7 @@ class DiskLegendPanel extends JPanel for (SectorType type : disk.getSectorTypeList ()) { - int x = LEFT + (count % 2 == 0 ? 0 : 145); + int x = LEFT + (count % 2 == 0 ? 0 : 155); int y = TOP + count++ / 2 * lineHeight; // draw border diff --git a/src/com/bytezone/diskbrowser/pascal/PascalDisk.java b/src/com/bytezone/diskbrowser/pascal/PascalDisk.java index 4806dec..a12dc2f 100755 --- a/src/com/bytezone/diskbrowser/pascal/PascalDisk.java +++ b/src/com/bytezone/diskbrowser/pascal/PascalDisk.java @@ -128,6 +128,9 @@ public class PascalDisk extends AbstractFormattedDisk public static boolean isCorrectFormat (AppleDisk disk, boolean debug) { disk.setInterleave (1); // should only ever be Prodos + if (checkFormat (disk, debug)) + return true; + disk.setInterleave (0); // SANE Disk 2.po if (checkFormat (disk, debug)) return true; return false; diff --git a/src/com/bytezone/diskbrowser/prodos/FileEntry.java b/src/com/bytezone/diskbrowser/prodos/FileEntry.java index e290f8f..14aa18f 100755 --- a/src/com/bytezone/diskbrowser/prodos/FileEntry.java +++ b/src/com/bytezone/diskbrowser/prodos/FileEntry.java @@ -49,7 +49,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants modified = HexFormatter.getAppleDate (entryBuffer, 0x21); headerPointer = HexFormatter.unsignedShort (entryBuffer, 0x25); - if (isGSOSFile ()) // I think this is wrong + if (isGSOSFile ()) // I think this is wrong System.out.printf ("************************************ %s is GS/OS%n", name); switch (storageType) @@ -74,20 +74,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants break; case GSOS_EXTENDED_FILE: - parentDisk.setSectorType (keyPtr, parentDisk.extendedKeySector); - indexBlocks.add (disk.getDiskAddress (keyPtr)); - - byte[] buffer2 = disk.readSector (keyPtr); // data fork and resource fork - - // read 2 mini entries (data fork / resource fork) - for (int i = 0; i < 512; i += 256) - { - int storageType = buffer2[i] & 0x0F; - int keyBlock = HexFormatter.unsignedShort (buffer2, i + 1); - int eof = - HexFormatter.intValue (buffer2[i + 3], buffer2[i + 4], buffer2[i + 5]); - addDataBlocks (storageType, keyBlock); - } + readForks (); break; case SUBDIRECTORY: @@ -102,6 +89,8 @@ class FileEntry extends CatalogEntry implements ProdosConstants case PASCAL_ON_PROFILE: indexBlocks.add (disk.getDiskAddress (keyPtr)); + System.out.println ("PASCAL on PROFILE: " + name); + // are these blocks guaranteed to be contiguous? break; default: @@ -109,6 +98,23 @@ class FileEntry extends CatalogEntry implements ProdosConstants } } + private void readForks () + { + parentDisk.setSectorType (keyPtr, parentDisk.extendedKeySector); + indexBlocks.add (disk.getDiskAddress (keyPtr)); + + byte[] buffer2 = disk.readSector (keyPtr); // data fork and resource fork + + // read 2 mini entries (data fork / resource fork) + for (int i = 0; i < 512; i += 256) + { + int storageType = buffer2[i] & 0x0F; + int keyBlock = HexFormatter.unsignedShort (buffer2, i + 1); + int eof = HexFormatter.intValue (buffer2[i + 3], buffer2[i + 4], buffer2[i + 5]); + addDataBlocks (storageType, keyBlock); + } + } + private void addDataBlocks (int storageType, int keyPtr) { DiskAddress emptyDiskAddress = disk.getDiskAddress (0); @@ -188,7 +194,10 @@ class FileEntry extends CatalogEntry implements ProdosConstants // should be removed private boolean isGSOSFile () { - return ((fileType & 0xF0) == 0x80); + // return ((fileType & 0xF0) == 0x80); + if ((fileType & 0xF0) == 0x80) + System.out.println ("GS/OS file: " + name); + return false; } // should be removed @@ -508,6 +517,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants } } + // should be removed private byte[] getGEOSBuffer () { switch (storageType) @@ -525,6 +535,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants } } + // should be removed private byte[] getMasterIndexFile (int keyPtr) { byte[] buffer = disk.readSector (keyPtr); @@ -545,6 +556,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants return fileBuffer; } + // should be removed private byte[] getIndexFile (int keyPtr) { byte[] buffer = disk.readSector (keyPtr);