From 4dae2990084bfd68e9f8ce31df3802bec5b56dae 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 | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) 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 54d271e..769616f 100644 --- a/src/simulator/mod.rs +++ b/src/simulator/mod.rs @@ -2,7 +2,7 @@ pub mod machine; pub mod decode; pub mod print; pub mod mem_cmp; - +pub mod interrupt; pub mod global {