Skip to content

Commit 39e9c28

Browse files
committed
Merge branch 'master' of github.com:kirjavascript/TetrisGYM
2 parents 84c979a + 0e7add4 commit 39e9c28

31 files changed

+617
-272
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
* Fixed PAL colours
2727
* Keep hz display enabled when topped out
2828
* Famicom Keyboard support
29+
* Autodetect MMC1/CNROM
30+
* NROM Support
2931
* MMC3 Support
3032
* MMC5 Support
3133

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,4 @@ This project descends from the TAUS disassembly of NES Tetris and has been heavi
436436

437437
* [https://github.com/ejona86/taus](https://github.com/ejona86/taus)
438438
* [https://github.com/CelestialAmber/TetrisNESDisasm](https://github.com/CelestialAmber/TetrisNESDisasm)
439+
* [https://github.com/pinobatch/holy-mapperel](https://github.com/pinobatch/holy-mapperel)

build.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ console.log('TetrisGYM buildscript');
66
console.time('build');
77

88
const mappers = { // https://www.nesdev.org/wiki/Mapper
9+
0: 'NROM',
910
1: 'MMC1',
1011
3: 'CNROM',
1112
4: 'MMC3',
1213
5: 'MMC5',
14+
1000: 'Autodetect MMC1/CNROM',
1315
};
1416

1517
// options handling
@@ -25,6 +27,7 @@ if (args.includes('-h')) {
2527
-k Famicom Keyboard support
2628
-w force WASM compiler
2729
-c force PNG to CHR conversion
30+
-o override autodetect mmc1 header with cnrom
2831
-t run tests (requires cargo)
2932
-h you are here
3033
`);
@@ -47,7 +50,7 @@ console.log(`using ${nativeCC65 ? 'system' : 'wasm'} ca65/ld65`);
4750

4851
// mapper options
4952

50-
const mapper = args.find((d) => d.startsWith('-m'))?.slice(2) ?? 1;
53+
const mapper = args.find((d) => d.startsWith('-m'))?.slice(2) ?? 1000;
5154

5255
if (!mappers[mapper]) {
5356
console.error(
@@ -79,6 +82,11 @@ if (args.includes('-s')) {
7982
console.log('highscore saving disabled');
8083
}
8184

85+
if (args.includes('-o')) {
86+
compileFlags.push('-D', 'CNROM_OVERRIDE=1');
87+
console.log('cnrom override for autodetect');
88+
}
89+
8290
console.log();
8391

8492
// build / compress nametables

src/boot.asm

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
ldy #$06
2-
sty tmp2
3-
ldy #$00
4-
sty tmp1
5-
lda #$00
6-
@zeroOutPages:
7-
sta (tmp1),y
8-
dey
9-
bne @zeroOutPages
10-
dec tmp2
11-
bpl @zeroOutPages
1+
; $0000 through $06FF cleared during vblank wait
122
lda initMagic
133
cmp #$54
144
bne @coldBoot

src/chr.asm

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
.segment "CHR"
2-
3-
.if HAS_MMC
2+
; CHRBankSet0:
43
.incbin "chr/title_menu_tileset.chr"
54
.incbin "chr/game_tileset.chr"
5+
; CHRBankSet1:
6+
.if INES_MAPPER <> 0 ; exclude for NROM
67
.incbin "chr/rocket_tileset.chr"
7-
.elseif INES_MAPPER = 3
8-
.incbin "chr/rocket_tileset.chr"
9-
.repeat $1000
10-
.byte $0
11-
.endrepeat
12-
.incbin "chr/title_menu_tileset.chr"
13-
.incbin "chr/game_tileset.chr"
148
.endif

src/chr/title_menu_tileset.png

-19.3 KB
Loading

src/constants.asm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
.ifndef INES_MAPPER ; is set via ca65 flags
2-
INES_MAPPER := 1 ; supports 1, 3 and 4 (MMC1 / CNROM / MMC3)
2+
INES_MAPPER := 1000 ; 0 (NROM), 1 (MMC1), 3 (CNROM), 4 (MMC3), 5 (MMC5), and 1000 (autodetect 1/3)
33
.endif
44

5-
HAS_MMC = INES_MAPPER = 1 || INES_MAPPER = 4 || INES_MAPPER = 5
6-
75
.ifndef SAVE_HIGHSCORES
86
SAVE_HIGHSCORES := 1
97
.endif
@@ -17,6 +15,10 @@ AUTO_WIN := 0
1715
KEYBOARD := 0
1816
.endif
1917

18+
.ifndef CNROM_OVERRIDE
19+
CNROM_OVERRIDE := 0
20+
.endif
21+
2022
NO_MUSIC := 1
2123

2224
; dev flags

src/gamemode/gametypemenu/menu.asm

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,6 @@ gameMode_gameTypeMenu:
1010
sta menuScrollY
1111
lda #0
1212
sta hideNextPiece
13-
RESET_MMC1
14-
.if HAS_MMC
15-
; switch to blank charmap
16-
; (stops glitching when resetting)
17-
lda #$03
18-
jsr changeCHRBank1
19-
.endif
20-
.if INES_MAPPER = 4
21-
; Horizontal mirroring
22-
lda #$1
23-
sta MMC3_MIRRORING
24-
.elseif INES_MAPPER = 5
25-
; Horizontal mirroring
26-
lda #$50
27-
sta MMC5_NT_MAPPING
28-
.endif
29-
lda #%10011 ; used to be $10 (enable horizontal mirroring)
30-
jsr setMMC1Control
3113
lda #$1
3214
sta renderMode
3315
jsr updateAudioWaitForNmiAndDisablePpuRendering
@@ -40,15 +22,12 @@ gameMode_gameTypeMenu:
4022
sta tmp3
4123
jsr copyRleNametableToPpuOffset
4224
.addr game_type_menu_nametable_extra
43-
lda #$00
44-
jsr changeCHRBank0
45-
lda #$00
46-
jsr changeCHRBank1
47-
.if INES_MAPPER = 3
48-
CNROM_CHR_MENU:
49-
lda #1
50-
sta CNROM_CHR_MENU+1
25+
.if INES_MAPPER <> 0
26+
lda #CHRBankSet0
27+
jsr changeCHRBanks
5128
.endif
29+
lda #NMIEnable
30+
sta currentPpuCtrl
5231
jsr waitForVBlankAndEnableNmi
5332
jsr updateAudioWaitForNmiAndResetOamStaging
5433
jsr updateAudioWaitForNmiAndEnablePpuRendering
@@ -72,8 +51,6 @@ gameTypeLoopCheckStart:
7251
lda practiseType
7352
cmp #MODE_KILLX2
7453
bne @checkSpeedTest
75-
lda #$10
76-
jsr setMMC1Control
7754
lda #29
7855
sta startLevel
7956
sta levelNumber

src/gamemode/levelmenu.asm

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
gameMode_levelMenu:
2-
RESET_MMC1
3-
lda #$10
4-
jsr setMMC1Control
5-
.if INES_MAPPER = 3
6-
lda currentPpuCtrl
7-
and #%10000000
2+
lda #NMIEnable
83
sta currentPpuCtrl
9-
.endif
104
jsr updateAudio2
115
lda #$7
126
sta renderMode
137
jsr updateAudioWaitForNmiAndDisablePpuRendering
148
jsr disableNmi
15-
lda #$00
16-
jsr changeCHRBank0
17-
lda #$00
18-
jsr changeCHRBank1
9+
.if INES_MAPPER <> 0
10+
lda #CHRBankSet0
11+
jsr changeCHRBanks
12+
.endif
1913
jsr bulkCopyToPpu
2014
.addr menu_palette
2115
jsr copyRleNametableToPpu

src/gamemode/speedtest.asm

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ gameMode_speedTest:
2222
sta PPUADDR
2323
lda #$30
2424
sta PPUDATA
25-
.if HAS_MMC
26-
lda #$01
27-
jsr changeCHRBank0
28-
lda #$01
29-
jsr changeCHRBank1
30-
.elseif INES_MAPPER = 3
31-
lda #%10011001
32-
sta PPUCTRL
25+
lda #NMIEnable|BGPattern1|SpritePattern1
3326
sta currentPpuCtrl
27+
.if INES_MAPPER <> 0
28+
lda #CHRBankSet0
29+
jsr changeCHRBanks
3430
.endif
3531

3632
jsr waitForVBlankAndEnableNmi

0 commit comments

Comments
 (0)