fix interrupts

This commit is contained in:
Alex Janka 2023-01-18 13:58:53 +11:00
parent df8acbfa32
commit 8f3cf515a9

View file

@ -54,6 +54,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],
interrupts: u8,
ime: bool, ime: bool,
io: [u8; 76], io: [u8; 76],
} }
@ -69,6 +70,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],
interrupts: 0x0,
ime: false, ime: false,
io: [0x0; 76], io: [0x0; 76],
} }
@ -113,7 +115,7 @@ impl Memory {
return self.cpu_ram[(address - 0xFF80) as usize]; return self.cpu_ram[(address - 0xFF80) as usize];
} }
0xFFFF => { 0xFFFF => {
return if self.ime { 1 } else { 0 }; return self.interrupts;
} }
} }
} }
@ -143,6 +145,9 @@ impl Memory {
// println!("empty space write: {:#X} to addr {:#X}", data, address); // println!("empty space write: {:#X} to addr {:#X}", data, address);
} }
0xFF00..0xFF4C => { 0xFF00..0xFF4C => {
print!("writing to addr {:#X}\r", address);
stdout().flush().unwrap();
if address == 0xFF02 && data == 0x81 { if address == 0xFF02 && data == 0x81 {
print!("{}", self.get(0xFF01) as char); print!("{}", self.get(0xFF01) as char);
stdout().flush().unwrap(); stdout().flush().unwrap();
@ -155,11 +160,11 @@ impl Memory {
0xFF80..0xFFFF => { 0xFF80..0xFFFF => {
self.cpu_ram[(address - 0xFF80) as usize] = data; self.cpu_ram[(address - 0xFF80) as usize] = data;
} }
0xFFFF => match data { 0xFFFF => {
0x0 => self.ime = false, println!("interrupts set to {:#b}", data);
0x1 => self.ime = true, println!(" / {:#X}", data);
_ => panic!("wrote weird number to ime: {:#X}", data), self.interrupts = data;
}, }
} }
} }
} }
@ -224,7 +229,7 @@ fn main() {
}, },
None => loop { None => loop {
cycle_num += 1; cycle_num += 1;
print_cycles(&cycle_num); // print_cycles(&cycle_num);
cpu.exec_next(); cpu.exec_next();
}, },
} }