method header lines

This commit is contained in:
Denis Molony 2020-02-07 21:52:46 +10:00
parent 467f5db110
commit e4ed878f69
10 changed files with 1441 additions and 1343 deletions

View File

@ -7,22 +7,28 @@ import java.util.List;
import com.bytezone.diskbrowser.utilities.FileFormatException; import com.bytezone.diskbrowser.utilities.FileFormatException;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
// ---------------------------------------------------------------------------------//
public class PascalCode extends AbstractFile public class PascalCode extends AbstractFile
implements PascalConstants, Iterable<PascalSegment> implements PascalConstants, Iterable<PascalSegment>
// ---------------------------------------------------------------------------------//
{ {
private final List<PascalSegment> segments = new ArrayList<> (16); private final List<PascalSegment> segments = new ArrayList<> (16);
private final String comment; private final String comment;
// private final int blockOffset; // private final int blockOffset;
// private final Relocator relocator; // private final Relocator relocator;
// ---------------------------------------------------------------------------------//
public static void print () public static void print ()
// ---------------------------------------------------------------------------------//
{ {
for (int i = 0; i < 216; i++) for (int i = 0; i < 216; i++)
System.out.printf ("%3d %d %3s %s%n", i + 128, PascalConstants.mnemonicSize[i], System.out.printf ("%3d %d %3s %s%n", i + 128, PascalConstants.mnemonicSize[i],
PascalConstants.mnemonics[i], PascalConstants.descriptions[i]); PascalConstants.mnemonics[i], PascalConstants.descriptions[i]);
} }
// ---------------------------------------------------------------------------------//
public PascalCode (String name, byte[] buffer, int blockOffset) public PascalCode (String name, byte[] buffer, int blockOffset)
// ---------------------------------------------------------------------------------//
{ {
super (name, buffer); super (name, buffer);
@ -55,8 +61,10 @@ public class PascalCode extends AbstractFile
comment = HexFormatter.getPascalString (buffer, 0x1B0); comment = HexFormatter.getPascalString (buffer, 0x1B0);
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (getHeader ()); StringBuilder text = new StringBuilder (getHeader ());
@ -75,13 +83,17 @@ public class PascalCode extends AbstractFile
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
private String getHeader () private String getHeader ()
// ---------------------------------------------------------------------------------//
{ {
return "Name : " + name + "\n\n"; return "Name : " + name + "\n\n";
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public Iterator<PascalSegment> iterator () public Iterator<PascalSegment> iterator ()
// ---------------------------------------------------------------------------------//
{ {
return segments.iterator (); return segments.iterator ();
} }

View File

@ -5,7 +5,9 @@ import java.util.List;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class PascalCodeStatement implements PascalConstants public class PascalCodeStatement implements PascalConstants
// -----------------------------------------------------------------------------------//
{ {
private static final String[] compValue = private static final String[] compValue =
{ "invalid", "", "REAL", "", "STR", "", "BOOL", "", "POWR", "", "BYT", "", "WORD" }; { "invalid", "", "REAL", "", "STR", "", "BOOL", "", "POWR", "", "BYT", "", "WORD" };
@ -22,7 +24,9 @@ public class PascalCodeStatement implements PascalConstants
boolean jumpTarget; boolean jumpTarget;
List<Jump> jumps = new ArrayList<> (); List<Jump> jumps = new ArrayList<> ();
// ---------------------------------------------------------------------------------//
public PascalCodeStatement (byte[] buffer, int ptr, int procPtr) public PascalCodeStatement (byte[] buffer, int ptr, int procPtr)
// ---------------------------------------------------------------------------------//
{ {
this.ptr = ptr; this.ptr = ptr;
this.buffer = buffer; this.buffer = buffer;
@ -223,44 +227,58 @@ public class PascalCodeStatement implements PascalConstants
} }
} }
// ---------------------------------------------------------------------------------//
private int getWord (byte[] buffer, int ptr) private int getWord (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//
{ {
return (buffer[ptr + 1] & 0xFF) * 256 + (buffer[ptr] & 0xFF); return (buffer[ptr + 1] & 0xFF) * 256 + (buffer[ptr] & 0xFF);
} }
// ---------------------------------------------------------------------------------//
private int getLengthOfB (byte b) private int getLengthOfB (byte b)
// ---------------------------------------------------------------------------------//
{ {
return (b & 0x80) == 0x80 ? 2 : 1; return (b & 0x80) == 0x80 ? 2 : 1;
} }
// ---------------------------------------------------------------------------------//
private int getValueOfB (byte[] buffer, int ptr, int length) private int getValueOfB (byte[] buffer, int ptr, int length)
// ---------------------------------------------------------------------------------//
{ {
if (length == 2) if (length == 2)
return (buffer[ptr] & 0x7F) * 256 + (buffer[ptr + 1] & 0xFF); return (buffer[ptr] & 0x7F) * 256 + (buffer[ptr + 1] & 0xFF);
return buffer[ptr] & 0xFF; return buffer[ptr] & 0xFF;
} }
// ---------------------------------------------------------------------------------//
private void setParameters (int p1) private void setParameters (int p1)
// ---------------------------------------------------------------------------------//
{ {
description = description.replaceFirst (":1", p1 + ""); description = description.replaceFirst (":1", p1 + "");
extras = "#" + p1; extras = "#" + p1;
} }
// ---------------------------------------------------------------------------------//
private void setParameters (int p1, int p2) private void setParameters (int p1, int p2)
// ---------------------------------------------------------------------------------//
{ {
setParameters (p1); setParameters (p1);
extras += ", #" + p2; extras += ", #" + p2;
description = description.replaceFirst (":2", p2 + ""); description = description.replaceFirst (":2", p2 + "");
} }
// ---------------------------------------------------------------------------------//
private void setParameters (int p1, int p2, String p3) private void setParameters (int p1, int p2, String p3)
// ---------------------------------------------------------------------------------//
{ {
setParameters (p1, p2); setParameters (p1, p2);
description = description.replaceFirst (":3", p3); description = description.replaceFirst (":3", p3);
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
String hex = getHex (buffer, ptr, length > 4 ? 4 : length); String hex = getHex (buffer, ptr, length > 4 ? 4 : length);
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
@ -290,7 +308,9 @@ public class PascalCodeStatement implements PascalConstants
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
private String getHex (byte[] buffer, int offset, int length) private String getHex (byte[] buffer, int offset, int length)
// ---------------------------------------------------------------------------------//
{ {
if ((offset + length) >= buffer.length) if ((offset + length) >= buffer.length)
{ {
@ -305,7 +325,9 @@ public class PascalCodeStatement implements PascalConstants
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
class Jump class Jump
// ---------------------------------------------------------------------------------//
{ {
int addressFrom; int addressFrom;
int addressTo; int addressTo;

View File

@ -1,6 +1,8 @@
package com.bytezone.diskbrowser.applefile; package com.bytezone.diskbrowser.applefile;
// -----------------------------------------------------------------------------------//
public interface PascalConstants public interface PascalConstants
// -----------------------------------------------------------------------------------//
{ {
static String[] mnemonics = static String[] mnemonics =
{ "ABI", "ABR", "ADI", "ADR", "LAND", "DIF", "DVI", "DVR", "CHK", "FLO", "FLT", { "ABI", "ABR", "ADI", "ADR", "LAND", "DIF", "DVI", "DVR", "CHK", "FLO", "FLT",
@ -66,7 +68,8 @@ public interface PascalConstants
"Load multiple words - push block of unsigned bytes at *ToS", "Load multiple words - push block of unsigned bytes at *ToS",
"Store multiple words - store block of UB at ToS to *ToS-1", "Store multiple words - store block of UB at ToS to *ToS-1",
"Load Byte - index the byte pointer ToS-1 by integer index ToS and push that byte", "Load Byte - index the byte pointer ToS-1 by integer index ToS and push that byte",
"Store Byte - index the byte pointer ToS-2 by integer index ToS-1 and move ToS to that location", "Store Byte - index the byte pointer ToS-2 by integer "
+ "index ToS-1 and move ToS to that location",
"Index packed array - do complicated stuff with :1 and :2", "Index packed array - do complicated stuff with :1 and :2",
"Return from base procedure (pass :1 words)", "Return from base procedure (pass :1 words)",
"Call Base Procedure :1 at lex level -1 or 0", "Compare Integer : ToS-1 = ToS", "Call Base Procedure :1 at lex level -1 or 0", "Compare Integer : ToS-1 = ToS",

View File

@ -1,15 +1,20 @@
package com.bytezone.diskbrowser.applefile; package com.bytezone.diskbrowser.applefile;
// -----------------------------------------------------------------------------------//
public class PascalInfo extends AbstractFile public class PascalInfo extends AbstractFile
// -----------------------------------------------------------------------------------//
{ {
// ---------------------------------------------------------------------------------//
public PascalInfo (String name, byte[] buffer) public PascalInfo (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
super (name, buffer); super (name, buffer);
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (getHeader ()); StringBuilder text = new StringBuilder (getHeader ());
@ -22,7 +27,9 @@ public class PascalInfo extends AbstractFile
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
private String getHeader () private String getHeader ()
// ---------------------------------------------------------------------------------//
{ {
return "Name : " + name + "\n\n"; return "Name : " + name + "\n\n";
} }

View File

@ -6,7 +6,9 @@ import java.util.List;
import com.bytezone.diskbrowser.applefile.PascalCodeStatement.Jump; import com.bytezone.diskbrowser.applefile.PascalCodeStatement.Jump;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class PascalProcedure public class PascalProcedure
// -----------------------------------------------------------------------------------//
{ {
// all procedures have these fields // all procedures have these fields
byte[] buffer; byte[] buffer;
@ -26,7 +28,9 @@ public class PascalProcedure
AssemblerProgram assembler; AssemblerProgram assembler;
int jumpTable = -8; int jumpTable = -8;
// ---------------------------------------------------------------------------------//
public PascalProcedure (byte[] buffer, int slot) public PascalProcedure (byte[] buffer, int slot)
// ---------------------------------------------------------------------------------//
{ {
this.buffer = buffer; this.buffer = buffer;
this.slot = slot; this.slot = slot;
@ -46,7 +50,9 @@ public class PascalProcedure
} }
} }
// ---------------------------------------------------------------------------------//
private void decode () private void decode ()
// ---------------------------------------------------------------------------------//
{ {
if (statements.size () > 0 || assembler != null) if (statements.size () > 0 || assembler != null)
return; return;
@ -118,7 +124,9 @@ public class PascalProcedure
} }
} }
// ---------------------------------------------------------------------------------//
public List<PascalCodeStatement> extractStrings () public List<PascalCodeStatement> extractStrings ()
// ---------------------------------------------------------------------------------//
{ {
decode (); decode ();
List<PascalCodeStatement> strings = new ArrayList<> (); List<PascalCodeStatement> strings = new ArrayList<> ();
@ -128,8 +136,10 @@ public class PascalProcedure
return strings; return strings;
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
if (!valid) if (!valid)
return ""; return "";

View File

@ -6,7 +6,9 @@ import java.util.List;
import com.bytezone.diskbrowser.utilities.FileFormatException; import com.bytezone.diskbrowser.utilities.FileFormatException;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class PascalSegment extends AbstractFile implements PascalConstants public class PascalSegment extends AbstractFile implements PascalConstants
// -----------------------------------------------------------------------------------//
{ {
private final static int BLOCK_SIZE = 512; private final static int BLOCK_SIZE = 512;
final int segmentNoHeader; final int segmentNoHeader;
@ -30,7 +32,9 @@ public class PascalSegment extends AbstractFile implements PascalConstants
private List<PascalProcedure> procedures; private List<PascalProcedure> procedures;
// private List<MultiDiskAddress> addresses; // private List<MultiDiskAddress> addresses;
// ---------------------------------------------------------------------------------//
public PascalSegment (String name, byte[] fullBuffer, int seq, int blockOffset) public PascalSegment (String name, byte[] fullBuffer, int seq, int blockOffset)
// ---------------------------------------------------------------------------------//
{ {
super (name, fullBuffer); // sets this.buffer to the full buffer temporarily super (name, fullBuffer); // sets this.buffer to the full buffer temporarily
@ -114,7 +118,9 @@ public class PascalSegment extends AbstractFile implements PascalConstants
// this.addresses = addresses; // this.addresses = addresses;
// } // }
// ---------------------------------------------------------------------------------//
private void buildProcedureList () private void buildProcedureList ()
// ---------------------------------------------------------------------------------//
{ {
procedures = new ArrayList<> (totalProcedures); procedures = new ArrayList<> (totalProcedures);
@ -122,7 +128,9 @@ public class PascalSegment extends AbstractFile implements PascalConstants
procedures.add (new PascalProcedure (buffer, i)); procedures.add (new PascalProcedure (buffer, i));
} }
// ---------------------------------------------------------------------------------//
public String toText () public String toText ()
// ---------------------------------------------------------------------------------//
{ {
int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1; int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1;
@ -133,8 +141,10 @@ public class PascalSegment extends AbstractFile implements PascalConstants
getMultiDiskAddresses ()); getMultiDiskAddresses ());
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
if (procedures == null) if (procedures == null)
buildProcedureList (); buildProcedureList ();
@ -194,7 +204,9 @@ public class PascalSegment extends AbstractFile implements PascalConstants
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
private String getMultiDiskAddresses () private String getMultiDiskAddresses ()
// ---------------------------------------------------------------------------------//
{ {
String multiDiskAddressText = ""; String multiDiskAddressText = "";
// int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1; // int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1;

View File

@ -1,14 +1,20 @@
package com.bytezone.diskbrowser.applefile; package com.bytezone.diskbrowser.applefile;
// -----------------------------------------------------------------------------------//
public class PascalText extends AbstractFile public class PascalText extends AbstractFile
// -----------------------------------------------------------------------------------//
{ {
// ---------------------------------------------------------------------------------//
public PascalText (String name, byte[] buffer) public PascalText (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
super (name, buffer); super (name, buffer);
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (getHeader ()); StringBuilder text = new StringBuilder (getHeader ());
@ -38,12 +44,16 @@ public class PascalText extends AbstractFile
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
private String getHeader () private String getHeader ()
// ---------------------------------------------------------------------------------//
{ {
return "Name : " + name + "\n\n"; return "Name : " + name + "\n\n";
} }
// ---------------------------------------------------------------------------------//
private String getLine (int ptr) private String getLine (int ptr)
// ---------------------------------------------------------------------------------//
{ {
StringBuilder line = new StringBuilder (); StringBuilder line = new StringBuilder ();
while (buffer[ptr] != 0x0D) while (buffer[ptr] != 0x0D)

View File

@ -5,9 +5,13 @@ import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer; import java.awt.image.DataBuffer;
// -----------------------------------------------------------------------------------//
public class PrintShopGraphic extends AbstractFile public class PrintShopGraphic extends AbstractFile
// -----------------------------------------------------------------------------------//
{ {
// ---------------------------------------------------------------------------------//
public PrintShopGraphic (String name, byte[] buffer) public PrintShopGraphic (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
super (name, buffer); super (name, buffer);
@ -27,8 +31,10 @@ public class PrintShopGraphic extends AbstractFile
g2d.dispose (); g2d.dispose ();
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();

View File

@ -1,15 +1,21 @@
package com.bytezone.diskbrowser.applefile; package com.bytezone.diskbrowser.applefile;
// -----------------------------------------------------------------------------------//
public class SegmentDictionary public class SegmentDictionary
// -----------------------------------------------------------------------------------//
{ {
private final boolean isValid; private final boolean isValid;
// ---------------------------------------------------------------------------------//
public SegmentDictionary (String name, byte[] buffer) public SegmentDictionary (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
isValid = !name.equals ("SYSTEM.INTERP"); // temporary isValid = !name.equals ("SYSTEM.INTERP"); // temporary
} }
// ---------------------------------------------------------------------------------//
public boolean isValid () public boolean isValid ()
// ---------------------------------------------------------------------------------//
{ {
return isValid; return isValid;
} }

View File

@ -21,14 +21,18 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
* S2+n last byte = 0 * S2+n last byte = 0
*/ */
// -----------------------------------------------------------------------------------//
public class ShapeTable extends AbstractFile public class ShapeTable extends AbstractFile
// -----------------------------------------------------------------------------------//
{ {
private final List<Shape> shapes = new ArrayList<> (); private final List<Shape> shapes = new ArrayList<> ();
private static final int SIZE = 400; private static final int SIZE = 400;
int maxWidth = 0; int maxWidth = 0;
int maxHeight = 0; int maxHeight = 0;
// ---------------------------------------------------------------------------------//
public ShapeTable (String name, byte[] buffer) public ShapeTable (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
super (name, buffer); super (name, buffer);
@ -81,8 +85,10 @@ public class ShapeTable extends AbstractFile
g2d.dispose (); g2d.dispose ();
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
@ -100,7 +106,9 @@ public class ShapeTable extends AbstractFile
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
public static boolean isShapeTable (byte[] buffer) public static boolean isShapeTable (byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
if (buffer.length == 0) if (buffer.length == 0)
return false; return false;
@ -134,7 +142,9 @@ public class ShapeTable extends AbstractFile
return true; return true;
} }
// ---------------------------------------------------------------------------------//
class Shape class Shape
// ---------------------------------------------------------------------------------//
{ {
private final byte[] buffer; private final byte[] buffer;
private final int index; private final int index;