io: Remove interrupt circuitry (it doesn't belong there anyway)

This commit is contained in:
John 2024-07-09 01:42:55 -05:00
parent 73e52f6aea
commit ecde36b995

View File

@ -195,49 +195,3 @@ pub trait BusAux: BusIO {
self.read_arr(0x14e).ok().map(u16::from_be_bytes) self.read_arr(0x14e).ok().map(u16::from_be_bytes)
} }
} }
pub mod interrupt {
use super::BusIO;
use bitfield_struct::bitfield;
/// Interrupt Enable register
const IE: usize = 0xffff;
/// Interrupt Flags register
const IF: usize = 0xff0f;
#[bitfield(u8)]
#[derive(PartialEq, Eq)]
pub struct Interrupt {
vblank: bool,
lcd: bool,
timer: bool,
serial: bool,
joypad: bool,
#[bits(3)]
_reserved: (),
}
impl<B: BusIO> Interrupts for B {}
/// Functionality for working with [Interrupt]s
pub trait Interrupts: BusIO {
/// Gets the set of enabled [Interrupt]s
fn enabled(&self) -> Option<Interrupt> {
self.read(IE).map(Interrupt::from_bits)
}
/// Gets the set of raised [Interrupt]s
#[inline]
fn raised(&self) -> Option<Interrupt> {
self.read(IF).map(Interrupt::from_bits)
}
/// Raises [Interrupt]s with the provided mask.
fn raise(&mut self, int: Interrupt) {
let flags = self.raised().unwrap_or_default();
let _ = self.write(IF, flags.into_bits() | int.into_bits());
}
/// Clears [Interrupt]s with the provided mask.
fn clear(&mut self, int: Interrupt) {
let flags = self.raised().unwrap_or_default();
let _ = self.write(IF, flags.into_bits() & !int.into_bits());
}
}
}