mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-27 09:36:39 +11:00
move enable and disable to impl
This commit is contained in:
parent
476b030b41
commit
5093884612
1 changed files with 44 additions and 42 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -56,8 +54,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -67,6 +65,10 @@ 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 {}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue