Reworked the sync function to reduce input-lag by one frame and changed confusing documentation.

This commit is contained in:
jan 2025-01-08 19:21:15 +01:00
parent cf3306eeb2
commit 29f215ff9e
5 changed files with 12 additions and 13 deletions

2
Cargo.lock generated
View File

@ -539,7 +539,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "svc16"
version = "0.9.0"
version = "0.9.1"
dependencies = [
"anyhow",
"clap",

View File

@ -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"

View File

@ -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.

View File

@ -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;
}

View File

@ -87,7 +87,6 @@ async fn main() -> Result<()> {
}
ipf += 1;
}
#[cfg(feature = "gamepad")]
while let Some(event) = gilrs.next_event() {
gilrs.update(&event);