dmolony-DiskBrowser/src/com/bytezone/diskbrowser/applefile/DebugBasicFormatter.java

104 lines
3.6 KiB
Java
Raw Permalink Normal View History

2021-03-03 13:19:13 +00:00
package com.bytezone.diskbrowser.applefile;
2021-03-04 03:57:49 +00:00
import static com.bytezone.diskbrowser.utilities.Utility.ASCII_COLON;
2021-03-03 13:19:13 +00:00
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 com.bytezone.diskbrowser.gui.BasicPreferences;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class DebugBasicFormatter extends BasicFormatter
// -----------------------------------------------------------------------------------//
{
2021-03-03 23:23:20 +00:00
int endPtr;
2021-03-03 13:19:13 +00:00
// ---------------------------------------------------------------------------------//
public DebugBasicFormatter (ApplesoftBasicProgram program,
BasicPreferences basicPreferences)
// ---------------------------------------------------------------------------------//
{
super (program, basicPreferences);
2021-03-03 23:23:20 +00:00
endPtr = program.getEndPtr ();
2021-03-03 13:19:13 +00:00
}
// ---------------------------------------------------------------------------------//
@Override
2021-03-09 06:23:05 +00:00
public void append (StringBuilder text)
2021-03-03 13:19:13 +00:00
// ---------------------------------------------------------------------------------//
{
int loadAddress = getLoadAddress ();
for (SourceLine sourceLine : sourceLines)
{
text.append (String.format ("%5d %s%n", sourceLine.lineNumber,
HexFormatter.formatNoHeader (buffer, sourceLine.linePtr, 4,
loadAddress + sourceLine.linePtr)));
for (SubLine subline : sourceLine.sublines)
{
String token = getDisplayToken (buffer[subline.startPtr]);
String formattedHex = HexFormatter.formatNoHeader (buffer, subline.startPtr,
subline.length, loadAddress + subline.startPtr);
for (String bytes : formattedHex.split (NEWLINE))
{
text.append (String.format (" %-8s %s%n", token, bytes));
token = "";
}
}
text.append (NEWLINE);
}
// check for assembler routines after the basic code
if (endPtr < buffer.length)
{
int length = buffer.length - endPtr;
int ptr = endPtr;
if (length >= 2)
{
text.append (" ");
text.append (HexFormatter.formatNoHeader (buffer, endPtr, 2, loadAddress + ptr));
text.append ("\n\n");
ptr += 2;
length -= 2;
}
if (length > 0)
{
// show the extra bytes as a hex dump
String formattedHex = HexFormatter.formatNoHeader (buffer, ptr,
buffer.length - ptr, loadAddress + ptr);
for (String bytes : formattedHex.split (NEWLINE))
text.append (String.format (" %s%n", bytes));
}
if (length > 1)
{
// 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, loadAddress + ptr);
text.append ("\n");
text.append (assemblerProgram.getText ());
}
}
}
// ---------------------------------------------------------------------------------//
private String getDisplayToken (byte b)
// ---------------------------------------------------------------------------------//
{
if (isHighBitSet (b))
return ApplesoftConstants.tokens[b & 0x7F];
2021-03-04 03:57:49 +00:00
if (isDigit (b) || isLetter (b) || b == ASCII_COLON || b == 0)
2021-03-03 13:19:13 +00:00
return "";
return "*******";
}
}