From 0498f90e33c864784a80996a9a1494e763041029 Mon Sep 17 00:00:00 2001 From: kn0000 Date: Sat, 26 Jul 2025 18:22:26 +0100 Subject: [PATCH] Added helper function for keyboard input --- src/lib.rs | 16 ++++++++++++++++ src/main.rs | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 2921be25fcfb6a13fa4f28941de1bfefe737002d..2e76ad447e3efc6d64a70773fe53d50fd4699e87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,8 @@ pub const SCREEN_WIDTH: usize = 512; pub const SCREEN_HEIGHT: usize = 512; pub const SCREEN_UPDATE_ADDRESS: usize = 0x7FFFF; +use minifb::Key; + #[derive(Debug)] pub struct Stack { buffer: [u16;STACK_SIZE], @@ -139,3 +141,17 @@ pub fn mem_to_buf(memory: &[u16]) -> Vec { } result } + +pub fn keys_to_state(keys: Vec) -> Vec { //output is using only 10 bits each to match with + let mut result = 0u128; //rest of system + for key in keys { //see minifb docs for what number each key is + result &= 1 << (key as usize); + } + let mut output = Vec::new(); + for i in 0..11 { + let slice = ((result>>(10*i))&0x3FF) as u16; + output.push(slice); + } + output +} + diff --git a/src/main.rs b/src/main.rs index 5f38a27af597569e1e7acec407a39705b720efb7..d377841f05efaace89c1c1e25ecd7cdbc477e37a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use std::{fs, io}; -use minifb::{Window, WindowOptions}; +use minifb::{Window, WindowOptions, Key}; use implementation::*; fn main() {