From 29f215ff9eff13fe369300395d187622653395c6 Mon Sep 17 00:00:00 2001 From: jan Date: Wed, 8 Jan 2025 19:21:15 +0100 Subject: [PATCH] Reworked the sync function to reduce input-lag by one frame and changed confusing documentation. --- Cargo.lock | 2 +- Cargo.toml | 2 +- specification/specification.typ | 2 +- src/engine.rs | 18 +++++++++--------- src/main.rs | 1 - 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3dc6655..ca300ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -539,7 +539,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "svc16" -version = "0.9.0" +version = "0.9.1" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index a86f7fd..a0d467c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "svc16" -version = "0.9.0" +version = "0.9.1" edition = "2021" authors = ["Jan Neuendorf"] description = "An emulator for a simple virtual computer" diff --git a/specification/specification.typ b/specification/specification.typ index e9963e1..bc23bf7 100644 --- a/specification/specification.typ +++ b/specification/specification.typ @@ -104,7 +104,7 @@ These keys are supposed to represent the face buttons of an NES controller. The codes for the *A* and *B* keys also represent the left and right mouse buttons. On synchronization the new input is loaded into the input-buffer. -Before the first synchronization, both input codes are zero. +Before the first synchronization, the input codes are not accessible. The *position code* is the index of the pixel, the mouse is currently on. It follows the same convention as the screen index explained in @screen. diff --git a/src/engine.rs b/src/engine.rs index 9298673..b1e36a0 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -25,8 +25,8 @@ pub struct Engine { screen_buffer: [u16; MEMSIZE], utility_buffer: [u16; MEMSIZE], instruction_pointer: u16, - pos_code: u16, - key_code: u16, + pos_code_dest: u16, + key_code_dest: u16, sync_called: bool, expansion_triggered: bool, } @@ -62,8 +62,8 @@ impl Engine { screen_buffer: [0; MEMSIZE], utility_buffer: [0; MEMSIZE], instruction_pointer: 0, - pos_code: 0, - key_code: 0, + pos_code_dest: 0, + key_code_dest: 0, sync_called: false, expansion_triggered: false, } @@ -72,8 +72,8 @@ impl Engine { return self.sync_called; } pub fn set_input(&mut self, pos_code: u16, key_code: u16) { - self.pos_code = pos_code; - self.key_code = key_code; + self.set(self.pos_code_dest, pos_code); + self.set(self.key_code_dest, key_code); } pub fn perform_sync( &mut self, @@ -81,9 +81,9 @@ impl Engine { key_code: u16, buffer: &mut [u16; MEMSIZE], ) -> () { - self.set_input(pos_code, key_code); self.sync_called = false; *buffer = self.screen_buffer; + self.set_input(pos_code, key_code); if self.expansion_triggered { self.expansion_triggered = false; self.utility_buffer = [0; MEMSIZE]; @@ -216,8 +216,8 @@ impl Engine { } SYNC => { self.sync_called = true; - self.set(arg1, self.pos_code); - self.set(arg2, self.key_code); + self.pos_code_dest = arg1; + self.key_code_dest = arg2; if arg3 > 0 { self.expansion_triggered = true; } diff --git a/src/main.rs b/src/main.rs index cb23554..10cfc25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,7 +87,6 @@ async fn main() -> Result<()> { } ipf += 1; } - #[cfg(feature = "gamepad")] while let Some(event) = gilrs.next_event() { gilrs.update(&event);