CPU Registers for CGB mode

This commit is contained in:
Franco Colmenarez 2021-12-26 08:58:09 -05:00
parent abac2b3bf3
commit eb0f61aebd
3 changed files with 26 additions and 4 deletions

View File

@ -36,6 +36,7 @@ pub struct Bus {
pub timer: Timer,
pub sound: Sound,
pub interrupts: Interrupts,
pub cgb_mode: bool,
}
impl Bus {
@ -67,6 +68,7 @@ impl Bus {
timer: Timer::new(),
sound: Sound::new(),
interrupts: Interrupts::new(),
cgb_mode,
};
// Hardware registers after the bootrom

View File

@ -87,6 +87,21 @@ impl Registers {
}
}
pub fn new_cgb() -> Self {
Self {
a: 0x11,
f: 0x00,
b: 0x00,
c: 0x00,
d: 0xFF,
e: 0x56,
h: 0x00,
l: 0x0D,
sp: 0xFFFE,
pc: 0x0100,
}
}
pub fn get(&self, register: Register) -> u16 {
match register {
Register::A => self.a as u16,
@ -818,9 +833,12 @@ pub struct CPU {
}
impl CPU {
pub fn new() -> Self {
pub fn new(cgb_mode: bool) -> Self {
Self {
registers: Registers::new(),
registers: match cgb_mode {
true => Registers::new_cgb(),
false => Registers::new(),
},
cycles: Cycles(0),
last_op_cycles: Cycles(0),
exec_calls_count: 0,

View File

@ -16,9 +16,11 @@ pub struct Emulator {
impl Emulator {
pub fn new() -> Self {
let bus = Bus::new();
let cgb_mode = bus.cgb_mode;
Self {
bus: Bus::new(),
cpu: CPU::new(),
bus,
cpu: CPU::new(cgb_mode),
}
}