diff --git a/src/cfg.c b/src/cfg.c new file mode 100644 index 0000000..3d05599 --- /dev/null +++ b/src/cfg.c @@ -0,0 +1,59 @@ +#include "cfg.h" +#include "config.h" +#include "uart.h" +#include "fileops.h" + +cfg_t CFG = { + .cfg_ver_maj = 1, + .cfg_ver_min = 0, + .last_game_valid = 0, + .vidmode_menu = VIDMODE_AUTO, + .vidmode_game = VIDMODE_AUTO, + .pair_mode_allowed = 0, + .bsx_use_systime = 0, + .bsx_time = 0x0619970301180530LL +}; + +int cfg_save() { + int err = 0; + file_open(CFG_FILE, FA_CREATE_ALWAYS | FA_WRITE); + if(file_writeblock(&CFG, 0, sizeof(CFG)) < sizeof(CFG)) { + err = file_res; + } + file_close(); + return err; +} + +int cfg_load() { + int err = 0; + file_open(CFG_FILE, FA_READ); + if(file_readblock(&CFG, 0, sizeof(CFG)) < sizeof(CFG)) { + err = file_res; + } + file_close(); + return err; +} + +int cfg_save_last_game(uint8_t *fn) { + int err = 0; + file_open(LAST_FILE, FA_CREATE_ALWAYS | FA_WRITE); + err = f_puts((const TCHAR*)fn, &file_handle); + file_close(); + return err; +} + +int cfg_get_last_game(uint8_t *fn) { + int err = 0; + file_open(LAST_FILE, FA_READ); + f_gets((TCHAR*)fn, 255, &file_handle); + file_close(); + return err; +} + +void cfg_set_last_game_valid(uint8_t valid) { + CFG.last_game_valid = valid; +} + +uint8_t cfg_is_last_game_valid() { + return CFG.last_game_valid; +} diff --git a/src/cfg.h b/src/cfg.h new file mode 100644 index 0000000..f45eabe --- /dev/null +++ b/src/cfg.h @@ -0,0 +1,39 @@ +#ifndef _CFG_H +#define _CFG_H + +#include + +#define CFG_FILE ((const uint8_t*)"/sd2snes/sd2snes.cfg") +#define LAST_FILE ((const uint8_t*)"/sd2snes/lastgame.cfg") + +typedef enum { + VIDMODE_AUTO = 0, + VIDMODE_60, + VIDMODE_50 +} cfg_vidmode_t; + +typedef struct _cfg_block { + uint8_t cfg_ver_maj; + uint8_t cfg_ver_min; + uint8_t last_game_valid; + uint8_t vidmode_menu; + uint8_t vidmode_game; + uint8_t pair_mode_allowed; + uint8_t bsx_use_systime; + uint64_t bsx_time; +} cfg_t; + +int cfg_save(void); +int cfg_load(void); + +int cfg_save_last_game(uint8_t *fn); +int cfg_get_last_game(uint8_t *fn); + +cfg_vidmode_t cfg_get_vidmode_menu(void); +cfg_vidmode_t cfg_get_vidmode_game(void); + +void cfg_set_last_game_valid(uint8_t); +uint8_t cfg_is_last_game_valid(void); +uint8_t cfg_is_pair_mode_allowed(void); + +#endif diff --git a/src/sysinfo.c b/src/sysinfo.c new file mode 100644 index 0000000..354f575 --- /dev/null +++ b/src/sysinfo.c @@ -0,0 +1,127 @@ +#include +#include +#include +#include "config.h" +#include "diskio.h" +#include "ff.h" +#include "timer.h" +#include "uart.h" +#include "fileops.h" +#include "memory.h" +#include "snes.h" +#include "fpga.h" +#include "fpga_spi.h" +#include "cic.h" +#include "sdnative.h" + +#include "sysinfo.h" + +static uint32_t sd_tacc_max, sd_tacc_avg; + +void sysinfo_loop() { + sd_tacc_max = 0; + sd_tacc_avg = 0; + while(sram_readbyte(SRAM_CMD_ADDR) != 0x00) { + write_sysinfo(); + delay_ms(100); + } +} + +void write_sysinfo() { + uint32_t sram_addr = SRAM_SYSINFO_ADDR; + char linebuf[40]; + int len; + int sd_ok = 0; + uint8_t *sd_cid = sdn_getcid(); + uint32_t sd_tacc_max_int = sd_tacc_max / 1000; + uint32_t sd_tacc_max_frac = sd_tacc_max - (sd_tacc_max_int * 1000); + uint32_t sd_tacc_avg_int = sd_tacc_avg / 1000; + uint32_t sd_tacc_avg_frac = sd_tacc_avg - (sd_tacc_avg_int * 1000); + uint16_t numfiles = sram_readshort(SRAM_DB_ADDR+12); + uint16_t numdirs = sram_readshort(SRAM_DB_ADDR+14); + int32_t sysclk = get_snes_sysclk(); + + len = snprintf(linebuf, sizeof(linebuf), "Firmware version: %s", CONFIG_VERSION); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), " "); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + if(disk_state == DISK_REMOVED) { + sd_tacc_max = 0; + sd_tacc_avg = 0; + len = snprintf(linebuf, sizeof(linebuf), " "); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), " *** SD Card removed *** "); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), " "); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), " "); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + sd_ok = 0; + } else { + len = snprintf(linebuf, sizeof(linebuf), "SD Maker/OEM: 0x%02x, \"%c%c\"", sd_cid[1], sd_cid[2], sd_cid[3]); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), "SD Product Name: \"%c%c%c%c%c\", Rev. %d.%d", sd_cid[4], sd_cid[5], sd_cid[6], sd_cid[7], sd_cid[8], sd_cid[9]>>4, sd_cid[9]&15); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), "SD Serial No.: %02x%02x%02x%02x, Mfd. %d/%02d", sd_cid[10], sd_cid[11], sd_cid[12], sd_cid[13], 2000+((sd_cid[14]&15)<<4)+(sd_cid[15]>>4), sd_cid[15]&15); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + if(sd_tacc_max) + len = snprintf(linebuf, sizeof(linebuf), "SD acc. time: %ld.%03ld / %ld.%03ld ms avg/max", sd_tacc_avg_int, sd_tacc_avg_frac, sd_tacc_max_int, sd_tacc_max_frac); + else + len = snprintf(linebuf, sizeof(linebuf), "SD acc. time: measuring... "); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + sd_ok = 1; + } + len = snprintf(linebuf, sizeof(linebuf), " "); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), "CIC state: %s", get_cic_statefriendlyname(get_cic_state())); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + if(sysclk == -1) + len = snprintf(linebuf, sizeof(linebuf), "SNES master clock: measuring..."); + else + len = snprintf(linebuf, sizeof(linebuf), "SNES master clock: %ldHz ", get_snes_sysclk()); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), " "); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), "Database: %d files, %d dirs", numfiles, numdirs); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), " "); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_addr += 40; + len = snprintf(linebuf, sizeof(linebuf), " "); + sram_writeblock(linebuf, sram_addr, 40); + sram_memset(sram_addr+len, 40-len, 0x20); + sram_hexdump(SRAM_SYSINFO_ADDR, 13*40); + if(sysclk != -1 && sd_ok)sdn_gettacc(&sd_tacc_max, &sd_tacc_avg); +} + diff --git a/src/sysinfo.h b/src/sysinfo.h new file mode 100644 index 0000000..e0c8003 --- /dev/null +++ b/src/sysinfo.h @@ -0,0 +1,7 @@ +#ifndef _SYSINFO_H +#define _SYSINFO_H + +void write_sysinfo(void); +void sysinfo_loop(void); + +#endif