Skip to content

Commit 6a72445

Browse files
committed
Improve video sync
Added a Vblank callback
1 parent 447c1d2 commit 6a72445

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

frontend/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ int main(int argc, const char* argv[]) {
2525
psxe_screen_reload(screen);
2626

2727
psx_gpu_set_event_callback(gpu, GPU_EVENT_DMODE, psxe_gpu_dmode_event_cb);
28+
psx_gpu_set_event_callback(gpu, GPU_EVENT_VBLANK, psxe_gpu_vblank_event_cb);
2829
psx_gpu_set_udata(gpu, 0, screen);
2930

3031
if (cfg->exe) {
@@ -36,9 +37,8 @@ int main(int argc, const char* argv[]) {
3637
}
3738

3839
while (psxe_screen_is_open(screen)) {
39-
psx_run_frame(psx);
40-
41-
psxe_screen_update(screen);
40+
// psx_run_frame(psx);
41+
psx_update(psx);
4242
}
4343

4444
psx_cpu_t* cpu = psx_get_cpu(psx);

frontend/screen.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,10 @@ void psxe_gpu_dmode_event_cb(psx_gpu_t* gpu) {
186186
screen->width * screen->scale,
187187
screen->height * screen->scale
188188
);
189+
}
190+
191+
void psxe_gpu_vblank_event_cb(psx_gpu_t* gpu) {
192+
psxe_screen_t* screen = gpu->udata[0];
193+
194+
psxe_screen_update(screen);
189195
}

frontend/screen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ void psxe_screen_toggle_debug_mode(psxe_screen_t*);
3535

3636
// GPU event handlers
3737
void psxe_gpu_dmode_event_cb(psx_gpu_t*);
38+
void psxe_gpu_vblank_event_cb(psx_gpu_t*);
3839

3940
#endif

psx/dev/gpu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,9 @@ void gpu_scanline_event(psx_gpu_t* gpu) {
889889
}
890890

891891
if (gpu->line == GPU_SCANS_PER_VDRAW_NTSC) {
892+
if (gpu->event_cb_table[GPU_EVENT_VBLANK])
893+
gpu->event_cb_table[GPU_EVENT_VBLANK](gpu);
894+
892895
psx_ic_irq(gpu->ic, IC_VBLANK);
893896
} else if (gpu->line == GPU_SCANS_PER_FRAME_NTSC) {
894897
gpu->line = 0;

0 commit comments

Comments
 (0)