Capturing the NibbleTrackReaderWriter so that 'acx dump' can dump a nibble version of a track. Useful for sleuthing.

This commit is contained in:
Rob Greene
2025-09-03 15:55:13 -05:00
parent a22525882e
commit aa4f4df0f8
2 changed files with 33 additions and 5 deletions
@@ -41,6 +41,7 @@ import io.github.applecommander.disassembler.api.mos6502.InstructionSet6502;
import io.github.applecommander.disassembler.api.sweet16.InstructionSetSWEET16;
import io.github.applecommander.disassembler.api.switching6502.InstructionSet6502Switching;
import org.applecommander.device.BlockDevice;
import org.applecommander.device.NibbleTrackReaderWriter;
import org.applecommander.device.TrackSectorDevice;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
@@ -82,6 +83,20 @@ public class DumpCommand extends ReadOnlyDiskImageCommandOptions {
});
return 0;
}
else if (options.coordinate.nibbleTrackRangeSelection != null) {
NibbleTrackReaderWriter trackReaderWriter = disk.get(NibbleTrackReaderWriter.class)
.orElseThrow(() -> new RuntimeException("This is not a nibble device."));
options.coordinate.nibbleTrackRangeSelection.tracks.stream().forEach(track -> {
final int tracksPerDisk = trackReaderWriter.getTracksOnDevice();
if (track < 0 || track >= tracksPerDisk) {
String errormsg = String.format("The track number(%d) is out of range(0-%d) on this image.", track, tracksPerDisk-1);
throw new IllegalArgumentException(errormsg);
}
byte[] data = trackReaderWriter.readTrackData(track).asBytes();
System.out.printf("Track %02d\n", track);
System.out.println(output.format(options, data));
});
}
System.out.println("Please choose block(s) or track(s) and sector(s).");
return 1;
}
@@ -166,7 +181,7 @@ public class DumpCommand extends ReadOnlyDiskImageCommandOptions {
// correctly...
private boolean includesBootSector;
@ArgGroup(multiplicity = "1", heading = "%nCoordinate Selection: (use '0' or '0-5' for a range)%n")
@ArgGroup(multiplicity = "1")
private CoordinateRangeSelection coordinate = new CoordinateRangeSelection();
@ArgGroup(heading = "%nDisassembler Options:%n", exclusive = false)
@@ -216,10 +231,12 @@ public class DumpCommand extends ReadOnlyDiskImageCommandOptions {
}
public static class CoordinateRangeSelection {
@ArgGroup(exclusive = false)
@ArgGroup(exclusive = false, heading = "%nBlock devices: (use '0' or '0-5' for a range)%n")
private BlockRangeSelection blockRangeSelection;
@ArgGroup(exclusive = false)
@ArgGroup(exclusive = false, heading = "%nTrack/Sector devices: (use '0' or '0-5' for a range)%n")
private TrackSectorRangeSelection trackSectorRangeSelection;
@ArgGroup(exclusive = false, heading = "%nNibble track/sector devices: (use '0' or '0-5' for a range)%n")
private NibbleTrackRangeSelection nibbleTrackRangeSelection;
}
public static class BlockRangeSelection {
@@ -235,4 +252,9 @@ public class DumpCommand extends ReadOnlyDiskImageCommandOptions {
converter = RangeTypeConverter.class)
private Range sectors;
}
public static class NibbleTrackRangeSelection {
@Option(names = "-n", description = "Track number(s).",
converter = RangeTypeConverter.class)
private Range tracks;
}
}
@@ -36,6 +36,7 @@ public interface DiskFactory {
class Context {
public final Source source;
public final NibbleTrackReaderWriter nibbleTrackReaderWriter;
public final List<FormattedDisk> disks = new ArrayList<>();
// Note: These are only set if we *KNOW* what they are. Except DSK images, where both will be set.
public final BlockDevice blockDevice;
@@ -48,17 +49,22 @@ public interface DiskFactory {
int signature = source.readBytes(0, 4).readInt();
if (WozImage.WOZ1_MAGIC == signature || WozImage.WOZ2_MAGIC == signature) {
blockDevice = null;
sectorDevice = identifySectorsPerTrack(new WozImage(source));
nibbleTrackReaderWriter = new WozImage(source);
sectorDevice = identifySectorsPerTrack(nibbleTrackReaderWriter);
} else if (source.is(Hint.NIBBLE_SECTOR_ORDER) || source.isApproxEQ(DiskConstants.APPLE_140KB_NIBBLE_DISK)) {
blockDevice = null;
sectorDevice = identifySectorsPerTrack(new NibbleImage(source));
nibbleTrackReaderWriter = new NibbleImage(source);
sectorDevice = identifySectorsPerTrack(nibbleTrackReaderWriter);
} else if (source.is(Hint.PRODOS_BLOCK_ORDER) || source.getSize() > DiskConstants.APPLE_400KB_DISK || source.extensionLike("po")) {
nibbleTrackReaderWriter = null;
blockDevice = new ProdosOrderedBlockDevice(source, BlockDevice.STANDARD_BLOCK_SIZE);
sectorDevice = null;
} else if (source.is(Hint.DOS_SECTOR_ORDER) || source.extensionLike("do")) {
nibbleTrackReaderWriter = null;
blockDevice = null;
sectorDevice = new DosOrderedTrackSectorDevice(source, Hint.DOS_SECTOR_ORDER);
} else {
nibbleTrackReaderWriter = null;
// Could be either - most likely the nebulous "dsk" extension
blockDevice = new ProdosOrderedBlockDevice(source, BlockDevice.STANDARD_BLOCK_SIZE);
sectorDevice = new DosOrderedTrackSectorDevice(source);