This commit is contained in:
Denis Molony 2021-02-21 18:03:26 +10:00
parent 20ad92fbd5
commit a8030c469c
6 changed files with 78 additions and 57 deletions

View File

@ -1,5 +1,12 @@
package com.bytezone.diskbrowser.applefile;
import static com.bytezone.diskbrowser.utilities.Utility.getIndent;
import static com.bytezone.diskbrowser.utilities.Utility.isDigit;
import static com.bytezone.diskbrowser.utilities.Utility.isHighBitSet;
import static com.bytezone.diskbrowser.utilities.Utility.isLetter;
import static com.bytezone.diskbrowser.utilities.Utility.isPossibleNumber;
import static com.bytezone.diskbrowser.utilities.Utility.unsignedShort;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -60,7 +67,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
int max = buffer.length - 6; // need at least 6 bytes to make a SourceLine
while (ptr <= max)
{
int nextAddress = Utility.unsignedShort (buffer, ptr);
int nextAddress = unsignedShort (buffer, ptr);
if (nextAddress <= currentAddress) // usually zero when finished
break;
@ -124,14 +131,14 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
byte b;
StringBuilder text = new StringBuilder ();
while ((nextLine = Utility.unsignedShort (buffer, ptr)) != 0)
while ((nextLine = unsignedShort (buffer, ptr)) != 0)
{
int lineNumber = Utility.unsignedShort (buffer, ptr + 2);
int lineNumber = unsignedShort (buffer, ptr + 2);
text.append (String.format (" %d ", lineNumber));
ptr += 4;
while ((b = buffer[ptr++]) != 0)
if (Utility.isHighBitSet (b))
if (isHighBitSet (b))
text.append (String.format (" %s ", ApplesoftConstants.tokens[b & 0x7F]));
else
switch (b)
@ -146,7 +153,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
break;
case Utility.ASCII_LF:
int indent = Utility.getIndent (text);
int indent = getIndent (text);
text.append ("\n");
for (int i = 0; i < indent; i++)
text.append (" ");
@ -256,7 +263,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
// Check for a wrappable REM/DATA/DIM statement
// (see SEA BATTLE on DISK283.DSK)
int inset = Math.max (text.length (), Utility.getIndent (fullText)) + 1;
int inset = Math.max (text.length (), getIndent (fullText)) + 1;
if (subline.is (TOKEN_REM) && lineText.length () > basicPreferences.wrapRemAt)
{
List<String> lines = splitLine (lineText, basicPreferences.wrapRemAt, ' ');
@ -322,7 +329,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
int ptr = endPtr + 2;
if (ptr < buffer.length - 1) // sometimes there's an extra byte on the end
{
int offset = Utility.unsignedShort (buffer, 0);
int offset = unsignedShort (buffer, 0);
int programLoadAddress = offset - getLineLength (0);
fullText.append ("\nExtra data:\n\n");
fullText.append (HexFormatter.formatNoHeader (buffer, ptr, buffer.length - ptr,
@ -489,7 +496,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
byte[] bytes = value.getBytes ();
int start = value.charAt (0) == Utility.ASCII_MINUS ? 1 : 0;
for (int i = start; i < bytes.length; i++)
if (!Utility.isPossibleNumber (bytes[i]))
if (!isPossibleNumber (bytes[i]))
return false;
return true;
}
@ -779,7 +786,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
private String getDebugText (StringBuilder text)
// ---------------------------------------------------------------------------------//
{
int offset = Utility.unsignedShort (buffer, 0);
int offset = unsignedShort (buffer, 0);
int programLoadAddress = offset - getLineLength (0);
for (SourceLine sourceLine : sourceLines)
@ -802,12 +809,35 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
text.append (NEWLINE);
}
// check for assembler routines after the basic code
if (endPtr < buffer.length)
{
String formattedHex = HexFormatter.formatNoHeader (buffer, endPtr,
buffer.length - endPtr, programLoadAddress + endPtr);
int length = buffer.length - endPtr;
int ptr = endPtr;
if (length > 2)
{
text.append (" ");
text.append (
HexFormatter.formatNoHeader (buffer, endPtr, 2, programLoadAddress + ptr));
text.append ("\n\n");
ptr += 2;
length -= 2;
}
// show the extra bytes as a hex dump
String formattedHex = HexFormatter.formatNoHeader (buffer, ptr, buffer.length - ptr,
programLoadAddress + ptr);
for (String bytes : formattedHex.split (NEWLINE))
text.append (String.format (" %s%n", bytes));
// show the extra bytes as a disassembly
byte[] extraBuffer = new byte[length];
System.arraycopy (buffer, ptr, extraBuffer, 0, extraBuffer.length);
AssemblerProgram assemblerProgram =
new AssemblerProgram ("extra", extraBuffer, programLoadAddress + ptr);
text.append ("\n");
text.append (assemblerProgram.getText ());
}
return Utility.rtrim (text);
@ -817,9 +847,9 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
private String getDisplayToken (byte b)
// ---------------------------------------------------------------------------------//
{
if (Utility.isHighBitSet (b))
if (isHighBitSet (b))
return ApplesoftConstants.tokens[b & 0x7F];
else if (Utility.isDigit (b) || Utility.isLetter (b))
else if (isDigit (b) || isLetter (b))
return "";
return "*******";
}
@ -851,7 +881,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
int programLoadAddress = 0;
if (buffer.length > 1)
{
int offset = Utility.unsignedShort (buffer, 0);
int offset = unsignedShort (buffer, 0);
programLoadAddress = offset - getLineLength (0);
}
return programLoadAddress;
@ -861,7 +891,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
private int getLineLength (int ptr)
// ---------------------------------------------------------------------------------//
{
int offset = Utility.unsignedShort (buffer, ptr);
int offset = unsignedShort (buffer, ptr);
if (offset == 0)
return 0;

View File

@ -1,5 +1,8 @@
package com.bytezone.diskbrowser.applefile;
import static com.bytezone.diskbrowser.utilities.Utility.isDigit;
import static com.bytezone.diskbrowser.utilities.Utility.isLetter;
import com.bytezone.diskbrowser.gui.BasicPreferences;
import com.bytezone.diskbrowser.utilities.Utility;
@ -23,13 +26,6 @@ public abstract class BasicProgram extends AbstractFile
super (name, buffer);
}
// ---------------------------------------------------------------------------------//
boolean isHighBitSet (byte value)
// ---------------------------------------------------------------------------------//
{
return (value & 0x80) != 0;
}
// ---------------------------------------------------------------------------------//
boolean isControlCharacter (byte value)
// ---------------------------------------------------------------------------------//
@ -38,20 +34,6 @@ public abstract class BasicProgram extends AbstractFile
return val > 0 && val < 32;
}
// ---------------------------------------------------------------------------------//
boolean isDigit (byte value)
// ---------------------------------------------------------------------------------//
{
return value >= 0x30 && value <= 0x39;
}
// ---------------------------------------------------------------------------------//
boolean isLetter (byte value)
// ---------------------------------------------------------------------------------//
{
return value >= 0x41 && value <= 0x5A;
}
// ---------------------------------------------------------------------------------//
boolean isPossibleVariable (byte value)
// ---------------------------------------------------------------------------------//

View File

@ -1,9 +1,11 @@
package com.bytezone.diskbrowser.applefile;
import static com.bytezone.diskbrowser.utilities.Utility.isHighBitSet;
import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.utilities.Utility;
import com.bytezone.diskbrowser.utilities.Utility;;
// -----------------------------------------------------------------------------------//
public class BasicProgramGS extends BasicProgram

View File

@ -1,5 +1,7 @@
package com.bytezone.diskbrowser.applefile;
import static com.bytezone.diskbrowser.utilities.Utility.unsignedShort;
import java.util.ArrayList;
import java.util.List;
@ -26,8 +28,8 @@ public class SourceLine implements ApplesoftConstants
this.buffer = buffer;
linePtr = ptr;
addressNext = Utility.unsignedShort (buffer, ptr);
lineNumber = Utility.unsignedShort (buffer, ptr + 2);
addressNext = unsignedShort (buffer, ptr);
lineNumber = unsignedShort (buffer, ptr + 2);
int startPtr = ptr += 4; // skip link to next line and lineNumber
boolean inString = false; // can toggle

View File

@ -1,5 +1,11 @@
package com.bytezone.diskbrowser.applefile;
import static com.bytezone.diskbrowser.utilities.Utility.isDigit;
import static com.bytezone.diskbrowser.utilities.Utility.isHighBitSet;
import static com.bytezone.diskbrowser.utilities.Utility.isLetter;
import static com.bytezone.diskbrowser.utilities.Utility.isPossibleNumber;
import static com.bytezone.diskbrowser.utilities.Utility.isPossibleVariable;
import java.util.ArrayList;
import java.util.List;
@ -64,12 +70,12 @@ public class SubLine implements ApplesoftConstants
else
{
ptr = startPtr;
if (Utility.isDigit (firstByte)) // split IF xx THEN nnn
if (isDigit (firstByte)) // split IF xx THEN nnn
{
addXref (getLineNumber (buffer, startPtr), gotoLines);
return;
}
else if (Utility.isLetter (firstByte)) // variable assignment
else if (isLetter (firstByte)) // variable assignment
setEqualsPosition ();
else if (isEndOfLine (firstByte)) // empty subline
return;
@ -130,10 +136,9 @@ public class SubLine implements ApplesoftConstants
continue;
}
if (Utility.isPossibleVariable (b) || Utility.isPossibleNumber (b))
if (isPossibleVariable (b) || isPossibleNumber (b))
{
if (var.isEmpty () && Utility.isPossibleNumber (b)
&& buffer[ptr - 2] == TOKEN_MINUS)
if (var.isEmpty () && isPossibleNumber (b) && buffer[ptr - 2] == TOKEN_MINUS)
var = "-";
var += (char) b;
@ -197,7 +202,7 @@ public class SubLine implements ApplesoftConstants
if (var.length () == 0)
return;
if (!Utility.isLetter ((byte) var.charAt (0)))
if (!isLetter ((byte) var.charAt (0)))
{
if (is (TOKEN_GOTO) || is (TOKEN_GOSUB) || is (TOKEN_ON) || is (TOKEN_ONERR))
return; // ignore line numbers
@ -311,7 +316,7 @@ public class SubLine implements ApplesoftConstants
if (chunk.isEmpty ())
continue;
b = (byte) chunk.charAt (0);
if (Utility.isPossibleNumber (b) || b == Utility.ASCII_MINUS)
if (isPossibleNumber (b) || b == Utility.ASCII_MINUS)
{
if (!addNumber (chunk))
stringsText.add (chunk);
@ -424,7 +429,7 @@ public class SubLine implements ApplesoftConstants
{
int lineNumber = 0;
while (ptr < buffer.length && Utility.isDigit (buffer[ptr]))
while (ptr < buffer.length && isDigit (buffer[ptr]))
lineNumber = lineNumber * 10 + (buffer[ptr++] & 0xFF) - 0x30;
return lineNumber;
@ -434,7 +439,7 @@ public class SubLine implements ApplesoftConstants
boolean isImpliedGoto ()
// ---------------------------------------------------------------------------------//
{
return (Utility.isDigit (buffer[startPtr]));
return (isDigit (buffer[startPtr]));
}
// Record the position of the equals sign so it can be aligned with adjacent lines.
@ -599,7 +604,7 @@ public class SubLine implements ApplesoftConstants
private boolean isToken (byte b)
// ---------------------------------------------------------------------------------//
{
return Utility.isHighBitSet (b);
return isHighBitSet (b);
}
// ---------------------------------------------------------------------------------//

View File

@ -59,19 +59,19 @@ public class DiskFactory
}
// ---------------------------------------------------------------------------------//
private static FormattedDisk create (String path)
private static FormattedDisk create (String pathName)
// ---------------------------------------------------------------------------------//
{
if (debug)
System.out.println ("\nFactory : " + path);
System.out.println ("\nFactory : " + pathName);
File file = new File (path);
File file = new File (pathName);
if (!file.exists ())
return null;
String suffix = path.substring (path.lastIndexOf (".") + 1).toLowerCase ();
String suffix = pathName.substring (pathName.lastIndexOf (".") + 1).toLowerCase ();
Boolean compressed = false;
Path originalPath = Paths.get (path);
Path originalPath = Paths.get (pathName);
if ("gz".equals (suffix))
{
@ -79,7 +79,7 @@ public class DiskFactory
System.out.println (" ** gzip **");
try
{
InputStream in = new GZIPInputStream (new FileInputStream (path));
InputStream in = new GZIPInputStream (new FileInputStream (pathName));
File tmp = File.createTempFile ("gzip", null);
FileOutputStream fos = new FileOutputStream (tmp);
@ -108,7 +108,7 @@ public class DiskFactory
System.out.println (" ** zip **");
try
{
ZipFile zipFile = new ZipFile (path);
ZipFile zipFile = new ZipFile (pathName);
Enumeration<? extends ZipEntry> entries = zipFile.entries ();
while (entries.hasMoreElements ()) // loop until first valid name
@ -458,7 +458,7 @@ public class DiskFactory
// empty boot sector
if (checksum != 227968344L && false)
System.out.println ("Unknown checksum : " + checksum + " : " + path);
System.out.println ("Unknown checksum : " + checksum + " : " + pathName);
}
if (debug)