mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-06 06:29:27 +00:00
list CALLs option
This commit is contained in:
parent
a0d702be73
commit
bc2c0b0abd
|
@ -20,6 +20,7 @@ public class ApplesoftBasicProgram extends BasicProgram
|
|||
|
||||
final Map<Integer, List<Integer>> gotoLines = new TreeMap<> ();
|
||||
final Map<Integer, List<Integer>> gosubLines = new TreeMap<> ();
|
||||
final Map<String, List<Integer>> callLines = new TreeMap<> ();
|
||||
private final Map<String, List<Integer>> symbolLines = new TreeMap<> ();
|
||||
private final Map<String, List<String>> uniqueSymbols = new TreeMap<> ();
|
||||
|
||||
|
@ -55,6 +56,8 @@ public class ApplesoftBasicProgram extends BasicProgram
|
|||
addXref (line.lineNumber, targetLine, gosubLines);
|
||||
for (int targetLine : subline.getGotoLines ())
|
||||
addXref (line.lineNumber, targetLine, gotoLines);
|
||||
if (subline.callTarget != null)
|
||||
addXref (line.lineNumber, subline.callTarget, callLines);
|
||||
}
|
||||
}
|
||||
endPtr = ptr;
|
||||
|
@ -94,6 +97,19 @@ public class ApplesoftBasicProgram extends BasicProgram
|
|||
lines.add (sourceLine);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void addXref (int sourceLine, String target, Map<String, List<Integer>> map)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
List<Integer> lines = map.get (target);
|
||||
if (lines == null)
|
||||
{
|
||||
lines = new ArrayList<> ();
|
||||
map.put (target, lines);
|
||||
}
|
||||
lines.add (sourceLine);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String getText ()
|
||||
|
@ -135,11 +151,11 @@ public class ApplesoftBasicProgram extends BasicProgram
|
|||
// - see P.CREATE on Diags2E.DSK
|
||||
if (subline.is (ApplesoftConstants.TOKEN_REM) && subline.containsToken ())
|
||||
{
|
||||
int address = subline.getAddress () + 1; // skip the REM token
|
||||
int address = getLoadAddress () + subline.startPtr + 1; // skip the REM token
|
||||
fullText.append (text + String.format ("REM - Inline assembler @ $%02X (%d)%n",
|
||||
address, address));
|
||||
String padding = " ".substring (0, text.length () + 2);
|
||||
for (String asm : subline.getAssembler ())
|
||||
for (String asm : getRemAssembler (subline))
|
||||
fullText.append (padding + asm + "\n");
|
||||
continue;
|
||||
}
|
||||
|
@ -275,10 +291,13 @@ public class ApplesoftBasicProgram extends BasicProgram
|
|||
}
|
||||
|
||||
if (basicPreferences.showXref && !gosubLines.isEmpty ())
|
||||
showLines (fullText, gosubLines, " GOSUB");
|
||||
showIntegerLines (fullText, gosubLines, " GOSUB");
|
||||
|
||||
if (basicPreferences.showXref && !gotoLines.isEmpty ())
|
||||
showLines (fullText, gotoLines, " GOTO");
|
||||
showIntegerLines (fullText, gotoLines, " GOTO");
|
||||
|
||||
if (basicPreferences.showCalls && !callLines.isEmpty ())
|
||||
showStringLines (fullText, callLines, " CALL");
|
||||
|
||||
if (basicPreferences.showSymbols && !symbolLines.isEmpty ())
|
||||
{
|
||||
|
@ -322,7 +341,7 @@ public class ApplesoftBasicProgram extends BasicProgram
|
|||
|
||||
if (basicPreferences.listStrings && stringsLine.size () > 0)
|
||||
{
|
||||
heading (fullText, " Line Strings");
|
||||
heading (fullText, " Line String");
|
||||
for (int i = 0; i < stringsLine.size (); i++)
|
||||
fullText.append (
|
||||
String.format (" %6s %s%n", stringsLine.get (i), stringsText.get (i)));
|
||||
|
@ -352,8 +371,8 @@ public class ApplesoftBasicProgram extends BasicProgram
|
|||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void showLines (StringBuilder fullText, Map<Integer, List<Integer>> lines,
|
||||
String heading)
|
||||
private void showIntegerLines (StringBuilder fullText,
|
||||
Map<Integer, List<Integer>> lines, String heading)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
heading (fullText, heading);
|
||||
|
@ -365,6 +384,20 @@ public class ApplesoftBasicProgram extends BasicProgram
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void showStringLines (StringBuilder fullText, Map<String, List<Integer>> lines,
|
||||
String heading)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
heading (fullText, heading);
|
||||
for (String target : lines.keySet ())
|
||||
{
|
||||
String list = lines.get (target).toString ();
|
||||
list = list.substring (1, list.length () - 1);
|
||||
fullText.append (String.format (" %6s %s%n", target, list));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private int getLongestVarName ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
@ -707,6 +740,17 @@ public class ApplesoftBasicProgram extends BasicProgram
|
|||
return pgm.toString ();
|
||||
}
|
||||
|
||||
// A REM statement might conceal an assembler routine
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private String[] getRemAssembler (SubLine subline)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
AssemblerProgram program = new AssemblerProgram ("REM assembler",
|
||||
subline.getBuffer (), getLoadAddress () + subline.startPtr + 1);
|
||||
|
||||
return program.getAssembler ().split ("\n");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void addHeader (StringBuilder pgm)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
@ -790,14 +834,14 @@ public class ApplesoftBasicProgram extends BasicProgram
|
|||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int ptr = symbol.length () - 1;
|
||||
|
||||
if (symbol.charAt (ptr) == Utility.ASCII_LEFT_BRACKET) // array
|
||||
ptr--;
|
||||
|
||||
if (symbol.charAt (ptr) == Utility.ASCII_DOLLAR // string
|
||||
|| symbol.charAt (ptr) == Utility.ASCII_PERCENT) // integer
|
||||
ptr--;
|
||||
|
||||
String unique =
|
||||
(ptr <= 1) ? symbol : symbol.substring (0, 2) + symbol.substring (ptr + 1);
|
||||
return unique;
|
||||
return (ptr <= 1) ? symbol : symbol.substring (0, 2) + symbol.substring (ptr + 1);
|
||||
}
|
||||
}
|
|
@ -44,6 +44,7 @@ public interface ApplesoftConstants
|
|||
static final byte TOKEN_DATA = (byte) 0x83;
|
||||
static final byte TOKEN_INPUT = (byte) 0x84;
|
||||
static final byte TOKEN_DIM = (byte) 0x86;
|
||||
static final byte TOKEN_CALL = (byte) 0x8C;
|
||||
static final byte TOKEN_ONERR = (byte) 0xA5;
|
||||
static final byte TOKEN_LET = (byte) 0xAA;
|
||||
static final byte TOKEN_GOTO = (byte) 0xAB;
|
||||
|
|
|
@ -10,10 +10,11 @@ public class SubLine
|
|||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
SourceLine parent;
|
||||
ApplesoftBasicProgram program;
|
||||
|
||||
int startPtr;
|
||||
int length;
|
||||
String[] nextVariables;
|
||||
String callTarget;
|
||||
String forVariable = "";
|
||||
int equalsPosition; // used for aligning the equals sign
|
||||
byte[] buffer;
|
||||
|
@ -30,8 +31,6 @@ public class SubLine
|
|||
this.startPtr = startPtr;
|
||||
this.length = length;
|
||||
|
||||
program = parent.parent;
|
||||
|
||||
this.buffer = parent.buffer;
|
||||
byte firstByte = buffer[startPtr];
|
||||
|
||||
|
@ -173,6 +172,15 @@ public class SubLine
|
|||
addXref (targetLine, gotoLines);
|
||||
}
|
||||
break;
|
||||
|
||||
case ApplesoftConstants.TOKEN_CALL:
|
||||
byte[] buffer = getBuffer ();
|
||||
|
||||
if (buffer[0] == (byte) 0xC9) // negative
|
||||
callTarget = "-" + new String (buffer, 1, buffer.length - 1);
|
||||
else
|
||||
callTarget = new String (buffer, 0, buffer.length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,13 +372,6 @@ public class SubLine
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public int getAddress ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return program.getLoadAddress () + startPtr;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String getAlignedText (int alignEqualsPos)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
@ -385,17 +386,18 @@ public class SubLine
|
|||
return line.toString ();
|
||||
}
|
||||
|
||||
// A REM statement might conceal an assembler routine
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String[] getAssembler ()
|
||||
public byte[] getBuffer ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
byte[] buffer2 = new byte[length - 1];
|
||||
// System.out.println (HexFormatter.format (buffer, startPtr, length));
|
||||
int len = length - 1;
|
||||
// System.out.printf ("%02X%n", buffer[startPtr + len]);
|
||||
if (buffer[startPtr + len] == Utility.ASCII_COLON || buffer[startPtr + len] == 0)
|
||||
len--;
|
||||
byte[] buffer2 = new byte[len];
|
||||
System.arraycopy (buffer, startPtr + 1, buffer2, 0, buffer2.length);
|
||||
AssemblerProgram program =
|
||||
new AssemblerProgram ("REM assembler", buffer2, getAddress () + 1);
|
||||
|
||||
return program.getAssembler ().split ("\n");
|
||||
return buffer2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
|
|
@ -16,6 +16,7 @@ public class BasicPreferences
|
|||
public boolean deleteExtraRemSpace = false;
|
||||
public boolean deleteExtraDataSpace = false;
|
||||
public boolean showXref = false;
|
||||
public boolean showCalls = false;
|
||||
public boolean showSymbols = false;
|
||||
public boolean showDuplicateSymbols = false;
|
||||
public boolean splitDim = false;
|
||||
|
@ -39,6 +40,7 @@ public class BasicPreferences
|
|||
text.append (String.format ("Show caret ............... %s%n", showCaret));
|
||||
text.append (String.format ("Show THEN ................ %s%n", showThen));
|
||||
text.append (String.format ("Show Xref ................ %s%n", showXref));
|
||||
text.append (String.format ("Show CALL ................ %s%n", showCalls));
|
||||
text.append (String.format ("Show symbols ............. %s%n", showSymbols));
|
||||
text.append (String.format ("Show duplicate symbols ... %s%n", showDuplicateSymbols));
|
||||
text.append (String.format ("List strings ............. %s%n", listStrings));
|
||||
|
|
|
@ -51,6 +51,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
|||
private static final String PREFS_SHOW_CARET = "showCaret";
|
||||
private static final String PREFS_SHOW_THEN = "showThen";
|
||||
private static final String PREFS_SHOW_XREF = "showXref";
|
||||
private static final String PREFS_SHOW_CALLS = "showCalls";
|
||||
private static final String PREFS_SHOW_SYMBOLS = "showSymbols";
|
||||
private static final String PREFS_SHOW_DUPLICATE_SYMBOLS = "showDuplicateSymbols";
|
||||
private static final String PREFS_LIST_STRINGS = "listStrings";
|
||||
|
@ -142,11 +143,12 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
|||
final JMenuItem showHeaderItem = new JCheckBoxMenuItem ("Show header");
|
||||
final JMenuItem showCaretItem = new JCheckBoxMenuItem ("Show caret");
|
||||
final JMenuItem showThenItem = new JCheckBoxMenuItem ("Show THEN after IF");
|
||||
final JMenuItem showXrefItem = new JCheckBoxMenuItem ("Show Xref");
|
||||
final JMenuItem showSymbolsItem = new JCheckBoxMenuItem ("Show variables");
|
||||
final JMenuItem showXrefItem = new JCheckBoxMenuItem ("List Xref");
|
||||
final JMenuItem showCallsItem = new JCheckBoxMenuItem ("List CALLs");
|
||||
final JMenuItem showSymbolsItem = new JCheckBoxMenuItem ("List variables");
|
||||
final JMenuItem showDuplicateSymbolsItem =
|
||||
new JCheckBoxMenuItem ("Show duplicate variables");
|
||||
final JMenuItem listStringsItem = new JCheckBoxMenuItem ("Show strings");
|
||||
new JCheckBoxMenuItem ("List duplicate variables");
|
||||
final JMenuItem listStringsItem = new JCheckBoxMenuItem ("List strings");
|
||||
final JMenuItem blankAfterReturn = new JCheckBoxMenuItem ("Blank line after RETURN");
|
||||
final JMenuItem deleteExtraRemSpace = new JCheckBoxMenuItem ("Delete extra REM space");
|
||||
final JMenuItem deleteExtraDataSpace =
|
||||
|
@ -247,13 +249,15 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
|||
applesoftMenu.add (onlyShowTargetLinesItem);
|
||||
applesoftMenu.add (showCaretItem);
|
||||
applesoftMenu.add (showThenItem);
|
||||
applesoftMenu.add (showXrefItem);
|
||||
applesoftMenu.add (showSymbolsItem);
|
||||
applesoftMenu.add (showDuplicateSymbolsItem);
|
||||
applesoftMenu.add (listStringsItem);
|
||||
applesoftMenu.add (blankAfterReturn);
|
||||
applesoftMenu.add (deleteExtraRemSpace);
|
||||
applesoftMenu.add (deleteExtraDataSpace);
|
||||
applesoftMenu.addSeparator ();
|
||||
applesoftMenu.add (showXrefItem);
|
||||
applesoftMenu.add (showCallsItem);
|
||||
applesoftMenu.add (showSymbolsItem);
|
||||
applesoftMenu.add (showDuplicateSymbolsItem);
|
||||
applesoftMenu.add (listStringsItem);
|
||||
|
||||
assemblerMenu.add (showAssemblerHeaderItem);
|
||||
assemblerMenu.add (showAssemblerTargetsItem);
|
||||
|
@ -313,6 +317,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
|||
showCaretItem.addActionListener (basicPreferencesAction);
|
||||
showThenItem.addActionListener (basicPreferencesAction);
|
||||
showXrefItem.addActionListener (basicPreferencesAction);
|
||||
showCallsItem.addActionListener (basicPreferencesAction);
|
||||
showSymbolsItem.addActionListener (basicPreferencesAction);
|
||||
showDuplicateSymbolsItem.addActionListener (basicPreferencesAction);
|
||||
listStringsItem.addActionListener (basicPreferencesAction);
|
||||
|
@ -364,6 +369,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
|||
basicPreferences.showCaret = showCaretItem.isSelected ();
|
||||
basicPreferences.showThen = showThenItem.isSelected ();
|
||||
basicPreferences.showXref = showXrefItem.isSelected ();
|
||||
basicPreferences.showCalls = showCallsItem.isSelected ();
|
||||
basicPreferences.showSymbols = showSymbolsItem.isSelected ();
|
||||
basicPreferences.showDuplicateSymbols = showDuplicateSymbolsItem.isSelected ();
|
||||
basicPreferences.listStrings = listStringsItem.isSelected ();
|
||||
|
@ -525,6 +531,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
|||
prefs.putBoolean (PREFS_SHOW_CARET, showCaretItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_THEN, showThenItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_XREF, showXrefItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_CALLS, showCallsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_SYMBOLS, showSymbolsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_DUPLICATE_SYMBOLS,
|
||||
showDuplicateSymbolsItem.isSelected ());
|
||||
|
@ -580,6 +587,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
|||
showCaretItem.setSelected (prefs.getBoolean (PREFS_SHOW_CARET, false));
|
||||
showThenItem.setSelected (prefs.getBoolean (PREFS_SHOW_THEN, true));
|
||||
showXrefItem.setSelected (prefs.getBoolean (PREFS_SHOW_XREF, false));
|
||||
showCallsItem.setSelected (prefs.getBoolean (PREFS_SHOW_CALLS, false));
|
||||
showSymbolsItem.setSelected (prefs.getBoolean (PREFS_SHOW_SYMBOLS, false));
|
||||
showDuplicateSymbolsItem
|
||||
.setSelected (prefs.getBoolean (PREFS_SHOW_DUPLICATE_SYMBOLS, false));
|
||||
|
|
Loading…
Reference in New Issue
Block a user