From c68b300d5e05859317edd156fe5deca6ab86839e Mon Sep 17 00:00:00 2001 From: bQUARKz Date: Sun, 8 Feb 2026 12:00:05 +0000 Subject: [PATCH] fixed issues with flickering on frame sync --- crates/prometeu-kernel/src/prometeu_os.rs | 16 +++++++++++++++- test-cartridges/test01/run.sh | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 test-cartridges/test01/run.sh diff --git a/crates/prometeu-kernel/src/prometeu_os.rs b/crates/prometeu-kernel/src/prometeu_os.rs index bcf55937..a64ffa4a 100644 --- a/crates/prometeu-kernel/src/prometeu_os.rs +++ b/crates/prometeu-kernel/src/prometeu_os.rs @@ -68,6 +68,10 @@ pub struct PrometeuOS { /// Debugging flag to execute exactly one instruction or frame regardless of budget. pub debug_step_request: bool, + /// When true, the next logical frame must rearm the entrypoint call before running + /// to avoid resuming at a pending RET after a FRAME_SYNC safe point. + needs_prepare_entry_call: bool, + /// Wall-clock time of system startup. boot_time: Instant, } @@ -109,6 +113,7 @@ impl PrometeuOS { certifier: Certifier::new(cap_config.unwrap_or_default()), paused: false, debug_step_request: false, + needs_prepare_entry_call: false, boot_time, }; @@ -218,8 +223,11 @@ impl PrometeuOS { // If the VM is not currently executing a function (e.g. at the start of the app // or after the entrypoint function returned), we prepare a new call to the entrypoint. - if vm.call_stack.is_empty() { + // Additionally, if the previous slice ended with FRAME_SYNC, we must force a rearm + // so we don't resume execution at a pending RET on the next tick. + if self.needs_prepare_entry_call || vm.call_stack.is_empty() { vm.prepare_call(&self.current_entrypoint); + self.needs_prepare_entry_call = false; } // Reset telemetry for the new logical frame @@ -285,6 +293,12 @@ impl PrometeuOS { self.logical_frame_active = false; self.logical_frame_remaining_cycles = 0; + // If the slice ended in FRAME_SYNC, ensure the next tick starts a fresh + // call to the entrypoint instead of resuming at the RET that follows. + if run.reason == LogicalFrameEndingReason::FrameSync { + self.needs_prepare_entry_call = true; + } + // If we were doing a "step frame" debug command, pause now that the frame is done. if self.debug_step_request { self.paused = true; diff --git a/test-cartridges/test01/run.sh b/test-cartridges/test01/run.sh new file mode 100755 index 00000000..473d9e14 --- /dev/null +++ b/test-cartridges/test01/run.sh @@ -0,0 +1,7 @@ +#!/bin/zsh + +set -e + +sdk/prometeu build . +cp build/program.pbc cartridge/program.pbc +sdk/prometeu run cartridge