mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2026-04-20 03:16:37 +00:00
Early draft of new Apple Pascal detection.
This commit is contained in:
@@ -48,6 +48,7 @@ import java.io.PrintStream;
|
||||
|
||||
import com.webcodepro.applecommander.storage.*;
|
||||
import com.webcodepro.applecommander.storage.os.dos33.DosDiskFactory;
|
||||
import com.webcodepro.applecommander.storage.os.pascal.PascalDiskFactory;
|
||||
import com.webcodepro.applecommander.storage.os.prodos.ProdosDiskFactory;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Task;
|
||||
@@ -64,7 +65,7 @@ public class AntTask extends Task
|
||||
// Issue was verified by creating a simple (and separate) Main class and then doing a source identification.
|
||||
Sources.setFactories(new FileSource.Factory(), new UniversalDiskImage.Factory(), new DiskCopyImage.Factory(),
|
||||
new FileEntrySource.Factory(), new ShrinkitSourceFactory());
|
||||
Disks.setFactories(new DosDiskFactory(), new ProdosDiskFactory());
|
||||
Disks.setFactories(new DosDiskFactory(), new PascalDiskFactory(), new ProdosDiskFactory());
|
||||
}
|
||||
|
||||
public void execute() throws BuildException
|
||||
|
||||
@@ -324,9 +324,6 @@ public class Disk {
|
||||
if (isNakedosFormat()) {
|
||||
return new FormattedDisk[]
|
||||
{ new NakedosFormatDisk(filename, imageOrder) };
|
||||
} else if (isPascalFormat()) {
|
||||
return new FormattedDisk[]
|
||||
{ new PascalFormatDisk(filename, imageOrder) };
|
||||
} else if (isRdosFormat()) {
|
||||
return new FormattedDisk[]
|
||||
{ new RdosFormatDisk(filename, imageOrder) };
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.webcodepro.applecommander.storage.os.pascal;
|
||||
|
||||
import com.webcodepro.applecommander.storage.Disk;
|
||||
import com.webcodepro.applecommander.storage.DiskFactory;
|
||||
import com.webcodepro.applecommander.storage.physical.ImageOrder;
|
||||
import org.applecommander.util.DataBuffer;
|
||||
|
||||
/**
|
||||
* Automatic discovery of Pascal volumes.
|
||||
*/
|
||||
public class PascalDiskFactory implements DiskFactory {
|
||||
@Override
|
||||
public void inspect(Context ctx) {
|
||||
ctx.orders.forEach(order -> {
|
||||
if (check(order)) {
|
||||
ctx.disks.add(new PascalFormatDisk(order.getName(), order));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Check for a likely directory structure. Note that we scan all sizes, even though that is overkill. */
|
||||
public boolean check(ImageOrder order) {
|
||||
boolean good = false;
|
||||
if (order.getPhysicalSize() >= Disk.APPLE_140KB_DISK) {
|
||||
// Read entire directory for analysis
|
||||
DataBuffer dir = DataBuffer.create(2048);
|
||||
for (int block=2; block<6; block++) {
|
||||
byte[] data = order.readBlock(block);
|
||||
dir.put((block-2)*Disk.BLOCK_SIZE, DataBuffer.wrap(data));
|
||||
}
|
||||
// Check volume entry
|
||||
int dFirstBlock = dir.getUnsignedShort(0);
|
||||
int dLastBlock = dir.getUnsignedShort(2);
|
||||
int dEntryType = dir.getUnsignedShort(4);
|
||||
int dNameLength = dir.getUnsignedByte(6);
|
||||
int dBlocksOnDisk = dir.getUnsignedShort(14);
|
||||
int dFilesOnDisk = dir.getUnsignedShort(16);
|
||||
int dZeroBlock = dir.getUnsignedShort(18);
|
||||
good = dFirstBlock == 0 && dLastBlock == 6 && dEntryType == 0
|
||||
&& (dNameLength > 0 && dNameLength < 8)
|
||||
&& dFilesOnDisk < 78
|
||||
&& dBlocksOnDisk >= 280 && dZeroBlock == 0;
|
||||
// Check (any) existing file entries
|
||||
int offset = 26;
|
||||
while (good && offset < dir.limit()) {
|
||||
int fFirstBlock = dir.getUnsignedShort(offset);
|
||||
int fLastBlock = dir.getUnsignedShort(offset+2);
|
||||
int fEntryType = dir.getUnsignedShort(offset+4);
|
||||
int fNameLength = dir.getUnsignedByte(offset+6);
|
||||
int fBytesLastBlock = dir.getUnsignedShort(offset+22);
|
||||
if (fNameLength == 0) break; // last entry?
|
||||
good = fFirstBlock < fLastBlock
|
||||
&& fLastBlock <= dBlocksOnDisk
|
||||
&& fEntryType < 9
|
||||
&& fNameLength < 16
|
||||
&& fBytesLastBlock <= 512;
|
||||
offset += 26;
|
||||
dFilesOnDisk--;
|
||||
if (dFilesOnDisk == 0) break;
|
||||
}
|
||||
}
|
||||
return good;
|
||||
}
|
||||
}
|
||||
+1
@@ -1,2 +1,3 @@
|
||||
com.webcodepro.applecommander.storage.os.dos33.DosDiskFactory
|
||||
com.webcodepro.applecommander.storage.os.pascal.PascalDiskFactory
|
||||
com.webcodepro.applecommander.storage.os.prodos.ProdosDiskFactory
|
||||
|
||||
Reference in New Issue
Block a user