diff --git a/src/com/bytezone/diskbrowser/applefile/CPMBasicFile.java b/src/com/bytezone/diskbrowser/applefile/CPMBasicFile.java index 73d1046..66672cb 100644 --- a/src/com/bytezone/diskbrowser/applefile/CPMBasicFile.java +++ b/src/com/bytezone/diskbrowser/applefile/CPMBasicFile.java @@ -46,10 +46,58 @@ public class CPMBasicFile extends TextFile while (buffer[ptr] != 0) { int val = buffer[ptr++] & 0xFF; - if ((val & 0x80) == 0 && val >= 32) + + if (val == 0x0E) + { + int next1 = buffer[ptr++] & 0xFF; + int next2 = buffer[ptr++] & 0xFF; + text.append (next2 * 256 + next1); + continue; + } + + if (val == 0x0F) + { + int nextVal = buffer[ptr++] & 0xFF; + text.append (nextVal); + continue; + } + + if (val == 0x0C) + { + int b1 = buffer[ptr++] & 0xFF; + int b2 = buffer[ptr++] & 0xFF; + text.append ("&H" + String.format ("%X", b2 * 256 + b1)); + continue; + } + + if (val == 0x0D) + { + System.out.println ("found 0x0D"); + } + + if (val >= 0x11 && val <= 0x1A) + { + text.append (val - 0x11); + continue; + } + + if (val == 0xFF) + { + int next = buffer[ptr++] & 0xFF; + String token = switch (next) + { + case 0x94 -> "ASC"; + case 0x96 -> "PEEK"; + default -> String.format ("<%02X>", next); + }; + text.append (token); + continue; + } + + if (val >= 0x20 && val <= 0x7E) text.append (String.format ("%s", (char) val)); // printable else - text.append (String.format ("<%02X>", val)); // token? + text.append (getToken (val)); } ptr = nextAddress - loadAddress; @@ -61,4 +109,123 @@ public class CPMBasicFile extends TextFile return text.toString (); } + + // ---------------------------------------------------------------------------------// + private String getToken (int val) + // ---------------------------------------------------------------------------------// + { + switch (val) + { + case 0x81: + return "END"; + + case 0x82: + return "FOR"; + + case 0x83: + return "NEXT"; + + case 0x84: + return "DATA"; + + case 0x85: + return "INPUT"; + + case 0x8B: + return "IF"; + + case 0x89: + return "GOTO"; + + case 0x8D: + return "GOSUB"; + + case 0x8E: + return "RETURN"; + + case 0x8F: + return "REM"; + + case 0x90: + return "POS"; + + case 0x91: + return "PRINT"; + + case 0x95: + return "ON"; + + case 0x97: + return "POKE"; + + case 0x9E: + return "ELSE"; + + case 0xB3: + return "DIM "; + + case 0xC5: + return "RESET"; + + case 0xC6: + return "TEXT"; + + case 0xC7: + return "HOME"; + + case 0xC8: + return "VTAB"; + + case 0xC9: + return "HTAB"; + + case 0xDD: + return "TO"; + + case 0xDE: + return "THEN"; + + case 0xDF: + return "TAB("; + + case 0xE0: + return "STEP"; + + case 0xE1: + return "USR"; + + case 0xE7: + return "STRING$"; + + case 0xEF: + return ">"; + + case 0xF0: + return "="; + + case 0xF1: + return "<"; + + case 0xF2: + return "+"; + + case 0xF3: + return "-"; + + case 0xF4: + return "*"; + + case 0xF7: + return "AND"; + + case 0xF8: + return "OR"; + + case 0xFC: + return "MOD"; + + default: + return String.format ("<%02X>", val); + } + } } diff --git a/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java b/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java index 48e851a..4c77c1b 100644 --- a/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java +++ b/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java @@ -213,20 +213,13 @@ class DirectoryEntry implements AppleFileSource byte[] exactBuffer = new byte[len]; System.arraycopy (buffer, 0, exactBuffer, 0, len); - int max = Math.min (256, exactBuffer.length); - int count = 0; - for (int i = 1; i < max; i++) - { - if (exactBuffer[i - 1] == 0x0D && exactBuffer[i] == 0x0A) - ++count; - } - if ("COM".equals (type)) appleFile = new DefaultAppleFile (name, exactBuffer, "COM File"); else if ("DVR".equals (type)) appleFile = new DefaultAppleFile (name, exactBuffer, "DVR File"); else if ("ASM".equals (type) || "DOC".equals (type) || "TXT".equals (type) - || count > 2) + || "LET".equals (type) || "ALX".equals (type) || "SRC".equals (type) + || exactBuffer[len - 1] == 0x1A) appleFile = new CPMTextFile (name, exactBuffer); else if ("BAS".equals (type)) appleFile = new CPMBasicFile (name, exactBuffer);