Split DIM option

This commit is contained in:
Denis Molony 2020-12-24 18:41:35 +10:00
parent 331cff059f
commit f84e0b0ce7
3 changed files with 125 additions and 78 deletions

View File

@ -5,6 +5,8 @@ import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.bytezone.diskbrowser.utilities.HexFormatter;
import com.bytezone.diskbrowser.utilities.Utility;
@ -17,6 +19,7 @@ public class ApplesoftBasicProgram extends BasicProgram
private static final byte TOKEN_NEXT = (byte) 0x82;
private static final byte TOKEN_DATA = (byte) 0x83;
private static final byte TOKEN_INPUT = (byte) 0x84;
private static final byte TOKEN_DIM = (byte) 0x86;
private static final byte TOKEN_LET = (byte) 0xAA;
private static final byte TOKEN_GOTO = (byte) 0xAB;
private static final byte TOKEN_IF = (byte) 0xAD;
@ -171,6 +174,11 @@ public class ApplesoftBasicProgram extends BasicProgram
List<String> lines = splitLine (lineText, basicPreferences.wrapDataAt, ',');
addSplitLines (lines, text);
}
else if (subline.is (TOKEN_DIM) && basicPreferences.splitDim)
{
List<String> lines = splitDim (lineText);
addSplitLines (lines, text);
}
else
text.append (lineText);
@ -348,7 +356,7 @@ public class ApplesoftBasicProgram extends BasicProgram
while (firstSpace < line.length () && line.charAt (firstSpace) != ' ')
++firstSpace;
List<String> remarks = new ArrayList<> ();
List<String> lines = new ArrayList<> ();
while (line.length () > wrapLength)
{
int max = Math.min (wrapLength, line.length () - 1);
@ -356,11 +364,31 @@ public class ApplesoftBasicProgram extends BasicProgram
--max;
if (max == 0)
break;
remarks.add (line.substring (0, max + 1));
lines.add (line.substring (0, max + 1));
line = " ".substring (0, firstSpace + 1) + line.substring (max + 1);
}
remarks.add (line);
return remarks;
lines.add (line);
return lines;
}
// ---------------------------------------------------------------------------------//
private List<String> splitDim (String line)
// ---------------------------------------------------------------------------------//
{
List<String> lines = new ArrayList<> ();
System.out.println (line);
Pattern p = Pattern.compile ("[A-Z][A-Z0-9]*[$%]?\\([0-9,]*\\),?");
Matcher m = p.matcher (line);
while (m.find ())
lines.add (" " + m.group ());
if (lines.size () > 0)
lines.set (0, "DIM " + lines.get (0).trim ());
return lines;
}
// ---------------------------------------------------------------------------------//
@ -699,86 +727,96 @@ public class ApplesoftBasicProgram extends BasicProgram
this.length = length;
byte b = buffer[startPtr];
if (isHighBitSet (b))
{
switch (b)
{
case TOKEN_FOR:
int p = startPtr + 1;
while (buffer[p] != TOKEN_EQUALS)
forVariable += (char) buffer[p++];
break;
case TOKEN_NEXT:
if (length == 2) // no variables
nextVariables = new String[0];
else
{
String varList = new String (buffer, startPtr + 1, length - 2);
nextVariables = varList.split (",");
}
break;
case TOKEN_LET:
recordEqualsPosition ();
break;
case TOKEN_GOTO:
int targetLine = getLineNumber (buffer, startPtr + 1);
addXref (targetLine, gotoLines);
break;
case TOKEN_GOSUB:
targetLine = getLineNumber (buffer, startPtr + 1);
addXref (targetLine, gosubLines);
break;
case TOKEN_ON:
p = startPtr + 1;
int max = startPtr + length - 1;
while (p < max && buffer[p] != TOKEN_GOTO && buffer[p] != TOKEN_GOSUB)
{
if (isHighBitSet (buffer[p]))
{
int val = buffer[p] & 0x7F;
if (val < ApplesoftConstants.tokens.length)
onExpression += " " + ApplesoftConstants.tokens[val];
}
else
onExpression += (char) (buffer[p]);
p++;
}
// System.out.println (onExpression); // may contain symbols +,- etc
switch (buffer[p++])
{
case TOKEN_GOSUB:
for (int destLine : getLineNumbers (buffer, p))
addXref (destLine, gosubLines);
break;
case TOKEN_GOTO:
for (int destLine : getLineNumbers (buffer, p))
addXref (destLine, gotoLines);
break;
default:
System.out.println ("GOTO / GOSUB not found");
}
break;
}
}
doToken (b);
else if (isDigit (b))
doDigit ();
else
doAlpha ();
}
private void doToken (byte b)
{
switch (b)
{
if (isDigit (b)) // numeric, so must be a line number
{
int targetLine = getLineNumber (buffer, startPtr);
addXref (targetLine, gotoLines);
}
else
case TOKEN_FOR:
int p = startPtr + 1;
while (buffer[p] != TOKEN_EQUALS)
forVariable += (char) buffer[p++];
break;
case TOKEN_NEXT:
if (length == 2) // no variables
nextVariables = new String[0];
else
{
String varList = new String (buffer, startPtr + 1, length - 2);
nextVariables = varList.split (",");
}
break;
case TOKEN_LET:
recordEqualsPosition ();
break;
case TOKEN_GOTO:
int targetLine = getLineNumber (buffer, startPtr + 1);
addXref (targetLine, gotoLines);
break;
case TOKEN_GOSUB:
targetLine = getLineNumber (buffer, startPtr + 1);
addXref (targetLine, gosubLines);
break;
case TOKEN_ON:
p = startPtr + 1;
int max = startPtr + length - 1;
while (p < max && buffer[p] != TOKEN_GOTO && buffer[p] != TOKEN_GOSUB)
{
if (isHighBitSet (buffer[p]))
{
int val = buffer[p] & 0x7F;
if (val < ApplesoftConstants.tokens.length)
onExpression += " " + ApplesoftConstants.tokens[val];
}
else
onExpression += (char) (buffer[p]);
p++;
}
// System.out.println (onExpression); // may contain symbols +,- etc
switch (buffer[p++])
{
case TOKEN_GOSUB:
for (int destLine : getLineNumbers (buffer, p))
addXref (destLine, gosubLines);
break;
case TOKEN_GOTO:
for (int destLine : getLineNumbers (buffer, p))
addXref (destLine, gotoLines);
break;
default:
System.out.println ("GOTO / GOSUB not found");
}
break;
}
}
private void doDigit ()
{
int targetLine = getLineNumber (buffer, startPtr);
addXref (targetLine, gotoLines);
}
private void doAlpha ()
{
recordEqualsPosition ();
}
private List<Integer> getLineNumbers (byte[] buffer, int ptr)
{
List<Integer> lineNumbers = new ArrayList<> ();

View File

@ -16,6 +16,7 @@ public class BasicPreferences
public boolean deleteExtraRemSpace = false;
public boolean deleteExtraDataSpace = false;
public boolean showXref = false;
public boolean splitDim = false;
public int wrapPrintAt = 0;
public int wrapRemAt = 60;
public int wrapDataAt = 60;
@ -42,7 +43,8 @@ public class BasicPreferences
text.append (String.format ("Delete extra DATA space .. %s%n", deleteExtraDataSpace));
text.append (String.format ("Wrap PRINT at ............ %d%n", wrapPrintAt));
text.append (String.format ("Wrap REM at .............. %d%n", wrapRemAt));
text.append (String.format ("Wrap DATA at ............. %d", wrapDataAt));
text.append (String.format ("Wrap DATA at ............. %d%n", wrapDataAt));
text.append (String.format ("Split DIM ................ %d", splitDim));
return text.toString ();
}

