shithub: m8c

Download patch

ref: f2de0b151ab7af35b72282ab932bd419e58ea6ea
parent: 99f90a25e4d3c5b9f5895c6cc7aa4b326b774d8b
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Mon Apr 7 14:14:10 EDT 2025

integer scaling config option, shorten default wait packets timeout value
- add integer scaling as a configurable option
- shorten the default "wait packets" value that determines

--- a/src/config.c
+++ b/src/config.c
@@ -29,10 +29,10 @@
   }
 
   c.init_fullscreen = 0; // default fullscreen state at load
+  c.integer_scaling = 0; // use integer scaling for the user interface
   c.idle_ms = 10;        // default to high performance
   c.wait_for_device = 1; // default to exit if device disconnected
-  c.wait_packets = 1024; // default zero-byte attempts to disconnect (about 2
-  // sec for default idle_ms)
+  c.wait_packets = 512; // amount of empty command queue reads before assuming device disconnected
   c.audio_enabled = 0;        // route M8 audio to default output
   c.audio_buffer_size = 0; // requested audio buffer size in samples: 0 = let SDL decide
   c.audio_device_name = NULL; // Use this device, leave NULL to use the default output device
@@ -90,7 +90,7 @@
 
   SDL_Log("Writing config file to %s", config_path);
 
-  const unsigned int INI_LINE_COUNT = 49;
+  const unsigned int INI_LINE_COUNT = 50;
   const unsigned int LINELEN = 50;
 
   // Entries for the config file
@@ -103,6 +103,7 @@
   snprintf(ini_values[initPointer++], LINELEN, "wait_for_device=%s\n",
            conf->wait_for_device ? "true" : "false");
   snprintf(ini_values[initPointer++], LINELEN, "wait_packets=%d\n", conf->wait_packets);
+  snprintf(ini_values[initPointer++], LINELEN, "integer_scaling=%s\n", conf->integer_scaling ? "true" : "false");
   snprintf(ini_values[initPointer++], LINELEN, "[audio]\n");
   snprintf(ini_values[initPointer++], LINELEN, "audio_enabled=%s\n",
            conf->audio_enabled ? "true" : "false");
@@ -233,11 +234,13 @@
   const char *idle_ms = ini_get(ini, "graphics", "idle_ms");
   const char *param_wait = ini_get(ini, "graphics", "wait_for_device");
   const char *wait_packets = ini_get(ini, "graphics", "wait_packets");
+  const char *integer_scaling = ini_get(ini, "graphics", "integer_scaling");
 
-  if (strcmpci(param_fs, "true") == 0) {
+  if (param_fs != NULL && strcmpci(param_fs, "true") == 0) {
     conf->init_fullscreen = 1;
-  } else
+  } else {
     conf->init_fullscreen = 0;
+  }
 
   if (idle_ms != NULL)
     conf->idle_ms = SDL_atoi(idle_ms);
@@ -251,6 +254,12 @@
   }
   if (wait_packets != NULL)
     conf->wait_packets = SDL_atoi(wait_packets);
+
+  if (integer_scaling != NULL && strcmpci(integer_scaling, "true") == 0) {
+    conf->integer_scaling = 1;
+  } else {
+    conf->integer_scaling = 0;
+  }
 }
 
 void read_key_config(const ini_t *ini, config_params_s *conf) {
--- a/src/config.h
+++ b/src/config.h
@@ -9,6 +9,7 @@
 typedef struct config_params_s {
   char *filename;
   unsigned int init_fullscreen;
+  unsigned int integer_scaling;
   unsigned int idle_ms;
   unsigned int wait_for_device;
   unsigned int wait_packets;
--- a/src/main.c
+++ b/src/main.c
@@ -96,7 +96,7 @@
           screensaver_destroy();
 #ifdef USE_RTMIDI
           show_error_message("Cannot initialize M8 remote display. Make sure you're running "
-                             "firmware 6.0.0 or newer.");
+                             "firmware 6.0.0 or newer. Please close and restart the application to try again.");
 #endif
         }
       }
@@ -258,7 +258,7 @@
   initialize_signals();
 
   device_connected = handle_device_initialization(conf.wait_for_device, preferred_device);
-  if (!renderer_initialize(conf.init_fullscreen)) {
+  if (!renderer_initialize(&conf)) {
     SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, "Failed to initialize renderer.");
     cleanup_resources(device_connected, &conf);
     return EXIT_FAILURE;
--- a/src/render.c
+++ b/src/render.c
@@ -7,6 +7,7 @@
 
 #include "SDL2_inprint.h"
 #include "command.h"
+#include "config.h"
 #include "fx_cube.h"
 
 #include "fonts/font1.h"
@@ -42,8 +43,17 @@
 
 static uint8_t dirty = 0;
 
+static void use_integer_scaling(const unsigned int use_integer_scaling) {
+  if (use_integer_scaling) {
+    scaling_mode = SDL_LOGICAL_PRESENTATION_INTEGER_SCALE;
+  } else {
+    scaling_mode = SDL_LOGICAL_PRESENTATION_LETTERBOX;
+  }
+  fix_texture_scaling_after_window_resize();
+}
+
 // Initializes SDL and creates a renderer and required surfaces
-int renderer_initialize(const unsigned int init_fullscreen) {
+int renderer_initialize(config_params_s *conf) {
 
   // SDL documentation recommends this
   atexit(SDL_Quit);
@@ -55,7 +65,7 @@
 
   if (!SDL_CreateWindowAndRenderer(
           "m8c", texture_width * 2, texture_height * 2,
-          SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | init_fullscreen, &win, &rend)) {
+          SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | conf->init_fullscreen, &win, &rend)) {
     SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window and renderer: %s",
                     SDL_GetError());
     return false;
@@ -77,6 +87,7 @@
   }
 
   SDL_SetTextureScaleMode(main_texture, SDL_SCALEMODE_NEAREST);
+  use_integer_scaling(conf->integer_scaling);
 
   SDL_SetRenderTarget(rend, main_texture);
 
--- a/src/render.h
+++ b/src/render.h
@@ -4,16 +4,19 @@
 #ifndef RENDER_H_
 #define RENDER_H_
 
-#include <stdint.h>
 #include "command.h"
+#include "config.h"
 
-int renderer_initialize(unsigned int init_fullscreen);
+#include <stdint.h>
+
+int renderer_initialize(config_params_s *conf);
 void renderer_close();
+void renderer_set_font_mode(int mode);
 
 void draw_waveform(struct draw_oscilloscope_waveform_command *command);
 void draw_rectangle(struct draw_rectangle_command *command);
 int draw_character(struct draw_character_command *command);
-void renderer_set_font_mode(int mode);
+
 void set_m8_model(unsigned int model);
 
 void render_screen();
@@ -27,4 +30,5 @@
 void screensaver_destroy();
 
 void fix_texture_scaling_after_window_resize(void);
+
 #endif
--