mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-01-14 23:30:17 +00:00
better CP/M format checker
This commit is contained in:
parent
5f29cfcd09
commit
26316a82a9
@ -1,6 +1,7 @@
|
||||
package com.bytezone.diskbrowser.cpm;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
@ -211,6 +212,60 @@ public class CPMDisk extends AbstractFormattedDisk
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public static boolean isCorrectFormat (AppleDisk disk)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
boolean debug = false;
|
||||
|
||||
disk.setInterleave (3);
|
||||
|
||||
// collect catalog sectors
|
||||
List<DiskAddress> catalog = new ArrayList<> ();
|
||||
for (int i = 0; i < 8; i++)
|
||||
catalog.add (disk.getDiskAddress (3, i));
|
||||
byte[] buffer = disk.readBlocks (catalog);
|
||||
|
||||
if (debug)
|
||||
System.out.println (HexFormatter.format (buffer));
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
int start = i * 1024;
|
||||
int end = start + 1024;
|
||||
|
||||
for (int ptr = start; ptr < end; ptr += 32)
|
||||
{
|
||||
if (buffer[ptr] == (byte) EMPTY_BYTE_VALUE)
|
||||
{
|
||||
if (buffer[ptr + 1] == (byte) EMPTY_BYTE_VALUE) // finished this block
|
||||
break;
|
||||
continue; // deleted file?
|
||||
}
|
||||
|
||||
int userNo = buffer[ptr] & 0xFF;
|
||||
if (userNo > 31)
|
||||
return false;
|
||||
|
||||
for (int j = 1; j < 12; j++)
|
||||
{
|
||||
int ch = buffer[ptr + j] & 0xFF;
|
||||
if (ch < 32 || ch > 126) // invalid ascii
|
||||
return false;
|
||||
}
|
||||
|
||||
if (debug)
|
||||
{
|
||||
String fileName = new String (buffer, ptr + 1, 8);
|
||||
String fileType = new String (buffer, ptr + 9, 3);
|
||||
System.out.printf ("%2d %s %s%n", userNo, fileName, fileType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private static boolean isCorrectFormat2 (AppleDisk disk)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
disk.setInterleave (3);
|
||||
|
||||
|
@ -468,6 +468,7 @@ public class AppleDisk implements Disk
|
||||
readBuffer (da, buffer, ptr);
|
||||
ptr += sectorSize;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -556,6 +556,9 @@ public class DiskFactory
|
||||
if (disk == null)
|
||||
disk = checkPascalDisk (appleDisk512);
|
||||
|
||||
if (disk == null)
|
||||
disk = checkCPMDisk (appleDisk256);
|
||||
|
||||
if (disk == null)
|
||||
{
|
||||
disk2 = checkInfocomDisk (appleDisk256);
|
||||
@ -563,9 +566,6 @@ public class DiskFactory
|
||||
disk = disk2;
|
||||
}
|
||||
|
||||
if (disk == null)
|
||||
disk = checkCPMDisk (appleDisk256); // checks almost nothing
|
||||
|
||||
if (disk == null)
|
||||
disk = new DataDisk (appleDisk256);
|
||||
|
||||
|
@ -57,9 +57,7 @@ class ZObject extends AbstractFile implements Comparable<ZObject>
|
||||
propertyTablePtr = header.getWord (offset + 7);
|
||||
int ptr = propertyTablePtr;
|
||||
int nameLength = header.getByte (ptr) * 2;
|
||||
System.out.printf ("was %s%n", this.getName ());
|
||||
setName (nameLength == 0 ? "<<" + id + ">>" : new ZString (header, ++ptr).value);
|
||||
System.out.printf ("now %s%n", this.getName ());
|
||||
ptr += nameLength;
|
||||
|
||||
// read each property
|
||||
|
Loading…
x
Reference in New Issue
Block a user