Skip to content

Commit

Permalink
Merge pull request #50 from daniel214/software-render-rename
Browse files Browse the repository at this point in the history
Rename software rendering option to use_gpu for clarity
  • Loading branch information
laamaa authored Mar 24, 2022
2 parents c4c1d4f + 0715705 commit 5f0d811
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
38 changes: 24 additions & 14 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,8 +76,8 @@ void write_config(config_params_s *conf) {
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);
Expand Down Expand Up @@ -151,19 +163,18 @@ void read_config(config_params_s *conf) {

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;
}

}
Expand Down Expand Up @@ -263,8 +274,7 @@ void read_gamepad_config(ini_t *ini, config_params_s *conf) {
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;
Expand Down
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions config.ini.sample
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
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;
Expand Down
4 changes: 2 additions & 2 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static int fps;
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();

Expand All @@ -37,7 +37,7 @@ int initialize_sdl(int init_fullscreen, int init_software) {
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);

Expand Down
2 changes: 1 addition & 1 deletion render.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5f0d811

Please sign in to comment.