mirror of
https://github.com/mist-devel/mist-firmware.git
synced 2026-04-26 04:17:40 +00:00
ini_parser: make it independent again
- factor out data_io and user_io calls from the parser core
This commit is contained in:
@@ -4,6 +4,7 @@ SRC = ini_test.c mist_cfg.c ini_parser.c
|
||||
OBJ = $(SRC:.c=.o)
|
||||
DEP = $(SRC:.c=.d)
|
||||
|
||||
CFLAGS = -Wno-attributes
|
||||
CPPFLAGS = -DINI_PARSER_TEST
|
||||
|
||||
# Our target.
|
||||
|
||||
63
ini_parser.c
63
ini_parser.c
@@ -14,8 +14,6 @@
|
||||
#ifndef INI_PARSER_TEST
|
||||
#include "debug.h"
|
||||
#include "fat.h"
|
||||
#include "user_io.h"
|
||||
#include "data_io.h"
|
||||
#endif
|
||||
|
||||
//// defines ////
|
||||
@@ -62,17 +60,6 @@ fileTYPE ini_file;
|
||||
|
||||
int ini_pt = 0;
|
||||
|
||||
// call data_io_rom_upload but reload sector_buffer afterwards since the io
|
||||
// operations in data_io_rom_upload may have overwritten the buffer
|
||||
// mode = 0: prepare for rom upload, mode = 1: rom upload, mode = 2, end rom upload
|
||||
void ini_rom_upload(char *s) {
|
||||
#ifndef INI_PARSER_TEST
|
||||
data_io_rom_upload(s, 1);
|
||||
|
||||
FileRead(&ini_file, sector_buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
//// ini_getch() ////
|
||||
char ini_getch()
|
||||
{
|
||||
@@ -158,37 +145,8 @@ int ini_putline(char* line)
|
||||
return ini_pt;
|
||||
}
|
||||
|
||||
char *get_core_name()
|
||||
{
|
||||
#ifndef INI_PARSER_TEST
|
||||
switch(user_io_core_type())
|
||||
{
|
||||
case CORE_TYPE_MINIMIG:
|
||||
case CORE_TYPE_MINIMIG2:
|
||||
return "MINIMIG";
|
||||
|
||||
case CORE_TYPE_PACE:
|
||||
return "PACE";
|
||||
|
||||
case CORE_TYPE_MIST:
|
||||
case CORE_TYPE_MIST2:
|
||||
return "ST";
|
||||
|
||||
case CORE_TYPE_ARCHIE:
|
||||
return "ARCHIE";
|
||||
|
||||
case CORE_TYPE_8BIT:
|
||||
return user_io_get_core_name();
|
||||
}
|
||||
|
||||
return "";
|
||||
#else
|
||||
return "TESTCORE";
|
||||
#endif
|
||||
}
|
||||
|
||||
//// ini_get_section() ////
|
||||
int ini_get_section(const ini_cfg_t* cfg, char* buf)
|
||||
int ini_get_section(const ini_cfg_t* cfg, char* buf, const char* alter_section)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
@@ -223,7 +181,10 @@ int ini_get_section(const ini_cfg_t* cfg, char* buf)
|
||||
}
|
||||
}
|
||||
|
||||
if(!strcasecmp(buf, get_core_name())) return cfg->sections[0].id;
|
||||
if(alter_section && !strcasecmp(buf, alter_section)) {
|
||||
ini_parser_debugf("Got ALTER SECTION '%s' with ID %d", buf, cfg->sections[0].id);
|
||||
return cfg->sections[0].id;
|
||||
}
|
||||
|
||||
return INI_SECTION_INVALID_ID;
|
||||
}
|
||||
@@ -312,17 +273,13 @@ void* ini_get_var(const ini_cfg_t* cfg, int cur_section, char* buf)
|
||||
|
||||
|
||||
//// ini_parse() ////
|
||||
void ini_parse(const ini_cfg_t* cfg)
|
||||
void ini_parse(const ini_cfg_t* cfg, const char *alter_section)
|
||||
{
|
||||
char line[INI_LINE_SIZE] = {0};
|
||||
int section = INI_SECTION_INVALID_ID;
|
||||
int line_status;
|
||||
|
||||
ini_parser_debugf("Start INI parser for core \"%s\".", get_core_name());
|
||||
|
||||
#ifndef INI_PARSER_TEST
|
||||
data_io_rom_upload(NULL, 0); // prepare upload
|
||||
#endif
|
||||
ini_parser_debugf("Start INI parser for core \"%s\".", alter_section);
|
||||
|
||||
// open ini file
|
||||
#ifdef INI_PARSER_TEST
|
||||
@@ -359,7 +316,7 @@ void ini_parse(const ini_cfg_t* cfg)
|
||||
if (line_status != 1) {
|
||||
if (line[0] == INI_SECTION_START) {
|
||||
// if first char in line is INI_SECTION_START, get section
|
||||
section = ini_get_section(cfg, line);
|
||||
section = ini_get_section(cfg, line, alter_section);
|
||||
} else {
|
||||
// otherwise this is a variable, get it
|
||||
ini_get_var(cfg, section, line);
|
||||
@@ -373,10 +330,6 @@ void ini_parse(const ini_cfg_t* cfg)
|
||||
// close file
|
||||
fclose(ini_fp);
|
||||
#endif
|
||||
|
||||
#ifndef INI_PARSER_TEST
|
||||
data_io_rom_upload(NULL, 2); // upload done
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef struct {
|
||||
|
||||
|
||||
//// functions ////
|
||||
void ini_parse(const ini_cfg_t* cfg);
|
||||
void ini_parse(const ini_cfg_t* cfg, const char *alter_section);
|
||||
void ini_save(const ini_cfg_t* cfg);
|
||||
void ini_rom_upload(char *s);
|
||||
|
||||
|
||||
@@ -15,5 +15,5 @@ int main() {
|
||||
|
||||
memset(&mist_cfg, 0, sizeof(mist_cfg));
|
||||
memset(&minimig_cfg, 0, sizeof(minimig_cfg));
|
||||
ini_parse(&mist_ini_cfg);
|
||||
ini_parse(&mist_ini_cfg, "DEFENDER");
|
||||
}
|
||||
|
||||
20
mist_cfg.c
20
mist_cfg.c
@@ -7,10 +7,24 @@
|
||||
#include "ini_parser.h"
|
||||
#include "mist_cfg.h"
|
||||
#include "user_io.h"
|
||||
#include "data_io.h"
|
||||
#include "usb/usb.h"
|
||||
#include "usb/hid.h"
|
||||
#include "usb/joymapping.h"
|
||||
|
||||
extern fileTYPE ini_file;
|
||||
|
||||
// call data_io_rom_upload but reload sector_buffer afterwards since the io
|
||||
// operations in data_io_rom_upload may have overwritten the buffer
|
||||
// mode = 0: prepare for rom upload, mode = 1: rom upload, mode = 2, end rom upload
|
||||
void ini_rom_upload(char *s) {
|
||||
#ifndef INI_PARSER_TEST
|
||||
data_io_rom_upload(s, 1);
|
||||
|
||||
FileRead(&ini_file, sector_buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
//// mist_ini_parse() ////
|
||||
void mist_ini_parse()
|
||||
{
|
||||
@@ -18,11 +32,13 @@ void mist_ini_parse()
|
||||
hid_joystick_button_remap_init();
|
||||
virtual_joystick_remap_init();
|
||||
joy_key_map_init();
|
||||
#endif
|
||||
data_io_rom_upload(NULL, 0); // prepare upload
|
||||
memset(&mist_cfg, 0, sizeof(mist_cfg));
|
||||
memset(&minimig_cfg, 0, sizeof(minimig_cfg));
|
||||
minimig_cfg.kick1x_memory_detection_patch = 1;
|
||||
ini_parse(&mist_ini_cfg);
|
||||
ini_parse(&mist_ini_cfg, user_io_get_core_name());
|
||||
data_io_rom_upload(NULL, 2); // upload done
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -242,10 +242,12 @@ void user_io_detect_core_type() {
|
||||
break;
|
||||
|
||||
case CORE_TYPE_MINIMIG:
|
||||
strcpy(core_name, "MINIMIG");
|
||||
puts("Identified Minimig V1 core");
|
||||
break;
|
||||
|
||||
case CORE_TYPE_MINIMIG2:
|
||||
strcpy(core_name, "MINIMIG");
|
||||
puts("Identified Minimig V2 core");
|
||||
break;
|
||||
|
||||
@@ -255,6 +257,7 @@ void user_io_detect_core_type() {
|
||||
|
||||
case CORE_TYPE_MIST:
|
||||
case CORE_TYPE_MIST2:
|
||||
strcpy(core_name, "ST");
|
||||
puts("Identified MiST core");
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user