Skip to content

Commit

Permalink
twoplayer: Rework playfield appearance using custom tiles
Browse files Browse the repository at this point in the history
Both versions have been updated to use custom tiles. This allowed
significantly improving the appearance of next-on-top. next-on-side
saw smaller appearance improvements by adopting some similar tiles to
next-on-top.
  • Loading branch information
ejona86 committed Nov 11, 2019
1 parent 27c2fa0 commit 5f48335
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 29 deletions.
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ build/playerid.o: build/tetris.inc
build/handicap.o: build/tetris.inc
build/screens.o: build/tetris.inc
build/chart.o: build/tetris.inc build/taus.chrs/fake
build/tetris.o: build/tetris-CHR-00.chr build/tetris-CHR-01.chr
build/twoplayer.o: rle.o build/tetris.inc build/twoplayer_game.nam.rle build/twoplayer_game_top.nam.rle
build/tetris-CHR.o: build/tetris-CHR-00.chr build/tetris-CHR-01.chr
build/twoplayer.o: build/tetris.inc build/twoplayer_game.nam.rle build/twoplayer_game_top.nam.rle build/tetris-CHR-00.chr build/twoplayer-CHR-01.chr
build/twoplayer-CHR-01.chr.ips.o: build/twoplayer.chrs/fake
# .diff base files. There should be a .diff for each target
build/twoplayer-tetris-PRG.s: build/tetris-PRG.s
# List linker dependencies. There should be a .cfg for each target
build/tetris.nes: build/tetris.o build/tetris-PRG.o build/tetris-ram.o
build/tetris.nes: build/tetris.o build/tetris-CHR.o build/tetris-PRG.o build/tetris-ram.o
build/taus.ips: build/taus.o build/ips.o build/fastlegal.o build/playerid.o build/chart.o
build/screens.ips: build/screens.o build/ips.o
build/highscores.ips: build/highscores.o build/ips.o
build/handicap.ips: build/handicap.o build/ips.o
build/twoplayer.nes: build/tetris.o build/twoplayer-tetris-PRG.o build/tetris-ram.o build/twoplayer.o build/rle.o
build/twoplayer-CHR-01.chr.ips: build/ips.o build/twoplayer-CHR-01.chr.ips.o
# IPS base dependencies. There should be a .ips for each target
build/taus.nes: build/tetris.nes
build/screens.nes: build/tetris.nes
build/highscores.nes: build/tetris.nes
build/handicap.nes: build/tetris.nes
build/twoplayer-CHR-01.chr: build/tetris-CHR-01.chr
# Combine mods
build/custom.nes: build/taus.ips build/highscores.ips

Expand All @@ -48,6 +51,12 @@ build/%.nes: build/%.ips
flips --apply $< $(word 2,$^) $@ > /dev/null || flips --apply $< $(word 2,$^) $@
flips --create $(word 2,$^) $@ build/$*.dist.ips > /dev/null

build/%: %.ips
# Second prerequisite is assumed to be source
# If the first time fails, run it a second time to display output
flips --apply $< $(word 2,$^) $@ > /dev/null || flips --apply $< $(word 2,$^) $@
flips --create $(word 2,$^) $@ build/$*.dist.ips > /dev/null

build/%.chrs/fake: %.chr | build
[ -d build/$*.chrs ] || mkdir build/$*.chrs
touch $@
Expand Down
2 changes: 2 additions & 0 deletions ips.inc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ IPSPRGOFFSET = 16-$8000
.dbyt .ident(.concat("__", name, "_SIZE__"))
.endmacro

.ifndef IPSCHROFFSET
IPSCHROFFSET = 16+$8000
.endif
CHR00 = $0000
CHR01 = $2000
CHR_LEFT = $0000
Expand Down
7 changes: 7 additions & 0 deletions tetris-CHR.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;
; CHR ROM
;

.segment "CHR"
.incbin "build/tetris-CHR-00.chr"
.incbin "build/tetris-CHR-01.chr"
8 changes: 0 additions & 8 deletions tetris.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,3 @@ INES_SRAM = 0 ; 1 = battery backed SRAM at $6000-7FFF
.byte INES_MIRROR | (INES_SRAM << 1) | ((INES_MAPPER & $f) << 4)
.byte (INES_MAPPER & %11110000)
.byte $0, $0, $0, $0, $0, $0, $0, $0 ; padding

;
; CHR ROM
;

.segment "CHR"
.incbin "build/tetris-CHR-00.chr"
.incbin "build/tetris-CHR-01.chr"
11 changes: 11 additions & 0 deletions twoplayer-CHR-01.chr.ips.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MEMORY {
IPSHDR: start = $0000, size = $0005;
IPSCHR: start = $0000, size = $8000;
IPSEOF: start = $0000, size = $0003;
}

SEGMENTS {
IPSHEADER:load = IPSHDR;
IPSEOF: load = IPSEOF;
IPSCHR: load = IPSCHR;
}
46 changes: 46 additions & 0 deletions twoplayer-CHR-01.chr.ips.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
IPSCHROFFSET = 0
.include "ips.inc"

