method header lines

This commit is contained in:
Denis Molony 2020-02-08 18:13:28 +10:00
parent 4788f4bca4
commit 04557bab39
19 changed files with 3041 additions and 2650 deletions

View File

@ -4,17 +4,23 @@ import com.bytezone.diskbrowser.disk.AbstractSector;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
public class CPMCatalogSector extends AbstractSector
// -----------------------------------------------------------------------------------//
class CPMCatalogSector extends AbstractSector
// -----------------------------------------------------------------------------------//
{
private static int CATALOG_ENTRY_SIZE = 32;
public CPMCatalogSector (Disk disk, byte[] buffer, DiskAddress diskAddress)
// ---------------------------------------------------------------------------------//
CPMCatalogSector (Disk disk, byte[] buffer, DiskAddress diskAddress)
// ---------------------------------------------------------------------------------//
{
super (disk, buffer, diskAddress);
}
// ---------------------------------------------------------------------------------//
@Override
public String createText ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = getHeader ("Catalog Sector");
@ -36,7 +42,7 @@ public class CPMCatalogSector extends AbstractSector
typeBuffer[2] = buffer[i + 11];
type = new String (typeBuffer).trim ();
extra = String.format (" (%s%s)", readOnly ? "read only" : "",
systemFile ? "system file" : "");
systemFile ? "system file" : "");
}
else
{

View File

@ -6,10 +6,17 @@ import java.util.List;
import javax.swing.tree.DefaultMutableTreeNode;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.disk.*;
import com.bytezone.diskbrowser.disk.AbstractFormattedDisk;
import com.bytezone.diskbrowser.disk.AppleDisk;
import com.bytezone.diskbrowser.disk.DefaultAppleFileSource;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.disk.SectorType;
import com.bytezone.diskbrowser.gui.DataSource;
// -----------------------------------------------------------------------------------//
public class CPMDisk extends AbstractFormattedDisk
// -----------------------------------------------------------------------------------//
{
private final Color green = new Color (0, 200, 0);
@ -27,7 +34,9 @@ public class CPMDisk extends AbstractFormattedDisk
// // http://www.seasip.info/Cpm/format31.html
private final DefaultMutableTreeNode volumeNode;
// ---------------------------------------------------------------------------------//
public CPMDisk (Disk disk)
// ---------------------------------------------------------------------------------//
{
super (disk);
@ -109,7 +118,9 @@ public class CPMDisk extends AbstractFormattedDisk
makeNodeVisible (volumeNode.getFirstLeaf ());
}
// ---------------------------------------------------------------------------------//
private SectorType getSectorType (String type)
// ---------------------------------------------------------------------------------//
{
if ("COM".equals (type))
return comSector;
@ -129,15 +140,19 @@ public class CPMDisk extends AbstractFormattedDisk
return otherSector;
}
// ---------------------------------------------------------------------------------//
@Override
public List<DiskAddress> getFileSectors (int fileNo)
// ---------------------------------------------------------------------------------//
{
if (fileEntries.size () > 0 && fileEntries.size () > fileNo)
return fileEntries.get (fileNo).getSectors ();
return null;
}
// ---------------------------------------------------------------------------------//
private DirectoryEntry findParent (DirectoryEntry child)
// ---------------------------------------------------------------------------------//
{
for (AppleFileSource entry : fileEntries)
if (((DirectoryEntry) entry).matches (child))
@ -146,8 +161,10 @@ public class CPMDisk extends AbstractFormattedDisk
return null;
}
// ---------------------------------------------------------------------------------//
@Override
public DataSource getFormattedSector (DiskAddress da)
// ---------------------------------------------------------------------------------//
{
SectorType type = sectorTypes[da.getBlock ()];
byte[] buffer = disk.readSector (da);
@ -158,8 +175,10 @@ public class CPMDisk extends AbstractFormattedDisk
return super.getFormattedSector (da);
}
// ---------------------------------------------------------------------------------//
@Override
public AppleFileSource getCatalog ()
// ---------------------------------------------------------------------------------//
{
String newLine = String.format ("%n");
String line =
@ -182,7 +201,9 @@ public class CPMDisk extends AbstractFormattedDisk
return new DefaultAppleFileSource ("CPM Disk ", text.toString (), this);
}
// ---------------------------------------------------------------------------------//
public static boolean isCorrectFormat (AppleDisk disk)
// ---------------------------------------------------------------------------------//
{
disk.setInterleave (3);
@ -227,7 +248,9 @@ public class CPMDisk extends AbstractFormattedDisk
return true;
}
// ---------------------------------------------------------------------------------//
private static boolean bufferContainsAll (byte[] buffer, byte value)
// ---------------------------------------------------------------------------------//
{
for (byte b : buffer)
if (b != value)
@ -235,8 +258,10 @@ public class CPMDisk extends AbstractFormattedDisk
return true;
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
StringBuffer text = new StringBuffer ("CPM disk");
return text.toString ();

View File

@ -14,7 +14,9 @@ import com.bytezone.diskbrowser.gui.DataSource;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// File Control Block (FCB)
public class DirectoryEntry implements AppleFileSource
// -----------------------------------------------------------------------------------//
class DirectoryEntry implements AppleFileSource
// -----------------------------------------------------------------------------------//
{
private final Disk disk;
private final CPMDisk parent;
@ -34,7 +36,9 @@ public class DirectoryEntry implements AppleFileSource
private final boolean readOnly;
private final boolean systemFile;
public DirectoryEntry (CPMDisk parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
DirectoryEntry (CPMDisk parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{
this.parent = parent;
disk = parent.getDisk ();
@ -75,18 +79,24 @@ public class DirectoryEntry implements AppleFileSource
}
}
public String getType ()
// ---------------------------------------------------------------------------------//
String getType ()
// ---------------------------------------------------------------------------------//
{
return type;
}
public boolean matches (DirectoryEntry directoryEntry)
// ---------------------------------------------------------------------------------//
boolean matches (DirectoryEntry directoryEntry)
// ---------------------------------------------------------------------------------//
{
return userNumber == directoryEntry.userNumber && name.equals (directoryEntry.name)
&& type.equals (directoryEntry.type);
}
public void add (DirectoryEntry entry)
// ---------------------------------------------------------------------------------//
void add (DirectoryEntry entry)
// ---------------------------------------------------------------------------------//
{
entries.add (entry);
@ -102,8 +112,10 @@ public class DirectoryEntry implements AppleFileSource
}
}
// ---------------------------------------------------------------------------------//
@Override
public boolean contains (DiskAddress da)
// ---------------------------------------------------------------------------------//
{
for (DiskAddress sector : blocks)
if (sector.matches (da))
@ -111,7 +123,9 @@ public class DirectoryEntry implements AppleFileSource
return false;
}
public String line ()
// ---------------------------------------------------------------------------------//
String line ()
// ---------------------------------------------------------------------------------//
{
String bytes = HexFormatter.getHexString (blockList, 0, 16);
bytes = bytes.replaceAll ("00", " ");
@ -131,7 +145,9 @@ public class DirectoryEntry implements AppleFileSource
return text;
}
public String toDetailedString ()
// ---------------------------------------------------------------------------------//
String toDetailedString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
@ -156,14 +172,18 @@ public class DirectoryEntry implements AppleFileSource
return text.toString ();
}
// ---------------------------------------------------------------------------------//
@Override
public String getUniqueName ()
// ---------------------------------------------------------------------------------//
{
return name + "." + type;
}
// ---------------------------------------------------------------------------------//
@Override
public DataSource getDataSource ()
// ---------------------------------------------------------------------------------//
{
if (appleFile != null)
return appleFile;
@ -208,20 +228,26 @@ public class DirectoryEntry implements AppleFileSource
return appleFile;
}
// ---------------------------------------------------------------------------------//
@Override
public List<DiskAddress> getSectors ()
// ---------------------------------------------------------------------------------//
{
return blocks;
}
// ---------------------------------------------------------------------------------//
@Override
public FormattedDisk getFormattedDisk ()
// ---------------------------------------------------------------------------------//
{
return parent;
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
return name + "." + type;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,129 +1,152 @@
package com.bytezone.diskbrowser.disk;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
import javax.swing.JPanel;
import com.bytezone.diskbrowser.applefile.AssemblerProgram;
import com.bytezone.diskbrowser.gui.DataSource;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public abstract class AbstractSector implements DataSource
{
private static String newLine = String.format ("%n");
private static String newLine2 = newLine + newLine;
final public byte[] buffer;
protected Disk disk;
protected DiskAddress diskAddress;
// private List<DiskAddress> diskAddressList;
AssemblerProgram assembler;
String description;
public AbstractSector (Disk disk, byte[] buffer, DiskAddress diskAddress)
{
this.buffer = buffer;
this.disk = disk;
this.diskAddress = diskAddress;
}
public AbstractSector (Disk disk, byte[] buffer)//, List<DiskAddress> diskAddressList)
{
this.buffer = buffer;
this.disk = disk;
// this.diskAddressList = diskAddressList;
}
@Override
public String getAssembler ()
{
if (assembler == null)
assembler = new AssemblerProgram ("noname", buffer, 0);
return assembler.getText ();
}
@Override
public String getHexDump ()
{
return HexFormatter.format (buffer, 0, buffer.length);
}
@Override
public BufferedImage getImage ()
{
return null;
}
@Override
public String getText ()
{
if (description == null)
description = createText ();
return description;
}
public abstract String createText ();
protected StringBuilder getHeader (String title)
{
StringBuilder text = new StringBuilder ();
text.append (title + newLine2);
text.append ("Offset Value Description" + newLine);
text.append ("======= =========== "
+ "===============================================================" + newLine);
return text;
}
@Override
public JComponent getComponent ()
{
JPanel panel = new JPanel ();
return panel;
}
protected void addText (StringBuilder text, byte[] buffer, int offset, int size,
String desc)
{
if ((offset + size - 1) > buffer.length)
return;
switch (size)
{
case 1:
text.append (String.format ("%03X %02X %s%n", offset,
buffer[offset], desc));
break;
case 2:
text.append (String.format ("%03X-%03X %02X %02X %s%n", offset,
offset + 1, buffer[offset], buffer[offset + 1], desc));
break;
case 3:
text.append (String.format ("%03X-%03X %02X %02X %02X %s%n", offset,
offset + 2, buffer[offset], buffer[offset + 1], buffer[offset + 2], desc));
break;
case 4:
text.append (String.format ("%03X-%03X %02X %02X %02X %02X %s%n", offset,
offset + 3, buffer[offset], buffer[offset + 1], buffer[offset + 2],
buffer[offset + 3], desc));
break;
default:
System.out.println ("Invalid length : " + size);
}
}
protected void addTextAndDecimal (StringBuilder text, byte[] b, int offset, int size,
String desc)
{
if (size == 1)
desc += " (" + (b[offset] & 0xFF) + ")";
else if (size == 2)
desc +=
String.format (" (%,d)", ((b[offset + 1] & 0xFF) * 256 + (b[offset] & 0xFF)));
else if (size == 3)
desc += String.format (" (%,d)", ((b[offset + 2] & 0xFF) * 65536)
+ ((b[offset + 1] & 0xFF) * 256) + (b[offset] & 0xFF));
addText (text, b, offset, size, desc);
}
package com.bytezone.diskbrowser.disk;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
import javax.swing.JPanel;
import com.bytezone.diskbrowser.applefile.AssemblerProgram;
import com.bytezone.diskbrowser.gui.DataSource;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public abstract class AbstractSector implements DataSource
// -----------------------------------------------------------------------------------//
{
private static String newLine = String.format ("%n");
private static String newLine2 = newLine + newLine;
final public byte[] buffer;
protected Disk disk;
protected DiskAddress diskAddress;
AssemblerProgram assembler;
String description;
// ---------------------------------------------------------------------------------//
public AbstractSector (Disk disk, byte[] buffer, DiskAddress diskAddress)
// ---------------------------------------------------------------------------------//
{
this.buffer = buffer;
this.disk = disk;
this.diskAddress = diskAddress;
}
// ---------------------------------------------------------------------------------//
public AbstractSector (Disk disk, byte[] buffer)
// ---------------------------------------------------------------------------------//
{
this.buffer = buffer;
this.disk = disk;
}
// ---------------------------------------------------------------------------------//
@Override
public String getAssembler ()
// ---------------------------------------------------------------------------------//
{
if (assembler == null)
assembler = new AssemblerProgram ("noname", buffer, 0);
return assembler.getText ();
}
// ---------------------------------------------------------------------------------//
@Override
public String getHexDump ()
// ---------------------------------------------------------------------------------//
{
return HexFormatter.format (buffer, 0, buffer.length);
}
// ---------------------------------------------------------------------------------//
@Override
public BufferedImage getImage ()
// ---------------------------------------------------------------------------------//
{
return null;
}
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
if (description == null)
description = createText ();
return description;
}
// ---------------------------------------------------------------------------------//
public abstract String createText ();
// ---------------------------------------------------------------------------------//
// ---------------------------------------------------------------------------------//
protected StringBuilder getHeader (String title)
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
text.append (title + newLine2);
text.append ("Offset Value Description" + newLine);
text.append ("======= =========== "
+ "===============================================================" + newLine);
return text;
}
// ---------------------------------------------------------------------------------//
@Override
public JComponent getComponent ()
// ---------------------------------------------------------------------------------//
{
JPanel panel = new JPanel ();
return panel;
}
// ---------------------------------------------------------------------------------//
protected void addText (StringBuilder text, byte[] buffer, int offset, int size,
String desc)
// ---------------------------------------------------------------------------------//
{
if ((offset + size - 1) > buffer.length)
return;
switch (size)
{
case 1:
text.append (String.format ("%03X %02X %s%n", offset,
buffer[offset], desc));
break;
case 2:
text.append (String.format ("%03X-%03X %02X %02X %s%n", offset,
offset + 1, buffer[offset], buffer[offset + 1], desc));
break;
case 3:
text.append (String.format ("%03X-%03X %02X %02X %02X %s%n", offset,
offset + 2, buffer[offset], buffer[offset + 1], buffer[offset + 2], desc));
break;
case 4:
text.append (String.format ("%03X-%03X %02X %02X %02X %02X %s%n", offset,
offset + 3, buffer[offset], buffer[offset + 1], buffer[offset + 2],
buffer[offset + 3], desc));
break;
default:
System.out.println ("Invalid length : " + size);
}
}
// ---------------------------------------------------------------------------------//
protected void addTextAndDecimal (StringBuilder text, byte[] b, int offset, int size,
String desc)
// ---------------------------------------------------------------------------------//
{
if (size == 1)
desc += " (" + (b[offset] & 0xFF) + ")";
else if (size == 2)
desc +=
String.format (" (%,d)", ((b[offset + 1] & 0xFF) * 256 + (b[offset] & 0xFF)));
else if (size == 3)
desc += String.format (" (%,d)", ((b[offset + 2] & 0xFF) * 65536)
+ ((b[offset + 1] & 0xFF) * 256) + (b[offset] & 0xFF));
addText (text, b, offset, size, desc);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,87 +1,109 @@
package com.bytezone.diskbrowser.disk;
public class AppleDiskAddress implements DiskAddress
{
private final int block;
private final int track;
private final int sector;
public final Disk owner;
private boolean zeroFlag;
public AppleDiskAddress (Disk owner, int block)
{
this.owner = owner;
this.block = block;
int sectorsPerTrack = owner.getSectorsPerTrack ();
if (sectorsPerTrack == 0)
{
track = 0;
sector = 0;
}
else
{
track = block / sectorsPerTrack;
sector = block % sectorsPerTrack;
}
}
public AppleDiskAddress (Disk owner, int track, int sector)
{
this.owner = owner;
zeroFlag = (track & 0x40) != 0;
this.track = track & 0x3F;
this.sector = sector & 0x1F;
this.block = this.track * owner.getSectorsPerTrack () + this.sector;
}
public boolean zeroFlag ()
{
return zeroFlag;
}
@Override
public int compareTo (DiskAddress that)
{
return this.block - that.getBlock ();
}
@Override
public boolean matches (DiskAddress that)
{
if (that == null)
return false;
return this.block == that.getBlock ();
}
@Override
public int getBlock ()
{
return block;
}
@Override
public int getSector ()
{
return sector;
}
@Override
public int getTrack ()
{
return track;
}
@Override
public Disk getDisk ()
{
return owner;
}
@Override
public String toString ()
{
return String.format ("[Block=%3d, Track=%2d, Sector=%2d, Zero=%s]", block, track,
sector, zeroFlag);
}
package com.bytezone.diskbrowser.disk;
// -----------------------------------------------------------------------------------//
public class AppleDiskAddress implements DiskAddress
// -----------------------------------------------------------------------------------//
{
private final int block;
private final int track;
private final int sector;
public final Disk owner;
private boolean zeroFlag;
// ---------------------------------------------------------------------------------//
public AppleDiskAddress (Disk owner, int block)
// ---------------------------------------------------------------------------------//
{
this.owner = owner;
this.block = block;
int sectorsPerTrack = owner.getSectorsPerTrack ();
if (sectorsPerTrack == 0)
{
track = 0;
sector = 0;
}
else
{
track = block / sectorsPerTrack;
sector = block % sectorsPerTrack;
}
}
// ---------------------------------------------------------------------------------//
public AppleDiskAddress (Disk owner, int track, int sector)
// ---------------------------------------------------------------------------------//
{
this.owner = owner;
zeroFlag = (track & 0x40) != 0;
this.track = track & 0x3F;
this.sector = sector & 0x1F;
this.block = this.track * owner.getSectorsPerTrack () + this.sector;
}
// ---------------------------------------------------------------------------------//
public boolean zeroFlag ()
// ---------------------------------------------------------------------------------//
{
return zeroFlag;
}
// ---------------------------------------------------------------------------------//
@Override
public int compareTo (DiskAddress that)
// ---------------------------------------------------------------------------------//
{
return this.block - that.getBlock ();
}
// ---------------------------------------------------------------------------------//
@Override
public boolean matches (DiskAddress that)
// ---------------------------------------------------------------------------------//
{
if (that == null)
return false;
return this.block == that.getBlock ();
}
// ---------------------------------------------------------------------------------//
@Override
public int getBlock ()
// ---------------------------------------------------------------------------------//
{
return block;
}
// ---------------------------------------------------------------------------------//
@Override
public int getSector ()
// ---------------------------------------------------------------------------------//
{
return sector;
}
// ---------------------------------------------------------------------------------//
@Override
public int getTrack ()
// ---------------------------------------------------------------------------------//
{
return track;
}
// ---------------------------------------------------------------------------------//
@Override
public Disk getDisk ()
// ---------------------------------------------------------------------------------//
{
return owner;
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
return String.format ("[Block=%3d, Track=%2d, Sector=%2d, Zero=%s]", block, track,
sector, zeroFlag);
}
}

View File

@ -1,53 +1,63 @@
package com.bytezone.diskbrowser.disk;
import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.gui.DataSource;
public class DataDisk extends AbstractFormattedDisk
{
// static final byte[] dos = { 0x01, (byte) 0xA5, 0x27, (byte) 0xC9, 0x09 };
// this should somehow tie in with the checksum from DiskFactory to determine
// whether it has a bootloader
public DataDisk (AppleDisk disk)
{
super (disk);
// byte[] buffer = disk.readSector (0, 0); // Boot sector
// boolean ok = true;
// for (int i = 0; i < dos.length; i++)
// if (buffer[i] != dos[i])
// {
// ok = false;
// break;
// }
// if (buffer[0] == 0x01)
// {
// bootSector = new BootSector (disk, buffer, "DOS");
// sectorTypesList.add (dosSector);
// sectorTypes[0] = dosSector;
// }
}
// no files on data disks
@Override
public List<DiskAddress> getFileSectors (int fileNo)
{
return new ArrayList<> ();
}
// no files on data disks
public DataSource getFile (int fileNo)
{
return null;
}
@Override
public String toString ()
{
return disk.toString ();
}
package com.bytezone.diskbrowser.disk;
import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.gui.DataSource;
// -----------------------------------------------------------------------------------//
public class DataDisk extends AbstractFormattedDisk
// -----------------------------------------------------------------------------------//
{
// static final byte[] dos = { 0x01, (byte) 0xA5, 0x27, (byte) 0xC9, 0x09 };
// this should somehow tie in with the checksum from DiskFactory to determine
// whether it has a bootloader
// ---------------------------------------------------------------------------------//
public DataDisk (AppleDisk disk)
// ---------------------------------------------------------------------------------//
{
super (disk);
// byte[] buffer = disk.readSector (0, 0); // Boot sector
// boolean ok = true;
// for (int i = 0; i < dos.length; i++)
// if (buffer[i] != dos[i])
// {
// ok = false;
// break;
// }
// if (buffer[0] == 0x01)
// {
// bootSector = new BootSector (disk, buffer, "DOS");
// sectorTypesList.add (dosSector);
// sectorTypes[0] = dosSector;
// }
}
// no files on data disks
// ---------------------------------------------------------------------------------//
@Override
public List<DiskAddress> getFileSectors (int fileNo)
// ---------------------------------------------------------------------------------//
{
return new ArrayList<> ();
}
// no files on data disks
// ---------------------------------------------------------------------------------//
public DataSource getFile (int fileNo)
// ---------------------------------------------------------------------------------//
{
return null;
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
return disk.toString ();
}
}

View File

@ -1,101 +1,125 @@
package com.bytezone.diskbrowser.disk;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.gui.DataSource;
/*
* Most AppleFileSource objects are CatalogEntry types. In order to allow Disk
* and Volume nodes in the tree to show some text in the centre panel, use a
* DefaultAppleFileSource which returns a DefaultDataSource (just some text).
*/
public class DefaultAppleFileSource implements AppleFileSource
{
final String title;
final DataSource file;
final FormattedDisk owner;
List<DiskAddress> blocks;
public DefaultAppleFileSource (String text, FormattedDisk owner)
{
this ("", text, owner);
}
public DefaultAppleFileSource (String title, String text, FormattedDisk owner)
{
this (title, new DefaultDataSource (text), owner);
}
public DefaultAppleFileSource (String title, DataSource file, FormattedDisk owner)
{
this.title = title;
this.file = file;
this.owner = owner;
}
public DefaultAppleFileSource (String title, DataSource file, FormattedDisk owner,
List<DiskAddress> blocks)
{
this (title, file, owner);
this.blocks = blocks;
if (file instanceof DefaultDataSource)
((DefaultDataSource) file).buffer = owner.getDisk ().readSectors (blocks);
}
public void setSectors (List<DiskAddress> blocks)
{
this.blocks = blocks;
if (file instanceof DefaultDataSource)
((DefaultDataSource) file).buffer = owner.getDisk ().readSectors (blocks);
}
@Override
public DataSource getDataSource ()
{
return file;
}
@Override
public FormattedDisk getFormattedDisk ()
{
return owner;
}
@Override
public List<DiskAddress> getSectors ()
{
return blocks;
}
/*
* See similar routine in CatalogPanel.DiskNode
*/
@Override
public String toString ()
{
final int MAX_NAME_LENGTH = 40;
final int SUFFIX_LENGTH = 12;
final int PREFIX_LENGTH = MAX_NAME_LENGTH - SUFFIX_LENGTH - 3;
if (title.length () > MAX_NAME_LENGTH)
return title.substring (0, PREFIX_LENGTH) + "..."
+ title.substring (title.length () - SUFFIX_LENGTH);
return title;
}
@Override
public String getUniqueName ()
{
return title;
}
@Override
public boolean contains (DiskAddress diskAddress)
{
for (DiskAddress da : blocks)
if (da.matches (diskAddress))
return true;
return false;
}
package com.bytezone.diskbrowser.disk;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.gui.DataSource;
/*
* Most AppleFileSource objects are CatalogEntry types. In order to allow Disk
* and Volume nodes in the tree to show some text in the centre panel, use a
* DefaultAppleFileSource which returns a DefaultDataSource (just some text).
*/
// -----------------------------------------------------------------------------------//
public class DefaultAppleFileSource implements AppleFileSource
// -----------------------------------------------------------------------------------//
{
final String title;
final DataSource file;
final FormattedDisk owner;
List<DiskAddress> blocks;
// ---------------------------------------------------------------------------------//
public DefaultAppleFileSource (String text, FormattedDisk owner)
// ---------------------------------------------------------------------------------//
{
this ("", text, owner);
}
// ---------------------------------------------------------------------------------//
public DefaultAppleFileSource (String title, String text, FormattedDisk owner)
// ---------------------------------------------------------------------------------//
{
this (title, new DefaultDataSource (text), owner);
}
// ---------------------------------------------------------------------------------//
public DefaultAppleFileSource (String title, DataSource file, FormattedDisk owner)
// ---------------------------------------------------------------------------------//
{
this.title = title;
this.file = file;
this.owner = owner;
}
// ---------------------------------------------------------------------------------//
public DefaultAppleFileSource (String title, DataSource file, FormattedDisk owner,
List<DiskAddress> blocks)
// ---------------------------------------------------------------------------------//
{
this (title, file, owner);
this.blocks = blocks;
if (file instanceof DefaultDataSource)
((DefaultDataSource) file).buffer = owner.getDisk ().readSectors (blocks);
}
// ---------------------------------------------------------------------------------//
public void setSectors (List<DiskAddress> blocks)
// ---------------------------------------------------------------------------------//
{
this.blocks = blocks;
if (file instanceof DefaultDataSource)
((DefaultDataSource) file).buffer = owner.getDisk ().readSectors (blocks);
}
// ---------------------------------------------------------------------------------//
@Override
public DataSource getDataSource ()
// ---------------------------------------------------------------------------------//
{
return file;
}
// ---------------------------------------------------------------------------------//
@Override
public FormattedDisk getFormattedDisk ()
// ---------------------------------------------------------------------------------//
{
return owner;
}
// ---------------------------------------------------------------------------------//
@Override
public List<DiskAddress> getSectors ()
// ---------------------------------------------------------------------------------//
{
return blocks;
}
/*
* See similar routine in CatalogPanel.DiskNode
*/
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
final int MAX_NAME_LENGTH = 40;
final int SUFFIX_LENGTH = 12;
final int PREFIX_LENGTH = MAX_NAME_LENGTH - SUFFIX_LENGTH - 3;
if (title.length () > MAX_NAME_LENGTH)
return title.substring (0, PREFIX_LENGTH) + "..."
+ title.substring (title.length () - SUFFIX_LENGTH);
return title;
}
// ---------------------------------------------------------------------------------//
@Override
public String getUniqueName ()
// ---------------------------------------------------------------------------------//
{
return title;
}
// ---------------------------------------------------------------------------------//
@Override
public boolean contains (DiskAddress diskAddress)
// ---------------------------------------------------------------------------------//
{
for (DiskAddress da : blocks)
if (da.matches (diskAddress))
return true;
return false;
}
}

View File

@ -1,49 +1,68 @@
package com.bytezone.diskbrowser.disk;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
import javax.swing.JPanel;
import com.bytezone.diskbrowser.gui.DataSource;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class DefaultDataSource implements DataSource
{
public String text;
byte[] buffer;
public DefaultDataSource (String text)
{
this.text = text;
}
public String getAssembler ()
{
return null;
}
public String getHexDump ()
{
if (buffer != null)
return HexFormatter.format (buffer, 0, buffer.length);
return null;
}
public BufferedImage getImage ()
{
return null;
}
public String getText ()
{
return text;
}
public JComponent getComponent ()
{
System.out.println ("In DefaultDataSource.getComponent()");
JPanel panel = new JPanel ();
return panel;
}
package com.bytezone.diskbrowser.disk;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
import javax.swing.JPanel;
import com.bytezone.diskbrowser.gui.DataSource;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class DefaultDataSource implements DataSource
// -----------------------------------------------------------------------------------//
{
public String text;
byte[] buffer;
// ---------------------------------------------------------------------------------//
public DefaultDataSource (String text)
// ---------------------------------------------------------------------------------//
{
this.text = text;
}
// ---------------------------------------------------------------------------------//
@Override
public String getAssembler ()
// ---------------------------------------------------------------------------------//
{
return null;
}
// ---------------------------------------------------------------------------------//
@Override
public String getHexDump ()
// ---------------------------------------------------------------------------------//
{
if (buffer != null)
return HexFormatter.format (buffer, 0, buffer.length);
return null;
}
// ---------------------------------------------------------------------------------//
@Override
public BufferedImage getImage ()
// ---------------------------------------------------------------------------------//
{
return null;
}
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
return text;
}
// ---------------------------------------------------------------------------------//
@Override
public JComponent getComponent ()
// ---------------------------------------------------------------------------------//
{
System.out.println ("In DefaultDataSource.getComponent()");
JPanel panel = new JPanel ();
return panel;
}
}

View File

@ -1,26 +1,34 @@
package com.bytezone.diskbrowser.disk;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class DefaultSector extends AbstractSector
{
String name;
public DefaultSector (String name, Disk disk, byte[] buffer, DiskAddress diskAddress)
{
super (disk, buffer, diskAddress);
this.name = name;
}
@Override
public String createText ()
{
return name + "\n\n" + HexFormatter.format (buffer, 0, buffer.length);
}
@Override
public String toString ()
{
return name;
}
}
package com.bytezone.diskbrowser.disk;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class DefaultSector extends AbstractSector
// -----------------------------------------------------------------------------------//
{
String name;
// ---------------------------------------------------------------------------------//
public DefaultSector (String name, Disk disk, byte[] buffer, DiskAddress diskAddress)
// ---------------------------------------------------------------------------------//
{
super (disk, buffer, diskAddress);
this.name = name;
}
// ---------------------------------------------------------------------------------//
@Override
public String createText ()
// ---------------------------------------------------------------------------------//
{
return name + "\n\n" + HexFormatter.format (buffer, 0, buffer.length);
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
return name;
}
}

View File

@ -1,62 +1,64 @@
package com.bytezone.diskbrowser.disk;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.List;
public interface Disk extends Iterable<DiskAddress>
{
public long getBootChecksum ();
public void setEmptyByte (byte value);
public int getTotalBlocks (); // blocks per disk - usually 560 or 280
public int getTotalTracks (); // usually 35
public int getBlockSize (); // bytes per block - 256 or 512
public void setBlockSize (int blockSize);
public int getTrackSize (); // bytes per track - 4096
public int getSectorsPerTrack (); // 8 or 16
public void setInterleave (int interleave);
public int getInterleave ();
public DiskAddress getDiskAddress (int block);
public List<DiskAddress> getDiskAddressList (int... blocks);
public DiskAddress getDiskAddress (int track, int sector);
public byte[] readSector (int block);
public byte[] readSector (int track, int sector);
public byte[] readSector (DiskAddress da);
public byte[] readSectors (List<DiskAddress> daList);
public void writeSector (DiskAddress da, byte[] buffer);
public boolean isSectorEmpty (int block);
public boolean isSectorEmpty (int track, int sector);
public boolean isSectorEmpty (DiskAddress da);
public boolean isValidAddress (int block);
public boolean isValidAddress (int track, int sector);
public boolean isValidAddress (DiskAddress da);
public File getFile ();
public void addActionListener (ActionListener listener);
public void removeActionListener (ActionListener listener);
package com.bytezone.diskbrowser.disk;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.List;
// -----------------------------------------------------------------------------------//
public interface Disk extends Iterable<DiskAddress>
// -----------------------------------------------------------------------------------//
{
public long getBootChecksum ();
public void setEmptyByte (byte value);
public int getTotalBlocks (); // blocks per disk - usually 560 or 280
public int getTotalTracks (); // usually 35
public int getBlockSize (); // bytes per block - 256 or 512
public void setBlockSize (int blockSize);
public int getTrackSize (); // bytes per track - 4096
public int getSectorsPerTrack (); // 8 or 16
public void setInterleave (int interleave);
public int getInterleave ();
public DiskAddress getDiskAddress (int block);
public List<DiskAddress> getDiskAddressList (int... blocks);
public DiskAddress getDiskAddress (int track, int sector);
public byte[] readSector (int block);
public byte[] readSector (int track, int sector);
public byte[] readSector (DiskAddress da);
public byte[] readSectors (List<DiskAddress> daList);
public void writeSector (DiskAddress da, byte[] buffer);
public boolean isSectorEmpty (int block);
public boolean isSectorEmpty (int track, int sector);
public boolean isSectorEmpty (DiskAddress da);
public boolean isValidAddress (int block);
public boolean isValidAddress (int track, int sector);
public boolean isValidAddress (DiskAddress da);
public File getFile ();
public void addActionListener (ActionListener listener);
public void removeActionListener (ActionListener listener);
}

View File

@ -1,14 +1,16 @@
package com.bytezone.diskbrowser.disk;
public interface DiskAddress extends Comparable<DiskAddress>
{
public int getBlock ();
public int getTrack ();
public int getSector ();
public Disk getDisk ();
public boolean matches (DiskAddress other);
package com.bytezone.diskbrowser.disk;
// -----------------------------------------------------------------------------------//
public interface DiskAddress extends Comparable<DiskAddress>
// -----------------------------------------------------------------------------------//
{
public int getBlock ();
public int getTrack ();
public int getSector ();
public Disk getDisk ();
public boolean matches (DiskAddress other);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,85 +1,87 @@
package com.bytezone.diskbrowser.disk;
import java.awt.Dimension;
import java.nio.file.Path;
import java.util.List;
import javax.swing.JTree;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.gui.DataSource;
public interface FormattedDisk
{
// Methods to be implemented by the implementer
public DataSource getFormattedSector (DiskAddress da);
public List<DiskAddress> getFileSectors (int fileNo);
// Methods implemented by AbstractFormattedDisk
public JTree getCatalogTree (); // each node is an AppleFileSource
public List<AppleFileSource> getCatalogList ();
public void writeFile (AbstractFile file);
public SectorType getSectorType (int track, int sector);
public SectorType getSectorType (int block);
public SectorType getSectorType (DiskAddress da);
public void setSectorType (int block, SectorType type);
public String getSectorFilename (DiskAddress da);
public List<SectorType> getSectorTypeList ();
public Disk getDisk ();
public FormattedDisk getParent ();
public void setParent (FormattedDisk disk);
public AppleFileSource getCatalog ();
public AppleFileSource getFile (String uniqueName);
public int clearOrphans ();
public void setSectorFree (int block, boolean free);
public boolean isSectorFree (DiskAddress da);
public boolean isSectorFree (int block);
public void verify ();
public boolean stillAvailable (DiskAddress da);
public boolean stillAvailable (int block);
public Dimension getGridLayout ();
public String getAbsolutePath ();
public String getDisplayPath ();
public void setOriginalPath (Path path);
public Path getOriginalPath ();
public boolean isTempDisk ();
// VTOC flags sector as free, but it is in use by a file
public int falsePositiveBlocks ();
// VTOC flags sector as in use, but no file is using it
public int falseNegativeBlocks ();
public String getName ();
}
// getFileTypeList ()
package com.bytezone.diskbrowser.disk;
import java.awt.Dimension;
import java.nio.file.Path;
import java.util.List;
import javax.swing.JTree;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.gui.DataSource;
// -----------------------------------------------------------------------------------//
public interface FormattedDisk
// -----------------------------------------------------------------------------------//
{
// Methods to be implemented by the implementer
public DataSource getFormattedSector (DiskAddress da);
public List<DiskAddress> getFileSectors (int fileNo);
// Methods implemented by AbstractFormattedDisk
public JTree getCatalogTree (); // each node is an AppleFileSource
public List<AppleFileSource> getCatalogList ();
public void writeFile (AbstractFile file);
public SectorType getSectorType (int track, int sector);
public SectorType getSectorType (int block);
public SectorType getSectorType (DiskAddress da);
public void setSectorType (int block, SectorType type);
public String getSectorFilename (DiskAddress da);
public List<SectorType> getSectorTypeList ();
public Disk getDisk ();
public FormattedDisk getParent ();
public void setParent (FormattedDisk disk);
public AppleFileSource getCatalog ();
public AppleFileSource getFile (String uniqueName);
public int clearOrphans ();
public void setSectorFree (int block, boolean free);
public boolean isSectorFree (DiskAddress da);
public boolean isSectorFree (int block);
public void verify ();
public boolean stillAvailable (DiskAddress da);
public boolean stillAvailable (int block);
public Dimension getGridLayout ();
public String getAbsolutePath ();
public String getDisplayPath ();
public void setOriginalPath (Path path);
public Path getOriginalPath ();
public boolean isTempDisk ();
// VTOC flags sector as free, but it is in use by a file
public int falsePositiveBlocks ();
// VTOC flags sector as in use, but no file is using it
public int falseNegativeBlocks ();
public String getName ();
}
// getFileTypeList ()
// getFiles (FileType type)

View File

@ -1,52 +1,58 @@
package com.bytezone.diskbrowser.disk;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AbstractFile;
public class SectorList extends AbstractFile
{
List<DiskAddress> sectors;
FormattedDisk formattedDisk;
public SectorList (FormattedDisk formattedDisk, List<DiskAddress> sectors)
{
super ("noname", null);
this.sectors = sectors;
this.formattedDisk = formattedDisk;
Disk disk = formattedDisk.getDisk ();
int ptr = 0;
buffer = new byte[sectors.size () * disk.getBlockSize ()];
for (DiskAddress da : sectors)
{
if (!disk.isValidAddress (da))
break;
byte[] tempBuffer = disk.readSector (da);
System.arraycopy (tempBuffer, 0, buffer, ptr, disk.getBlockSize ());
ptr += disk.getBlockSize ();
}
}
@Override
public String getText ()
{
StringBuilder text = new StringBuilder ("Block Sector Type Owner\n");
text.append (
"----- ------------------ ---------------------------------------------\n");
for (DiskAddress da : sectors)
{
SectorType sectorType = formattedDisk.getSectorType (da);
String owner = formattedDisk.getSectorFilename (da);
if (owner == null)
owner = "";
text.append (
String.format (" %04X %-18s %s%n", da.getBlock (), sectorType.name, owner));
}
return text.toString ();
}
package com.bytezone.diskbrowser.disk;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AbstractFile;
// -----------------------------------------------------------------------------------//
public class SectorList extends AbstractFile
// -----------------------------------------------------------------------------------//
{
List<DiskAddress> sectors;
FormattedDisk formattedDisk;
// ---------------------------------------------------------------------------------//
public SectorList (FormattedDisk formattedDisk, List<DiskAddress> sectors)
// ---------------------------------------------------------------------------------//
{
super ("noname", null);
this.sectors = sectors;
this.formattedDisk = formattedDisk;
Disk disk = formattedDisk.getDisk ();
int ptr = 0;
buffer = new byte[sectors.size () * disk.getBlockSize ()];
for (DiskAddress da : sectors)
{
if (!disk.isValidAddress (da))
break;
byte[] tempBuffer = disk.readSector (da);
System.arraycopy (tempBuffer, 0, buffer, ptr, disk.getBlockSize ());
ptr += disk.getBlockSize ();
}
}
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ("Block Sector Type Owner\n");
text.append (
"----- ------------------ ---------------------------------------------\n");
for (DiskAddress da : sectors)
{
SectorType sectorType = formattedDisk.getSectorType (da);
String owner = formattedDisk.getSectorFilename (da);
if (owner == null)
owner = "";
text.append (
String.format (" %04X %-18s %s%n", da.getBlock (), sectorType.name, owner));
}
return text.toString ();
}
}

View File

@ -3,12 +3,16 @@ package com.bytezone.diskbrowser.disk;
import java.util.ArrayList;
import java.util.List;
// -----------------------------------------------------------------------------------//
public class SectorListConverter
// -----------------------------------------------------------------------------------//
{
public final List<DiskAddress> sectors;
public final String sectorText;
// ---------------------------------------------------------------------------------//
public SectorListConverter (String text, Disk disk)
// ---------------------------------------------------------------------------------//
{
sectors = new ArrayList<> ();
sectorText = text;
@ -29,7 +33,9 @@ public class SectorListConverter
}
}
// ---------------------------------------------------------------------------------//
public SectorListConverter (List<DiskAddress> sectors)
// ---------------------------------------------------------------------------------//
{
this.sectors = sectors;
StringBuilder text = new StringBuilder ();
@ -55,7 +61,9 @@ public class SectorListConverter
sectorText = text.deleteCharAt (text.length () - 1).toString ();
}
// ---------------------------------------------------------------------------------//
private void addToText (StringBuilder text, int firstBlock, int runLength)
// ---------------------------------------------------------------------------------//
{
if (runLength == 0)
text.append (firstBlock + ";");

View File

@ -1,21 +1,27 @@
package com.bytezone.diskbrowser.disk;
import java.awt.Color;
public class SectorType
{
public final String name;
public final Color colour;
public SectorType (String name, Color colour)
{
this.name = name;
this.colour = colour;
}
@Override
public String toString ()
{
return String.format ("[SectorType : %s, %s]", name, colour);
}
package com.bytezone.diskbrowser.disk;
import java.awt.Color;
// -----------------------------------------------------------------------------------//
public class SectorType
// -----------------------------------------------------------------------------------//
{
public final String name;
public final Color colour;
// ---------------------------------------------------------------------------------//
public SectorType (String name, Color colour)
// ---------------------------------------------------------------------------------//
{
this.name = name;
this.colour = colour;
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
return String.format ("[SectorType : %s, %s]", name, colour);
}
}

View File

@ -3,17 +3,23 @@ package com.bytezone.diskbrowser.disk;
import java.util.ArrayList;
import java.util.List;
// -----------------------------------------------------------------------------------//
public class UnknownDisk extends AbstractFormattedDisk
// -----------------------------------------------------------------------------------//
{
// could arrange for the blocks to appear as a question mark
// ---------------------------------------------------------------------------------//
public UnknownDisk (AppleDisk disk)
// ---------------------------------------------------------------------------------//
{
super (disk);
}
// ---------------------------------------------------------------------------------//
@Override
public List<DiskAddress> getFileSectors (int fileNo)
// ---------------------------------------------------------------------------------//
{
return new ArrayList<> ();
}