View File

@ -43,6 +43,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
private static final String PREFS_SCALE = "scale";
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";
@ -131,6 +132,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
// Applesoft menu items
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 =
@ -234,6 +236,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
applesoftMenu.add (showHeaderItem);
applesoftMenu.add (splitRemarkItem);
applesoftMenu.add (splitDimItem);
applesoftMenu.add (alignAssignItem);
applesoftMenu.add (showBasicTargetsItem);
applesoftMenu.add (onlyShowTargetLinesItem);
@ -295,6 +298,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
};
splitRemarkItem.addActionListener (basicPreferencesAction);
splitDimItem.addActionListener (basicPreferencesAction);
alignAssignItem.addActionListener (basicPreferencesAction);
showBasicTargetsItem.addActionListener (basicPreferencesAction);
onlyShowTargetLinesItem.addActionListener (basicPreferencesAction);
@ -346,6 +350,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
// ---------------------------------------------------------------------------------//
{
basicPreferences.splitRem = splitRemarkItem.isSelected ();
basicPreferences.splitDim = splitDimItem.isSelected ();
basicPreferences.alignAssign = alignAssignItem.isSelected ();
basicPreferences.showCaret = showCaretItem.isSelected ();
basicPreferences.showThen = showThenItem.isSelected ();
@ -504,6 +509,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
prefs.putInt (PREFS_SCALE, scale);
prefs.putBoolean (PREFS_SPLIT_REMARKS, splitRemarkItem.isSelected ());
prefs.putBoolean (PREFS_SPLIT_DIM, splitDimItem.isSelected ());
prefs.putBoolean (PREFS_ALIGN_ASSIGN, alignAssignItem.isSelected ());
prefs.putBoolean (PREFS_SHOW_CARET, showCaretItem.isSelected ());
prefs.putBoolean (PREFS_SHOW_THEN, showThenItem.isSelected ());
@ -555,6 +561,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
}
splitRemarkItem.setSelected (prefs.getBoolean (PREFS_SPLIT_REMARKS, false));
splitDimItem.setSelected (prefs.getBoolean (PREFS_SPLIT_DIM, false));
alignAssignItem.setSelected (prefs.getBoolean (PREFS_ALIGN_ASSIGN, true));
showCaretItem.setSelected (prefs.getBoolean (PREFS_SHOW_CARET, false));
showThenItem.setSelected (prefs.getBoolean (PREFS_SHOW_THEN, true));