move ime to ram

This commit is contained in:
Alex Janka 2023-01-17 09:45:49 +11:00
parent 7bf1034265
commit 3cf0df204d
2 changed files with 10 additions and 9 deletions

View file

@ -49,6 +49,7 @@ pub struct Memory {
switchable_ram: [u8; 8192], switchable_ram: [u8; 8192],
cpu_ram: [u8; 128], cpu_ram: [u8; 128],
oam: [u8; 160], oam: [u8; 160],
ime: bool,
} }
impl Memory { impl Memory {
@ -60,6 +61,7 @@ impl Memory {
switchable_ram: [0x0; 8192], switchable_ram: [0x0; 8192],
cpu_ram: [0x0; 128], cpu_ram: [0x0; 128],
oam: [0x0; 160], oam: [0x0; 160],
ime: false,
} }
} }
@ -98,7 +100,7 @@ impl Memory {
return self.cpu_ram[(address - 0xFF80) as usize]; return self.cpu_ram[(address - 0xFF80) as usize];
} }
0xFFFF => { 0xFFFF => {
panic!("interrupt enable register memory read???"); return if self.ime { 1 } else { 0 };
} }
} }
} }
@ -136,9 +138,10 @@ impl Memory {
0xFF80..0xFFFF => { 0xFF80..0xFFFF => {
self.cpu_ram[(address - 0xFF80) as usize] = data; self.cpu_ram[(address - 0xFF80) as usize] = data;
} }
0xFFFF => { 0xFFFF => match data {
panic!("interrupt enable register memory write???"); 0x0 => self.ime = false,
} _ => panic!("wrote weird number to ime: {:#X}", data),
},
} }
} }
} }
@ -182,7 +185,6 @@ fn main() {
let mut cpu = CPU { let mut cpu = CPU {
memory: Memory::init(run_rom), memory: Memory::init(run_rom),
state, state,
ime: false,
}; };
match args.step_by { match args.step_by {
Some(step_size) => loop { Some(step_size) => loop {

View file

@ -16,7 +16,6 @@ enum FLAGS {
pub struct CPU { pub struct CPU {
pub memory: Memory, pub memory: Memory,
pub state: State, pub state: State,
pub ime: bool,
} }
impl CPU { impl CPU {
@ -829,7 +828,7 @@ impl CPU {
} }
0xD9 => { 0xD9 => {
self.state.pc = self.pop_word(); self.state.pc = self.pop_word();
self.ime = true; self.memory.ime = true;
} }
0xDA => { 0xDA => {
let maybe_next = self.ld_immediate_word(); let maybe_next = self.ld_immediate_word();
@ -939,7 +938,7 @@ impl CPU {
self.state.af.as_u8s.left = self.memory.get(address.as_u16); self.state.af.as_u8s.left = self.memory.get(address.as_u16);
}; };
} }
0xF3 => self.ime = false, 0xF3 => self.memory.ime = false,
0xF4 => undefined(0xF4), 0xF4 => undefined(0xF4),
0xF5 => self.push(self.state.af), 0xF5 => self.push(self.state.af),
0xF6 => unsafe { 0xF6 => unsafe {
@ -959,7 +958,7 @@ impl CPU {
let address = self.ld_immediate_word().as_u16; let address = self.ld_immediate_word().as_u16;
self.state.af.as_u8s.left = self.memory.get(address); self.state.af.as_u8s.left = self.memory.get(address);
}, },
0xFB => self.ime = true, 0xFB => self.memory.ime = true,
0xFC => undefined(0xFC), 0xFC => undefined(0xFC),
0xFD => undefined(0xFD), 0xFD => undefined(0xFD),
0xFE => unsafe { 0xFE => unsafe {