From 7a5036ff5111da0a884d793a7fb1a52628bd6bb5 Mon Sep 17 00:00:00 2001 From: beeanyew Date: Tue, 8 Jun 2021 11:13:29 +0200 Subject: [PATCH] Rework RTG WaitVerticalSync a bit --- platforms/amiga/rtg/rtg-output-raylib.c | 3 +++ platforms/amiga/rtg/rtg.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/platforms/amiga/rtg/rtg-output-raylib.c b/platforms/amiga/rtg/rtg-output-raylib.c index 9fc00fa..e29869b 100644 --- a/platforms/amiga/rtg/rtg-output-raylib.c +++ b/platforms/amiga/rtg/rtg-output-raylib.c @@ -33,6 +33,8 @@ extern uint16_t rtg_display_format; extern uint16_t rtg_pitch, rtg_total_rows; extern uint16_t rtg_offset_x, rtg_offset_y; +uint32_t cur_rtg_frame = 0; + static pthread_t thread_id; static uint8_t mouse_cursor_enabled = 0, cursor_image_updated = 0, updating_screen = 0, debug_palette = 0, show_fps = 0; static uint8_t mouse_cursor_w = 16, mouse_cursor_h = 16; @@ -269,6 +271,7 @@ reinit_raylib:; EndDrawing(); rtg_output_in_vblank = 1; + cur_rtg_frame++; if (format == RTGFMT_RBG565) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { diff --git a/platforms/amiga/rtg/rtg.c b/platforms/amiga/rtg/rtg.c index 7fd1fee..80c7538 100644 --- a/platforms/amiga/rtg/rtg.c +++ b/platforms/amiga/rtg/rtg.c @@ -92,6 +92,10 @@ unsigned int rtg_get_fb() { return PIGFX_RTG_BASE + PIGFX_REG_SIZE + framebuffer_addr_adj; } +uint8_t wait_vblank = 0; +uint32_t wait_rtg_frame = 0; +extern uint32_t cur_rtg_frame; + unsigned int rtg_read(uint32_t address, uint8_t mode) { //printf("%s read from RTG: %.8X\n", op_type_names[mode], address); if (address >= PIGFX_REG_SIZE) { @@ -115,6 +119,23 @@ unsigned int rtg_read(uint32_t address, uint8_t mode) { case RTG_COMMAND: return rtg_enabled ? 0xFFCF : 0x0000; case RTG_WAITVSYNC: + if (rtg_on) { + if (!wait_vblank && cur_rtg_frame != wait_rtg_frame) { + wait_rtg_frame = cur_rtg_frame; + if (wait_rtg_frame == 0) { + wait_rtg_frame = cur_rtg_frame; + } + if (wait_rtg_frame == 0) + printf("Wait RTG frame was zero!\n"); + wait_vblank = 1; + } + if (cur_rtg_frame != wait_rtg_frame && wait_vblank) { + wait_vblank = 0; + return 1; + } + else + return 0; + } // fallthrough case RTG_INVBLANK: return !rtg_on || rtg_output_in_vblank; -- 2.39.2