From e4db7ec96bf4ca9085af49ceb871de655b80a308 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 1 Mar 2023 17:18:45 +0100 Subject: [PATCH] Implement interrupt --- src/simulator/interrupt.rs | 38 ++++++++++++++++++++++++++++++++++++++ src/simulator/mod.rs | 1 + 2 files changed, 39 insertions(+) create mode 100644 src/simulator/interrupt.rs diff --git a/src/simulator/interrupt.rs b/src/simulator/interrupt.rs new file mode 100644 index 0000000..8f71885 --- /dev/null +++ b/src/simulator/interrupt.rs @@ -0,0 +1,38 @@ + + +struct Interrupt { + level: InterruptStatus +} + +impl Interrupt { + + pub fn new() -> Self { + Self { + level: InterruptStatus::InterruptOff + } + } + + pub fn set_status(&mut self, newStatus: InterruptStatus) -> InterruptStatus { + let old = self.level; + self.level = newStatus; + if newStatus == InterruptStatus::InterruptOn && old == InterruptStatus::InterruptOff { + self.one_tick(1); + } + old + } + + fn one_tick(&self, nb_cycle: i32) { + todo!(); + } + + pub fn get_status(&self) -> InterruptStatus { + self.level + } + +} + +#[derive(PartialEq, Clone, Copy)] +pub enum InterruptStatus { + InterruptOff, + InterruptOn +} \ No newline at end of file diff --git a/src/simulator/mod.rs b/src/simulator/mod.rs index 6ee59e2..85a7d51 100644 --- a/src/simulator/mod.rs +++ b/src/simulator/mod.rs @@ -3,6 +3,7 @@ pub mod decode; pub mod print; pub mod mem_cmp; pub mod loader; +pub mod interrupt; pub mod global {