From c6e55799735158b1a174b7fd179d89ca5f5aacfb Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Wed, 4 Aug 2021 17:19:56 +0100 Subject: [PATCH] Redo the DPMS patch The first version can cause the RTG to reinitialize badly, causing PiStorm to die. This version will gracefully shutdown the RTG thread if DPMS is enabled and start the thread again when it wakes up. --- platforms/amiga/rtg/rtg-output-raylib.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/platforms/amiga/rtg/rtg-output-raylib.c b/platforms/amiga/rtg/rtg-output-raylib.c index b307c40..993fd79 100644 --- a/platforms/amiga/rtg/rtg-output-raylib.c +++ b/platforms/amiga/rtg/rtg-output-raylib.c @@ -26,7 +26,7 @@ #define DEBUG(...) #endif -uint8_t busy = 0, rtg_on = 0, rtg_initialized = 0, emulator_exiting = 0, rtg_output_in_vblank = 0, reinit = 0, rtg_dpms = 0; +uint8_t busy = 0, rtg_on = 0, rtg_initialized = 0, emulator_exiting = 0, rtg_output_in_vblank = 0, rtg_dpms = 0, shutdown = 0; extern uint8_t *rtg_mem, display_enabled; extern uint32_t framebuffer_addr; extern uint32_t framebuffer_addr_adj; @@ -193,7 +193,7 @@ void *rtgThread(void *args) { printf("RTG thread running\n"); fflush(stdout); - int old_filter_mode = -1; + int reinit = 0, old_filter_mode = -1; rtg_on = 1; uint32_t *indexed_buf = NULL; @@ -218,7 +218,6 @@ void *rtgThread(void *args) { Texture raylib_clut_texture; Image raylib_fb, raylib_cursor, raylib_clut; -reinit_raylib:; InitWindow(GetScreenWidth(), GetScreenHeight(), "Pistorm RTG"); HideCursor(); SetTargetFPS(60); @@ -245,6 +244,7 @@ reinit_raylib:; raylib_cursor.data = cursor_data; raylib_cursor_texture = LoadTextureFromImage(raylib_cursor); +reinit_raylib:; if (reinit) { printf("Reinitializing raylib...\n"); width = rtg_display_width; @@ -365,7 +365,7 @@ reinit_raylib:; DrawText("RTG is currently sleeping.", 16, 16, 12, RAYWHITE); EndDrawing(); } - if (pitch != *data->pitch || height != *data->height || width != *data->width || format != *data->format || reinit) { + if (pitch != *data->pitch || height != *data->height || width != *data->width || format != *data->format) { printf("Reinitializing due to something change.\n"); reinit = 1; goto shutdown_raylib; @@ -373,8 +373,12 @@ reinit_raylib:; if (emulator_exiting) { goto shutdown_raylib; } + if (shutdown) { + break; + } } + shutdown = 0; rtg_initialized = 0; printf("RTG thread shut down.\n"); @@ -407,11 +411,10 @@ void rtg_set_clut_entry(uint8_t index, uint32_t xrgb) { void rtg_init_display() { int err; + rtg_on = 1; if (rtg_dpms) { vc_tv_hdmi_power_on_preferred(); } - reinit = 1; - rtg_on = 1; if (!rtg_initialized) { err = pthread_create(&thread_id, NULL, &rtgThread, (void *)&rtg_share_data); @@ -431,11 +434,13 @@ void rtg_init_display() { void rtg_shutdown_display() { printf("RTG display disabled.\n"); - rtg_on = 0; - display_enabled = 0xFF; if (rtg_dpms) { + shutdown = 1; vc_tv_power_off(); } + + rtg_on = 0; + display_enabled = 0xFF; } void rtg_enable_mouse_cursor() {