From: beeanyew Date: Thu, 3 Jun 2021 20:48:52 +0000 (+0200) Subject: Add somewhat proper RTG vsync handling X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=ceebc59532553f7903c3a4219e663d905ad9fb34;p=pistorm Add somewhat proper RTG vsync handling --- diff --git a/platforms/amiga/rtg/rtg-output-raylib.c b/platforms/amiga/rtg/rtg-output-raylib.c index 5f33fda..ddca531 100644 --- a/platforms/amiga/rtg/rtg-output-raylib.c +++ b/platforms/amiga/rtg/rtg-output-raylib.c @@ -23,7 +23,7 @@ #define DEBUG(...) #endif -uint8_t busy = 0, rtg_on = 0, rtg_initialized = 0, emulator_exiting = 0; +uint8_t busy = 0, rtg_on = 0, rtg_initialized = 0, emulator_exiting = 0, rtg_output_in_vblank = 0; extern uint8_t *rtg_mem; extern uint32_t framebuffer_addr; extern uint32_t framebuffer_addr_adj; @@ -164,6 +164,8 @@ reinit_raylib:; raylib_texture = LoadTextureFromImage(raylib_fb); + printf("Loaded framebuffer texture.\n"); + srcrect.x = srcrect.y = 0; srcrect.width = width; srcrect.height = height; @@ -222,6 +224,7 @@ reinit_raylib:; while (1) { if (rtg_on) { BeginDrawing(); + rtg_output_in_vblank = 0; updating_screen = 1; switch (format) { @@ -265,6 +268,7 @@ reinit_raylib:; } EndDrawing(); + rtg_output_in_vblank = 1; 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 91e4e77..8ec0061 100644 --- a/platforms/amiga/rtg/rtg.c +++ b/platforms/amiga/rtg/rtg.c @@ -41,7 +41,7 @@ static void handle_irtg_command(uint32_t cmd); uint8_t realtime_graphics_debug = 0; extern int cpu_emulation_running; extern struct emulator_config *cfg; -extern uint8_t rtg_on; +extern uint8_t rtg_on, rtg_output_in_vblank; //#define DEBUG_RTG @@ -94,9 +94,6 @@ unsigned int rtg_get_fb() { unsigned int rtg_read(uint32_t address, uint8_t mode) { //printf("%s read from RTG: %.8X\n", op_type_names[mode], address); - if (address == RTG_COMMAND) { - return 0xFFCF; - } if (address >= PIGFX_REG_SIZE) { if (rtg_mem && (address - PIGFX_REG_SIZE) < PIGFX_UPPER) { switch (mode) { @@ -114,6 +111,16 @@ unsigned int rtg_read(uint32_t address, uint8_t mode) { } } } + switch (address) { + case RTG_COMMAND: + return 0xFFCF; + case RTG_WAITVSYNC: + // fallthrough + case RTG_INVBLANK: + return !rtg_on || rtg_output_in_vblank; + default: + break; + } return 0; } diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c b/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c index bf8b793..eb0bb57 100644 --- a/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c +++ b/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c @@ -80,6 +80,7 @@ void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)); void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane)); void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle)); +BOOL GetVSyncState(__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle)); void FillRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(ULONG color), __REGD5(UBYTE mask), __REGD7(RGBFTYPE format)); void InvertRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(UBYTE mask), __REGD7(RGBFTYPE format)); @@ -305,7 +306,7 @@ int __attribute__((used)) InitCard(__REGA0(struct BoardInfo* b)) { //b->SetSplitPosition = (void *)NULL; //b->ReInitMemory = (void *)NULL; //b->WriteYUVRect = (void *)NULL; - //b->GetVSyncState = (void *)NULL; + b->GetVSyncState = (void *)GetVSyncState; //b->GetVBeamPos = (void *)NULL; //b->SetDPMSLevel = (void *)NULL; //b->ResetChip = (void *)NULL; @@ -461,8 +462,18 @@ void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)) { void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane)) { } +static uint16_t vblank; + void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle)) { - // I don't know why this one has a bool in D0, but it isn't used for anything. + vblank = 0; + do { + READSHORT(RTG_WAITVSYNC, vblank); + } while (!vblank); +} + +BOOL GetVSyncState(__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle)) { + READSHORT(RTG_INVBLANK, vblank); + return vblank; } void FillRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(ULONG color), __REGD5(UBYTE mask), __REGD7(RGBFTYPE format)) { diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card index 1f7e20a..83cda5b 100644 Binary files a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card and b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card differ diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card index b837484..c87da7c 100644 Binary files a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card and b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card differ diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card b/platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card index 1f7e20a..83cda5b 100644 Binary files a/platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card and b/platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card differ diff --git a/platforms/amiga/rtg/rtg_enums.h b/platforms/amiga/rtg/rtg_enums.h index 4f0688b..d25778e 100644 --- a/platforms/amiga/rtg/rtg_enums.h +++ b/platforms/amiga/rtg/rtg_enums.h @@ -27,6 +27,8 @@ enum pi_regs { RTG_ADDR3 = 0x30, RTG_ADDR4 = 0x34, RTG_DEBUGME = 0x50, + RTG_WAITVSYNC = 0x60, + RTG_INVBLANK = 0x62, IRTG_COMMAND = 0x60, };