mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2025-02-05 14:30:02 +00:00
Merge pull request #81 from AppleCommander/feature/dump_with_offset
Dump command now allows offset into sectore/block.
This commit is contained in:
commit
ce92b7b280
@ -30,6 +30,16 @@ public class CoordinateSelection {
|
|||||||
@ArgGroup(exclusive = false)
|
@ArgGroup(exclusive = false)
|
||||||
private CoordinateSelection.BlockCoordinateSelection blockCoordinate;
|
private CoordinateSelection.BlockCoordinateSelection blockCoordinate;
|
||||||
|
|
||||||
|
public boolean includesBootSector() {
|
||||||
|
if (sectorCoordinate != null) {
|
||||||
|
return sectorCoordinate.isBootSector();
|
||||||
|
}
|
||||||
|
else if (blockCoordinate != null) {
|
||||||
|
return blockCoordinate.isBootBlock();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] read(Disk disk) {
|
public byte[] read(Disk disk) {
|
||||||
if (sectorCoordinate != null) {
|
if (sectorCoordinate != null) {
|
||||||
return sectorCoordinate.read(disk);
|
return sectorCoordinate.read(disk);
|
||||||
@ -56,6 +66,9 @@ public class CoordinateSelection {
|
|||||||
@Option(names = { "-s", "--sector" }, required = true, description = "Sector number.")
|
@Option(names = { "-s", "--sector" }, required = true, description = "Sector number.")
|
||||||
private Integer sector;
|
private Integer sector;
|
||||||
|
|
||||||
|
public boolean isBootSector() {
|
||||||
|
return track == 0 && sector == 0;
|
||||||
|
}
|
||||||
public byte[] read(Disk disk) {
|
public byte[] read(Disk disk) {
|
||||||
return disk.readSector(track, sector);
|
return disk.readSector(track, sector);
|
||||||
}
|
}
|
||||||
@ -67,6 +80,9 @@ public class CoordinateSelection {
|
|||||||
@Option(names = { "-b", "--block" }, description = "Block number.")
|
@Option(names = { "-b", "--block" }, description = "Block number.")
|
||||||
private Integer block;
|
private Integer block;
|
||||||
|
|
||||||
|
public boolean isBootBlock() {
|
||||||
|
return block == 0;
|
||||||
|
}
|
||||||
public byte[] read(Disk disk) {
|
public byte[] read(Disk disk) {
|
||||||
return disk.readBlock(block);
|
return disk.readBlock(block);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ package io.github.applecommander.acx.command;
|
|||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -28,35 +29,34 @@ import com.webcodepro.applecommander.util.AppleUtil;
|
|||||||
|
|
||||||
import io.github.applecommander.acx.arggroup.CoordinateSelection;
|
import io.github.applecommander.acx.arggroup.CoordinateSelection;
|
||||||
import io.github.applecommander.acx.base.ReadOnlyDiskImageCommandOptions;
|
import io.github.applecommander.acx.base.ReadOnlyDiskImageCommandOptions;
|
||||||
|
import io.github.applecommander.acx.converter.IntegerTypeConverter;
|
||||||
import io.github.applecommander.disassembler.api.Disassembler;
|
import io.github.applecommander.disassembler.api.Disassembler;
|
||||||
import io.github.applecommander.disassembler.api.Instruction;
|
import io.github.applecommander.disassembler.api.Instruction;
|
||||||
import io.github.applecommander.disassembler.api.mos6502.InstructionSet6502;
|
import io.github.applecommander.disassembler.api.mos6502.InstructionSet6502;
|
||||||
import picocli.CommandLine.ArgGroup;
|
import picocli.CommandLine.ArgGroup;
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
|
import picocli.CommandLine.Mixin;
|
||||||
import picocli.CommandLine.Option;
|
import picocli.CommandLine.Option;
|
||||||
|
|
||||||
@Command(name = "dump", description = "Dump a block or sector.")
|
@Command(name = "dump", description = "Dump a block or sector.")
|
||||||
public class DumpCommand extends ReadOnlyDiskImageCommandOptions {
|
public class DumpCommand extends ReadOnlyDiskImageCommandOptions {
|
||||||
@ArgGroup(multiplicity = "1", heading = "%nCoordinate Selection:%n")
|
|
||||||
private CoordinateSelection coordinate = new CoordinateSelection();
|
|
||||||
|
|
||||||
@ArgGroup(heading = "%nOutput Selection:%n")
|
@ArgGroup(heading = "%nOutput Selection:%n")
|
||||||
private OutputSelection output = new OutputSelection();
|
private OutputSelection output = new OutputSelection();
|
||||||
|
|
||||||
@Option(names = { "-a", "--address" }, description = "Starting address.")
|
@Mixin
|
||||||
private int address = 0x800;
|
private Options options = new Options();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int handleCommand() throws Exception {
|
public int handleCommand() throws Exception {
|
||||||
byte[] data = coordinate.read(disk);
|
byte[] data = options.coordinate.read(disk);
|
||||||
System.out.println(output.format(address, data));
|
System.out.println(output.format(options, data));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class OutputSelection {
|
public static class OutputSelection {
|
||||||
private BiFunction<Integer,byte[],String> fn = this::formatHexDump;
|
private BiFunction<Options,byte[],String> fn = this::formatHexDump;
|
||||||
public String format(int address, byte[] data) {
|
public String format(Options options, byte[] data) {
|
||||||
return fn.apply(address, data);
|
return fn.apply(options, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Option(names = "--hex", description = "Hex dump.")
|
@Option(names = "--hex", description = "Hex dump.")
|
||||||
@ -69,13 +69,16 @@ public class DumpCommand extends ReadOnlyDiskImageCommandOptions {
|
|||||||
fn = this::formatDisassembly;
|
fn = this::formatDisassembly;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String formatHexDump(int address, byte[] data) {
|
public String formatHexDump(Options options, byte[] data) {
|
||||||
return AppleUtil.getHexDump(address, data);
|
return AppleUtil.getHexDump(options.address, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String formatDisassembly(int address, byte[] data) {
|
public String formatDisassembly(Options options, byte[] data) {
|
||||||
|
// If the offset is given, use that. If not, use 0 except for the boot sector and then use 1.
|
||||||
|
int calculatedOffset = options.offset.orElse(options.coordinate.includesBootSector() ? 1 : 0);
|
||||||
return Disassembler.with(data)
|
return Disassembler.with(data)
|
||||||
.startingAddress(address)
|
.startingAddress(options.address)
|
||||||
|
.bytesToSkip(calculatedOffset)
|
||||||
.use(InstructionSet6502.for6502())
|
.use(InstructionSet6502.for6502())
|
||||||
.decode()
|
.decode()
|
||||||
.stream()
|
.stream()
|
||||||
@ -100,4 +103,17 @@ public class DumpCommand extends ReadOnlyDiskImageCommandOptions {
|
|||||||
return sw.toString();
|
return sw.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Options {
|
||||||
|
@ArgGroup(multiplicity = "1", heading = "%nCoordinate Selection:%n")
|
||||||
|
private CoordinateSelection coordinate = new CoordinateSelection();
|
||||||
|
|
||||||
|
@Option(names = { "-a", "--address" }, converter = IntegerTypeConverter.class,
|
||||||
|
description = "Starting address.")
|
||||||
|
private int address = 0x800;
|
||||||
|
|
||||||
|
@Option(names = { "-o", "--offset" }, converter = IntegerTypeConverter.class,
|
||||||
|
description = "Number of bytes to skip into file before disassembling.")
|
||||||
|
private Optional<Integer> offset = Optional.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,4 @@ commonsCsvVersion=1.8
|
|||||||
gsonVersion=2.8.6
|
gsonVersion=2.8.6
|
||||||
picocliVersion=4.6.2
|
picocliVersion=4.6.2
|
||||||
springBoot=2.6.1
|
springBoot=2.6.1
|
||||||
acdasmVersion=0.3.0
|
acdasmVersion=0.4.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user