Skip to content

Commit

Permalink
Merge branch 'develop' of ssh://github.com/mrehkopf/sd2snes into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehkopf committed Sep 3, 2018
2 parents e894661 + 2586c60 commit 77686a6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 10 deletions.
2 changes: 1 addition & 1 deletion snes/memmap.i65
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 46 additions & 1 deletion snes/nmihook.a65
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/config
Original file line number Diff line number Diff line change
@@ -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
9 changes: 5 additions & 4 deletions src/snes.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,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] != '/') {
Expand Down Expand Up @@ -399,12 +399,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() {
Expand Down
2 changes: 1 addition & 1 deletion src/snes.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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)
Expand Down

0 comments on commit 77686a6

Please sign in to comment.