created HeaderFormatter

This commit is contained in:
Denis Molony 2021-03-04 09:23:20 +10:00
parent 34c8c16aba
commit a290327a3e
4 changed files with 35 additions and 24 deletions

View File

@ -16,6 +16,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
private AppleBasicFormatter appleBasicFormatter; private AppleBasicFormatter appleBasicFormatter;
private DebugBasicFormatter debugBasicFormatter; private DebugBasicFormatter debugBasicFormatter;
private XrefFormatter xrefFormatter; private XrefFormatter xrefFormatter;
private HeaderFormatter headerFormatter;
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public ApplesoftBasicProgram (String name, byte[] buffer) public ApplesoftBasicProgram (String name, byte[] buffer)
@ -38,6 +39,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
appleBasicFormatter = new AppleBasicFormatter (this, basicPreferences); appleBasicFormatter = new AppleBasicFormatter (this, basicPreferences);
debugBasicFormatter = new DebugBasicFormatter (this, basicPreferences); debugBasicFormatter = new DebugBasicFormatter (this, basicPreferences);
xrefFormatter = new XrefFormatter (this, basicPreferences); xrefFormatter = new XrefFormatter (this, basicPreferences);
headerFormatter = new HeaderFormatter (this, basicPreferences);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -48,7 +50,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
if (basicPreferences.showHeader) if (basicPreferences.showHeader)
addHeader (text); headerFormatter.format (text);
if (showDebugText) if (showDebugText)
{ {
@ -93,14 +95,4 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
{ {
return endPtr; return endPtr;
} }
// ---------------------------------------------------------------------------------//
private void addHeader (StringBuilder pgm)
// ---------------------------------------------------------------------------------//
{
pgm.append ("Name : " + name + "\n");
pgm.append (String.format ("Length : $%04X (%<,d)%n", buffer.length));
pgm.append (String.format ("Load at : $%04X (%<,d)%n%n",
BasicFormatter.getLoadAddress (buffer)));
}
} }

View File

@ -16,7 +16,6 @@ public abstract class BasicFormatter implements ApplesoftConstants
BasicPreferences basicPreferences; BasicPreferences basicPreferences;
byte[] buffer; byte[] buffer;
List<SourceLine> sourceLines; List<SourceLine> sourceLines;
int endPtr;
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public BasicFormatter (ApplesoftBasicProgram program, BasicPreferences basicPreferences) public BasicFormatter (ApplesoftBasicProgram program, BasicPreferences basicPreferences)
@ -26,7 +25,6 @@ public abstract class BasicFormatter implements ApplesoftConstants
this.basicPreferences = basicPreferences; this.basicPreferences = basicPreferences;
this.buffer = program.getBuffer (); this.buffer = program.getBuffer ();
this.sourceLines = program.getSourceLines (); this.sourceLines = program.getSourceLines ();
this.endPtr = program.getEndPtr ();
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -37,20 +35,11 @@ public abstract class BasicFormatter implements ApplesoftConstants
int getLoadAddress () int getLoadAddress ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
// return program.getLoadAddress (); return (buffer.length > 1) ? unsignedShort (buffer, 0) - getLineLength (0) : 0;
return getLoadAddress (buffer);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
static int getLoadAddress (byte[] buffer) private int getLineLength (int ptr)
// ---------------------------------------------------------------------------------//
{
return (buffer.length > 1) ? unsignedShort (buffer, 0) - getLineLength (buffer, 0)
: 0;
}
// ---------------------------------------------------------------------------------//
private static int getLineLength (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
int linkField = unsignedShort (buffer, ptr); int linkField = unsignedShort (buffer, ptr);

View File

@ -11,12 +11,16 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
public class DebugBasicFormatter extends BasicFormatter public class DebugBasicFormatter extends BasicFormatter
// -----------------------------------------------------------------------------------// // -----------------------------------------------------------------------------------//
{ {
int endPtr;
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public DebugBasicFormatter (ApplesoftBasicProgram program, public DebugBasicFormatter (ApplesoftBasicProgram program,
BasicPreferences basicPreferences) BasicPreferences basicPreferences)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
super (program, basicPreferences); super (program, basicPreferences);
endPtr = program.getEndPtr ();
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//

View File

@ -0,0 +1,26 @@
package com.bytezone.diskbrowser.applefile;
import com.bytezone.diskbrowser.gui.BasicPreferences;
// -----------------------------------------------------------------------------------//
public class HeaderFormatter extends BasicFormatter
// -----------------------------------------------------------------------------------//
{
// ---------------------------------------------------------------------------------//
public HeaderFormatter (ApplesoftBasicProgram program,
BasicPreferences basicPreferences)
// ---------------------------------------------------------------------------------//
{
super (program, basicPreferences);
}
// ---------------------------------------------------------------------------------//
@Override
public void format (StringBuilder fullText)
// ---------------------------------------------------------------------------------//
{
fullText.append ("Name : " + program.name + "\n");
fullText.append (String.format ("Length : $%04X (%<,d)%n", buffer.length));
fullText.append (String.format ("Load at : $%04X (%<,d)%n%n", getLoadAddress ()));
}
}