added isZero() and Selector

This commit is contained in:
Denis Molony 2020-05-10 21:28:01 +10:00
parent 0b032b13f5
commit 96c49fc61d
13 changed files with 521 additions and 387 deletions

View File

@ -0,0 +1,111 @@
package com.bytezone.diskbrowser.applefile;
import java.util.ArrayList;
import java.util.List;
// -----------------------------------------------------------------------------------//
public class Selector extends AbstractFile
// -----------------------------------------------------------------------------------//
{
int numRunListEntries;
int numOtherRunListEntries;
List<Entry> entries = new ArrayList<> ();
List<Path> paths = new ArrayList<> ();
// ---------------------------------------------------------------------------------//
public Selector (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{
super (name, buffer);
numRunListEntries = buffer[0] & 0xFF;
numOtherRunListEntries = buffer[1] & 0xFF;
int ptr = 2;
for (int i = 0; i < 24; i++)
{
entries.add (new Entry (buffer, ptr));
ptr += 16;
}
ptr = 386;
for (int i = 0; i < 24; i++)
{
paths.add (new Path (buffer, ptr));
ptr += 64;
}
}
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
text.append ("Name : " + name + "\n");
text.append (String.format ("Length : $%04X (%<,d)%n%n", buffer.length));
text.append (String.format ("NumRunListEntries ....... %d%n", buffer[0]));
text.append (String.format ("NumOtherRunListEntries .. %d%n%n", buffer[1]));
text.append ("Name Copy Path\n");
text.append ("-------------- ---------- ------------------------------------\n");
for (int i = 0; i < entries.size (); i++)
{
Entry entry = entries.get (i);
Path path = paths.get (i);
if (entry.labelLength > 0)
text.append (String.format ("%-14s %-10s %s%n", entry.label, entry.copyText,
path.pathName));
}
return text.toString ();
}
// ---------------------------------------------------------------------------------//
class Entry
// ---------------------------------------------------------------------------------//
{
int labelLength;
String label;
byte copyFlags;
String copyText;
public Entry (byte[] buffer, int ptr)
{
labelLength = buffer[ptr] & 0xFF;
label = new String (buffer, ptr + 1, labelLength);
copyFlags = buffer[ptr + 15];
switch (copyFlags & 0xFF)
{
case 0:
copyText = "First boot";
break;
case 0x80:
copyText = "First use";
break;
case 0xC0:
copyText = "Never";
break;
default:
copyText = "Unknown";
break;
}
}
}
// ---------------------------------------------------------------------------------//
class Path
// ---------------------------------------------------------------------------------//
{
int length;
String pathName;
public Path (byte[] buffer, int ptr)
{
length = buffer[ptr] & 0xFF;
pathName = new String (buffer, ptr + 1, length);
}
}
}

View File

@ -233,7 +233,7 @@ public class CPMDisk extends AbstractFormattedDisk
if (val == 0xE5) if (val == 0xE5)
break; break;
if (val > 31) // && val != 0xE5) if (val > 31)
return false; return false;
for (int j = 1; j <= 8; j++) for (int j = 1; j <= 8; j++)
@ -259,11 +259,11 @@ public class CPMDisk extends AbstractFormattedDisk
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@Override // @Override
public String toString () // public String toString ()
// ---------------------------------------------------------------------------------// // // ---------------------------------------------------------------------------------//
{ // {
StringBuffer text = new StringBuffer ("CPM disk"); // StringBuffer text = new StringBuffer ("CPM disk");
return text.toString (); // return text.toString ();
} // }
} }

View File

@ -394,7 +394,7 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
public DataSource getFormattedSector (DiskAddress da) public DataSource getFormattedSector (DiskAddress da)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (da.getBlockNo () == 0 && bootSector != null) if (da.isZero () && bootSector != null)
return bootSector; return bootSector;
SectorType sectorType = sectorTypes[da.getBlockNo ()]; SectorType sectorType = sectorTypes[da.getBlockNo ()];
@ -564,6 +564,7 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
text.append (String.format ("Disk name ............. %s%n", getDisplayPath ()));
text.append (String.format ("Block size..... %d%n", disk.getBlockSize ())); text.append (String.format ("Block size..... %d%n", disk.getBlockSize ()));
text.append (String.format ("Interleave..... %d", disk.getInterleave ())); text.append (String.format ("Interleave..... %d", disk.getInterleave ()));
return text.toString (); return text.toString ();

