From 668ed719fac284fc4e4f86a2bdaa6220db8f2922 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Fri, 16 Sep 2022 06:26:52 +1000 Subject: [PATCH] tidying --- .../applefile/ApplesoftBasicProgram.java | 2 +- .../diskbrowser/dos/AbstractCatalogEntry.java | 50 +++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java index 6c0e7f9..8af3172 100644 --- a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java +++ b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java @@ -10,7 +10,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons // -----------------------------------------------------------------------------------// { private final List sourceLines = new ArrayList<> (); - private int ptr; // end-of-program marker + private int ptr = 0; // end-of-program marker private final UserBasicFormatter userBasicFormatter; private final AppleBasicFormatter appleBasicFormatter; diff --git a/src/com/bytezone/diskbrowser/dos/AbstractCatalogEntry.java b/src/com/bytezone/diskbrowser/dos/AbstractCatalogEntry.java index e783099..24a64cd 100644 --- a/src/com/bytezone/diskbrowser/dos/AbstractCatalogEntry.java +++ b/src/com/bytezone/diskbrowser/dos/AbstractCatalogEntry.java @@ -89,8 +89,8 @@ abstract class AbstractCatalogEntry implements AppleFileSource lastModified = Utility.getDateTime (entryBuffer, 0x1B); // CATALOG command only formats the LO byte - see Beneath Apple DOS pp4-6 - String base = String.format ("%s%s %03d ", locked ? "*" : " ", getFileType (), - reportedSize & 0xFF); + String base = + String.format ("%s%s %03d ", locked ? "*" : " ", getFileType (), reportedSize & 0xFF); catalogName = getName (base, entryBuffer); displayName = getDisplayName (entryBuffer); } @@ -235,18 +235,28 @@ abstract class AbstractCatalogEntry implements AppleFileSource case IntegerBasic: reportedLength = Utility.getShort (buffer, 0); - exactBuffer = new byte[reportedLength]; - System.arraycopy (buffer, 2, exactBuffer, 0, reportedLength); - appleFile = new IntegerBasicProgram (name, exactBuffer); + if (reportedLength > 0) + { + exactBuffer = new byte[reportedLength]; + System.arraycopy (buffer, 2, exactBuffer, 0, reportedLength); + appleFile = new IntegerBasicProgram (name, exactBuffer); + } + else + appleFile = new DefaultAppleFile (name, buffer); break; case ApplesoftBasic: reportedLength = Utility.getShort (buffer, 0); - exactBuffer = new byte[reportedLength]; - if (reportedLength > buffer.length) - reportedLength = buffer.length - 2; - System.arraycopy (buffer, 2, exactBuffer, 0, reportedLength); - appleFile = new ApplesoftBasicProgram (name, exactBuffer); + if (reportedLength > 0) + { + exactBuffer = new byte[reportedLength]; + if (reportedLength > buffer.length) + reportedLength = buffer.length - 2; + System.arraycopy (buffer, 2, exactBuffer, 0, reportedLength); + appleFile = new ApplesoftBasicProgram (name, exactBuffer); + } + else + appleFile = new DefaultAppleFile (name, buffer); break; case Binary: // binary file @@ -256,8 +266,8 @@ abstract class AbstractCatalogEntry implements AppleFileSource reportedLength = Utility.getShort (buffer, 2); if (reportedLength == 0) { - System.out.println (name.trim () + " reported length : 0 - reverting to " - + (buffer.length - 4)); + System.out.println ( + name.trim () + " reported length : 0 - reverting to " + (buffer.length - 4)); reportedLength = buffer.length - 4; } @@ -268,9 +278,8 @@ abstract class AbstractCatalogEntry implements AppleFileSource exactBuffer = new byte[buffer.length - 4]; // reported length is too long System.arraycopy (buffer, 4, exactBuffer, 0, exactBuffer.length); - if ((name.endsWith (".FONT") || name.endsWith (" FONT") - || name.endsWith (".SET") || name.startsWith ("ASCII.")) - && FontFile.isFont (exactBuffer)) + if ((name.endsWith (".FONT") || name.endsWith (" FONT") || name.endsWith (".SET") + || name.startsWith ("ASCII.")) && FontFile.isFont (exactBuffer)) appleFile = new FontFile (name, exactBuffer, loadAddress); else if (name.endsWith (".MW")) appleFile = new MagicWindowText (name, exactBuffer); @@ -305,8 +314,7 @@ abstract class AbstractCatalogEntry implements AppleFileSource appleFile = new AssemblerProgram (name, exactBuffer, loadAddress); } else if (reportedLength == 0x240 // - && (loadAddress == 0x5800 || loadAddress == 0x6000 - || loadAddress == 0x7800)) + && (loadAddress == 0x5800 || loadAddress == 0x6000 || loadAddress == 0x7800)) appleFile = new PrintShopGraphic (name, exactBuffer); else if (isRunCommand (exactBuffer)) { @@ -319,8 +327,8 @@ abstract class AbstractCatalogEntry implements AppleFileSource { appleFile = new AssemblerProgram (name, exactBuffer, loadAddress); if ((exactBuffer.length + 4) < buffer.length) - ((AssemblerProgram) appleFile).setExtraBuffer (buffer, - exactBuffer.length + 4, buffer.length - (exactBuffer.length + 4)); + ((AssemblerProgram) appleFile).setExtraBuffer (buffer, exactBuffer.length + 4, + buffer.length - (exactBuffer.length + 4)); } break; @@ -362,8 +370,8 @@ abstract class AbstractCatalogEntry implements AppleFileSource int reportedLength = Utility.getShort (buffer, 2); if (reportedLength == 0) { - System.out.println ( - name.trim () + " reported length : 0 - reverting to " + (buffer.length - 4)); + System.out + .println (name.trim () + " reported length : 0 - reverting to " + (buffer.length - 4)); reportedLength = buffer.length - 4; }