Applesoft ugly line-wrapping option

This commit is contained in:
Denis Molony 2021-02-22 13:09:45 +10:00
parent 5507271a74
commit 228c70e1ea
3 changed files with 120 additions and 29 deletions

View File

@ -129,32 +129,37 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
currentLine.append (String.format (" %d ", lineNumber));
ptr += 4;
while ((b = buffer[ptr++]) != 0)
if (isHighBitSet (b))
currentLine
.append (String.format (" %s ", ApplesoftConstants.tokens[b & 0x7F]));
else
switch (b)
if (basicPreferences.appleLineWrap)
ptr = append (currentLine, ptr);
else
while ((b = buffer[ptr++]) != 0)
if (isHighBitSet (b))
{
case Utility.ASCII_CR:
currentLine.append (NEWLINE);
break;
case Utility.ASCII_BACKSPACE:
if (currentLine.length () > 0)
currentLine.deleteCharAt (currentLine.length () - 1);
break;
case Utility.ASCII_LF:
int indent = getIndent (currentLine);
currentLine.append ("\n");
for (int i = 0; i < indent; i++)
currentLine.append (" ");
break;
default:
currentLine.append ((char) b);
String token = String.format (" %s ", ApplesoftConstants.tokens[b & 0x7F]);
currentLine.append (token);
}
else
switch (b)
{
case Utility.ASCII_CR:
currentLine.append (NEWLINE);
break;
case Utility.ASCII_BACKSPACE:
if (currentLine.length () > 0)
currentLine.deleteCharAt (currentLine.length () - 1);
break;
case Utility.ASCII_LF:
int indent = getIndent (currentLine);
currentLine.append ("\n");
for (int i = 0; i < indent; i++)
currentLine.append (" ");
break;
default:
currentLine.append ((char) b);
}
if (ptr != (linkField - loadAddress))
{
@ -165,16 +170,85 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
currentLine.append (NEWLINE);
// List<String> lines = wrap (text, 29);
// fullText.append (String.format ("%d %s%n", lineNumber, lines.get (0)));
// for (int i = 1; i < lines.size (); i++)
// fullText.append (String.format (" %s%n", lines.get (i)));
fullText.append (currentLine);
currentLine.setLength (0);
}
}
// ---------------------------------------------------------------------------------//
private int append (StringBuilder currentLine, int ptr)
// ---------------------------------------------------------------------------------//
{
byte b;
int left = 5;
int right = 33;
int cursor = currentLine.length ();
while ((b = buffer[ptr++]) != 0)
if (isHighBitSet (b))
{
String token = String.format (" %s ", ApplesoftConstants.tokens[b & 0x7F]);
currentLine.append (token);
cursor = increment (currentLine, cursor, token.length ());
}
else
switch (b)
{
case Utility.ASCII_CR:
currentLine.append (NEWLINE);
cursor = left;
break;
case Utility.ASCII_BACKSPACE:
if (currentLine.length () > 0)
{
currentLine.deleteCharAt (currentLine.length () - 1);
--cursor;
}
break;
case Utility.ASCII_LF:
int indent = getIndent (currentLine);
currentLine.append ("\n");
for (int i = 0; i < indent; i++)
currentLine.append (" ");
break;
default:
currentLine.append ((char) b);
cursor = increment (currentLine, cursor, 1);
}
return ptr;
}
// ---------------------------------------------------------------------------------//
private int increment (StringBuilder currentLine, int cursor, int size)
// ---------------------------------------------------------------------------------//
{
int left = 5;
int right = 33;
cursor += size;
if (cursor >= right)
{
if (cursor < 40)
{
cursor = left;
currentLine.append ("\n ".substring (0, left + 1));
}
else
// this is presumably a bug in the applesoft ROM
// see line 1610 in KEY-CAT on the UtilityCity.dsk
{
cursor = 0;
currentLine.append ("\n");
}
}
return cursor;
}
// ---------------------------------------------------------------------------------//
private void getUserFormat (StringBuilder fullText)
// ---------------------------------------------------------------------------------//

View File

@ -7,6 +7,7 @@ public class BasicPreferences
public boolean showHeader = true;
public boolean formatApplesoft = true;
public boolean showAllXref = true;
public boolean appleLineWrap = false;
public boolean splitRem = false;
public boolean alignAssign = true;
// public boolean showTargets = true;
@ -44,6 +45,7 @@ public class BasicPreferences
text.append (String.format ("Show header .............. %s%n", showHeader));
text.append (String.format ("Format applesoft ......... %s%n", formatApplesoft));
text.append (String.format ("Show All Xref ............ %s%n", showAllXref));
text.append (String.format ("Apple line wrap .......... %s%n", appleLineWrap));
text.append (String.format ("Show caret ............... %s%n", showCaret));
text.append (String.format ("Show THEN ................ %s%n", showThen));
text.append (String.format ("Show GOTO/GOSUB .......... %s%n", showXref));

