Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/mrehkopf/sd2snes into usb
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/cfg.c
#	src/config
#	src/fpga.h
#	src/led.c
#	src/main.c
#	src/memory.c
#	src/msu1.c
#	src/smc.c
#	src/snes.c
#	src/snes.h
#	verilog/sd2snes/main.v
  • Loading branch information
RedGuyyyy committed Dec 16, 2018
2 parents b8874f7 + 21e0b37 commit 4c0c9a9
Show file tree
Hide file tree
Showing 93 changed files with 23,706 additions and 612 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
v1.9.0
======
* add SA-1 support by RedGuy
* add partial SRAM change detection for known games (SuperFX/SA-1) by RedGuy
this enables sensible autosaving for games that use part SRAM as work RAM,
without having to resort to periodic saving. I added some more games to the
known CRC list.
Note that this feature performs full ROM CRC calculation after loading and
running the ROM so firmware is unresponsive to in-game hooks and resetting
for a couple of seconds after the game has started. I have some ideas for
optimization.
* add option to always go back to menu when resetting
* add LED brightness setting
* add an option to start out with cheats enabled or disabled
* disable Satellaview emulation when a real Satellaview unit is present to
avoid conflicts and facilitate Satellaview development
* add SNES CPU <-> PPU clock phase alignment correction on reset
(fixes flickering sprite slabs e.g. giant Frog in Chrono Trigger, sprites in
Kirby Super Star, Star Ocean...)
* show current effective video mode (50/60Hz) in System Information
* fixes:
- earlier signal edge detection, improving stability on some consoles
- fix timing of auto region patching
- fix brightness patching for games that use HDMA to set brightness/blanking
- fix an occasional lockup when loading a game that uses OBC-1/SuperFX/SA-1
- fix SuperCIC pair mode entry for consoles with <= 3.072MHz CIC clock
- reset S-RTC register state on reset

v1.8.0
======
* add SuperFX support by RedGuy (v10)
Expand Down
55 changes: 39 additions & 16 deletions cic/mangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void mangle(unsigned char* data) {
a+=data[offset]+carry;
}
temp=a; a=data[offset]; data[offset++]=temp&0xf;

while(offset<0x10) {
a++;
a+=data[offset]+carry;
Expand All @@ -62,33 +62,55 @@ void mangle(unsigned char* data) {
} while(carry);
}

