Skip to content

Commit

Permalink
Correct interrupts
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Dec 11, 2023
1 parent 10f5d60 commit 2b9fb24
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl CPU {
return 0;
}

let intf = self.mem.read(0xFFFF);
let inte = self.mem.read(0xFF0F);
let intf = self.mem.read(0xFF0F);
let inte = self.mem.read(0xFFFF);
let triggered = intf & inte;
if triggered == 0 {
return 0;
Expand Down
23 changes: 19 additions & 4 deletions src/mmu.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bitflags::bitflags;
use crate::gpu::GPU;
use crate::mode::GBMode;

Expand All @@ -6,18 +7,30 @@ pub struct MMU {
pub gpu: GPU,
wram: [u8; 0x8000],
hram: [u8; 0x7F],
interrupt: u8,
intf: Interrupts,
inte: Interrupts,
wram_bank: usize,
}

bitflags! {
pub struct Interrupts: u8 {
const JOYPAD = 0b0001_0000;
const SERIAL = 0b0000_1000;
const TIMER = 0b0000_0100;
const LCD = 0b0000_0010;
const V_BLANK = 0b0000_0001;
}
}

impl MMU {
pub fn new(mode: GBMode, rom: Vec<u8>) -> Self {
Self {
rom,
gpu: GPU::new(mode),
wram: [0; 0x8000],
hram: [0; 0x7f],
interrupt: 0,
intf: Interrupts::empty(),
inte: Interrupts::empty(),
wram_bank: 0x01
}
}
Expand All @@ -32,7 +45,8 @@ impl MMU {
0xF000..=0xFDFF => self.wram[a as usize - 0xF000 + 0x1000 * self.wram_bank],
0xFF40..=0xFF4F => self.gpu.read(a),
0xFF80..=0xFFFE => self.hram[a as usize - 0xFF80],
0xFFFF => self.interrupt,
0xFF0F => self.intf.bits(),
0xFFFF => self.inte.bits(),
_ => 0x00,
}
}
Expand All @@ -47,7 +61,8 @@ impl MMU {
0xF000..=0xFDFF => self.wram[a as usize - 0xF000 + 0x1000 * self.wram_bank] = v,
0xFF40..=0xFF4F => self.gpu.write(a, v),
0xFF80..=0xFFFE => self.hram[a as usize - 0xFF80] = v,
0xFFFF => self.interrupt = v,
0xFF0F => self.intf = Interrupts::from_bits(v).unwrap(),
0xFFFF => self.inte = Interrupts::from_bits(v).unwrap(),
_ => {},
}
}
Expand Down

0 comments on commit 2b9fb24

Please sign in to comment.