From 558ae20c8002ae3ee3e33cc4b4ca6e6cf747c819 Mon Sep 17 00:00:00 2001 From: Robert Greene Date: Thu, 12 Dec 2002 04:36:16 +0000 Subject: [PATCH] Added recognition for UniDOS 800K volumes (basically fixed 35 track and 16 sector bias in code). --- .../applecommander/storage/Disk.java | 28 +++++++++++++++---- .../applecommander/storage/DosFormatDisk.java | 5 ++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/com/webcodepro/applecommander/storage/Disk.java b/src/com/webcodepro/applecommander/storage/Disk.java index 0efff0e..061fd8a 100644 --- a/src/com/webcodepro/applecommander/storage/Disk.java +++ b/src/com/webcodepro/applecommander/storage/Disk.java @@ -350,7 +350,13 @@ public class Disk { * with. */ protected int getOffset(int track, int sector) throws IllegalArgumentException { - if ((track * 16 + sector) * SECTOR_SIZE > getPhysicalSize()) { + int length = diskImage.length; + if (length != APPLE_140KB_DISK && length != APPLE_800KB_DISK) { + throw new IllegalArgumentException("Unrecognized DOS format!"); + } + int sectorsPerTrack = 16; + if (length == APPLE_800KB_DISK) sectorsPerTrack = 32; + if ((track * sectorsPerTrack + sector) * SECTOR_SIZE > getPhysicalSize()) { throw new IllegalArgumentException( "The track (" + track + ") and sector (" + sector + ") do not match the disk image size."); @@ -362,7 +368,7 @@ public class Disk { return ((track * 8) + blockInterleave[sector]) * BLOCK_SIZE + blockOffsets[sector] * SECTOR_SIZE; } else if (isDosOrder()) { - return (track * 16 + sector) * SECTOR_SIZE; + return (track * sectorsPerTrack + sector) * SECTOR_SIZE; } else { throw new IllegalArgumentException( "Unknown disk format."); @@ -382,15 +388,25 @@ public class Disk { /** * Test the disk format to see if this is a DOS 3.3 formatted - * disk. + * disk. This is a little nasty - since 800KB and 140KB images have + * different characteristics. */ public boolean isDosFormat() { byte[] vtoc = readSector(17, 0); return vtoc[0x01] == 17 // expect catalog to start on track 17 - && vtoc[0x02] == 15 // expect catalog to start on sector 15 + && ( + vtoc[0x02] == 15 // expect catalog to start on sector 15 (140KB disk only!) + || + vtoc[0x02] == 31 // expect catalog to start on sector 31 (800KB disk only!) + ) && vtoc[0x27] == 122 // expect 122 tract/sector pairs per sector - && vtoc[0x34] == 35 // expect 35 tracks per disk (140KB disk only!) - && vtoc[0x35] == 16 // expect 16 sectors per disk (140KB disk only!) + && (( + vtoc[0x34] == 35 // expect 35 tracks per disk (140KB disk only!) + && vtoc[0x35] == 16 // expect 16 sectors per disk (140KB disk only!) + ) || ( + vtoc[0x34] == 50 // expect 50 tracks per disk (800KB disk only!) + && vtoc[0x35] == 32 // expect 32 sectors per disk (800KB disk only!) + )) && vtoc[0x36] == 0 // bytes per sector (low byte) && vtoc[0x37] == 1; // bytes per sector (high byte) } diff --git a/src/com/webcodepro/applecommander/storage/DosFormatDisk.java b/src/com/webcodepro/applecommander/storage/DosFormatDisk.java index 8d2a742..12d6656 100644 --- a/src/com/webcodepro/applecommander/storage/DosFormatDisk.java +++ b/src/com/webcodepro/applecommander/storage/DosFormatDisk.java @@ -464,10 +464,11 @@ public class DosFormatDisk extends FormattedDisk { } /** - * Validate track/sector range. + * Validate track/sector range. This just validates the + * maximum values allowable for track and sector. */ protected void checkRange(int track, int sector) { - if (track > 35 || sector > 32) { + if (track > 50 || sector > 32) { throw new IllegalArgumentException( "Invalid track (" + track + "), sector (" + sector + ") combination.");