]> git.sesse.net Git - pistorm/blobdiff - platforms/amiga/rtg/rtg-output-raylib.c
iRTG initial implementation
[pistorm] / platforms / amiga / rtg / rtg-output-raylib.c
index 83a2fad4b5e310b374880927d9c06c821e05f90c..5f33fdac803cc20b3bb2f141028cd893a8a4a583 100644 (file)
 
 #define RTG_INIT_ERR(a) { printf(a); *data->running = 0; }
 
-uint8_t busy = 0, rtg_on = 0, rtg_initialized = 0;
+//#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;
 extern uint8_t *rtg_mem;
 extern uint32_t framebuffer_addr;
 extern uint32_t framebuffer_addr_adj;
@@ -162,10 +170,6 @@ reinit_raylib:;
     dstscale.x = dstscale.y = 0;
     dstscale.width = width;
     dstscale.height = height;
-    scale_x = 1.0f;
-    scale_y = 1.0f;
-    origin.x = 0.0f;
-    origin.y = 0.0f;
 
     if (dstscale.height * 2 <= GetScreenHeight()) {
         if (width == 320) {
@@ -175,6 +179,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()) {
@@ -182,10 +189,36 @@ reinit_raylib:;
                 dstscale.width += width;
             }
         }
-        scale_x = dstscale.width / (float)width;
-        scale_y = dstscale.height / (float)height;
+    } else if (dstscale.width > GetScreenWidth() || dstscale.height > GetScreenHeight()) {
+        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);
+        }
     }
 
+    scale_x = dstscale.width / (float)width;
+    scale_y = dstscale.height / (float)height;
+
+    origin.x = (dstscale.width - GetScreenWidth()) * 0.5;
+    origin.y = (dstscale.height - GetScreenHeight()) * 0.5;
+
     while (1) {
         if (rtg_on) {
             BeginDrawing();
@@ -259,9 +292,9 @@ reinit_raylib:;
             reinit = 1;
             goto shutdown_raylib;
         }
-        /*if (!rtg_on) {
+        if (emulator_exiting) {
             goto shutdown_raylib;
-        }*/
+        }
     }
 
     rtg_initialized = 0;