16-bit increment and decrement

This commit is contained in:
Martin Löffler 2023-01-25 23:44:10 +01:00
parent c35340ecce
commit d186950e99
Signed by: FatalErrorCoded
GPG key ID: FFEF368AC076566A
2 changed files with 25 additions and 1 deletions

View file

@ -68,3 +68,15 @@ pub fn dcr(register: Register, state: &mut EmulatorState) {
set_cc(state, result as u16, 0b1101); set_cc(state, result as u16, 0b1101);
set_register(register, result, state); set_register(register, result, state);
} }
/// Increase register pair
pub fn inx(register: Register, state: &mut EmulatorState) {
let (result, _) = get_register_pair(register, state).overflowing_add(1);
set_register_pair(register, result, state);
}
/// Decrease register pair
pub fn dcx(register: Register, state: &mut EmulatorState) {
let (result, _) = get_register_pair(register, state).overflowing_sub(1);
set_register_pair(register, result, state);
}

View file

@ -62,10 +62,10 @@ fn tick(state: &mut EmulatorState) {
0xfb => state.ei = true, // EI 0xfb => state.ei = true, // EI
0xf3 => state.ei = false, // DI 0xf3 => state.ei = false, // DI
0x76 => { 0x76 => {
// HLT
if state.ei { if state.ei {
todo!() todo!()
} else { } else {
// HLT
println!("HLT called after DI; exiting."); println!("HLT called after DI; exiting.");
print_state(state); print_state(state);
std::process::exit(0); std::process::exit(0);
@ -99,6 +99,18 @@ fn tick(state: &mut EmulatorState) {
0x29 => arithmetic::dad(Register::H, state), 0x29 => arithmetic::dad(Register::H, state),
0x39 => arithmetic::dad(Register::SP, state), 0x39 => arithmetic::dad(Register::SP, state),
// INX
0x03 => arithmetic::inx(Register::B, state),
0x13 => arithmetic::inx(Register::D, state),
0x23 => arithmetic::inx(Register::H, state),
0x33 => arithmetic::inx(Register::SP, state),
// DCX
0x0b => arithmetic::dcx(Register::B, state),
0x1b => arithmetic::dcx(Register::D, state),
0x2b => arithmetic::dcx(Register::H, state),
0x3b => arithmetic::dcx(Register::SP, state),
0x80..=0x87 => arithmetic::add(register_from_num(instruction & 0xf), state), // ADD 0x80..=0x87 => arithmetic::add(register_from_num(instruction & 0xf), state), // ADD
0x88..=0x8f => arithmetic::adc(register_from_num(instruction & 0xf), state), // ADC 0x88..=0x8f => arithmetic::adc(register_from_num(instruction & 0xf), state), // ADC
0xc6 => arithmetic::adi(next_byte(), state), // ADI 0xc6 => arithmetic::adi(next_byte(), state), // ADI