Gemma:
- Adding SCHIP instructions SDL2: - Sorting out Joystick/Gamepad/Whatever Util: - Disassembler in progress
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
use std::path::Path;
|
||||
use clap::{command, Parser};
|
||||
use gemma::chip8::instructions::Chip8CpuInstructions;
|
||||
use gemma::chip8::instructions::Chip8CpuInstructions::XXXXERRORINSTRUCTION;
|
||||
|
||||
/// ch8disasm
|
||||
///
|
||||
/// Provide disassembled version of the CH8 file provided.
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct DisassemblerApp {
|
||||
#[arg(short)]
|
||||
input_file: Box<Path>,
|
||||
#[arg(short)]
|
||||
output_file: Option<Box<Path>>
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Taxation is Theft");
|
||||
let result = DisassemblerApp::parse();
|
||||
println!("PREPARING TO DISASSEMBLE {:?}", result.input_file.file_name());
|
||||
let mut last_byte: u8 = 0x00;
|
||||
let mut working_instruction: u16 = 0x0000;
|
||||
// read the input file and loop through it byte by byte.
|
||||
|
||||
for (offset, byte) in std::fs::read(result.input_file).unwrap().iter().enumerate() {
|
||||
working_instruction = (working_instruction << 8) | (*byte as u16);
|
||||
if offset % 2 != 0 {
|
||||
// println!("ODD BYTE -> {:02x} / WORKING: {working_instruction:04x}", *byte as u16);
|
||||
let decoded = Chip8CpuInstructions::decode(working_instruction);
|
||||
match decoded {
|
||||
XXXXERRORINSTRUCTION => {
|
||||
println!("\t\t; ERROR: BYTES: {} OFFSET: {}", working_instruction, offset);
|
||||
println!("FOUND ERROR INSTRUCTION. LIKELY DATA.");
|
||||
}
|
||||
Chip8CpuInstructions::JpAddr(x) => {
|
||||
if x == (offset + 0x1ff) as u16 {
|
||||
println!("FOUND JUMP TO SELF. INFINITE LOOP DETECTED.");
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
println!("{}\t\t; Bytes [{:04x}] ending offset [{:04x}]", decoded, working_instruction, offset);
|
||||
}
|
||||
}
|
||||
working_instruction = 0x0000;
|
||||
}
|
||||
}
|
||||
|
||||
match result.output_file {
|
||||
None => {
|
||||
println!("Output to console.");
|
||||
}
|
||||
Some(target) => {
|
||||
println!("Output to {:?}", target);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user