2021-03-03 13:19:13 +00:00
|
|
|
package com.bytezone.diskbrowser.applefile;
|
|
|
|
|
2021-05-19 08:13:17 +00:00
|
|
|
import static com.bytezone.diskbrowser.utilities.Utility.getShort;
|
2021-03-03 15:34:09 +00:00
|
|
|
|
2021-03-03 13:19:13 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import com.bytezone.diskbrowser.gui.BasicPreferences;
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
public abstract class BasicFormatter implements ApplesoftConstants
|
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
{
|
|
|
|
static final String NEWLINE = "\n";
|
|
|
|
|
|
|
|
ApplesoftBasicProgram program;
|
|
|
|
BasicPreferences basicPreferences;
|
|
|
|
byte[] buffer;
|
|
|
|
List<SourceLine> sourceLines;
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
public BasicFormatter (ApplesoftBasicProgram program, BasicPreferences basicPreferences)
|
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
{
|
|
|
|
this.program = program;
|
|
|
|
this.basicPreferences = basicPreferences;
|
|
|
|
this.buffer = program.getBuffer ();
|
|
|
|
this.sourceLines = program.getSourceLines ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------//
|
2021-03-09 06:23:05 +00:00
|
|
|
public abstract void append (StringBuilder fullText);
|
2021-03-03 13:19:13 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
int getLoadAddress ()
|
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
{
|
2021-05-19 08:13:17 +00:00
|
|
|
return (buffer.length > 3) ? getShort (buffer, 0) - getFirstLineLength () : 0;
|
2021-03-03 15:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------//
|
2021-03-04 03:57:49 +00:00
|
|
|
private int getFirstLineLength ()
|
2021-03-03 15:34:09 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
{
|
2021-05-19 08:13:17 +00:00
|
|
|
int linkField = getShort (buffer, 0);
|
2021-03-03 15:34:09 +00:00
|
|
|
if (linkField == 0)
|
|
|
|
return 2;
|
|
|
|
|
2021-03-04 03:57:49 +00:00
|
|
|
int ptr = 4; // skip link field and line number
|
2021-03-03 15:34:09 +00:00
|
|
|
|
|
|
|
while (ptr < buffer.length && buffer[ptr++] != 0)
|
2021-03-04 03:57:49 +00:00
|
|
|
;
|
2021-03-03 15:34:09 +00:00
|
|
|
|
2021-03-04 03:57:49 +00:00
|
|
|
return ptr;
|
2021-03-03 13:19:13 +00:00
|
|
|
}
|
|
|
|
}
|