mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-09-08 05:54:45 +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);
|
||||
|
||||
|
@ -50,9 +50,9 @@ public class AppleDisk implements Disk
|
||||
private static int[][] interleaveSector = //
|
||||
{ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
|
||||
22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }, // None
|
||||
{ 0, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15 }, // Prodos/Pascal
|
||||
{ 0, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2, 15 }, // Infocom
|
||||
{ 0, 6, 12, 3, 9, 15, 14, 5, 11, 2, 8, 7, 13, 4, 10, 1 } }; // CPM
|
||||
{ 0, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15 }, // Prodos/Pascal
|
||||
{ 0, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2, 15 }, // Infocom
|
||||
{ 0, 6, 12, 3, 9, 15, 14, 5, 11, 2, 8, 7, 13, 4, 10, 1 } }; // CPM
|
||||
|
||||
// Physical disk interleave:
|
||||
// Info from http://www.applelogic.org/TheAppleIIEGettingStarted.html
|
||||
@ -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…
Reference in New Issue
Block a user