method header lines

This commit is contained in:
Denis Molony 2020-02-07 21:44:51 +10:00
parent 135c946047
commit 467f5db110
7 changed files with 704 additions and 633 deletions

View File

@ -101,6 +101,9 @@ public abstract class HiResImage extends AbstractFile
// 4 System Addons.hdv // 4 System Addons.hdv
// //
// see also - https://docs.google.com/spreadsheets/d
// /1rKR6A_bVniSCtIP_rrv8QLWJdj4h6jEU1jJj0AebWwg/edit#gid=0
static PaletteFactory paletteFactory = new PaletteFactory (); static PaletteFactory paletteFactory = new PaletteFactory ();
static final byte[] pngHeader = static final byte[] pngHeader =

View File

@ -1,154 +1,162 @@
package com.bytezone.diskbrowser.applefile; package com.bytezone.diskbrowser.applefile;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class SimpleText2 extends AbstractFile // -----------------------------------------------------------------------------------//
{ public class SimpleText2 extends AbstractFile
List<Integer> lineStarts = new ArrayList<> (); // -----------------------------------------------------------------------------------//
int loadAddress; {
boolean showByte = false; List<Integer> lineStarts = new ArrayList<> ();
int loadAddress;
public SimpleText2 (String name, byte[] buffer, int loadAddress) boolean showByte = false;
{
super (name, buffer); public SimpleText2 (String name, byte[] buffer, int loadAddress)
this.loadAddress = loadAddress; {
super (name, buffer);
// store a pointer to each new line this.loadAddress = loadAddress;
int ptr = 0;
while (ptr < buffer.length && buffer[ptr] != -1) // store a pointer to each new line
{ int ptr = 0;
int length = buffer[ptr] & 0xFF; while (ptr < buffer.length && buffer[ptr] != -1)
lineStarts.add (ptr); {
ptr += length + 1; int length = buffer[ptr] & 0xFF;
} lineStarts.add (ptr);
} ptr += length + 1;
}
@Override }
public String getText ()
{ // ---------------------------------------------------------------------------------//
StringBuilder text = new StringBuilder (); @Override
public String getText ()
text.append ("Name : " + name + "\n"); // ---------------------------------------------------------------------------------//
text.append (String.format ("Length : $%04X (%d)%n", buffer.length, buffer.length)); {
text.append (String.format ("Load at : $%04X%n%n", loadAddress)); StringBuilder text = new StringBuilder ();
for (Integer i : lineStarts) text.append ("Name : " + name + "\n");
text.append (String.format ("%05X %s%n", i, getLine (i))); text.append (String.format ("Length : $%04X (%d)%n", buffer.length, buffer.length));
if (text.charAt (text.length () - 1) == '\n') text.append (String.format ("Load at : $%04X%n%n", loadAddress));
text.deleteCharAt (text.length () - 1);
return text.toString (); for (Integer i : lineStarts)
} text.append (String.format ("%05X %s%n", i, getLine (i)));
if (text.charAt (text.length () - 1) == '\n')
@Override text.deleteCharAt (text.length () - 1);
public String getHexDump () return text.toString ();
{ }
StringBuilder text = new StringBuilder ();
// ---------------------------------------------------------------------------------//
for (Integer i : lineStarts) @Override
text.append ( public String getHexDump ()
HexFormatter.formatNoHeader (buffer, i, (buffer[i] & 0xFF) + 1) + "\n"); // ---------------------------------------------------------------------------------//
text.append (HexFormatter.formatNoHeader (buffer, buffer.length - 2, 2) + "\n"); {
StringBuilder text = new StringBuilder ();
return text.toString ();
} for (Integer i : lineStarts)
text.append (
// convert buffer to text, ignore line-break at the end HexFormatter.formatNoHeader (buffer, i, (buffer[i] & 0xFF) + 1) + "\n");
private String getLine (int ptr) text.append (HexFormatter.formatNoHeader (buffer, buffer.length - 2, 2) + "\n");
{
StringBuilder line = new StringBuilder (); return text.toString ();
int length = buffer[ptr] & 0xFF; }
while (--length > 0)
{ // convert buffer to text, ignore line-break at the end
int val = buffer[++ptr] & 0xFF; // ---------------------------------------------------------------------------------//
if (val == 0xBB) private String getLine (int ptr)
{ // ---------------------------------------------------------------------------------//
while (line.length () < 35) {
line.append (' '); StringBuilder line = new StringBuilder ();
line.append (';'); int length = buffer[ptr] & 0xFF;
} while (--length > 0)
else if (val >= 0x80) {
{ int val = buffer[++ptr] & 0xFF;
while (line.length () < 10) if (val == 0xBB)
line.append (' '); {
if (val == 0xDC) while (line.length () < 35)
line.append (String.format ("EQU %02X", val)); line.append (' ');
else if (val == 0xD0) line.append (';');
line.append (String.format ("STA %02X", val)); }
else if (val == 0xD2) else if (val >= 0x80)
line.append (String.format ("STY %02X", val)); {
else if (val == 0xD4) while (line.length () < 10)
line.append (String.format ("LSR %02X", val)); line.append (' ');
else if (val == 0xD5) if (val == 0xDC)
line.append (String.format ("ROR %02X", val)); line.append (String.format ("EQU %02X", val));
else if (val == 0xD7) else if (val == 0xD0)
line.append (String.format ("ASL %02X", val)); line.append (String.format ("STA %02X", val));
else if (val == 0xD9) else if (val == 0xD2)
line.append (String.format ("EQ %02X", val)); line.append (String.format ("STY %02X", val));
else if (val == 0xDB) else if (val == 0xD4)
line.append (String.format ("TGT %02X", val)); line.append (String.format ("LSR %02X", val));
else if (val == 0xDA) else if (val == 0xD5)
line.append (String.format ("ORG %02X", val)); line.append (String.format ("ROR %02X", val));
else if (val == 0xB1) else if (val == 0xD7)
line.append (String.format ("TYA %02X", val)); line.append (String.format ("ASL %02X", val));
else if (val == 0xC1) else if (val == 0xD9)
line.append (String.format ("AND %02X", val)); line.append (String.format ("EQ %02X", val));
else if (val == 0xC4) else if (val == 0xDB)
line.append (String.format ("CMP %02X", val)); line.append (String.format ("TGT %02X", val));
else if (val == 0xC8) else if (val == 0xDA)
line.append (String.format ("EOR %02X", val)); line.append (String.format ("ORG %02X", val));
else if (val == 0xCA) else if (val == 0xB1)
line.append (String.format ("JMP %02X", val)); line.append (String.format ("TYA %02X", val));
else if (val == 0xCB) else if (val == 0xC1)
line.append (String.format ("JSR %02X", val)); line.append (String.format ("AND %02X", val));
else if (val == 0xCD) else if (val == 0xC4)
line.append (String.format ("LDA %02X", val)); line.append (String.format ("CMP %02X", val));
else if (val == 0xCE) else if (val == 0xC8)
line.append (String.format ("LDX %02X", val)); line.append (String.format ("EOR %02X", val));
else if (val == 0xCF) else if (val == 0xCA)
line.append (String.format ("LDY %02X", val)); line.append (String.format ("JMP %02X", val));
else if (val == 0xA1) else if (val == 0xCB)
line.append (String.format ("PHA %02X", val)); line.append (String.format ("JSR %02X", val));
else if (val == 0xA2) else if (val == 0xCD)
line.append (String.format ("PLA %02X", val)); line.append (String.format ("LDA %02X", val));
else if (val == 0xA5) else if (val == 0xCE)
line.append (String.format ("RTS %02X", val)); line.append (String.format ("LDX %02X", val));
else if (val == 0xA9) else if (val == 0xCF)
line.append (String.format ("SEC %02X", val)); line.append (String.format ("LDY %02X", val));
else if (val == 0xAD) else if (val == 0xA1)
line.append (String.format ("TAY %02X", val)); line.append (String.format ("PHA %02X", val));
else if (val == 0x82) else if (val == 0xA2)
line.append (String.format ("BMI %02X", val)); line.append (String.format ("PLA %02X", val));
else if (val == 0x84) else if (val == 0xA5)
line.append (String.format ("BCS %02X", val)); line.append (String.format ("RTS %02X", val));
else if (val == 0x85) else if (val == 0xA9)
line.append (String.format ("BPL %02X", val)); line.append (String.format ("SEC %02X", val));
else if (val == 0x86) else if (val == 0xAD)
line.append (String.format ("BNE %02X", val)); line.append (String.format ("TAY %02X", val));
else if (val == 0x87) else if (val == 0x82)
line.append (String.format ("BEQ %02X", val)); line.append (String.format ("BMI %02X", val));
else if (val == 0x99) else if (val == 0x84)
line.append (String.format ("CLC %02X", val)); line.append (String.format ("BCS %02X", val));
else if (val == 0x9C) else if (val == 0x85)
line.append (String.format ("DEX %02X", val)); line.append (String.format ("BPL %02X", val));
else if (val == 0x9F) else if (val == 0x86)
line.append (String.format ("INY %02X", val)); line.append (String.format ("BNE %02X", val));
else else if (val == 0x87)
line.append (String.format (".%02X.", val)); line.append (String.format ("BEQ %02X", val));
else if (val == 0x99)
line.append (' '); line.append (String.format ("CLC %02X", val));
++ptr; else if (val == 0x9C)
if (buffer[ptr] < 0x20 && showByte) line.append (String.format ("DEX %02X", val));
{ else if (val == 0x9F)
val = buffer[ptr] & 0xFF; line.append (String.format ("INY %02X", val));
line.append (String.format (".%02X. ", val)); else
} line.append (String.format (".%02X.", val));
}
else line.append (' ');
line.append ((char) val); ++ptr;
} if (buffer[ptr] < 0x20 && showByte)
return line.toString (); {
} val = buffer[ptr] & 0xFF;
line.append (String.format (".%02X. ", val));
}
}
else
line.append ((char) val);
}
return line.toString ();
}
} }

View File

@ -1,245 +1,261 @@
package com.bytezone.diskbrowser.applefile; package com.bytezone.diskbrowser.applefile;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class StoredVariables extends AbstractFile // -----------------------------------------------------------------------------------//
{ public class StoredVariables extends AbstractFile
public StoredVariables (String name, byte[] buffer) // -----------------------------------------------------------------------------------//
{ {
super (name, buffer); // ---------------------------------------------------------------------------------//
} public StoredVariables (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
@Override {
public String getText () super (name, buffer);
{ }
StringBuilder text = new StringBuilder ();
String strValue = null; // ---------------------------------------------------------------------------------//
int intValue = 0; @Override
// double doubleValue = 0.0; public String getText ()
int strPtr = buffer.length; // ---------------------------------------------------------------------------------//
{
text.append ("File length : " + HexFormatter.format4 (buffer.length)); StringBuilder text = new StringBuilder ();
int totalLength = HexFormatter.intValue (buffer[0], buffer[1]); String strValue = null;
text.append ("\nTotal length : " + HexFormatter.format4 (totalLength)); int intValue = 0;
// double doubleValue = 0.0;
int varLength = HexFormatter.intValue (buffer[2], buffer[3]); int strPtr = buffer.length;
text.append ("\nVar length : " + HexFormatter.format4 (varLength));
text.append ("\n\n"); text.append ("File length : " + HexFormatter.format4 (buffer.length));
int totalLength = HexFormatter.intValue (buffer[0], buffer[1]);
// list simple variables text.append ("\nTotal length : " + HexFormatter.format4 (totalLength));
int ptr = 5; int varLength = HexFormatter.intValue (buffer[2], buffer[3]);
while (ptr < varLength + 5) text.append ("\nVar length : " + HexFormatter.format4 (varLength));
{ text.append ("\n\n");
String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]);
text.append (variableName); // list simple variables
char suffix = variableName.charAt (variableName.length () - 1); int ptr = 5;
if (suffix == '$') while (ptr < varLength + 5)
{ {
int strLength = buffer[ptr + 2] & 0xFF; String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]);
strPtr -= strLength; text.append (variableName);
strValue = HexFormatter.getString (buffer, strPtr, strLength);
text.append (" = " + strValue); char suffix = variableName.charAt (variableName.length () - 1);
} if (suffix == '$')
else if (suffix == '%') {
{ int strLength = buffer[ptr + 2] & 0xFF;
intValue = HexFormatter.intValue (buffer[ptr + 3], buffer[ptr + 2]); strPtr -= strLength;
if ((buffer[ptr + 2] & 0x80) > 0) strValue = HexFormatter.getString (buffer, strPtr, strLength);
intValue -= 65536; text.append (" = " + strValue);
text.append (" = " + intValue); }
} else if (suffix == '%')
else {
{ intValue = HexFormatter.intValue (buffer[ptr + 3], buffer[ptr + 2]);
if (hasValue (ptr + 2)) if ((buffer[ptr + 2] & 0x80) > 0)
{ intValue -= 65536;
String value = HexFormatter.floatValue (buffer, ptr + 2) + ""; text.append (" = " + intValue);
if (value.endsWith (".0")) }
text.append (" = " + value.substring (0, value.length () - 2)); else
else {
text.append (" = " + value); if (hasValue (ptr + 2))
} {
} String value = HexFormatter.floatValue (buffer, ptr + 2) + "";
if (value.endsWith (".0"))
text.append ("\n"); text.append (" = " + value.substring (0, value.length () - 2));
ptr += 7; else
} text.append (" = " + value);
listArrays (text, ptr, totalLength, strPtr); }
}
return text.toString ();
} text.append ("\n");
ptr += 7;
private String getVariableName (byte b1, byte b2) }
{ listArrays (text, ptr, totalLength, strPtr);
char c1, c2, suffix;
return text.toString ();
if ((b1 & 0x80) > 0) // integer }
{
c1 = (char) (b1 & 0x7F); // ---------------------------------------------------------------------------------//
c2 = (char) (b2 & 0x7F); private String getVariableName (byte b1, byte b2)
suffix = '%'; // ---------------------------------------------------------------------------------//
} {
else if ((b2 & 0x80) > 0) // string char c1, c2, suffix;
{
c1 = (char) b1; if ((b1 & 0x80) > 0) // integer
c2 = (char) (b2 & 0x7F); {
suffix = '$'; c1 = (char) (b1 & 0x7F);
} c2 = (char) (b2 & 0x7F);
else suffix = '%';
{ }
c1 = (char) b1; else if ((b2 & 0x80) > 0) // string
c2 = (char) b2; {
suffix = ' '; c1 = (char) b1;
} c2 = (char) (b2 & 0x7F);
suffix = '$';
StringBuffer variableName = new StringBuffer (); }
variableName.append (c1); else
if (c2 > 32) {
variableName.append (c2); c1 = (char) b1;
if (suffix != ' ') c2 = (char) b2;
variableName.append (suffix); suffix = ' ';
}
return variableName.toString ();
} StringBuffer variableName = new StringBuffer ();
variableName.append (c1);
private String getDimensionText (int[] values) if (c2 > 32)
{ variableName.append (c2);
StringBuilder text = new StringBuilder ("("); if (suffix != ' ')
for (int i = 0; i < values.length; i++) variableName.append (suffix);
{
text.append (values[i]); return variableName.toString ();
if (i < values.length - 1) }
text.append (',');
} // ---------------------------------------------------------------------------------//
return text.append (')').toString (); private String getDimensionText (int[] values)
} // ---------------------------------------------------------------------------------//
{
private void listArrays (StringBuilder text, int ptr, int totalLength, int strPtr) StringBuilder text = new StringBuilder ("(");
{ for (int i = 0; i < values.length; i++)
while (ptr < totalLength + 5) {
{ text.append (values[i]);
String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]); if (i < values.length - 1)
text.append ("\n"); text.append (',');
int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]); }
int dimensions = buffer[ptr + 4] & 0xFF; return text.append (')').toString ();
int[] dimensionSizes = new int[dimensions]; }
int totalElements = 0;
for (int i = 0; i < dimensions; i++) // ---------------------------------------------------------------------------------//
{ private void listArrays (StringBuilder text, int ptr, int totalLength, int strPtr)
int p = i * 2 + 5 + ptr; // ---------------------------------------------------------------------------------//
int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]); {
dimensionSizes[dimensions - i - 1] = elements - 1; while (ptr < totalLength + 5)
if (totalElements == 0) {
totalElements = elements; String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]);
else text.append ("\n");
totalElements *= elements; int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]);
} int dimensions = buffer[ptr + 4] & 0xFF;
int[] dimensionSizes = new int[dimensions];
int headerSize = 5 + dimensions * 2; int totalElements = 0;
int elementSize = (offset - headerSize) / totalElements; for (int i = 0; i < dimensions; i++)
{
int p = ptr + headerSize; int p = i * 2 + 5 + ptr;
int[] values = new int[dimensions]; int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]);
for (int i = 0; i < values.length; i++) dimensionSizes[dimensions - i - 1] = elements - 1;
values[i] = 0; if (totalElements == 0)
out: while (true) totalElements = elements;
{ else
text.append (variableName + " " + getDimensionText (values) + " = "); totalElements *= elements;
if (elementSize == 2) }
{
int intValue = HexFormatter.intValue (buffer[p + 1], buffer[p]); int headerSize = 5 + dimensions * 2;
if ((buffer[p] & 0x80) > 0) int elementSize = (offset - headerSize) / totalElements;
intValue -= 65536;
text.append (intValue + "\n"); int p = ptr + headerSize;
} int[] values = new int[dimensions];
else if (elementSize == 3) for (int i = 0; i < values.length; i++)
{ values[i] = 0;
int strLength = buffer[p] & 0xFF; out: while (true)
if (strLength > 0) {
{ text.append (variableName + " " + getDimensionText (values) + " = ");
strPtr -= strLength; if (elementSize == 2)
text.append (HexFormatter.getString (buffer, strPtr, strLength)); {
} int intValue = HexFormatter.intValue (buffer[p + 1], buffer[p]);
text.append ("\n"); if ((buffer[p] & 0x80) > 0)
} intValue -= 65536;
else if (elementSize == 5) text.append (intValue + "\n");
{ }
if (hasValue (p)) else if (elementSize == 3)
text.append (HexFormatter.floatValue (buffer, p)); {
text.append ("\n"); int strLength = buffer[p] & 0xFF;
} if (strLength > 0)
p += elementSize; {
int cp = 0; strPtr -= strLength;
while (++values[cp] > dimensionSizes[cp]) text.append (HexFormatter.getString (buffer, strPtr, strLength));
{ }
values[cp++] = 0; text.append ("\n");
if (cp >= values.length) }
break out; else if (elementSize == 5)
} {
} if (hasValue (p))
ptr += offset; text.append (HexFormatter.floatValue (buffer, p));
} text.append ("\n");
} }
p += elementSize;
private boolean hasValue (int p) int cp = 0;
{ while (++values[cp] > dimensionSizes[cp])
for (int i = 0; i < 5; i++) {
if (buffer[p + i] != 0) values[cp++] = 0;
return true; if (cp >= values.length)
return false; break out;
} }
}
@Override ptr += offset;
public String getHexDump () }
{ }
StringBuffer text = new StringBuffer ();
// ---------------------------------------------------------------------------------//
text.append ("File length : " + HexFormatter.format4 (buffer.length)); private boolean hasValue (int p)
int totalLength = HexFormatter.intValue (buffer[0], buffer[1]); // ---------------------------------------------------------------------------------//
text.append ("\nTotal length : " + HexFormatter.format4 (totalLength)); {
for (int i = 0; i < 5; i++)
int varLength = HexFormatter.intValue (buffer[2], buffer[3]); if (buffer[p + i] != 0)
text.append ("\nVar length : " + HexFormatter.format4 (varLength)); return true;
return false;
int unknown = buffer[4] & 0xFF; }
text.append ("\nUnknown : " + HexFormatter.format2 (unknown));
text.append ("\n\n"); // ---------------------------------------------------------------------------------//
@Override
int ptr = 5; public String getHexDump ()
text.append ("Simple variables : \n\n"); // ---------------------------------------------------------------------------------//
while (ptr < varLength + 5) {
{ StringBuffer text = new StringBuffer ();
text.append (HexFormatter.format (buffer, ptr, 7, false, 0) + "\n");
ptr += 7; text.append ("File length : " + HexFormatter.format4 (buffer.length));
} int totalLength = HexFormatter.intValue (buffer[0], buffer[1]);
text.append ("\nArrays : \n\n"); text.append ("\nTotal length : " + HexFormatter.format4 (totalLength));
while (ptr < totalLength + 5)
{ int varLength = HexFormatter.intValue (buffer[2], buffer[3]);
int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]); text.append ("\nVar length : " + HexFormatter.format4 (varLength));
int dimensions = buffer[ptr + 4] & 0xFF;
int[] dimensionSizes = new int[dimensions]; int unknown = buffer[4] & 0xFF;
int totalElements = 0; text.append ("\nUnknown : " + HexFormatter.format2 (unknown));
for (int i = 0; i < dimensions; i++) text.append ("\n\n");
{
int p = i * 2 + 5 + ptr; int ptr = 5;
int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]); text.append ("Simple variables : \n\n");
dimensionSizes[dimensions - i - 1] = elements; while (ptr < varLength + 5)
if (totalElements == 0) {
totalElements = elements; text.append (HexFormatter.format (buffer, ptr, 7, false, 0) + "\n");
else ptr += 7;
totalElements *= elements; }
} text.append ("\nArrays : \n\n");
int headerSize = 5 + dimensions * 2; while (ptr < totalLength + 5)
text.append (HexFormatter.format (buffer, ptr, headerSize, false, 0) + "\n\n"); {
text.append ( int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]);
HexFormatter.format (buffer, ptr + headerSize, offset - headerSize, false, 0) int dimensions = buffer[ptr + 4] & 0xFF;
+ "\n\n"); int[] dimensionSizes = new int[dimensions];
ptr += offset; int totalElements = 0;
} for (int i = 0; i < dimensions; i++)
text.append ("Strings : \n\n"); {
int length = buffer.length - ptr; int p = i * 2 + 5 + ptr;
text.append (HexFormatter.format (buffer, ptr, length, false, 0) + "\n\n"); int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]);
dimensionSizes[dimensions - i - 1] = elements;
return text.toString (); if (totalElements == 0)
} totalElements = elements;
else
totalElements *= elements;
}
int headerSize = 5 + dimensions * 2;
text.append (HexFormatter.format (buffer, ptr, headerSize, false, 0) + "\n\n");
text.append (
HexFormatter.format (buffer, ptr + headerSize, offset - headerSize, false, 0)
+ "\n\n");
ptr += offset;
}
text.append ("Strings : \n\n");
int length = buffer.length - ptr;
text.append (HexFormatter.format (buffer, ptr, length, false, 0) + "\n\n");
return text.toString ();
}
} }

