Skip to content

Commit a81ac4d

Browse files
committed
added config file handling (saving console and game aspect ratio for now)
1 parent a6c28ff commit a81ac4d

6 files changed

Lines changed: 50 additions & 27 deletions

File tree

chip/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CC = $(CROSS_COMPILE)-gcc
88

99
OBJS = chip.o main.o menu.o cpu.o memory.o video.o input.o sound.o gui.o \
1010
cheats.o zip.o cpu_threaded.o arm_stub.o video_blend.o warm.o \
11-
upscale_aspect.o neon_scaler.o
11+
upscale_aspect.o neon_scaler.o configfile.o
1212
BIN = gpsp
1313

1414
# Platform specific definitions

input.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "common.h"
2121
#include "menu.h"
22+
#include "configfile.h"
2223
#include "video.h"
2324

2425
// Special thanks to psp298 for the analog->dpad code!
@@ -943,6 +944,9 @@ u32 update_input()
943944
if (fp == NULL) {
944945
printf("Failed to run command %s\n", shell_cmd);
945946
}
947+
948+
// Save config file
949+
configfile_save(cfg_file_rom);
946950
}
947951
/// --- Aspect ratio increase ---
948952
else if(event.key.keysym.sym == SDLK_i)
@@ -964,6 +968,9 @@ u32 update_input()
964968
if (fp == NULL) {
965969
printf("Failed to run command %s\n", shell_cmd);
966970
}
971+
972+
// Save config file
973+
configfile_save(cfg_file_rom);
967974
}
968975
/// --- Change display mode ---
969976
else if(event.key.keysym.sym == SDLK_h)
@@ -987,6 +994,9 @@ u32 update_input()
987994
if (fp == NULL) {
988995
printf("Failed to run command %s\n", shell_cmd);
989996
}
997+
998+
// Save config file
999+
configfile_save(cfg_file_rom);
9901000
}
9911001
else if(event.key.keysym.sym == SDLK_BACKQUOTE)
9921002
{

main.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
*/
1919

2020
#include <signal.h>
21+
#include <ini.h>
2122
#include "common.h"
2223
#include "menu.h"
24+
#include "configfile.h"
2325
#include "video.h"
2426

2527
#define BIOS_PATH "/mnt/Game Boy Advance"
@@ -101,6 +103,11 @@ static char *quick_save_file_extension = "quicksave";
101103
char *mRomName = NULL;
102104
char *mRomPath = NULL;
103105
char *quick_save_file = NULL;
106+
char *console_name;
107+
char *cfg_file_default = NULL;
108+
char *cfg_file_rom = NULL;
109+
static char *cfg_file_default_name = "default_config";
110+
static char *cfg_file_extension = "cfg";
104111
u32 mQuickSaveAndPoweroff=0;
105112

106113

@@ -333,7 +340,7 @@ void parse_cmd_line(int argc, char *argv[])
333340
*slash = 0;
334341

335342
/* Rom name without extension */
336-
char *point = strrchr ((char*)slash+1, '.');
343+
char *point = strrchr((char*)slash+1, '.');
337344
*point = 0;
338345

339346
/* Set quicksave filename */
@@ -343,6 +350,25 @@ void parse_cmd_line(int argc, char *argv[])
343350
mRomPath, slash+1, quick_save_file_extension);
344351
printf("Quick_save_file: %s\n", quick_save_file);
345352

353+
/* Set rom cfg filepath */
354+
cfg_file_rom = (char *)malloc(strlen(mRomPath) + strlen(slash+1) +
355+
strlen(cfg_file_extension) + 2 + 1);
356+
sprintf(cfg_file_rom, "%s/%s.%s",
357+
mRomPath, slash+1, cfg_file_extension);
358+
printf("cfg_file_rom: %s\n", cfg_file_rom);
359+
360+
/* Set console cfg filepath */
361+
cfg_file_default = (char *)malloc(strlen(mRomPath) + strlen(cfg_file_default_name) +
362+
strlen(cfg_file_extension) + 2 + 1);
363+
sprintf(cfg_file_default, "%s/%s.%s",
364+
mRomPath, cfg_file_default_name, cfg_file_extension);
365+
printf("cfg_file_default: %s\n", cfg_file_default);
366+
367+
/** Load config files */
368+
configfile_load(cfg_file_default);
369+
configfile_load(cfg_file_rom);
370+
371+
346372
fclose(f);
347373
break;
348374
}