View File

@ -113,6 +113,7 @@ public class AppleDisk implements Disk
if ("2mg".equalsIgnoreCase (suffix) || "2IMG".equals (prefix)) if ("2mg".equalsIgnoreCase (suffix) || "2IMG".equals (prefix))
{ {
// System.out.println ("checking 2mg");
if ("2IMG".equals (prefix)) if ("2IMG".equals (prefix))
{ {
Prefix2mg prefix2mg = new Prefix2mg (buffer); Prefix2mg prefix2mg = new Prefix2mg (buffer);

View File

@ -66,6 +66,14 @@ public class AppleDiskAddress implements DiskAddress
return this.block == that.getBlockNo (); return this.block == that.getBlockNo ();
} }
// ---------------------------------------------------------------------------------//
@Override
public boolean isZero ()
// ---------------------------------------------------------------------------------//
{
return block == 0;
}
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@Override @Override
public int getBlockNo () public int getBlockNo ()

View File

@ -10,6 +10,8 @@ public interface DiskAddress extends Comparable<DiskAddress>
public int getSectorNo (); public int getSectorNo ();
public boolean isZero ();
public Disk getDisk (); public Disk getDisk ();
public boolean matches (DiskAddress other); public boolean matches (DiskAddress other);

View File

@ -137,7 +137,11 @@ public class DualDosDisk implements FormattedDisk
else if (disks[1] == fd) else if (disks[1] == fd)
currentDisk = 1; currentDisk = 1;
else else
{
// this happens when the top-level folder is selected (i.e. neither disk)
System.out.println ("Disk not found: " + fd); System.out.println ("Disk not found: " + fd);
// Utility.printStackTrace ();
}
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//

View File

@ -17,7 +17,7 @@ class CatalogEntry extends AbstractCatalogEntry
CatalogEntry (DosDisk dosDisk, DiskAddress catalogSector, byte[] entryBuffer) CatalogEntry (DosDisk dosDisk, DiskAddress catalogSector, byte[] entryBuffer)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
super (dosDisk, catalogSector, entryBuffer); // build lists of ts and data sectors super (dosDisk, catalogSector, entryBuffer);
// if (reportedSize > 0 && disk.isValidAddress (entryBuffer[0], entryBuffer[1])) // if (reportedSize > 0 && disk.isValidAddress (entryBuffer[0], entryBuffer[1]))
if (disk.isValidAddress (entryBuffer[0], entryBuffer[1])) if (disk.isValidAddress (entryBuffer[0], entryBuffer[1]))
@ -26,7 +26,7 @@ class CatalogEntry extends AbstractCatalogEntry
DiskAddress da = disk.getDiskAddress (entryBuffer[0], entryBuffer[1]); DiskAddress da = disk.getDiskAddress (entryBuffer[0], entryBuffer[1]);
// Loop through all TS-list sectors // Loop through all TS-list sectors
loop: while (da.getBlockNo () > 0 || ((AppleDiskAddress) da).zeroFlag ()) loop: while (!da.isZero () || ((AppleDiskAddress) da).zeroFlag ())
{ {
if (dosDisk.stillAvailable (da)) if (dosDisk.stillAvailable (da))
{ {
@ -70,7 +70,7 @@ class CatalogEntry extends AbstractCatalogEntry
i, sectorBuffer[i], sectorBuffer[i + 1], name.trim ()); i, sectorBuffer[i], sectorBuffer[i + 1], name.trim ());
break loop; break loop;
} }
if (da.getBlockNo () == 0 && !((AppleDiskAddress) da).zeroFlag ()) if (da.isZero () && !((AppleDiskAddress) da).zeroFlag ())
{ {
if (fileType != FileType.Text) if (fileType != FileType.Text)
break; break;
@ -151,7 +151,8 @@ class CatalogEntry extends AbstractCatalogEntry
return false; return false;
if (buffer[3] != 0 || buffer[4] != 0) // not supposed to be used if (buffer[3] != 0 || buffer[4] != 0) // not supposed to be used
// Diags2E.dsk stores its own sector address here // Diags2E.dsk stores its own sector address here
if (da.getTrackNo () != (buffer[3] & 0xFF) && da.getSectorNo () != (buffer[4] & 0xFF)) if (da.getTrackNo () != (buffer[3] & 0xFF)
&& da.getSectorNo () != (buffer[4] & 0xFF))
return false; return false;
return true; return true;
@ -175,9 +176,9 @@ class CatalogEntry extends AbstractCatalogEntry
if (dataSectors.size () == 0) if (dataSectors.size () == 0)
message += "No data "; message += "No data ";
String catName = catalogName.length () >= 8 ? catalogName.substring (7) : catalogName; // String catName = catalogName.length () >= 8 ? catalogName.substring (7) : catalogName;
String text = String.format ("%1s %1s %03d %-30.30s %-5s %-13s %3d %3d %s", String text = String.format ("%1s %1s %03d %-30.30s %-5s %-13s %3d %3d %s",
lockedFlag, getFileType (), actualSize, catName, addressText, lengthText, lockedFlag, getFileType (), actualSize, catalogName, addressText, lengthText,
tsSectors.size (), (dataSectors.size () - textFileGaps), message.trim ()); tsSectors.size (), (dataSectors.size () - textFileGaps), message.trim ());
if (actualSize == 0) if (actualSize == 0)
text = text.substring (0, 50); text = text.substring (0, 50);

View File

@ -51,7 +51,7 @@ class DeletedCatalogEntry extends AbstractCatalogEntry
} }
// Loop through all TS-list sectors // Loop through all TS-list sectors
loop: while (da.getBlockNo () > 0 || ((AppleDiskAddress) da).zeroFlag ()) loop: while (!da.isZero () || ((AppleDiskAddress) da).zeroFlag ())
{ {
if (!dosDisk.stillAvailable (da)) if (!dosDisk.stillAvailable (da))
{ {
@ -67,10 +67,10 @@ class DeletedCatalogEntry extends AbstractCatalogEntry
da = getValidAddress (sectorBuffer, i); da = getValidAddress (sectorBuffer, i);
if (da == null) if (da == null)
break loop; break loop;
if (da.getBlockNo () > 0 && debug) if (!da.isZero () && debug)
System.out.println (da); System.out.println (da);
if (da.getBlockNo () > 0 || ((AppleDiskAddress) da).zeroFlag ()) if (!da.isZero () || ((AppleDiskAddress) da).zeroFlag ())
{ {
if (!dosDisk.stillAvailable (da)) if (!dosDisk.stillAvailable (da))
{ {

View File

@ -132,7 +132,7 @@ public class DosDisk extends AbstractFormattedDisk
da = disk.getDiskAddress (track, sector); da = disk.getDiskAddress (track, sector);
} while (da.getBlockNo () != 0); } while (!da.isZero ());
// same loop, but now all the catalog sectors are properly flagged // same loop, but now all the catalog sectors are properly flagged
da = disk.getDiskAddress (catalogStart.getBlockNo ()); da = disk.getDiskAddress (catalogStart.getBlockNo ());
@ -149,15 +149,15 @@ public class DosDisk extends AbstractFormattedDisk
if (sectorBuffer[ptr] == 0) // empty slot, no more catalog entries if (sectorBuffer[ptr] == 0) // empty slot, no more catalog entries
continue; continue;
byte[] entry = new byte[ENTRY_SIZE]; byte[] entryBuffer = new byte[ENTRY_SIZE];
System.arraycopy (sectorBuffer, ptr, entry, 0, ENTRY_SIZE); System.arraycopy (sectorBuffer, ptr, entryBuffer, 0, ENTRY_SIZE);
int track = entry[0] & 0xFF; int track = entryBuffer[0] & 0xFF;
boolean deletedFlag = (entry[0] & 0x80) != 0; boolean deletedFlag = (entryBuffer[0] & 0x80) != 0;
if (deletedFlag) // deleted file if (deletedFlag) // deleted file
{ {
DeletedCatalogEntry deletedCatalogEntry = DeletedCatalogEntry deletedCatalogEntry =
new DeletedCatalogEntry (this, da, entry, dosVTOCSector.dosVersion); new DeletedCatalogEntry (this, da, entryBuffer, dosVTOCSector.dosVersion);
deletedFileEntries.add (deletedCatalogEntry); deletedFileEntries.add (deletedCatalogEntry);
DefaultMutableTreeNode node = new DefaultMutableTreeNode (deletedCatalogEntry); DefaultMutableTreeNode node = new DefaultMutableTreeNode (deletedCatalogEntry);
node.setAllowsChildren (false); node.setAllowsChildren (false);
@ -165,7 +165,7 @@ public class DosDisk extends AbstractFormattedDisk
} }
else else
{ {
CatalogEntry catalogEntry = new CatalogEntry (this, da, entry); CatalogEntry catalogEntry = new CatalogEntry (this, da, entryBuffer);
fileEntries.add (catalogEntry); fileEntries.add (catalogEntry);
DefaultMutableTreeNode node = new DefaultMutableTreeNode (catalogEntry); DefaultMutableTreeNode node = new DefaultMutableTreeNode (catalogEntry);
node.setAllowsChildren (false); node.setAllowsChildren (false);
@ -186,7 +186,7 @@ public class DosDisk extends AbstractFormattedDisk
da = disk.getDiskAddress (sectorBuffer[1], sectorBuffer[2]); da = disk.getDiskAddress (sectorBuffer[1], sectorBuffer[2]);
} while (da.getBlockNo () != 0); } while (!da.isZero ());
// link double hi-res files // link double hi-res files
for (AppleFileSource fe : fileEntries) for (AppleFileSource fe : fileEntries)
@ -426,7 +426,7 @@ public class DosDisk extends AbstractFormattedDisk
da = disk.getDiskAddress (buffer[1], buffer[2]); da = disk.getDiskAddress (buffer[1], buffer[2]);
} while (da.getBlockNo () != 0); } while (!da.isZero ());
if (debug) if (debug)
System.out.printf ("Catalog blocks: %d%n", catalogAddresses.size ()); System.out.printf ("Catalog blocks: %d%n", catalogAddresses.size ());
@ -469,7 +469,7 @@ public class DosDisk extends AbstractFormattedDisk
SectorType type = sectorTypes[da.getBlockNo ()]; SectorType type = sectorTypes[da.getBlockNo ()];
if (type == vtocSector) if (type == vtocSector)
return dosVTOCSector; return dosVTOCSector;
if (da.getBlockNo () == 0) if (da.isZero ())
return bootSector; return bootSector;
byte[] buffer = disk.readBlock (da); byte[] buffer = disk.readBlock (da);

View File

@ -26,6 +26,7 @@ import com.bytezone.diskbrowser.applefile.OriginalHiResImage;
import com.bytezone.diskbrowser.applefile.QuickDrawFont; import com.bytezone.diskbrowser.applefile.QuickDrawFont;
import com.bytezone.diskbrowser.applefile.SHRPictureFile1; import com.bytezone.diskbrowser.applefile.SHRPictureFile1;
import com.bytezone.diskbrowser.applefile.SHRPictureFile2; import com.bytezone.diskbrowser.applefile.SHRPictureFile2;
import com.bytezone.diskbrowser.applefile.Selector;
import com.bytezone.diskbrowser.applefile.ShapeTable; import com.bytezone.diskbrowser.applefile.ShapeTable;
import com.bytezone.diskbrowser.applefile.SimpleText; import com.bytezone.diskbrowser.applefile.SimpleText;
import com.bytezone.diskbrowser.applefile.StoredVariables; import com.bytezone.diskbrowser.applefile.StoredVariables;
@ -268,12 +269,17 @@ class FileEntry extends CatalogEntry implements ProdosConstants
{ {
switch (fileType) switch (fileType)
{ {
case FILE_TYPE_USER_DEFINED_1: // OVL case FILE_TYPE_OVL:
if (endOfFile == 0x2000 && auxType == 0) if (endOfFile == 0x2000 && auxType == 0)
{ {
file = new OriginalHiResImage (name, exactBuffer, auxType); file = new OriginalHiResImage (name, exactBuffer, auxType);
break; break;
} }
else if (endOfFile == 0x800 && "SELECTOR.LIST".equals (name))
{
file = new Selector (name, exactBuffer);
break;
}
// drop through // drop through
case FILE_TYPE_BINARY: case FILE_TYPE_BINARY:
case FILE_TYPE_RELOCATABLE: case FILE_TYPE_RELOCATABLE:

View File

@ -34,7 +34,7 @@ public interface ProdosConstants
static int FILE_TYPE_ICN = 0xCA; static int FILE_TYPE_ICN = 0xCA;
static int FILE_TYPE_APPLETALK = 0xE2; static int FILE_TYPE_APPLETALK = 0xE2;
static int FILE_TYPE_PASCAL_VOLUME = 0xEF; static int FILE_TYPE_PASCAL_VOLUME = 0xEF;
static int FILE_TYPE_USER_DEFINED_1 = 0xF1; // OVL static int FILE_TYPE_OVL = 0xF1;
static int FILE_TYPE_BAT = 0xF5; static int FILE_TYPE_BAT = 0xF5;
static int FILE_TYPE_INTEGER_BASIC = 0xFA; static int FILE_TYPE_INTEGER_BASIC = 0xFA;
static int FILE_TYPE_INTEGER_BASIC_VARS = 0xFB; static int FILE_TYPE_INTEGER_BASIC_VARS = 0xFB;

View File

@ -152,12 +152,12 @@ public class ProdosDisk extends AbstractFormattedDisk
break; break;
case ProdosConstants.SUBDIRECTORY: case ProdosConstants.SUBDIRECTORY:
FileEntry ce = new FileEntry (this, entry, localHeader, block); FileEntry fileEntry = new FileEntry (this, entry, localHeader, block);
fileEntries.add (ce); fileEntries.add (fileEntry);
DefaultMutableTreeNode directoryNode = new DefaultMutableTreeNode (ce); DefaultMutableTreeNode directoryNode = new DefaultMutableTreeNode (fileEntry);
directoryNode.setAllowsChildren (true); directoryNode.setAllowsChildren (true);
parentNode.add (directoryNode); parentNode.add (directoryNode);
processDirectoryBlock (ce.keyPtr, ce, directoryNode); // Recursion !! processDirectoryBlock (fileEntry.keyPtr, fileEntry, directoryNode); // Recursion!!
break; break;
case ProdosConstants.SEEDLING: case ProdosConstants.SEEDLING:
@ -165,9 +165,9 @@ public class ProdosDisk extends AbstractFormattedDisk
case ProdosConstants.TREE: case ProdosConstants.TREE:
case ProdosConstants.PASCAL_ON_PROFILE: case ProdosConstants.PASCAL_ON_PROFILE:
case ProdosConstants.GSOS_EXTENDED_FILE: case ProdosConstants.GSOS_EXTENDED_FILE:
FileEntry fe = new FileEntry (this, entry, localHeader, block); fileEntry = new FileEntry (this, entry, localHeader, block);
fileEntries.add (fe); fileEntries.add (fileEntry);
DefaultMutableTreeNode node = new DefaultMutableTreeNode (fe); DefaultMutableTreeNode node = new DefaultMutableTreeNode (fileEntry);
node.setAllowsChildren (false); node.setAllowsChildren (false);
parentNode.add (node); parentNode.add (node);
break; break;
@ -271,7 +271,7 @@ public class ProdosDisk extends AbstractFormattedDisk
public DataSource getFormattedSector (DiskAddress da) public DataSource getFormattedSector (DiskAddress da)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (da.getBlockNo () == 0) if (da.isZero ())
return bootSector; return bootSector;
byte[] buffer = disk.readBlock (da); byte[] buffer = disk.readBlock (da);