]> git.sesse.net Git - pistorm/commitdiff
Rework RTG WaitVerticalSync a bit
authorbeeanyew <beeanyew@gmail.com>
Tue, 8 Jun 2021 09:13:29 +0000 (11:13 +0200)
committerbeeanyew <beeanyew@gmail.com>
Tue, 8 Jun 2021 09:13:29 +0000 (11:13 +0200)
platforms/amiga/rtg/rtg-output-raylib.c
platforms/amiga/rtg/rtg.c

index 9fc00fac3ccf2f79d324bce2af260dc6cd904c73..e29869b73b4c9c8831a0592c602082b751052cb2 100644 (file)
@@ -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++) {
index 7fd1feebf97252a3bb0eeb296f7beec8056a4e99..80c75380281d520aa33a1cd687ca335a6e81b9dd 100644 (file)
@@ -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;