do not expose interrupts

This commit is contained in:
Corwin Kuiper 2021-03-07 01:05:41 +00:00
parent ac88468333
commit a034b2b83c

View file

@ -1,6 +1,6 @@
use crate::memory_mapped::MemoryMapped;
pub enum Interrupt {
pub(crate) enum Interrupt {
VBlank,
HBlank,
VCounter,
@ -20,21 +20,21 @@ pub enum Interrupt {
const ENABLED_INTERRUPTS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04000200) };
const INTERRUPTS_ENABLED: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04000208) };
pub fn enable(interrupt: Interrupt) {
pub(crate) fn enable(interrupt: Interrupt) {
let _interrupt_token = temporary_interrupt_disable();
let interrupt = interrupt as usize;
let enabled = ENABLED_INTERRUPTS.get() | (1 << (interrupt as u16));
ENABLED_INTERRUPTS.set(enabled);
}
pub fn disable(interrupt: Interrupt) {
pub(crate) fn disable(interrupt: Interrupt) {
let _interrupt_token = temporary_interrupt_disable();
let interrupt = interrupt as usize;
let enabled = ENABLED_INTERRUPTS.get() & !(1 << (interrupt as u16));
ENABLED_INTERRUPTS.set(enabled);
}
pub struct Disable {}
pub(crate) struct Disable {}
impl Drop for Disable {
fn drop(&mut self) {
@ -42,15 +42,15 @@ impl Drop for Disable {
}
}
pub fn temporary_interrupt_disable() -> Disable {
pub(crate) fn temporary_interrupt_disable() -> Disable {
disable_interrupts();
Disable {}
}
pub fn enable_interrupts() {
pub(crate) fn enable_interrupts() {
INTERRUPTS_ENABLED.set(1);
}
fn disable_interrupts() {
pub(crate) fn disable_interrupts() {
INTERRUPTS_ENABLED.set(0);
}