CPM catalog

This commit is contained in:
Denis Molony 2016-02-25 12:55:14 +11:00
parent 82c14fb8c3
commit 13f8229db8
3 changed files with 52 additions and 37 deletions

View File

@ -1,9 +1,10 @@
package com.bytezone.diskbrowser.cpm;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import javax.swing.tree.DefaultMutableTreeNode;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.applefile.BootSector;
import com.bytezone.diskbrowser.disk.*;
@ -15,7 +16,6 @@ public class CPMDisk extends AbstractFormattedDisk
public final SectorType cpmSector = new SectorType ("CPM", Color.lightGray);
private int version; // http://www.seasip.info/Cpm/format22.html
private final List<DirectoryEntry> directoryEntries = new ArrayList<DirectoryEntry> ();
public CPMDisk (Disk disk)
{
@ -32,6 +32,8 @@ public class CPMDisk extends AbstractFormattedDisk
if ("DIR ERA TYPESAVEREN USER".equals (text))
version = buffer[41] & 0xFF;
DefaultMutableTreeNode root = getCatalogTreeRoot ();
for (int sector = 0; sector < 8; sector++)
{
DiskAddress da = disk.getDiskAddress (3, sector);
@ -44,16 +46,23 @@ public class CPMDisk extends AbstractFormattedDisk
break;
if (buffer[i] == 0)
{
DirectoryEntry entry = new DirectoryEntry (buffer, i);
DirectoryEntry entry = new DirectoryEntry (this, buffer, i);
DirectoryEntry parent = findParent (entry);
if (parent == null)
directoryEntries.add (entry);
{
fileEntries.add (entry);
DefaultMutableTreeNode node = new DefaultMutableTreeNode (entry);
root.add (node);
node.setAllowsChildren (false);
}
else
parent.add (entry);
}
}
}
// listEntries ();
root.setUserObject (getCatalog ());
makeNodeVisible (root.getFirstLeaf ());
}
@Override
@ -62,19 +71,12 @@ public class CPMDisk extends AbstractFormattedDisk
return null;
}
public void listEntries ()
{
for (DirectoryEntry entry : directoryEntries)
System.out.println (entry);
}
private DirectoryEntry findParent (DirectoryEntry child)
{
for (DirectoryEntry entry : directoryEntries)
{
if (entry.matches (child))
return entry;
}
for (AppleFileSource entry : fileEntries)
if (((DirectoryEntry) entry).matches (child))
return (DirectoryEntry) entry;
return null;
}
@ -82,15 +84,15 @@ 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" + newLine);
text.append ("User Name Type Exts Size" + newLine);
text.append (line);
for (DirectoryEntry entry : directoryEntries)
for (AppleFileSource entry : fileEntries)
{
text.append (entry.line ());
text.append (((DirectoryEntry) entry).line ());
text.append (newLine);
}

View File

