From 9970a04cc988d8de5a54097620bafb2cca09636e Mon Sep 17 00:00:00 2001 From: Ry Date: Fri, 9 Sep 2022 16:16:09 -0700 Subject: [PATCH] Implement an RTC, bump version to 0.4.0 --- Cargo.lock | 30 ++++++++++++++++++++++++++++-- Cargo.toml | 3 ++- src/bus.rs | 30 ++++++++++++++++++++++++++++++ src/main.rs | 2 ++ 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ccfda5..3c45f67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -349,6 +349,20 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" +[[package]] +name = "chrono" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6127248204b9aba09a362f6c930ef6a78f2c1b2215f8a7b398c06e1083f17af0" +dependencies = [ + "js-sys", + "num-integer", + "num-traits", + "time 0.1.44", + "wasm-bindgen", + "winapi", +] + [[package]] name = "clang-sys" version = "1.3.1" @@ -852,9 +866,10 @@ dependencies = [ [[package]] name = "fox32" -version = "0.3.1" +version = "0.4.0" dependencies = [ "anyhow", + "chrono", "image", "log", "pixels", @@ -2557,6 +2572,17 @@ dependencies = [ "weezl", ] +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + [[package]] name = "time" version = "0.3.13" @@ -2665,7 +2691,7 @@ dependencies = [ "git2", "rustversion", "thiserror", - "time", + "time 0.3.13", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 04d602c..ed39913 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,12 @@ [package] name = "fox32" -version = "0.3.1" +version = "0.4.0" authors = ["ry"] edition = "2021" build = "build.rs" [dependencies] +chrono = "0.4" image = "0.24" log = "0.4" pixels = "0.9.0" diff --git a/src/bus.rs b/src/bus.rs index 486b899..51185fc 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -2,6 +2,7 @@ use crate::{Memory, AudioChannel, DiskController, Keyboard, Mouse, Overlay}; +use chrono::prelude::*; use std::sync::{Arc, Mutex}; use std::io::{Write, stdout}; @@ -19,6 +20,8 @@ pub struct Bus { pub mouse: Arc>, pub overlays: Arc>>, + + pub startup_time: i64, } impl Bus { @@ -109,6 +112,33 @@ impl Bus { _ => panic!("invalid audio channel"), } } + 0x80000700..=0x80000706 => { // RTC port + let setting = (port & 0x000000FF) as u8; + match setting { + 0 => { // year + Local::now().year() as u32 + }, + 1 => { // month + Local::now().month() + }, + 2 => { // day + Local::now().day() + }, + 3 => { // hour + Local::now().hour() + }, + 4 => { // minute + Local::now().minute() + }, + 5 => { // second + Local::now().second() + }, + 6 => { // milliseconds elapsed since startup + (Local::now().timestamp_millis() - self.startup_time) as u32 + }, + _ => panic!("invalid RTC port"), + } + } 0x80001000..=0x80002003 => { // disk controller port let id = port as u8; let operation = (port & 0x0000F000) >> 8; diff --git a/src/main.rs b/src/main.rs index 0773712..940d28a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ use std::process::exit; use std::env; use std::fs::{File, read}; +use chrono::prelude::*; use image; use log::error; use pixels::{Pixels, SurfaceTexture}; @@ -97,6 +98,7 @@ fn main() { keyboard: keyboard.clone(), mouse: mouse.clone(), overlays: display.overlays.clone(), + startup_time: Local::now().timestamp_millis(), }; if args.len() > 1 {