Skip to content

Commit 2766f60

Browse files
committed
add retry logic to system detection and default to NTSC
1 parent d4b6246 commit 2766f60

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

kernel/nintendo/reset.s

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ vblankwait1:
2020

2121
; We now have about 30,000 cycles to burn before the PPU stabilizes.
2222
; we'll use it to identify our system.
23+
lda #3 ; number of times to try system detection.
24+
countcycles:
25+
ldx #0
2326
ldy #0
2427

2528
vblankwait2:
@@ -40,6 +43,19 @@ noincy:
4043
; PAL NES | 33247 | 12.005 | $0A $D2 | $15 $A4
4144
; Dendy | 35464 | 12.005 | $0B $8A | $17 $14
4245

46+
; if Y is in the expected range then we should be able to correctly identify the system.
47+
cpy #$18
48+
bcc sysid ; branch if we can identify the system.
49+
50+
; we'll try counting cycles again until we get a usable result
51+
; or the maximum number of attempts is reached.
52+
sec
53+
sbc #1
54+
cmp #0
55+
beq isntsc ; branch if we have reached the max attempts. (assume NTSC since it's more likely).
56+
bne countcycles ; otherwise, count cycles again.
57+
58+
sysid:
4359
; check if we encountered 2 vblanks...
4460
tya
4561
cmp #$10
@@ -53,9 +69,10 @@ nodiv2:
5369
; NTSC FC/NES | 0
5470
; PAL NES | 1
5571
; Dendy | 2
56-
; unknown | 3+
57-
beq +
72+
; unknown | 3+ (shouldn't be possible)
73+
beq isntsc
5874
lda #larchf_pal
59-
+ ora #larch_nintendo
75+
isntsc:
76+
ora #larch_nintendo
6077
ora lk_archtype
6178
sta lk_archtype

lunix.fds

17 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)