]> git.sesse.net Git - pistorm/blobdiff - platforms/amiga/rtg/rtg-output-raylib.c
Some RTG fixes
[pistorm] / platforms / amiga / rtg / rtg-output-raylib.c
index 672eab730b9ba22dd7098f92c5c2283dc4ee3c9c..9fc00fac3ccf2f79d324bce2af260dc6cd904c73 100644 (file)
 
 #define RTG_INIT_ERR(a) { printf(a); *data->running = 0; }
 
-uint8_t busy = 0, rtg_on = 0, rtg_initialized = 0;
-extern uint8_t *rtg_mem;
+//#define DEBUG_RAYLIB_RTG
+
+#ifdef DEBUG_RAYLIB_RTG
+#define DEBUG printf
+#else
+#define DEBUG(...)
+#endif
+
+uint8_t busy = 0, rtg_on = 0, rtg_initialized = 0, emulator_exiting = 0, rtg_output_in_vblank = 0;
+extern uint8_t *rtg_mem, display_enabled;
 extern uint32_t framebuffer_addr;
 extern uint32_t framebuffer_addr_adj;
 
@@ -156,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;
@@ -171,6 +181,9 @@ reinit_raylib:;
             } else if (GetScreenHeight() == 1080) {
                 dstscale.width = 1440;
                 dstscale.height = 1080;
+            } else if (GetScreenHeight() == 1200) {
+                dstscale.width = 1600;
+                dstscale.height = 1200;
             }
         } else {
             while (dstscale.height + height <= GetScreenHeight()) {
@@ -179,13 +192,26 @@ reinit_raylib:;
             }
         }
     } else if (dstscale.width > GetScreenWidth() || dstscale.height > GetScreenHeight()) {
-        if (dstscale.width > GetScreenWidth()) {
-            dstscale.height = dstscale.height * ((float)GetScreenWidth() / (float)width);
-            dstscale.width = GetScreenWidth();
-        }
         if (dstscale.height > GetScreenHeight()) {
+            DEBUG("[H > SH]\n");
+            DEBUG("Adjusted width from %d to", (int)dstscale.width);
             dstscale.width = dstscale.width * ((float)GetScreenHeight() / (float)height);
+            DEBUG("%d.\n", (int)dstscale.width);
+            DEBUG("Adjusted height from %d to", (int)dstscale.height);
             dstscale.height = GetScreenHeight();
+            DEBUG("%d.\n", (int)dstscale.height);
+        }
+        if (dstscale.width > GetScreenWidth()) {
+            // First scaling attempt failed, do not double adjust, re-adjust
+            dstscale.width = width;
+            dstscale.height = height;
+            DEBUG("[W > SW]\n");
+            DEBUG("Adjusted height from %d to", (int)dstscale.height);
+            dstscale.height = dstscale.height * ((float)GetScreenWidth() / (float)width);
+            DEBUG("%d.\n", (int)dstscale.height);
+            DEBUG("Adjusted width from %d to", (int)dstscale.width);
+            dstscale.width = GetScreenWidth();
+            DEBUG("%d.\n", (int)dstscale.width);
         }
     }
 
@@ -198,6 +224,7 @@ reinit_raylib:;
     while (1) {
         if (rtg_on) {
             BeginDrawing();
+            rtg_output_in_vblank = 0;
             updating_screen = 1;
 
             switch (format) {
@@ -241,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++) {
@@ -268,9 +296,9 @@ reinit_raylib:;
             reinit = 1;
             goto shutdown_raylib;
         }
-        /*if (!rtg_on) {
+        if (emulator_exiting) {
             goto shutdown_raylib;
-        }*/
+        }
     }
 
     rtg_initialized = 0;
@@ -310,6 +338,7 @@ void rtg_init_display() {
         err = pthread_create(&thread_id, NULL, &rtgThread, (void *)&rtg_share_data);
         if (err != 0) {
             rtg_on = 0;
+            display_enabled = 0xFF;
             printf("can't create RTG thread :[%s]", strerror(err));
         }
         else {
@@ -324,6 +353,7 @@ void rtg_init_display() {
 void rtg_shutdown_display() {
     printf("RTG display disabled.\n");
     rtg_on = 0;
+    display_enabled = 0xFF;
 }
 
 void rtg_enable_mouse_cursor() {