2015-06-01 09:35:51 +00:00
|
|
|
package com.bytezone.diskbrowser.dos;
|
|
|
|
|
|
|
|
import com.bytezone.diskbrowser.disk.AbstractSector;
|
|
|
|
import com.bytezone.diskbrowser.disk.Disk;
|
|
|
|
import com.bytezone.diskbrowser.disk.DiskAddress;
|
2016-02-24 21:11:14 +00:00
|
|
|
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
class DosTSListSector extends AbstractSector
|
|
|
|
{
|
2016-07-18 05:02:04 +00:00
|
|
|
private final String name;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-07-17 04:41:04 +00:00
|
|
|
public DosTSListSector (String name, Disk disk, byte[] buffer, DiskAddress diskAddress)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-07-17 04:41:04 +00:00
|
|
|
super (disk, buffer, diskAddress);
|
2015-06-01 09:35:51 +00:00
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isValid (DosDisk dosDisk)
|
|
|
|
{
|
|
|
|
// what is the count of blocks? does it match? this sector can't tell, there
|
|
|
|
// might be more than one TS list
|
|
|
|
|
|
|
|
// validate the sector, throw an exception if invalid
|
|
|
|
for (int i = 12; i < buffer.length; i += 2)
|
|
|
|
{
|
|
|
|
DiskAddress da = getValidAddress (buffer, i);
|
|
|
|
if (da == null)
|
|
|
|
{
|
|
|
|
System.out.println ("Invalid sector address : null");
|
2016-07-17 03:32:30 +00:00
|
|
|
break; // throw exception?
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (da.getBlock () > 0 && dosDisk.stillAvailable (da))
|
|
|
|
{
|
|
|
|
System.out.println ("Invalid sector address : " + da);
|
2016-07-17 03:32:30 +00:00
|
|
|
break; // throw exception?
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is in too many places
|
|
|
|
protected DiskAddress getValidAddress (byte[] buffer, int offset)
|
|
|
|
{
|
|
|
|
if (disk.isValidAddress (buffer[offset], buffer[offset + 1]))
|
|
|
|
return disk.getDiskAddress (buffer[offset], buffer[offset + 1]);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String createText ()
|
|
|
|
{
|
2016-07-17 04:41:04 +00:00
|
|
|
DiskAddress da = disk.getDiskAddress (buffer[1], buffer[2]);
|
2016-07-17 22:42:44 +00:00
|
|
|
String msg = da.matches (diskAddress) ? " (circular reference)" : "";
|
2016-07-17 04:41:04 +00:00
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
StringBuilder text = getHeader ("TS List Sector : " + name);
|
|
|
|
addText (text, buffer, 0, 1, "Not used");
|
2016-07-17 04:41:04 +00:00
|
|
|
addText (text, buffer, 1, 2, "Next TS list track/sector" + msg);
|
2015-06-01 09:35:51 +00:00
|
|
|
addText (text, buffer, 3, 2, "Not used");
|
|
|
|
addTextAndDecimal (text, buffer, 5, 2, "Sector base number");
|
|
|
|
addText (text, buffer, 7, 4, "Not used");
|
|
|
|
addText (text, buffer, 11, 1, "Not used");
|
|
|
|
|
|
|
|
int sectorBase = HexFormatter.intValue (buffer[5], buffer[6]);
|
|
|
|
|
|
|
|
for (int i = 12; i <= 255; i += 2)
|
|
|
|
{
|
|
|
|
if (buffer[i] == 0 && buffer[i + 1] == 0)
|
2016-07-18 08:55:32 +00:00
|
|
|
msg = "";
|
2015-06-01 09:35:51 +00:00
|
|
|
else
|
2019-01-30 09:06:48 +00:00
|
|
|
{
|
|
|
|
String msg2 = buffer[i] == 0x40 ? " - track zero" : "";
|
|
|
|
msg = String.format ("Track/sector of file sector %04X (%<,d)%s",
|
|
|
|
((i - 12) / 2 + sectorBase), msg2);
|
|
|
|
}
|
2016-07-18 08:55:32 +00:00
|
|
|
addText (text, buffer, i, 2, msg);
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
text.deleteCharAt (text.length () - 1);
|
|
|
|
return text.toString ();
|
|
|
|
}
|
|
|
|
}
|