WIP BRK and COP instructions

This commit is contained in:
2022-12-05 19:35:16 -05:00
parent 296500cc8e
commit 1b4200bf5e
3 changed files with 28 additions and 3 deletions
+7
View File
@@ -384,6 +384,13 @@ impl CPU {
pub fn increment_cycles_xba(&mut self) {
self.registers.increment_pc(1); self.cycles += 3;
}
pub fn increment_cycles_brk(&mut self) {
self.registers.increment_pc(2); self.cycles += 7;
if self.registers.emulation_mode {
self.cycles += 1;
}
}
}
#[cfg(test)]
+20 -2
View File
@@ -516,6 +516,24 @@ impl CPU {
}
}
fn brk(&mut self, bus: &mut Bus) {
self.do_push(bus, &[self.registers.pbr]);
self.do_push(bus, &[(self.registers.pc >> 8) as u8, self.registers.pc as u8]);
self.do_push(bus, &[self.registers.p]);
self.registers.set_decimal_mode_flag(false);
self.registers.set_irq_disable_flag(true);
self.increment_cycles_brk();
}
fn cop(&mut self, bus: &mut Bus) {
self.do_push(bus, &[self.registers.pbr]);
self.do_push(bus, &[(self.registers.pc >> 8) as u8, self.registers.pc as u8]);
self.do_push(bus, &[self.registers.p]);
self.registers.set_decimal_mode_flag(false);
self.registers.set_irq_disable_flag(true);
self.increment_cycles_brk();
}
fn pea(&mut self, bus: &mut Bus) {
let address = self.get_effective_address(bus, AddressingMode::Absolute);
self.do_push(bus, &[(address >> 8) as u8, address as u8]);
@@ -1066,7 +1084,7 @@ impl CPU {
// BRA
0x80 => self.bra(bus),
// BRK
0x00 => unimplemented!("BRK instruction not implemented yet"),
0x00 => self.brk(bus),
// BRL
0x82 => self.brl(bus),
// BVC
@@ -1104,7 +1122,7 @@ impl CPU {
0xC3 => self.cmp(bus, A::StackRelative),
0xD3 => self.cmp(bus, A::StackRelativeIndirectIndexed(I::Y)),
// COP
0x02 => unimplemented!("COP instruction not implemented yet"),
0x02 => self.cop(bus),
// CPX
0xE0 => self.cpx(bus, A::Immediate),
0xEC => self.cpx(bus, A::Absolute),
+1 -1
View File
@@ -10,7 +10,7 @@ pub struct Registers {
pub pbr: u8, // Program bank register
pub dbr: u8, // Data bank register
pub pc: u16, // Program counter
pub emulation_mode: bool, // Program counter
pub emulation_mode: bool,
}
impl Registers {