]> git.sesse.net Git - pistorm/commitdiff
Updated SDL2 RTG output courtesy of Claude
authorbeeanyew <beeanyew@gmail.com>
Tue, 5 Jan 2021 12:27:00 +0000 (13:27 +0100)
committerbeeanyew <beeanyew@gmail.com>
Tue, 5 Jan 2021 12:27:00 +0000 (13:27 +0100)
emulator.c
platforms/amiga/rtg/rtg-output.c

index c6bf30cbcd3717ebe8dd3a38480080f729070ba3..f9c1295e5c133bf4ba097abf3cc6d79a9c49c7f3 100644 (file)
@@ -14,7 +14,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
-#include <SDL2/SDL.h>
 #include "m68k.h"
 #include "main.h"
 #include "platforms/platforms.h"
@@ -138,22 +137,6 @@ int main(int argc, char *argv[]) {
     }
   }
 
-  // Initialize SDL.
-  printf("Initializing SDL2...\n");
-  if (SDL_Init(0) < 0) {
-      printf("Failed to initialize SDL2.\n");
-  }
-  else {
-    printf("Initializing SDL2 Video...\n");
-    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
-        printf("Failed to initialize SDL2 Video. Trying again.\n");
-        if (SDL_Init(SDL_INIT_VIDEO) < 0) {
-            printf("Failed to initialize SDL2 Video again. Dying.\n");
-        }
-    }
-    printf("Initialized SDL2 Video.\n");
-  }
-
   keyboard_fd = open(keyboard_file, O_RDONLY | O_NONBLOCK);
   if (keyboard_fd == -1) {
     printf("Failed to open keyboard event source.\n");
index 3b8ddb7c0025a6c5035332436d681c74e38b5d6c..afb35c2ad9524ebdf99dea7e3bf20b965a0337de 100644 (file)
@@ -32,34 +32,13 @@ SDL_Texture *img = NULL;
 
 struct rtg_shared_data rtg_share_data;
 
-void rtg_update_screen() {
-    struct rtg_shared_data *data = &rtg_share_data;
-
-    //printf("RTG thread running\n");
-    //fflush(stdout);
-
-    //while (*data->running) {
-        //printf("We in da loop?\n");
-        //busy = 1;
-        SDL_UpdateTexture(img, NULL, &data->memory[*data->addr + (*data->offset_x << *data->format) + (*data->offset_y * *data->pitch)], *data->pitch);
-        //busy = 0;
-        SDL_RenderClear(renderer);
-        SDL_RenderCopy(renderer, img, NULL, NULL);
-        SDL_RenderPresent(renderer);
-        //sleep(0);
-    //}
-
-    //SDL_Quit();
-    //printf("RTG thread exited somewhat peacefully.\n");
+void rtg_update_screen() {}
 
-    //return args;
-}
-
-void rtg_set_clut_entry(uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
+void *rtgThread(void *args) {
 
-}
+    printf("RTG thread running\n");
+    fflush(stdout);
 
-void rtg_init_display() {
     int err;
     rtg_on = 1;
 
@@ -74,64 +53,82 @@ void rtg_init_display() {
     rtg_share_data.addr = &framebuffer_addr;
     struct rtg_shared_data *data = &rtg_share_data;
 
+    printf("Initializing SDL2...\n");
+    if (SDL_Init(0) < 0) {
+        printf("Failed to initialize SDL2.\n");
+    }
+
+    printf("Initializing SDL2 Video...\n");
+    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+        printf("Failed to initialize SDL2 Video..\n");
+    }
+
     printf("Creating %dx%d SDL2 window...\n", *data->width, *data->height);
-    fflush(stdout);
     win = SDL_CreateWindow("Pistorm RTG", 0, 0, *data->width, *data->height, 0);
     if (!win) {
         RTG_INIT_ERR("Failed create SDL2 window.\n");
-        fflush(stdout);
-        goto death;
     }
     else {
         printf("Created %dx%d window.\n", *data->width, *data->height);
-        fflush(stdout);
     }
 
     printf("Creating SDL2 renderer...\n");
-    fflush(stdout);
     renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
     if (!renderer) {
         RTG_INIT_ERR("Failed create SDL2 renderer.\n");
-        fflush(stdout);
-        goto death;
     }
     else {
         printf("Created SDL2 renderer.\n");
-        fflush(stdout);
     }
 
     printf("Creating SDL2 texture...\n");
-    fflush(stdout);
     img = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_TARGET, *data->width, *data->height);
     if (!img) {
         RTG_INIT_ERR("Failed create SDL2 texture.\n");
-        fflush(stdout);
-        goto death;
     }
     else {
         printf("Created %dx%d texture.\n", *data->width, *data->height);
-        fflush(stdout);
     }
 
-    /*err = pthread_create(&thread_id, NULL, &rtgThread, (void *)&rtg_share_data);
+    while (1) {
+        if (renderer && win && img) {
+            SDL_UpdateTexture(img, NULL, &data->memory[*data->addr + (*data->offset_x << *data->format) + (*data->offset_y * *data->pitch)], *data->pitch);
+            SDL_RenderClear(renderer);
+            SDL_RenderCopy(renderer, img, NULL, NULL);
+            SDL_RenderPresent(renderer);
+            usleep(16667); //ghetto 60hz
+        }
+        else
+            break;
+    }
+
+    printf("RTG thread shut down.\n");
+
+    return args;
+}
+
+void rtg_set_clut_entry(uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
+
+}
+
+void rtg_init_display() {
+    int err;
+    rtg_on = 1;
+
+    err = pthread_create(&thread_id, NULL, &rtgThread, (void *)&rtg_share_data);
     if (err != 0) {
         rtg_on = 0;
         printf("can't create RTG thread :[%s]", strerror(err));
     }
     else {
-        printf("RTG Thread created successfully\n");*/
+        printf("RTG Thread created successfully\n");
         printf("RTG display enabled.\n");
-    //}
-    death:;
+    }
 }
 
 void rtg_shutdown_display() {
-    //void *balf;
     printf("RTG display disabled.\n");
-    //while(rtg_on) {
-        rtg_on = 0;
-        //sleep(0);
-    //}
+    rtg_on = 0;
 
     if (img) SDL_DestroyTexture(img);
     if (renderer) SDL_DestroyRenderer(renderer);