Skip to content

Commit 9382e3e

Browse files
committed
Merge remote-tracking branch 'origin/master' into keyboard_score_entry
2 parents f1c76b8 + df937b1 commit 9382e3e

26 files changed

+682
-149
lines changed

CHANGELOG.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [unreleased]
4+
5+
* Fixed a glitch when using Crash Mode + Crunch Mode
6+
* Fixed a glitch in Hard Drop Mode
7+
* Fixed line based floor caps outside of levelups
8+
* Reset scores when no SRAM is present
9+
310
## v6
411
* Crunch Trainer
512
* Marathon Trainer
@@ -58,9 +65,9 @@
5865
* Start on any level
5966
* Rewrite of all scoring code
6067
* Classic scoring
61-
* Millions counter
68+
* Millions counter
6269
* 7 digit score
63-
* 999999 scorecap
70+
* 999999 scorecap
6471
* Fixed T-Spin scoring
6572
* Crash free with no long frames
6673
* Rewrite of all highscore code
@@ -83,7 +90,7 @@
8390
* Added option to disable tetris flashing
8491
* Changes made to more closely match the original ROM
8592
* Restore seed shredding on level menu
86-
* Hold `select` to start in Qual Mode and reset level cursor
93+
* Hold `select` to start in Qual Mode and reset level cursor
8794
* Transition from Legal to Title screen after 512 frames
8895
* Hide next box between Curtain and Rocket
8996
* Persist Qual Mode (and menu config) between reset button presses
@@ -153,7 +160,7 @@
153160
- Garbage Trainer
154161
- Always Tetris Ready
155162
- Normal Garbage
156-
- Smart Garbage
163+
- Smart Garbage
157164
- Hard Garbage
158165
- Infinite Digging
159166
- Piece distribution in Setups Trainer is now even