int main(void) {
int main(int argc, char **argv) {
unsigned char *label[2];
unsigned char restart=1;
unsigned char keyseed[16]={0x0, // dummy
unsigned char restart = 1, swap = 0;
long streamno = 0;
char *endptr;
unsigned char lockseed[16]={0x0, // dummy
0xb,0x1,0x4,0xf,
0x4,0xb,0x5,0x7,
0xf,0xd,0x6,0x1,
0xe,0x9,0x8};
unsigned char lockseed[16]={0x0, // dummy
0xf,0x9,0xa,0x1,
unsigned char keyseed[16]={0x0, // dummy
0x0, // fill-in value sent by lock on reset in bit order 3-0-1-2
0x9,0xa,0x1,
0x8,0x5,0xf,0x1,
0x1,0xe,0x1,0x0,
0xd,0xe,0xc};

if(argc < 2) {
printf("Usage: %s <stream number>\n\n", argv[0]);
printf("<stream number> selects one of 16 fill-in values sent by the lock on reset.\n");
printf("Both sides use it as the first nibble of the seed initially sent on D1 by\n");
printf("the lock. Transmission bit order is 3-0-1-2. e.g. '1-0-1-1' => 0xe\n");
return -1;
}

streamno = strtol(argv[1], &endptr, 0);
printf("%p %p\n", argv[1], endptr);
if(*endptr) {
printf("invalid format for stream number. example: decimal: 15, hex: 0xe, oct: 017\n");
return 1;
}
if(streamno > 15 || streamno < 0) {
printf("invalid stream number. Valid range is 0x0-0xf\n");
return 1;
}
keyseed[1] = (unsigned char) streamno;
printf("initial seeds:\n");
printseed(keyseed);
printseed(lockseed);
printseed(keyseed);
printf("\n");

label[0] = "LockInKeyOut";
label[1] = "LockOutKeyIn";
label[0] = "LockOutKeyIn";
label[1] = "LockInKeyOut";
while(1) {
printf("\n");
printf("D0[%s]: ", label[0]);
printstream(keyseed, restart);
printstream(swap ? keyseed : lockseed, restart);
printf("D1[%s]: ", label[1]);
printstream(lockseed, restart);
printstream(swap ? lockseed : keyseed, restart);
mangle(keyseed);
mangle(keyseed);
mangle(keyseed);
Expand All @@ -98,13 +120,14 @@ while(1) {

//printseed(keyseed);
//printseed(lockseed);
restart=lockseed[7];
if(lockseed[7] & 1) {
label[0] = "LockOutKeyIn";
label[1] = "LockInKeyOut";
} else {
restart = keyseed[7];
swap = restart & 1;
if(swap) {
label[0] = "LockInKeyOut";
label[1] = "LockOutKeyIn";
} else {
label[0] = "LockOutKeyIn";
label[1] = "LockInKeyOut";
}
// lockseed[3]=lockseed[7];
if(!restart)restart=1;
Expand Down
32 changes: 8 additions & 24 deletions cic/supercic/supercic-key.asm
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,12 @@ isr
init
org 0x0010
bcf STATUS, RP0
nop
clrf GPIO
movlw 0x07 ; GPIO2..0 are digital I/O (not connected to comparator)
movwf CMCON
movlw 0x90 ; global enable interrupts + enable external interrupt
movwf INTCON
bsf STATUS, RP0
nop
movlw 0x2d ; in out in in out in
movwf TRISIO
movlw 0x24 ; pullups for reset+clk to avoid errors when no CIC in host
Expand All @@ -119,18 +117,15 @@ init
movwf OPTION_REG
bcf STATUS, RP0
nop
bsf GPIO, 4 ; LED on
idle
goto idle ; wait for interrupt from lock

main
bsf STATUS, RP0
nop
bsf TRISIO, 0
bcf TRISIO, 1
bcf STATUS, RP0
nop
; --------INIT LOCK SEED (what the lock sends)--------
movlw 0xb
movwf 0x21
Expand Down Expand Up @@ -165,12 +160,10 @@ main
; --------INIT KEY SEED (what we must send)--------
bsf STATUS, RP0 ; D/F411 and D/F413
nop
clrf EEADR ; differ in 2nd seed nibble
bsf EECON1, RD ; of key stream,
movf EEDAT, w ; restore saved nibble from EEPROM
bcf STATUS, RP0
nop
movwf 0x32
movlw 0xa
movwf 0x33
Expand Down Expand Up @@ -236,12 +229,9 @@ main
btfsc GPIO, 0 ; check stream ID bit
bsf 0x31, 2 ; copy to lock seed
bsf STATUS, RP0
nop
bcf TRISIO, 0
bsf TRISIO, 1
bcf STATUS, RP0
nop
nop
movlw 0x27 ; "wait" 1
call wait ; wait 121
; --------main loop--------
Expand All @@ -251,6 +241,7 @@ loop0
addlw 0x30 ; key stream
movwf FSR ; store in index reg
loop1
nop
nop
nop
movf INDF, w ; load seed value
Expand All @@ -262,19 +253,21 @@ loop1
movf 0x20, w
movwf GPIO
nop
nop
movlw 0x10
movwf GPIO ; reset GPIO
movlw 0x14
movlw 0x13
call wait
nop
btfsc 0x5d, 0 ; pair mode available signal
bcf GPIO, 4 ;
nop
nop
bsf GPIO, 4 ;
bsf GPIO, 4 ;
btfsc GPIO, 0 ; both pins must be low...
goto die
btfsc GPIO, 1 ; ...when no bit transfer takes place
goto die ; if not -> lock cic error state -> die
goto die ; if not -> lock cic error state -> die
incf FSR, f ; next one
movlw 0xf
andwf FSR, w
Expand All @@ -290,19 +283,16 @@ loop1
btfsc 0x37, 0
goto swap
bsf STATUS, RP0
nop
bcf TRISIO, 0
bsf TRISIO, 1
goto swapskip
swap
bsf STATUS, RP0
nop
bsf TRISIO, 0
bcf TRISIO, 1
nop
swapskip
bcf STATUS, RP0
nop
movf 0x37, w
andlw 0xf
btfss STATUS, Z
Expand Down Expand Up @@ -709,13 +699,11 @@ die
movlw 0x3a ;wait 50ms before writing
call longwait ;("error" might be due to power loss)
bsf STATUS, RP0
nop
clrw
movwf EEADR
bsf EECON1, RD
movf EEDAT, w
bcf STATUS, RP0
nop
movwf 0x4d
btfsc 0x4d, 0
goto die_reg_6
Expand All @@ -726,7 +714,6 @@ die_reg_6
movlw 0x6 ; died with NTSC, fall back to PAL
die_reg_cont
bsf STATUS, RP0
nop
movwf EEDAT
bsf EECON1, WREN

Expand All @@ -743,19 +730,16 @@ die_intloop
bsf INTCON, GIE

bcf STATUS, RP0
nop
bcf GPIO, 4
; --------get caught up--------
die_trap
goto die_trap
; -----------------------------------------------------------------------
supercic_pairmode
bsf STATUS, RP0
nop
bsf TRISIO, 0
bsf TRISIO, 1
bcf STATUS, RP0
nop
supercic_pairmode_loop
bsf GPIO, 4
nop
Expand All @@ -764,6 +748,6 @@ supercic_pairmode_loop
goto supercic_pairmode_loop

; eeprom memory
DEEPROM CODE
org __EEPROM_START
de 0x09 ; D411 (NTSC)
end
end
24 changes: 23 additions & 1 deletion snes/const.a65
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,16 @@ mtext_browser_sort .byt "Sort directories", 0
mtext_browser_hide_ext .byt "Hide file extensions", 0
mtext_browser_screensaver .byt "Screensaver", 0
mtext_browser_screensaver_timeout .byt "Fade screen after", 0
mtext_browser_ledbright .byt "LED brightness", 0
mtext_ingame_cheats .byt "Start with cheats enabled", 0
mtext_ingame_shortreset .byt "Reset to menu", 0
mtext_ingame_enable .byt "In-game hook", 0
mtext_ingame_buttons .byt " ",129,"In-game buttons", 0
mtext_ingame_holdoff .byt " ",129,"Initial holdoff", 0
mtext_ingame_regionpatch .byt "Auto region patch", 0
mtext_ingame_1chiptransientfixes .byt "1CHIP transient fixes", 0
mtext_ingame_brightlimit .byt "Brightness limit", 0
mtext_ingame_resetpatch .byt "Reset patch for clock phase", 0
mtext_chip_cx4_speed .byt "Cx4 speed", 0
mtext_chip_gsu_speed .byt "SuperFX speed", 0
mtext_chip_msu1_volume_boost .byt "MSU-1 volume boost", 0
Expand All @@ -234,13 +237,16 @@ mdesc_browser_sort .byt "Choose whether to sort file lists", 0
mdesc_browser_hide_ext .byt "Choose whether to hide file extensions", 0
mdesc_browser_screensaver .byt "Fade-out the screen after some time", 0
mdesc_browser_screensaver_timeout .byt "Set time after which to fade the screen", 0
mdesc_browser_ledbright .byt "Change brightness of LEDs", 0
mdesc_ingame_cheats .byt "Whether to start out with cheats enabled. Can be changed using in-game buttons", 0
mdesc_ingame_shortreset .byt "Go back to menu on short reset if enabled", 0
mdesc_ingame_enable .byt "Required for in-game buttons and 7E/7F cheats", 0
mdesc_ingame_buttons .byt "Enable in-game buttons (reset, en/disable cheats", 127, 128, "). Requires in-game hook to be enabled.", 0
mdesc_ingame_holdoff .byt "Wait 10 seconds before enabling hook (helps some games boot with hook enabled)", 0
mdesc_ingame_regionpatch .byt "Bypass simple region protection by games", 0
mdesc_ingame_1chiptransientfixes .byt "Patch brightness changes to fix sync glitches, fading scanlines and missing shadow on 1CHIP/Jr. consoles", 0
mdesc_ingame_brightlimit .byt "Limit overall brightness (e.g. on 1CHIP consoles to meet RGB line levels)", 0
mdesc_ingame_resetpatch .byt "Enable reset patch to align clocks. Fixes graphical issues in some games", 0
mdesc_chip_cx4_speed .byt "Set speed of Cx4 soft core", 0
mdesc_chip_gsu_speed .byt "Set speed of SuperFX soft core", 0
mdesc_chip_msu1_volume_boost .byt "Set volume boost for MSU1 audio if your sd2snes is too quiet (Rev. E-G)", 0
Expand All @@ -253,7 +259,7 @@ text_statusbar_keys .byt "A:Select B:Back X:Menu", 0
text_statusbar_spc .byt "B:Back", 0
text_statusbar_menu .byt "A:Select B:Back", 0
text_last .byt "Recent games", 0
text_system .byt "CPU Rev.: x PPU1 Rev.: y PPU2 Rev.: z",0
text_system .byt "CPU/PPU1/PPU2: a/b/c VMode: x0Hz",0

text_on .byt "On", 0
text_off .byt "Off", 0
Expand Down Expand Up @@ -293,6 +299,22 @@ text_minus5 .byt "-5", 0
text_minus6 .byt "-6", 0
text_minus7 .byt "-7", 0

text_1 .byt "1", 0
text_2 .byt "2", 0
text_3 .byt "3", 0
text_4 .byt "4", 0
text_5 .byt "5", 0
text_6 .byt "6", 0
text_7 .byt "7", 0
text_8 .byt "8", 0
text_9 .byt "9", 0
text_10 .byt "10", 0
text_11 .byt "11", 0
text_12 .byt "12", 0
text_13 .byt "13", 0
text_14 .byt "14", 0
text_15_max .byt "15 (max)", 0

text_3_5db .byt "+3.5dBFS", 0
text_6db .byt "+6dBFS", 0
text_9_5db .byt "+9.5dBFS", 0
Expand Down
4 changes: 1 addition & 3 deletions snes/header.a65
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ NMI_8bit:
.byt "MR" ; 2 bytes - company id
.byt "SNSD" ; 4 bytes - rom id

;*= $C0FFC0
; .byt "SD2SNES MAIN MENU "
*= $C0FFC0
.byt "SD2SNES MENU v1.8.0 "
.byt "SD2SNES MENU v1.9.0 "
; 123456789012345678901 - max 21 chars

*= $C0FFD5 .byt $31 ; rom map + speed (HiROM FastROM)
Expand Down
26 changes: 26 additions & 0 deletions snes/main.a65
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,29 @@ detect_ultra16_out:
sta @$0021c0
plp
rts

detect_satellaview:
php
sep #$20 : .as
lda #$aa
sta $2188
cmp $2188
bne detect_satellaview_out
lda #$55
sta $2188
cmp $2188
bne detect_satellaview_out
detect_satellaview_found:
stz $2188
stz $2189
stz $218e
stz $218f
lda #$01
sta @ST_HAS_SATELLAVIEW
plp
rts
detect_satellaview_out:
lda #$00
sta @ST_HAS_SATELLAVIEW
plp
rts
Loading

0 comments on commit 4c0c9a9

Please sign in to comment.