mirror of
https://github.com/FranLMSP/snes.git
synced 2026-08-03 08:30:01 -04:00
stp
This commit is contained in:
@@ -3,7 +3,7 @@ use super::registers::Registers;
|
|||||||
pub struct CPU {
|
pub struct CPU {
|
||||||
pub registers: Registers,
|
pub registers: Registers,
|
||||||
pub cycles: usize, // TODO: remove cycles from here
|
pub cycles: usize, // TODO: remove cycles from here
|
||||||
pub is_stopped: bool,
|
pub is_stopped: bool, // TODO: remove from here
|
||||||
pub is_waiting_interrupt: bool,
|
pub is_waiting_interrupt: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ pub mod sep;
|
|||||||
pub mod sta;
|
pub mod sta;
|
||||||
pub mod stx;
|
pub mod stx;
|
||||||
pub mod sty;
|
pub mod sty;
|
||||||
|
pub mod stp;
|
||||||
pub mod bit_common;
|
pub mod bit_common;
|
||||||
pub mod dec_common;
|
pub mod dec_common;
|
||||||
pub mod decoder_common;
|
pub mod decoder_common;
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
use crate::cpu::{bus::Bus, registers::Registers};
|
||||||
|
|
||||||
|
use crate::cpu::cycles;
|
||||||
|
use super::{CPUInstruction, Decode};
|
||||||
|
use super::decoder_common;
|
||||||
|
|
||||||
|
static INSTR_NAME: &'static str = "STP";
|
||||||
|
|
||||||
|
pub struct STP {}
|
||||||
|
|
||||||
|
impl CPUInstruction for STP {
|
||||||
|
fn execute(&self, registers: &mut Registers, _bus: &mut Bus) {
|
||||||
|
registers.is_cpu_stopped = true;
|
||||||
|
let (bytes, cycles) = cycles::increment_cycles_stp();
|
||||||
|
registers.increment_pc(bytes); registers.cycles += cycles;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decode for STP {
|
||||||
|
fn mnemonic(&self, _registers: &Registers, _bus: &Bus, opcode: u8) -> String {
|
||||||
|
decoder_common::mnemonic_single_byte_instr(opcode, INSTR_NAME)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod cpu_instructions_tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test() {
|
||||||
|
let mut registers = Registers::new();
|
||||||
|
let mut bus = Bus::new();
|
||||||
|
registers.is_cpu_stopped = false;
|
||||||
|
registers.pc = 0x0000;
|
||||||
|
let instruction = STP{};
|
||||||
|
instruction.execute(&mut registers, &mut bus);
|
||||||
|
assert_eq!(registers.pc, 0x0001);
|
||||||
|
assert_eq!(registers.is_cpu_stopped, true);
|
||||||
|
assert_eq!(registers.cycles, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ pub struct Registers {
|
|||||||
pub dbr: u8, // Data bank register
|
pub dbr: u8, // Data bank register
|
||||||
pub pc: u16, // Program counter
|
pub pc: u16, // Program counter
|
||||||
pub emulation_mode: bool,
|
pub emulation_mode: bool,
|
||||||
|
pub is_cpu_stopped: bool,
|
||||||
pub cycles: usize,
|
pub cycles: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ impl Registers {
|
|||||||
dbr: 0,
|
dbr: 0,
|
||||||
pc: 0,
|
pc: 0,
|
||||||
emulation_mode: true,
|
emulation_mode: true,
|
||||||
|
is_cpu_stopped: false,
|
||||||
cycles: 0,
|
cycles: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user