display font characters

This commit is contained in:
Denis Molony 2017-01-20 15:07:08 +11:00
parent c8397009fa
commit 978aa8b6a0
12 changed files with 195 additions and 89 deletions

View File

@ -18,14 +18,14 @@ public class IconFile extends AbstractFile
super (name, buffer); super (name, buffer);
iBlkNext = HexFormatter.getLong (buffer, 0); iBlkNext = HexFormatter.getLong (buffer, 0);
iBlkID = HexFormatter.getShort (buffer, 4); iBlkID = HexFormatter.unsignedShort (buffer, 4);
iBlkPath = HexFormatter.getLong (buffer, 6); iBlkPath = HexFormatter.getLong (buffer, 6);
iBlkName = HexFormatter.getHexString (buffer, 10, 16); iBlkName = HexFormatter.getHexString (buffer, 10, 16);
int ptr = 26; int ptr = 26;
while (true) while (true)
{ {
int dataLen = HexFormatter.getShort (buffer, ptr); int dataLen = HexFormatter.unsignedShort (buffer, ptr);
if (dataLen == 0 || (dataLen + ptr) > buffer.length) if (dataLen == 0 || (dataLen + ptr) > buffer.length)
break; break;
icons.add (new Icon (buffer, ptr)); icons.add (new Icon (buffer, ptr));
@ -66,7 +66,7 @@ public class IconFile extends AbstractFile
public Icon (byte[] fullBuffer, int ptr) public Icon (byte[] fullBuffer, int ptr)
{ {
iDataLen = HexFormatter.getShort (fullBuffer, ptr); iDataLen = HexFormatter.unsignedShort (fullBuffer, ptr);
buffer = new byte[iDataLen]; buffer = new byte[iDataLen];
System.arraycopy (fullBuffer, ptr, buffer, 0, buffer.length); System.arraycopy (fullBuffer, ptr, buffer, 0, buffer.length);
@ -77,8 +77,8 @@ public class IconFile extends AbstractFile
len = buffer[66] & 0xFF; len = buffer[66] & 0xFF;
dataName = new String (buffer, 67, len); dataName = new String (buffer, 67, len);
iDataType = HexFormatter.getShort (buffer, 82); iDataType = HexFormatter.unsignedShort (buffer, 82);
iDataAux = HexFormatter.getShort (buffer, 84); iDataAux = HexFormatter.unsignedShort (buffer, 84);
largeImage = new Image (buffer, 86); largeImage = new Image (buffer, 86);
smallImage = new Image (buffer, 86 + largeImage.size ()); smallImage = new Image (buffer, 86 + largeImage.size ());
@ -111,10 +111,10 @@ public class IconFile extends AbstractFile
public Image (byte[] buffer, int ptr) public Image (byte[] buffer, int ptr)
{ {
iconType = HexFormatter.getShort (buffer, ptr); iconType = HexFormatter.unsignedShort (buffer, ptr);
iconSize = HexFormatter.getShort (buffer, ptr + 2); iconSize = HexFormatter.unsignedShort (buffer, ptr + 2);
iconHeight = HexFormatter.getShort (buffer, ptr + 4); iconHeight = HexFormatter.unsignedShort (buffer, ptr + 4);
iconWidth = HexFormatter.getShort (buffer, ptr + 6); iconWidth = HexFormatter.unsignedShort (buffer, ptr + 6);
main = new byte[iconSize]; main = new byte[iconSize];
mask = new byte[iconSize]; mask = new byte[iconSize];

View File

@ -1,10 +1,19 @@
package com.bytezone.diskbrowser.applefile; package com.bytezone.diskbrowser.applefile;
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.util.HashMap;
import java.util.Map;
import com.bytezone.diskbrowser.prodos.ProdosConstants; import com.bytezone.diskbrowser.prodos.ProdosConstants;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class QuickDrawFont extends AbstractFile public class QuickDrawFont extends AbstractFile
{ {
Map<Integer, Character> characters = new HashMap<Integer, Character> ();
private boolean corrupt; private boolean corrupt;
private final int fileType; private final int fileType;
private final int auxType; private final int auxType;
@ -19,12 +28,12 @@ public class QuickDrawFont extends AbstractFile
private final int fontType; private final int fontType;
private final int firstChar; private final int firstChar;
private final int lastChar; private final int lastChar;
private final int maxWidth; private final int widMax;
private final int maxKern; private final int kernMax;
private final int negativeDescent; private final int nDescent;
private final int rectangleWidth; private final int fRectWidth;
private final int rectangleHeight; private final int fRectHeight;
private final int offsetToOffsetWidthTable; private final int owTLoc;
private final int ascent; private final int ascent;
private final int descent; private final int descent;
private final int leading; private final int leading;
@ -53,44 +62,44 @@ public class QuickDrawFont extends AbstractFile
fontName = HexFormatter.getPascalString (buffer, 0); fontName = HexFormatter.getPascalString (buffer, 0);
int nameLength = (buffer[0] & 0xFF); int nameLength = (buffer[0] & 0xFF);
int ptr = nameLength + 1; int ptr = nameLength + 1; // start of header record
headerSize = HexFormatter.getShort (buffer, ptr); headerSize = HexFormatter.unsignedShort (buffer, ptr);
fontDefinitionOffset = nameLength + 1 + headerSize * 2; fontDefinitionOffset = nameLength + 1 + headerSize * 2;
fontFamily = HexFormatter.getShort (buffer, ptr + 2); fontFamily = HexFormatter.unsignedShort (buffer, ptr + 2);
fontStyle = HexFormatter.getShort (buffer, ptr + 4); fontStyle = HexFormatter.unsignedShort (buffer, ptr + 4);
fontSize = HexFormatter.getShort (buffer, ptr + 6); fontSize = HexFormatter.unsignedShort (buffer, ptr + 6);
versionMajor = buffer[ptr + 8] & 0xFF; versionMajor = buffer[ptr + 8] & 0xFF;
versionMinor = buffer[ptr + 9] & 0xFF; versionMinor = buffer[ptr + 9] & 0xFF;
extent = HexFormatter.getShort (buffer, ptr + 10); extent = HexFormatter.unsignedShort (buffer, ptr + 10);
ptr = fontDefinitionOffset; ptr = fontDefinitionOffset;
fontType = HexFormatter.getShort (buffer, ptr); fontType = HexFormatter.unsignedShort (buffer, ptr);
firstChar = HexFormatter.getShort (buffer, ptr + 2); firstChar = HexFormatter.unsignedShort (buffer, ptr + 2);
lastChar = HexFormatter.getShort (buffer, ptr + 4); lastChar = HexFormatter.unsignedShort (buffer, ptr + 4);
maxWidth = HexFormatter.getShort (buffer, ptr + 6); widMax = HexFormatter.unsignedShort (buffer, ptr + 6);
maxKern = HexFormatter.getShort (buffer, ptr + 8); kernMax = HexFormatter.signedShort (buffer, ptr + 8);
negativeDescent = HexFormatter.getShort (buffer, ptr + 10); nDescent = HexFormatter.signedShort (buffer, ptr + 10);
rectangleWidth = HexFormatter.getShort (buffer, ptr + 12); fRectWidth = HexFormatter.unsignedShort (buffer, ptr + 12);
rectangleHeight = HexFormatter.getShort (buffer, ptr + 14); fRectHeight = HexFormatter.unsignedShort (buffer, ptr + 14);
imageLines = new String[rectangleHeight]; imageLines = new String[fRectHeight];
offsetToOffsetWidthTable = HexFormatter.getShort (buffer, ptr + 16); owTLoc = HexFormatter.unsignedShort (buffer, ptr + 16);
offsetWidthTableOffset = (ptr + 16) + offsetToOffsetWidthTable * 2; offsetWidthTableOffset = (ptr + 16) + owTLoc * 2;
locationTableOffset = offsetWidthTableOffset - (lastChar - firstChar + 3) * 2; locationTableOffset = offsetWidthTableOffset - (lastChar - firstChar + 3) * 2;
bitImageOffset = ptr + 26; bitImageOffset = ptr + 26;
ascent = HexFormatter.getShort (buffer, ptr + 18); ascent = HexFormatter.unsignedShort (buffer, ptr + 18);
descent = HexFormatter.getShort (buffer, ptr + 20); descent = HexFormatter.unsignedShort (buffer, ptr + 20);
leading = HexFormatter.getShort (buffer, ptr + 22); leading = HexFormatter.unsignedShort (buffer, ptr + 22);
rowWords = HexFormatter.getShort (buffer, ptr + 24); rowWords = HexFormatter.unsignedShort (buffer, ptr + 24);
totalCharacters = lastChar - firstChar + 2; // includes missing character totalCharacters = lastChar - firstChar + 2; // includes missing character
bitImage = new byte[rowWords * 2 * rectangleHeight]; // should use java bits bitImage = new byte[rowWords * 2 * fRectHeight]; // should use java bits
locationTable = new byte[(totalCharacters + 1) * 2]; locationTable = new byte[(totalCharacters + 1) * 2];
offsetWidthTable = new byte[(totalCharacters + 1) * 2]; offsetWidthTable = new byte[(totalCharacters + 1) * 2];
@ -115,7 +124,7 @@ public class QuickDrawFont extends AbstractFile
System.arraycopy (buffer, offsetWidthTableOffset, offsetWidthTable, 0, System.arraycopy (buffer, offsetWidthTableOffset, offsetWidthTable, 0,
offsetWidthTable.length); offsetWidthTable.length);
for (int i = 0; i < rectangleHeight; i++) for (int i = 0; i < fRectHeight; i++)
{ {
int rowOffset = i * rowWords * 2; int rowOffset = i * rowWords * 2;
@ -128,14 +137,14 @@ public class QuickDrawFont extends AbstractFile
// System.out.println ("\n Location table o/w table\n"); // System.out.println ("\n Location table o/w table\n");
for (int i = 0, max = totalCharacters + 1; i < max; i++) for (int i = 0, max = totalCharacters + 1; i < max; i++)
{ {
int location = HexFormatter.getShort (locationTable, i * 2); int location = HexFormatter.unsignedShort (locationTable, i * 2);
int offset = offsetWidthTable[i * 2] & 0xFF; int offset = offsetWidthTable[i * 2] & 0xFF;
int width = offsetWidthTable[i * 2 + 1] & 0xFF; int width = offsetWidthTable[i * 2 + 1] & 0xFF;
int j = i + 1; int j = i + 1;
if (j < max) if (j < max)
{ {
int nextLocation = HexFormatter.getShort (locationTable, j * 2); int nextLocation = HexFormatter.unsignedShort (locationTable, j * 2);
int pixelWidth = nextLocation - location; int pixelWidth = nextLocation - location;
// System.out.printf ("%3d %04X %04X %2d %02X %02X%n", i, location, // System.out.printf ("%3d %04X %04X %2d %02X %02X%n", i, location,
// nextLocation, pixelWidth, offset, width); // nextLocation, pixelWidth, offset, width);
@ -145,9 +154,50 @@ public class QuickDrawFont extends AbstractFile
corrupt = true; corrupt = true;
return; return;
} }
if (pixelWidth > 0)
characters.put (i, new Character (location, pixelWidth));
} }
// else }
// System.out.printf ("%3d %04X %n", i, location);
if (true)
{
int base = 10;
int spacing = 5;
int charsWide = (int) Math.sqrt (totalCharacters);
int charsHigh = (totalCharacters - 1) / charsWide + 1;
image = new BufferedImage (charsWide * (widMax + spacing) + base * 2,
charsHigh * (fRectHeight + leading) + base * 2, BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2d = image.createGraphics ();
g2d.setComposite (
AlphaComposite.getInstance (AlphaComposite.SRC_OVER, (float) 1.0));
int x = base;
int y = base;
int count = 0;
for (int i = 0; i < totalCharacters + 1; i++)
{
Character character;
if (characters.containsKey (i))
character = characters.get (i);
else
character = characters.get (lastChar + 1);
if (character != null)
g2d.drawImage (character.image, x, y, null);
x += widMax + spacing;
if (++count % charsWide == 0)
{
x = base;
y += fRectHeight + leading;
}
}
g2d.dispose ();
} }
} }
@ -169,12 +219,12 @@ public class QuickDrawFont extends AbstractFile
text.append (String.format ("Font type : %d%n", fontType)); text.append (String.format ("Font type : %d%n", fontType));
text.append (String.format ("First char : %d%n", firstChar)); text.append (String.format ("First char : %d%n", firstChar));
text.append (String.format ("Last char : %d%n", lastChar)); text.append (String.format ("Last char : %d%n", lastChar));
text.append (String.format ("Max width : %d%n", maxWidth)); text.append (String.format ("Max width : %d%n", widMax));
text.append (String.format ("Max kern : %d%n", maxKern)); text.append (String.format ("Max kern : %d%n", kernMax));
text.append (String.format ("Neg descent : %d%n", negativeDescent)); text.append (String.format ("Neg descent : %d%n", nDescent));
text.append (String.format ("Width : %d%n", rectangleWidth)); text.append (String.format ("Width : %d%n", fRectWidth));
text.append (String.format ("Height : %d%n", rectangleHeight)); text.append (String.format ("Height : %d%n", fRectHeight));
text.append (String.format ("O/W Offset : %d%n", offsetToOffsetWidthTable)); text.append (String.format ("O/W Offset : %04X%n", owTLoc));
text.append (String.format ("Ascent : %d%n", ascent)); text.append (String.format ("Ascent : %d%n", ascent));
text.append (String.format ("Descent : %d%n", descent)); text.append (String.format ("Descent : %d%n", descent));
text.append (String.format ("Leading : %d%n", leading)); text.append (String.format ("Leading : %d%n", leading));
@ -194,17 +244,18 @@ public class QuickDrawFont extends AbstractFile
if (offset == 255 && width == 255) if (offset == 255 && width == 255)
continue; continue;
int location = HexFormatter.getShort (locationTable, i * 2); int location = HexFormatter.unsignedShort (locationTable, i * 2);
int nextLocation = HexFormatter.getShort (locationTable, (i + 1) * 2); int nextLocation = HexFormatter.unsignedShort (locationTable, (i + 1) * 2);
int pixelWidth = nextLocation - location; int pixelWidth = nextLocation - location;
text.append (String.format ("Char %3d %,5d %2d %,5d %,5d%n", i, location, text.append (String.format (
pixelWidth, offset, width)); "Char %3d, location %,5d, pixelWidth %2d. offset %,5d, width %,5d%n", i,
location, pixelWidth, offset, width));
if (pixelWidth > 0 && location + pixelWidth < imageLines[0].length ()) if (pixelWidth > 0 && location + pixelWidth < imageLines[0].length ())
for (int j = 0; j < rectangleHeight; j++) for (int j = 0; j < fRectHeight; j++)
{ {
for (int w = 0; w < width; w++) for (int w = 0; w < offset; w++)
text.append (' '); text.append (' ');
text.append (imageLines[j].substring (location, location + pixelWidth)); text.append (imageLines[j].substring (location, location + pixelWidth));
text.append ("\n"); text.append ("\n");
@ -214,7 +265,7 @@ public class QuickDrawFont extends AbstractFile
if (false) if (false)
{ {
text.append ("\n\n"); text.append ("\n\n");
for (int i = 0; i < rectangleHeight; i++) for (int i = 0; i < fRectHeight; i++)
{ {
text.append (String.format ("Row: %d%n", i)); text.append (String.format ("Row: %d%n", i));
int rowOffset = i * rowWords * 2; int rowOffset = i * rowWords * 2;
@ -235,7 +286,7 @@ public class QuickDrawFont extends AbstractFile
text.append ("\n\n"); text.append ("\n\n");
for (int i = 0; i < totalCharacters; i++) for (int i = 0; i < totalCharacters; i++)
{ {
int location = HexFormatter.getShort (locationTable, i * 2); int location = HexFormatter.unsignedShort (locationTable, i * 2);
text.append (String.format ("%3d %04X %,7d%n", i, location, location)); text.append (String.format ("%3d %04X %,7d%n", i, location, location));
} }
@ -250,4 +301,34 @@ public class QuickDrawFont extends AbstractFile
return text.toString (); return text.toString ();
} }
class Character
{
private final BufferedImage image;
private final int location;
private final int pixelWidth;
// offset - where to start drawing relative to current pen location
// width - how far to move the current pen location after drawing
// location - index into imageLines[]
// pixelWidth - number of pixels to copy from imageLines[]
public Character (int location, int pixelWidth)
{
this.location = location;
this.pixelWidth = pixelWidth;
image = new BufferedImage (pixelWidth, fRectHeight, BufferedImage.TYPE_BYTE_GRAY);
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
if (pixelWidth > 0 && location + pixelWidth < imageLines[0].length ())
for (int i = 0; i < fRectHeight; i++)
{
int element = i * pixelWidth; // start of row
String row = imageLines[i].substring (location, location + pixelWidth);
for (char c : row.toCharArray ())
dataBuffer.setElem (element++, c == '.' ? 0 : 255);
}
}
}
} }

View File

@ -122,7 +122,7 @@ public class ShapeTable extends AbstractFile
return false; return false;
// check index points inside the file // check index points inside the file
int offset = HexFormatter.getShort (buffer, ptr); int offset = HexFormatter.unsignedShort (buffer, ptr);
if (offset == 0 || offset >= buffer.length) if (offset == 0 || offset >= buffer.length)
return false; return false;
} }
@ -156,7 +156,7 @@ public class ShapeTable extends AbstractFile
int row = startRow; int row = startRow;
int col = startCol; int col = startCol;
offset = HexFormatter.getShort (buffer, index * 2 + 2); offset = HexFormatter.unsignedShort (buffer, index * 2 + 2);
int ptr = offset; int ptr = offset;
while (ptr < buffer.length) while (ptr < buffer.length)

View File

@ -48,7 +48,7 @@ public class AppleworksADBFile extends AbstractFile
dbMinVersion = buffer[218] & 0xFF; dbMinVersion = buffer[218] & 0xFF;
headerSize = HexFormatter.getShort (buffer, 0); headerSize = HexFormatter.unsignedShort (buffer, 0);
cursorDirectionSRL = buffer[30]; cursorDirectionSRL = buffer[30];
cursorDirectionMRL = (char) buffer[31]; cursorDirectionMRL = (char) buffer[31];
currentDisplay = (char) buffer[34]; currentDisplay = (char) buffer[34];
@ -56,7 +56,7 @@ public class AppleworksADBFile extends AbstractFile
categoryNames = new String[categories]; categoryNames = new String[categories];
totalReports = buffer[38] & 0xFF; totalReports = buffer[38] & 0xFF;
int recs = HexFormatter.getShort (buffer, 36); int recs = HexFormatter.unsignedShort (buffer, 36);
totalRecords = dbMinVersion == 0 ? recs : recs & 0x7FFF; totalRecords = dbMinVersion == 0 ? recs : recs & 0x7FFF;
for (int i = 0; i < 30; i++) for (int i = 0; i < 30; i++)
@ -75,9 +75,9 @@ public class AppleworksADBFile extends AbstractFile
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
selectionRules[i] = HexFormatter.getShort (buffer, 223 + i * 2); selectionRules[i] = HexFormatter.unsignedShort (buffer, 223 + i * 2);
testTypes[i] = HexFormatter.getShort (buffer, 229 + i * 2); testTypes[i] = HexFormatter.unsignedShort (buffer, 229 + i * 2);
continuation[i] = HexFormatter.getShort (buffer, 235 + i * 2); continuation[i] = HexFormatter.unsignedShort (buffer, 235 + i * 2);
comparison[i] = new String (buffer, 241 + i * 20, 20); comparison[i] = new String (buffer, 241 + i * 20, 20);
} }
@ -102,7 +102,7 @@ public class AppleworksADBFile extends AbstractFile
ptr += 600; ptr += 600;
} }
int length = HexFormatter.getShort (buffer, ptr); int length = HexFormatter.unsignedShort (buffer, ptr);
ptr += 2; ptr += 2;
if (length == 0) if (length == 0)
@ -114,7 +114,7 @@ public class AppleworksADBFile extends AbstractFile
for (int recordNo = 0; recordNo < totalRecords; recordNo++) for (int recordNo = 0; recordNo < totalRecords; recordNo++)
{ {
length = HexFormatter.getShort (buffer, ptr); length = HexFormatter.unsignedShort (buffer, ptr);
ptr += 2; ptr += 2;
if (length == 0) if (length == 0)
break; break;

View File

@ -20,7 +20,7 @@ public class AppleworksSSFile extends AbstractFile
int ptr = header.ssMinVers == 0 ? 300 : 302; int ptr = header.ssMinVers == 0 ? 300 : 302;
while (ptr < buffer.length) while (ptr < buffer.length)
{ {
int length = HexFormatter.getShort (buffer, ptr); int length = HexFormatter.unsignedShort (buffer, ptr);
if (length == 0xFFFF) if (length == 0xFFFF)
break; break;
@ -92,7 +92,7 @@ public class AppleworksSSFile extends AbstractFile
calcOrder = (char) buffer[131]; calcOrder = (char) buffer[131];
calcFrequency = (char) buffer[132]; calcFrequency = (char) buffer[132];
lastRow = HexFormatter.getShort (buffer, 133); lastRow = HexFormatter.unsignedShort (buffer, 133);
lastColumn = buffer[135] & 0xFF; lastColumn = buffer[135] & 0xFF;
windowLayout = (char) buffer[136]; windowLayout = (char) buffer[136];
windowSynch = buffer[137] != 0; windowSynch = buffer[137] != 0;
@ -193,15 +193,15 @@ public class AppleworksSSFile extends AbstractFile
r1 = buffer[offset + 3] & 0xFF; r1 = buffer[offset + 3] & 0xFF;
c1 = buffer[offset + 4] & 0xFF; c1 = buffer[offset + 4] & 0xFF;
r2 = HexFormatter.getShort (buffer, offset + 5); r2 = HexFormatter.unsignedShort (buffer, offset + 5);
c2 = buffer[offset + 7] & 0xFF; c2 = buffer[offset + 7] & 0xFF;
r3 = HexFormatter.getShort (buffer, offset + 8); r3 = HexFormatter.unsignedShort (buffer, offset + 8);
c3 = buffer[offset + 10] & 0xFF; c3 = buffer[offset + 10] & 0xFF;
r4 = HexFormatter.getShort (buffer, offset + 11); r4 = HexFormatter.unsignedShort (buffer, offset + 11);
c4 = buffer[offset + 13] & 0xFF; c4 = buffer[offset + 13] & 0xFF;
r5 = buffer[offset + 14] & 0xFF; r5 = buffer[offset + 14] & 0xFF;
c5 = buffer[offset + 15] & 0xFF; c5 = buffer[offset + 15] & 0xFF;
r6 = HexFormatter.getShort (buffer, offset + 16); r6 = HexFormatter.unsignedShort (buffer, offset + 16);
c6 = buffer[offset + 18] & 0xFF; c6 = buffer[offset + 18] & 0xFF;
r7 = buffer[offset + 19] & 0xFF; r7 = buffer[offset + 19] & 0xFF;
c7 = buffer[offset + 20] & 0xFF; c7 = buffer[offset + 20] & 0xFF;
@ -252,7 +252,7 @@ public class AppleworksSSFile extends AbstractFile
public Row (int ptr) public Row (int ptr)
{ {
rowNumber = HexFormatter.getShort (buffer, ptr); rowNumber = HexFormatter.unsignedShort (buffer, ptr);
ptr += 2; // first control byte ptr += 2; // first control byte
int column = 0; int column = 0;

View File

@ -126,9 +126,9 @@ abstract class Report
if (buffer[offset + 480 + fudge] == 0) // test high byte if (buffer[offset + 480 + fudge] == 0) // test high byte
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
selectionRules[i] = HexFormatter.getShort (buffer, offset + 479 + i * 2 + fudge); selectionRules[i] = HexFormatter.unsignedShort (buffer, offset + 479 + i * 2 + fudge);
testTypes[i] = HexFormatter.getShort (buffer, offset + 485 + i * 2 + fudge); testTypes[i] = HexFormatter.unsignedShort (buffer, offset + 485 + i * 2 + fudge);
continuation[i] = HexFormatter.getShort (buffer, offset + 491 + i * 2 + fudge); continuation[i] = HexFormatter.unsignedShort (buffer, offset + 491 + i * 2 + fudge);
comparison[i] = pascalString (buffer, offset + 497 + i * 32 + fudge); comparison[i] = pascalString (buffer, offset + 497 + i * 32 + fudge);
} }
else else

View File

@ -57,4 +57,18 @@ abstract class CatalogEntry implements AppleFileSource
return true; return true;
return false; return false;
} }
@Override
public String toString ()
{
StringBuilder text = new StringBuilder ();
text.append (String.format ("Name .......... %s%n", name));
text.append (String.format ("Storage type... %02X%n", storageType));
text.append (String.format ("Created ....... %s%n",
created == null ? "" : parentDisk.df.format (created.getTime ())));
text.append (String.format ("Version ....... %d%n", version));
return text.toString ();
}
} }

View File

@ -36,6 +36,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants
int parentBlock) int parentBlock)
{ {
super (fDisk, entryBuffer); super (fDisk, entryBuffer);
assert parent != null;
this.parentDirectory = parent; this.parentDirectory = parent;
this.catalogBlock = this.disk.getDiskAddress (parentBlock); this.catalogBlock = this.disk.getDiskAddress (parentBlock);
@ -93,8 +94,11 @@ class FileEntry extends CatalogEntry implements ProdosConstants
case ProdosConstants.TYPE_SAPLING: case ProdosConstants.TYPE_SAPLING:
traverseIndex (keyBlock); traverseIndex (keyBlock);
break; break;
case ProdosConstants.TYPE_TREE:
traverseMasterIndex (keyBlock);
break;
default: default:
System.out.println ("fork not a sapling or seedling!!!"); System.out.println ("fork not a tree, sapling or seedling!!!");
} }
} }
break; break;
@ -335,9 +339,14 @@ class FileEntry extends CatalogEntry implements ProdosConstants
case FILE_TYPE_ASP: case FILE_TYPE_ASP:
file = new AppleworksSSFile (name + " (Appleworks Spreadsheet File)", buffer); file = new AppleworksSSFile (name + " (Appleworks Spreadsheet File)", buffer);
break; break;
case FILE_TYPE_ASM_SOURCE: case FILE_TYPE_IIGS_SOURCE: // I think this has a resource fork
file = new SimpleText (name, exactBuffer); file = new SimpleText (name, exactBuffer);
break; break;
case FILE_TYPE_IIGS_APPLICATION:
// file =
// new DefaultAppleFile (name, buffer, "S16 Apple IIgs Application Program");
file = new AssemblerProgram (name, buffer, auxType);
break;
case FILE_TYPE_ICN: case FILE_TYPE_ICN:
file = new IconFile (name, exactBuffer); file = new IconFile (name, exactBuffer);
break; break;
@ -352,11 +361,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants
break; break;
default: default:
System.out.format ("Unknown file type : %02X%n", fileType); 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);
} }
} }
catch (Exception e) catch (Exception e)

