dmolony-DiskBrowser/src/com/bytezone/diskbrowser/applefile/BootSector.java

104 lines
3.9 KiB
Java
Raw Normal View History

2015-06-01 09:35:51 +00:00
package com.bytezone.diskbrowser.applefile;
import com.bytezone.diskbrowser.disk.AbstractSector;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
2016-07-31 02:14:48 +00:00
import com.bytezone.diskbrowser.utilities.HexFormatter;
2015-06-01 09:35:51 +00:00
2020-09-14 07:59:15 +00:00
// -----------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
public class BootSector extends AbstractSector
2020-09-14 07:59:15 +00:00
// -----------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
2017-04-17 03:29:29 +00:00
private static final byte[] skew = { 0x00, 0x0D, 0x0B, 0x09, 0x07, 0x05, 0x03, 0x01,
0x0E, 0x0C, 0x0A, 0x08, 0x06, 0x04, 0x02, 0x0F };
2017-06-22 23:13:37 +00:00
private static final int SKEW_OFFSET = 0x4D;
2019-09-04 20:44:43 +00:00
private static final int SKEW_OFFSET_2 = 0x3C; // DOS 4.x
2017-06-22 23:13:37 +00:00
2016-07-31 02:14:48 +00:00
AssemblerProgram assembler1;
AssemblerProgram assembler2;
String name; // DOS or Prodos
2020-09-14 07:59:15 +00:00
// ---------------------------------------------------------------------------------//
public BootSector (Disk disk, byte[] buffer, String name, DiskAddress diskAddress)
2020-09-14 07:59:15 +00:00
// ---------------------------------------------------------------------------------//
{
super (disk, buffer, diskAddress);
this.name = name;
}
2015-06-01 09:35:51 +00:00
2020-09-14 07:59:15 +00:00
// ---------------------------------------------------------------------------------//
2017-06-22 23:13:37 +00:00
public BootSector (Disk disk, byte[] buffer, String name)
2020-09-14 07:59:15 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
2017-06-22 23:13:37 +00:00
super (disk, buffer);
2015-06-01 09:35:51 +00:00
this.name = name;
}
2020-09-14 07:59:15 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
@Override
public String createText ()
2020-09-14 07:59:15 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
StringBuilder text = new StringBuilder ();
2016-07-31 02:14:48 +00:00
if (assembler1 == null)
2015-06-01 09:35:51 +00:00
{
2019-09-04 20:44:43 +00:00
int flag = buffer[0] & 0xFF; // how many blocks to load
if (flag == 1) // apple II
2016-07-31 02:14:48 +00:00
{
2017-06-22 23:13:37 +00:00
if (matches (buffer, SKEW_OFFSET, skew))
2016-07-31 02:14:48 +00:00
{
2017-06-22 23:13:37 +00:00
int newLen = 0x100 - (SKEW_OFFSET + skew.length);
2016-07-31 02:14:48 +00:00
byte[] buf1 = new byte[0x4D];
byte[] buf2 = new byte[newLen];
2017-06-22 23:13:37 +00:00
System.arraycopy (buffer, 0, buf1, 0, SKEW_OFFSET);
System.arraycopy (buffer, SKEW_OFFSET + skew.length, buf2, 0, newLen);
2016-07-31 02:14:48 +00:00
assembler1 = new AssemblerProgram (name + " (first)", buf1, 0x800, 1);
2017-06-22 23:13:37 +00:00
assembler2 = new AssemblerProgram (name + " (second)", buf2,
SKEW_OFFSET + skew.length, 0);
2016-07-31 02:14:48 +00:00
}
else
assembler1 = new AssemblerProgram (name + " Boot Loader", buffer, 0x00, 1);
}
else // apple III (SOS)
2015-06-01 09:35:51 +00:00
{
2019-09-04 20:44:43 +00:00
// byte[] newBuffer = new byte[buffer.length * 2];
// System.arraycopy (buffer, 0, newBuffer, 0, buffer.length);
2015-06-01 09:35:51 +00:00
2016-08-06 10:00:01 +00:00
// byte[] buf = disk.readSector (1);
// System.arraycopy (buf, 0, newBuffer, buf.length, buf.length);
2015-12-16 02:14:05 +00:00
2016-08-06 10:00:01 +00:00
// this was doubling the size of Pascal boot blocks - 06/08/2016
// buffer = newBuffer;
2016-07-31 02:14:48 +00:00
assembler1 = new AssemblerProgram (name + " Boot Loader", buffer, 0x00, 0);
2015-12-16 02:14:05 +00:00
}
2015-06-01 09:35:51 +00:00
}
2016-07-31 02:14:48 +00:00
text.append (assembler1.getText ());
2019-09-04 20:44:43 +00:00
2016-07-31 02:14:48 +00:00
if (assembler2 != null)
{
text.append ("\n\n");
2017-06-22 23:13:37 +00:00
text.append (HexFormatter.formatNoHeader (buffer, SKEW_OFFSET, skew.length,
0x800 + SKEW_OFFSET));
2016-07-31 02:14:48 +00:00
text.append ("\n\n");
text.append (assembler2.getText ());
}
2015-06-01 09:35:51 +00:00
return text.toString ();
}
2016-07-31 02:14:48 +00:00
2020-09-14 07:59:15 +00:00
// ---------------------------------------------------------------------------------//
2016-07-31 02:14:48 +00:00
private boolean matches (byte[] buffer, int offset, byte[] test)
2020-09-14 07:59:15 +00:00
// ---------------------------------------------------------------------------------//
2016-07-31 02:14:48 +00:00
{
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;
}
2015-06-01 09:35:51 +00:00
}