diff --git a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java index 1e0b3c7..8e96019 100644 --- a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java +++ b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java @@ -17,10 +17,12 @@ public class ApplesoftBasicProgram extends BasicProgram { private final List sourceLines = new ArrayList<> (); private final int endPtr; + final Map> gotoLines = new TreeMap<> (); final Map> gosubLines = new TreeMap<> (); final Map> symbolLines = new TreeMap<> (); final Map> uniqueSymbols = new TreeMap<> (); + final List stringsLine = new ArrayList<> (); final List stringsText = new ArrayList<> (); @@ -31,19 +33,19 @@ public class ApplesoftBasicProgram extends BasicProgram super (name, buffer); int ptr = 0; - int prevOffset = 0; + int currentAddress = 0; int max = buffer.length - 6; // need at least 6 bytes to make a SourceLine while (ptr <= max) { int nextAddress = Utility.unsignedShort (buffer, ptr); - if (nextAddress <= prevOffset) // usually zero + if (nextAddress <= currentAddress) // usually zero when finished break; SourceLine line = new SourceLine (this, buffer, ptr); sourceLines.add (line); ptr += line.length; - prevOffset = nextAddress; + currentAddress = nextAddress; } endPtr = ptr; } @@ -181,8 +183,8 @@ public class ApplesoftBasicProgram extends BasicProgram if (basicPreferences.wrapPrintAt > 0 // && (subline.is (ApplesoftConstants.TOKEN_PRINT) || subline.is (ApplesoftConstants.TOKEN_INPUT)) - && countChars (text, Utility.ASCII_QUOTE) == 2 // just start and end quotes - && countChars (text, Utility.ASCII_CARET) == 0) // no control characters + && countChars (text, Utility.ASCII_QUOTE) == 2 // just start and end quotes + && countChars (text, Utility.ASCII_CARET) == 0) // no control characters // && countChars (text, ASCII_SEMI_COLON) == 0) { if (true) // new method @@ -279,7 +281,15 @@ public class ApplesoftBasicProgram extends BasicProgram String format = longestVarName > 6 ? "%" + longestVarName + "s %s%n" : "%6s %s%n"; for (String symbol : symbolLines.keySet ()) - fullText.append (String.format (format, symbol, symbolLines.get (symbol))); + { + String line = symbolLines.get (symbol).toString (); + line = line.substring (1, line.length () - 2); + for (String s : splitXref (line, 90, ' ')) + { + fullText.append (String.format (format, symbol, s)); + symbol = ""; + } + } } if (basicPreferences.showDuplicateSymbols && !uniqueSymbols.isEmpty ()) @@ -397,6 +407,7 @@ public class ApplesoftBasicProgram extends BasicProgram int firstSpace = 0; while (firstSpace < line.length () && line.charAt (firstSpace) != ' ') ++firstSpace; + System.out.println (line); List lines = new ArrayList<> (); while (line.length () > wrapLength) @@ -414,6 +425,26 @@ public class ApplesoftBasicProgram extends BasicProgram return lines; } + // ---------------------------------------------------------------------------------// + private List splitXref (String line, int wrapLength, char breakChar) + // ---------------------------------------------------------------------------------// + { + List lines = new ArrayList<> (); + while (line.length () > wrapLength) + { + int max = Math.min (wrapLength, line.length () - 1); + while (max > 0 && line.charAt (max) != breakChar) + --max; + if (max == 0) + break; + lines.add (line.substring (0, max + 1)); + line = line.substring (max + 1); + } + + lines.add (line); + return lines; + } + // ---------------------------------------------------------------------------------// private List splitDim (String line) // ---------------------------------------------------------------------------------// diff --git a/src/com/bytezone/diskbrowser/applefile/SourceLine.java b/src/com/bytezone/diskbrowser/applefile/SourceLine.java index c4771a3..022591c 100644 --- a/src/com/bytezone/diskbrowser/applefile/SourceLine.java +++ b/src/com/bytezone/diskbrowser/applefile/SourceLine.java @@ -9,12 +9,12 @@ import com.bytezone.diskbrowser.utilities.Utility; public class SourceLine // -----------------------------------------------------------------------------------// { + ApplesoftBasicProgram parent; List sublines = new ArrayList<> (); int lineNumber; int linePtr; int length; byte[] buffer; - ApplesoftBasicProgram parent; // ---------------------------------------------------------------------------------// SourceLine (ApplesoftBasicProgram parent, byte[] buffer, int ptr) @@ -77,7 +77,6 @@ public class SourceLine 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; } diff --git a/src/com/bytezone/diskbrowser/applefile/SubLine.java b/src/com/bytezone/diskbrowser/applefile/SubLine.java index 4b15caa..980dc49 100644 --- a/src/com/bytezone/diskbrowser/applefile/SubLine.java +++ b/src/com/bytezone/diskbrowser/applefile/SubLine.java @@ -16,7 +16,6 @@ public class SubLine int length; String[] nextVariables; String forVariable = ""; - String onExpression = ""; int assignEqualPos; // used for aligning the equals sign byte[] buffer; @@ -150,14 +149,14 @@ public class SubLine while (p < max && parent.buffer[p] != ApplesoftConstants.TOKEN_GOTO && parent.buffer[p] != ApplesoftConstants.TOKEN_GOSUB) { - if (Utility.isHighBitSet (parent.buffer[p])) - { - int val = parent.buffer[p] & 0x7F; - if (val < ApplesoftConstants.tokens.length) - onExpression += " " + ApplesoftConstants.tokens[val]; - } - else - onExpression += (char) (parent.buffer[p]); + // if (Utility.isHighBitSet (parent.buffer[p])) + // { + // int val = parent.buffer[p] & 0x7F; + // if (val < ApplesoftConstants.tokens.length) + // onExpression += " " + ApplesoftConstants.tokens[val]; + // } + // else + // onExpression += (char) (parent.buffer[p]); p++; } @@ -325,6 +324,7 @@ public class SubLine { int ptr = startPtr + 1; int max = startPtr + length; + while (ptr < max) { if (parent.buffer[ptr++] == token) @@ -378,14 +378,21 @@ public class SubLine while (ptr <= max) { - int c = buffer[ptr] & 0xFF; - // System.out.printf ("%02X %s%n", c, (char) c); - if (c == 0x08 && text.length () > 0) - text.deleteCharAt (text.length () - 1); - else if (c == 0x0D) - text.append ("\n"); - else - text.append ((char) c); + switch (buffer[ptr]) + { + case Utility.ASCII_BACKSPACE: + if (text.length () > 0) + text.deleteCharAt (text.length () - 1); + break; + + case Utility.ASCII_CR: + text.append ("\n"); + break; + + default: + text.append ((char) buffer[ptr]); // do not mask with 0xFF + } + ptr++; } } @@ -418,6 +425,7 @@ public class SubLine System.arraycopy (buffer, startPtr + 1, buffer2, 0, buffer2.length); AssemblerProgram program = new AssemblerProgram ("REM assembler", buffer2, getAddress () + 1); + return program.getAssembler ().split ("\n"); } @@ -460,7 +468,7 @@ public class SubLine } else if (Utility.isControlCharacter (b)) line.append (ApplesoftBasicProgram.basicPreferences.showCaret - ? "^" + (char) (b + 64) : ""); + ? "^" + (char) (b + 64) : "."); else line.append ((char) b); } diff --git a/src/com/bytezone/diskbrowser/utilities/Utility.java b/src/com/bytezone/diskbrowser/utilities/Utility.java index fa75cc6..e4dbc71 100644 --- a/src/com/bytezone/diskbrowser/utilities/Utility.java +++ b/src/com/bytezone/diskbrowser/utilities/Utility.java @@ -17,6 +17,8 @@ import java.util.zip.Checksum; public class Utility // -----------------------------------------------------------------------------------// { + public static final byte ASCII_BACKSPACE = 0x08; + public static final byte ASCII_CR = 0x0D; public static final byte ASCII_QUOTE = 0x22; public static final byte ASCII_DOLLAR = 0x24; public static final byte ASCII_PERCENT = 0x25;