2019-08-09 23:45:49 +00:00
|
|
|
package com.bytezone.diskbrowser.applefile;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-06-26 03:29:46 +00:00
|
|
|
import com.bytezone.diskbrowser.utilities.Utility;
|
2019-08-09 23:45:49 +00:00
|
|
|
|
2020-09-13 00:22:49 +00:00
|
|
|
// -----------------------------------------------------------------------------------//
|
2021-01-08 07:52:47 +00:00
|
|
|
public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftConstants
|
2020-09-13 00:22:49 +00:00
|
|
|
// -----------------------------------------------------------------------------------//
|
2019-08-09 23:45:49 +00:00
|
|
|
{
|
|
|
|
private final List<SourceLine> sourceLines = new ArrayList<> ();
|
2022-09-15 20:26:52 +00:00
|
|
|
private int ptr = 0; // end-of-program marker
|
2021-01-06 07:37:54 +00:00
|
|
|
|
2021-03-04 03:57:49 +00:00
|
|
|
private final UserBasicFormatter userBasicFormatter;
|
|
|
|
private final AppleBasicFormatter appleBasicFormatter;
|
|
|
|
private final DebugBasicFormatter debugBasicFormatter;
|
|
|
|
private final XrefFormatter xrefFormatter;
|
|
|
|
private final HeaderFormatter headerFormatter;
|
2021-03-03 13:19:13 +00:00
|
|
|
|
2020-09-13 00:22:49 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2019-08-09 23:45:49 +00:00
|
|
|
public ApplesoftBasicProgram (String name, byte[] buffer)
|
2020-09-13 00:22:49 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2019-08-09 23:45:49 +00:00
|
|
|
{
|
|
|
|
super (name, buffer);
|
|
|
|
|
2021-02-21 23:24:34 +00:00
|
|
|
while (buffer[ptr + 1] != 0) // msb of link field
|
2019-08-09 23:45:49 +00:00
|
|
|
{
|
2020-12-30 03:06:50 +00:00
|
|
|
SourceLine line = new SourceLine (this, buffer, ptr);
|
2019-08-09 23:45:49 +00:00
|
|
|
sourceLines.add (line);
|
2021-02-21 23:24:34 +00:00
|
|
|
ptr += line.length; // assumes lines are contiguous
|
2019-08-09 23:45:49 +00:00
|
|
|
}
|
2021-01-18 23:54:52 +00:00
|
|
|
|
2021-03-03 13:19:13 +00:00
|
|
|
userBasicFormatter = new UserBasicFormatter (this, basicPreferences);
|
|
|
|
appleBasicFormatter = new AppleBasicFormatter (this, basicPreferences);
|
|
|
|
debugBasicFormatter = new DebugBasicFormatter (this, basicPreferences);
|
2021-03-03 15:34:09 +00:00
|
|
|
xrefFormatter = new XrefFormatter (this, basicPreferences);
|
2021-03-03 23:23:20 +00:00
|
|
|
headerFormatter = new HeaderFormatter (this, basicPreferences);
|
2019-08-09 23:45:49 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 00:22:49 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2019-08-09 23:45:49 +00:00
|
|
|
@Override
|
|
|
|
public String getText ()
|
2020-09-13 00:22:49 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2020-12-19 05:42:25 +00:00
|
|
|
{
|
2021-01-13 20:29:36 +00:00
|
|
|
StringBuilder text = new StringBuilder ();
|
|
|
|
|
|
|
|
if (basicPreferences.showHeader)
|
2021-03-09 06:23:05 +00:00
|
|
|
headerFormatter.append (text);
|
2021-01-13 20:29:36 +00:00
|
|
|
|
2021-01-18 00:06:17 +00:00
|
|
|
if (showDebugText)
|
2021-03-03 13:19:13 +00:00
|
|
|
{
|
2021-03-09 06:23:05 +00:00
|
|
|
debugBasicFormatter.append (text);
|
2021-03-03 13:19:13 +00:00
|
|
|
return Utility.rtrim (text);
|
|
|
|
}
|
2021-01-18 00:06:17 +00:00
|
|
|
|
2021-01-13 20:29:36 +00:00
|
|
|
if (sourceLines.size () == 0)
|
|
|
|
{
|
|
|
|
text.append ("\n\nThis page intentionally left blank");
|
|
|
|
return text.toString ();
|
|
|
|
}
|
|
|
|
|
2021-03-06 00:29:54 +00:00
|
|
|
if (basicPreferences.userFormat)
|
2021-03-09 06:23:05 +00:00
|
|
|
userBasicFormatter.append (text);
|
2021-01-13 20:29:36 +00:00
|
|
|
else
|
2021-03-09 06:23:05 +00:00
|
|
|
appleBasicFormatter.append (text);
|
2021-01-11 02:59:01 +00:00
|
|
|
|
|
|
|
if (basicPreferences.showAllXref)
|
2021-03-09 06:23:05 +00:00
|
|
|
xrefFormatter.append (text);
|
2021-01-11 02:59:01 +00:00
|
|
|
|
2021-01-18 19:47:01 +00:00
|
|
|
return Utility.rtrim (text);
|
2020-12-19 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 13:19:13 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
List<SourceLine> getSourceLines ()
|
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
{
|
|
|
|
return sourceLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
int getEndPtr ()
|
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
{
|
2021-03-04 03:57:49 +00:00
|
|
|
return ptr;
|
2021-03-03 13:19:13 +00:00
|
|
|
}
|
2019-08-09 23:45:49 +00:00
|
|
|
}
|