dmolony-DiskBrowser/src/com/bytezone/diskbrowser/applefile/PascalCode.java

88 lines
2.7 KiB
Java
Raw Normal View History

2015-06-01 09:35:51 +00:00
package com.bytezone.diskbrowser.applefile;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
2016-08-06 07:17:16 +00:00
import com.bytezone.diskbrowser.utilities.FileFormatException;
2016-02-24 21:11:14 +00:00
import com.bytezone.diskbrowser.utilities.HexFormatter;
2015-06-01 09:35:51 +00:00
2016-08-02 10:37:27 +00:00
public class PascalCode extends AbstractFile
implements PascalConstants, Iterable<PascalSegment>
2015-06-01 09:35:51 +00:00
{
2020-02-02 10:17:49 +00:00
private final List<PascalSegment> segments = new ArrayList<> (16);
2016-08-05 08:40:32 +00:00
private final String comment;
2016-08-06 07:17:16 +00:00
// private final int blockOffset;
// private final Relocator relocator;
2015-06-01 09:35:51 +00:00
2016-08-02 10:37:27 +00:00
public static void print ()
{
for (int i = 0; i < 216; i++)
System.out.printf ("%3d %d %3s %s%n", i + 128, PascalConstants.mnemonicSize[i],
2016-08-04 12:00:53 +00:00
PascalConstants.mnemonics[i], PascalConstants.descriptions[i]);
2016-08-02 10:37:27 +00:00
}
2015-06-01 09:35:51 +00:00
2016-08-09 04:15:44 +00:00
public PascalCode (String name, byte[] buffer, int blockOffset)
2016-08-02 10:37:27 +00:00
{
super (name, buffer);
2016-08-05 08:40:32 +00:00
2016-08-06 07:17:16 +00:00
SegmentDictionary segmentDictionary = new SegmentDictionary (name, buffer);
if (!segmentDictionary.isValid ())
throw new FileFormatException ("Error in PascalSegment");
// this.blockOffset = blockOffset;
// this.relocator = relocator;
2016-08-09 04:15:44 +00:00
// if (relocator != null)
// relocator.getMultiDiskAddress ("SEG-DIC", blockOffset, 1);
2016-08-05 08:40:32 +00:00
2016-08-02 10:37:27 +00:00
int nonameCounter = 0;
2015-06-01 09:35:51 +00:00
2016-08-03 11:32:47 +00:00
// Create segment list (up to 16 segments)
2016-08-02 10:37:27 +00:00
for (int i = 0; i < 16; i++)
{
2016-08-04 12:00:53 +00:00
String codeName = HexFormatter.getString (buffer, 0x40 + i * 8, 8).trim ();
2016-08-02 10:37:27 +00:00
int size = HexFormatter.intValue (buffer[i * 4 + 2], buffer[i * 4 + 3]);
2016-08-04 12:00:53 +00:00
if (codeName.length () == 0 && size > 0)
codeName = "<NULL" + ++nonameCounter + ">";
2016-08-02 10:37:27 +00:00
if (size > 0)
2016-08-06 00:02:45 +00:00
{
2016-08-06 07:17:16 +00:00
// this could throw an exception
2016-08-06 00:02:45 +00:00
PascalSegment pascalSegment =
2016-08-09 04:15:44 +00:00
new PascalSegment (codeName, buffer, i, blockOffset);
2016-08-06 00:02:45 +00:00
segments.add (pascalSegment);
}
2016-08-02 10:37:27 +00:00
}
2016-08-06 00:02:45 +00:00
2016-08-02 10:37:27 +00:00
comment = HexFormatter.getPascalString (buffer, 0x1B0);
}
2015-06-01 09:35:51 +00:00
2016-08-02 10:37:27 +00:00
@Override
public String getText ()
{
StringBuilder text = new StringBuilder (getHeader ());
2015-06-01 09:35:51 +00:00
2016-08-02 10:37:27 +00:00
text.append ("Segment Dictionary\n==================\n\n");
2015-06-01 09:35:51 +00:00
2016-08-06 07:17:16 +00:00
text.append ("Slot Addr Blks Byte Name Kind"
+ " Txt Seg Mch Ver I/S I/S Disk:Block\n");
2016-08-05 21:29:27 +00:00
text.append ("---- ---- ---- ---- -------- ---------------"
+ " --- --- --- --- --- --- ---------------------\n");
2016-08-05 08:40:32 +00:00
2016-08-02 10:37:27 +00:00
for (PascalSegment segment : segments)
2016-08-06 00:02:45 +00:00
text.append (segment.toText () + "\n");
text.append ("\nComment : " + comment);
2015-06-01 09:35:51 +00:00
2016-08-02 10:37:27 +00:00
return text.toString ();
}
2015-06-01 09:35:51 +00:00
2016-08-02 10:37:27 +00:00
private String getHeader ()
{
return "Name : " + name + "\n\n";
}
2015-06-01 09:35:51 +00:00
2016-08-02 10:37:27 +00:00
@Override
public Iterator<PascalSegment> iterator ()
{
return segments.iterator ();
}
2015-06-01 09:35:51 +00:00
}