.segment "IPSCHR"

.ifdef NEXT_ON_TOP
ips_tilehdr CHR_RIGHT,$68
.incbin "build/twoplayer.chrs/18"
.endif

ips_tilehdr CHR_RIGHT,$76
.incbin "build/twoplayer.chrs/04"

ips_tilehdr CHR_RIGHT,$86
.incbin "build/twoplayer.chrs/05"

ips_tilehdr CHR_RIGHT,$8C
.incbin "build/twoplayer.chrs/00"

.ifndef NEXT_ON_TOP
ips_tilehdr CHR_RIGHT,$8D
.incbin "build/twoplayer.chrs/01"

ips_tilehdr CHR_RIGHT,$9C
.incbin "build/twoplayer.chrs/02"
.else
ips_tilehdr CHR_RIGHT,$8D
.incbin "build/twoplayer.chrs/11"

ips_tilehdr CHR_RIGHT,$9B
.incbin "build/twoplayer.chrs/19"

ips_tilehdr CHR_RIGHT,$9C
.incbin "build/twoplayer.chrs/12"
.endif

ips_tilehdr CHR_RIGHT,$9D
.incbin "build/twoplayer.chrs/03"

.ifdef NEXT_ON_TOP
ips_tilehdr CHR_RIGHT,$9E
.incbin "build/twoplayer.chrs/16"

ips_tilehdr CHR_RIGHT,$9F
.incbin "build/twoplayer.chrs/17"
.endif
47 changes: 29 additions & 18 deletions twoplayer-tetris-PRG.s.diff
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
and #$01
beq @renderLevel
lda numberOfPlayers
@@ -2424,36 +2533,36 @@ @renderLines:
@@ -2424,36 +2533,47 @@ @renderLines:
and #$FE
sta outOfDateRenderFlags
jmp @renderLevel
Expand All @@ -454,18 +454,29 @@
+ lda #$21
sta PPUADDR
- lda #$68
+.ifndef NEXT_ON_TOP
+ lda #$CF
+.else
+ lda #$6F
+.endif
sta PPUADDR
lda player1_lines+1
sta PPUDATA
lda player1_lines
jsr twoDigsToPPU
- lda #$20
+.ifndef NEXT_ON_TOP
+ lda #$23
sta PPUADDR
- lda #$7A
+ lda #$30
sta PPUADDR
+.else
+ lda #$22
+ sta PPUADDR
+ lda #$50
+ sta PPUADDR
+.endif
lda player2_lines+1
sta PPUDATA
lda player2_lines
Expand All @@ -488,7 +499,7 @@
sta generalCounter
lda #$22
sta PPUADDR
@@ -2464,12 +2573,17 @@ @renderLevel:
@@ -2464,12 +2584,17 @@ @renderLevel:
jsr updatePaletteForLevel
lda outOfDateRenderFlags
and #$FD
Expand All @@ -508,7 +519,7 @@
and #$04
beq @renderStats
lda #$21
@@ -2517,13 +2631,14 @@ @renderTetrisFlashAndSound:
@@ -2517,13 +2642,14 @@ @renderTetrisFlashAndSound:
lda #$3F
sta PPUADDR
lda #$0E
Expand All @@ -526,7 +537,7 @@
bne @setPaletteColor
ldx #$30
lda frameCounter
@@ -2532,17 +2647,28 @@ @renderTetrisFlashAndSound:
@@ -2532,17 +2658,28 @@ @renderTetrisFlashAndSound:
lda #$09
sta soundEffectSlot1Init
@setPaletteColor:
Expand Down Expand Up @@ -558,7 +569,7 @@
.dbyt $2286,$22C6,$2306
levelDisplayTable:
.byte $00,$01,$02,$03,$04,$05,$06,$07
@@ -2552,63 +2678,74 @@ levelDisplayTable:
@@ -2552,63 +2689,74 @@ levelDisplayTable:
multBy10Table:
.byte $00,$0A,$14,$1E,$28,$32,$3C,$46
.byte $50,$5A,$64,$6E,$78,$82,$8C,$96
Expand Down Expand Up @@ -652,7 +663,7 @@
sta PPUADDR
@copyRow:
ldx #$0A
@@ -2632,15 +2769,15 @@ updateLineClearingAnimation:
@@ -2632,15 +2780,15 @@ updateLineClearingAnimation:
bne @ret
lda #$00
sta generalCounter3
Expand All @@ -672,7 +683,7 @@
cmp #$01
bne @twoPlayers
lda generalCounter
@@ -2653,22 +2790,22 @@ @twoPlayers:
@@ -2653,22 +2801,22 @@ @twoPlayers:
lda playfieldAddr+1
cmp #$04
bne @player2
Expand All @@ -699,7 +710,7 @@
ldx rowY
lda leftColumns,x
clc
@@ -2702,45 +2839,47 @@ leftColumns:
@@ -2702,45 +2850,47 @@ leftColumns:
rightColumns:
.byte $05,$06,$07,$08,$09
; Set Background palette 2 and Sprite palette 2
Expand Down Expand Up @@ -759,7 +770,7 @@
.dbyt $0F30,$2112,$0F30,$291A
.dbyt $0F30,$2414,$0F30,$2A12
.dbyt $0F30,$2B15,$0F30,$222B
@@ -2767,11 +2906,12 @@ @ret: rts
@@ -2767,11 +2917,12 @@ @ret: rts

