show extra bytes for binary files

This commit is contained in:
Denis Molony 2016-02-05 11:23:53 +11:00
parent 62206d25d7
commit fc50481a58
6 changed files with 156 additions and 84 deletions

View File

@ -1,3 +0,0 @@
#Build Number for ANT. Do not edit!
#Mon Dec 14 07:20:11 AEDT 2015
build.number=633

View File

@ -53,15 +53,19 @@ public abstract class AbstractFile implements DataSource
text.append (hb.title + "\n\n"); text.append (hb.title + "\n\n");
text.append (HexFormatter.format (buffer, hb.ptr, hb.size) + "\n\n"); text.append (HexFormatter.format (buffer, hb.ptr, hb.size) + "\n\n");
} }
text.deleteCharAt (text.length () - 1); text.deleteCharAt (text.length () - 1);
text.deleteCharAt (text.length () - 1); text.deleteCharAt (text.length () - 1);
return text.toString (); return text.toString ();
} }
if (buffer == null || buffer.length == 0) if (buffer == null || buffer.length == 0)
return "No buffer"; return "No buffer";
if (buffer.length <= 99999) if (buffer.length <= 99999)
return HexFormatter.format (buffer, 0, buffer.length); return HexFormatter.format (buffer, 0, buffer.length);
return HexFormatter.format (buffer, 0, 99999); return HexFormatter.format (buffer, 0, 99999);
} }

View File

