From c24b973fc4ac6a989671690d091f9321b7bd731d Mon Sep 17 00:00:00 2001 From: sorgelig Date: Tue, 17 Sep 2019 02:51:31 +0800 Subject: [PATCH] alt mode --- cfg.cpp | 4 ++-- ini_parser.cpp | 10 +++------- ini_parser.h | 2 +- user_io.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ user_io.h | 1 + 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/cfg.cpp b/cfg.cpp index 970f1c2..5cd3b08 100644 --- a/cfg.cpp +++ b/cfg.cpp @@ -14,7 +14,7 @@ void MiSTer_ini_parse() memset(&cfg, 0, sizeof(cfg)); cfg.bootscreen = 1; cfg.fb_terminal = 1; - ini_parse(&ini_cfg); + ini_parse(&ini_cfg, altcfg()); } // mist ini sections @@ -61,7 +61,7 @@ const ini_var_t ini_vars[] = { // mist ini config const ini_cfg_t ini_cfg = { "MiSTer.ini", - CONFIG_DIR"/MiSTer.ini", + "MiSTer_alt.ini", ini_sections, ini_vars, (int)(sizeof(ini_sections) / sizeof(ini_section_t)), diff --git a/ini_parser.cpp b/ini_parser.cpp index 513b93d..8113793 100644 --- a/ini_parser.cpp +++ b/ini_parser.cpp @@ -192,7 +192,7 @@ void* ini_get_var(const ini_cfg_t* cfg, int cur_section, char* buf) return (void*)0; } -void ini_parse(const ini_cfg_t* cfg) +void ini_parse(const ini_cfg_t* cfg, int alt) { char line[INI_LINE_SIZE] = { 0 }; int section = INI_SECTION_INVALID_ID; @@ -201,13 +201,9 @@ void ini_parse(const ini_cfg_t* cfg) ini_parser_debugf("Start INI parser for core \"%s\".", user_io_get_core_name_ex()); memset(&ini_file, 0, sizeof(ini_file)); - if (!FileOpen(&ini_file, cfg->filename)) + if (!FileOpen(&ini_file, alt ? cfg->filename_alt : cfg->filename)) { - if (!FileOpen(&ini_file, cfg->filename_alt)) - { - return; - } - else ini_parser_debugf("Opened file %s with size %llu bytes.", cfg->filename_alt, ini_file.size); + return; } else ini_parser_debugf("Opened file %s with size %llu bytes.", cfg->filename, ini_file.size); diff --git a/ini_parser.h b/ini_parser.h index f429220..a85aaa5 100644 --- a/ini_parser.h +++ b/ini_parser.h @@ -40,7 +40,7 @@ typedef struct { //// functions //// -void ini_parse(const ini_cfg_t* cfg); +void ini_parse(const ini_cfg_t* cfg, int alt); #endif // __INI_PARSER_H__ diff --git a/user_io.cpp b/user_io.cpp index a523c97..9fb2737 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -609,6 +609,49 @@ uint16_t sdram_sz(int sz) return res; } +uint16_t altcfg(int alt) +{ + int res = 0; + + int fd; + if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) return 0; + + void* buf = mmap(0, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x1FFFF000); + if (buf == (void *)-1) + { + printf("Unable to mmap(/dev/mem)\n"); + close(fd); + return 0; + } + + volatile uint8_t* par = (volatile uint8_t*)buf; + par += 0xF04; + if (alt >= 0) + { + *par++ = 0x34; + *par++ = 0x99; + *par++ = 0xBA; + *par++ = (uint8_t)alt; + printf("** altcfg(%d)\n", alt); + } + else + { + if ((par[0] == 0x34) && (par[1] == 0x99) && (par[2] == 0xBA)) + { + res = par[3]; + printf("** altcfg: got cfg %d\n", res); + } + else + { + printf("** altcfg: no cfg\n"); + } + } + + munmap(buf, 0x1000); + close(fd); + return res; +} + int user_io_is_dualsdr() { return dual_sdr; @@ -1704,6 +1747,15 @@ void user_io_send_buttons(char force) if ((map != key_map) || force) { + if ((key_map & (BUTTON1 | BUTTON2)) == BUTTON2 && (map & (BUTTON1 | BUTTON2)) == (BUTTON1 | BUTTON2) && is_menu_core()) + { + if (FileExists(ini_cfg.filename_alt)) + { + altcfg(altcfg() ? 0 : 1); + fpga_load_rbf("menu.rbf"); + } + } + const char *name = get_rbf_path(); if (name[0] && (get_key_mod() & (LGUI | LSHIFT)) == (LGUI | LSHIFT) && (key_map & BUTTON2) && !(map & BUTTON2)) { diff --git a/user_io.h b/user_io.h index bfbc361..1d5e1b3 100644 --- a/user_io.h +++ b/user_io.h @@ -238,6 +238,7 @@ const char* get_rbf_path(); uint16_t sdram_sz(int sz = -1); int user_io_is_dualsdr(); +uint16_t altcfg(int alt = -1); int GetUARTMode(); int GetMidiLinkMode();