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 (HexFormatter.format (buffer, hb.ptr, hb.size) + "\n\n");
}
text.deleteCharAt (text.length () - 1);
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
if (buffer == null || buffer.length == 0)
return "No buffer";
if (buffer.length <= 99999)
return HexFormatter.format (buffer, 0, buffer.length);
return HexFormatter.format (buffer, 0, 99999);
}

View File

@ -9,13 +9,19 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.bytezone.diskbrowser.HexFormatter;
import com.bytezone.diskbrowser.gui.DiskBrowser;
public class AssemblerProgram extends AbstractFile
{
private static Map<Integer, String> equates;
private final int loadAddress;
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)
{
@ -32,6 +38,39 @@ public class AssemblerProgram extends AbstractFile
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
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 ("%n"));
return pgm.append (getStringBuilder ()).toString ();
return pgm.append (getStringBuilder2 ()).toString ();
}
public StringBuilder getStringBuilder ()
private StringBuilder getStringBuilder ()
{
if (true)
return getStringBuilder2 ();
@ -58,7 +97,8 @@ public class AssemblerProgram extends AbstractFile
int ptr = 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++)
pgm.append (String.format ("%04X: %02X%n", (loadAddress + i), buffer[i]));
@ -115,12 +155,13 @@ public class AssemblerProgram extends AbstractFile
return pgm;
}
public StringBuilder getStringBuilder2 ()
private StringBuilder getStringBuilder2 ()
{
StringBuilder pgm = new StringBuilder ();
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++)
pgm.append (String.format (" %04X: %02X%n", (loadAddress + i), buffer[i]));
@ -128,7 +169,8 @@ public class AssemblerProgram extends AbstractFile
{
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)
line.append (String.format ("%02X ", cmd.operand1));
@ -174,7 +216,8 @@ public class AssemblerProgram extends AbstractFile
private List<AssemblerStatement> getLines ()
{
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> ();
int ptr = executeOffset;
@ -230,12 +273,6 @@ public class AssemblerProgram extends AbstractFile
return arrow;
}
@Override
public String getAssembler ()
{
return getStringBuilder ().toString ();
}
private void getEquates ()
{
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> tsSectors = new ArrayList<DiskAddress> ();
public AbstractCatalogEntry (DosDisk dosDisk, DiskAddress catalogSector, byte[] entryBuffer)
public AbstractCatalogEntry (DosDisk dosDisk, DiskAddress catalogSector,
byte[] entryBuffer)
{
this.dosDisk = dosDisk;
this.disk = dosDisk.getDisk ();
@ -58,8 +59,7 @@ abstract class AbstractCatalogEntry implements AppleFileSource
name = getName ("", entryBuffer);
// CATALOG command only formats the LO byte - see Beneath Apple DOS pp4-6
String base =
String.format ("%s%s %03d ", (locked) ? "*" : " ", getFileType (),
String base = String.format ("%s%s %03d ", (locked) ? "*" : " ", getFileType (),
(entryBuffer[33] & 0xFF));
catalogName = getName (base, entryBuffer);
}
@ -140,6 +140,9 @@ abstract class AbstractCatalogEntry implements AppleFileSource
try
{
byte[] exactBuffer;
byte[] extraBuffer = new byte[0];
switch (this.fileType)
{
case Text:
@ -148,12 +151,14 @@ abstract class AbstractCatalogEntry implements AppleFileSource
else
appleFile = new TextFile (name, buffer);
break;
case IntegerBasic:
reportedLength = HexFormatter.intValue (buffer[0], buffer[1]);
byte[] exactBuffer = new byte[reportedLength];
exactBuffer = new byte[reportedLength];
System.arraycopy (buffer, 2, exactBuffer, 0, reportedLength);
appleFile = new IntegerBasicProgram (name, exactBuffer);
break;
case ApplesoftBasic:
reportedLength = HexFormatter.intValue (buffer[0], buffer[1]);
exactBuffer = new byte[reportedLength];
@ -163,6 +168,7 @@ abstract class AbstractCatalogEntry implements AppleFileSource
// appleFile = new ApplesoftBasicProgram (name, exactBuffer);
appleFile = new BasicProgram (name, exactBuffer);
break;
case Binary: // binary file
case Relocatable: // relocatable binary file
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
if ((reportedLength + 4) <= buffer.length)
{
exactBuffer = new byte[reportedLength];
// extraBuffer = new byte[buffer.length - reportedLength - 4];
// System.arraycopy (buffer, reportedLength + 4, extraBuffer, 0,
// extraBuffer.length);
}
else
exactBuffer = new byte[buffer.length - 4]; // reported length is too long
System.arraycopy (buffer, 4, exactBuffer, 0, exactBuffer.length);
if (ShapeTable.isShapeTable (exactBuffer))
@ -202,17 +214,26 @@ abstract class AbstractCatalogEntry implements AppleFileSource
else if (name.endsWith (".S"))
appleFile = new MerlinSource (name, exactBuffer);
else
{
appleFile = new AssemblerProgram (name, exactBuffer, loadAddress);
if (exactBuffer.length < buffer.length + 4)
((AssemblerProgram) appleFile)
.setExtraBuffer (buffer, reportedLength + 4,
buffer.length - reportedLength - 4);
}
}
break;
case SS: // what is this?
System.out.println ("SS file");
appleFile = new DefaultAppleFile (name, buffer);
break;
case AA: // what is this?
System.out.println ("AA file");
appleFile = new DefaultAppleFile (name, buffer);
break;
case BB: // what is this?
int loadAddress = HexFormatter.intValue (buffer[0], buffer[1]);
reportedLength = HexFormatter.intValue (buffer[2], buffer[3]);
@ -220,6 +241,7 @@ abstract class AbstractCatalogEntry implements AppleFileSource
System.arraycopy (buffer, 4, exactBuffer, 0, reportedLength);
appleFile = new SimpleText2 (name, exactBuffer, loadAddress);
break;
default:
System.out.println ("Unknown file type : " + fileType);
appleFile = new DefaultAppleFile (name, buffer);

View File

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

View File

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