This commit is contained in:
Denis Molony 2021-03-09 16:23:05 +10:00
parent 5e133715cd
commit 62bf355ca3
10 changed files with 57 additions and 61 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 724 KiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@ -26,7 +26,7 @@ public class AppleBasicFormatter extends BasicFormatter
// ---------------------------------------------------------------------------------//
@Override
public void format (StringBuilder fullText)
public void append (StringBuilder fullText)
// ---------------------------------------------------------------------------------//
{
int loadAddress = getLoadAddress ();
@ -42,26 +42,22 @@ public class AppleBasicFormatter extends BasicFormatter
ptr += 4;
if (basicPreferences.appleLineWrap)
ptr = appendWithWrap (currentLine, ptr);
ptr = wrapLine (currentLine, ptr);
else
ptr = appendWithOutWrap (currentLine, ptr);
ptr = flatLine (currentLine, ptr);
if (ptr != (linkField - loadAddress))
{
System.out.printf ("%s: ptr: %04X, nextLine: %04X%n", program.name,
ptr + loadAddress, linkField);
// ptr = linkField - loadAddress; // use this when tested
}
currentLine.append (NEWLINE);
fullText.append (currentLine);
currentLine.setLength (0);
}
}
// ---------------------------------------------------------------------------------//
private int appendWithOutWrap (StringBuilder currentLine, int ptr)
private int flatLine (StringBuilder currentLine, int ptr)
// ---------------------------------------------------------------------------------//
{
byte b;
@ -99,11 +95,11 @@ public class AppleBasicFormatter extends BasicFormatter
}
// ---------------------------------------------------------------------------------//
private int appendWithWrap (StringBuilder currentLine, int ptr)
private int wrapLine (StringBuilder currentLine, int ptr)
// ---------------------------------------------------------------------------------//
{
byte b;
int cursor = currentLine.length (); // controls when to wrap
int cursor = currentLine.length ();
while ((b = buffer[ptr++]) != 0)
if (isHighBitSet (b))

View File

@ -46,11 +46,11 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
StringBuilder text = new StringBuilder ();
if (basicPreferences.showHeader)
headerFormatter.format (text);
headerFormatter.append (text);
if (showDebugText)
{
debugBasicFormatter.format (text);
debugBasicFormatter.append (text);
return Utility.rtrim (text);
}
@ -61,12 +61,12 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
}
if (basicPreferences.userFormat)
userBasicFormatter.format (text);
userBasicFormatter.append (text);
else
appleBasicFormatter.format (text);
appleBasicFormatter.append (text);
if (basicPreferences.showAllXref)
xrefFormatter.format (text);
xrefFormatter.append (text);
return Utility.rtrim (text);
}

View File

@ -28,7 +28,7 @@ public abstract class BasicFormatter implements ApplesoftConstants
}
// ---------------------------------------------------------------------------------//
public abstract void format (StringBuilder fullText);
public abstract void append (StringBuilder fullText);
// ---------------------------------------------------------------------------------//
// ---------------------------------------------------------------------------------//

View File

