From edbbfb0d5f4473854643ad3575d76b48f11ef75d Mon Sep 17 00:00:00 2001 From: velllu <91963404+velllu@users.noreply.github.com> Date: Wed, 6 Sep 2023 23:08:43 +0200 Subject: [PATCH] Added `LD (a8), A` opcode (`0xE0`) --- src/consts.rs | 1 + src/cpu.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/consts.rs b/src/consts.rs index e026584..511b7c3 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -2,6 +2,7 @@ pub(crate) mod bus { pub(crate) const EOM_SIZE: usize = 160; pub(crate) const HIGH_RAM_SIZE: usize = 127; pub(crate) const IO_SIZE: usize = 128; + pub(crate) const IO_START: usize = 0xFF00; pub(crate) const ROM_SIZE: usize = 32768; pub(crate) const VIDEO_RAM_SIZE: usize = 8192; pub(crate) const WORK_RAM_SIZE: usize = 8192; diff --git a/src/cpu.rs b/src/cpu.rs index a097744..c80d135 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -1,4 +1,5 @@ use crate::common::{merge_two_u8s_into_u16, Operator}; +use crate::consts::bus::IO_START; use crate::registers::OneByteRegister; use crate::GameBoy; @@ -63,6 +64,11 @@ impl GameBoy { let register = self.registers.get_r(register); *register = i; } + + pub(crate) fn load_i_into_io(&mut self, register: OneByteRegister) { + let register = *self.registers.get_r(register); + self.bus.write_byte((IO_START + self.next(1) as usize) as u16, register); + } } // Bitwise operation functions (not all of them as of now) @@ -221,6 +227,9 @@ impl GameBoy { (1, 2) }, + // Load R into IO (yes, only one of this) + 0xE0 => { self.load_i_into_io(OneByteRegister::A); (2, 3) }, + // Jump // When we jump, we set 0 bytes, because if we returned the "correct" amount // of bytes, the program will add them to PC after the jump