This commit is contained in:
Denis Molony 2016-02-25 13:49:12 +11:00
parent 13f8229db8
commit 37b0f587e7
3 changed files with 70 additions and 5 deletions

View File

@ -14,14 +14,23 @@ public class CPMDisk extends AbstractFormattedDisk
private final Color green = new Color (0, 200, 0);
public final SectorType catalogSector = new SectorType ("Catalog", green);
public final SectorType cpmSector = new SectorType ("CPM", Color.lightGray);
public final SectorType comSector = new SectorType ("COM", Color.red);
public final SectorType dataSector = new SectorType ("Data", Color.blue);
public final SectorType docSector = new SectorType ("DOC", Color.cyan);
public final SectorType xxxSector = new SectorType ("xxx", Color.gray);
private int version; // http://www.seasip.info/Cpm/format22.html
public CPMDisk (Disk disk)
{
super (disk);
sectorTypesList.add (catalogSector);
sectorTypesList.add (cpmSector);
sectorTypesList.add (comSector);
sectorTypesList.add (dataSector);
sectorTypesList.add (xxxSector);
sectorTypesList.add (docSector);
byte[] sectorBuffer = disk.readSector (0, 0); // Boot sector
bootSector = new BootSector (disk, sectorBuffer, "CPM");
@ -47,6 +56,10 @@ public class CPMDisk extends AbstractFormattedDisk
if (buffer[i] == 0)
{
DirectoryEntry entry = new DirectoryEntry (this, buffer, i);
SectorType sectorType = getSectorType (entry.getType ());
for (DiskAddress block : entry.getSectors ())
sectorTypes[block.getBlock ()] = sectorType;
DirectoryEntry parent = findParent (entry);
if (parent == null)
{
@ -65,6 +78,16 @@ public class CPMDisk extends AbstractFormattedDisk
makeNodeVisible (root.getFirstLeaf ());
}
private SectorType getSectorType (String type)
{
if ("COM".equals (type))
return comSector;
if ("DOC".equals (type))
return docSector;
return dataSector;
}
@Override
public List<DiskAddress> getFileSectors (int fileNo)
{
@ -84,10 +107,11 @@ public class CPMDisk extends AbstractFormattedDisk
public AppleFileSource getCatalog ()
{
String newLine = String.format ("%n");
String line = "---- --------- ---- ---- ----" + newLine;
String line = "---- --------- ---- ---- ---- ----------------------------"
+ "-------------------" + newLine;
StringBuilder text = new StringBuilder ();
text.append (String.format ("Disk : %s%n%n", getAbsolutePath ()));
text.append ("User Name Type Exts Size" + newLine);
text.append ("User Name Type Exts Size Blocks" + newLine);
text.append (line);
for (AppleFileSource entry : fileEntries)
@ -95,6 +119,7 @@ public class CPMDisk extends AbstractFormattedDisk
text.append (((DirectoryEntry) entry).line ());
text.append (newLine);
}
text.append (line);
return new DefaultAppleFileSource ("CPM Disk ", text.toString (), this);
}

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.disk.AppleDiskAddress;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.disk.FormattedDisk;
import com.bytezone.diskbrowser.gui.DataSource;
@ -21,6 +23,7 @@ public class DirectoryEntry implements AppleFileSource
private final int rc;
private final byte[] blockList = new byte[16];
private final List<DirectoryEntry> entries = new ArrayList<DirectoryEntry> ();
private final List<DiskAddress> blocks = new ArrayList<DiskAddress> ();
public DirectoryEntry (CPMDisk parent, byte[] buffer, int offset)
{
@ -33,6 +36,22 @@ public class DirectoryEntry implements AppleFileSource
s1 = buffer[offset + 14] & 0xFF;
rc = buffer[offset + 15] & 0xFF;
System.arraycopy (buffer, offset + 16, blockList, 0, 16);
Disk disk = parent.getDisk ();
for (byte b : blockList)
{
if (b == 0)
break;
int blockNumber = b * 4 + 48;
for (int i = 0; i < 4; i++)
blocks.add (new AppleDiskAddress (blockNumber + i, disk));
}
}
public String getType ()
{
return type;
}
public boolean matches (DirectoryEntry directoryEntry)
@ -44,13 +63,33 @@ public class DirectoryEntry implements AppleFileSource
public void add (DirectoryEntry entry)
{
entries.add (entry);
Disk disk = parent.getDisk ();
for (byte b : entry.blockList)
{
if (b == 0)
break;
int blockNumber = b * 4 + 48;
for (int i = 0; i < 4; i++)
blocks.add (new AppleDiskAddress (blockNumber + i, disk));
}
}
public String line ()
{
int blocks = ((rc & 0xF0) >> 3) + (((rc & 0x0F) + 7) / 8);
return String.format ("%3d %-8s %-3s %3d %3d", userNumber, name, type,
entries.size () + 1, blocks);
String bytes = HexFormatter.getHexString (blockList, 0, 16);
bytes = bytes.replaceAll ("00", " ");
String text = String.format ("%3d %-8s %-3s %3d %3d %s", userNumber, name,
type, entries.size () + 1, blocks, bytes);
for (DirectoryEntry entry : entries)
{
bytes = HexFormatter.getHexString (entry.blockList, 0, 16);
bytes = bytes.replaceAll ("00", " ");
text = text + String.format ("%n%-36.36s%s", "", bytes);
}
return text;
}
public String toDetailedString ()
@ -93,7 +132,7 @@ public class DirectoryEntry implements AppleFileSource
@Override
public List<DiskAddress> getSectors ()
{
return null;
return blocks;
}
@Override

View File

@ -355,6 +355,7 @@ public class PascalDisk extends AbstractFormattedDisk
public FileEntry (byte[] buffer)
{
super (buffer);
bytesUsedInLastBlock = HexFormatter.intValue (buffer[22], buffer[23]);
date = HexFormatter.getPascalDate (buffer, 24);