From 907f5140b04af9e5061120b6c7f701fdc6ccb088 Mon Sep 17 00:00:00 2001 From: kn0000 Date: Sun, 27 Jul 2025 02:08:19 +0100 Subject: [PATCH] Added keyboard input checking, yet to be tested though, but nothing that was working is broken. --- src/lib.rs | 2 ++ src/main.rs | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2e76ad447e3efc6d64a70773fe53d50fd4699e87..834c3f4bfa723f3757fef9e673c0ec8eefd595cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ pub const MEMORY_SIZE: usize = 1<<20; pub const SCREEN_WIDTH: usize = 512; pub const SCREEN_HEIGHT: usize = 512; pub const SCREEN_UPDATE_ADDRESS: usize = 0x7FFFF; +pub const KEYBOARD_INTERFACE_ADDRESS: usize = 480<<10; use minifb::Key; @@ -155,3 +156,4 @@ pub fn keys_to_state(keys: Vec) -> Vec { //output is using only 10 bit output } + diff --git a/src/main.rs b/src/main.rs index d377841f05efaace89c1c1e25ecd7cdbc477e37a..154a901d51bafff50c9e2b9f7aa932a22c964b1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use std::{fs, io}; -use minifb::{Window, WindowOptions, Key}; +use minifb::{Window, WindowOptions}; use implementation::*; fn main() { @@ -41,17 +41,19 @@ fn main() { let mut window = Window::new("STT Display", SCREEN_WIDTH, SCREEN_HEIGHT, WindowOptions::default()).unwrap(); window.update_with_buffer(&[0;(1<<14)],128,128).unwrap(); - let mut instructions_run = 0; while window.is_open() && processor.run() { if processor.memory[SCREEN_UPDATE_ADDRESS] != 0 { processor.memory[SCREEN_UPDATE_ADDRESS] = 0; window.update_with_buffer(&mem_to_buf(&processor.memory), SCREEN_WIDTH, SCREEN_HEIGHT).unwrap(); } - instructions_run += 1; - if instructions_run%1000 == 0 { - println!("Program running"); + + if processor.memory[KEYBOARD_INTERFACE_ADDRESS] != 0 { //update keyboard state + processor.memory[KEYBOARD_INTERFACE_ADDRESS] = 0; + for (i, value) in keys_to_state(window.get_keys()).iter().enumerate() { + processor.memory[KEYBOARD_INTERFACE_ADDRESS+i+1] = *value; + } } } - + println!("Stack A: {0:?}\nStack B: {1:?}", processor.stack_a, processor.stack_b); }