added nib package

This commit is contained in:
Denis Molony 2018-08-17 11:20:00 +10:00
parent aa7b57dca8
commit 60eb17c12d
17 changed files with 135 additions and 101 deletions

View File

@ -15,6 +15,9 @@ import java.util.zip.Checksum;
import com.bytezone.common.Utility;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.nib.NibFile;
import com.bytezone.diskbrowser.nib.V2dFile;
import com.bytezone.diskbrowser.nib.WozFile;
import com.bytezone.diskbrowser.utilities.FileFormatException;
import com.bytezone.diskbrowser.utilities.HexFormatter;
@ -208,7 +211,7 @@ public class AppleDisk implements Disk
this.tracks = tracks;
this.sectors = sectors;
file = disk.file;
diskBuffer = disk.diskBuffer;
diskBuffer = disk.getDiskBuffer ();
trackSize = 4096;
sectorSize = trackSize / sectors;
@ -223,7 +226,7 @@ public class AppleDisk implements Disk
tracks = 35;
trackSize = 4096;
file = disk.file;
diskBuffer = disk.buffer;
diskBuffer = disk.getDiskBuffer ();
}
public AppleDisk (WozFile wozFile, int tracks, int sectors)
@ -231,7 +234,7 @@ public class AppleDisk implements Disk
this.tracks = tracks;
this.sectors = sectors;
file = wozFile.file;
diskBuffer = wozFile.diskBuffer;
diskBuffer = wozFile.getDiskBuffer ();
if (sectors == 13)
{

View File

@ -15,6 +15,9 @@ import java.util.zip.ZipFile;
import com.bytezone.diskbrowser.cpm.CPMDisk;
import com.bytezone.diskbrowser.dos.DosDisk;
import com.bytezone.diskbrowser.infocom.InfocomDisk;
import com.bytezone.diskbrowser.nib.NibFile;
import com.bytezone.diskbrowser.nib.V2dFile;
import com.bytezone.diskbrowser.nib.WozFile;
import com.bytezone.diskbrowser.pascal.PascalDisk;
import com.bytezone.diskbrowser.prodos.ProdosDisk;
import com.bytezone.diskbrowser.utilities.FileFormatException;

View File

@ -222,11 +222,16 @@ abstract class AbstractCatalogEntry implements AppleFileSource
else
appleFile = new AssemblerProgram (name, exactBuffer, loadAddress);
}
else if ((loadAddress == 0x5800 //
|| loadAddress == 0x6000 //
|| loadAddress == 0x7800) //
&& reportedLength == 0x240)
else if (reportedLength == 0x240 //
&& (loadAddress == 0x5800 || loadAddress == 0x6000
|| loadAddress == 0x7800))
appleFile = new PrintShopGraphic (name, exactBuffer);
else if (isRunCommand (exactBuffer))
{
byte[] buf = new byte[exactBuffer.length - 4];
System.arraycopy (exactBuffer, 4, buf, 0, buf.length);
appleFile = new BasicProgram (name, buf);
}
else
{
appleFile = new AssemblerProgram (name, exactBuffer, loadAddress);
@ -290,6 +295,13 @@ abstract class AbstractCatalogEntry implements AppleFileSource
return exactBuffer;
}
private boolean isRunCommand (byte[] buffer)
{
// see Stargate - Disk 1, Side A.woz
return buffer[0] == 0x4C && buffer[1] == (byte) 0xFC && buffer[2] == (byte) 0xA4
&& buffer[3] == 0x00;
}
private boolean isScrunched (int reportedLength)
{
if ((name.equals ("FLY LOGO") || name.equals ("FLY LOGO SCRUNCHED"))

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
public abstract class ByteTranslator
{

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
public class ByteTranslator5and3 extends ByteTranslator
{

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
public class ByteTranslator6and2 extends ByteTranslator
{

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
class DiskAddressField
{

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
public class DiskNibbleException extends Exception
{

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
public abstract class DiskReader
{

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
public class DiskReader13Sector extends DiskReader
{

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
public class DiskReader16Sector extends DiskReader
{

View File

@ -1,9 +1,9 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.utilities.HexFormatter;
import com.bytezone.diskbrowser.disk.*;
class MC3470
{
@ -25,7 +25,29 @@ class MC3470
private final DiskReader diskReader13Sector = new DiskReader13Sector ();
private final byte[] dataBuffer = new byte[MAX_DATA];
private int dataPtr = 0;
private int dataPtr;
// D5 AA 96 16 sector address prologue
// D5 AA B5 13 sector address prologue
// D5 AA AD data prologue
// DE AA EB epilogue
// non-standard:
// D4 AA 96 address prologue - Bouncing Kamungas
// D5 BB CF data prologue - Hard Hat Mac
// DA AA EB address epilogue - Bouncing Kamungas
private static final byte[] address16prologue =
{ (byte) 0xD5, (byte) 0xAA, (byte) 0x96 };
private static final byte[] address13prologue =
{ (byte) 0xD5, (byte) 0xAA, (byte) 0xB5 };
private static final byte[] dataPrologue = { (byte) 0xD5, (byte) 0xAA, (byte) 0xAD };
private static final byte[] epilogue = { (byte) 0xDE, (byte) 0xAA, (byte) 0xEB };
private static final byte[] address16prologueX =
{ (byte) 0xD4, (byte) 0xAA, (byte) 0x96 };
private static final byte[] dataPrologueX = { (byte) 0xD5, (byte) 0xBB, (byte) 0xCF };
private static final byte[] epilogueX = { (byte) 0xDA, (byte) 0xAA, (byte) 0xEB };
private enum State
{
@ -46,11 +68,11 @@ class MC3470
diskReader = null;
currentDiskSector = null;
currentState = State.OTHER;
expectedDataSize = MAX_DATA;
restarted = false;
byte value = 0; // value to be stored
dataPtr = 0;
expectedDataSize = MAX_DATA;
int inPtr = offset; // keep offset in case we have to loop around
final int max = offset + bytesUsed;
@ -123,34 +145,36 @@ class MC3470
{
assert currentState == State.OTHER;
switch (dataBuffer[dataPtr - 1]) // last byte added
if (dataPtr < 3) // not enough bytes to test
return;
if (match (address16prologue) || match (address16prologueX))
{
case (byte) 0xB5:
if (isPrologue ())
{
diskReader = diskReader13Sector;
setState (State.ADDRESS);
}
break;
case (byte) 0x96:
if (isPrologue ())
{
diskReader = diskReader16Sector;
setState (State.ADDRESS);
}
break;
case (byte) 0xAD:
if (isPrologue ())
setState (State.DATA);
break;
case (byte) 0xEB:
if (isEpilogue ())
setState (State.OTHER);
break;
diskReader = diskReader16Sector;
setState (State.ADDRESS);
}
else if (match (address13prologue))
{
diskReader = diskReader13Sector;
setState (State.ADDRESS);
}
else if (match (dataPrologue) || match (dataPrologueX))
setState (State.DATA);
else if (match (epilogue) || match (epilogueX))
setState (State.OTHER);
}
// ---------------------------------------------------------------------------------//
// match
// ---------------------------------------------------------------------------------//
private boolean match (byte[] pattern)
{
for (int i = 0, j = dataPtr - 3; i < 3; i++, j++)
if (pattern[i] != dataBuffer[j])
return false;
return true;
}
// ---------------------------------------------------------------------------------//
@ -164,7 +188,7 @@ class MC3470
assert currentState != newState : currentState + " -> " + newState;
switch (currentState) // this state is now finished
switch (currentState) // this state is now finished
{
case ADDRESS:
if (currentDiskSector != null)
@ -191,68 +215,33 @@ class MC3470
break;
}
switch (newState) // this state is now starting
switch (newState) // this state is now starting
{
case ADDRESS:
if (currentDiskSector != null)
throw new DiskNibbleException ("cannot start ADDRESS: " + currentDiskSector);
expectedDataSize = 8;
if (dump)
System.out.print ("ADDRESS ");
break;
case DATA:
if (currentDiskSector == null)
throw new DiskNibbleException ("cannot start DATA without ADDRESS");
expectedDataSize = diskReader.expectedDataSize ();
if (dump)
System.out.println ("DATA");
if (debug && currentDiskSector == null)
{
System.out.println ("starting DATA with no ADDRESS");
System.out.println (HexFormatter.format (dataBuffer, 0, dataPtr));
}
break;
case OTHER:
expectedDataSize = MAX_DATA; // what is the maximum filler?
expectedDataSize = MAX_DATA; // what is the maximum filler?
if (dump)
System.out.println ("OTHER");
break;
}
currentState = newState;
dataPtr = 0; // start collecting new buffer
}
// D5 AA 96 16 sector address prologue
// D5 AA B5 13 sector address prologue
// D5 AA AD data prologue
// DE AA EB epilogue
// non-standard:
// D4 AA 96 xx sector address prologue - Bouncing Kamungas
// D5 BB CF data prologue - Hard Hat Mac
// DA AA EB address epilogue - Bouncing Kamungas
// ---------------------------------------------------------------------------------//
// isPrologue
// ---------------------------------------------------------------------------------//
private boolean isPrologue ()
{
return dataPtr >= 3
&& (dataBuffer[dataPtr - 3] == (byte) 0xD5
|| dataBuffer[dataPtr - 3] == (byte) 0xD4) // non-standard
&& dataBuffer[dataPtr - 2] == (byte) 0xAA;
}
// ---------------------------------------------------------------------------------//
// isEpilogue
// ---------------------------------------------------------------------------------//
private boolean isEpilogue ()
{
return dataPtr >= 3
&& (dataBuffer[dataPtr - 3] == (byte) 0xDE
|| dataBuffer[dataPtr - 3] == (byte) 0xDA) // non-standard
&& dataBuffer[dataPtr - 2] == (byte) 0xAA;
dataPtr = 0; // start collecting new buffer
}
// ---------------------------------------------------------------------------------//

View File

@ -1,19 +1,19 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
class NibFile
public class NibFile
{
// private final Nibblizer nibbler;
final File file;
public final File file;
int tracks;
int actualTracks;
final byte[] buffer = new byte[4096 * 35];
final byte[] diskBuffer = new byte[4096 * 35];
// .nib files are 232,960 bytes
// 6,656 bytes x 35 tracks (0x1A00)
@ -53,4 +53,13 @@ class NibFile
e.printStackTrace ();
}
}
// ---------------------------------------------------------------------------------//
// getDiskBuffer
// ---------------------------------------------------------------------------------//
public byte[] getDiskBuffer ()
{
return diskBuffer;
}
}

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
class Nibblizer
{

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
public class RawDiskSector
{

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
import java.io.BufferedInputStream;
import java.io.File;
@ -30,7 +30,7 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
// Position: 0 8 1 9 2 A 3 B 4 C 5 D 6 E 7 F - Prodos (.PO disks)
// Position: 0 7 E 6 D 5 C 4 B 3 A 2 9 1 8 F - Dos (.DO disks)
class V2dFile
public class V2dFile
{
// private static int[][] interleave =
// { { 0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15 },
@ -43,7 +43,7 @@ class V2dFile
private final Nibblizer nibbler;
final File file;
public final File file;
final int tracks;
final byte[] diskBuffer = new byte[4096 * 35];
@ -100,4 +100,13 @@ class V2dFile
this.tracks = tracks;
}
// ---------------------------------------------------------------------------------//
// getDiskBuffer
// ---------------------------------------------------------------------------------//
public byte[] getDiskBuffer ()
{
return diskBuffer;
}
}

View File

@ -1,4 +1,4 @@
package com.bytezone.diskbrowser.disk;
package com.bytezone.diskbrowser.nib;
import java.io.BufferedInputStream;
import java.io.File;
@ -8,7 +8,7 @@ import java.util.List;
import com.bytezone.diskbrowser.utilities.Utility;
class WozFile
public class WozFile
{
private static final byte[] WOZ_FILE_HEADER =
{ 0x57, 0x4F, 0x5A, 0x31, (byte) 0xFF, 0x0a, 0x0D, 0x0A };
@ -20,7 +20,7 @@ class WozFile
private final boolean debug = false;
private int diskType; // 5.25 or 3.5
final File file;
public final File file;
byte[] diskBuffer;
private final MC3470 mc3470 = new MC3470 ();
@ -156,7 +156,7 @@ class WozFile
// getSectorsPerTrack
// ---------------------------------------------------------------------------------//
int getSectorsPerTrack ()
public int getSectorsPerTrack ()
{
return mc3470.is13Sector () ? 13 : mc3470.is16Sector () ? 16 : 0;
}
@ -177,6 +177,15 @@ class WozFile
return value;
}
// ---------------------------------------------------------------------------------//
// getDiskBuffer
// ---------------------------------------------------------------------------------//
public byte[] getDiskBuffer ()
{
return diskBuffer;
}
// ---------------------------------------------------------------------------------//
// readFile
// ---------------------------------------------------------------------------------//