Skip to content

Commit 51302bc

Browse files
XeroxxxXeroX
authored andcommitted
feat: Clear Slot B on reset; Make Slot B savegames work
1 parent 9d518b5 commit 51302bc

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/memory.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ uint16_t sram_writeblock(void* buf, uint32_t addr, uint16_t size) {
235235

236236
char current_filename[258];
237237
char slotb_filename[258];
238+
uint32_t slotb_ramsize_bytes = 0; /* Slot B SRAM size in bytes; 0 when no Slot B or no SRAM */
238239
uint32_t load_rom(uint8_t* filename, uint32_t base_addr, uint8_t flags) {
239240
UINT bytes_read;
240241
DWORD filesize;
@@ -389,6 +390,7 @@ uint32_t load_rom(uint8_t* filename, uint32_t base_addr, uint8_t flags) {
389390
/* Read Slot B SRAM size from ST header byte 0x37 (2KB units) */
390391
uint32_t slotb_ramsize = (uint32_t)sram_readbyte(0x600037) * 2048;
391392
slotb_rammask = slotb_ramsize ? (slotb_ramsize - 1) : 0;
393+
slotb_ramsize_bytes = slotb_ramsize;
392394
/* Initialize Slot B SRAM region (0xE80000) and load from .srm file */
393395
if(slotb_ramsize) {
394396
sram_memset(0xE80000, slotb_ramsize, 0xFF);

src/memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
extern char current_filename[];
3434
extern char slotb_filename[];
35+
extern uint32_t slotb_ramsize_bytes;
3536

3637
#define MENU_ADDR_BRAM_SRC (0xFF00)
3738

src/snes.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ void prepare_reset() {
114114
save_srm(file_lfn, romprops.ramsize_bytes, SRAM_SAVE_ADDR);
115115
writeled(0);
116116
}
117+
if(slotb_ramsize_bytes && fpga_test() == FPGA_TEST_TOKEN) {
118+
writeled(1);
119+
save_srm((uint8_t*)slotb_filename, slotb_ramsize_bytes, 0xE80000);
120+
writeled(0);
121+
}
117122
// don't save SGB RTC since we are in reset and it may be undefined
118123
rdyled(1);
119124
readled(1);
@@ -123,7 +128,8 @@ void prepare_reset() {
123128
snes_reset(1);
124129
fpga_dspx_reset(1);
125130
delay_ms(200);
126-
slotb_filename[0] = 0; /* clear Slot B selection on every return-to-menu */
131+
slotb_filename[0] = 0; /* clear Slot B selection on every return-to-menu */
132+
slotb_ramsize_bytes = 0;
127133
}
128134

129135
void snes_init() {
@@ -314,6 +320,7 @@ uint8_t snes_main_loop() {
314320
printf("SaveRAM CRC: 0x%04lx; saving %s\n", saveram_crc, file_lfn);
315321
writeled(1);
316322
save_srm(file_lfn, romprops.ramsize_bytes, SRAM_SAVE_ADDR);
323+
if(slotb_ramsize_bytes) save_srm((uint8_t*)slotb_filename, slotb_ramsize_bytes, 0xE80000);
317324
last_save_failed = save_failed;
318325
save_failed = file_res ? 1 : 0;
319326
didnotsave = save_failed ? 25 : 0;
@@ -324,6 +331,7 @@ uint8_t snes_main_loop() {
324331
diffcount=0;
325332
writeled(1);
326333
save_srm(file_lfn, romprops.ramsize_bytes, SRAM_SAVE_ADDR);
334+
if(slotb_ramsize_bytes) save_srm((uint8_t*)slotb_filename, slotb_ramsize_bytes, 0xE80000);
327335
last_save_failed = save_failed;
328336
save_failed = file_res ? 1 : 0;
329337
didnotsave = save_failed ? 25 : 0;

0 commit comments

Comments
 (0)