View File

@ -81,7 +81,7 @@ class ProdosCatalogSector extends AbstractSector
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
int fileType = buffer[offset + 16] & 0xFF; int fileType = buffer[offset + 16] & 0xFF;
int auxType = HexFormatter.getShort (buffer, offset + 31); int auxType = HexFormatter.unsignedShort (buffer, offset + 31);
addText (text, buffer, offset + 16, 1, addText (text, buffer, offset + 16, 1,
"File type (" + ProdosConstants.fileTypes[fileType] + ")"); "File type (" + ProdosConstants.fileTypes[fileType] + ")");
addTextAndDecimal (text, buffer, offset + 17, 2, "Key pointer"); addTextAndDecimal (text, buffer, offset + 17, 2, "Key pointer");

View File

@ -10,9 +10,10 @@ public interface ProdosConstants
int FILE_TYPE_AWP = 0x1A; int FILE_TYPE_AWP = 0x1A;
int FILE_TYPE_ASP = 0x1B; int FILE_TYPE_ASP = 0x1B;
int FILE_TYPE_GWP = 0x50; int FILE_TYPE_GWP = 0x50;
int FILE_TYPE_ASM_SOURCE = 0xB0; int FILE_TYPE_IIGS_SOURCE = 0xB0;
int FILE_TYPE_ASM_OBJECT = 0xB1; int FILE_TYPE_IIGS_OBJECT = 0xB1;
int FILE_TYPE_FORKED_FILE = 0xB3; // S16 // int FILE_TYPE_FORKED_FILE = 0xB3; // S16
int FILE_TYPE_IIGS_APPLICATION = 0xB3;
int FILE_TYPE_PNT = 0xC0; int FILE_TYPE_PNT = 0xC0;
int FILE_TYPE_PIC = 0xC1; int FILE_TYPE_PIC = 0xC1;
int FILE_TYPE_FONT = 0xC8; int FILE_TYPE_FONT = 0xC8;

