pub const IRQ2: u8 = 0b0000_0001;
pub const IRQ1: u8 = 0b0000_0010;
pub const TIQ: u8 = 0b0000_0100;
#[derive(Clone, Copy, Debug, Default)]
pub struct InterruptController {
disable: u8,
}
impl InterruptController {
#[must_use]
pub const fn new() -> Self {
Self { disable: 0 }
}
#[must_use]
pub const fn read(&self, offset: u16, sources: u8) -> u8 {
match offset & 0x03 {
0x02 => self.disable,
0x03 => sources & 0x07,
_ => 0xFF,
}
}
pub const fn write(&mut self, offset: u16, value: u8) -> bool {
match offset & 0x03 {
0x02 => {
self.disable = value & 0x07;
false
}
0x03 => true,
_ => false,
}
}
#[must_use]
pub const fn active(&self, sources: u8) -> u8 {
sources & !self.disable & 0x07
}
#[must_use]
pub const fn pending(&self, sources: u8) -> bool {
self.active(sources) != 0
}
}