mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2026-04-21 10:16:33 +00:00
Converted Gutenberg over to devices.
This commit is contained in:
+34
-7
@@ -21,28 +21,55 @@ package com.webcodepro.applecommander.storage.os.gutenberg;
|
||||
|
||||
import com.webcodepro.applecommander.storage.DiskConstants;
|
||||
import com.webcodepro.applecommander.storage.DiskFactory;
|
||||
import com.webcodepro.applecommander.storage.physical.ImageOrder;
|
||||
import org.applecommander.device.BlockToTrackSectorAdapter;
|
||||
import org.applecommander.device.ProdosBlockToTrackSectorAdapterStrategy;
|
||||
import org.applecommander.device.SkewedTrackSectorDevice;
|
||||
import org.applecommander.device.TrackSectorDevice;
|
||||
import org.applecommander.hint.Hint;
|
||||
import org.applecommander.util.DataBuffer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.webcodepro.applecommander.storage.os.gutenberg.GutenbergFormatDisk.*;
|
||||
|
||||
public class GutenbergDiskFactory implements DiskFactory {
|
||||
@Override
|
||||
public void inspect(Context ctx) {
|
||||
ctx.orders.forEach(order -> {
|
||||
if (check(order)) {
|
||||
ctx.disks.add(new GutenbergFormatDisk(ctx.source.getName(), order));
|
||||
List<TrackSectorDevice> devices = new ArrayList<>();
|
||||
// We need DOS ordered...
|
||||
if (ctx.sectorDevice != null) {
|
||||
if (ctx.sectorDevice.is(Hint.NIBBLE_SECTOR_ORDER)) {
|
||||
devices.add(SkewedTrackSectorDevice.physicalToDosSkew(ctx.sectorDevice));
|
||||
}
|
||||
else if (ctx.sectorDevice.is(Hint.DOS_SECTOR_ORDER)) {
|
||||
devices.add(ctx.sectorDevice);
|
||||
}
|
||||
else if (ctx.sectorDevice.is(Hint.PRODOS_BLOCK_ORDER)) {
|
||||
// Cheating a bit...
|
||||
TrackSectorDevice tmp = SkewedTrackSectorDevice.pascalToPhysicalSkew(ctx.sectorDevice);
|
||||
devices.add(SkewedTrackSectorDevice.physicalToDosSkew(tmp));
|
||||
}
|
||||
}
|
||||
else if (ctx.blockDevice != null) {
|
||||
TrackSectorDevice po = new BlockToTrackSectorAdapter(ctx.blockDevice, new ProdosBlockToTrackSectorAdapterStrategy());
|
||||
TrackSectorDevice tmp = SkewedTrackSectorDevice.pascalToPhysicalSkew(po);
|
||||
devices.add(SkewedTrackSectorDevice.physicalToDosSkew(tmp));
|
||||
}
|
||||
devices.forEach(device -> {
|
||||
if (check(device)) {
|
||||
ctx.disks.add(new GutenbergFormatDisk(ctx.source.getName(), device));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean check(ImageOrder order) {
|
||||
public boolean check(TrackSectorDevice order) {
|
||||
boolean good = false;
|
||||
if (order.isSizeApprox(DiskConstants.APPLE_140KB_DISK) || order.isSizeApprox(DiskConstants.APPLE_140KB_NIBBLE_DISK)) {
|
||||
if (order.getGeometry().sectorsPerDisk() == DiskConstants.DOS33_SECTORS_ON_140KB_DISK) {
|
||||
final int tracksPerDisk = 35;
|
||||
final int sectorsPerTrack = 16;
|
||||
// Everything starts at T17,S7
|
||||
DataBuffer data = DataBuffer.wrap(order.readSector(CATALOG_TRACK, VTOC_SECTOR));
|
||||
DataBuffer data = order.readSector(CATALOG_TRACK, VTOC_SECTOR);
|
||||
for (int i=0x0f; i<data.limit(); i+= 0x10) {
|
||||
// Check for the CR at every 16th byte.
|
||||
if (data.getUnsignedByte(i) != 0x8d) return false;
|
||||
|
||||
+31
-22
@@ -20,13 +20,18 @@
|
||||
package com.webcodepro.applecommander.storage.os.gutenberg;
|
||||
|
||||
import com.webcodepro.applecommander.storage.*;
|
||||
import com.webcodepro.applecommander.storage.physical.ImageOrder;
|
||||
import com.webcodepro.applecommander.util.AppleUtil;
|
||||
import com.webcodepro.applecommander.util.TextBundle;
|
||||
import org.applecommander.device.TrackSectorDevice;
|
||||
import org.applecommander.source.Source;
|
||||
import org.applecommander.util.Container;
|
||||
import org.applecommander.util.DataBuffer;
|
||||
|
||||
import static com.webcodepro.applecommander.storage.DiskConstants.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Manages a disk that is in Gutenberg Word Processor format.
|
||||
@@ -34,7 +39,7 @@ import java.util.List;
|
||||
* Date created: Dec 17, 2008 04:29:23 PM
|
||||
* @author David Schmidt
|
||||
*/
|
||||
public class GutenbergFormatDisk extends FormattedDiskX {
|
||||
public class GutenbergFormatDisk extends FormattedDisk implements Container {
|
||||
private TextBundle textBundle = StorageBundle.getInstance();
|
||||
/**
|
||||
* Indicates the index of the track in the location array.
|
||||
@@ -101,24 +106,39 @@ public class GutenbergFormatDisk extends FormattedDiskX {
|
||||
}
|
||||
}
|
||||
|
||||
private TrackSectorDevice device;
|
||||
|
||||
/**
|
||||
* Constructor for GutenbergFormatDisk.
|
||||
*/
|
||||
public GutenbergFormatDisk(String filename, ImageOrder imageOrder) {
|
||||
super(filename, imageOrder);
|
||||
public GutenbergFormatDisk(String filename, TrackSectorDevice device) {
|
||||
super(filename, device.get(Source.class).orElseThrow());
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a GutenbergFormatDisk. All DOS disk images are expected to
|
||||
* be 140K in size.
|
||||
*/
|
||||
public static GutenbergFormatDisk[] create(String filename, ImageOrder imageOrder) {
|
||||
GutenbergFormatDisk disk = new GutenbergFormatDisk(filename, imageOrder);
|
||||
public static GutenbergFormatDisk[] create(String filename, TrackSectorDevice device) {
|
||||
GutenbergFormatDisk disk = new GutenbergFormatDisk(filename, device);
|
||||
disk.format();
|
||||
return new GutenbergFormatDisk[] { disk };
|
||||
}
|
||||
|
||||
/**
|
||||
@Override
|
||||
public <T> Optional<T> get(Class<T> iface) {
|
||||
return Container.get(iface, device);
|
||||
}
|
||||
|
||||
byte[] readSector(int track, int sector) {
|
||||
return device.readSector(track, sector).asBytes();
|
||||
}
|
||||
void writeSector(int track, int sector, byte[] data) {
|
||||
device.writeSector(track, sector, DataBuffer.wrap(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify the operating system format of this disk as Gutenberg.
|
||||
* @see com.webcodepro.applecommander.storage.FormattedDisk#getFormat()
|
||||
*/
|
||||
@@ -517,7 +537,7 @@ public class GutenbergFormatDisk extends FormattedDiskX {
|
||||
* @see com.webcodepro.applecommander.storage.FormattedDisk#format()
|
||||
*/
|
||||
public void format() {
|
||||
getImageOrder().format();
|
||||
device.format();
|
||||
format(15, 35, 16);
|
||||
}
|
||||
|
||||
@@ -525,10 +545,9 @@ public class GutenbergFormatDisk extends FormattedDiskX {
|
||||
* Format the disk as DOS 3.3 given the dymanic parameters.
|
||||
* (Used for UniDOS and OzDOS.)
|
||||
*/
|
||||
protected void format(int firstCatalogSector, int tracksPerDisk,
|
||||
int sectorsPerTrack) {
|
||||
|
||||
writeBootCode();
|
||||
protected void format(int firstCatalogSector, int tracksPerDisk, int sectorsPerTrack) {
|
||||
byte[] bootCode = getBootCode();
|
||||
writeSector(0, 0, bootCode);
|
||||
// create catalog sectors
|
||||
byte[] data = new byte[SECTOR_SIZE];
|
||||
for (int sector=firstCatalogSector; sector > 0; sector--) {
|
||||
@@ -679,16 +698,6 @@ public class GutenbergFormatDisk extends FormattedDiskX {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change to a different ImageOrder. Remains in DOS 3.3 format but
|
||||
* the underlying order can change.
|
||||
* @see ImageOrder
|
||||
*/
|
||||
public void changeImageOrder(ImageOrder imageOrder) {
|
||||
AppleUtil.changeImageOrderByTrackAndSector(getImageOrder(), imageOrder);
|
||||
setImageOrder(imageOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DirectoryEntry.
|
||||
* @see com.webcodepro.applecommander.storage.DirectoryEntry#createDirectory(String)
|
||||
|
||||
Reference in New Issue
Block a user