shithub: psxe

Download patch

ref: 4b2b73a2e6d6a4b2c1eccca9e5b52aa5c3d0f094
parent: 563a4d774d0214245d07197199a0c91f021ecac0
author: allkern <lisandroaalarcon@gmail.com>
date: Thu Jun 29 05:57:21 EDT 2023

Add API to toggle screen debug mode

--- /dev/null
+++ b/frontend/common.h
@@ -1,0 +1,17 @@
+#ifndef COMMON_H
+#define COMMON_H
+
+#ifndef OS_INFO
+#define OS_INFO unknown
+#endif
+#ifndef REP_VERSION
+#define REP_VERSION latest
+#endif
+#ifndef REP_COMMIT_HASH
+#define REP_COMMIT_HASH latest
+#endif
+
+#define STR1(m) #m
+#define STR(m) STR1(m)
+
+#endif
\ No newline at end of file
--- a/frontend/config.c
+++ b/frontend/config.c
@@ -2,19 +2,7 @@
 #include <stdlib.h>
 
 #include "config.h"
-
-#ifndef OS_INFO
-#define OS_INFO unknown
-#endif
-#ifndef REP_VERSION
-#define REP_VERSION latest
-#endif
-#ifndef REP_COMMIT_HASH
-#define REP_COMMIT_HASH latest
-#endif
-
-#define STR1(m) #m
-#define STR(m) STR1(m)
+#include "common.h"
 
 static const char* g_version_text =
 #ifdef _WIN32
--- a/frontend/screen.c
+++ b/frontend/screen.c
@@ -1,7 +1,5 @@
 #include "screen.h"
 
-// #define PSXE_SCREEN_DEBUG 1
-
 psxe_screen_t* psxe_screen_create() {
     return (psxe_screen_t*)malloc(sizeof(psxe_screen_t));
 }
@@ -9,13 +7,14 @@
 void psxe_screen_init(psxe_screen_t* screen, psx_t* psx) {
     memset(screen, 0, sizeof(psxe_screen_t));
 
-#ifdef PSXE_SCREEN_DEBUG
-    screen->width = PSX_GPU_FB_WIDTH;
-    screen->height = PSX_GPU_FB_HEIGHT;
-#else
-    screen->width = 320;
-    screen->height = 240;
-#endif
+    if (screen->debug_mode) {
+        screen->width = PSX_GPU_FB_WIDTH;
+        screen->height = PSX_GPU_FB_HEIGHT;
+    } else {
+        screen->width = 320;
+        screen->height = 240;
+    }
+
     screen->scale = 1;
     screen->open = 1;
     screen->psx = psx;
@@ -22,11 +21,11 @@
 
     SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
 
-    SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", "2");
+    SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", "0");
 }
 
 void psxe_screen_reload(psxe_screen_t* screen) {
-    SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", "2");
+    SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", "0");
 
     if (screen->texture) SDL_DestroyTexture(screen->texture);
     if (screen->renderer) SDL_DestroyRenderer(screen->renderer);
@@ -33,7 +32,7 @@
     if (screen->window) SDL_DestroyWindow(screen->window);
 
     screen->window = SDL_CreateWindow(
-        "PSXE",
+        "psxe " STR(REP_VERSION) "-" STR(REP_COMMIT_HASH),
         SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
         screen->width * screen->scale,
         screen->height * screen->scale,
@@ -72,6 +71,12 @@
     return screen->open;
 }
 
+void psxe_screen_toggle_debug_mode(psxe_screen_t* screen) {
+    screen->debug_mode = !screen->debug_mode;
+
+    psxe_screen_reload(screen);
+}
+
 void psxe_screen_update(psxe_screen_t* screen) {
     void* display_buf = psx_get_display_buffer(screen->psx);
 
@@ -91,13 +96,13 @@
 }
 
 void psxe_screen_set_scale(psxe_screen_t* screen, unsigned int scale) {
-#ifdef PSXE_SCREEN_DEBUG
-    screen->scale = 1;
-    screen->saved_scale = 1;
-#else
-    screen->scale = scale;
-    screen->saved_scale = scale;
-#endif
+    if (screen->debug_mode) {
+        screen->scale = 1;
+        screen->saved_scale = 1;
+    } else {
+        screen->scale = scale;
+        screen->saved_scale = scale;
+    }
 }
 
 void psxe_screen_destroy(psxe_screen_t* screen) {
@@ -113,14 +118,14 @@
 void psxe_gpu_dmode_event_cb(psx_gpu_t* gpu) {
     psxe_screen_t* screen = gpu->udata[0];
 
-#ifdef PSXE_SCREEN_DEBUG
-    screen->width = PSX_GPU_FB_WIDTH;
-    screen->height = PSX_GPU_FB_HEIGHT;
-#else
-    screen->width = psx_get_display_width(screen->psx);
-    screen->height = psx_get_display_height(screen->psx);
-#endif
-    
+    if (screen->debug_mode) {
+        screen->width = PSX_GPU_FB_WIDTH;
+        screen->height = PSX_GPU_FB_HEIGHT;
+    } else {
+        screen->width = psx_get_display_width(screen->psx);
+        screen->height = psx_get_display_height(screen->psx);
+    }
+
     if (screen->width > 512) {
         screen->saved_scale = screen->scale;
         screen->scale = 1;
--- a/frontend/screen.h
+++ b/frontend/screen.h
@@ -2,6 +2,7 @@
 #define SCREEN_H
 
 #include "psx/psx.h"
+#include "common.h"
 
 #include <string.h>
 
@@ -17,6 +18,7 @@
     unsigned int saved_scale;
     unsigned int width, height, scale;
 
+    int debug_mode;
     int open;
 } psxe_screen_t;
 
@@ -27,6 +29,7 @@
 void psxe_screen_update(psxe_screen_t*);
 void psxe_screen_destroy(psxe_screen_t*);
 void psxe_screen_set_scale(psxe_screen_t*, unsigned int);
+void psxe_screen_toggle_debug_mode(psxe_screen_t*);
 
 // GPU event handlers
 void psxe_gpu_dmode_event_cb(psx_gpu_t*);
--