move enable and disable to impl

This commit is contained in:
Corwin Kuiper 2021-08-06 23:32:06 +01:00
parent 476b030b41
commit 5093884612

View file

@ -25,27 +25,25 @@ pub enum Interrupt {
Gamepak = 13, Gamepak = 13,
} }
const ENABLED_INTERRUPTS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04000200) }; impl Interrupt {
const INTERRUPTS_ENABLED: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04000208) }; fn enable(self) {
fn enable(interrupt: Interrupt) {
let _interrupt_token = temporary_interrupt_disable(); let _interrupt_token = temporary_interrupt_disable();
other_things_to_enable_interrupt(interrupt); self.other_things_to_enable_interrupt();
let interrupt = interrupt as usize; let interrupt = self as usize;
let enabled = ENABLED_INTERRUPTS.get() | (1 << (interrupt as u16)); let enabled = ENABLED_INTERRUPTS.get() | (1 << (interrupt as u16));
ENABLED_INTERRUPTS.set(enabled); ENABLED_INTERRUPTS.set(enabled);
} }
fn disable(interrupt: Interrupt) { fn disable(self) {
let _interrupt_token = temporary_interrupt_disable(); let _interrupt_token = temporary_interrupt_disable();
other_things_to_disable_interrupt(interrupt); self.other_things_to_disable_interrupt();
let interrupt = interrupt as usize; let interrupt = self as usize;
let enabled = ENABLED_INTERRUPTS.get() & !(1 << (interrupt as u16)); let enabled = ENABLED_INTERRUPTS.get() & !(1 << (interrupt as u16));
ENABLED_INTERRUPTS.set(enabled); ENABLED_INTERRUPTS.set(enabled);
} }
fn other_things_to_enable_interrupt(interrupt: Interrupt) { fn other_things_to_enable_interrupt(self) {
match interrupt { match self {
Interrupt::VBlank => { Interrupt::VBlank => {
DISPLAY_STATUS.set_bits(1, 1, 3); DISPLAY_STATUS.set_bits(1, 1, 3);
} }
@ -54,10 +52,10 @@ fn other_things_to_enable_interrupt(interrupt: Interrupt) {
} }
_ => {} _ => {}
} }
} }
fn other_things_to_disable_interrupt(interrupt: Interrupt) { fn other_things_to_disable_interrupt(self) {
match interrupt { match self {
Interrupt::VBlank => { Interrupt::VBlank => {
DISPLAY_STATUS.set_bits(0, 1, 3); DISPLAY_STATUS.set_bits(0, 1, 3);
} }
@ -66,8 +64,12 @@ fn other_things_to_disable_interrupt(interrupt: Interrupt) {
} }
_ => {} _ => {}
} }
}
} }
const ENABLED_INTERRUPTS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04000200) };
const INTERRUPTS_ENABLED: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04000208) };
struct Disable {} struct Disable {}
impl Drop for Disable { impl Drop for Disable {
@ -107,7 +109,7 @@ impl InterruptRoot {
fn reduce(&self) { fn reduce(&self) {
let new_count = self.count.get() - 1; let new_count = self.count.get() - 1;
if new_count == 0 { if new_count == 0 {
disable(self.interrupt); self.interrupt.disable();
} }
self.count.set(new_count); self.count.set(new_count);
} }
@ -115,7 +117,7 @@ impl InterruptRoot {
fn add(&self) { fn add(&self) {
let count = self.count.get(); let count = self.count.get();
if count == 0 { if count == 0 {
enable(self.interrupt); self.interrupt.enable();
} }
self.count.set(count + 1); self.count.set(count + 1);
} }