From df49656b25bb62855c64d56c7a246e376c46762a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 16 Jan 2025 20:01:11 +1100 Subject: [PATCH] PS1: Implement more accurate thread sleeping --- misc/ps1/ps1defs.h | 2 +- src/Platform_PS1.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/misc/ps1/ps1defs.h b/misc/ps1/ps1defs.h index e4c10a006..5185f0db7 100644 --- a/misc/ps1/ps1defs.h +++ b/misc/ps1/ps1defs.h @@ -24,7 +24,7 @@ enum gp1_cmd_type { GP1_CMD_DMA_MODE = 0x04000000, }; -enum gp1_dma_mode { +enum gp1_cmd_dma_mode { GP1_DMA_NONE = 0, GP1_DMA_CPU_TO_GP0 = 2, }; diff --git a/src/Platform_PS1.c b/src/Platform_PS1.c index d6cbf9d79..eaeeee543 100644 --- a/src/Platform_PS1.c +++ b/src/Platform_PS1.c @@ -160,8 +160,12 @@ cc_result File_Length(cc_file file, cc_uint32* len) { *--------------------------------------------------------Threading--------------------------------------------------------* *#########################################################################################################################*/ void Thread_Sleep(cc_uint32 milliseconds) { - // TODO sleep a bit - VSync(0); + // Simulate sleep with a busy loop + cc_uint64 delay = (cc_uint64)milliseconds * F_CPU / (8 * 1000); + cc_uint32 delay_ = (cc_uint32)delay; + + for (cc_uint32 i = 0; i < delay_; i++) { __asm__ volatile(""); } + ChangeClearPAD(0); } void Thread_Run(void** handle, Thread_StartFunc func, int stackSize, const char* name) {