This commit is contained in:
Dominic Grimm 2023-03-09 17:05:33 +01:00
parent fe6086b45c
commit 2bc7ee5f42
No known key found for this signature in database
GPG key ID: 6F294212DEAAC530
7 changed files with 52 additions and 3 deletions

30
Cargo.lock generated
View file

@ -231,6 +231,7 @@ dependencies = [
"rand", "rand",
"rhexdump", "rhexdump",
"rust-embed", "rust-embed",
"sdl2",
"unescape", "unescape",
] ]
@ -467,6 +468,29 @@ dependencies = [
"winapi-util", "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]] [[package]]
name = "sha2" name = "sha2"
version = "0.10.6" version = "0.10.6"
@ -544,6 +568,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "version-compare"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"

9
examples/test.asm Normal file
View file

@ -0,0 +1,9 @@
.include "$lib/core.asm"
.include "$lib/std.asm"
.include "$lib/main.asm"
.jump_main
main: .main main
.std_stop

BIN
examples/test.bin Normal file

Binary file not shown.

View file

@ -9,7 +9,6 @@ repository = "https://git.dergrimm.net/dergrimm/hence.git"
[dependencies] [dependencies]
itertools = "0.10.2" itertools = "0.10.2"
# num-parse = "0.1.2"
clap = { version = "3.2.16", features = ["derive"] } clap = { version = "3.2.16", features = ["derive"] }
rhexdump = "0.1.1" rhexdump = "0.1.1"
radix_fmt = "1" radix_fmt = "1"
@ -19,3 +18,4 @@ anyhow = { version = "1.0.62", features = ["backtrace"] }
rust-embed = "6.4.0" rust-embed = "6.4.0"
unescape = "0.1.0" unescape = "0.1.0"
parse_int = "0.6.0" parse_int = "0.6.0"
sdl2 = "0.35"

View file

@ -49,3 +49,4 @@
.define CORE_ALU_BOL, 0x10 .define CORE_ALU_BOL, 0x10
.define CORE_ALU_INV, 0x11 .define CORE_ALU_INV, 0x11
.define CORE_ALU_RND, 0x12 .define CORE_ALU_RND, 0x12
.define CORE_ALU_TME, 0x13

View file

@ -3,7 +3,7 @@
.requires "$lib/core.asm" .requires "$lib/core.asm"
.requires "$lib/std.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 .macro jump_main
.std_jump lib_main_local_jump_main .std_jump lib_main_local_jump_main

View file

@ -3,6 +3,7 @@ use itertools::Itertools;
use radix_fmt::radix; use radix_fmt::radix;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::io::{self, Write}; use std::io::{self, Write};
use std::time::Instant;
#[derive(Debug)] #[derive(Debug)]
pub struct Data { pub struct Data {
@ -17,6 +18,8 @@ pub struct Data {
pub reg_b: u16, pub reg_b: u16,
pub reg_c: u16, pub reg_c: u16,
pub reg_d: u16, pub reg_d: u16,
pub time: u16,
pub last_time: Instant,
memory: [u16; 16 * 1024], memory: [u16; 16 * 1024],
term: console::Term, term: console::Term,
} }
@ -35,6 +38,8 @@ impl Data {
reg_b: 0, reg_b: 0,
reg_c: 0, reg_c: 0,
reg_d: 0, reg_d: 0,
time: 0,
last_time: Instant::now(),
memory: [0; 16 * 1024], memory: [0; 16 * 1024],
term: console::Term::stdout(), term: console::Term::stdout(),
} }
@ -209,6 +214,11 @@ impl Data {
0x12 => { 0x12 => {
self.tmp = rand::random(); 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)), _ => bail!("Invalid ALU operation: 0x{}", radix(operation, 16)),
} }
@ -241,7 +251,6 @@ pub fn emulate(data: &mut Data) -> Result<()> {
} }
0x02 => { 0x02 => {
data.reg_sp = data.reg_sp.wrapping_sub(1); data.reg_sp = data.reg_sp.wrapping_sub(1);
data.memory[data.reg_sp as usize] = 0;
} }
0x03 => { 0x03 => {
data.tmp = data.reg_arg; data.tmp = data.reg_arg;