diff --git a/src/com/bytezone/diskbrowser/applefile/ExoBuffer.java b/src/com/bytezone/diskbrowser/applefile/ExoBuffer.java index 95e34aa..214876b 100644 --- a/src/com/bytezone/diskbrowser/applefile/ExoBuffer.java +++ b/src/com/bytezone/diskbrowser/applefile/ExoBuffer.java @@ -74,7 +74,7 @@ public class ExoBuffer if (address != 0x6000 && address != 0x8000 && address != 0xA000) return false; - return true; // maybe + return false; // not dealing with fuckwits } // ---------------------------------------------------------------------------------// diff --git a/src/com/bytezone/diskbrowser/dos/DosDisk.java b/src/com/bytezone/diskbrowser/dos/DosDisk.java index 9661eb9..1765622 100755 --- a/src/com/bytezone/diskbrowser/dos/DosDisk.java +++ b/src/com/bytezone/diskbrowser/dos/DosDisk.java @@ -136,7 +136,7 @@ public class DosDisk extends AbstractFormattedDisk // same loop, but now all the catalog sectors are properly flagged da = disk.getDiskAddress (catalogStart.getBlockNo ()); - do + loop: do { if (!disk.isValidAddress (da)) break; @@ -147,7 +147,7 @@ public class DosDisk extends AbstractFormattedDisk for (int ptr = 11; ptr < 256; ptr += ENTRY_SIZE) { if (sectorBuffer[ptr] == 0) // empty slot, no more catalog entries - continue; + break loop; byte[] entryBuffer = new byte[ENTRY_SIZE]; System.arraycopy (sectorBuffer, ptr, entryBuffer, 0, ENTRY_SIZE); diff --git a/src/com/bytezone/diskbrowser/dosmaster/DosMasterDisk.java b/src/com/bytezone/diskbrowser/dosmaster/DosMasterDisk.java index 4228c45..f9c1439 100644 --- a/src/com/bytezone/diskbrowser/dosmaster/DosMasterDisk.java +++ b/src/com/bytezone/diskbrowser/dosmaster/DosMasterDisk.java @@ -1,23 +1,119 @@ package com.bytezone.diskbrowser.dosmaster; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import com.bytezone.diskbrowser.disk.Disk; +import com.bytezone.diskbrowser.disk.DiskAddress; +import com.bytezone.diskbrowser.prodos.ProdosDisk; +import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.Utility; // -----------------------------------------------------------------------------------// public class DosMasterDisk // -----------------------------------------------------------------------------------// { + private static final String base = "/Users/denismolony/Dropbox/Examples/Testing/"; + // ---------------------------------------------------------------------------------// - public static boolean isDos33 (byte[] buffer) + public static boolean isDos33 (ProdosDisk parentDisk, byte[] buffer) // ---------------------------------------------------------------------------------// { + // System.out.println (HexFormatter.format (buffer, 0x38, 0x30)); + System.out.println (); + System.out.println ("# S D B Lo B Hi Size Vols Secs"); + + Disk disk = parentDisk.getDisk (); + + for (int i = 0; i < 8; i++) + { + int slotDrive = buffer[0x38 + i] & 0xFF; + if (slotDrive == 0) + continue; + + int slot = (slotDrive & 0x70) >>> 4; + int drive = ((slotDrive & 0x80) >>> 7) + 1; + int firstBlock = Utility.unsignedShort (buffer, 0x40 + i * 2); // of first volume + + int skip = i / 2 * 2; // 0, 0, 2, 2, 4, 4, 6, 6 - same for both drives + + int lastBlock = Utility.unsignedShort (buffer, 0x50 + skip); // of last volume + int volSize = Utility.unsignedShort (buffer, 0x58 + skip); + + if (firstBlock > lastBlock) // WTF? + firstBlock -= 16 * 4096; + + int vols = (lastBlock - firstBlock) / volSize - 1; + int sectors = volSize * 2; + + System.out.printf ("%d %02X %d %d %04X %04X %04X %3d %3d%n", i, + buffer[0x38 + i], slot, drive, firstBlock, lastBlock, volSize, vols, sectors); + + if (vols > 0 && true) + { + int volNo = 10; + + int firstDiskBlock = firstBlock + volNo * volSize; + int lastDiskBlock = firstDiskBlock + volSize; + + List daList = new ArrayList<> (); + for (int block = firstDiskBlock; block < lastDiskBlock; block++) + daList.add (disk.getDiskAddress (block)); + + byte[] diskBuffer = disk.readBlocks (daList); + System.out.println (HexFormatter.format (diskBuffer)); + System.out.printf ("Buffer: %,d%n", diskBuffer.length); + System.out.printf ("Blocks: %,d x 2 = %,d%n", daList.size (), daList.size () * 2); + + if (false) + createDisk (String.format ("%sVol%03d.dsk", base, i), diskBuffer); + } + } + + return false; + } + + // ---------------------------------------------------------------------------------// + private static void createDisk (String name, byte[] buffer) + // ---------------------------------------------------------------------------------// + { + File file = new File (name); + if (file.exists ()) + { + System.out.printf ("File: %s already exists%n", name); + return; + } + + try + { + Path path = Paths.get (name); + Files.write (path, buffer); + } + catch (IOException e) + { + e.printStackTrace (); + } + } + + // ---------------------------------------------------------------------------------// + private void oldCode (ProdosDisk parentDisk, byte[] buffer) + // ---------------------------------------------------------------------------------// + { + int slots = 3 * 16 + 8; int v0 = slots + 8; int size = v0 + 16; int vsiz = size + 8; // int adrs = vsiz + 8; + System.out.println (); System.out.println ( - "Slots v0 size vsiz d d0 slot ptr st sz v num"); + "Slots v0 size vsiz d d0 s/d ptr strt sz end vols"); StringBuilder text = new StringBuilder (); @@ -42,9 +138,9 @@ public class DosMasterDisk text.append (String.format ("Slot %d, Drive %d has", s / 16, dr + 1)); int ptr = v0 + 2 * d0 + 2 * dr; - int st = Utility.unsignedShort (buffer, ptr); - int sz = Utility.unsignedShort (buffer, vsiz + d0); - int v = Utility.unsignedShort (buffer, size + d0); + int st = Utility.unsignedShort (buffer, ptr); // start block of first volume + int sz = Utility.unsignedShort (buffer, vsiz + d0); // blocks per volume + int v = Utility.unsignedShort (buffer, size + d0); // end block of last volume if (st > v) st -= 16 * 4096; @@ -55,11 +151,30 @@ public class DosMasterDisk System.out.printf (" %02X %04X %04X %04X %04X%n", ptr, st, sz, v, num); - } + Disk disk = parentDisk.getDisk (); + + if (num > 0 && false) + { + // for (int i = 1; i <= num; i++) + int i = 15; + { + int firstBlock = st + i * sz; + int lastBlock = firstBlock + sz; + int length = lastBlock - firstBlock; + System.out.printf ("%3d %04X %04X %04X%n", i, firstBlock, lastBlock, length); + + List daList = new ArrayList<> (); + for (int block = firstBlock; block < lastBlock; block++) + daList.add (disk.getDiskAddress (block)); + byte[] diskBuffer = disk.readBlocks (daList); + + if (false) + createDisk (String.format ("%sVol%03d.dsk", base, i), diskBuffer); + } + } + } System.out.println (); System.out.println (text.toString ()); - - return false; } } diff --git a/src/com/bytezone/diskbrowser/prodos/FileEntry.java b/src/com/bytezone/diskbrowser/prodos/FileEntry.java index 38f74eb..d8f01b0 100755 --- a/src/com/bytezone/diskbrowser/prodos/FileEntry.java +++ b/src/com/bytezone/diskbrowser/prodos/FileEntry.java @@ -358,7 +358,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants // else if (name.endsWith (".PIC")) // 0091 X-BASIC../../XBASIC.PIC // file = new SHRPictureFile2 (name, exactBuffer, fileType, auxType, endOfFile); else if (name.equals ("DOS.3.3") && endOfFile == 0x2800 - && DosMasterDisk.isDos33 (exactBuffer)) + && DosMasterDisk.isDos33 (parentDisk, exactBuffer)) { }