View File

@ -3,13 +3,17 @@ package com.bytezone.diskbrowser.applefile;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
// only used by Prodos text files - note the fixed block size of 512 - bad! // only used by Prodos text files - note the fixed block size of 512 - bad!
// -----------------------------------------------------------------------------------//
public class TextBuffer public class TextBuffer
// -----------------------------------------------------------------------------------//
{ {
public final byte[] buffer; public final byte[] buffer;
public final int reclen; public final int reclen;
public final int firstRecNo; public final int firstRecNo;
// ---------------------------------------------------------------------------------//
public TextBuffer (byte[] tempBuffer, int reclen, int firstBlock) public TextBuffer (byte[] tempBuffer, int reclen, int firstBlock)
// ---------------------------------------------------------------------------------//
{ {
this.reclen = reclen; this.reclen = reclen;
@ -34,8 +38,10 @@ public class TextBuffer
System.arraycopy (tempBuffer, offset, buffer, 0, copyBytes); System.arraycopy (tempBuffer, offset, buffer, 0, copyBytes);
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();

View File

@ -1,189 +1,209 @@
package com.bytezone.diskbrowser.applefile; package com.bytezone.diskbrowser.applefile;
import java.util.List; import java.util.List;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class TextFile extends AbstractFile // -----------------------------------------------------------------------------------//
{ public class TextFile extends AbstractFile
private int recordLength; // prodos aux // -----------------------------------------------------------------------------------//
private List<TextBuffer> buffers; // only used if it is a Prodos text file {
private int eof; private int recordLength; // prodos aux
private boolean prodosFile; private List<TextBuffer> buffers; // only used if it is a Prodos text file
private int eof;
public TextFile (String name, byte[] buffer) private boolean prodosFile;
{
super (name, buffer); // ---------------------------------------------------------------------------------//
} public TextFile (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
public TextFile (String name, byte[] buffer, int auxType, int eof) {
{ super (name, buffer);
this (name, buffer); }
this.eof = eof;
recordLength = auxType; // ---------------------------------------------------------------------------------//
prodosFile = true; public TextFile (String name, byte[] buffer, int auxType, int eof)
} // ---------------------------------------------------------------------------------//
{
public TextFile (String name, List<TextBuffer> buffers, int auxType, int eof) this (name, buffer);
{ this.eof = eof;
super (name, null); recordLength = auxType;
this.buffers = buffers; prodosFile = true;
this.eof = eof; }
recordLength = auxType;
prodosFile = true; // ---------------------------------------------------------------------------------//
} public TextFile (String name, List<TextBuffer> buffers, int auxType, int eof)
// ---------------------------------------------------------------------------------//
@Override {
public String getHexDump () super (name, null);
{ this.buffers = buffers;
if (buffers == null) this.eof = eof;
return (super.getHexDump ()); recordLength = auxType;
prodosFile = true;
StringBuilder text = new StringBuilder (); }
for (TextBuffer tb : buffers)
{ // ---------------------------------------------------------------------------------//
for (int i = 0, rec = 0; i < tb.buffer.length; i += tb.reclen, rec++) @Override
{ public String getHexDump ()
text.append ("\nRecord #" + (tb.firstRecNo + rec) + "\n"); // ---------------------------------------------------------------------------------//
text.append (HexFormatter.format (tb.buffer, i, tb.reclen) + "\n"); {
} if (buffers == null)
} return (super.getHexDump ());
return text.toString ();
} StringBuilder text = new StringBuilder ();
for (TextBuffer tb : buffers)
@Override {
public String getText () for (int i = 0, rec = 0; i < tb.buffer.length; i += tb.reclen, rec++)
{ {
StringBuilder text = new StringBuilder (); text.append ("\nRecord #" + (tb.firstRecNo + rec) + "\n");
text.append (HexFormatter.format (tb.buffer, i, tb.reclen) + "\n");
text.append ("Name : " + name + "\n"); }
if (prodosFile) }
{ return text.toString ();
text.append (String.format ("Record length : %,8d%n", recordLength)); }
text.append (String.format ("End of file : %,8d%n", eof));
} // ---------------------------------------------------------------------------------//
else @Override
text.append (String.format ("End of file : %,8d%n", buffer.length)); public String getText ()
text.append ("\n"); // ---------------------------------------------------------------------------------//
{
// check whether file is spread over multiple buffers StringBuilder text = new StringBuilder ();
if (buffers != null)
return treeFileText (text); // calls knownLength() text.append ("Name : " + name + "\n");
if (prodosFile)
// check whether the record length is known {
if (recordLength == 0) text.append (String.format ("Record length : %,8d%n", recordLength));
return unknownLength (text); text.append (String.format ("End of file : %,8d%n", eof));
}
text.append ("Offset Record# Text values\n"); else
text.append ( text.append (String.format ("End of file : %,8d%n", buffer.length));
"------ ------- -------------------------------------------------------\n"); text.append ("\n");
return knownLength (text, 0).toString ();
} // check whether file is spread over multiple buffers
if (buffers != null)
private String treeFileText (StringBuilder text) return treeFileText (text); // calls knownLength()
{
text.append (" Offset Record# Text values\n"); // check whether the record length is known
text.append ( if (recordLength == 0)
"---------- ------- -------------------------------------------------------\n"); return unknownLength (text);
for (TextBuffer tb : buffers)
{ text.append ("Offset Record# Text values\n");
buffer = tb.buffer; text.append (
text = knownLength (text, tb.firstRecNo); "------ ------- -------------------------------------------------------\n");
} return knownLength (text, 0).toString ();
return text.toString (); }
}
// ---------------------------------------------------------------------------------//
private StringBuilder knownLength (StringBuilder text, int recNo) private String treeFileText (StringBuilder text)
{ // ---------------------------------------------------------------------------------//
for (int ptr = 0; ptr < buffer.length; ptr += recordLength) {
{ text.append (" Offset Record# Text values\n");
if (buffer[ptr] == 0) text.append (
{ "---------- ------- -------------------------------------------------------\n");
recNo++; for (TextBuffer tb : buffers)
continue; {
} buffer = tb.buffer;
text = knownLength (text, tb.firstRecNo);
int len = buffer.length - ptr; }
int bytes = len < recordLength ? len : recordLength; return text.toString ();
}
while (buffer[ptr + bytes - 1] == 0)
bytes--; // ---------------------------------------------------------------------------------//
private StringBuilder knownLength (StringBuilder text, int recNo)
if ((buffer[ptr + bytes - 1] & 0x7F) == 0x0D) // ignore CR // ---------------------------------------------------------------------------------//
bytes--; {
for (int ptr = 0; ptr < buffer.length; ptr += recordLength)
String line = HexFormatter.getString (buffer, ptr, bytes); {
line = line.replaceAll ("\\n", "\n "); if (buffer[ptr] == 0)
text.append ( {
String.format ("%,10d %,8d %s%n", recNo * recordLength, recNo++, line)); recNo++;
} continue;
}
return text;
} int len = buffer.length - ptr;
int bytes = len < recordLength ? len : recordLength;
private String unknownLength (StringBuilder text)
{ while (buffer[ptr + bytes - 1] == 0)
int nulls = 0; bytes--;
int ptr = 0;
int size = buffer.length; if ((buffer[ptr + bytes - 1] & 0x7F) == 0x0D) // ignore CR
int lastVal = 0; bytes--;
boolean newFormat = true;
boolean showAllOffsets = true; String line = HexFormatter.getString (buffer, ptr, bytes);
line = line.replaceAll ("\\n", "\n ");
if (newFormat) text.append (
{ String.format ("%,10d %,8d %s%n", recNo * recordLength, recNo++, line));
text.append (" Offset Text values\n"); }
text.append ("---------- -------------------------------------------------------"
+ "-------------------\n"); return text;
if (buffer.length == 0) }
return text.toString ();
// ---------------------------------------------------------------------------------//
if (buffer[0] != 0) private String unknownLength (StringBuilder text)
text.append (String.format ("%,10d ", ptr)); // ---------------------------------------------------------------------------------//
} {
int nulls = 0;
int gcd = 0; int ptr = 0;
int size = buffer.length;
while (ptr < size) int lastVal = 0;
{ boolean newFormat = true;
int val = buffer[ptr++] & 0x7F; // strip hi-order bit boolean showAllOffsets = true;
if (val == 0)
++nulls; if (newFormat)
else if (val == 0x0D) // carriage return {
text.append ("\n"); text.append (" Offset Text values\n");
else text.append ("---------- -------------------------------------------------------"
{ + "-------------------\n");
if (nulls > 0) if (buffer.length == 0)
{ return text.toString ();
if (newFormat)
text.append (String.format ("%,10d ", ptr - 1)); if (buffer[0] != 0)
else text.append (String.format ("%,10d ", ptr));
text.append ("\nNew record at : " + (ptr - 1) + "\n"); }
nulls = 0;
int gcd = 0;
gcd = gcd == 0 ? ptr - 1 : gcd (gcd, ptr - 1);
} while (ptr < size)
else if (lastVal == 0x0D && newFormat) {
if (showAllOffsets) int val = buffer[ptr++] & 0x7F; // strip hi-order bit
text.append (String.format ("%,10d ", ptr - 1)); if (val == 0)
else ++nulls;
text.append (" "); else if (val == 0x0D) // carriage return
text.append ("\n");
text.append ((char) val); else
} {
lastVal = val; if (nulls > 0)
} {
if (newFormat)
if (gcd > 0) text.append (String.format ("%,10d ", ptr - 1));
text.append (String.format ("%nGCD: %,d", gcd)); else
else if (text.length () > 0 && text.charAt (text.length () - 1) == '\n') text.append ("\nNew record at : " + (ptr - 1) + "\n");
text.deleteCharAt (text.length () - 1); nulls = 0;
return text.toString (); gcd = gcd == 0 ? ptr - 1 : gcd (gcd, ptr - 1);
} }
else if (lastVal == 0x0D && newFormat)
private int gcd (int a, int b) if (showAllOffsets)
{ text.append (String.format ("%,10d ", ptr - 1));
return a == 0 ? b : gcd (b % a, a); else
} text.append (" ");
text.append ((char) val);
}
lastVal = val;
}
if (gcd > 0)
text.append (String.format ("%nGCD: %,d", gcd));
else if (text.length () > 0 && text.charAt (text.length () - 1) == '\n')
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
// ---------------------------------------------------------------------------------//
private int gcd (int a, int b)
// ---------------------------------------------------------------------------------//
{
return a == 0 ? b : gcd (b % a, a);
}
} }

View File

@ -2,18 +2,24 @@ package com.bytezone.diskbrowser.applefile;
import com.bytezone.diskbrowser.visicalc.Sheet; import com.bytezone.diskbrowser.visicalc.Sheet;
// -----------------------------------------------------------------------------------//
public class VisicalcFile extends AbstractFile public class VisicalcFile extends AbstractFile
// -----------------------------------------------------------------------------------//
{ {
private static boolean debug; private static boolean debug;
private Sheet sheet; private Sheet sheet;
// ---------------------------------------------------------------------------------//
public VisicalcFile (String name, byte[] buffer) public VisicalcFile (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
super (name, buffer); super (name, buffer);
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
if (sheet == null) if (sheet == null)
sheet = new Sheet (buffer); sheet = new Sheet (buffer);
@ -26,17 +32,23 @@ public class VisicalcFile extends AbstractFile
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
public static void setDefaultDebug (boolean value) public static void setDefaultDebug (boolean value)
// ---------------------------------------------------------------------------------//
{ {
debug = value; debug = value;
} }
// ---------------------------------------------------------------------------------//
public static void setDebug (boolean value) public static void setDebug (boolean value)
// ---------------------------------------------------------------------------------//
{ {
debug = value; debug = value;
} }
// ---------------------------------------------------------------------------------//
public static boolean isVisicalcFile (byte[] buffer) public static boolean isVisicalcFile (byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
int firstByte = buffer[0] & 0xFF; int firstByte = buffer[0] & 0xFF;
if (firstByte != 0xBE && firstByte != 0xAF) if (firstByte != 0xBE && firstByte != 0xAF)

View File

@ -1,49 +1,55 @@
package com.bytezone.diskbrowser.applefile; package com.bytezone.diskbrowser.applefile;
public class WizardryTitle extends AbstractFile // -----------------------------------------------------------------------------------//
{ public class WizardryTitle extends AbstractFile
public WizardryTitle (String name, byte[] buffer) // -----------------------------------------------------------------------------------//
{ {
super (name, buffer); public WizardryTitle (String name, byte[] buffer)
} {
super (name, buffer);
@Override }
public String getText ()
{ // ---------------------------------------------------------------------------------//
int size = 20; @Override
StringBuilder text = new StringBuilder (); public String getText ()
for (int i = 0; i < buffer.length; i += size) // ---------------------------------------------------------------------------------//
{ {
for (int line = 0; line < size; line++) int size = 20;
{ StringBuilder text = new StringBuilder ();
int p = i + line; for (int i = 0; i < buffer.length; i += size)
if (p >= buffer.length) {
break; for (int line = 0; line < size; line++)
int value = buffer[p] & 0xFF; {
text = decode2 (value, text); int p = i + line;
} if (p >= buffer.length)
text.append ("\n"); break;
} int value = buffer[p] & 0xFF;
return text.toString (); text = decode2 (value, text);
} }
text.append ("\n");
// private StringBuilder decode (int value, StringBuilder text) }
// { return text.toString ();
// for (int bit = 0; bit < 8; bit++) }
// {
// text.append ((value & 0x01) == 1 ? "X" : " "); // private StringBuilder decode (int value, StringBuilder text)
// value >>= 1; // {
// } // for (int bit = 0; bit < 8; bit++)
// return text; // {
// } // text.append ((value & 0x01) == 1 ? "X" : " ");
// value >>= 1;
private StringBuilder decode2 (int value, StringBuilder text) // }
{ // return text;
for (int bit = 7; bit >= 0; bit--) // }
{
text.append ((value & 0x01) == 1 ? "X" : " "); // ---------------------------------------------------------------------------------//
value >>= 1; private StringBuilder decode2 (int value, StringBuilder text)
} // ---------------------------------------------------------------------------------//
return text; {
} for (int bit = 7; bit >= 0; bit--)
{
text.append ((value & 0x01) == 1 ? "X" : " ");
value >>= 1;
}
return text;
}
} }