build.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const mappers = { // https://www.nesdev.org/wiki/Mapper
1919
const args = process.argv.slice(2);
2020

2121
if (args.includes('-h')) {
22-
console.log(`usage: node build.js [-h] [-v] [-m<${Object.keys(mappers).join('|')}>] [-a] [-s] [-k] [-w]
22+
console.log(`usage: node build.js [-h] [-v] [-m<${Object.keys(mappers).join('|')}>] [-a] [-s] [-k] [-w] [-- (ca65 args)]
2323
2424
-m mapper
2525
-a faster aeppoz + press select to end game
@@ -29,6 +29,7 @@ if (args.includes('-h')) {
2929
-c force PNG to CHR conversion
3030
-o override autodetect mmc1 header with cnrom
3131
-t run tests (requires cargo)
32+
-T run single test
3233
-h you are here
3334
`);
3435
process.exit(0);
@@ -87,6 +88,13 @@ if (args.includes('-o')) {
8788
console.log('cnrom override for autodetect');
8889
}
8990

91+
// pass additional arguments to ca65
92+
if (args.includes('--')) {
93+
const ca65Flags = args.slice(1+args.indexOf('--'));
94+
compileFlags.push(...ca65Flags);
95+
args.splice(args.indexOf('--'), 1+ca65Flags.length);
96+
}
97+
9098
console.log();
9199

92100
// build / compress nametables
@@ -126,15 +134,22 @@ console.timeEnd('CHR');
126134

127135
const { spawnSync } = require('child_process');
128136

137+
function execArgs(exe, args) {
138+
const result = spawnSync(exe, args);
139+
if (result.stderr.length) {
140+
console.error(result.stderr.toString());
141+
}
142+
if (result.stdout.length) {
143+
console.log(result.stdout.toString());
144+
}
145+
if (result.status) {
146+
process.exit(result.status);
147+
}
148+
}
149+
129150
function exec(cmd) {
130151
const [exe, ...args] = cmd.split(' ');
131-
const output = spawnSync(exe, args).output.flatMap(
132-
(d) => d?.toString() || [],
133-
);
134-
if (output.length) {
135-
console.log(output.join('\n'));
136-
process.exit(0);
137-
}
152+
execArgs(exe, args)
138153
}
139154

140155
const ca65bin = nativeCC65 ? 'ca65' : 'node ./tools/assemble/ca65.js';
@@ -199,7 +214,15 @@ console.log();
199214

200215
console.timeEnd('build');
201216

217+
// tests
218+
202219
if (args.includes('-t')) {
203220
console.log('\nrunning tests');
204221
exec('cargo run --release --manifest-path tests/Cargo.toml -- -t');
205222
}
223+
224+
if (args.includes('-T')) {
225+
const singleTest = args.slice(1+args.indexOf('-T')).join(' ');
226+
console.log(`\nrunning single test: ${singleTest}`);
227+
execArgs('cargo', [...'run --release --manifest-path tests/Cargo.toml -- -T'.split(' '), singleTest]);
228+
}

src/audio.asm

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ copyToApuChannel:
7373
ldy #$00
7474
@copyByte:
7575
lda (AUDIOTMP3),y
76+
.if SWAP_DUTY_CYCLES
77+
cpy #0
78+
bne @notFirstByte
79+
jsr swapDutyCycles
80+
@notFirstByte:
81+
.endif
7682
sta (AUDIOTMP1),y
7783
iny
7884
tya
@@ -137,15 +143,9 @@ advanceAudioSlotFrame:
137143
sta soundEffectSlot0FrameCounter,x
138144
@ret: rts
139145

140-
unreferenced_data3:
141-
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
142-
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
143-
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
144-
.byte $00,$00,$00,$00,$00,$00,$00,$00
145-
.byte $00,$00,$00,$00,$00,$00,$00,$00
146-
.byte $00,$00,$00,$00,$00,$00,$00,$00
147-
.byte $00,$00,$00,$00,$00,$00,$00,$00
148-
.byte $03,$7F,$0F,$C0
146+
.align $100
147+
.byte $00 ; pad so low byte is not zero. See tya in initSoundEffectShared
148+
149149
; Referenced by initSoundEffectShared
150150
soundEffectSlot0_gameOverCurtainInitData:
151151
.byte $1F,$7F,$0F,$C0
@@ -473,6 +473,9 @@ soundEffectSlot1_chirpChirpPlaying:
473473
and #$03
474474
tay
475475
lda soundEffectSlot1_chirpChirpSq1Vol_table,y
476+
.if SWAP_DUTY_CYCLES
477+
jsr swapDutyCycles
478+
.endif
476479
sta SQ1_VOL
477480
inc soundEffectSlot1SecondaryCounter
478481
lda soundEffectSlot1SecondaryCounter
@@ -623,6 +626,10 @@ LE442: jsr copyToSq1Channel
623626
sta SQ1_LO
624627
ldy soundEffectSlot1SecondaryCounter
625628
lda sq1vol_unknown2_table,y
629+
.if SWAP_DUTY_CYCLES
630+
jsr swapDutyCycles
631+
tay ; set z flag based on a; y can be safely clobbered
632+
.endif
626633
sta SQ1_VOL
627634
bne LE46F
628635
lda soundEffectSlot1Playing
@@ -1070,6 +1077,9 @@ updateMusicFrame_setChanVol:
10701077
bne @ret
10711078
tya
10721079
ldy musicChannelOffset
1080+
.if SWAP_DUTY_CYCLES
1081+
jsr swapDutyCycles
1082+
.endif
10731083
sta SQ1_VOL,y
10741084
@ret: rts
10751085

@@ -1350,6 +1360,9 @@ updateMusicFrame_updateChannel:
13501360
@useDirectVolume:
13511361
lda AUDIOTMP1
13521362
@setMmio:
1363+
.if SWAP_DUTY_CYCLES
1364+
jsr swapDutyCycles
1365+
.endif
13531366
sta SQ1_VOL,y
13541367
lda musicStagingSq1Sweep,x
13551368
sta SQ1_SWEEP,y
@@ -1462,6 +1475,15 @@ musicGetNextInstructionByte:
14621475
lda (musicChanTmpAddr),y
14631476
rts
14641477

1478+
.if SWAP_DUTY_CYCLES
1479+
; input a: byte to be written to $4000 or $4004. output a: the same byte with the duty cycle index mapped from (0, 1, 2, 3) to (0, 2, 1, 3), counteracting the behavior of some clone consoles
1480+
swapDutyCycles:
1481+
cmp #%01000000
1482+
bmi @ret ; branch if upper bits are not %01 or %10
1483+
eor #%11000000 ; swap between %01 and %10
1484+
@ret: rts
1485+
.endif
1486+
14651487
musicChanVolControlTable:
14661488
noteToWaveTable:
14671489
noteDurationTable:

src/constants.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ NO_SFX := 0
2727
NO_MENU := 0
2828
ALWAYS_CURTAIN := 0
2929
QUAL_BOOT := 0
30+
SWAP_DUTY_CYCLES := 0 ; counters the duty cycle swap present in some clone consoles
3031

3132
INITIAL_CUSTOM_LEVEL := 29
3233
INITIAL_LINECAP_LEVEL := 39

src/data/orientation.asm

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,10 @@ orientationTable:
3030
.byte $00,$00,$7B,$01,$00,$FF,$00,$00
3131
.byte $FF,$00,$00,$FF,$00,$00,$FF,$00
3232

33-
; Only cares about orientations selected by spawnTable
34-
orientationToSpriteTable:
35-
.byte $00,$00,$06,$00,$00,$00,$00,$09
36-
.byte $08,$00,$0B,$07,$00,$00,$0A,$00
37-
.byte $00,$00,$0C
38-
3933
tetriminoTypeFromOrientation:
4034
.byte $00,$00,$00,$00,$01,$01,$01,$01
4135
.byte $02,$02,$03,$04,$04,$05,$05,$05
4236
.byte $05,$06,$06
4337
spawnTable:
4438
.byte $02,$07,$08,$0A,$0B,$0E,$12
4539
.byte $02
46-
spawnOrientationFromOrientation:
47-
.byte $02,$02,$02,$02,$07,$07,$07,$07
48-
.byte $08,$08,$0A,$0B,$0B,$0E,$0E,$0E
49-
.byte $0E,$12,$12

src/gamemode/levelmenu.asm

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ gameMode_levelMenu_processPlayer1Navigation:
7777
lda newlyPressedButtons_player1
7878
sta newlyPressedButtons
7979

80-
.if SAVE_HIGHSCORES
8180
lda levelControlMode
8281
cmp #4
8382
bne @notClearingHighscores
@@ -89,11 +88,15 @@ gameMode_levelMenu_processPlayer1Navigation:
8988
lda #0
9089
sta levelControlMode
9190
jsr resetScores
91+
.if SAVE_HIGHSCORES
92+
jsr detectSRAM
93+
beq @notResettingSavedScores
9294
jsr resetSavedScores
95+
@notResettingSavedScores:
96+
.endif
9397
jsr updateAudioWaitForNmiAndResetOamStaging
9498
jmp gameMode_levelMenu
9599
@notClearingHighscores:
96-
.endif
97100

98101
jsr levelControl
99102
jsr levelMenuRenderHearts
@@ -191,7 +194,6 @@ levelControl:
191194
.addr levelControlClearHighScores
192195
.addr levelControlClearHighScoresConfirm
193196

194-
.if SAVE_HIGHSCORES
195197
levelControlClearHighScores:
196198
lda #$20
197199
sta spriteXOffset
@@ -238,13 +240,7 @@ highScoreClearUpOrLeave:
238240
sta levelControlMode
239241
@ret:
240242
rts
241-
.else
242-
levelControlClearHighScores:
243-
levelControlClearHighScoresConfirm:
244-
lda #0
245-
sta levelControlMode
246-
rts
247-
.endif
243+
248244

249245
levelControlCustomLevel:
250246
jsr handleReadyInput
@@ -324,10 +320,7 @@ MAX_HEARTS := 7
324320
jsr @changeHearts
325321
@checkUpPressed:
326322

327-
.if SAVE_HIGHSCORES
328323
; to clear mode
329-
jsr detectSRAM
330-
beq @notClearMode
331324
lda newlyPressedButtons
332325
cmp #BUTTON_DOWN
333326
bne @notClearMode
@@ -336,7 +329,6 @@ MAX_HEARTS := 7
336329
lda #$3
337330
sta levelControlMode
338331
@notClearMode:
339-
.endif
340332

341333
; to normal mode
342334
lda newlyPressedButtons

src/gamemodestate/initstate.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ gameModeState_initGameState:
4646
sta dasOnlyShiftDisabled
4747
sta invisibleFlag
4848
sta currentFloor
49+
sta crashState
4950

5051
; initialize currentFloor if necessary
5152
lda practiseType

src/gamemodestate/pause.asm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ pause:
3535
sta renderMode
3636

3737
@pauseSetupPart2:
38-
jsr updateAudioAndWaitForNmi
39-
jsr resetOAMStaging
38+
jsr updateAudioWaitForNmiAndResetOamStaging
4039

4140
@pauseLoop:
4241
lda qualFlag

src/main.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
; region code at start of page to keep cycle count consistent
2020
.include "util/check_region.asm"
21+
.include "audio.asm"
2122

2223
initRam:
2324

@@ -31,7 +32,6 @@ mainLoop:
3132
@continue:
3233
jmp mainLoop
3334

34-
.include "audio.asm"
3535
.include "nmi/nmi.asm"
3636
.include "nmi/render.asm"
3737
.include "nmi/pollcontroller.asm"

0 commit comments

Comments
 (0)