Fix labels

This commit is contained in:
Matthias 2023-06-29 11:24:39 +02:00
parent 4172c4bcba
commit f4b8291e5e
1 changed files with 24 additions and 5 deletions

View File

@ -1,4 +1,5 @@
use mos6502::cpu; use mos6502::cpu;
use mos6502::instruction::OpInput;
use mos6502::memory::Bus; use mos6502::memory::Bus;
use mos6502::memory::Memory; use mos6502::memory::Memory;
use std::collections::HashMap; use std::collections::HashMap;
@ -29,18 +30,36 @@ fn main() {
// Use `fetch_next_and_decode` instead of // Use `fetch_next_and_decode` instead of
// `single_step` to see the decoded instruction // `single_step` to see the decoded instruction
if let Some(decoded_instr) = cpu.fetch_next_and_decode() { if let Some(decoded_instr) = cpu.fetch_next_and_decode() {
let label = labels.get(&cpu.registers.program_counter); let address = match decoded_instr.1 {
match label { OpInput::UseImmediate(v) => Some(v as u16),
Some(name) => println!("{}: {}", name, decoded_instr), OpInput::UseRelative(v) => Some(v),
None => println!("{}", decoded_instr), OpInput::UseAddress(v) => Some(v),
OpInput::UseImplied => None,
};
if let Some(address) = address {
let label = labels.get(&address);
match label {
Some(label) => println!("{} ({})", decoded_instr, label),
None => println!("{}", decoded_instr),
}
} else {
println!("{}", decoded_instr);
} }
// println!("Getting label for address: {:04X}", address);
// let label = labels.get(&cpu.registers.program_counter);
// match label {
// Some(name) => println!("{}: {}", name, decoded_instr),
// None => println!("{}", decoded_instr),
// }
cpu.execute_instruction(decoded_instr); cpu.execute_instruction(decoded_instr);
} }
cpu.single_step(); cpu.single_step();
println!("{cpu:?}");
if cpu.registers.program_counter == old_pc { if cpu.registers.program_counter == old_pc {
println!("Infinite loop detected!"); println!("Infinite loop detected!");
println!("{cpu:?}");
break; break;
} }