@@ -217,6 +217,7 @@ presetIndex := $60E
217217pausedOutOfDateRenderFlags := $60F ; 0 - statistics 1 - saveslot
218218debugLevelEdit := $610
219219debugNextCounter := $611
220+ regionFlag := $612
220221
221222; ... $67F
222223musicStagingSq1Lo: = $0680
@@ -278,6 +279,7 @@ highScoreNames := $0700
278279highScoreScoresA: = $0730
279280; highScoreScoresB:= $073C
280281highScoreLevels := $0748
282+ ; .. bunch of unused stuff: highScoreNames sized
281283initMagic := $0750 ; Initialized to a hard-coded number. When resetting, if not correct number then it knows this is a cold boot
282284
283285menuSeedCursorIndex := $760
@@ -330,9 +332,9 @@ MMC1_CHR1 := $DFFF
330332.segment "PRG_chunk1" : absolute
331333
332334; incremented to reset MMC1 reg
333- initRam: ldx #$00
335+ initRam:
336+ ldx #$00
334337 jmp initRamContinued
335-
336338nmi: pha
337339 txa
338340 pha
@@ -500,6 +502,53 @@ initRamContinued:
500502@continue:
501503 jmp @mainLoop
502504
505+ checkRegion:
506+ lda regionFlag
507+ beq @check
508+ rts
509+ @check:
510+ lda #1
511+ sta regionFlag
512+ ; region detection via http://forums.nesdev.com/viewtopic.php?p=163258#p163258
513+ ;;; use the power-on wait to detect video system-
514+ ldx #0
515+ ldy #0
516+ @vwait1:
517+ bit $2002
518+ bpl @vwait1 ; at this point, about 27384 cycles have passed
519+ @vwait2:
520+ inx
521+ bne @noincy
522+ iny
523+ @noincy:
524+ bit $2002
525+ bpl @vwait2 ; at this point, about 57165 cycles have passed
526+
527+ ;;; BUT because of a hardware oversight, we might have missed a vblank flag.
528+ ;;; so we need to both check for 1Vbl and 2Vbl
529+ ;;; NTSC NES: 29780 cycles / 12.005 -> $9B0 or $1361 (Y:X)
530+ ;;; PAL NES: 33247 cycles / 12.005 -> $AD1 or $15A2
531+ ;;; Dendy: 35464 cycles / 12.005 -> $B8A or $1714
532+
533+ tya
534+ cmp #16
535+ bcc @nodiv2
536+ lsr
537+ @nodiv2:
538+ clc
539+ adc #<-9
540+ cmp #3
541+ bcc @noclip3
542+ lda #3
543+ @noclip3:
544+ ;;; Right now, A contains 0,1,2,3 for NTSC,PAL,Dendy,Bad
545+ cmp #0
546+ beq @ntsc
547+ lda #1
548+ sta palFlag
549+ @ntsc:
550+ rts
551+
503552gameMode_playAndEndingHighScore_jmp:
504553 jsr gameMode_playAndEndingHighScore
505554 rts
@@ -578,6 +627,11 @@ playState_playerControlsActiveTetrimino:
578627gameMode_legalScreen: ; boot
579628 ; ABSS goes to gameTypeMenu instead of here
580629
630+ ; reset cursors (seems to cause problems on misterFPGA)
631+ lda #$0
632+ sta practiseType
633+ sta menuSeedCursorIndex
634+
581635 ; set start level to 18
582636 lda #$08
583637 sta startLevel
@@ -590,35 +644,10 @@ gameMode_legalScreen: ; boot
590644 dex
591645 bpl @loop
592646
593- ; reset cursors (seems to cause problems on misterFPGA)
594- lda #$0
595- sta practiseType
596- sta menuSeedCursorIndex
597-
598647 ; default pace to A
599648 lda #$A
600649 sta paceModifier
601650
602- ; region detection
603- ldx #0
604- ldy #0
605- @vwait1:
606- bit $2002
607- bpl @vwait1
608- @vwait2:
609- inx
610- bne @noincy
611- iny
612- @noincy:
613- bit $2002
614- bpl @vwait2
615-
616- cpx #$40 ;
617- bmi @ntsc
618- lda #1
619- sta palFlag
620- @ntsc:
621-
622651 ; fallthrough
623652gameMode_titleScreen:
624653 inc gameMode
@@ -651,6 +680,7 @@ gameMode_gameTypeMenu:
651680 jsr changeCHRBank0
652681 lda #$00
653682 jsr changeCHRBank1
683+ jsr checkRegion
654684 jsr waitForVBlankAndEnableNmi
655685 jsr updateAudioWaitForNmiAndResetOamStaging
656686 jsr updateAudioWaitForNmiAndEnablePpuRendering
@@ -2568,14 +2598,6 @@ pickTetriminoPre:
25682598 beq pickTetriminoPreset
25692599 jmp pickRandomTetrimino
25702600
2571- pickTetriminoPost:
2572- lda practiseType
2573- cmp #MODE_DROUGHT
2574- beq pickTetriminoDrought
2575- lda spawnID ; restore A
2576- rts
2577-
2578-
25792601pickTetriminoTSpin:
25802602 lda #$2
25812603 sta spawnID
@@ -2587,9 +2609,27 @@ pickTetriminoTap:
25872609 rts
25882610
25892611pickTetriminoSeed:
2590- ldx #set_seed
2591- ldy #$02
2592- jsr generateNextPseudorandomNumber
2612+ jsr setSeedNextRNG
2613+
2614+ ; SPSv2
2615+
2616+ lda set_seed_input+2
2617+ ror
2618+ ror
2619+ ror
2620+ ror
2621+ and #$F
2622+ cmp #0
2623+ beq @compatMode
2624+
2625+ adc #1
2626+ sta tmp3 ; step + 1 in tmp3
2627+ @loop:
2628+ jsr setSeedNextRNG
2629+ dec tmp3
2630+ lda tmp3
2631+ bne @loop
2632+ @compatMode:
25932633
25942634 inc set_seed+2 ; 'spawnCount'
25952635 lda set_seed
@@ -2624,6 +2664,12 @@ pickTetriminoSeed:
26242664 sta spawnID
26252665 rts
26262666
2667+ setSeedNextRNG:
2668+ ldx #set_seed
2669+ ldy #$02
2670+ jsr generateNextPseudorandomNumber
2671+ rts
2672+
26272673pickTetriminoPreset:
26282674presetBitmask := tmp2
26292675@start:
@@ -2656,6 +2702,13 @@ presetBitmask := tmp2
26562702 sta spawnID
26572703 rts
26582704
2705+ pickTetriminoPost:
2706+ lda practiseType
2707+ cmp #MODE_DROUGHT
2708+ beq pickTetriminoDrought
2709+ lda spawnID ; restore A
2710+ rts
2711+
26592712pickTetriminoDrought:
26602713 lda spawnID ; restore A
26612714 cmp #$12
0 commit comments