- Adding SCHIP instructions
SDL2:
- Sorting out Joystick/Gamepad/Whatever
Util:
- Disassembler in progress
This commit is contained in:
2024-10-19 08:24:43 -04:00
parent be6e652982
commit dea4b1aa92
8 changed files with 416 additions and 136 deletions
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "gemmautil"
version = "0.1.0"
edition = "2021"
[dependencies]
gemma = { path = "../gemma" }
clap = { version = "4.5.20", features = ["derive"] }
+58
View File
@@ -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);
}
}
}