More v2d code

This commit is contained in:
Denis Molony 2016-11-30 08:27:44 +11:00
parent d1ceac22ac
commit 681b33df4f
7 changed files with 110 additions and 26 deletions

View File

@ -59,7 +59,7 @@ public class AssemblerProgram extends AbstractFile
return text;
return text + "\n\n" + HexFormatter.format (extraBuffer, 0, extraBuffer.length,
loadAddress + buffer.length);
loadAddress + buffer.length);
}
@Override
@ -180,8 +180,8 @@ public class AssemblerProgram extends AbstractFile
{
StringBuilder line = new StringBuilder ();
line.append (String.format ("%3.3s %04X: %02X ", getArrow (cmd), cmd.address,
cmd.value));
line.append (
String.format ("%3.3s %04X: %02X ", getArrow (cmd), cmd.address, cmd.value));
if (cmd.size > 1)
line.append (String.format ("%02X ", cmd.operand1));
@ -306,7 +306,7 @@ public class AssemblerProgram extends AbstractFile
{
int address = Integer.parseInt (line.substring (0, 4), 16);
if (equates.containsKey (address))
System.out.println ("Duplicate equate entry : " + address);
System.out.printf ("Duplicate equate entry : %04X%n" + address);
else
equates.put (address, line.substring (6));
}

View File

@ -32,7 +32,7 @@
03EA VECT
A56E catalog routine
C000 80STOREOFF Allow page2 to switch video page1 page2
* C000 80STOREOFF Allow page2 to switch video page1 page2
C001 80STOREON Allow page2 to switch main & aux video memory
C002 RAMRDOFF Read enable main memory from $0200-$BFFF
C003 RAMDRON Read enable aux memory from $0200-$BFFF

View File

@ -221,18 +221,27 @@ public class AppleDisk implements Disk
public AppleDisk (V2dDisk disk)
{
tracks = disk.actualTracks;
tracks = 35;
trackSize = 4096;
file = disk.file;
diskBuffer = disk.buffer;
sectorSize = 256;
sectors = 16;
blocks = tracks * sectors;
file = disk.file;
diskBuffer = disk.buffer;
hasData = new boolean[blocks];
checkSectorsForData ();
}
public AppleDisk (NibDisk disk) // not used yet
{
tracks = 35;
trackSize = 4096;
file = disk.file;
diskBuffer = disk.buffer;
}
private byte[] getPrefix (File path)
{
byte[] buffer = new byte[64];
@ -463,9 +472,12 @@ public class AppleDisk implements Disk
@Override
public DiskAddress getDiskAddress (int track, int sector)
{
// should this return null for invalid addresses?
assert (isValidAddress (track, sector)) : "Invalid address : " + track + ", "
+ sector;
if (!isValidAddress (track, sector))
{
System.out.println ("Invalid block : " + track + "/" + sector);
return null;
// return new AppleDiskAddress (this, 0); this was looping 26/07/2016
}
return new AppleDiskAddress (this, track, sector);
}

View File

@ -44,7 +44,6 @@ public class DiskFactory
String suffix = path.substring (path.lastIndexOf (".") + 1).toLowerCase ();
Boolean compressed = false;
Path p = Paths.get (path);
V2dDisk v2dDisk = null;
if (suffix.equals ("sdk"))
{
@ -157,16 +156,20 @@ public class DiskFactory
if (suffix.equals ("v2d"))
{
// Disk disk = checkV2DDisk (file);
// return disk2;
// checkV2DDisk (file);
// return null;
v2dDisk = new V2dDisk (file);
V2dDisk v2dDisk = new V2dDisk (file);
AppleDisk appleDisk16 = new AppleDisk (v2dDisk);
disk = checkDos (appleDisk16);
return disk;
}
if (suffix.equals ("nib"))
{
NibDisk nibDisk = new NibDisk (file);
AppleDisk appleDisk16 = new AppleDisk (nibDisk);
disk = checkDos (appleDisk16);
return null;
}
long length = file.length ();
if (length == 116480) // 13 sector disk

View File

@ -0,0 +1,43 @@
package com.bytezone.diskbrowser.disk;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class NibDisk
{
private final Nibblizer nibbler = new Nibblizer ();
final File file;
int tracks;
int actualTracks;
final byte[] buffer = new byte[4096 * 35];
// .nib files are 232,960 bytes
// 6,656 bytes x 35 tracks (0x1A00)
public NibDisk (File file)
{
this.file = file;
byte[] buffer = new byte[6656];
try
{
byte[] diskBuffer = new byte[10];
BufferedInputStream in = new BufferedInputStream (new FileInputStream (file));
for (int i = 0; i < 35; i++)
{
in.read (buffer);
// System.out.println (HexFormatter.format (buffer));
}
in.close ();
}
catch (IOException e)
{
e.printStackTrace ();
}
}
}

View File

@ -275,7 +275,7 @@ public class Nibblizer
System.out.printf ("%02X ", buffer[offset++]);
++count;
}
System.out.println ();
// System.out.println ();
return count;
}
@ -316,6 +316,11 @@ public class Nibblizer
checksum = decode4and4 (buffer, offset + 9);
valid = true;
}
else
{
listBytes (buffer, offset, 14);
System.out.println ();
}
}
@Override
@ -331,10 +336,21 @@ public class Nibblizer
{
super (buffer, offset);
if (matchBytes (buffer, offset, dataPrologue)
&& matchBytes (buffer, offset + 346, epilogue))
if (matchBytes (buffer, offset, dataPrologue))
{
valid = true;
if (!matchBytes (buffer, offset + 346, epilogue))
{
System.out.print (" bad data epilogue: ");
listBytes (buffer, offset + 346, 3);
System.out.println ();
}
}
else
{
System.out.print (" bad data prologue: ");
listBytes (buffer, offset, 3);
System.out.println ();
}
}

