mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-11-29 11:49:29 +00:00
Update DiskReaderGRC.java
tidying
This commit is contained in:
parent
19386e5c8e
commit
43cabfa7bb
@ -20,42 +20,48 @@ public class DiskReaderGRC extends DiskReader
|
|||||||
{
|
{
|
||||||
byte[] outBuffer = new byte[BLOCK_SIZE * 2 + 12]; // 524 bytes
|
byte[] outBuffer = new byte[BLOCK_SIZE * 2 + 12]; // 524 bytes
|
||||||
int outPtr = 0;
|
int outPtr = 0;
|
||||||
|
|
||||||
int[] checksums = new int[3];
|
int[] checksums = new int[3];
|
||||||
|
|
||||||
|
// decode four disk bytes into three data bytes (175 * 3 - 1 = 524)
|
||||||
for (int j = 0; j < 175; j++)
|
for (int j = 0; j < 175; j++)
|
||||||
{
|
{
|
||||||
checksums[0] = (checksums[0] & 0xFF) << 1; // ROL
|
checksums[0] = (checksums[0] & 0xFF) << 1; // ROL
|
||||||
if ((checksums[0] > 0xFF))
|
if ((checksums[0] > 0xFF))
|
||||||
++checksums[0];
|
++checksums[0];
|
||||||
|
|
||||||
|
// 6&2 translation
|
||||||
byte d3 = byteTranslator.decode (buffer[ptr++]); // composite byte
|
byte d3 = byteTranslator.decode (buffer[ptr++]); // composite byte
|
||||||
byte d0 = byteTranslator.decode (buffer[ptr++]);
|
byte d0 = byteTranslator.decode (buffer[ptr++]);
|
||||||
byte d1 = byteTranslator.decode (buffer[ptr++]);
|
byte d1 = byteTranslator.decode (buffer[ptr++]);
|
||||||
|
|
||||||
|
// reassemble bytes
|
||||||
byte b0 = (byte) ((d0 & 0x3F) | ((d3 & 0x30) << 2));
|
byte b0 = (byte) ((d0 & 0x3F) | ((d3 & 0x30) << 2));
|
||||||
byte b1 = (byte) ((d1 & 0x3F) | ((d3 & 0x0C) << 4));
|
byte b1 = (byte) ((d1 & 0x3F) | ((d3 & 0x0C) << 4));
|
||||||
|
|
||||||
|
// calculate running checksums
|
||||||
outBuffer[outPtr++] = checksum (b0, checksums, 0, 2);
|
outBuffer[outPtr++] = checksum (b0, checksums, 0, 2);
|
||||||
outBuffer[outPtr++] = checksum (b1, checksums, 2, 1);
|
outBuffer[outPtr++] = checksum (b1, checksums, 2, 1);
|
||||||
|
|
||||||
if (j < 174)
|
if (j < 174) // get fourth disk byte if we are not at the very end
|
||||||
{
|
{
|
||||||
byte d2 = byteTranslator.decode (buffer[ptr++]);
|
byte d2 = byteTranslator.decode (buffer[ptr++]); // translate
|
||||||
byte b2 = (byte) ((d2 & 0x3F) | ((d3 & 0x03) << 6));
|
byte b2 = (byte) ((d2 & 0x3F) | ((d3 & 0x03) << 6)); // reassemble
|
||||||
outBuffer[outPtr++] = checksum (b2, checksums, 1, 0);
|
outBuffer[outPtr++] = checksum (b2, checksums, 1, 0); // checksum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decode four disk bytes into three data bytes
|
||||||
byte d3 = byteTranslator.decode (buffer[ptr++]); // composite byte
|
byte d3 = byteTranslator.decode (buffer[ptr++]); // composite byte
|
||||||
byte d0 = byteTranslator.decode (buffer[ptr++]);
|
byte d0 = byteTranslator.decode (buffer[ptr++]);
|
||||||
byte d1 = byteTranslator.decode (buffer[ptr++]);
|
byte d1 = byteTranslator.decode (buffer[ptr++]);
|
||||||
byte d2 = byteTranslator.decode (buffer[ptr++]);
|
byte d2 = byteTranslator.decode (buffer[ptr++]);
|
||||||
|
|
||||||
|
// reassemble bytes
|
||||||
byte b0 = (byte) ((d0 & 0x3F) | ((d3 & 0x30) << 2));
|
byte b0 = (byte) ((d0 & 0x3F) | ((d3 & 0x30) << 2));
|
||||||
byte b1 = (byte) ((d1 & 0x3F) | ((d3 & 0x0C) << 4));
|
byte b1 = (byte) ((d1 & 0x3F) | ((d3 & 0x0C) << 4));
|
||||||
byte b2 = (byte) ((d2 & 0x3F) | ((d3 & 0x03) << 6));
|
byte b2 = (byte) ((d2 & 0x3F) | ((d3 & 0x03) << 6));
|
||||||
|
|
||||||
|
// compare disk checksums with calculated checksums
|
||||||
if ((checksums[0] & 0xFF) != (b2 & 0xFF) //
|
if ((checksums[0] & 0xFF) != (b2 & 0xFF) //
|
||||||
|| (checksums[1] & 0xFF) != (b1 & 0xFF) //
|
|| (checksums[1] & 0xFF) != (b1 & 0xFF) //
|
||||||
|| (checksums[2] & 0xFF) != (b0 & 0xFF))
|
|| (checksums[2] & 0xFF) != (b0 & 0xFF))
|
||||||
|
Loading…
Reference in New Issue
Block a user