Permalink
Browse files

Merge pull request #109 from RedGuyyyy/reset

Added experimental reset check for clock alignment.
  • Loading branch information...
mrehkopf committed Aug 31, 2018
2 parents c7cc929 + 29ce6a7 commit 2586c60be32cdcc2bb6b347762d04ce67f087016
Showing with 56 additions and 10 deletions.
  1. +1 −1 snes/memmap.i65
  2. +46 −1 snes/nmihook.a65
  3. +1 −1 src/cli.c
  4. +2 −2 src/config
  5. +5 −4 src/snes.c
  6. +1 −1 src/snes.h
View
@@ -28,7 +28,7 @@
#define NMI_VECT_DISABLE $002BFD
#define NMI_WRAM_PATCH_DISABLE $002BFE
#define NMI_WRAM_PATCH_COUNT $002BFF
#define NMI_WRAM_CHEATS $002A90
#define NMI_WRAM_CHEATS $002B00
#define WINDOW_STACK_BASE $7E2000
#define BG2_TILE_BUF $7EA000
View
@@ -86,12 +86,57 @@ nmi_stop:
resethook: ; EMULATION MODE
.as : .xs
; mask interrupt handler call
sei
; x stores the count of scanlines
ldx #$20
ldy #$00
; setup irq on h-position $100. this value was acquired via manual training
lda #$00
sta $4207
inc
sta $4208
lda #$10
sta $4200
- wai
; sep seems to set the alignment correctly so an integer value in $4207/$4208 detects h-blank
; there seem to be more distinct phases now. different padding may change this.
sep #$20
lda $4212
; ignore lines in v-blank
bmi +
; decrement non-vblank scanlines encountered
dex
; shift h-blank bit into upper position
asl
; no error if not in h-blank
bpl +
; increment error counter if h-blank is set (early h-blank)
iny
; ack interrupt and check if we have hit all scanlines
+ lda $4211
cpx #$00
bne -
; stop interrupts and check if we have any errors
stz $4200
dey
bmi +
; perform reset
lda #$80
sta @MCU_CMD
- bra -
; clean up state
+ dex
stx $4207
resethook_loop:
- lda $4212
bpl -
- lda $4212
bmi -
lda $213f
bmi resethook
bmi resethook_loop
stz NMI_VECT_DISABLE
jmp ($fffc)
View
@@ -437,7 +437,7 @@ void cmd_cheat(void) {
void cmd_test(void) {
int i;
uint8_t databuf[512];
fpga_set_snescmd_addr(0);
fpga_set_snescmd_addr(SNESCMD_MCU_CMD);
for(i=0; i<512; i++) {
databuf[i]=fpga_read_snescmd();
}
View
@@ -1,3 +1,3 @@
CONFIG_VERSION="1.8.0"
CONFIG_FWVER=0x01080000
CONFIG_VERSION="1.8.0-reset"
CONFIG_FWVER=0x11080000
CONFIG_MCU_FOSC=12000000
View
@@ -257,7 +257,7 @@ void get_selected_name(uint8_t* fn) {
uint32_t fdaddr;
char *dot;
cwdaddr = snes_get_mcu_param();
fdaddr = snescmd_readlong(0x08);
fdaddr = snescmd_readlong(SNESCMD_MCU_CMD + 0x08);
printf("cwd addr=%lx fdaddr=%lx\n", cwdaddr, fdaddr);
uint16_t count = sram_readstrn(fn, cwdaddr, 256);
if(count && fn[count-1] != '/') {
@@ -398,12 +398,13 @@ uint16_t snescmd_readstrn(void *buf, uint16_t addr, uint16_t size) {
return elemcount;
}
#define BRAM_SIZE (256 - (SNESCMD_MCU_PARAM - SNESCMD_MCU_CMD))
void snescmd_prepare_nmihook() {
uint16_t bram_src = sram_readshort(SRAM_MENU_ADDR + MENU_ADDR_BRAM_SRC);
uint8_t bram[224];
sram_readblock(bram, SRAM_MENU_ADDR + bram_src, 224);
uint8_t bram[BRAM_SIZE];
sram_readblock(bram, SRAM_MENU_ADDR + bram_src, BRAM_SIZE);
// snescmd_writeblock(bram, SNESCMD_HOOKS, 40);
snescmd_writeblock(bram, 0x4, 224);
snescmd_writeblock(bram, SNESCMD_MCU_PARAM, BRAM_SIZE);
}
void status_load_to_menu() {
View
@@ -75,7 +75,7 @@
#define SNESCMD_NMI_ENABLE_BUTTONS (0x2bfc)
#define SNESCMD_NMI_DISABLE_WRAM (0x2bfe)
#define SNESCMD_NMI_WRAM_PATCH_COUNT (0x2bff)
#define SNESCMD_WRAM_CHEATS (0x2a90)
#define SNESCMD_WRAM_CHEATS (0x2b00)
#define ASM_LDA_IMM (0xa9)
#define ASM_STA_ABSLONG (0x8f)

0 comments on commit 2586c60

Please sign in to comment.