View File

@ -44,7 +44,7 @@ public class V2dDisk
final File file;
final int tracks;
int actualTracks;
// int actualTracks;
final byte[] buffer = new byte[4096 * 35];
@ -62,6 +62,7 @@ public class V2dDisk
String id = HexFormatter.getString (diskBuffer, 4, 4); // 4 bytes
tracks = HexFormatter.getShortBigEndian (diskBuffer, 8); // 2 bytes
assert diskLength + 8 == file.length ();
assert "D5NI".equals (id);
for (int i = 0; i < tracks; i++)
@ -69,18 +70,20 @@ public class V2dDisk
byte[] trackHeader = new byte[4];
in.read (trackHeader);
int trackNumber = HexFormatter.getShortBigEndian (trackHeader, 0);
int trackLength = HexFormatter.getShortBigEndian (trackHeader, 2);
int trackLength = HexFormatter.getShortBigEndian (trackHeader, 2); // 6304
int fullTrackNo = trackNumber / 4;
int halfTrackNo = trackNumber % 4;
// System.out.printf ("%3d %3d%n", fullTrackNo, halfTrackNo);
byte[] trackData = new byte[trackLength];
in.read (trackData);
// only process full tracks
if (halfTrackNo == 0 && processTrack (fullTrackNo, trackData, buffer))
actualTracks++;
if (halfTrackNo == 0)
processTrack (fullTrackNo, trackData, buffer);
else
System.out.printf ("%s skipping half track %02X / %02X%n", file.getName (),
fullTrackNo, halfTrackNo);
}
in.close ();
@ -99,7 +102,8 @@ public class V2dDisk
while (buffer[ptr] == (byte) 0xEB)
{
System.out.println ("overrun: " + ptr + " in track " + trackNo);
System.out.printf ("%s overrun 0xEB offset %d in track %02X%n", file.getName (),
ptr, trackNo);
++ptr;
}
@ -116,8 +120,14 @@ public class V2dDisk
DataField dataField = nibbler.getDataField (buffer, ptr);
if (!dataField.isValid ())
{
System.out.printf ("skipping data %02X / %02X%n", addressField.track,
addressField.sector);
return false;
}
// System.out.printf ("decoding track %02X / %02X%n", addressField.track,
// addressField.sector);
byte[] decodedBuffer = nibbler.decode6and2 (buffer, ptr + 3);
int offset = addressField.track * 4096 + interleave[DOS][addressField.sector] * 256;