diff --git a/src/Makefile b/src/Makefile index e7e6157..7e5c748 100644 --- a/src/Makefile +++ b/src/Makefile @@ -55,7 +55,7 @@ TARGET = $(OBJDIR)/sd2snes # List C source files here. (C dependencies are automatically generated.) -SRC = main.c ff.c ccsbcs.c clock.c uart.c power.c led.c timer.c printf.c spi.c fileops.c rtc.c fpga.c fpga_spi.c snes.c smc.c memory.c filetypes.c faulthandler.c sort.c crc32.c cic.c cli.c xmodem.c irq.c rle.c sdnative.c msu1.c crc16.c sysinfo.c +SRC = main.c ff.c ccsbcs.c clock.c uart.c power.c led.c timer.c printf.c spi.c fileops.c rtc.c fpga.c fpga_spi.c snes.c smc.c memory.c filetypes.c faulthandler.c sort.c crc32.c cic.c cli.c xmodem.c irq.c rle.c sdnative.c msu1.c crc16.c sysinfo.c cfg.c # usbcontrol.c usb_hid.c usbhw_lpc.c usbinit.c usbstdreq.c diff --git a/src/ffconf.h b/src/ffconf.h index 14551ed..b909757 100644 --- a/src/ffconf.h +++ b/src/ffconf.h @@ -36,7 +36,7 @@ / 3: f_lseek is removed in addition to 2. */ -#define _USE_STRFUNC 0 /* 0:Disable or 1/2:Enable */ +#define _USE_STRFUNC 1 /* 0:Disable or 1/2:Enable */ /* To enable string functions, set _USE_STRFUNC to 1 or 2. */ diff --git a/src/fileops.c b/src/fileops.c index 4e681d1..d5c5a60 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -55,7 +55,7 @@ void file_open_by_filinfo(FILINFO* fno) { file_res = l_openfilebycluster(&fatfs, &file_handle, (TCHAR*)"", fno->clust, fno->fsize); } -void file_open(uint8_t* filename, BYTE flags) { +void file_open(const uint8_t* filename, BYTE flags) { if (disk_state == DISK_CHANGED) { file_reinit(); newcard = 1; diff --git a/src/fileops.h b/src/fileops.h index 633ee25..f3b3c3d 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -40,7 +40,7 @@ uint16_t file_block_off, file_block_max; enum filestates file_status; void file_init(void); -void file_open(uint8_t* filename, BYTE flags); +void file_open(const uint8_t* filename, BYTE flags); FRESULT dir_open_by_filinfo(DIR* dir, FILINFO* fno_param); void file_open_by_filinfo(FILINFO* fno); void file_close(void); diff --git a/src/main.c b/src/main.c index 15ba57d..dcc8487 100644 --- a/src/main.c +++ b/src/main.c @@ -27,6 +27,7 @@ #include "msu1.h" #include "rtc.h" #include "sysinfo.h" +#include "cfg.h" #define EMC0TOGGLE (3<<4) #define MR0R (1<<1) @@ -45,8 +46,11 @@ extern volatile tick_t ticks; extern snes_romprops_t romprops; extern volatile int reset_changed; +extern volatile cfg_t CFG; + enum system_states { - SYS_RTC_STATUS = 0 + SYS_RTC_STATUS = 0, + SYS_LAST_STATUS = 1 }; int main(void) { @@ -138,6 +142,11 @@ printf("PCONP=%lx\n", LPC_SC->PCONP); readled(0); writeled(0); + cfg_load(); + cfg_save(); + sram_writebyte(cfg_is_last_game_valid(), SRAM_STATUS_ADDR+SYS_LAST_STATUS); + cfg_get_last_game(file_lfn); + sram_writeblock(strrchr((const char*)file_lfn, '/')+1, SRAM_LASTGAME_ADDR, 256); *fs_path=0; uint32_t saved_dir_id; get_db_id(&saved_dir_id); @@ -238,6 +247,9 @@ printf("PCONP=%lx\n", LPC_SC->PCONP); case SNES_CMD_LOADROM: get_selected_name(file_lfn); printf("Selected name: %s\n", file_lfn); + cfg_save_last_game(file_lfn); + cfg_set_last_game_valid(1); + cfg_save(); filesize = load_rom(file_lfn, SRAM_ROM_ADDR, LOADROM_WITH_SRAM | LOADROM_WITH_RESET); break; case SNES_CMD_SETRTC: @@ -253,6 +265,11 @@ printf("PCONP=%lx\n", LPC_SC->PCONP); sysinfo_loop(); cmd=0; /* stay in menu loop */ break; + case SNES_CMD_LOADLAST: + cfg_get_last_game(file_lfn); + printf("Selected name: %s\n", file_lfn); + filesize = load_rom(file_lfn, SRAM_ROM_ADDR, LOADROM_WITH_SRAM | LOADROM_WITH_RESET); + break; default: printf("unknown cmd: %d\n", cmd); cmd=0; /* unknown cmd: stay in loop */ diff --git a/src/memory.h b/src/memory.h index 7ee78e1..c2062d9 100644 --- a/src/memory.h +++ b/src/memory.h @@ -39,7 +39,8 @@ #define SRAM_CMD_ADDR (0xFF1000L) #define SRAM_PARAM_ADDR (0xFF1004L) #define SRAM_STATUS_ADDR (0xFF1100L) -#define SRAM_SYSINFO_ADDR (0xFF1110L) +#define SRAM_SYSINFO_ADDR (0xFF1200L) +#define SRAM_LASTGAME_ADDR (0xFF1420L) #define SRAM_MENU_SAVE_ADDR (0xFF0000L) #define SRAM_SCRATCHPAD (0xFFFF00L) #define SRAM_DIRID (0xFFFFF0L) diff --git a/src/snes.h b/src/snes.h index b8548e3..35a6c11 100644 --- a/src/snes.h +++ b/src/snes.h @@ -30,6 +30,7 @@ #define SNES_CMD_LOADROM (1) #define SNES_CMD_SETRTC (2) #define SNES_CMD_SYSINFO (3) +#define SNES_CMD_LOADLAST (4) #define MENU_ERR_OK (0) #define MENU_ERR_NODSP (1)