@ -11,6 +11,7 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
public class DirectoryEntry implements AppleFileSource
{
private final CPMDisk parent;
private final int userNumber;
private final String name;
private final String type;
@ -21,8 +22,9 @@ public class DirectoryEntry implements AppleFileSource
private final byte[] blockList = new byte[16];
private final List<DirectoryEntry> entries = new ArrayList<DirectoryEntry> ();
public DirectoryEntry (byte[] buffer, int offset)
public DirectoryEntry (CPMDisk parent, byte[] buffer, int offset)
{
this.parent = parent;
userNumber = buffer[offset] & 0xFF;
name = new String (buffer, offset + 1, 8).trim ();
type = new String (buffer, offset + 9, 3).trim ();
@ -46,11 +48,12 @@ public class DirectoryEntry implements AppleFileSource
public String line ()
{
return name + "." + type;
int blocks = ((rc & 0xF0) >> 3) + (((rc & 0x0F) + 7) / 8);
return String.format ("%3d %-8s %-3s %3d %3d", userNumber, name, type,
entries.size () + 1, blocks);
}
@Override
public String toString ()
public String toDetailedString ()
{
StringBuilder text = new StringBuilder ();
@ -96,6 +99,12 @@ public class DirectoryEntry implements AppleFileSource
@Override
public FormattedDisk getFormattedDisk ()
{
return null;
return parent;
}
@Override
public String toString ()
{
return name + "." + type;
}
}

View File

@ -20,8 +20,8 @@ public class PascalDisk extends AbstractFormattedDisk
private final VolumeEntry volume;
private final PascalCatalogSector diskCatalogSector;
private final String[] fileTypes = { "Volume", "Xdsk", "Code", "Text", "Info", "Data",
"Graf", "Foto", "SecureDir" };
private final String[] fileTypes =
{ "Volume", "Xdsk", "Code", "Text", "Info", "Data", "Graf", "Foto", "SecureDir" };
SectorType diskBootSector = new SectorType ("Boot", Color.lightGray);
SectorType catalogSector = new SectorType ("Catalog", Color.magenta);
@ -104,7 +104,7 @@ public class PascalDisk extends AbstractFormattedDisk
{
// List<DiskAddress> blocks = new ArrayList<DiskAddress> ();
DefaultMutableTreeNode segmentNode =
new DefaultMutableTreeNode (new PascalCodeObject (ps, fe.firstBlock));
new DefaultMutableTreeNode (new PascalCodeObject (ps, fe.firstBlock));
node.add (segmentNode);
segmentNode.setAllowsChildren (false);
}
@ -229,13 +229,15 @@ public class PascalDisk extends AbstractFormattedDisk
{
String newLine = String.format ("%n");
String newLine2 = newLine + newLine;
String line = "---- --------------- ---- -------- ------- ---- ----" + newLine;
String line =
"---- --------------- ---- -------- ------- ---- ----" + newLine;
String date = volume.date == null ? "--" : df.format (volume.date.getTime ());
StringBuilder text = new StringBuilder ();
text.append ("Disk : " + disk.getFile ().getAbsolutePath () + newLine2);
text.append ("Volume : " + volume.name + newLine);
text.append ("Date : " + date + newLine2);
text.append ("Blks Name Type Date Length Frst Last" + newLine);
text.append ("Blks Name Type Date Length Frst Last"
+ newLine);
text.append (line);
int usedBlocks = 6;
@ -247,13 +249,13 @@ public class PascalDisk extends AbstractFormattedDisk
date = ce.date == null ? "--" : df.format (ce.date.getTime ());
int bytes = (size - 1) * 512 + ce.bytesUsedInLastBlock;
text.append (String.format (" %3d %-15s %s %8s %,8d $%03X $%03X%n", size,
ce.name, fileTypes[ce.fileType], date, bytes, ce.firstBlock,
ce.lastBlock));
ce.name, fileTypes[ce.fileType], date, bytes,
ce.firstBlock, ce.lastBlock));
}
text.append (line);
text.append (String.format ("Blocks free : %3d Blocks used : %3d Total blocks : %3d%n",
(volume.totalBlocks - usedBlocks), usedBlocks,
volume.totalBlocks));
text.append (String
.format ("Blocks free : %3d Blocks used : %3d Total blocks : %3d%n",
(volume.totalBlocks - usedBlocks), usedBlocks, volume.totalBlocks));
return new DefaultAppleFileSource (volume.name, text.toString (), this);
}
@ -261,7 +263,7 @@ public class PascalDisk extends AbstractFormattedDisk
{
String name;
int firstBlock;
int lastBlock; // block AFTER last used block
int lastBlock; // block AFTER last used block
int fileType;
GregorianCalendar date;
List<DiskAddress> blocks = new ArrayList<DiskAddress> ();
@ -322,6 +324,7 @@ public class PascalDisk extends AbstractFormattedDisk
public VolumeEntry (byte[] buffer)
{
super (buffer);
totalBlocks = HexFormatter.intValue (buffer[14], buffer[15]);
totalFiles = HexFormatter.intValue (buffer[16], buffer[17]);
firstBlock = HexFormatter.intValue (buffer[18], buffer[19]);
@ -334,12 +337,13 @@ public class PascalDisk extends AbstractFormattedDisk
@Override
public AbstractFile getDataSource ()
{
System.out.println ("in Volume Entry **********************");
// System.out.println ("in Volume Entry **********************");
if (file != null)
return file;
byte[] buffer = disk.readSectors (blocks);
file = new DefaultAppleFile (name, buffer);
return file;
}
}