Rework RTG WaitVerticalSync a bit

This commit is contained in:
beeanyew
2021-06-08 11:13:29 +02:00
parent 90c802592b
commit 7a5036ff51
2 changed files with 24 additions and 0 deletions

View 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++) {

View 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;