View File

@ -314,7 +314,7 @@ public class HexFormatter
return val; return val;
} }
public static int getShort (byte[] buffer, int ptr) public static int unsignedShort (byte[] buffer, int ptr)
{ {
int val = 0; int val = 0;
for (int i = 1; i >= 0; i--) for (int i = 1; i >= 0; i--)
@ -325,6 +325,11 @@ public class HexFormatter
return val; return val;
} }
public static int signedShort (byte[] buffer, int ptr)
{
return (short) (((buffer[ptr] & 0xFF) << 8) | (buffer[ptr + 1] & 0xFF));
}
public static int getShortBigEndian (byte[] buffer, int ptr) public static int getShortBigEndian (byte[] buffer, int ptr)
{ {
int val = 0; int val = 0;

View File

@ -286,11 +286,11 @@ public class Wizardry4BootDisk extends PascalDisk
{ {
// System.out.println (HexFormatter.format (buffer, 0x08600 + i * 32, 32)); // System.out.println (HexFormatter.format (buffer, 0x08600 + i * 32, 32));
int offset = 0x08600 + i * 32 + 18; int offset = 0x08600 + i * 32 + 18;
int key = HexFormatter.getShort (buffer, offset); int key = HexFormatter.unsignedShort (buffer, offset);
if (key > 0) if (key > 0)
text.append (String.format ("%04X %04X * %s%n", offset, key, text.append (String.format ("%04X %04X * %s%n", offset, key,
messageBlock.getMessageText (key))); messageBlock.getMessageText (key)));
key = HexFormatter.getShort (buffer, offset + 8); key = HexFormatter.unsignedShort (buffer, offset + 8);
if (key > 0) if (key > 0)
text.append (String.format ("%04X %04X %s%n", offset + 8, key, text.append (String.format ("%04X %04X %s%n", offset + 8, key,
messageBlock.getMessageText (key))); messageBlock.getMessageText (key)));