ref: 5b8ff8235dcc3a4acbb078b69a946bfd055da20f
parent: e07d462698cef23d15d8d0b15f5a012fc0c196db
author: Daniel Hooper <44912292+daniel214@users.noreply.github.com>
date: Wed Mar 23 17:50:59 EDT 2022
Rename software rendering option to use_gpu for clarity Also adds case-insensitive string comparison function from the ini library.
--- a/config.c
+++ b/config.c
@@ -2,15 +2,27 @@
// Released under the MIT licence, https://opensource.org/licenses/MIT
#include "config.h"
+#include "ini.h"
#include <SDL.h>
+/* Case insensitive string compare from ini.h library */
+static int strcmpci(const char *a, const char *b) {+ for (;;) {+ int d = tolower(*a) - tolower(*b);
+ if (d != 0 || !*a) {+ return d;
+ }
+ a++, b++;
+ }
+}
+
config_params_s init_config() {config_params_s c;
c.filename = "config.ini"; // default config file to load
- c.init_fullscreen = 0; // default fullscreen state at load
- c.init_software = 0;
+ c.init_fullscreen = 0; // default fullscreen state at load
+ c.init_use_gpu = 1; // default to use hardware acceleration
c.key_up = SDL_SCANCODE_UP;
c.key_left = SDL_SCANCODE_LEFT;
@@ -64,8 +76,8 @@
sprintf(ini_values[initPointer++], "[graphics]\n");
sprintf(ini_values[initPointer++], "fullscreen=%s\n",
conf->init_fullscreen ? "true" : "false");
- sprintf(ini_values[initPointer++], "software=%s\n",
- conf->init_software ? "true" : "false");
+ sprintf(ini_values[initPointer++], "use_gpu=%s\n",
+ conf->init_use_gpu ? "true" : "false");
sprintf(ini_values[initPointer++], "[keyboard]\n");
sprintf(ini_values[initPointer++], "key_up=%d\n", conf->key_up);
sprintf(ini_values[initPointer++], "key_left=%d\n", conf->key_left);
@@ -151,19 +163,18 @@
void read_graphics_config(ini_t *ini, config_params_s *conf) {const char *param_fs = ini_get(ini, "graphics", "fullscreen");
- const char *param_sw = ini_get(ini, "graphics", "software");
- // This obviously requires the parameter to be a lowercase true to enable
- // fullscreen
- if (strcmp(param_fs, "true") == 0) {+ const char *param_gpu = ini_get(ini, "graphics", "use_gpu");
+
+ if (strcmpci(param_fs, "true") == 0) {conf->init_fullscreen = 1;
} else
conf->init_fullscreen = 0;
- if(param_sw != NULL){- if (strcmp(param_sw, "true") == 0) {- conf->init_software = 1;
+ if(param_gpu != NULL){+ if (strcmpci(param_gpu, "true") == 0) {+ conf->init_use_gpu = 1;
} else
- conf->init_software = 0;
+ conf->init_use_gpu = 0;
}
}
@@ -263,8 +274,7 @@
if (gamepad_analog_threshold)
conf->gamepad_analog_threshold = SDL_atoi(gamepad_analog_threshold);
- // This requires the parameter to be a lowercase true to enable fullscreen
- if (strcmp(gamepad_analog_invert, "true") == 0)
+ if (strcmpci(gamepad_analog_invert, "true") == 0)
conf->gamepad_analog_invert = 1;
else
conf->gamepad_analog_invert = 0;
--- a/config.h
+++ b/config.h
@@ -9,7 +9,7 @@
typedef struct config_params_s {char *filename;
int init_fullscreen;
- int init_software;
+ int init_use_gpu;
int key_up;
int key_left;
--- a/config.ini.sample
+++ b/config.ini.sample
@@ -1,8 +1,13 @@
+; edit this file to change m8c defaults
+; this file is re-written every time it is read,
+; so do not expect comments or commented out values to survive!
+; valid parameter changes will be written back and persisted though.
+
[graphics]
; set this to true to have m8c start fullscreen
fullscreen=false
-; set this to true to run m8c in software rendering mode (use for raspberry pi)
-software=false
+; set this to false to run m8c in software rendering mode (may be useful for Raspberry Pi)
+use_gpu=true
[keyboard]
; these need to be the decimal value of the SDL scancodes.
--- a/main.c
+++ b/main.c
@@ -61,7 +61,7 @@
if (enable_and_reset_display(port) == -1)
run = 0;
- if (initialize_sdl(conf.init_fullscreen, conf.init_software) == -1)
+ if (initialize_sdl(conf.init_fullscreen, conf.init_use_gpu) == -1)
run = 0;
uint8_t prev_input = 0;
--- a/render.c
+++ b/render.c
@@ -20,7 +20,7 @@
uint8_t fullscreen = 0;
// Initializes SDL and creates a renderer and required surfaces
-int initialize_sdl(int init_fullscreen, int init_software) {+int initialize_sdl(int init_fullscreen, int init_use_gpu) {ticks = SDL_GetTicks();
@@ -37,7 +37,7 @@
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL |
SDL_WINDOW_RESIZABLE | init_fullscreen);
- rend = SDL_CreateRenderer(win, -1, init_software ? SDL_RENDERER_SOFTWARE : SDL_RENDERER_ACCELERATED);
+ rend = SDL_CreateRenderer(win, -1, init_use_gpu ? SDL_RENDERER_ACCELERATED : SDL_RENDERER_SOFTWARE);
SDL_RenderSetLogicalSize(rend, 320, 240);
--- a/render.h
+++ b/render.h
@@ -6,7 +6,7 @@
#include "command.h"
-int initialize_sdl(int init_fullscreen, int init_software);
+int initialize_sdl(int init_fullscreen, int init_use_gpu);
void close_renderer();
int process_queues(struct command_queues *queues);
--
⑨