mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-11-29 11:49:29 +00:00
tidying
This commit is contained in:
parent
1e6648dc73
commit
e1d1e0408a
@ -1,22 +1,47 @@
|
||||
package com.bytezone.diskbrowser.nib;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public abstract class DiskReader
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
static final int BLOCK_SIZE = 256;
|
||||
static final byte[] dataPrologue = { (byte) 0xD5, (byte) 0xAA, (byte) 0xAD };
|
||||
|
||||
static DiskReader reader13;
|
||||
static DiskReader reader16;
|
||||
|
||||
final int sectorsPerTrack;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
// constructor
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
||||
DiskReader (int 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
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return decodeSector (buffer, 0);
|
||||
}
|
||||
|
@ -27,12 +27,9 @@ public class WozFile
|
||||
private static final int TRK_SIZE = 0x1A00;
|
||||
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 =
|
||||
{ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
{ 0, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 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 } }; // 16 sector
|
||||
|
||||
public final File file;
|
||||
|
||||
@ -95,7 +92,7 @@ public class WozFile
|
||||
ptr += size + 8;
|
||||
}
|
||||
|
||||
DiskReader diskReader = diskSectors == 13 ? diskReader13Sector : diskReader16Sector;
|
||||
DiskReader diskReader = DiskReader.getDiskReader (diskSectors);
|
||||
diskBuffer = new byte[35 * diskSectors * 256];
|
||||
int ndx = diskSectors == 13 ? 0 : 1;
|
||||
|
||||
@ -144,7 +141,7 @@ public class WozFile
|
||||
System.out.printf ("Creator ............. %s%n", creator);
|
||||
}
|
||||
|
||||
if (wozVersion == 2)
|
||||
if (wozVersion >= 2)
|
||||
{
|
||||
int sides = val8 (buffer, ptr + 45);
|
||||
int bootSectorFormat = val8 (buffer, ptr + 46);
|
||||
@ -217,6 +214,7 @@ public class WozFile
|
||||
|
||||
int reclen = wozVersion == 1 ? TRK_SIZE : 8;
|
||||
int max = wozVersion == 1 ? 35 : 160;
|
||||
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
try
|
||||
@ -248,15 +246,18 @@ public class WozFile
|
||||
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)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return (buffer[ptr++] & 0xFF) + ((buffer[ptr++] & 0xFF) << 8)
|
||||
+ ((buffer[ptr++] & 0xFF) << 16) + ((buffer[ptr] & 0xFF) << 24);
|
||||
return (buffer[ptr] & 0xFF) //
|
||||
| ((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 blockCount;
|
||||
int bitCount;
|
||||
int bytesUsed; // WOZ1 - not needed
|
||||
|
||||
byte[] rawBuffer;
|
||||
byte[] newBuffer;
|
||||
@ -319,7 +321,6 @@ public class WozFile
|
||||
int byteIndex;
|
||||
int trackIndex;
|
||||
int revolutions;
|
||||
int bytesUsed;
|
||||
|
||||
List<Sector> sectors = new ArrayList<> ();
|
||||
|
||||
@ -471,13 +472,6 @@ public class WozFile
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void dump ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
System.out.println (HexFormatter.format (newBuffer));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
@ -485,14 +479,17 @@ public class WozFile
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
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
|
||||
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));
|
||||
|
||||
int count = 0;
|
||||
for (Sector sector : sectors)
|
||||
text.append (String.format ("%2d %s%n", count++, sector));
|
||||
text.deleteCharAt (text.length () - 1);
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
@ -537,16 +534,6 @@ public class WozFile
|
||||
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
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
Loading…
Reference in New Issue
Block a user