boxswap
This commit is contained in:
+86
-17
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
64tass -a -o instructions.bin -b instructions.asm &&
|
||||
cargo run --bin de6502 -- -v instructions.bin instructions_produced.asm &&
|
||||
64tass -a -b instructions_produced.asm -o instructions_produced.bin
|
||||
*/
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
@@ -15,7 +20,10 @@ struct CliOptions {
|
||||
/// File to Decompile
|
||||
input: PathBuf,
|
||||
/// File to write
|
||||
output: PathBuf
|
||||
output: PathBuf,
|
||||
/// Verbose output
|
||||
#[arg(short, action = clap::ArgAction::Count)]
|
||||
verbose: u8
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -57,15 +65,16 @@ impl WorkingProgram {
|
||||
|
||||
}
|
||||
|
||||
fn decompile(data: &[u8]) -> Vec<(u16, DecompiledLine)> {
|
||||
println!("Preparing to decompile {}b", data.len());
|
||||
let mut current_data_position: u16 = 0;
|
||||
fn parse_to_decompiled_lines(data: &[u8]) -> HashMap<u16, DecompiledLine> {
|
||||
println!("PARSE GOT {}b", data.len());
|
||||
let mut current_data_position = 0;
|
||||
let mut lines: HashMap<u16, DecompiledLine> = HashMap::new();
|
||||
|
||||
while current_data_position < data.len() as u16 {
|
||||
// read the next byte.
|
||||
let next_byte = data[current_data_position as usize];
|
||||
let mut bytes = vec![next_byte];
|
||||
println!("Bytes = {bytes:?}");
|
||||
let target_op = INSTRUCTION_TABLE[next_byte as usize].clone();
|
||||
|
||||
if let Some(top) = target_op {
|
||||
@@ -83,7 +92,7 @@ fn decompile(data: &[u8]) -> Vec<(u16, DecompiledLine)> {
|
||||
if num_bytes_to_load == 2 {
|
||||
bytes.push(data[current_data_position as usize + 1]);
|
||||
bytes.push(data[current_data_position as usize + 2]);
|
||||
// 16 bit parameter.
|
||||
// 16 bit parameter.
|
||||
param = Some(((bytes[2] as u16) << 8) | bytes[1] as u16);
|
||||
formatted_asm = format!("{}{:04x}{}", formatted_asm, param.unwrap(), top.format_postfix);
|
||||
};
|
||||
@@ -103,25 +112,45 @@ fn decompile(data: &[u8]) -> Vec<(u16, DecompiledLine)> {
|
||||
current_data_position += 1;
|
||||
}
|
||||
}
|
||||
lines
|
||||
}
|
||||
|
||||
fn decompile(data: &Vec<u8>) -> Vec<(u16, DecompiledLine)> {
|
||||
println!("Preparing to decompile {}b", data.len());
|
||||
let mut current_data_position: u16 = 0;
|
||||
let mut lines: HashMap<u16, DecompiledLine> = parse_to_decompiled_lines(data);
|
||||
|
||||
println!("Found {} instructions in pass 1. Adding labels for jumps.", lines.len());
|
||||
|
||||
//let targets = vec![];
|
||||
|
||||
for (index, line) in &lines {
|
||||
|
||||
if line.bytes[0] == ISA_OP_JMP_ABS {
|
||||
// println!("ABS JUMP FOUND");
|
||||
}
|
||||
}
|
||||
|
||||
let mut items: Vec<_> = lines.into_iter().collect();
|
||||
items.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
|
||||
|
||||
// loop through the lines for JSR and label the 'target' as SUB<index>
|
||||
// let mut jump_targets = vec![];
|
||||
for (line_index, working_line) in &mut items {
|
||||
if working_line.is_jump() {
|
||||
println!("There are {}b in bytes", working_line.bytes.len());
|
||||
let target = read_word(&working_line.bytes[1..=2]);
|
||||
println!("Found a jump at index {line_index} / 0x{line_index} with target of 0x{:04x}", target);;
|
||||
// Derp -> this doesnt work.
|
||||
// items[target as usize].1.label = Some("Label1".parse().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
// check the vectors to label those entrypoints.
|
||||
// // check the vectors to label those entrypoints.
|
||||
// let (mut main, mut nmi, mut irq) = (0, 0, 0);
|
||||
// match data.len() {
|
||||
// SIZE_32KB | SIZE_64KB => {
|
||||
// main = read_word(&data[OFFSET_RESET_VECTORS..=OFFSET_RESET_VECTORS + 1]);
|
||||
// nmi = read_word(&data[OFFSET_NMI_VECTORS..=OFFSET_NMI_VECTORS + 1]);
|
||||
// irq = read_word(&data[OFFSET_INT_VECTORS..=OFFSET_INT_VECTORS]);
|
||||
// }
|
||||
// _ => {
|
||||
// // dont know where to look for our offsets. :(
|
||||
// }
|
||||
// }
|
||||
// -> main
|
||||
// -> NMI
|
||||
// -> IRQ
|
||||
@@ -129,6 +158,37 @@ fn decompile(data: &[u8]) -> Vec<(u16, DecompiledLine)> {
|
||||
items
|
||||
}
|
||||
|
||||
/// read_word
|
||||
///
|
||||
/// Read a word from the provided data with first byte being
|
||||
/// LSB
|
||||
fn read_word(from: &[u8]) -> u16 {
|
||||
(from[1] as u16) << 8 | from[0] as u16
|
||||
}
|
||||
|
||||
/// read_word_swap
|
||||
///
|
||||
/// Read a word from the provided data with first byte being
|
||||
/// MSB
|
||||
fn read_word_swap(from: &[u8]) -> u16 {
|
||||
(from[0] as u16) << 8 | from[1] as u16
|
||||
}
|
||||
|
||||
/// format_bytes
|
||||
///
|
||||
/// formats data for stuff
|
||||
fn format_bytes(from: &Vec<u8>) -> String {
|
||||
let mut to_return = String::from("[");
|
||||
|
||||
for index in 0..from.len() {
|
||||
to_return = format!("{} 0x{:02x}", to_return, from[index]);
|
||||
}
|
||||
to_return = format!("{} ]", to_return);
|
||||
|
||||
to_return
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let opts = CliOptions::parse();
|
||||
println!("Taxation is theft.");
|
||||
@@ -147,8 +207,17 @@ fn main() {
|
||||
|
||||
// ...reap the decompiled code.
|
||||
for (_, line) in &result {
|
||||
let line =format!("{:width$}; {:?}", line.text,line.bytes, width=30 );
|
||||
println!("{}", line);
|
||||
writeln!(output_file, "{}", line).expect("cant write output file. you picked the red snapper.");
|
||||
let formatted_bytes = format_bytes(&line.bytes);
|
||||
let output_line =format!("{:width$}; {}", line.text, formatted_bytes, width=30 );
|
||||
|
||||
// do we need a label
|
||||
if let Some(label) = &line.label {
|
||||
println!("There is a label - {label}");
|
||||
}
|
||||
if opts.verbose > 0 {
|
||||
println!("{}", output_line);
|
||||
}
|
||||
writeln!(output_file, "{}", output_line).expect("cant write output file. you picked the red snapper.");
|
||||
}
|
||||
println!("OPTS = {}", opts.verbose);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
use core::computers::kim1::Kim1;
|
||||
|
||||
fn main() {
|
||||
println!("Taxation is theft.");
|
||||
|
||||
let mut kim = Kim1::new();
|
||||
let mut num_ticks = 0;
|
||||
|
||||
kim.running = true;
|
||||
|
||||
while kim.running {
|
||||
kim.tick();
|
||||
num_ticks += 1;
|
||||
|
||||
if num_ticks == 11 {
|
||||
println!("Got our 11 ticks. time to hotwire this pc.");
|
||||
kim.running = true;
|
||||
kim.dump();
|
||||
}
|
||||
|
||||
if num_ticks == 15 {
|
||||
kim.running = false;
|
||||
kim.dump();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
use clap::Parser;
|
||||
use core::computers::rom_only::backplane::Backplane;
|
||||
use core::computers::rom_only::backplane::RomOnlyComputer;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct CliOptions {
|
||||
@@ -13,6 +13,6 @@ fn main() {
|
||||
|
||||
let opts = CliOptions::parse();
|
||||
|
||||
let mut rom_only = Backplane::new();
|
||||
let mut rom_only = RomOnlyComputer::new();
|
||||
rom_only.tick()
|
||||
}
|
||||
Reference in New Issue
Block a user