Permalink
Browse files

Added dedicated snes reset loop.

  • Loading branch information...
RedGuyyyy committed Sep 5, 2018
1 parent 8ca0fc6 commit 0f3997c3698f67609927880a5535d2235a063ead
Showing with 52 additions and 5 deletions.
  1. +3 −1 snes/nmihook.a65
  2. +1 −1 src/config
  3. +3 −3 src/main.c
  4. +4 −0 src/memory.c
  5. +4 −0 src/msu1.c
  6. +34 −0 src/snes.c
  7. +3 −0 src/snes.h
View
@@ -123,12 +123,14 @@ resethook: ; EMULATION MODE
dey
bmi +
; perform reset
lda #$80
lda #$85
sta @MCU_CMD
- bra -
; clean up state
+ dex
stx $4207
lda #$86
sta @MCU_CMD
resethook_loop:
- lda $4212
View
@@ -1,4 +1,4 @@
CONFIG_VERSION="1.8.0-sa1-v07"
CONFIG_FWVER=0xFEFFFFF0
CONFIG_FWVER=0xFEFFFFEF
#CONFIG_FWVER=0x44534E53
CONFIG_MCU_FOSC=12000000
View
@@ -366,10 +366,10 @@ printf("PCONP=%lx\n", LPC_SC->PCONP);
cmd=snes_main_loop();
if(cmd) {
switch(cmd) {
case SNES_CMD_RESET_LOOP_FAIL:
snes_reset_loop();
break;
case SNES_CMD_RESET:
// TODO: add reset loop here to speedup reset cycling for proper clock alignment.
// A reset loop will also be needed when first entering the game loop from the menu to avoid long running tasks stalling it.
// Ideally, there would only be one code loop that does it and it will count failures to allow the loop to exit at some point.
snes_reset_pulse();
break;
case SNES_CMD_RESET_TO_MENU:
View
@@ -413,8 +413,12 @@ uint32_t load_rom(uint8_t* filename, uint32_t base_addr, uint8_t flags) {
// XXX cheat_yaml_save(filename);
cheat_program();
fpga_set_features(romprops.fpga_features);
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 checksum is no longer valid
View
@@ -179,6 +179,10 @@ int msu1_loop() {
cmd = snes_get_mcu_cmd();
if(cmd) {
switch(cmd) {
case SNES_CMD_RESET_LOOP_FAIL:
msu_res = SNES_RESET_SHORT;
snes_reset_loop();
break;
case SNES_CMD_RESET:
msu_res = SNES_RESET_SHORT;
snes_reset_pulse();
View
@@ -122,6 +122,40 @@ void snes_reset(int state) {
BITBAND(SNES_RESET_REG->FIODIR, SNES_RESET_BIT) = state;
}
/*
* provides a mini reset environment to speed reset for clock synchronization
*
* returns: upon loop exit returns the current non-reset related command
*/
uint8_t snes_reset_loop(void) {
uint8_t cmd = 0;
while(fpga_test() == FPGA_TEST_TOKEN) {
cmd = snes_get_mcu_cmd();
if (cmd) {
printf("snes_reset_loop: cmd=%hhx\n", cmd);
switch (cmd) {
case SNES_CMD_RESET_LOOP_FAIL:
snes_set_mcu_cmd(0);
cmd = 0;
snes_reset_pulse();
delay_us(SNES_RELEASE_RESET_DELAY_US);
break;
case SNES_CMD_RESET_LOOP_PASS:
snes_set_mcu_cmd(0);
cmd = 0;
default:
goto snes_reset_loop_out;
}
}
}
snes_reset_loop_out:
return cmd;
}
/*
* gets the SNES reset state.
*
View
@@ -46,6 +46,8 @@
#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 MCU_CMD_RDY (0x55)
@@ -109,6 +111,7 @@ void snes_reset_pulse(void);
void snes_reset(int state);
uint8_t get_snes_reset(void);
uint8_t get_snes_reset_state(void);
uint8_t snes_reset_loop(void);
uint8_t snes_main_loop(void);
uint8_t menu_main_loop(void);
void get_selected_name(uint8_t* lfn);

0 comments on commit 0f3997c

Please sign in to comment.