View File

@ -48,6 +48,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
private static final String PREFS_SHOW_ALL_FORMAT = "formatApplesoft";
private static final String PREFS_SHOW_ALL_XREF = "showAllXref";
private static final String PREFS_APPLE_LINE_WRAP = "appleLineWrap";
private static final String PREFS_SPLIT_REMARKS = "splitRemarks";
private static final String PREFS_SPLIT_DIM = "splitDim";
private static final String PREFS_ALIGN_ASSIGN = "alignAssign";
@ -149,6 +151,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
final JMenuItem showAllFormatItem = new JCheckBoxMenuItem ("Enable Format options");
final JMenuItem showAllXrefItem = new JCheckBoxMenuItem ("Enable XREF options");
final JMenuItem appleLineWrapItem = new JCheckBoxMenuItem ("Apple line wrap");
final JMenuItem splitRemarkItem = new JCheckBoxMenuItem ("Split remarks");
final JMenuItem splitDimItem = new JCheckBoxMenuItem ("Split DIM");
final JMenuItem alignAssignItem = new JCheckBoxMenuItem ("Align consecutive assign");
@ -264,6 +268,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
applesoftMenu.add (showAllFormatItem);
applesoftMenu.add (showAllXrefItem);
applesoftMenu.addSeparator ();
applesoftMenu.add (appleLineWrapItem);
applesoftMenu.addSeparator ();
applesoftMenu.add (splitRemarkItem);
applesoftMenu.add (splitDimItem);
applesoftMenu.add (alignAssignItem);
@ -343,6 +349,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
showHeaderItem.addActionListener (basicPreferencesAction);
showAllFormatItem.addActionListener (basicPreferencesAction);
showAllXrefItem.addActionListener (basicPreferencesAction);
appleLineWrapItem.addActionListener (basicPreferencesAction);
for (JMenuItem item : applesoftFormatItems)
item.addActionListener (basicPreferencesAction);
for (JMenuItem item : applesoftXrefItems)
@ -395,6 +402,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
basicPreferences.formatApplesoft = showAllFormatItem.isSelected ();
basicPreferences.showAllXref = showAllXrefItem.isSelected ();
basicPreferences.appleLineWrap = appleLineWrapItem.isSelected ();
basicPreferences.splitRem = splitRemarkItem.isSelected ();
basicPreferences.splitDim = splitDimItem.isSelected ();
basicPreferences.alignAssign = alignAssignItem.isSelected ();
@ -420,6 +429,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
for (JMenuItem item : applesoftFormatItems)
item.setEnabled (basicPreferences.formatApplesoft);
appleLineWrapItem.setEnabled (!basicPreferences.formatApplesoft);
for (JMenuItem item : applesoftXrefItems)
item.setEnabled (basicPreferences.showAllXref);
}
@ -571,6 +582,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
prefs.putBoolean (PREFS_SHOW_ALL_FORMAT, showAllFormatItem.isSelected ());
prefs.putBoolean (PREFS_SHOW_ALL_XREF, showAllXrefItem.isSelected ());
prefs.putBoolean (PREFS_APPLE_LINE_WRAP, appleLineWrapItem.isSelected ());
prefs.putBoolean (PREFS_SPLIT_REMARKS, splitRemarkItem.isSelected ());
prefs.putBoolean (PREFS_SPLIT_DIM, splitDimItem.isSelected ());
prefs.putBoolean (PREFS_ALIGN_ASSIGN, alignAssignItem.isSelected ());
@ -633,6 +646,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
showAllFormatItem.setSelected (prefs.getBoolean (PREFS_SHOW_ALL_FORMAT, true));
showAllXrefItem.setSelected (prefs.getBoolean (PREFS_SHOW_ALL_XREF, true));
appleLineWrapItem.setSelected (prefs.getBoolean (PREFS_APPLE_LINE_WRAP, false));
splitRemarkItem.setSelected (prefs.getBoolean (PREFS_SPLIT_REMARKS, false));
splitDimItem.setSelected (prefs.getBoolean (PREFS_SPLIT_DIM, false));
alignAssignItem.setSelected (prefs.getBoolean (PREFS_ALIGN_ASSIGN, true));