mirror of https://github.com/mre/mos6502.git
Make instruction printable
This commit is contained in:
parent
d9499fa419
commit
05420f23e5
|
@ -175,14 +175,15 @@ impl<M: Bus> CPU<M> {
|
|||
self.registers.program_counter =
|
||||
self.registers.program_counter.wrapping_add(num_bytes);
|
||||
|
||||
Some((instr, am_out))
|
||||
Some(DecodedInstr(instr, am_out))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute_instruction(&mut self, decoded_instr: DecodedInstr) {
|
||||
match decoded_instr {
|
||||
pub fn execute_instruction<T: Into<DecodedInstr>>(&mut self, decoded_instr: T) {
|
||||
let decoded_instr = decoded_instr.into();
|
||||
match (decoded_instr.0, decoded_instr.1) {
|
||||
(Instruction::ADC, OpInput::UseImmediate(val)) => {
|
||||
debug!("add with carry immediate: {}", val);
|
||||
self.add_with_carry(val as i8);
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
// PC | program counter
|
||||
//
|
||||
|
||||
use core::fmt::{Display, Error, Formatter};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Instruction {
|
||||
ADC, // ADd with Carry................ | NV ...ZC A = A + M + C
|
||||
|
@ -152,7 +154,24 @@ impl AddressingMode {
|
|||
}
|
||||
}
|
||||
|
||||
pub type DecodedInstr = (Instruction, OpInput);
|
||||
pub struct DecodedInstr(pub Instruction, pub OpInput);
|
||||
|
||||
impl Display for DecodedInstr {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||
match self.1 {
|
||||
OpInput::UseImplied => write!(f, "{:?}", self.0),
|
||||
OpInput::UseImmediate(v) => write!(f, "{:?} #${:02X}", self.0, v),
|
||||
OpInput::UseRelative(v) => write!(f, "{:?} ${:04X}", self.0, v),
|
||||
OpInput::UseAddress(v) => write!(f, "{:?} ${:04X}", self.0, v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(Instruction, OpInput)> for DecodedInstr {
|
||||
fn from((instr, op): (Instruction, OpInput)) -> DecodedInstr {
|
||||
DecodedInstr(instr, op)
|
||||
}
|
||||
}
|
||||
|
||||
pub static OPCODES: [Option<(Instruction, AddressingMode)>; 256] = [
|
||||
/*0x00*/
|
||||
|
|
Loading…
Reference in New Issue