diff --git a/README.md b/README.md index 38d81fa..91b44c3 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,13 @@ Un petit simulateur de processeur pour les cours de L3 de l'ENS de Lyon -usage: cargo run --release path_to_bin \ No newline at end of file +usage: cargo run --release path_to_bin + +MMIO: +écran: à partir de 0x01000000 + - pixels en 0BGR, de en haut a gauche a en bas a droite. +clavier: 0x01200000 + - scancode (comme sim.py, != du simulateur c) +clock: 0x01200004 + - millisecondes écoulées depuis la création du simulateur + (nb: un u32 peut stocker 49 jours) diff --git a/src/cpu.rs b/src/cpu.rs index 500414f..688b1d3 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -4,7 +4,7 @@ use std::{ process::exit, sync::{Mutex, atomic::AtomicU32}, thread::sleep, - time::Duration, + time::{self, Duration, Instant}, }; use pixels::Pixels; @@ -157,6 +157,7 @@ impl From for Instruction { } pub struct Computer<'a, 'b> { + creation: Instant, ram: Box<[u32; 0x01000000 / 4]>, regs: [u32; 16], pc: usize, @@ -172,6 +173,7 @@ fn iot() -> ! { impl<'a, 'b> Computer<'a, 'b> { pub fn new(filename: String, screen: &'b Mutex>, key: &'b AtomicU32) -> Self { let mut new = Self { + creation: Instant::now(), ram: Box::new([0; 0x01000000 / 4]), regs: [0; 16], pc: 0, @@ -304,6 +306,8 @@ impl<'a, 'b> Computer<'a, 'b> { res } else if addr == 0x01200000 { self.key.load(std::sync::atomic::Ordering::Relaxed) + } else if addr == 0x01200004{ + time::Instant::now().duration_since(self.creation).as_millis() as u32 } else { iot(); },