shithub: m8c

Download patch

ref: 4fb87c2464ef0a061ec884b132d6875bfd499cd5
parent: 6430599b7e26909012aa0c0aea52880394d43060
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Wed Jun 1 18:57:16 EDT 2022

clean up sdl on classic behaviour, add extra check for run status

--- a/config.c
+++ b/config.c
@@ -25,8 +25,7 @@
   c.init_fullscreen = 0; // default fullscreen state at load
   c.init_use_gpu = 1;    // default to use hardware acceleration
   c.idle_ms = 10;        // default to high performance
-  c.wait_for_device =
-      1; // default to classic startup behaviour (exit if device disconnected)
+  c.wait_for_device = 0; // default to exit if device disconnected
 
   c.key_up = SDL_SCANCODE_UP;
   c.key_left = SDL_SCANCODE_LEFT;
--- a/main.c
+++ b/main.c
@@ -7,8 +7,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "SDL_log.h"
-#include "SDL_timer.h"
 #include "command.h"
 #include "config.h"
 #include "input.h"
@@ -109,7 +107,7 @@
         if (!port && SDL_GetTicks() - ticks_poll_device > 1000) {
           ticks_poll_device = SDL_GetTicks();
           port = init_serial(0);
-          if (port != NULL) {
+          if (run == WAIT_FOR_DEVICE && port != NULL) {
             // Device was found; enable display and proceed to the main loop
             if (enable_and_reset_display(port)) {
               run = RUN;
@@ -125,8 +123,12 @@
 
     } else {
       // classic startup behaviour, exit if device is not found
-      if (port == NULL)
+      if (port == NULL) {
+        close_game_controllers();
+        close_renderer();
+        SDL_Quit();
         return -1;
+      }
     }
 
     // main loop
--- a/render.c
+++ b/render.c
@@ -17,7 +17,6 @@
 SDL_Texture *maintexture;
 SDL_Color background_color = (SDL_Color){0, 0, 0, 0};
 
-static uint32_t ticks_screensaver;
 static uint32_t ticks_fps;
 static int fps;
 uint8_t fullscreen = 0;
--- a/write.c
+++ b/write.c
@@ -7,19 +7,6 @@
 #include <stdio.h>
 #include <unistd.h>
 
-int send_msg_dummy(struct sp_port *port){
-  SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Sending dummy packet to M8");
-  uint8_t buf[1];
-  int result;
-  buf[0] = 0x00;
-  result = sp_blocking_write(port, buf, 2, 5);
-  if (result == 1){
-    return 1;
-  } else {
-    return 0;
-  }
-}
-
 int reset_display(struct sp_port *port){
   SDL_Log("Reset display\n");
   uint8_t buf[2];
--