playState_spawnNextTetrimino:
lda vramRow
Expand All @@ -773,7 +784,7 @@
lda twoPlayerPieceDelayCounter
cmp #$00
bne @twoPlayerPieceDelay
@@ -2796,24 +2936,25 @@ @notDelaying:
@@ -2796,24 +2947,25 @@ @notDelaying:
sta tetriminoY
lda #$01
sta playState
Expand Down Expand Up @@ -802,7 +813,7 @@
sta autorepeatY
@ret: rts

@@ -2832,43 +2973,47 @@ chooseNextTetrimino:
@@ -2832,43 +2984,47 @@ chooseNextTetrimino:
tax
lda spawnTable,x
rts
Expand Down Expand Up @@ -860,7 +871,7 @@
tetriminoTypeFromOrientation:
.byte $00,$00,$00,$00,$01,$01,$01,$01
.byte $02,$02,$03,$04,$04,$05,$05,$05
@@ -3028,12 +3173,15 @@ @checkForStartButton:
@@ -3028,12 +3184,15 @@ @checkForStartButton:
lda newlyPressedButtons_player1
cmp #$10
bne @ret2
Expand All @@ -878,7 +889,7 @@
playState_checkForCompletedRows:
lda vramRow
cmp #$20
@@ -3128,11 +3276,12 @@ @ret: rts
@@ -3128,11 +3287,12 @@ @ret: rts

playState_receiveGarbage:
lda numberOfPlayers
Expand All @@ -892,7 +903,7 @@
cmp #$20
bmi L9B52
lda multBy10Table,y
@@ -3154,11 +3303,11 @@ L9B31: cpx garbageHole
@@ -3154,11 +3314,11 @@ L9B31: cpx garbageHole
beq @garbageEmptySpace
lda #$78
jmp @placeGarbage
Expand All @@ -905,7 +916,7 @@
inx
cpx #$0A
bne L9B45
@@ -3389,11 +3538,12 @@ gameModeState_handleGameOver:
@@ -3389,11 +3549,12 @@ gameModeState_handleGameOver:
sta generalCounter2
lda player2_playState
cmp #$00
Expand All @@ -919,7 +930,7 @@
lda #$09
sta gameModeState
rts
@@ -3438,23 +3588,31 @@ @checkForBlockInRow:
@@ -3438,23 +3599,31 @@ @checkForBlockInRow:
bne @foundBlockInRow
iny
dex
Expand Down Expand Up @@ -956,7 +967,7 @@
adc #$04
tax
lda musicSelectionTable,x
@@ -3823,11 +3981,11 @@ L9FE9: ldy #$00
@@ -3823,11 +3992,11 @@ L9FE9: ldy #$00
sty PPUSCROLL
sty PPUSCROLL
rts
Expand All @@ -969,7 +980,7 @@
jmp LA085

L9FFB: jsr bulkCopyToPpu
@@ -6204,17 +6362,17 @@ dmc1: .byte $6D,$6E,$6F,$5F,$3C,$33,
@@ -6204,17 +6373,17 @@ dmc1: .byte $6D,$6E,$6F,$5F,$3C,$33,
.byte $87,$78,$84,$7A,$77,$87,$78,$84
.byte $7A,$67,$87,$77,$87,$77,$72,$83
.byte $80,$81,$77,$67,$82,$79,$7A,$67
Expand Down
Binary file added twoplayer.chr
Binary file not shown.
18 changes: 18 additions & 0 deletions twoplayer.s
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

.include "build/tetris.inc"

.segment "CHR"
.incbin "build/tetris-CHR-00.chr"
.incbin "build/twoplayer-CHR-01.chr"

.bss


Expand Down Expand Up @@ -136,18 +140,32 @@ renderPlay_mod:
eor #$02
and #$06
bne @renderScore
.ifndef NEXT_ON_TOP
lda #$20
sta PPUADDR
lda #$EF
sta PPUADDR
.else
lda #$21
sta PPUADDR
lda #$0F
sta PPUADDR
.endif
ldx player1_levelNumber
lda levelDisplayTable,x
jsr twoDigsToPPU
jsr updatePaletteForLevel
.ifndef NEXT_ON_TOP
lda #$22
sta PPUADDR
lda #$50
sta PPUADDR
.else
lda #$21
sta PPUADDR
lda #$F0
sta PPUADDR
.endif
ldx player2_levelNumber
lda levelDisplayTable,x
jsr twoDigsToPPU
Expand Down
Binary file modified twoplayer_game.nam
Binary file not shown.
Binary file modified twoplayer_game_top.nam
Binary file not shown.

0 comments on commit 5f48335

Please sign in to comment.