mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2025-01-03 10:29:19 +00:00
Added write block and lessened the DOS 3.3 recognition. For some
reason, some DOS 3.3 images do not set the VTOC byte 0x03 to be 3 - this is the DOS release number which created the disk. The images I have just have a zero (0) in this position.
This commit is contained in:
parent
24ebe07191
commit
b1a4c9d31d
@ -249,32 +249,79 @@ public class Disk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the block from the disk image.
|
* Read the block from the disk image.
|
||||||
*/
|
*/
|
||||||
public byte[] readBlock(int block) {
|
public byte[] readBlock(int block) {
|
||||||
|
byte[] data = new byte[BLOCK_SIZE];
|
||||||
|
System.arraycopy(readBytes(getOffset1(block), SECTOR_SIZE),
|
||||||
|
0, data, 0, SECTOR_SIZE);
|
||||||
|
System.arraycopy(readBytes(getOffset2(block), SECTOR_SIZE),
|
||||||
|
0, data, SECTOR_SIZE, SECTOR_SIZE);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the block to the disk image.
|
||||||
|
*/
|
||||||
|
public void writeBlock(int block, byte[] data) {
|
||||||
|
byte[] sector = new byte[SECTOR_SIZE];
|
||||||
|
System.arraycopy(data, 0, sector, 0, SECTOR_SIZE);
|
||||||
|
writeBytes(getOffset1(block), sector);
|
||||||
|
System.arraycopy(data, SECTOR_SIZE, sector, 0, SECTOR_SIZE);
|
||||||
|
writeBytes(getOffset2(block), sector);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the block offset into the disk image.
|
||||||
|
* Note that for ProDOS blocks the offset is broken into two
|
||||||
|
* pieces - depending of the format the image is in, they may
|
||||||
|
* or may not be adjacent within the disk image itself.
|
||||||
|
* This takes into account what type of format is being dealt
|
||||||
|
* with.
|
||||||
|
*/
|
||||||
|
protected int getOffset1(int block) throws IllegalArgumentException {
|
||||||
if (block * BLOCK_SIZE > getPhysicalSize()) {
|
if (block * BLOCK_SIZE > getPhysicalSize()) {
|
||||||
return null;
|
throw new IllegalArgumentException("The block (" + block
|
||||||
|
+ ") does match the disk image size.");
|
||||||
|
} else if (isProdosOrder()) {
|
||||||
|
return block*BLOCK_SIZE;
|
||||||
|
} else if (isDosOrder()) {
|
||||||
|
int[] sectorMapping1 = { 0, 13, 11, 9, 7, 5, 3, 1 };
|
||||||
|
int track = block / 8;
|
||||||
|
int sectorOffset = block % 8;
|
||||||
|
int sector1 = sectorMapping1[sectorOffset];
|
||||||
|
int physicalLocation1 = (track * 16 + sector1) * SECTOR_SIZE;
|
||||||
|
return physicalLocation1;
|
||||||
} else {
|
} else {
|
||||||
if (isProdosOrder()) {
|
throw new IllegalArgumentException(
|
||||||
return readBytes(block*BLOCK_SIZE, BLOCK_SIZE);
|
"Unknown disk format.");
|
||||||
} else if (isDosOrder()) {
|
}
|
||||||
int[] sectorMapping1 = { 0, 13, 11, 9, 7, 5, 3, 1 };
|
}
|
||||||
int[] sectorMapping2 = { 14, 12, 10, 8, 6, 4, 2, 15 };
|
|
||||||
int track = block / 8;
|
/**
|
||||||
int sectorOffset = block % 8;
|
* Compute the block offset into the disk image.
|
||||||
int sector1 = sectorMapping1[sectorOffset];
|
* Note that for ProDOS blocks the offset is broken into two
|
||||||
int sector2 = sectorMapping2[sectorOffset];
|
* pieces - depending of the format the image is in, they may
|
||||||
int physicalLocation1 = (track * 16 + sector1) * SECTOR_SIZE;
|
* or may not be adjacent within the disk image itself.
|
||||||
int physicalLocation2 = (track * 16 + sector2) * SECTOR_SIZE;
|
* This takes into account what type of format is being dealt
|
||||||
byte[] data = new byte[BLOCK_SIZE];
|
* with.
|
||||||
System.arraycopy(readBytes(physicalLocation1, SECTOR_SIZE),
|
*/
|
||||||
0, data, 0, SECTOR_SIZE);
|
protected int getOffset2(int block) throws IllegalArgumentException {
|
||||||
System.arraycopy(readBytes(physicalLocation2, SECTOR_SIZE),
|
if (block * BLOCK_SIZE > getPhysicalSize()) {
|
||||||
0, data, SECTOR_SIZE, SECTOR_SIZE);
|
throw new IllegalArgumentException("The block (" + block
|
||||||
return data;
|
+ ") does match the disk image size.");
|
||||||
} else {
|
} else if (isProdosOrder()) {
|
||||||
return null;
|
return block*BLOCK_SIZE + SECTOR_SIZE;
|
||||||
}
|
} else if (isDosOrder()) {
|
||||||
|
int[] sectorMapping2 = { 14, 12, 10, 8, 6, 4, 2, 15 };
|
||||||
|
int track = block / 8;
|
||||||
|
int sectorOffset = block % 8;
|
||||||
|
int sector2 = sectorMapping2[sectorOffset];
|
||||||
|
int physicalLocation2 = (track * 16 + sector2) * SECTOR_SIZE;
|
||||||
|
return physicalLocation2;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Unknown disk format.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +384,6 @@ public class Disk {
|
|||||||
byte[] vtoc = readSector(17, 0);
|
byte[] vtoc = readSector(17, 0);
|
||||||
return vtoc[0x01] == 17 // expect catalog to start on track 17
|
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
|
||||||
&& vtoc[0x03] == 3 // expect DOS release number of 3
|
|
||||||
&& vtoc[0x27] == 122 // expect 122 tract/sector pairs per sector
|
&& vtoc[0x27] == 122 // expect 122 tract/sector pairs per sector
|
||||||
&& vtoc[0x34] == 35 // expect 35 tracks 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[0x35] == 16 // expect 16 sectors per disk (140KB disk only!)
|
||||||
|
Loading…
Reference in New Issue
Block a user