This commit is contained in:
Denis Molony 2019-07-30 21:38:03 +10:00
parent 1e6648dc73
commit e1d1e0408a
2 changed files with 45 additions and 33 deletions

View File

@ -1,22 +1,47 @@
package com.bytezone.diskbrowser.nib; package com.bytezone.diskbrowser.nib;
// ---------------------------------------------------------------------------------//
public abstract class DiskReader public abstract class DiskReader
// ---------------------------------------------------------------------------------//
{ {
static final int BLOCK_SIZE = 256; static final int BLOCK_SIZE = 256;
static final byte[] dataPrologue = { (byte) 0xD5, (byte) 0xAA, (byte) 0xAD }; static final byte[] dataPrologue = { (byte) 0xD5, (byte) 0xAA, (byte) 0xAD };
static DiskReader reader13;
static DiskReader reader16;
final int sectorsPerTrack; final int sectorsPerTrack;
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
// constructor
// ---------------------------------------------------------------------------------//
DiskReader (int sectorsPerTrack) DiskReader (int sectorsPerTrack)
// ---------------------------------------------------------------------------------//
{ {
this.sectorsPerTrack = sectorsPerTrack; this.sectorsPerTrack = sectorsPerTrack;
} }
// ---------------------------------------------------------------------------------//
static DiskReader getDiskReader (int sectors)
// ---------------------------------------------------------------------------------//
{
if (sectors == 13)
{
if (reader13 == null)
reader13 = new DiskReader13Sector ();
return reader13;
}
if (sectors == 16)
{
if (reader16 == null)
reader16 = new DiskReader16Sector ();
return reader16;
}
return null;
}
// ---------------------------------------------------------------------------------//
byte[] decodeSector (byte[] buffer) throws DiskNibbleException byte[] decodeSector (byte[] buffer) throws DiskNibbleException
// ---------------------------------------------------------------------------------//
{ {
return decodeSector (buffer, 0); return decodeSector (buffer, 0);
} }

View File

@ -27,12 +27,9 @@ public class WozFile
private static final int TRK_SIZE = 0x1A00; private static final int TRK_SIZE = 0x1A00;
private static final int DATA_SIZE = TRK_SIZE - 10; private static final int DATA_SIZE = TRK_SIZE - 10;
private final DiskReader13Sector diskReader13Sector = new DiskReader13Sector ();
private final DiskReader16Sector diskReader16Sector = new DiskReader16Sector ();
private static int[][] interleave = private static int[][] interleave =
{ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // 13 sector
{ 0, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 15 } }; { 0, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 15 } }; // 16 sector
public final File file; public final File file;
@ -95,7 +92,7 @@ public class WozFile
ptr += size + 8; ptr += size + 8;
} }
DiskReader diskReader = diskSectors == 13 ? diskReader13Sector : diskReader16Sector; DiskReader diskReader = DiskReader.getDiskReader (diskSectors);
diskBuffer = new byte[35 * diskSectors * 256]; diskBuffer = new byte[35 * diskSectors * 256];
int ndx = diskSectors == 13 ? 0 : 1; int ndx = diskSectors == 13 ? 0 : 1;
@ -144,7 +141,7 @@ public class WozFile
System.out.printf ("Creator ............. %s%n", creator); System.out.printf ("Creator ............. %s%n", creator);
} }
if (wozVersion == 2) if (wozVersion >= 2)
{ {
int sides = val8 (buffer, ptr + 45); int sides = val8 (buffer, ptr + 45);
int bootSectorFormat = val8 (buffer, ptr + 46); int bootSectorFormat = val8 (buffer, ptr + 46);
@ -217,6 +214,7 @@ public class WozFile
int reclen = wozVersion == 1 ? TRK_SIZE : 8; int reclen = wozVersion == 1 ? TRK_SIZE : 8;
int max = wozVersion == 1 ? 35 : 160; int max = wozVersion == 1 ? 35 : 160;
for (int i = 0; i < max; i++) for (int i = 0; i < max; i++)
{ {
try try
@ -248,15 +246,18 @@ public class WozFile
private int val16 (byte[] buffer, int ptr) private int val16 (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
return (buffer[ptr++] & 0xFF) + ((buffer[ptr] & 0xFF) << 8); return (buffer[ptr] & 0xFF) //
| ((buffer[ptr + 1] & 0xFF) << 8);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private int val32 (byte[] buffer, int ptr) private int val32 (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
return (buffer[ptr++] & 0xFF) + ((buffer[ptr++] & 0xFF) << 8) return (buffer[ptr] & 0xFF) //
+ ((buffer[ptr++] & 0xFF) << 16) + ((buffer[ptr] & 0xFF) << 24); | ((buffer[ptr + 1] & 0xFF) << 8) //
| ((buffer[ptr + 2] & 0xFF) << 16) //
| ((buffer[ptr + 3] & 0xFF) << 24);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -311,6 +312,7 @@ public class WozFile
int startingBlock; int startingBlock;
int blockCount; int blockCount;
int bitCount; int bitCount;
int bytesUsed; // WOZ1 - not needed
byte[] rawBuffer; byte[] rawBuffer;
byte[] newBuffer; byte[] newBuffer;
@ -319,7 +321,6 @@ public class WozFile
int byteIndex; int byteIndex;
int trackIndex; int trackIndex;
int revolutions; int revolutions;
int bytesUsed;
List<Sector> sectors = new ArrayList<> (); List<Sector> sectors = new ArrayList<> ();
@ -471,13 +472,6 @@ public class WozFile
return -1; return -1;
} }
// ---------------------------------------------------------------------------------//
void dump ()
// ---------------------------------------------------------------------------------//
{
System.out.println (HexFormatter.format (newBuffer));
}
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
@ -485,14 +479,17 @@ public class WozFile
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
if (wozVersion == 1) if (wozVersion == 1)
text.append (String.format ("Bytes: %2d, Bits: %,8d%n%n", bytesUsed, bitCount)); text.append (
String.format ("WOZ1: Bytes: %2d, Bits: %,8d%n%n", bytesUsed, bitCount));
else else
text.append (String.format ("Start: %4d, Blocks: %2d, Bits: %,8d%n%n", text.append (String.format ("WOZ2: Start: %4d, Blocks: %2d, Bits: %,8d%n%n",
startingBlock, blockCount, bitCount)); startingBlock, blockCount, bitCount));
int count = 0; int count = 0;
for (Sector sector : sectors) for (Sector sector : sectors)
text.append (String.format ("%2d %s%n", count++, sector)); text.append (String.format ("%2d %s%n", count++, sector));
text.deleteCharAt (text.length () - 1); text.deleteCharAt (text.length () - 1);
return text.toString (); return text.toString ();
} }
@ -537,16 +534,6 @@ public class WozFile
return this.sectorNo == sector.sectorNo; return this.sectorNo == sector.sectorNo;
} }
// ---------------------------------------------------------------------------------//
void dump ()
// ---------------------------------------------------------------------------------//
{
System.out.println ();
System.out.println (this);
System.out.println (HexFormatter.format (track.newBuffer, addressOffset, BLOCK_SIZE,
addressOffset));
}
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
void pack (DiskReader diskReader, byte[] buffer, int ptr) throws DiskNibbleException void pack (DiskReader diskReader, byte[] buffer, int ptr) throws DiskNibbleException
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//