menu.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
#include <SDL/SDL.h>
1111
#include <SDL/SDL_ttf.h>
1212
#include <SDL/SDL_image.h>
13+
#include <ini.h>
1314

1415
#include "common.h"
1516
#include "main.h"
1617
#include "menu.h"
1718
#include "gui.h"
1819
#include "video.h"
20+
#include "configfile.h"
1921

2022

2123
/// -------------- DEFINES --------------
@@ -103,13 +105,6 @@ static uint16_t y_brightness_bar = 0;
103105
int volume_percentage = 0;
104106
int brightness_percentage = 0;
105107

106-
#undef X
107-
#define X(a, b) b,
108-
const char *aspect_ratio_name[] = {ASPECT_RATIOS};
109-
int aspect_ratio = ASPECT_RATIOS_TYPE_STRETCHED;
110-
int aspect_ratio_factor_percent = 50;
111-
int aspect_ratio_factor_step = 10;
112-
113108
static int quick_load_slot_chosen = 0;
114109

115110
#undef X
@@ -767,8 +762,12 @@ void run_menu_loop()
767762
else if(idx_menus[menuItem] == MENU_TYPE_ASPECT_RATIO){
768763
MENU_DEBUG_PRINTF("Aspect Ratio DOWN\n");
769764
aspect_ratio = (!aspect_ratio)?(NB_ASPECT_RATIOS_TYPES-1):(aspect_ratio-1);
765+
770766
/// ------ Refresh screen ------
771767
screen_refresh = 1;
768+
769+
// Save config file
770+
configfile_save(cfg_file_rom);
772771
}
773772
break;
774773

@@ -834,8 +833,12 @@ void run_menu_loop()
834833
else if(idx_menus[menuItem] == MENU_TYPE_ASPECT_RATIO){
835834
MENU_DEBUG_PRINTF("Aspect Ratio UP\n");
836835
aspect_ratio = (aspect_ratio+1)%NB_ASPECT_RATIOS_TYPES;
836+
837837
/// ------ Refresh screen ------
838838
screen_refresh = 1;
839+
840+
// Save config file
841+
configfile_save(cfg_file_rom);
839842
}
840843
break;
841844

menu.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@ typedef enum{
1919
NB_MENU_TYPES,
2020
} ENUM_MENU_TYPE;
2121

22-
23-
///------ Definition of the different aspect ratios
24-
#define ASPECT_RATIOS \
25-
X(ASPECT_RATIOS_TYPE_MANUAL, "MANUAL ZOOM") \
26-
X(ASPECT_RATIOS_TYPE_STRETCHED, "STRETCHED") \
27-
X(ASPECT_RATIOS_TYPE_CROPPED, "CROPPED") \
28-
X(ASPECT_RATIOS_TYPE_SCALED, "SCALED") \
29-
X(NB_ASPECT_RATIOS_TYPES, "")
30-
31-
////------ Enumeration of the different aspect ratios ------
32-
#undef X
33-
#define X(a, b) a,
34-
typedef enum {ASPECT_RATIOS} ENUM_ASPECT_RATIOS_TYPES;
35-
3622
///------ Definition of the different resume options
3723
#define RESUME_OPTIONS \
3824
X(RESUME_YES, "RESUME GAME") \
@@ -67,13 +53,10 @@ typedef enum {RESUME_OPTIONS} ENUM_RESUME_OPTIONS;
6753
extern int volume_percentage;
6854
extern int brightness_percentage;
6955

70-
extern const char *aspect_ratio_name[];
71-
extern int aspect_ratio;
72-
extern int aspect_ratio_factor_percent;
73-
extern int aspect_ratio_factor_step;
7456
extern int stop_menu_loop;
7557
extern char *mRomName;
7658
extern char *mRomPath;
59+
extern char *cfg_file_rom;
7760
extern char *quick_save_file;
7861

7962
#endif //MENU_H

video.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define WANT_FONT_BITS
2323
#include "font.h"
2424
#include "menu.h"
25+
#include "configfile.h"
2526

2627
#ifdef CHIP_BUILD
2728
#include "arm/neon_scaler.h"

0 commit comments

Comments
 (0)