display DOS boot sector at $800

This commit is contained in:
Denis Molony 2016-07-31 12:14:48 +10:00
parent 13f80145e7
commit c44128200f
2 changed files with 67 additions and 16 deletions

View File

@ -5,10 +5,15 @@ import java.util.List;
import com.bytezone.diskbrowser.disk.AbstractSector;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class BootSector extends AbstractSector
{
AssemblerProgram assembler;
private static final byte[] skew =
{ 0x00, 0x0D, 0x0B, 0x09, 0x07, 0x05, 0x03, 0x01, 0x0E, 0x0C, 0x0A, 0x08, 0x06,
0x04, 0x02, 0x0F, 0x00 };
AssemblerProgram assembler1;
AssemblerProgram assembler2;
String name; // DOS or Prodos
public BootSector (Disk disk, byte[] buffer, String name, DiskAddress diskAddress)
@ -29,11 +34,25 @@ public class BootSector extends AbstractSector
{
StringBuilder text = new StringBuilder ();
if (assembler == null)
if (assembler1 == null)
{
int flag = buffer[0] & 0xFF;
if (flag == 1) // apple II
assembler = new AssemblerProgram (name + " Boot Loader", buffer, 0x00, 1);
{
if (matches (buffer, 0x4D, skew))
{
int newLen = 0x100 - (0x4D + skew.length);
byte[] buf1 = new byte[0x4D];
byte[] buf2 = new byte[newLen];
System.arraycopy (buffer, 0, buf1, 0, 0x4D);
System.arraycopy (buffer, 0x4D + skew.length, buf2, 0, newLen);
assembler1 = new AssemblerProgram (name + " (first)", buf1, 0x800, 1);
assembler2 =
new AssemblerProgram (name + " (second)", buf2, 0x84D + skew.length, 0);
}
else
assembler1 = new AssemblerProgram (name + " Boot Loader", buffer, 0x00, 1);
}
else // apple III (SOS)
{
byte[] newBuffer = new byte[buffer.length * 2];
@ -43,12 +62,31 @@ public class BootSector extends AbstractSector
System.arraycopy (buf, 0, newBuffer, buf.length, buf.length);
buffer = newBuffer;
assembler = new AssemblerProgram (name + " Boot Loader", buffer, 0x00, 0);
assembler1 = new AssemblerProgram (name + " Boot Loader", buffer, 0x00, 0);
}
}
text.append (assembler.getText ());
text.append (assembler1.getText ());
if (assembler2 != null)
{
text.append ("\n\n");
text.append (HexFormatter.formatNoHeader (buffer, 0x4D, skew.length, 0x800));
text.append ("\n\n");
text.append (assembler2.getText ());
}
return text.toString ();
}
private boolean matches (byte[] buffer, int offset, byte[] test)
{
if (test.length == 0 || test.length > buffer.length - offset)
return false;
for (int i = 0; i < test.length; i++)
if (test[i] != buffer[offset++])
return false;
return true;
}
}

View File

@ -35,11 +35,12 @@ public class AppleDisk implements Disk
private int interleave = 0;
private static int[][] interleaveSector = //
{ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // Dos
{ 0, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15 }, // Prodos
{ 0, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2, 15 }, // Infocom
{ 0, 6, 12, 3, 9, 15, 14, 5, 11, 2, 8, 7, 13, 4, 10, 1 } }; // CPM
{ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // Dos
{ 0, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15 }, // Prodos
{ 0, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2, 15 }, // Infocom
{ 0, 6, 12, 3, 9, 15, 14, 5, 11, 2, 8, 7, 13, 4, 10, 1 } }; // CPM
// Physical disk interleave:
// Info from http://www.applelogic.org/TheAppleIIEGettingStarted.html
// Block: 0 1 2 3 4 5 6 7 8 9 A B C D E F
// Position: 0 8 1 9 2 A 3 B 4 C 5 D 6 E 7 F - Prodos (.PO disks)
@ -59,6 +60,17 @@ public class AppleDisk implements Disk
// {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
//};
// * TABLE OF PHYSICAL BSECTR NUMBERS
// * WHICH CORRESPOND TO THE LOGICAL
// * BSECTRS 0-F ON TRACK ZERO...
// BHERE2 EQU >*
// TABLE EQU $800+BHERE2
// DFB $00,13,11 ;00->00,01->13,02->11
// DFB 09,07,05 ;03->09,04->07;05->05
// DFB 03,01,14 ;06->03,07->01,08->14
// DFB 12,10,08 ;09->12,10->10,11->08
// DFB 06,04,02,15 ;12->06,13->04,14->02,15->15
private boolean[] hasData;
private byte emptyByte = 0;
@ -82,7 +94,7 @@ public class AppleDisk implements Disk
int skip = 0;
if ((pos > 0 && name.substring (pos + 1).equalsIgnoreCase ("2mg"))
|| "2IMG".equals (prefix))
|| "2IMG".equals (prefix))
// if ("2IMG".equals (prefix))
{
if (debug)
@ -395,7 +407,8 @@ public class AppleDisk implements Disk
public DiskAddress getDiskAddress (int track, int sector)
{
// should this return null for invalid addresses?
assert (isValidAddress (track, sector)) : "Invalid address : " + track + ", " + sector;
assert (isValidAddress (track, sector)) : "Invalid address : " + track + ", "
+ sector;
return new AppleDiskAddress (this, track, sector);
}
@ -438,22 +451,22 @@ public class AppleDisk implements Disk
assert da.getDisk () == this : "Disk address not applicable to this disk";
assert sectorSize == 256 || sectorSize == 512 : "Invalid sector size : " + sectorSize;
assert interleave >= 0 && interleave <= MAX_INTERLEAVE : "Invalid interleave : "
+ interleave;
+ interleave;
if (sectorSize == 256)
{
int diskOffset = da.getTrack () * trackSize
+ interleaveSector[interleave][da.getSector ()] * sectorSize;
+ interleaveSector[interleave][da.getSector ()] * sectorSize;
System.arraycopy (diskBuffer, diskOffset, buffer, bufferOffset, sectorSize);
}
else if (sectorSize == 512)
{
int diskOffset = da.getTrack () * trackSize
+ interleaveSector[interleave][da.getSector () * 2] * 256;
+ interleaveSector[interleave][da.getSector () * 2] * 256;
System.arraycopy (diskBuffer, diskOffset, buffer, bufferOffset, 256);
diskOffset = da.getTrack () * trackSize
+ interleaveSector[interleave][da.getSector () * 2 + 1] * 256;
+ interleaveSector[interleave][da.getSector () * 2 + 1] * 256;
System.arraycopy (diskBuffer, diskOffset, buffer, bufferOffset + 256, 256);
}
}
@ -474,7 +487,7 @@ public class AppleDisk implements Disk
{
if (actionListenerList != null)
actionListenerList
.actionPerformed (new ActionEvent (this, ActionEvent.ACTION_PERFORMED, text));
.actionPerformed (new ActionEvent (this, ActionEvent.ACTION_PERFORMED, text));
}
public AppleFileSource getDetails ()