abandoned load address indexing

This commit is contained in:
Denis Molony 2021-07-29 09:33:41 +10:00
parent a8574d24f8
commit 4aefc8b695

View File

@ -60,9 +60,9 @@ public class CPMBasicFile extends BasicProgram
while (buffer[ptr] != 0) while (buffer[ptr] != 0)
ptr++; ptr++;
int loadAddress = getShort (buffer, 1) - ptr - 1; // int loadAddress = getShort (buffer, 1) - ptr - 1;
if (!validate (buffer, loadAddress)) // if (!validate (buffer, loadAddress))
System.out.println ("Invalid load address"); // System.out.println ("Invalid load address");
if (showDebugText) if (showDebugText)
return debugText (loadAddress); return debugText (loadAddress);
@ -80,11 +80,14 @@ public class CPMBasicFile extends BasicProgram
text.append (String.format (" %d ", lineNumber)); text.append (String.format (" %d ", lineNumber));
ptr += 4; ptr += 4;
int end = nextAddress - loadAddress - 1; // int end = nextAddress - loadAddress - 1;
while (ptr < end) while (true)
{ {
int val = buffer[ptr++] & 0xFF; int val = buffer[ptr++] & 0xFF;
if (val == 0)
break;
if (val >= 0x80) if (val >= 0x80)
{ {
if (val == 0xFF) if (val == 0xFF)
@ -186,9 +189,11 @@ public class CPMBasicFile extends BasicProgram
text.append (String.format ("<%02X>", val)); text.append (String.format ("<%02X>", val));
} }
} }
System.out.println (); System.out.println ();
ptr = nextAddress - loadAddress; // ptr = nextAddress - loadAddress;
// ptr++;
text.append ("\n"); text.append ("\n");
} }
@ -214,38 +219,27 @@ public class CPMBasicFile extends BasicProgram
break; break;
int lineNumber = getShort (buffer, ptr + 2); int lineNumber = getShort (buffer, ptr + 2);
lastPtr = ptr; lastPtr = ptr;
ptr = nextAddress - loadAddress;
text.append (String.format (" %d ", lineNumber)); ptr += 4;
text.append (HexFormatter.getHexString (buffer, lastPtr + 4, ptr - lastPtr - 4));
text.append ("\n"); int val;
while ((val = buffer[ptr++]) != 0)
{
ptr += switch (val)
{
case 0x0C, 0x0E, 0x1C -> 2; // 2 byte numeric
case 0x1D -> 4; // 4 byte single precision
case 0x1F -> 8; // 8 byte double precision
case 0x0F, 0xFF -> 1; // 1 byte numeric, function table entry
default -> 0;
};
}
text.append (String.format (" %d %s%n", lineNumber,
HexFormatter.getHexString (buffer, lastPtr + 4, ptr - lastPtr - 4)));
} }
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
private boolean validate (byte[] buffer, int loadAddress)
// ---------------------------------------------------------------------------------//
{
// System.out.printf ("Load Address: %04X%n", loadAddress);
int ptr = 1;
while (ptr < buffer.length)
{
int nextAddress = getShort (buffer, ptr);
// System.out.printf ("%04X%n", nextAddress);
if (nextAddress == 0)
return true;
ptr = nextAddress - loadAddress;
if (ptr < 0 || ptr >= buffer.length)
return false;
if (buffer[ptr - 1] != 0) // end of previous line
return false;
}
return false;
}
} }