ajout d'une clock par MMIO

This commit is contained in:
Mwa
2026-03-10 20:14:25 +01:00
parent c7ce6f6e69
commit e747425381
2 changed files with 15 additions and 2 deletions

View File

@@ -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
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)

View File

@@ -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<u32> 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<Pixels<'a>>, 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();
},