From 2a79664404a3db8b05dc4fed3cf8ecbac942b74b Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Wed, 25 Jul 2018 15:48:14 +1000 Subject: [PATCH] graphic images --- .../diskbrowser/applefile/HiResImage.java | 42 ++++- ...RPictureFile.java => SHRPictureFile1.java} | 12 +- .../applefile/SHRPictureFile2.java | 119 ++++++++----- .../diskbrowser/applefile/ShapeTable.java | 29 +-- .../bytezone/diskbrowser/disk/AppleDisk.java | 3 - src/com/bytezone/diskbrowser/disk/Disk.java | 4 +- .../duplicates/DuplicateSwingWorker.java | 3 + .../bytezone/diskbrowser/gui/TreeBuilder.java | 4 + .../diskbrowser/prodos/FileEntry.java | 166 ++++++++++-------- .../prodos/ProdosBitMapSector.java | 2 - .../diskbrowser/prodos/ProdosConstants.java | 1 + .../diskbrowser/prodos/ProdosDisk.java | 5 + .../diskbrowser/utilities/HexFormatter.java | 22 ++- 13 files changed, 253 insertions(+), 159 deletions(-) rename src/com/bytezone/diskbrowser/applefile/{SHRPictureFile.java => SHRPictureFile1.java} (95%) diff --git a/src/com/bytezone/diskbrowser/applefile/HiResImage.java b/src/com/bytezone/diskbrowser/applefile/HiResImage.java index 1a9c4c5..4292d67 100644 --- a/src/com/bytezone/diskbrowser/applefile/HiResImage.java +++ b/src/com/bytezone/diskbrowser/applefile/HiResImage.java @@ -12,6 +12,40 @@ import com.bytezone.diskbrowser.utilities.HexFormatter; public abstract class HiResImage extends AbstractFile { + // File Type Aux Name + // $06 BIN isGif() - OriginalHiResImage + // $06 BIN isPng() - OriginalHiResImage + // $06 BIN .BMP isBmp() - OriginalHiResImage + // $06 BIN .AUX - DoubleHiResImage + // $06 BIN .PAC - DoubleHiResImage + // $06 BIN .A2FC - DoubleHiResImage + // $06 BIN $2000 eof $4000 - DoubleHiResImage + // $06 BIN $1FFF eof $1FF8/$1FFF/$2000/$4000 - OriginalHiResImage + // $06 BIN $2000 eof $1FF8/$1FFF/$2000/$4000 - OriginalHiResImage + // $06 BIN $4000 eof $1FF8/$1FFF/$2000/$4000 - OriginalHiResImage + // $06 BIN .3200 - ??? + // $06 BIN .3201 - ??? + + // $08 PICT <$4000 Apple II Graphics File - ??? + // $08 PICT $4000 Packed Hi-Res file - ??? + // $08 PICT $4001 Packed Double Hi-Res file - ??? + + // $C0 PNT $0000 Paintworks Packed Super Hi-Res - SHRPictureFile2 * + // * $C0 PNT $0001 Packed IIGS Super Hi-Res Image (xx) - SHRPictureFile2 + // * $C0 PNT $0002 IIGS Super Hi-Res Picture File (APF) - SHRPictureFile + // $C0 PNT $0003 Packed IIGS QuickDraw II PICT File - SHRPictureFile2 * + // $C0 PNT $0004 Packed Super Hi-Res 3200 (Brooks) (yy) - SHRPictureFile2 * + // $C0 PNT $8001 + // $C0 PNT $8005 + // $C0 PNT $8006 + + // * $C1 PIC $0000 IIGS Super Hi-Res Image (xx) - SHRPictureFile2 + // $C1 PIC $0001 IIGS QuickDraw II PICT File - SHRPictureFile2 * + // * $C1 PIC $0002 Super Hi-Res 3200 (Brooks) (yy) - SHRPictureFile2 + // $C1 PIC $8001 + // $C1 PIC $8002 + // $C1 PIC $8003 + protected static PaletteFactory paletteFactory = new PaletteFactory (); private static final byte[] pngHeader = @@ -215,18 +249,18 @@ public abstract class HiResImage extends AbstractFile switch (type) { - case 0: + case 0: // copy next 1-64 bytes as is while (count-- != 0) newBuf[newPtr++] = buffer[ptr++]; break; - case 1: + case 1: // repeat next byte 3/5/6/7 times byte b = buffer[ptr++]; while (count-- != 0) newBuf[newPtr++] = b; break; - case 2: + case 2: // repeat next 4 bytes (count) times for (int i = 0; i < 4; i++) fourBuf[i] = buffer[ptr++]; while (count-- != 0) @@ -234,7 +268,7 @@ public abstract class HiResImage extends AbstractFile newBuf[newPtr++] = fourBuf[i]; break; - case 3: + case 3: // repeat next byte (4*count) times b = buffer[ptr++]; count *= 4; while (count-- != 0) diff --git a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java similarity index 95% rename from src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java rename to src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java index 5629f5e..da22643 100644 --- a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java +++ b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java @@ -7,14 +7,14 @@ import java.util.List; import com.bytezone.diskbrowser.utilities.HexFormatter; -public class SHRPictureFile extends HiResImage +public class SHRPictureFile1 extends HiResImage { private final List blocks = new ArrayList (); private Main mainBlock; private Multipal multipalBlock; - // 0xC0 aux = 2 - public SHRPictureFile (String name, byte[] buffer, int fileType, int auxType, int eof) + // 0xC0 aux = 2 - Apple IIGS Super Hi-Res Picture File + public SHRPictureFile1 (String name, byte[] buffer, int fileType, int auxType, int eof) { super (name, buffer, fileType, auxType, eof); @@ -176,9 +176,9 @@ public class SHRPictureFile extends HiResImage private class Main extends Block { - int masterMode; - int pixelsPerScanLine; - int numColorTables; + int masterMode; // 0 = Brooks, 0 = PNT 320 80 = PNT 640 + int pixelsPerScanLine; // 320 or 640 + int numColorTables; // 1 = Brooks, 16 = Other ColorTable[] colorTables; int numScanLines; DirEntry[] scanLineDirectory; diff --git a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java index cf3bd8a..22f2254 100644 --- a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java +++ b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java @@ -11,59 +11,88 @@ public class SHRPictureFile2 extends HiResImage ColorTable[] colorTables; byte[] scb; // 0xC1 aux=0 + // see Graphics & Animation.2mg + public SHRPictureFile2 (String name, byte[] buffer, int fileType, int auxType, int eof) { super (name, buffer, fileType, auxType, eof); - if (fileType == ProdosConstants.FILE_TYPE_PNT) // 0xC0 + switch (fileType) { - if (auxType == 0) - { - System.out.println ("0xC0 aux 0 not written"); - } - else if (auxType == 1) // Eagle/PackBytes - { - // this unpacks directly to the screen locations - System.out.println ("0xC0 aux 1 not written"); - } - else - System.out.println ("C0 unknown aux " + auxType); - } - else if (fileType == ProdosConstants.FILE_TYPE_PIC) // 0xC1 - { - if (auxType > 2) - { - System.out.printf ("Changing aux from %04X to 0 in %s%n", auxType, name); - auxType = 0; - } - - if (auxType == 0) // 32,768 - { - scb = new byte[200]; - System.arraycopy (buffer, 32000, scb, 0, scb.length); - - colorTables = new ColorTable[16]; - for (int i = 0; i < colorTables.length; i++) - colorTables[i] = new ColorTable (i, buffer, 32256 + i * 32); - } - else if (auxType == 1) - { - System.out.println ("0xC1 aux 1 not written"); - } - else if (auxType == 2) // Brooks 38,400 - { - colorTables = new ColorTable[200]; - for (int i = 0; i < colorTables.length; i++) + case ProdosConstants.FILE_TYPE_PNT: + switch (auxType) { - colorTables[i] = new ColorTable (i, buffer, 32000 + i * 32); - colorTables[i].reverse (); + case 0: + System.out.printf ( + "%s: PNT aux 0 (Paintworks Packed SHR Image) not written yet%n", name); + break; + + case 1: // Eagle/PackBytes - unpacks to PIC/$00 + this.buffer = unpackBytes (buffer); + scb = new byte[200]; + System.arraycopy (this.buffer, 32000, scb, 0, scb.length); + + colorTables = new ColorTable[16]; + for (int i = 0; i < colorTables.length; i++) + colorTables[i] = new ColorTable (i, this.buffer, 32256 + i * 32); + break; + + case 2: // handled in SHRPictureFile1 + break; + + case 3: + System.out.printf ("%s: PNT aux 3 (Packed IIGS SHR Image) not written yet%n", + name); + break; + + case 4: + System.out.printf ( + "%s: PNT aux 4 (Packed SHR Brooks Image) not written yet%n", name); + break; + + default: + System.out.printf ("%s: PNT unknown aux: %04X%n", name, auxType); } - } - else - System.out.println ("C1 unknown aux " + auxType); + break; + + case ProdosConstants.FILE_TYPE_PIC: + if (auxType > 2) + { + System.out.printf ("%s: PIC changing aux from %04X to 0%n", name, auxType); + auxType = 0; + } + + switch (auxType) + { + case 0: // 32,768 + scb = new byte[200]; + System.arraycopy (buffer, 32000, scb, 0, scb.length); + + colorTables = new ColorTable[16]; + for (int i = 0; i < colorTables.length; i++) + colorTables[i] = new ColorTable (i, buffer, 32256 + i * 32); + break; + + case 1: + System.out.printf ("%s: PIC aux 1 not written yet%n", name); + break; + + case 2: // Brooks 38,400 + colorTables = new ColorTable[200]; + for (int i = 0; i < colorTables.length; i++) + { + colorTables[i] = new ColorTable (i, buffer, 32000 + i * 32); + colorTables[i].reverse (); + } + break; + + default: + System.out.println ("PIC unknown aux " + auxType); + } + break; + default: + System.out.println ("unknown filetype " + fileType); } - else - System.out.println ("unknown filetype " + fileType); if (colorTables != null) createImage (); diff --git a/src/com/bytezone/diskbrowser/applefile/ShapeTable.java b/src/com/bytezone/diskbrowser/applefile/ShapeTable.java index cae6a82..f907f69 100755 --- a/src/com/bytezone/diskbrowser/applefile/ShapeTable.java +++ b/src/com/bytezone/diskbrowser/applefile/ShapeTable.java @@ -41,6 +41,8 @@ public class ShapeTable extends AbstractFile for (int i = 0; i < totalShapes; i++) { Shape shape = new Shape (buffer, i); + if (!shape.valid) + return; shapes.add (shape); minRow = Math.min (minRow, shape.minRow); @@ -87,8 +89,6 @@ public class ShapeTable extends AbstractFile text.append (String.format ("File Name : %s%n", name)); text.append (String.format ("File size : %,d%n", buffer.length)); text.append (String.format ("Total shapes : %d%n", shapes.size ())); - // text.append (String.format ("Smallest : %d%n", minSize)); - // text.append (String.format ("Largest : %d%n", maxSize)); text.append (String.format ("Max dimensions : %d x %d%n%n", maxWidth, maxHeight)); for (Shape shape : shapes) @@ -139,12 +139,11 @@ public class ShapeTable extends AbstractFile int actualLength; int minRow, maxRow; int minCol, maxCol; - // int endRow, endCol; int startRow = SIZE / 2; int startCol = SIZE / 2; int[][] grid = new int[SIZE][SIZE]; int[][] displayGrid; - // int height, width; + boolean valid; private BufferedImage image; @@ -174,7 +173,8 @@ public class ShapeTable extends AbstractFile // rightmost 3 bits if (v3 >= 4) - plot (grid, row, col); + if (!plot (grid, row, col)) + return; if (v3 == 0 || v3 == 4) row--; @@ -187,7 +187,8 @@ public class ShapeTable extends AbstractFile // middle 3 bits if (v2 >= 4) - plot (grid, row, col); + if (!plot (grid, row, col)) + return; // cannot move up without plotting if v1 is zero if ((v2 == 0 && v1 != 0) || v2 == 4) @@ -240,12 +241,7 @@ public class ShapeTable extends AbstractFile maxCol = Math.max (maxCol, col); } } - - // height = maxRow - minRow + 1; - // width = maxCol - minCol + 1; - // System.out.printf ("%4d %4d %4d %4d %4d%n", - // index, minRow, maxRow, minCol, - // maxCol); + valid = true; } void convertGrid (int offsetRows, int offsetColumns, int rows, int columns) @@ -275,11 +271,18 @@ public class ShapeTable extends AbstractFile // endCol -= offsetColumns; } - private void plot (int[][] grid, int row, int col) + private boolean plot (int[][] grid, int row, int col) { + if (row < 0 || row >= SIZE || col < 0 || col >= SIZE) + { + System.out.printf ("Shape table out of range: %d, %d%n", row, col); + return false; + } grid[row][col] = 1; // plot grid[0][col]++; // increment total column dots grid[row][0]++; // increment total row dots + + return true; } public void drawText (StringBuilder text) diff --git a/src/com/bytezone/diskbrowser/disk/AppleDisk.java b/src/com/bytezone/diskbrowser/disk/AppleDisk.java index 87923e9..ca07ea5 100755 --- a/src/com/bytezone/diskbrowser/disk/AppleDisk.java +++ b/src/com/bytezone/diskbrowser/disk/AppleDisk.java @@ -484,9 +484,6 @@ public class AppleDisk implements Disk @Override public boolean isValidAddress (int block) { - // if (block < 0 || block >= this.blocks) - // return false; - // return true; return block >= 0 && block < this.blocks; } diff --git a/src/com/bytezone/diskbrowser/disk/Disk.java b/src/com/bytezone/diskbrowser/disk/Disk.java index 1a8bce2..e67516d 100755 --- a/src/com/bytezone/diskbrowser/disk/Disk.java +++ b/src/com/bytezone/diskbrowser/disk/Disk.java @@ -42,12 +42,12 @@ public interface Disk extends Iterable public void writeSector (DiskAddress da, byte[] buffer); - public boolean isSectorEmpty (DiskAddress da); - public boolean isSectorEmpty (int block); public boolean isSectorEmpty (int track, int sector); + public boolean isSectorEmpty (DiskAddress da); + public boolean isValidAddress (int block); public boolean isValidAddress (int track, int sector); diff --git a/src/com/bytezone/diskbrowser/duplicates/DuplicateSwingWorker.java b/src/com/bytezone/diskbrowser/duplicates/DuplicateSwingWorker.java index 0cdfa47..783a595 100644 --- a/src/com/bytezone/diskbrowser/duplicates/DuplicateSwingWorker.java +++ b/src/com/bytezone/diskbrowser/duplicates/DuplicateSwingWorker.java @@ -53,6 +53,9 @@ public class DuplicateSwingWorker extends SwingWorker if (rootFolderData.progressPanel.cancelled) return; + if (file.isHidden ()) + continue; + if (file.isDirectory ()) { if (file.getName ().equalsIgnoreCase ("emulators")) diff --git a/src/com/bytezone/diskbrowser/gui/TreeBuilder.java b/src/com/bytezone/diskbrowser/gui/TreeBuilder.java index 9a06032..87c0db8 100755 --- a/src/com/bytezone/diskbrowser/gui/TreeBuilder.java +++ b/src/com/bytezone/diskbrowser/gui/TreeBuilder.java @@ -60,10 +60,14 @@ public class TreeBuilder Arrays.sort (files, fileComparator); for (File file : files) + { + if (file.isHidden ()) + continue; if (file.isDirectory ()) parentNode.add (createNode (file, true)); else if (Utility.validFileType (file.getName ()) && file.length () > 0) parentNode.add (createNode (file, false)); + } } private DefaultMutableTreeNode createNode (File file, boolean allowsChildren) diff --git a/src/com/bytezone/diskbrowser/prodos/FileEntry.java b/src/com/bytezone/diskbrowser/prodos/FileEntry.java index d95239e..803f932 100755 --- a/src/com/bytezone/diskbrowser/prodos/FileEntry.java +++ b/src/com/bytezone/diskbrowser/prodos/FileEntry.java @@ -115,19 +115,19 @@ class FileEntry extends CatalogEntry implements ProdosConstants switch (storageType) { case SEEDLING: - if (disk.isValidAddress (keyPtr)) + if (isValid (keyPtr)) blocks.add (keyPtr); break; case SAPLING: - if (disk.isValidAddress (keyPtr)) + if (isValid (keyPtr)) blocks.addAll (readIndex (keyPtr)); break; case TREE: - if (disk.isValidAddress (keyPtr)) + if (isValid (keyPtr)) for (Integer indexBlock : readMasterIndex (keyPtr)) - if (disk.isValidAddress (indexBlock)) + if (isValid (indexBlock)) blocks.addAll (readIndex (indexBlock)); break; } @@ -164,7 +164,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants for (int i = 0; i < 256; i++) { int blockNo = (buffer[i] & 0xFF) | ((buffer[i + 0x100] & 0xFF) << 8); - blocks.add (disk.isValidAddress (blockNo) ? blockNo : 0); + blocks.add (isValid (blockNo) ? blockNo : 0); } } @@ -187,12 +187,24 @@ class FileEntry extends CatalogEntry implements ProdosConstants for (int i = 0; i <= highest; i++) { int blockNo = (buffer[i] & 0xFF) | ((buffer[i + 256] & 0xFF) << 8); - blocks.add (disk.isValidAddress (blockNo) ? blockNo : 0); + blocks.add (isValid (blockNo) ? blockNo : 0); } return blocks; } + private boolean isValid (int blockNo) + { + if (true) + { + if (!disk.isValidAddress (blockNo)) + System.out.println ("--Invalid Address: " + blockNo); + if (parentDisk.isSectorFree (blockNo)) + System.out.println ("--Free block: " + blockNo); + } + return disk.isValidAddress (blockNo) && !parentDisk.isSectorFree (blockNo); + } + @Override public DataSource getDataSource () { @@ -208,7 +220,6 @@ class FileEntry extends CatalogEntry implements ProdosConstants if (fileType == FILE_TYPE_TEXT && auxType > 0) // random access file return getRandomAccessTextFile (); - // byte[] buffer = isGSOSFile () ? getGEOSBuffer () : getBuffer (); byte[] buffer = getBuffer (); byte[] exactBuffer = getExactBuffer (buffer); @@ -223,16 +234,18 @@ class FileEntry extends CatalogEntry implements ProdosConstants case FILE_TYPE_USER_DEFINED_1: // if (name.endsWith (".S")) // file = new MerlinSource (name, exactBuffer, auxType, endOfFile); - if (ShapeTable.isShapeTable (exactBuffer)) - file = new ShapeTable (name, exactBuffer); - else if (SimpleText.isHTML (exactBuffer)) + if (SimpleText.isHTML (exactBuffer)) file = new SimpleText (name, exactBuffer); else if (HiResImage.isGif (exactBuffer) || HiResImage.isPng (exactBuffer)) file = new OriginalHiResImage (name, exactBuffer, auxType); else if (name.endsWith (".BMP") && HiResImage.isBmp (exactBuffer)) file = new OriginalHiResImage (name, exactBuffer, auxType); + else if (name.endsWith (".3200") || name.endsWith (".3201")) // unknown image file + file = new AssemblerProgram (name, exactBuffer, auxType); else if (name.endsWith (".FNT") && FontFile.isFont (exactBuffer)) file = new FontFile (name, exactBuffer); + else if (ShapeTable.isShapeTable (exactBuffer)) + file = new ShapeTable (name, exactBuffer); else if (link != null) { if (name.endsWith (".AUX")) @@ -243,9 +256,8 @@ class FileEntry extends CatalogEntry implements ProdosConstants else if (name.endsWith (".PAC") || name.endsWith (".A2FC") || (endOfFile == 0x4000 && auxType == 0x2000)) file = new DoubleHiResImage (name, exactBuffer); - else if ((endOfFile == 0x1FF8 || endOfFile == 0x1FFF || endOfFile == 0x2000 - || endOfFile == 0x4000) - && (auxType == 0x1FFF || auxType == 0x2000 || auxType == 0x4000)) + else if (oneOf (endOfFile, 0x1FF8, 0x1FFF, 0x2000, 0x4000) + && oneOf (auxType, 0x1FFF, 0x2000, 0x4000)) file = new OriginalHiResImage (name, exactBuffer, auxType); else if (endOfFile == 38400 && name.startsWith ("LVL.")) file = new LodeRunner (name, exactBuffer); @@ -328,7 +340,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants case FILE_TYPE_PNT: if (auxType == 2) - file = new SHRPictureFile (name, exactBuffer, fileType, auxType, endOfFile); + file = new SHRPictureFile1 (name, exactBuffer, fileType, auxType, endOfFile); else file = new SHRPictureFile2 (name, exactBuffer, fileType, auxType, endOfFile); break; @@ -337,6 +349,11 @@ class FileEntry extends CatalogEntry implements ProdosConstants file = new SHRPictureFile2 (name, exactBuffer, fileType, auxType, endOfFile); break; + case FILE_TYPE_PICT: + System.out.println ("*** PICT : " + name); + file = new DefaultAppleFile (name, exactBuffer); + break; + case FILE_TYPE_FONT: file = new QuickDrawFont (name, exactBuffer, fileType, auxType); break; @@ -352,6 +369,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants case FILE_TYPE_FINDER: case FILE_TYPE_PASCAL_VOLUME: case FILE_TYPE_GEO: + case FILE_TYPE_LDF: file = new DefaultAppleFile (name, exactBuffer); break; @@ -368,16 +386,19 @@ class FileEntry extends CatalogEntry implements ProdosConstants return file; } + private boolean oneOf (int val, int... values) + { + for (int value : values) + if (val == value) + return true; + return false; + } + private byte[] getExactBuffer (byte[] buffer) { - // if (buffer.length < endOfFile && fileType != FILE_TYPE_DIRECTORY) - // System.out.printf ("Buffer (%,d) shorter than EOF (%,d) in %s %02X%n", - // buffer.length, endOfFile, name, fileType); - byte[] exactBuffer; if (buffer.length < endOfFile) { - // exactBuffer = new byte[buffer.length]; exactBuffer = new byte[endOfFile]; System.arraycopy (buffer, 0, exactBuffer, 0, buffer.length); } @@ -502,63 +523,63 @@ class FileEntry extends CatalogEntry implements ProdosConstants } // should be removed - private byte[] getGEOSBuffer () - { - switch (storageType) - { - case SEEDLING: - System.out.println ("Seedling GEOS file : " + name); // not sure if possible - return disk.readSectors (dataBlocks); - case SAPLING: - return getIndexFile (keyPtr); - case TREE: - return getMasterIndexFile (keyPtr); - default: - System.out.println ("Unknown storage type for GEOS file : " + storageType); - return new byte[512]; - } - } + // private byte[] getGEOSBuffer () + // { + // switch (storageType) + // { + // case SEEDLING: + // System.out.println ("Seedling GEOS file : " + name); // not sure if possible + // return disk.readSectors (dataBlocks); + // case SAPLING: + // return getIndexFile (keyPtr); + // case TREE: + // return getMasterIndexFile (keyPtr); + // default: + // System.out.println ("Unknown storage type for GEOS file : " + storageType); + // return new byte[512]; + // } + // } // should be removed - private byte[] getMasterIndexFile (int keyPtr) - { - byte[] buffer = disk.readSector (keyPtr); - int length = HexFormatter.intValue (buffer[0xFF], buffer[0x1FF]); - byte[] fileBuffer = new byte[length]; - int ptr = 0; - for (int i = 0; i < 0x80; i++) - { - int block = HexFormatter.intValue (buffer[i], buffer[i + 256]); - if (block == 0) - break; - if (block == 0xFFFF) // should this insert 131,072 zeroes? - continue; - byte[] temp = getIndexFile (block); - System.arraycopy (temp, 0, fileBuffer, ptr, temp.length); - ptr += temp.length; - } - return fileBuffer; - } + // private byte[] getMasterIndexFile (int keyPtr) + // { + // byte[] buffer = disk.readSector (keyPtr); + // int length = HexFormatter.intValue (buffer[0xFF], buffer[0x1FF]); + // byte[] fileBuffer = new byte[length]; + // int ptr = 0; + // for (int i = 0; i < 0x80; i++) + // { + // int block = HexFormatter.intValue (buffer[i], buffer[i + 256]); + // if (block == 0) + // break; + // if (block == 0xFFFF) // should this insert 131,072 zeroes? + // continue; + // byte[] temp = getIndexFile (block); + // System.arraycopy (temp, 0, fileBuffer, ptr, temp.length); + // ptr += temp.length; + // } + // return fileBuffer; + // } // should be removed - private byte[] getIndexFile (int keyPtr) - { - byte[] buffer = disk.readSector (keyPtr); - int length = HexFormatter.intValue (buffer[0xFF], buffer[0x1FF]); - byte[] fileBuffer = new byte[length]; - for (int i = 0; i < 0x80; i++) - { - int block = HexFormatter.intValue (buffer[i], buffer[i + 256]); - if (block == 0) - break; - if (block == 0xFFFF) // should this insert 512 zeroes? - continue; - byte[] temp = disk.readSector (block); - System.arraycopy (temp, 0, fileBuffer, i * 512, length > 512 ? 512 : length); - length -= 512; - } - return fileBuffer; - } + // private byte[] getIndexFile (int keyPtr) + // { + // byte[] buffer = disk.readSector (keyPtr); + // int length = HexFormatter.intValue (buffer[0xFF], buffer[0x1FF]); + // byte[] fileBuffer = new byte[length]; + // for (int i = 0; i < 0x80; i++) + // { + // int block = HexFormatter.intValue (buffer[i], buffer[i + 256]); + // if (block == 0) + // break; + // if (block == 0xFFFF) // should this insert 512 zeroes? + // continue; + // byte[] temp = disk.readSector (block); + // System.arraycopy (temp, 0, fileBuffer, i * 512, length > 512 ? 512 : length); + // length -= 512; + // } + // return fileBuffer; + // } private int readIndexBlock (int indexBlock, List addresses, List buffers, int logicalBlock) @@ -609,6 +630,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants return false; } + // called from ProdosDisk.processDirectoryBlock void link (FileEntry fileEntry) { this.link = fileEntry; diff --git a/src/com/bytezone/diskbrowser/prodos/ProdosBitMapSector.java b/src/com/bytezone/diskbrowser/prodos/ProdosBitMapSector.java index 34cefa8..30ad274 100755 --- a/src/com/bytezone/diskbrowser/prodos/ProdosBitMapSector.java +++ b/src/com/bytezone/diskbrowser/prodos/ProdosBitMapSector.java @@ -8,13 +8,11 @@ import com.bytezone.diskbrowser.disk.DiskAddress; class ProdosBitMapSector extends AbstractSector { - // private final DiskAddress da; private final ProdosDisk parent; ProdosBitMapSector (ProdosDisk parent, Disk disk, byte[] buffer, DiskAddress da) { super (disk, buffer, da); - // this.da = da; this.parent = parent; } diff --git a/src/com/bytezone/diskbrowser/prodos/ProdosConstants.java b/src/com/bytezone/diskbrowser/prodos/ProdosConstants.java index 8d5ddeb..da8613b 100755 --- a/src/com/bytezone/diskbrowser/prodos/ProdosConstants.java +++ b/src/com/bytezone/diskbrowser/prodos/ProdosConstants.java @@ -17,6 +17,7 @@ public interface ProdosConstants // int FILE_TYPE_FORKED_FILE = 0xB3; // S16 int FILE_TYPE_IIGS_APPLICATION = 0xB3; int FILE_TYPE_IIGS_DEVICE_DRIVER = 0xBB; + int FILE_TYPE_LDF = 0xBC; int FILE_TYPE_GSOS_FILE_SYSTEM_TRANSLATOR = 0xBD; int FILE_TYPE_PNT = 0xC0; int FILE_TYPE_PIC = 0xC1; diff --git a/src/com/bytezone/diskbrowser/prodos/ProdosDisk.java b/src/com/bytezone/diskbrowser/prodos/ProdosDisk.java index b7617cd..d0f4df5 100755 --- a/src/com/bytezone/diskbrowser/prodos/ProdosDisk.java +++ b/src/com/bytezone/diskbrowser/prodos/ProdosDisk.java @@ -169,6 +169,11 @@ public class ProdosDisk extends AbstractFormattedDisk } } + public boolean isReservedAddress (int blockNo) + { + return false; + } + public static boolean isCorrectFormat (AppleDisk disk) { disk.setInterleave (1); diff --git a/src/com/bytezone/diskbrowser/utilities/HexFormatter.java b/src/com/bytezone/diskbrowser/utilities/HexFormatter.java index 73a1fb3..55cd864 100755 --- a/src/com/bytezone/diskbrowser/utilities/HexFormatter.java +++ b/src/com/bytezone/diskbrowser/utilities/HexFormatter.java @@ -329,23 +329,21 @@ public class HexFormatter public static int unsignedShort (byte[] buffer, int ptr) { - // int val = 0; - // for (int i = 1; i >= 0; i--) - // { - // val <<= 8; - // val += buffer[ptr + i] & 0xFF; - // } - // return val; + if (ptr >= buffer.length) + { + System.out.println ("index out of range: " + ptr); + return 0; + } return (buffer[ptr] & 0xFF) | ((buffer[ptr + 1] & 0xFF) << 8); } - // public static int signedShort (byte[] buffer, int ptr) - // { - // return (short) (((buffer[ptr] & 0xFF) << 8) | (buffer[ptr + 1] & 0xFF)); - // } - public static int signedShort (byte[] buffer, int ptr) { + if (ptr >= buffer.length) + { + System.out.println ("index out of range: " + ptr); + return 0; + } return (short) ((buffer[ptr] & 0xFF) | ((buffer[ptr + 1] & 0xFF) << 8)); }