MeowGB/meowgb-core/tests/misc_opcodes.rs

70 lines
1.4 KiB
Rust
Raw Permalink Normal View History

use meowgb_core::setup_test_emulator;
#[test]
fn test_nop() {
let mut emulator = setup_test_emulator([0x00]);
let expected_register_state = {
let mut state = emulator.registers.clone();
state.pc += 1;
state
};
2024-01-02 05:11:26 +00:00
emulator.tick_4();
assert_eq!(emulator.registers, expected_register_state);
}
#[test]
fn test_di() {
let mut emulator = setup_test_emulator([0xF3]);
let expected_register_state = {
let mut state = emulator.registers.clone();
state.pc += 1;
state
};
emulator.interrupts.ime = true;
2024-01-02 05:11:26 +00:00
emulator.tick_4();
assert_eq!(emulator.registers, expected_register_state);
assert!(!emulator.interrupts.ime);
}
#[test]
fn test_ei() {
let mut emulator = setup_test_emulator([0xFB]);
let expected_register_state = {
let mut state = emulator.registers.clone();
state.pc += 1;
state
};
emulator.interrupts.ime = false;
2024-01-02 05:11:26 +00:00
emulator.tick_4();
assert_eq!(emulator.registers, expected_register_state);
assert!(!emulator.interrupts.ime);
2024-01-02 05:11:26 +00:00
emulator.tick_4(); // <-- Execute the NOP that comes after as the `EI` instruction only takes
// effect a cycle after
assert!(emulator.interrupts.ime);
}
#[test]
fn test_halt() {
let mut emulator = setup_test_emulator([0x76]);
let expected_register_state = {
let mut state = emulator.registers.clone();
state.pc += 1;
state
};
emulator.interrupts.ime = true;
2024-01-02 05:11:26 +00:00
emulator.tick_4();
assert_eq!(emulator.registers, expected_register_state);
assert!(emulator.halt);
}