@ -9,13 +9,19 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.bytezone.diskbrowser.HexFormatter;
import com.bytezone.diskbrowser.gui.DiskBrowser; import com.bytezone.diskbrowser.gui.DiskBrowser;
public class AssemblerProgram extends AbstractFile public class AssemblerProgram extends AbstractFile
{ {
private static Map<Integer, String> equates;
private final int loadAddress; private final int loadAddress;
private int executeOffset; private int executeOffset;
private static Map<Integer, String> equates;
private byte[] extraBuffer;
// private int offset;
// private int length;
public AssemblerProgram (String name, byte[] buffer, int address) public AssemblerProgram (String name, byte[] buffer, int address)
{ {
@ -32,6 +38,39 @@ public class AssemblerProgram extends AbstractFile
this.executeOffset = executeOffset; this.executeOffset = executeOffset;
} }
public void setExtraBuffer (byte[] fullBuffer, int offset, int length)
{
this.extraBuffer = new byte[length];
System.arraycopy (fullBuffer, offset, extraBuffer, 0, length);
}
@Override
public String getHexDump ()
{
String text = super.getHexDump ();
if (extraBuffer == null)
return text;
return text + "\n\n"
+ HexFormatter.format (extraBuffer, 0, extraBuffer.length, buffer.length);
}
@Override
public String getAssembler ()
{
String text = super.getAssembler ();
if (extraBuffer == null)
return text;
String extraName = String.format ("%s (extra)", name);
AssemblerProgram assemblerProgram =
new AssemblerProgram (extraName, extraBuffer, buffer.length);
return text + "\n\n" + assemblerProgram.getText ();
}
@Override @Override
public String getText () public String getText ()
{ {
@ -45,10 +84,10 @@ public class AssemblerProgram extends AbstractFile
pgm.append (String.format ("Entry : $%04X%n", (loadAddress + executeOffset))); pgm.append (String.format ("Entry : $%04X%n", (loadAddress + executeOffset)));
pgm.append (String.format ("%n")); pgm.append (String.format ("%n"));
return pgm.append (getStringBuilder ()).toString (); return pgm.append (getStringBuilder2 ()).toString ();
} }
public StringBuilder getStringBuilder () private StringBuilder getStringBuilder ()
{ {
if (true) if (true)
return getStringBuilder2 (); return getStringBuilder2 ();
@ -58,7 +97,8 @@ public class AssemblerProgram extends AbstractFile
int ptr = executeOffset; int ptr = executeOffset;
int address = loadAddress + executeOffset; int address = loadAddress + executeOffset;
// if the assembly doesn't start at the beginning, just dump the bytes that are skipped // if the assembly doesn't start at the beginning, just dump the bytes that
// are skipped
for (int i = 0; i < executeOffset; i++) for (int i = 0; i < executeOffset; i++)
pgm.append (String.format ("%04X: %02X%n", (loadAddress + i), buffer[i])); pgm.append (String.format ("%04X: %02X%n", (loadAddress + i), buffer[i]));
@ -115,12 +155,13 @@ public class AssemblerProgram extends AbstractFile
return pgm; return pgm;
} }
public StringBuilder getStringBuilder2 () private StringBuilder getStringBuilder2 ()
{ {
StringBuilder pgm = new StringBuilder (); StringBuilder pgm = new StringBuilder ();
List<AssemblerStatement> lines = getLines (); List<AssemblerStatement> lines = getLines ();
// if the assembly doesn't start at the beginning, just dump the bytes that are skipped // if the assembly doesn't start at the beginning, just dump the bytes that
// are skipped
for (int i = 0; i < executeOffset; i++) for (int i = 0; i < executeOffset; i++)
pgm.append (String.format (" %04X: %02X%n", (loadAddress + i), buffer[i])); pgm.append (String.format (" %04X: %02X%n", (loadAddress + i), buffer[i]));
@ -128,7 +169,8 @@ public class AssemblerProgram extends AbstractFile
{ {
StringBuilder line = new StringBuilder (); StringBuilder line = new StringBuilder ();
line.append (String.format ("%3.3s %04X: %02X ", getArrow (cmd), cmd.address, cmd.value)); line.append (String.format ("%3.3s %04X: %02X ", getArrow (cmd), cmd.address,
cmd.value));
if (cmd.size > 1) if (cmd.size > 1)
line.append (String.format ("%02X ", cmd.operand1)); line.append (String.format ("%02X ", cmd.operand1));
@ -174,7 +216,8 @@ public class AssemblerProgram extends AbstractFile
private List<AssemblerStatement> getLines () private List<AssemblerStatement> getLines ()
{ {
List<AssemblerStatement> lines = new ArrayList<AssemblerStatement> (); List<AssemblerStatement> lines = new ArrayList<AssemblerStatement> ();
Map<Integer, AssemblerStatement> linesMap = new HashMap<Integer, AssemblerStatement> (); Map<Integer, AssemblerStatement> linesMap =
new HashMap<Integer, AssemblerStatement> ();
List<Integer> targets = new ArrayList<Integer> (); List<Integer> targets = new ArrayList<Integer> ();
int ptr = executeOffset; int ptr = executeOffset;
@ -230,12 +273,6 @@ public class AssemblerProgram extends AbstractFile
return arrow; return arrow;
} }
@Override
public String getAssembler ()
{
return getStringBuilder ().toString ();
}
private void getEquates () private void getEquates ()
{ {
equates = new HashMap<Integer, String> (); equates = new HashMap<Integer, String> ();

View File

@ -27,7 +27,8 @@ abstract class AbstractCatalogEntry implements AppleFileSource
protected final List<DiskAddress> dataSectors = new ArrayList<DiskAddress> (); protected final List<DiskAddress> dataSectors = new ArrayList<DiskAddress> ();
protected final List<DiskAddress> tsSectors = new ArrayList<DiskAddress> (); protected final List<DiskAddress> tsSectors = new ArrayList<DiskAddress> ();
public AbstractCatalogEntry (DosDisk dosDisk, DiskAddress catalogSector, byte[] entryBuffer) public AbstractCatalogEntry (DosDisk dosDisk, DiskAddress catalogSector,
byte[] entryBuffer)
{ {
this.dosDisk = dosDisk; this.dosDisk = dosDisk;
this.disk = dosDisk.getDisk (); this.disk = dosDisk.getDisk ();
@ -58,8 +59,7 @@ abstract class AbstractCatalogEntry implements AppleFileSource
name = getName ("", entryBuffer); name = getName ("", entryBuffer);
// CATALOG command only formats the LO byte - see Beneath Apple DOS pp4-6 // CATALOG command only formats the LO byte - see Beneath Apple DOS pp4-6
String base = String base = String.format ("%s%s %03d ", (locked) ? "*" : " ", getFileType (),
String.format ("%s%s %03d ", (locked) ? "*" : " ", getFileType (),
(entryBuffer[33] & 0xFF)); (entryBuffer[33] & 0xFF));
catalogName = getName (base, entryBuffer); catalogName = getName (base, entryBuffer);
} }
@ -140,6 +140,9 @@ abstract class AbstractCatalogEntry implements AppleFileSource
try try
{ {
byte[] exactBuffer;
byte[] extraBuffer = new byte[0];
switch (this.fileType) switch (this.fileType)
{ {
case Text: case Text:
@ -148,12 +151,14 @@ abstract class AbstractCatalogEntry implements AppleFileSource
else else
appleFile = new TextFile (name, buffer); appleFile = new TextFile (name, buffer);
break; break;
case IntegerBasic: case IntegerBasic:
reportedLength = HexFormatter.intValue (buffer[0], buffer[1]); reportedLength = HexFormatter.intValue (buffer[0], buffer[1]);
byte[] exactBuffer = new byte[reportedLength]; exactBuffer = new byte[reportedLength];
System.arraycopy (buffer, 2, exactBuffer, 0, reportedLength); System.arraycopy (buffer, 2, exactBuffer, 0, reportedLength);
appleFile = new IntegerBasicProgram (name, exactBuffer); appleFile = new IntegerBasicProgram (name, exactBuffer);
break; break;
case ApplesoftBasic: case ApplesoftBasic:
reportedLength = HexFormatter.intValue (buffer[0], buffer[1]); reportedLength = HexFormatter.intValue (buffer[0], buffer[1]);
exactBuffer = new byte[reportedLength]; exactBuffer = new byte[reportedLength];
@ -163,6 +168,7 @@ abstract class AbstractCatalogEntry implements AppleFileSource
// appleFile = new ApplesoftBasicProgram (name, exactBuffer); // appleFile = new ApplesoftBasicProgram (name, exactBuffer);
appleFile = new BasicProgram (name, exactBuffer); appleFile = new BasicProgram (name, exactBuffer);
break; break;
case Binary: // binary file case Binary: // binary file
case Relocatable: // relocatable binary file case Relocatable: // relocatable binary file
if (buffer.length == 0) if (buffer.length == 0)
@ -180,9 +186,15 @@ abstract class AbstractCatalogEntry implements AppleFileSource
// buffer is a multiple of the block size, so it usually needs to be reduced // buffer is a multiple of the block size, so it usually needs to be reduced
if ((reportedLength + 4) <= buffer.length) if ((reportedLength + 4) <= buffer.length)
{
exactBuffer = new byte[reportedLength]; exactBuffer = new byte[reportedLength];
// extraBuffer = new byte[buffer.length - reportedLength - 4];
// System.arraycopy (buffer, reportedLength + 4, extraBuffer, 0,
// extraBuffer.length);
}
else else
exactBuffer = new byte[buffer.length - 4]; // reported length is too long exactBuffer = new byte[buffer.length - 4]; // reported length is too long
System.arraycopy (buffer, 4, exactBuffer, 0, exactBuffer.length); System.arraycopy (buffer, 4, exactBuffer, 0, exactBuffer.length);
if (ShapeTable.isShapeTable (exactBuffer)) if (ShapeTable.isShapeTable (exactBuffer))
@ -202,17 +214,26 @@ abstract class AbstractCatalogEntry implements AppleFileSource
else if (name.endsWith (".S")) else if (name.endsWith (".S"))
appleFile = new MerlinSource (name, exactBuffer); appleFile = new MerlinSource (name, exactBuffer);
else else
{
appleFile = new AssemblerProgram (name, exactBuffer, loadAddress); appleFile = new AssemblerProgram (name, exactBuffer, loadAddress);
if (exactBuffer.length < buffer.length + 4)
((AssemblerProgram) appleFile)
.setExtraBuffer (buffer, reportedLength + 4,
buffer.length - reportedLength - 4);
}
} }
break; break;
case SS: // what is this? case SS: // what is this?
System.out.println ("SS file"); System.out.println ("SS file");
appleFile = new DefaultAppleFile (name, buffer); appleFile = new DefaultAppleFile (name, buffer);
break; break;
case AA: // what is this? case AA: // what is this?
System.out.println ("AA file"); System.out.println ("AA file");
appleFile = new DefaultAppleFile (name, buffer); appleFile = new DefaultAppleFile (name, buffer);
break; break;
case BB: // what is this? case BB: // what is this?
int loadAddress = HexFormatter.intValue (buffer[0], buffer[1]); int loadAddress = HexFormatter.intValue (buffer[0], buffer[1]);
reportedLength = HexFormatter.intValue (buffer[2], buffer[3]); reportedLength = HexFormatter.intValue (buffer[2], buffer[3]);
@ -220,6 +241,7 @@ abstract class AbstractCatalogEntry implements AppleFileSource
System.arraycopy (buffer, 4, exactBuffer, 0, reportedLength); System.arraycopy (buffer, 4, exactBuffer, 0, reportedLength);
appleFile = new SimpleText2 (name, exactBuffer, loadAddress); appleFile = new SimpleText2 (name, exactBuffer, loadAddress);
break; break;
default: default:
System.out.println ("Unknown file type : " + fileType); System.out.println ("Unknown file type : " + fileType);
appleFile = new DefaultAppleFile (name, buffer); appleFile = new DefaultAppleFile (name, buffer);

View File

@ -35,6 +35,7 @@ abstract class CatalogEntry implements AppleFileSource
access = HexFormatter.intValue (entryBuffer[30]); access = HexFormatter.intValue (entryBuffer[30]);
} }
@Override
public String getUniqueName () public String getUniqueName ()
{ {
if (parentDirectory == null) if (parentDirectory == null)
@ -42,6 +43,7 @@ abstract class CatalogEntry implements AppleFileSource
return parentDirectory.getUniqueName () + "/" + name; return parentDirectory.getUniqueName () + "/" + name;
} }
@Override
public FormattedDisk getFormattedDisk () public FormattedDisk getFormattedDisk ()
{ {
return parentDisk; return parentDisk;

View File

@ -265,13 +265,20 @@ class FileEntry extends CatalogEntry implements ProdosConstants
file = new SimpleText (name, exactBuffer); file = new SimpleText (name, exactBuffer);
else if (HiResImage.isGif (exactBuffer)) else if (HiResImage.isGif (exactBuffer))
file = new HiResImage (name, exactBuffer); file = new HiResImage (name, exactBuffer);
else if ((endOfFile == 0x1FF8 || endOfFile == 0x1FFF || endOfFile == 0x2000 || endOfFile == 0x4000) else if ((endOfFile == 0x1FF8 || endOfFile == 0x1FFF || endOfFile == 0x2000
|| endOfFile == 0x4000)
&& (auxType == 0x1FFF || auxType == 0x2000 || auxType == 0x4000)) && (auxType == 0x1FFF || auxType == 0x2000 || auxType == 0x4000))
file = new HiResImage (name, exactBuffer); file = new HiResImage (name, exactBuffer);
else if (endOfFile == 38400 && name.startsWith ("LVL.")) else if (endOfFile == 38400 && name.startsWith ("LVL."))
file = new LodeRunner (name, exactBuffer); file = new LodeRunner (name, exactBuffer);
else else
{
file = new AssemblerProgram (name, exactBuffer, auxType); file = new AssemblerProgram (name, exactBuffer, auxType);
if (exactBuffer.length < buffer.length)
((AssemblerProgram) file)
.setExtraBuffer (buffer, exactBuffer.length,
buffer.length - exactBuffer.length);
}
break; break;
case FILE_TYPE_TEXT: case FILE_TYPE_TEXT:
assert auxType == 0; // auxType > 0 handled above assert auxType == 0; // auxType > 0 handled above
@ -288,8 +295,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants
break; break;
case FILE_TYPE_DIRECTORY: case FILE_TYPE_DIRECTORY:
VolumeDirectoryHeader vdh = ((ProdosDisk) parentDisk).vdh; VolumeDirectoryHeader vdh = ((ProdosDisk) parentDisk).vdh;
file = file = new ProdosDirectory (parentDisk, name, buffer, vdh.totalBlocks,
new ProdosDirectory (parentDisk, name, buffer, vdh.totalBlocks,
vdh.freeBlocks, vdh.usedBlocks); vdh.freeBlocks, vdh.usedBlocks);
break; break;
case FILE_TYPE_APPLESOFT_BASIC_VARS: case FILE_TYPE_APPLESOFT_BASIC_VARS:
@ -328,8 +334,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants
default: default:
System.out.format ("Unknown file type : %02X%n", fileType); System.out.format ("Unknown file type : %02X%n", fileType);
if (fileType == 0xB3) if (fileType == 0xB3)
file = file = new DefaultAppleFile (name, exactBuffer,
new DefaultAppleFile (name, exactBuffer,
"S16 Apple IIgs Application Program"); "S16 Apple IIgs Application Program");
else else
file = new DefaultAppleFile (name, exactBuffer); file = new DefaultAppleFile (name, exactBuffer);
@ -370,7 +375,8 @@ class FileEntry extends CatalogEntry implements ProdosConstants
byte[] mainIndexBuffer = disk.readSector (keyPtr); byte[] mainIndexBuffer = disk.readSector (keyPtr);
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
{ {
int indexBlock = HexFormatter.intValue (mainIndexBuffer[i], mainIndexBuffer[i + 256]); int indexBlock =
HexFormatter.intValue (mainIndexBuffer[i], mainIndexBuffer[i + 256]);
if (indexBlock > 0) if (indexBlock > 0)
logicalBlock = readIndexBlock (indexBlock, addresses, buffers, logicalBlock); logicalBlock = readIndexBlock (indexBlock, addresses, buffers, logicalBlock);
else else
@ -378,7 +384,8 @@ class FileEntry extends CatalogEntry implements ProdosConstants
if (addresses.size () > 0) if (addresses.size () > 0)
{ {
byte[] tempBuffer = disk.readSectors (addresses); byte[] tempBuffer = disk.readSectors (addresses);
buffers.add (new TextBuffer (tempBuffer, auxType, logicalBlock - addresses.size ())); buffers.add (new TextBuffer (tempBuffer, auxType,
logicalBlock - addresses.size ()));
addresses.clear (); addresses.clear ();
} }
logicalBlock += 256; logicalBlock += 256;
@ -508,7 +515,8 @@ class FileEntry extends CatalogEntry implements ProdosConstants
else if (addresses.size () > 0) else if (addresses.size () > 0)
{ {
byte[] tempBuffer = disk.readSectors (addresses); byte[] tempBuffer = disk.readSectors (addresses);
buffers.add (new TextBuffer (tempBuffer, auxType, logicalBlock - addresses.size ())); buffers
.add (new TextBuffer (tempBuffer, auxType, logicalBlock - addresses.size ()));
addresses.clear (); addresses.clear ();
} }
logicalBlock++; logicalBlock++;
@ -549,12 +557,14 @@ class FileEntry extends CatalogEntry implements ProdosConstants
// String locked = (access == 0x01) ? "*" : " "; // String locked = (access == 0x01) ? "*" : " ";
String locked = (access == 0x00) ? "*" : " "; String locked = (access == 0x00) ? "*" : " ";
if (true) if (true)
return String.format ("%s %03d %s", ProdosConstants.fileTypes[fileType], blocksUsed, return String.format ("%s %03d %s", ProdosConstants.fileTypes[fileType],
locked) + name; blocksUsed, locked)
+ name;
String timeC = created == null ? "" : ProdosDisk.df.format (created.getTime ()); String timeC = created == null ? "" : ProdosDisk.df.format (created.getTime ());
String timeF = modified == null ? "" : ProdosDisk.df.format (modified.getTime ()); String timeF = modified == null ? "" : ProdosDisk.df.format (modified.getTime ());
return String.format ("%s %s%-30s %3d %,10d %15s %15s", return String.format ("%s %s%-30s %3d %,10d %15s %15s",
ProdosConstants.fileTypes[fileType], locked, parentDirectory.name ProdosConstants.fileTypes[fileType], locked,
+ "/" + name, blocksUsed, endOfFile, timeC, timeF); parentDirectory.name + "/" + name, blocksUsed, endOfFile, timeC,
timeF);
} }
} }