@ -26,7 +26,7 @@ public class DebugBasicFormatter extends BasicFormatter
// ---------------------------------------------------------------------------------//
@Override
public void format (StringBuilder text)
public void append (StringBuilder text)
// ---------------------------------------------------------------------------------//
{
int loadAddress = getLoadAddress ();

View File

@ -16,7 +16,7 @@ public class HeaderFormatter extends BasicFormatter
// ---------------------------------------------------------------------------------//
@Override
public void format (StringBuilder fullText)
public void append (StringBuilder fullText)
// ---------------------------------------------------------------------------------//
{
fullText.append ("Name : " + program.name + "\n");

View File

@ -1,5 +1,7 @@
package com.bytezone.diskbrowser.applefile;
import static com.bytezone.diskbrowser.utilities.Utility.ASCII_COLON;
import static com.bytezone.diskbrowser.utilities.Utility.ASCII_QUOTE;
import static com.bytezone.diskbrowser.utilities.Utility.unsignedShort;
import java.util.ArrayList;
@ -11,7 +13,7 @@ import com.bytezone.diskbrowser.utilities.Utility;
public class SourceLine implements ApplesoftConstants
// -----------------------------------------------------------------------------------//
{
ApplesoftBasicProgram parent;
ApplesoftBasicProgram program;
int linkField;
int lineNumber;
int linePtr;
@ -21,17 +23,17 @@ public class SourceLine implements ApplesoftConstants
List<SubLine> sublines = new ArrayList<> ();
// ---------------------------------------------------------------------------------//
SourceLine (ApplesoftBasicProgram parent, byte[] buffer, int ptr)
SourceLine (ApplesoftBasicProgram program, byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//
{
this.parent = parent;
this.program = program;
this.buffer = buffer;
linePtr = ptr;
linkField = unsignedShort (buffer, ptr);
lineNumber = unsignedShort (buffer, ptr + 2);
int startPtr = ptr += 4; // skip link to next line and lineNumber
int startPtr = ptr += 4; // skip link field and lineNumber
boolean inString = false; // can toggle
boolean inRemark = false; // can only go false -> true
byte b;
@ -43,7 +45,7 @@ public class SourceLine implements ApplesoftConstants
if (inString)
{
if (b == Utility.ASCII_QUOTE) // terminate string
if (b == ASCII_QUOTE) // terminate string
inString = false;
continue;
}
@ -51,36 +53,28 @@ public class SourceLine implements ApplesoftConstants
switch (b)
{
// break IF statements into two sublines (allows for easier line indenting)
case ApplesoftConstants.TOKEN_IF:
// skip to THEN or GOTO - if not found then it's an error
case TOKEN_IF:
while (buffer[ptr] != TOKEN_THEN && buffer[ptr] != TOKEN_GOTO
&& buffer[ptr] != 0)
ptr++;
// keep THEN with the IF
if (buffer[ptr] == TOKEN_THEN)
if (buffer[ptr] == TOKEN_THEN) // keep THEN with the IF
++ptr;
// create subline from the condition (plus THEN if it exists)
sublines.add (new SubLine (this, startPtr, ptr - startPtr));
startPtr = ptr;
startPtr = addSubLine (startPtr, ptr); // create subline from the condition
break;
// end of subline, so add it, advance startPtr and continue
case Utility.ASCII_COLON:
sublines.add (new SubLine (this, startPtr, ptr - startPtr));
startPtr = ptr;
case ASCII_COLON: // end of subline
startPtr = addSubLine (startPtr, ptr);
break;
case TOKEN_REM:
if (ptr == startPtr + 1)
if (ptr == startPtr + 1) // at start of line
inRemark = true;
else
{ // REM appears mid-line (should follow a colon)
System.out.printf ("%5d %s%n", lineNumber, "mid-line REM token");
ptr--; // point back to this REM
sublines.add (new SubLine (this, startPtr, ptr - startPtr));
startPtr = ptr;
else // mid-line - should be illegal
{
System.out.printf ("%s : %5d mid-line REM token%n", program.name, lineNumber);
startPtr = addSubLine (startPtr, --ptr); // point back to the REM
}
break;
@ -92,9 +86,14 @@ public class SourceLine implements ApplesoftConstants
length = ptr - linePtr;
// add whatever is left after the last colon
// if no colon was found this is the entire line
int bytesLeft = ptr - startPtr;
sublines.add (new SubLine (this, startPtr, bytesLeft));
addSubLine (startPtr, ptr);
}
// ---------------------------------------------------------------------------------//
private int addSubLine (int startPtr, int ptr)
// ---------------------------------------------------------------------------------//
{
sublines.add (new SubLine (this, startPtr, ptr - startPtr));
return ptr;
}
}

View File

@ -27,7 +27,7 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;;
public class SubLine implements ApplesoftConstants
// -----------------------------------------------------------------------------------//
{
SourceLine parent;
SourceLine sourceLine;
byte[] buffer;
int startPtr;
@ -57,13 +57,13 @@ public class SubLine implements ApplesoftConstants
private final List<String> stringsText = new ArrayList<> ();
// ---------------------------------------------------------------------------------//
SubLine (SourceLine parent, int startPtr, int length)
SubLine (SourceLine sourceLine, int offset, int length)
// ---------------------------------------------------------------------------------//
{
this.parent = parent;
this.startPtr = startPtr;
this.sourceLine = sourceLine;
this.startPtr = offset;
this.length = length;
this.buffer = parent.buffer;
this.buffer = sourceLine.buffer;
int ptr = startPtr;
byte firstByte = buffer[startPtr];
@ -91,8 +91,9 @@ public class SubLine implements ApplesoftConstants
else if (isEndOfLine (firstByte)) // empty subline
return;
else // probably Beagle Bros 0D or 0A
System.out.printf ("%s unexpected bytes at line %5d:%n%s%n", parent.parent.name,
parent.lineNumber, HexFormatter.formatNoHeader (buffer, startPtr, length));
System.out.printf ("%s unexpected bytes at line %5d:%n%s%n",
sourceLine.program.name, sourceLine.lineNumber,
HexFormatter.formatNoHeader (buffer, startPtr, length));
}
String var = "";
@ -102,11 +103,11 @@ public class SubLine implements ApplesoftConstants
boolean inDefine = false;
int stringPtr = 0;
int max = startPtr + length - 1;
while (isEndOfLine (buffer[max]))
--max;
int endOfLine = startPtr + length - 1;
while (isEndOfLine (buffer[endOfLine])) // zero or colon
--endOfLine;
while (ptr <= max)
while (ptr <= endOfLine)
{
byte b = buffer[ptr++];
@ -484,7 +485,7 @@ public class SubLine implements ApplesoftConstants
boolean isFirst ()
// ---------------------------------------------------------------------------------//
{
return (parent.linePtr + 4) == startPtr;
return (sourceLine.linePtr + 4) == startPtr;
}
// ---------------------------------------------------------------------------------//
@ -564,7 +565,7 @@ public class SubLine implements ApplesoftConstants
{
// apple format uses left-justified line numbers so the length varies
text.setLength (0);
text.append (String.format (" %d REM ", parent.lineNumber)); // mimic apple
text.append (String.format (" %d REM ", sourceLine.lineNumber)); // mimic apple
}
else
text.append (" REM ");

View File

@ -32,7 +32,7 @@ public class UserBasicFormatter extends BasicFormatter
// ---------------------------------------------------------------------------------//
@Override
public void format (StringBuilder fullText)
public void append (StringBuilder fullText)
// ---------------------------------------------------------------------------------//
{
boolean insertBlankLine = false;
@ -254,7 +254,7 @@ public class UserBasicFormatter extends BasicFormatter
boolean started = false;
alignment.setFirst (startSubline);
outerLoop: for (int i = sourceLines.indexOf (startSubline.parent); i < sourceLines
outerLoop: for (int i = sourceLines.indexOf (startSubline.sourceLine); i < sourceLines
.size (); i++)
{
boolean precededByIf = false;

View File

@ -93,7 +93,7 @@ public class XrefFormatter extends BasicFormatter
// ---------------------------------------------------------------------------------//
@Override
public void format (StringBuilder fullText)
public void append (StringBuilder fullText)
// ---------------------------------------------------------------------------------//
{
if (basicPreferences.showSymbols)