mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-02-20 04:29:02 +00:00
added option to not format applesoft
This commit is contained in:
parent
e7554f7856
commit
f5ca23da26
@ -17,6 +17,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
|
||||
{
|
||||
static final String underline = "----------------------------------------------------"
|
||||
+ "----------------------------------------------";
|
||||
|
||||
private final List<SourceLine> sourceLines = new ArrayList<> ();
|
||||
private final int endPtr;
|
||||
private final int longestVarName;
|
||||
@ -85,13 +86,52 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
|
||||
longestVarName = getLongestName ();
|
||||
formatLeft = longestVarName > 7 ? "%-" + longestVarName + "." + longestVarName + "s "
|
||||
: "%-7.7s ";
|
||||
formatRight = longestVarName > 7 ? "%" + longestVarName + "." + longestVarName + "s "
|
||||
: "%7.7s ";
|
||||
formatRight = formatLeft.replace ("-", "");
|
||||
|
||||
maxDigits = getMaxDigits ();
|
||||
formatLineNumber = "%" + maxDigits + "d ";
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private String list ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
if (basicPreferences.showHeader)
|
||||
addHeader (text);
|
||||
|
||||
int loadAddress = getLoadAddress ();
|
||||
int ptr = 0;
|
||||
int nextLine;
|
||||
byte b;
|
||||
|
||||
while ((nextLine = Utility.unsignedShort (buffer, ptr)) != 0)
|
||||
{
|
||||
int lineNumber = Utility.unsignedShort (buffer, ptr + 2);
|
||||
text.append (String.format ("%5d ", lineNumber));
|
||||
// text.append (
|
||||
// String.format ("%04X %04X %5d ", loadAddress + ptr, nextLine, lineNumber));
|
||||
ptr += 4;
|
||||
|
||||
while ((b = buffer[ptr++]) != 0)
|
||||
if (Utility.isHighBitSet (b))
|
||||
text.append (
|
||||
String.format (" %s ", ApplesoftConstants.tokens[b & 0x7F].trim ()));
|
||||
else
|
||||
text.append ((char) b);
|
||||
|
||||
assert ptr == nextLine - loadAddress;
|
||||
// ptr = nextLine - loadAddress;
|
||||
text.append ("\n");
|
||||
}
|
||||
|
||||
if (text.length () > 0)
|
||||
text.deleteCharAt (text.length () - 1);
|
||||
// text.append (String.format ("%04X %04X%n%n", loadAddress + ptr, nextLine));
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void checkVar (String var, int lineNumber, Map<String, List<Integer>> map,
|
||||
Map<String, List<String>> unique)
|
||||
@ -175,6 +215,9 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
|
||||
private String getProgramText ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (!basicPreferences.formatApplesoft)
|
||||
return list ();
|
||||
|
||||
int indentSize = 2;
|
||||
boolean insertBlankLine = false;
|
||||
|
||||
@ -383,6 +426,9 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
|
||||
private int getMaxDigits ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (sourceLines.size () == 0)
|
||||
return 4; // anything non-zero
|
||||
|
||||
SourceLine lastLine = sourceLines.get (sourceLines.size () - 1);
|
||||
return (lastLine.lineNumber + "").length ();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public interface ApplesoftConstants
|
||||
"RUN ", "IF ", "RESTORE ", "& ", // 0xAC
|
||||
"GOSUB ", "RETURN ", "REM ", "STOP ", // 0xB0
|
||||
"ON ", "WAIT ", "LOAD ", "SAVE ", // 0xB4
|
||||
"DEF", "POKE ", "PRINT ", "CONT", // 0xB8
|
||||
"DEF ", "POKE ", "PRINT ", "CONT", // 0xB8
|
||||
"LIST ", "CLEAR ", "GET ", "NEW ", // 0xBC
|
||||
"TAB(", "TO ", "FN ", "SPC(", // 0xC0
|
||||
"THEN ", "AT ", "NOT ", "STEP ", // 0xC4
|
||||
|
@ -39,8 +39,8 @@ public class SubLine implements ApplesoftConstants
|
||||
this.parent = parent;
|
||||
this.startPtr = startPtr;
|
||||
this.length = length;
|
||||
|
||||
this.buffer = parent.buffer;
|
||||
|
||||
byte firstByte = buffer[startPtr];
|
||||
|
||||
if (Utility.isHighBitSet (firstByte))
|
||||
@ -59,6 +59,7 @@ public class SubLine implements ApplesoftConstants
|
||||
|
||||
int ptr = startPtr;
|
||||
String var = "";
|
||||
|
||||
boolean inQuote = false;
|
||||
boolean inFunction = false;
|
||||
boolean inDefine = false;
|
||||
@ -120,6 +121,21 @@ public class SubLine implements ApplesoftConstants
|
||||
checkVar (var, (byte) 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void doDigit ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int targetLine = getLineNumber (buffer, startPtr);
|
||||
addXref (targetLine, gotoLines);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void doAlpha ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
recordEqualsPosition ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void checkFunction (String var, byte terminator)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@ -306,21 +322,6 @@ public class SubLine implements ApplesoftConstants
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void doDigit ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int targetLine = getLineNumber (buffer, startPtr);
|
||||
addXref (targetLine, gotoLines);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void doAlpha ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
recordEqualsPosition ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void addXref (int targetLine, List<Integer> list)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
@ -4,10 +4,11 @@ package com.bytezone.diskbrowser.gui;
|
||||
public class BasicPreferences
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public boolean showHeader = true;
|
||||
public boolean formatApplesoft = true;
|
||||
public boolean splitRem = false;
|
||||
public boolean alignAssign = true;
|
||||
public boolean showTargets = true;
|
||||
public boolean showHeader = true;
|
||||
public boolean onlyShowTargetLineNumbers = true;
|
||||
public boolean showCaret = false;
|
||||
public boolean showThen = true;
|
||||
@ -39,6 +40,7 @@ public class BasicPreferences
|
||||
text.append (
|
||||
String.format ("Only target lines ........ %s%n", onlyShowTargetLineNumbers));
|
||||
text.append (String.format ("Show header .............. %s%n", showHeader));
|
||||
text.append (String.format ("Format applesoft ......... %s%n", formatApplesoft));
|
||||
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));
|
||||
|
@ -4,6 +4,7 @@ import java.awt.Desktop;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.prefs.Preferences;
|
||||
@ -42,12 +43,13 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
private static final String PREFS_MONOCHROME = "monochrome";
|
||||
private static final String PREFS_SCALE = "scale";
|
||||
|
||||
private static final String PREFS_SHOW_HEADER = "showHeader";
|
||||
private static final String PREFS_FORMAT_APPLESOFT = "formatApplesoft";
|
||||
private static final String PREFS_SPLIT_REMARKS = "splitRemarks";
|
||||
private static final String PREFS_SPLIT_DIM = "splitDim";
|
||||
private static final String PREFS_ALIGN_ASSIGN = "alignAssign";
|
||||
private static final String PREFS_SHOW_TARGETS = "showTargets";
|
||||
private static final String PREFS_ONLY_SHOW_TARGETS = "onlyShowTargets";
|
||||
private static final String PREFS_SHOW_HEADER = "showHeader";
|
||||
private static final String PREFS_SHOW_CARET = "showCaret";
|
||||
private static final String PREFS_SHOW_THEN = "showThen";
|
||||
private static final String PREFS_SHOW_XREF = "showXref";
|
||||
@ -92,6 +94,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
private final List<TextPreferencesListener> textPreferencesListeners =
|
||||
new ArrayList<> ();
|
||||
|
||||
private List<JCheckBoxMenuItem> applesoftMenuItems;
|
||||
|
||||
JMenuBar menuBar = new JMenuBar ();
|
||||
JMenu fileMenu = new JMenu ("File");
|
||||
JMenu formatMenu = new JMenu ("Format");
|
||||
@ -136,13 +140,14 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
final JMenuItem scale3Item = new JRadioButtonMenuItem ("Scale 2");
|
||||
|
||||
// Applesoft menu items
|
||||
final JMenuItem showHeaderItem = new JCheckBoxMenuItem ("Show header");
|
||||
final JMenuItem showFormatApplesoftItem = new JCheckBoxMenuItem ("Format Applesoft");
|
||||
final JMenuItem splitRemarkItem = new JCheckBoxMenuItem ("Split remarks");
|
||||
final JMenuItem splitDimItem = new JCheckBoxMenuItem ("Split DIM");
|
||||
final JMenuItem alignAssignItem = new JCheckBoxMenuItem ("Align consecutive assign");
|
||||
final JMenuItem showBasicTargetsItem = new JCheckBoxMenuItem ("Show targets");
|
||||
final JMenuItem onlyShowTargetLinesItem =
|
||||
new JCheckBoxMenuItem ("Only show target line numbers");
|
||||
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 ("List GOSUB/GOTO");
|
||||
@ -246,6 +251,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
imageMenu.add (scale3Item);
|
||||
|
||||
applesoftMenu.add (showHeaderItem);
|
||||
applesoftMenu.add (showFormatApplesoftItem);
|
||||
applesoftMenu.addSeparator ();
|
||||
applesoftMenu.add (splitRemarkItem);
|
||||
applesoftMenu.add (splitDimItem);
|
||||
applesoftMenu.add (alignAssignItem);
|
||||
@ -274,6 +281,12 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
|
||||
prodosMenu.add (prodosSortDirectoriesItem);
|
||||
|
||||
applesoftMenuItems = new ArrayList (Arrays.asList (splitRemarkItem, splitDimItem,
|
||||
alignAssignItem, showBasicTargetsItem, onlyShowTargetLinesItem, showCaretItem,
|
||||
showThenItem, blankAfterReturn, deleteExtraRemSpace, deleteExtraDataSpace,
|
||||
showXrefItem, showCallsItem, showSymbolsItem, showFunctionsItem,
|
||||
showConstantsItem, listStringsItem, showDuplicateSymbolsItem));
|
||||
|
||||
ActionListener basicPreferencesAction = new ActionListener ()
|
||||
{
|
||||
@Override
|
||||
@ -314,24 +327,27 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
}
|
||||
};
|
||||
|
||||
splitRemarkItem.addActionListener (basicPreferencesAction);
|
||||
splitDimItem.addActionListener (basicPreferencesAction);
|
||||
alignAssignItem.addActionListener (basicPreferencesAction);
|
||||
showBasicTargetsItem.addActionListener (basicPreferencesAction);
|
||||
onlyShowTargetLinesItem.addActionListener (basicPreferencesAction);
|
||||
showHeaderItem.addActionListener (basicPreferencesAction);
|
||||
showCaretItem.addActionListener (basicPreferencesAction);
|
||||
showThenItem.addActionListener (basicPreferencesAction);
|
||||
showXrefItem.addActionListener (basicPreferencesAction);
|
||||
showCallsItem.addActionListener (basicPreferencesAction);
|
||||
showSymbolsItem.addActionListener (basicPreferencesAction);
|
||||
showFunctionsItem.addActionListener (basicPreferencesAction);
|
||||
showConstantsItem.addActionListener (basicPreferencesAction);
|
||||
showDuplicateSymbolsItem.addActionListener (basicPreferencesAction);
|
||||
listStringsItem.addActionListener (basicPreferencesAction);
|
||||
blankAfterReturn.addActionListener (basicPreferencesAction);
|
||||
deleteExtraRemSpace.addActionListener (basicPreferencesAction);
|
||||
deleteExtraDataSpace.addActionListener (basicPreferencesAction);
|
||||
showFormatApplesoftItem.addActionListener (basicPreferencesAction);
|
||||
// splitRemarkItem.addActionListener (basicPreferencesAction);
|
||||
// splitDimItem.addActionListener (basicPreferencesAction);
|
||||
// alignAssignItem.addActionListener (basicPreferencesAction);
|
||||
// showBasicTargetsItem.addActionListener (basicPreferencesAction);
|
||||
// onlyShowTargetLinesItem.addActionListener (basicPreferencesAction);
|
||||
// showCaretItem.addActionListener (basicPreferencesAction);
|
||||
// showThenItem.addActionListener (basicPreferencesAction);
|
||||
// showXrefItem.addActionListener (basicPreferencesAction);
|
||||
// showCallsItem.addActionListener (basicPreferencesAction);
|
||||
// showSymbolsItem.addActionListener (basicPreferencesAction);
|
||||
// showFunctionsItem.addActionListener (basicPreferencesAction);
|
||||
// showConstantsItem.addActionListener (basicPreferencesAction);
|
||||
// showDuplicateSymbolsItem.addActionListener (basicPreferencesAction);
|
||||
// listStringsItem.addActionListener (basicPreferencesAction);
|
||||
// blankAfterReturn.addActionListener (basicPreferencesAction);
|
||||
// deleteExtraRemSpace.addActionListener (basicPreferencesAction);
|
||||
// deleteExtraDataSpace.addActionListener (basicPreferencesAction);
|
||||
for (JMenuItem item : applesoftMenuItems)
|
||||
item.addActionListener (basicPreferencesAction);
|
||||
|
||||
showAssemblerTargetsItem.addActionListener (assemblerPreferencesAction);
|
||||
showAssemblerStringsItem.addActionListener (assemblerPreferencesAction);
|
||||
@ -367,10 +383,21 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
saveSectorsItem.setAction (saveSectorsAction);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void enableApplesoftMenuItems (boolean value)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
for (JMenuItem item : applesoftMenuItems)
|
||||
item.setEnabled (value);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void setBasicPreferences ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
basicPreferences.showHeader = showHeaderItem.isSelected ();
|
||||
basicPreferences.formatApplesoft = showFormatApplesoftItem.isSelected ();
|
||||
|
||||
basicPreferences.splitRem = splitRemarkItem.isSelected ();
|
||||
basicPreferences.splitDim = splitDimItem.isSelected ();
|
||||
basicPreferences.alignAssign = alignAssignItem.isSelected ();
|
||||
@ -386,10 +413,11 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
basicPreferences.blankAfterReturn = blankAfterReturn.isSelected ();
|
||||
basicPreferences.deleteExtraRemSpace = deleteExtraRemSpace.isSelected ();
|
||||
basicPreferences.deleteExtraDataSpace = deleteExtraDataSpace.isSelected ();
|
||||
basicPreferences.showHeader = showHeaderItem.isSelected ();
|
||||
basicPreferences.showTargets = showBasicTargetsItem.isSelected ();
|
||||
basicPreferences.onlyShowTargetLineNumbers = onlyShowTargetLinesItem.isSelected ();
|
||||
BasicProgram.setBasicPreferences (basicPreferences);
|
||||
|
||||
enableApplesoftMenuItems (basicPreferences.formatApplesoft);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@ -535,6 +563,9 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
int scale = scale1Item.isSelected () ? 1 : scale2Item.isSelected () ? 2 : 3;
|
||||
prefs.putInt (PREFS_SCALE, scale);
|
||||
|
||||
prefs.putBoolean (PREFS_SHOW_HEADER, showHeaderItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_FORMAT_APPLESOFT, showFormatApplesoftItem.isSelected ());
|
||||
|
||||
prefs.putBoolean (PREFS_SPLIT_REMARKS, splitRemarkItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SPLIT_DIM, splitDimItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_ALIGN_ASSIGN, alignAssignItem.isSelected ());
|
||||
@ -548,7 +579,6 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
prefs.putBoolean (PREFS_SHOW_DUPLICATE_SYMBOLS,
|
||||
showDuplicateSymbolsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_LIST_STRINGS, listStringsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_HEADER, showHeaderItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_TARGETS, showBasicTargetsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_ONLY_SHOW_TARGETS, onlyShowTargetLinesItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_BLANK_AFTER_RETURN, blankAfterReturn.isSelected ());
|
||||
@ -593,6 +623,9 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
break;
|
||||
}
|
||||
|
||||
showHeaderItem.setSelected (prefs.getBoolean (PREFS_SHOW_HEADER, true));
|
||||
showFormatApplesoftItem.setSelected (prefs.getBoolean (PREFS_FORMAT_APPLESOFT, true));
|
||||
|
||||
splitRemarkItem.setSelected (prefs.getBoolean (PREFS_SPLIT_REMARKS, false));
|
||||
splitDimItem.setSelected (prefs.getBoolean (PREFS_SPLIT_DIM, false));
|
||||
alignAssignItem.setSelected (prefs.getBoolean (PREFS_ALIGN_ASSIGN, true));
|
||||
@ -606,7 +639,6 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
showDuplicateSymbolsItem
|
||||
.setSelected (prefs.getBoolean (PREFS_SHOW_DUPLICATE_SYMBOLS, false));
|
||||
listStringsItem.setSelected (prefs.getBoolean (PREFS_LIST_STRINGS, false));
|
||||
showHeaderItem.setSelected (prefs.getBoolean (PREFS_SHOW_HEADER, true));
|
||||
showBasicTargetsItem.setSelected (prefs.getBoolean (PREFS_SHOW_TARGETS, false));
|
||||
onlyShowTargetLinesItem
|
||||
.setSelected (prefs.getBoolean (PREFS_ONLY_SHOW_TARGETS, false));
|
||||
|
Loading…
x
Reference in New Issue
Block a user