mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-16 10:29:29 +00:00
test checksum
This commit is contained in:
parent
65791d994e
commit
b74f3f06e2
|
@ -134,7 +134,6 @@ public class Nibblizer
|
|||
if (ptr < 0)
|
||||
{
|
||||
System.out.printf ("Track: %02X - Address prologue not found%n", trackNo);
|
||||
// System.out.println (HexFormatter.format (buffer));
|
||||
return false;
|
||||
}
|
||||
AddressField addressField = getAddressField (buffer, ptr);
|
||||
|
@ -174,10 +173,10 @@ public class Nibblizer
|
|||
return false;
|
||||
}
|
||||
|
||||
int offset = addressField.track * TRACK_SIZE
|
||||
int o = addressField.track * TRACK_SIZE
|
||||
+ interleave[DOS][addressField.sector] * BLOCK_SIZE;
|
||||
|
||||
System.arraycopy (dataField.dataBuffer, 0, diskBuffer, offset, BLOCK_SIZE);
|
||||
System.arraycopy (dataField.dataBuffer, 0, diskBuffer, o, BLOCK_SIZE);
|
||||
|
||||
if (++totalSectors == 16)
|
||||
break;
|
||||
|
|
|
@ -5,6 +5,8 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.bytezone.diskbrowser.utilities.Utility;
|
||||
|
||||
public class WozDisk
|
||||
{
|
||||
private static final int TRK_SIZE = 0x1A00;
|
||||
|
@ -27,97 +29,95 @@ public class WozDisk
|
|||
{
|
||||
this.file = f;
|
||||
Nibblizer nibbler = new Nibblizer (f);
|
||||
|
||||
byte[] id = new byte[8];
|
||||
byte[] checksum = new byte[4];
|
||||
byte[] trackBuffer = new byte[TRK_SIZE];
|
||||
byte[] infoBuffer = new byte[INFO_SIZE];
|
||||
byte[] tmapBuffer = new byte[TMAP_SIZE];
|
||||
byte[] buffer = null;
|
||||
|
||||
try
|
||||
{
|
||||
BufferedInputStream in = new BufferedInputStream (new FileInputStream (file));
|
||||
in.read (id);
|
||||
assert matches (id, header);
|
||||
in.read (checksum);
|
||||
|
||||
read: while (in.available () > 8)
|
||||
{
|
||||
String chunkId = readString (in, 4);
|
||||
int chunkSize = readInt (in, 4);
|
||||
|
||||
if ("INFO".equals (chunkId))
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
in.read (infoBuffer);
|
||||
System.out.printf ("Version ........... %02X%n", infoBuffer[0]);
|
||||
System.out.printf ("Disk type ......... %02X%n", infoBuffer[1]);
|
||||
System.out.printf ("Write protected ... %02X%n", infoBuffer[2]);
|
||||
System.out.printf ("Synchronised ...... %02X%n", infoBuffer[3]);
|
||||
System.out.printf ("Cleaned ........... %02X%n", infoBuffer[4]);
|
||||
System.out.printf ("Creator ........... %s%n%n",
|
||||
new String (infoBuffer, 5, 32));
|
||||
}
|
||||
else
|
||||
in.skip (infoBuffer.length);
|
||||
}
|
||||
else if ("TMAP".equals (chunkId))
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
in.read (tmapBuffer);
|
||||
int ptr = 0;
|
||||
for (int track = 0; track < 40; track++)
|
||||
{
|
||||
for (int qtr = 0; qtr < 4; qtr++)
|
||||
System.out.printf ("%02X ", tmapBuffer[ptr++]);
|
||||
System.out.println ();
|
||||
}
|
||||
System.out.println ();
|
||||
}
|
||||
else
|
||||
in.skip (tmapBuffer.length);
|
||||
}
|
||||
else if ("TRKS".equals (chunkId))
|
||||
{
|
||||
int tracks = chunkSize / TRK_SIZE;
|
||||
for (int track = 0; track < tracks; track++)
|
||||
{
|
||||
int bytesRead = in.read (trackBuffer);
|
||||
assert bytesRead == TRK_SIZE;
|
||||
int bytesUsed = readInt (trackBuffer, DATA_SIZE, 2);
|
||||
int bitCount = readInt (trackBuffer, DATA_SIZE + 2, 2);
|
||||
|
||||
byte[] trackData = new byte[bytesUsed];
|
||||
readTrack (trackBuffer, trackData, bytesUsed);
|
||||
if (!nibbler.processTrack (track, trackData, diskBuffer))
|
||||
{
|
||||
System.out.println ("Nibblizer failure");
|
||||
// System.out.println (HexFormatter.format (trackBuffer, 0, trackBuffer.length,
|
||||
// TRK_SIZE * track + 256));
|
||||
// System.out.println ();
|
||||
break read;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ("META".equals (chunkId))
|
||||
{
|
||||
System.out.printf ("[%s] %08X%n", chunkId, chunkSize);
|
||||
skip (in, chunkSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.printf ("Unknown %08X%n", chunkSize);
|
||||
skip (in, chunkSize);
|
||||
}
|
||||
}
|
||||
buffer = in.readAllBytes ();
|
||||
in.close ();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace ();
|
||||
System.exit (1);
|
||||
return;
|
||||
}
|
||||
|
||||
assert matches (header, buffer);
|
||||
|
||||
int cs1 = readInt (buffer, 8, 4);
|
||||
int cs2 = Utility.crc32 (buffer, 12, 256 - 12 + 35 * 6656);
|
||||
if (cs1 != cs2)
|
||||
{
|
||||
System.out.printf ("Checksum: %08X%n", cs1);
|
||||
System.out.printf ("Calculat: %08X%n", cs2);
|
||||
}
|
||||
|
||||
int ptr = 12;
|
||||
read: while (ptr < buffer.length)
|
||||
{
|
||||
String chunkId = readString (buffer, ptr, 4);
|
||||
ptr += 4;
|
||||
int chunkSize = readInt (buffer, ptr, 4);
|
||||
ptr += 4;
|
||||
|
||||
if ("INFO".equals (chunkId))
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
System.out.printf ("Version ........... %02X%n", buffer[ptr]);
|
||||
System.out.printf ("Disk type ......... %02X%n", buffer[ptr + 1]);
|
||||
System.out.printf ("Write protected ... %02X%n", buffer[ptr + 2]);
|
||||
System.out.printf ("Synchronised ...... %02X%n", buffer[ptr + 3]);
|
||||
System.out.printf ("Cleaned ........... %02X%n", buffer[ptr + 4]);
|
||||
System.out.printf ("Creator ........... %s%n%n",
|
||||
new String (buffer, ptr + 5, 32));
|
||||
}
|
||||
ptr += INFO_SIZE;
|
||||
}
|
||||
else if ("TMAP".equals (chunkId))
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
for (int track = 0; track < 40; track++)
|
||||
{
|
||||
for (int qtr = 0; qtr < 4; qtr++)
|
||||
System.out.printf ("%02X ", buffer[ptr++]);
|
||||
System.out.println ();
|
||||
}
|
||||
System.out.println ();
|
||||
}
|
||||
else
|
||||
ptr += TMAP_SIZE;
|
||||
}
|
||||
else if ("TRKS".equals (chunkId))
|
||||
{
|
||||
int tracks = chunkSize / TRK_SIZE;
|
||||
for (int track = 0; track < tracks; track++)
|
||||
{
|
||||
int bytesUsed = readInt (buffer, ptr + DATA_SIZE, 2);
|
||||
int bitCount = readInt (buffer, ptr + DATA_SIZE + 2, 2);
|
||||
|
||||
byte[] trackData = new byte[bytesUsed];
|
||||
readTrack (buffer, ptr, trackData, bytesUsed);
|
||||
if (!nibbler.processTrack (track, trackData, diskBuffer))
|
||||
{
|
||||
System.out.println ("Nibblizer failure");
|
||||
break read;
|
||||
}
|
||||
ptr += TRK_SIZE;
|
||||
}
|
||||
}
|
||||
else if ("META".equals (chunkId))
|
||||
{
|
||||
System.out.printf ("[%s] %08X%n", chunkId, chunkSize);
|
||||
ptr += chunkSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.printf ("Unknown %08X%n", chunkSize);
|
||||
ptr += chunkSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,11 +135,11 @@ public class WozDisk
|
|||
// readString
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
||||
private String readString (BufferedInputStream file, int size) throws IOException
|
||||
private String readString (byte[] buffer, int offset, int length)
|
||||
{
|
||||
byte[] bytes = new byte[size];
|
||||
file.read (bytes);
|
||||
return new String (bytes);
|
||||
// byte[] bytes = new byte[size];
|
||||
// file.read (bytes);
|
||||
return new String (buffer, offset, length);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
@ -162,12 +162,12 @@ public class WozDisk
|
|||
// readInt
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
||||
private int readInt (BufferedInputStream file, int size) throws IOException
|
||||
{
|
||||
byte[] buffer = new byte[size];
|
||||
file.read (buffer);
|
||||
return readInt (buffer, 0, size);
|
||||
}
|
||||
// private int readInt (BufferedInputStream file, int size) throws IOException
|
||||
// {
|
||||
// byte[] buffer = new byte[size];
|
||||
// file.read (buffer);
|
||||
// return readInt (buffer, 0, size);
|
||||
// }
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
// matches
|
||||
|
@ -185,13 +185,13 @@ public class WozDisk
|
|||
// readTrack
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
||||
private void readTrack (byte[] buffer, byte[] trackData, int bytesUsed)
|
||||
private void readTrack (byte[] buffer, int offset, byte[] trackData, int bytesUsed)
|
||||
{
|
||||
// int consecutiveZeros = 0;
|
||||
int value = 0;
|
||||
int ptr = 0;
|
||||
|
||||
for (int i = 0; i < bytesUsed; i++)
|
||||
for (int i = offset; i < offset + bytesUsed; i++)
|
||||
{
|
||||
int b = buffer[i] & 0xFF;
|
||||
for (int mask = 0x80; mask > 0; mask >>>= 1)
|
||||
|
|
|
@ -94,15 +94,16 @@ public class Utility
|
|||
return suffixes.contains (getSuffix (filename));
|
||||
}
|
||||
|
||||
public int crc32 (byte[] buffer, int size)
|
||||
public static int crc32 (byte[] buffer, int offset, int length)
|
||||
{
|
||||
int crc = ~0; // one's complement
|
||||
int crc = 0xFFFFFFFF; // one's complement
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
crc = crc32_tab[(crc ^ buffer[i]) & 0xFF] ^ (crc >>> 8);
|
||||
|
||||
return ~crc; // one's complement
|
||||
return ~crc; // one's complement
|
||||
}
|
||||
|
||||
static int[] crc32_tab =
|
||||
{ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
|
|
Loading…
Reference in New Issue
Block a user