Permalink
Browse files

Formatting

  • Loading branch information...
mrehkopf committed Nov 18, 2018
1 parent 72e040c commit 531d02abcd7238f831479b5587bf9242b0ab6ca0
Showing with 47 additions and 46 deletions.
  1. +1 −1 snes/nmihook.a65
  2. +2 −2 src/memory.c
  3. +1 −1 src/msu1.c
  4. +19 −18 src/snes.c
  5. +24 −24 src/snes.h
@@ -134,7 +134,7 @@ resethook: ; EMULATION MODE
resethook_skip:
lda #$86
sta @MCU_CMD
resethook_loop:
- lda $4212
bpl -
@@ -418,11 +418,11 @@ uint32_t load_rom(uint8_t* filename, uint32_t base_addr, uint8_t flags) {
snes_set_mcu_cmd(0);
snes_reset(0);
fpga_dspx_reset(0);
// handle reset loop from hook
snes_reset_loop();
}
// loading a new rom implies the previous crc is no longer valid
sram_crc_valid = 0;
sram_crc_romsize = filesize - romprops.offset;
@@ -182,7 +182,7 @@ int msu1_loop() {
case SNES_CMD_RESET_LOOP_FAIL:
msu_res = SNES_RESET_SHORT;
snes_reset_loop();
break;
break;
case SNES_CMD_RESET:
msu_res = SNES_RESET_SHORT;
snes_reset_pulse();
@@ -481,30 +481,31 @@ void status_save_from_menu() {
sram_readblock(&ST, SRAM_STATUS_ADDR, sizeof(status_t));
}
// The goals of this function are the following:
// - detect a small, fixed set of popular games where the save location is a known, strict subset of sram.
// this avoids switching to the periodic save to sd mode.
// - revert to full sram save if there is any change in the rom. this includes minor hacks that don't change save location.
// - not support any user control beyond rom modification.
// user control is very error prone: bad crc when rom is modified, incorrect save region definition, etc.
// - very limited rom hack coverage. if the hack changes then it will no longer benefit without an updated crc.
//
// The full sram location is still loaded and saved. The restricted bounds are only used to detect when to save.
/*
The goals of this function are the following:
- detect a small, fixed set of popular games where the save location is a known, strict subset of sram.
this avoids switching to the periodic save to sd mode.
- revert to full sram save if there is any change in the rom. this includes minor hacks that don't change save location.
- not support any user control beyond rom modification.
user control is very error prone: bad crc when rom is modified, incorrect save region definition, etc.
- very limited rom hack coverage. if the hack changes then it will no longer benefit without an updated crc.
The full sram location is still loaded and saved. The restricted bounds are only used to detect when to save.
*/
void recalculate_sram_range() {
if (!sram_crc_valid && sram_valid) {
// insert arbitrary delay to avoid startup problem in some games
delay_ms(2000);
printf("calculating rom hash (base=%06lx, size=%ld): ", SRAM_ROM_ADDR + romprops.load_address, sram_crc_romsize);
// there is a very small chance of collision. there are several ways to avoid this:
// - incorporate (concatenate) checksum16 or other information
// - use a better hash function like sha-256
/*
there is a very small chance of collision. there are several ways to avoid this:
- incorporate (concatenate) checksum16 or other information
- use a better hash function like sha-256
*/
uint32_t crc = calc_sram_crc(SRAM_ROM_ADDR + romprops.load_address, sram_crc_romsize);
printf("%08lx\n", crc);
if (crc_valid) {
sram_crc_valid = 1;
sram_crc_valid = 1;
for (uint32_t i = 0; i < (sizeof(SramOffsetTable)/sizeof(SramOffset)); i++) {
if (crc == SramOffsetTable[i].crc) {
romprops.srambase = SramOffsetTable[i].base;
@@ -513,6 +514,6 @@ void recalculate_sram_range() {
break;
}
}
}
}
}
}
@@ -27,32 +27,32 @@
#ifndef SNES_H
#define SNES_H
#define SNES_CMD_LOADROM (0x01)
#define SNES_CMD_SETRTC (0x02)
#define SNES_CMD_SYSINFO (0x03)
#define SNES_CMD_LOADLAST (0x04)
#define SNES_CMD_LOADSPC (0x05)
#define SNES_CMD_SET_ALLOW_PAIR (0x07)
#define SNES_CMD_SET_VIDMODE_GAME (0x08)
#define SNES_CMD_SET_VIDMODE_MENU (0x09)
#define SNES_CMD_READDIR (0x0a)
#define SNES_CMD_FPGA_RECONF (0x0b)
#define SNES_CMD_LOAD_CHT (0x0c)
#define SNES_CMD_SAVE_CHT (0x0d)
#define SNES_CMD_SAVE_CFG (0x0e)
#define SNES_CMD_LED_BRIGHTNESS (0x12)
#define SNES_CMD_RESET (0x80)
#define SNES_CMD_RESET_TO_MENU (0x81)
#define SNES_CMD_ENABLE_CHEATS (0x82)
#define SNES_CMD_DISABLE_CHEATS (0x83)
#define SNES_CMD_KILL_NMIHOOK (0x84)
#define SNES_CMD_RESET_LOOP_FAIL (0x85)
#define SNES_CMD_RESET_LOOP_PASS (0x86)
#define SNES_CMD_GAMELOOP (0xff)
#define SNES_CMD_LOADROM (0x01)
#define SNES_CMD_SETRTC (0x02)
#define SNES_CMD_SYSINFO (0x03)
#define SNES_CMD_LOADLAST (0x04)
#define SNES_CMD_LOADSPC (0x05)
#define SNES_CMD_SET_ALLOW_PAIR (0x07)
#define SNES_CMD_SET_VIDMODE_GAME (0x08)
#define SNES_CMD_SET_VIDMODE_MENU (0x09)
#define SNES_CMD_READDIR (0x0a)
#define SNES_CMD_FPGA_RECONF (0x0b)
#define SNES_CMD_LOAD_CHT (0x0c)
#define SNES_CMD_SAVE_CHT (0x0d)
#define SNES_CMD_SAVE_CFG (0x0e)
#define SNES_CMD_LED_BRIGHTNESS (0x12)
#define SNES_CMD_RESET (0x80)
#define SNES_CMD_RESET_TO_MENU (0x81)
#define SNES_CMD_ENABLE_CHEATS (0x82)
#define SNES_CMD_DISABLE_CHEATS (0x83)
#define SNES_CMD_KILL_NMIHOOK (0x84)
#define SNES_CMD_RESET_LOOP_FAIL (0x85)
#define SNES_CMD_RESET_LOOP_PASS (0x86)
#define SNES_CMD_RESET_LOOP_TIMEOUT (0x87)
#define SNES_CMD_GAMELOOP (0xff)
#define MCU_CMD_RDY (0x55)
#define MCU_CMD_ERR (0xaa)
#define MCU_CMD_RDY (0x55)
#define MCU_CMD_ERR (0xaa)
#define MENU_ERR_OK (0x0)
#define MENU_ERR_FS (0x1)

0 comments on commit 531d02a

Please sign in to comment.