shithub: psxe

Download patch

ref: a08cd7d4da4c30d76f0ef8db08a484300b7474ae
parent: 0f73e41c1fa19b5e13345f35024f182143edb068
author: allkern <lisandroaalarcon@gmail.com>
date: Wed Aug 2 12:49:22 EDT 2023

Add `get_vram` API, fix 368 resolution

--- a/frontend/screen.c
+++ b/frontend/screen.c
@@ -95,7 +95,8 @@
 }
 
 void psxe_screen_update(psxe_screen_t* screen) {
-    void* display_buf = psx_get_display_buffer(screen->psx);
+    void* display_buf = screen->debug_mode ?
+        psx_get_vram(screen->psx) : psx_get_display_buffer(screen->psx);
 
     SDL_UpdateTexture(screen->texture, NULL, display_buf, PSX_GPU_FB_STRIDE);
     SDL_RenderCopy(screen->renderer, screen->texture, NULL, NULL);
--- a/psx/dev/cdrom.c
+++ b/psx/dev/cdrom.c
@@ -297,8 +297,7 @@
                 return;
             }
 
-            PFIFO_POP;
-            PFIFO_POP;
+            cdrom->pfifo_index = 0;
 
             cdrom->irq_delay = DELAY_1MS;
             cdrom->delayed_command = CDL_SETFILTER;
--- a/psx/dev/gpu.c
+++ b/psx/dev/gpu.c
@@ -944,6 +944,14 @@
             switch (cmd) {
                 case 0x04: {
                 } break;
+                case 0x05: {
+                    gpu->disp_x = value & 0x3ff;
+                    gpu->disp_y = (value >> 10) & 0x1ff;
+                } break;
+                case 0x06: {
+                    gpu->disp_x1 = value & 0xfff;
+                    gpu->disp_x2 = (value >> 12) & 0xfff;
+                } break;
                 case 0x08:
                     gpu->display_mode = value & 0xffffff;
 
--- a/psx/dev/gpu.h
+++ b/psx/dev/gpu.h
@@ -107,6 +107,8 @@
 
     // Display area
     uint32_t disp_x, disp_y;
+    uint32_t disp_x1, disp_x2;
+    uint32_t disp_y1, disp_y2;
 
     // Timing and IRQs
     float cycles;
--- a/psx/psx.c
+++ b/psx/psx.c
@@ -48,12 +48,20 @@
     return psx_gpu_get_display_buffer(psx->gpu);
 }
 
+void* psx_get_vram(psx_t* psx) {
+    return psx->gpu->vram;
+}
+
 uint32_t psx_get_display_width(psx_t* psx) {
     static int dmode_hres_table[] = {
         256, 320, 512, 640
     };
 
-    return dmode_hres_table[psx->gpu->display_mode & 0x3];
+    if (psx->gpu->display_mode & 0x40) {
+        return 368;
+    } else {
+        return dmode_hres_table[psx->gpu->display_mode & 0x3];
+    }
 }
 
 uint32_t psx_get_display_height(psx_t* psx) {
--- a/psx/psx.h
+++ b/psx/psx.h
@@ -37,6 +37,7 @@
 void psx_update(psx_t*);
 void psx_run_frame(psx_t*);
 void* psx_get_display_buffer(psx_t*);
+void* psx_get_vram(psx_t*);
 uint32_t psx_get_display_width(psx_t*);
 uint32_t psx_get_display_height(psx_t*);
 uint32_t psx_get_display_format(psx_t*);
--