From cd437ac14027b38fc5f987a72d6849c4f8ecbfd0 Mon Sep 17 00:00:00 2001 From: TakuikaNinja Date: Wed, 22 May 2024 20:56:56 +1200 Subject: [PATCH 01/10] Update header to NES2.0 --- src/header.asm | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/header.asm b/src/header.asm index dea15da7..d6b8ce32 100644 --- a/src/header.asm +++ b/src/header.asm @@ -1,8 +1,8 @@ ; -; iNES header +; NES2.0 header ; -; This iNES header is from Brad Smith (rainwarrior) +; iNES header adapted from Brad Smith (rainwarrior) ; https://github.com/bbbradsmith/NES-ca65-example .segment "HEADER" @@ -11,6 +11,9 @@ INES_MIRROR = 0 ; 0 = horizontal mirroring, 1 = vertical mirroring (ignored in MMC1) INES_SRAM = 1 ; 1 = battery backed SRAM at $6000-7FFF +NES2_SRAM_SHIFT = INES_SRAM * 7 ; if SRAM present, set shift to 7 for (64 << 7) = 8KiB size +NES2_REGION = 2 ; 0 = NTSC, 1 = PAL, 2 = multi-region, 3 = UA6538 ("Dendy") +NES2_INPUT = 1 ; 1 = standard NES/FC controllers ; Override INES_MAPPER for mode 1000 (auto detect) .if INES_MAPPER = 1000 @@ -20,12 +23,23 @@ INES_SRAM = 1 ; 1 = battery backed SRAM at $6000-7FFF _INES_MAPPER = 1 ; MMC1 for Emulator/Flashcart .endif .else -_INES_MAPPER = INES_MAPPER ; use actual INES_MAPPER otherwise + _INES_MAPPER = INES_MAPPER ; use actual INES_MAPPER otherwise +.endif + +; Pick the appropriate NES2_SUBMAPPER +.if _INES_MAPPER = 1 + NES2_SUBMAPPER = 5 ; MMC1 fixed PRG +.elseif _INES_MAPPER = 3 + NES2_SUBMAPPER = 2 ; CNROM bus conflicts +.else + NES2_SUBMAPPER = 0 ; otherwise don't specify submapper .endif .byte 'N', 'E', 'S', $1A ; ID .byte $02 ; 16k PRG chunk count .byte $02 ; 8k CHR chunk count .byte INES_MIRROR | (INES_SRAM << 1) | ((_INES_MAPPER & $f) << 4) -.byte (_INES_MAPPER & %11110000) -.byte $0, $0, $0, $0, $0, $0, $0, $0 ; padding +.byte (_INES_MAPPER & %11110000) | %00001000 ; NES2.0 header identifier +.byte ((NES2_SUBMAPPER & $f) << 4) ; submapper +.byte $0, (NES2_SRAM_SHIFT << 4) ; PRG MSB, SRAM shift count +.byte $0, NES2_REGION, $0, $0, NES2_INPUT ; misc. fields, region, input device From 1d6e2fc9e4e39214bb2dd164c8917b7308c5b17b Mon Sep 17 00:00:00 2001 From: TakuikaNinja Date: Wed, 22 May 2024 21:31:09 +1200 Subject: [PATCH 02/10] Document header change in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 97bb3687..be1ed495 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ ROM CRC32: 1394F57E A link to the BPS can be found on the [releases page](https://github.com/kirjavascript/TetrisGYM/releases). -The BPS produces a file with an MMC1 header, but it also works when treated as CNROM. +The BPS produces a file with an NES2.0 header specifying MMC1 with fixed PRG (mapper 1:5), but it also works when specified as CNROM with bus conflicts (mapper 3:2). ## Trainers From 10484d4ed0218e3417961d895def93a4f6f36235 Mon Sep 17 00:00:00 2001 From: TakuikaNinja Date: Sat, 25 May 2024 14:36:36 +1200 Subject: [PATCH 03/10] Add -i flag for iNES header --- README.md | 2 +- build.js | 6 ++++++ src/constants.asm | 4 ++++ src/header.asm | 16 ++++++++++++---- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index be1ed495..d27c0462 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ ROM CRC32: 1394F57E A link to the BPS can be found on the [releases page](https://github.com/kirjavascript/TetrisGYM/releases). -The BPS produces a file with an NES2.0 header specifying MMC1 with fixed PRG (mapper 1:5), but it also works when specified as CNROM with bus conflicts (mapper 3:2). +The BPS produces a file with its header specifying MMC1 with fixed PRG (mapper 1:5), but it also works when specified as CNROM with bus conflicts (mapper 3:2). ## Trainers diff --git a/build.js b/build.js index 2b6eb256..ebec902f 100644 --- a/build.js +++ b/build.js @@ -27,6 +27,7 @@ if (args.includes('-h')) { -k Famicom Keyboard support -w force WASM compiler -c force PNG to CHR conversion +-i use iNES header instead of NES2.0 -o override autodetect mmc1 header with cnrom -t run tests (requires cargo) -h you are here @@ -82,6 +83,11 @@ if (args.includes('-s')) { console.log('highscore saving disabled'); } +if (args.includes('-i')) { + compileFlags.push('-D', 'INES_OVERRIDE=1'); + console.log('iNES header override'); +} + if (args.includes('-o')) { compileFlags.push('-D', 'CNROM_OVERRIDE=1'); console.log('cnrom override for autodetect'); diff --git a/src/constants.asm b/src/constants.asm index 3fb96acf..3e784ea9 100644 --- a/src/constants.asm +++ b/src/constants.asm @@ -15,6 +15,10 @@ AUTO_WIN := 0 KEYBOARD := 0 .endif +.ifndef INES_OVERRIDE +INES_OVERRIDE := 0 +.endif + .ifndef CNROM_OVERRIDE CNROM_OVERRIDE := 0 .endif diff --git a/src/header.asm b/src/header.asm index d6b8ce32..f3c1b34e 100644 --- a/src/header.asm +++ b/src/header.asm @@ -35,11 +35,19 @@ NES2_INPUT = 1 ; 1 = standard NES/FC controllers NES2_SUBMAPPER = 0 ; otherwise don't specify submapper .endif +; Construct header .byte 'N', 'E', 'S', $1A ; ID .byte $02 ; 16k PRG chunk count .byte $02 ; 8k CHR chunk count .byte INES_MIRROR | (INES_SRAM << 1) | ((_INES_MAPPER & $f) << 4) -.byte (_INES_MAPPER & %11110000) | %00001000 ; NES2.0 header identifier -.byte ((NES2_SUBMAPPER & $f) << 4) ; submapper -.byte $0, (NES2_SRAM_SHIFT << 4) ; PRG MSB, SRAM shift count -.byte $0, NES2_REGION, $0, $0, NES2_INPUT ; misc. fields, region, input device + +.if INES_OVERRIDE = 0 + .byte (_INES_MAPPER & %11110000) | %00001000 ; NES2.0 header identifier + .byte ((NES2_SUBMAPPER & $f) << 4) ; submapper + .byte $0, (NES2_SRAM_SHIFT << 4) ; PRG MSB, SRAM shift count + .byte $0, NES2_REGION, $0, $0, NES2_INPUT ; misc. fields, region, input device +.else + .byte (_INES_MAPPER & %11110000) + .byte $0, $0, $0, $0, $0, $0, $0, $0 ; padding +.endif + From 350a0638e51408424c76dcb9017b74800b8e93ec Mon Sep 17 00:00:00 2001 From: TakuikaNinja Date: Sat, 25 May 2024 14:49:00 +1200 Subject: [PATCH 04/10] Include mapper MSB in NES2.0 header --- src/header.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/header.asm b/src/header.asm index f3c1b34e..4a7b370a 100644 --- a/src/header.asm +++ b/src/header.asm @@ -43,7 +43,7 @@ NES2_INPUT = 1 ; 1 = standard NES/FC controllers .if INES_OVERRIDE = 0 .byte (_INES_MAPPER & %11110000) | %00001000 ; NES2.0 header identifier - .byte ((NES2_SUBMAPPER & $f) << 4) ; submapper + .byte ((NES2_SUBMAPPER & $f) << 4) | ((_INES_MAPPER & $f00) >> 8) ; submapper/mapper MSB .byte $0, (NES2_SRAM_SHIFT << 4) ; PRG MSB, SRAM shift count .byte $0, NES2_REGION, $0, $0, NES2_INPUT ; misc. fields, region, input device .else From 2ce34c4ae3b1f514e7298bc5fe0002851a92ef92 Mon Sep 17 00:00:00 2001 From: TakuikaNinja Date: Sat, 25 May 2024 15:08:52 +1200 Subject: [PATCH 05/10] Pick expansion device based on KEYBOARD flag --- src/header.asm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/header.asm b/src/header.asm index 4a7b370a..714333c4 100644 --- a/src/header.asm +++ b/src/header.asm @@ -1,5 +1,6 @@ ; ; NES2.0 header +; https://www.nesdev.org/wiki/NES_2.0 ; ; iNES header adapted from Brad Smith (rainwarrior) @@ -13,7 +14,13 @@ INES_MIRROR = 0 ; 0 = horizontal mirroring, 1 = vertical mirroring (ignored in M INES_SRAM = 1 ; 1 = battery backed SRAM at $6000-7FFF NES2_SRAM_SHIFT = INES_SRAM * 7 ; if SRAM present, set shift to 7 for (64 << 7) = 8KiB size NES2_REGION = 2 ; 0 = NTSC, 1 = PAL, 2 = multi-region, 3 = UA6538 ("Dendy") -NES2_INPUT = 1 ; 1 = standard NES/FC controllers + +; Pick default expansion device +.if KEYBOARD = 1 + NES2_INPUT = $23 ; Family BASIC Keyboard +.else + NES2_INPUT = 1 ; standard NES/FC controllers +.endif ; Override INES_MAPPER for mode 1000 (auto detect) .if INES_MAPPER = 1000 From 9feb8912851436d66c2dba3e39773afe512abb92 Mon Sep 17 00:00:00 2001 From: TakuikaNinja Date: Sat, 25 May 2024 15:14:41 +1200 Subject: [PATCH 06/10] Document PowerPak workaround --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d27c0462..094c7212 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ A link to the BPS can be found on the [releases page](https://github.com/kirjava The BPS produces a file with its header specifying MMC1 with fixed PRG (mapper 1:5), but it also works when specified as CNROM with bus conflicts (mapper 3:2). +If you are using a PowerPak, you will need to install an [alternate N.MAP loader](https://forums.nesdev.org/viewtopic.php?p=283943#p283943) so its header check passes. + ## Trainers Some trainers have additional configuration values; use left and right in the main menu to change them. From 201056f757606a39bd97b44c47bb62ed3d18c4cc Mon Sep 17 00:00:00 2001 From: TakuikaNinja Date: Sat, 25 May 2024 15:39:16 +1200 Subject: [PATCH 07/10] Reflect SRAM flag in header --- src/header.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/header.asm b/src/header.asm index 714333c4..7d896919 100644 --- a/src/header.asm +++ b/src/header.asm @@ -11,7 +11,7 @@ .include "constants.asm" ; for INES_HEADER INES_MIRROR = 0 ; 0 = horizontal mirroring, 1 = vertical mirroring (ignored in MMC1) -INES_SRAM = 1 ; 1 = battery backed SRAM at $6000-7FFF +INES_SRAM = SAVE_HIGHSCORES ; 1 = battery backed SRAM at $6000-7FFF NES2_SRAM_SHIFT = INES_SRAM * 7 ; if SRAM present, set shift to 7 for (64 << 7) = 8KiB size NES2_REGION = 2 ; 0 = NTSC, 1 = PAL, 2 = multi-region, 3 = UA6538 ("Dendy") From 81ec479b00496ee8a29b47c3befa1a45d49502d6 Mon Sep 17 00:00:00 2001 From: TakuikaNinja Date: Sun, 26 May 2024 09:38:42 +1200 Subject: [PATCH 08/10] Revert header/mapper description in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 094c7212..7b475c2f 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ ROM CRC32: 1394F57E A link to the BPS can be found on the [releases page](https://github.com/kirjavascript/TetrisGYM/releases). -The BPS produces a file with its header specifying MMC1 with fixed PRG (mapper 1:5), but it also works when specified as CNROM with bus conflicts (mapper 3:2). +The BPS produces a file with an MMC1 header, but it also works when treated as CNROM. If you are using a PowerPak, you will need to install an [alternate N.MAP loader](https://forums.nesdev.org/viewtopic.php?p=283943#p283943) so its header check passes. From 17561c4a24ec305cb7c07c47b238bceb415d4fde Mon Sep 17 00:00:00 2001 From: TakuikaNinja Date: Tue, 28 May 2024 22:10:59 +1200 Subject: [PATCH 09/10] Don't specify input device --- README.md | 2 -- src/header.asm | 8 +------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/README.md b/README.md index 7b475c2f..97bb3687 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,6 @@ A link to the BPS can be found on the [releases page](https://github.com/kirjava The BPS produces a file with an MMC1 header, but it also works when treated as CNROM. -If you are using a PowerPak, you will need to install an [alternate N.MAP loader](https://forums.nesdev.org/viewtopic.php?p=283943#p283943) so its header check passes. - ## Trainers Some trainers have additional configuration values; use left and right in the main menu to change them. diff --git a/src/header.asm b/src/header.asm index 7d896919..e09a2698 100644 --- a/src/header.asm +++ b/src/header.asm @@ -14,13 +14,7 @@ INES_MIRROR = 0 ; 0 = horizontal mirroring, 1 = vertical mirroring (ignored in M INES_SRAM = SAVE_HIGHSCORES ; 1 = battery backed SRAM at $6000-7FFF NES2_SRAM_SHIFT = INES_SRAM * 7 ; if SRAM present, set shift to 7 for (64 << 7) = 8KiB size NES2_REGION = 2 ; 0 = NTSC, 1 = PAL, 2 = multi-region, 3 = UA6538 ("Dendy") - -; Pick default expansion device -.if KEYBOARD = 1 - NES2_INPUT = $23 ; Family BASIC Keyboard -.else - NES2_INPUT = 1 ; standard NES/FC controllers -.endif +NES2_INPUT = 0 ; 0 = unspecified, 1 = standard NES/FC controllers, $23 = Family BASIC Keyboard ; Override INES_MAPPER for mode 1000 (auto detect) .if INES_MAPPER = 1000 From ae3a49d477ee2ac2e83aef26ff54515f1ab01b8f Mon Sep 17 00:00:00 2001 From: TakuikaNinja Date: Tue, 28 May 2024 22:19:31 +1200 Subject: [PATCH 10/10] Add separate HAS_SRAM flag --- build.js | 1 + src/constants.asm | 4 ++++ src/header.asm | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build.js b/build.js index ebec902f..c049dd6d 100644 --- a/build.js +++ b/build.js @@ -80,6 +80,7 @@ if (args.includes('-k')) { if (args.includes('-s')) { compileFlags.push('-D', 'SAVE_HIGHSCORES=0'); + compileFlags.push('-D', 'HAS_SRAM=0'); console.log('highscore saving disabled'); } diff --git a/src/constants.asm b/src/constants.asm index 3e784ea9..e4ced4d7 100644 --- a/src/constants.asm +++ b/src/constants.asm @@ -6,6 +6,10 @@ INES_MAPPER := 1000 ; 0 (NROM), 1 (MMC1), 3 (CNROM), 4 (MMC3), 5 (MMC5), and 100 SAVE_HIGHSCORES := 1 .endif +.ifndef HAS_SRAM +HAS_SRAM := 1 +.endif + .ifndef AUTO_WIN ; faster aeppoz + press select to end game AUTO_WIN := 0 diff --git a/src/header.asm b/src/header.asm index e09a2698..62e8bbb9 100644 --- a/src/header.asm +++ b/src/header.asm @@ -11,8 +11,8 @@ .include "constants.asm" ; for INES_HEADER INES_MIRROR = 0 ; 0 = horizontal mirroring, 1 = vertical mirroring (ignored in MMC1) -INES_SRAM = SAVE_HIGHSCORES ; 1 = battery backed SRAM at $6000-7FFF -NES2_SRAM_SHIFT = INES_SRAM * 7 ; if SRAM present, set shift to 7 for (64 << 7) = 8KiB size +INES_SRAM = HAS_SRAM ; 1 = battery backed SRAM at $6000-7FFF +NES2_SRAM_SHIFT = HAS_SRAM * 7 ; if SRAM present, set shift to 7 for (64 << 7) = 8KiB size NES2_REGION = 2 ; 0 = NTSC, 1 = PAL, 2 = multi-region, 3 = UA6538 ("Dendy") NES2_INPUT = 0 ; 0 = unspecified, 1 = standard NES/FC controllers, $23 = Family BASIC Keyboard