From 2bc7ee5f42043bef024859dee210792676e87012 Mon Sep 17 00:00:00 2001 From: Dominic Grimm Date: Thu, 9 Mar 2023 17:05:33 +0100 Subject: [PATCH] Update --- Cargo.lock | 30 ++++++++++++++++++++++++++++++ examples/test.asm | 9 +++++++++ examples/test.bin | Bin 0 -> 32768 bytes hence/Cargo.toml | 2 +- hence/lib/core.asm | 1 + hence/lib/main.asm | 2 +- hence/src/emulator.rs | 11 ++++++++++- 7 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 examples/test.asm create mode 100644 examples/test.bin diff --git a/Cargo.lock b/Cargo.lock index 77c4d18..55313ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -231,6 +231,7 @@ dependencies = [ "rand", "rhexdump", "rust-embed", + "sdl2", "unescape", ] @@ -467,6 +468,29 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "sdl2" +version = "0.35.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7959277b623f1fb9e04aea73686c3ca52f01b2145f8ea16f4ff30d8b7623b1a" +dependencies = [ + "bitflags", + "lazy_static", + "libc", + "sdl2-sys", +] + +[[package]] +name = "sdl2-sys" +version = "0.35.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3586be2cf6c0a8099a79a12b4084357aa9b3e0b0d7980e3b67aaf7a9d55f9f0" +dependencies = [ + "cfg-if", + "libc", + "version-compare", +] + [[package]] name = "sha2" version = "0.10.6" @@ -544,6 +568,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "version-compare" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29" + [[package]] name = "version_check" version = "0.9.4" diff --git a/examples/test.asm b/examples/test.asm new file mode 100644 index 0000000..d9d7407 --- /dev/null +++ b/examples/test.asm @@ -0,0 +1,9 @@ +.include "$lib/core.asm" +.include "$lib/std.asm" +.include "$lib/main.asm" + +.jump_main + +main: .main main + +.std_stop diff --git a/examples/test.bin b/examples/test.bin new file mode 100644 index 0000000000000000000000000000000000000000..cfb7a72147d65c1039812315b9ec6c5ab8a20d16 GIT binary patch literal 32768 zcmeIu!3n@15CFl0vjYnb_&78*2TTK2AhVzSPd;C*jQ-9wPRqS3M1TMR0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U iAV7cs0RjXF5FkK+009C72oNAZfB*pk1TGfHX!Qf?q7Cc- literal 0 HcmV?d00001 diff --git a/hence/Cargo.toml b/hence/Cargo.toml index a39a5d4..271054c 100644 --- a/hence/Cargo.toml +++ b/hence/Cargo.toml @@ -9,7 +9,6 @@ repository = "https://git.dergrimm.net/dergrimm/hence.git" [dependencies] itertools = "0.10.2" -# num-parse = "0.1.2" clap = { version = "3.2.16", features = ["derive"] } rhexdump = "0.1.1" radix_fmt = "1" @@ -19,3 +18,4 @@ anyhow = { version = "1.0.62", features = ["backtrace"] } rust-embed = "6.4.0" unescape = "0.1.0" parse_int = "0.6.0" +sdl2 = "0.35" diff --git a/hence/lib/core.asm b/hence/lib/core.asm index f9dc64b..0c07a5f 100644 --- a/hence/lib/core.asm +++ b/hence/lib/core.asm @@ -49,3 +49,4 @@ .define CORE_ALU_BOL, 0x10 .define CORE_ALU_INV, 0x11 .define CORE_ALU_RND, 0x12 + .define CORE_ALU_TME, 0x13 diff --git a/hence/lib/main.asm b/hence/lib/main.asm index b061933..2cf6443 100644 --- a/hence/lib/main.asm +++ b/hence/lib/main.asm @@ -3,7 +3,7 @@ .requires "$lib/core.asm" .requires "$lib/std.asm" -.define lib_main_local_jump_main, (CORE_MEM_ST - 3 - 1) +.define lib_main_local_jump_main, (CORE_MEM_PRG_END - 3 - 1) .macro jump_main .std_jump lib_main_local_jump_main diff --git a/hence/src/emulator.rs b/hence/src/emulator.rs index 7a69a5d..5f873d0 100644 --- a/hence/src/emulator.rs +++ b/hence/src/emulator.rs @@ -3,6 +3,7 @@ use itertools::Itertools; use radix_fmt::radix; use std::cmp::Ordering; use std::io::{self, Write}; +use std::time::Instant; #[derive(Debug)] pub struct Data { @@ -17,6 +18,8 @@ pub struct Data { pub reg_b: u16, pub reg_c: u16, pub reg_d: u16, + pub time: u16, + pub last_time: Instant, memory: [u16; 16 * 1024], term: console::Term, } @@ -35,6 +38,8 @@ impl Data { reg_b: 0, reg_c: 0, reg_d: 0, + time: 0, + last_time: Instant::now(), memory: [0; 16 * 1024], term: console::Term::stdout(), } @@ -209,6 +214,11 @@ impl Data { 0x12 => { self.tmp = rand::random(); } + 0x13 => { + let time = Instant::now(); + self.tmp = self.last_time.elapsed().as_millis() as u16; + self.last_time = time; + } _ => bail!("Invalid ALU operation: 0x{}", radix(operation, 16)), } @@ -241,7 +251,6 @@ pub fn emulate(data: &mut Data) -> Result<()> { } 0x02 => { data.reg_sp = data.reg_sp.wrapping_sub(1); - data.memory[data.reg_sp as usize] = 0; } 0x03 => { data.tmp = data.reg_arg;