Skip to content

Commit

Permalink
Reorganize code to split mods into their components
Browse files Browse the repository at this point in the history
Rename files to try to be more clear what is used for what.
  • Loading branch information
ejona86 committed May 19, 2019
1 parent 643b712 commit 1660d2e
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 103 deletions.
52 changes: 32 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
all: tetris mod screens
all: tetris taus screens

# Manually list prerequisites that are generated. Non-generated files will
# automatically be computed.
build/taus.o: build/tetris.inc
build/screens.o: build/tetris.inc
# List linker dependencies
build/tetris.nes: build/tetris.o tetris-PRG.o
build/taus.ips: build/taus.o build/ips.o build/fastlegal.o build/highscores.o
build/screens.ips: build/screens.o build/ips.o

CAFLAGS =
LDFLAGS =
VPATH = build

build:
mkdir build

build/tetris-PRG.s: disasm.info tetris-PRG.bin Makefile | build
da65 -i disasm.info -o build/tetris-PRG.s tetris-PRG.bin

build/%.o: %.s Makefile | build
ca65 $< -o $@
ca65 $(CAFLAGS) --create-dep $@.d $< -o $@

build/tetris.o: tetris-CHR-00.bin tetris-CHR-01.bin
build/%: %.cfg
ld65 $(LDFLAGS) -o $@ -C $< $(filter %.o,$^)

build/tetris.nes: tetris.cfg build/tetris.o build/tetris-PRG.s
ca65 -g build/tetris-PRG.s -o build/tetris-PRG.o
ld65 -o build/tetris.nes -C tetris.cfg -Ln build/tetris.lbl build/tetris.o build/tetris-PRG.o
sed -E -e 's/al 00(.{4}) .(.*)/\2 := $$\1/' build/tetris.lbl > build/tetris.inc
build/%.nes: build/%.ips build/tetris.nes
cp build/tetris.nes $@
flips $< $@ > /dev/null
flips build/tetris.nes $@ build/$*.dist.ips > /dev/null

build/tetris-mod.o: build/tetris.nes
build/tetris-screens.o: build/tetris.nes
build/tetris-PRG.s: tetris-PRG.info tetris-PRG.bin Makefile | build
da65 -i tetris-PRG.info -o $@ tetris-PRG.bin

build/tetris-%.nes: tetris-%.cfg build/tetris-%.o build/tetris.nes
ld65 -o build/tetris-$*.ips -C tetris-$*.cfg build/tetris-$*.o
cp build/tetris.nes build/tetris-$*.nes
flips build/tetris-$*.ips build/tetris-$*.nes > /dev/null
flips build/tetris.nes build/tetris-$*.nes build/tetris-$*.dist.ips > /dev/null
build/tetris-PRG.o: CAFLAGS = -g
build/tetris.nes: LDFLAGS = -Ln build/tetris.lbl
build/tetris.inc: build/tetris.nes
sed -E -e 's/al 00(.{4}) .(.*)/\2 := $$\1/' build/tetris.lbl > build/tetris.inc

test: tetris.nes build/tetris.nes
diff tetris.nes build/tetris.nes
Expand All @@ -33,11 +43,11 @@ clean:

dis: build/tetris-PRG.s
tetris: build/tetris.nes
mod: build/tetris-mod.nes
screens: build/tetris-screens.nes
taus: build/taus.nes
screens: build/screens.nes

# These are simply aliases
.PHONY: all dis tetris mod screens
.PHONY: all dis tetris taus screens
# These are "true" phonies, and always execute something
.PHONY: test clean

Expand All @@ -46,3 +56,5 @@ screens: build/tetris-screens.nes
ifneq "$(V)" "1"
.SILENT:
endif

include $(wildcard build/*.d)
16 changes: 16 additions & 0 deletions fastlegal.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;
; Mod that allows pressing start to skip legal screen
;

.include "ips.inc"

.segment "SKIP_LEGALHDR"
.import __SKIP_LEGAL_RUN__, __SKIP_LEGAL_SIZE__
.byte 0
.dbyt __SKIP_LEGAL_RUN__-IPSPRGOFFSET
.dbyt __SKIP_LEGAL_SIZE__

.segment "SKIP_LEGAL"

; Allow skipping legal screen
lda #$00
40 changes: 40 additions & 0 deletions highscores.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
;
; Custom high scores
;

.include "ips.inc"

.segment "DEFAULT_HIGH_SCORESHDR"
.import __DEFAULT_HIGH_SCORES_RUN__, __DEFAULT_HIGH_SCORES_SIZE__
.byte 0
.dbyt __DEFAULT_HIGH_SCORES_RUN__-IPSPRGOFFSET
.dbyt __DEFAULT_HIGH_SCORES_SIZE__

.segment "DEFAULT_HIGH_SCORES"

; replace defaultHighScoresTable
; NAME
; # Convert ALPHA string to hex:
; list(map(lambda x: hex(ord(x)-64), "CHEATR"))
.byte $01,$13,$08,$01,$12,$01 ; "ASHARA"
.byte $05,$0D,$2A,$0A,$2B,$2B ; "EM.J "
.byte $05,$12,$09,$03,$2B,$2B ; "ERIC "
.byte $00,$00,$00,$00,$00,$00
.byte $01,$0C,$05,$18,$2B,$2B
.byte $14,$0F,$0E,$19,$2B,$2B
.byte $0E,$09,$0E,$14,$05,$0E
.byte $00,$00,$00,$00,$00,$00
; SCORE, in BCD
.byte $39,$97,$72
.byte $29,$51,$88
.byte $17,$30,$68
.byte $00,$00,$00
.byte $00,$20,$00
.byte $00,$10,$00
.byte $00,$05,$00
.byte $00,$00,$00
; LV, in binary
.byte $13,$12,$09,$00
.byte $09,$05,$00,$00
.byte $FF

1 change: 1 addition & 0 deletions ips.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IPSPRGOFFSET = -16+$8000
9 changes: 9 additions & 0 deletions ips.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
;
; IPS file boilerplate
;

.segment "IPSHEADER"
.byte 'P', 'A', 'T', 'C', 'H'

.segment "IPSEOF"
.byte 'E', 'O', 'F'
10 changes: 5 additions & 5 deletions tetris-screens.cfg → screens.ips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ MEMORY {
HUNK1: start = $800E, size = $0003, type = ro, file = %O;
JMP_MAIN_LOOP_ITERHDR:start = $0000, size = $0005, type = ro, file = %O;
JMP_MAIN_LOOP_ITER: start = $8138, size = $0003, type = ro, file = %O;
MAINHDR:start = $0000, size = $0005, type = ro, file = %O;
MAIN: start = $D6C9, size = $0837, type = ro, file = %O;
CODEHDR:start = $0000, size = $0005, type = ro, file = %O;
CODE: start = $D6C9, size = $0837, type = ro, file = %O;
IPSEOF: start = $0000, size = $0003, type = ro, file = %O;
}

SEGMENTS {
IPSHEADER:load = IPSHDR, type = ro;
IPSEOF: load = IPSEOF, type = ro;
CODEHDR: load = CODEHDR, type = ro;
CODE: load = CODE, type = ro, define = yes;
HUNK1HDR: load = HUNK1HDR, type = ro;
HUNK1: load = HUNK1, type = ro, define = yes;
JMP_MAIN_LOOP_ITERHDR: load = JMP_MAIN_LOOP_ITERHDR, type = ro;
JMP_MAIN_LOOP_ITER: load = JMP_MAIN_LOOP_ITER, type = ro, define = yes;
MAINHDR: load = MAINHDR, type = ro;
MAIN: load = MAIN, type = ro, define = yes;
IPSEOF: load = IPSEOF, type = ro;
}
19 changes: 6 additions & 13 deletions tetris-screens.s → screens.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
;

.include "build/tetris.inc"

IPSPRGOFFSET = -16+$8000

.segment "IPSHEADER"
.byte 'P', 'A', 'T', 'C', 'H'

.segment "IPSEOF"
.byte 'E', 'O', 'F'
.include "ips.inc"

.segment "HUNK1HDR"
.import __HUNK1_RUN__, __HUNK1_SIZE__
Expand All @@ -37,13 +30,13 @@ IPSPRGOFFSET = -16+$8000
jsr mainLoopIterMod


.segment "MAINHDR"
.import __MAIN_RUN__, __MAIN_SIZE__
.segment "CODEHDR"
.import __CODE_RUN__, __CODE_SIZE__
.byte 0
.dbyt __MAIN_RUN__-IPSPRGOFFSET
.dbyt __MAIN_SIZE__
.dbyt __CODE_RUN__-IPSPRGOFFSET
.dbyt __CODE_SIZE__

.segment "MAIN"
.segment "CODE"

screenToDisplay := levelNumber
backgroundRendered := levelNumber+1
Expand Down
10 changes: 5 additions & 5 deletions tetris-mod.cfg → taus.ips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ MEMORY {
DEFAULT_HIGH_SCORES: start = $AD67, size = $8000, type = ro, file = %O;
GAME_BGHDR:start = $0000, size = $0005, type = ro, file = %O;
GAME_BG: start = $BF3C, size = $8000, type = ro, file = %O;
MAINHDR:start = $0000, size = $0005, type = ro, file = %O;
MAIN: start = $D6C9, size = $0837, type = ro, file = %O;
CODEHDR:start = $0000, size = $0005, type = ro, file = %O;
CODE: start = $D6C9, size = $0837, type = ro, file = %O;
IPSEOF: start = $0000, size = $0003, type = ro, file = %O;
}

SEGMENTS {
IPSHEADER:load = IPSHDR, type = ro;
IPSEOF: load = IPSEOF, type = ro;
CODEHDR: load = CODEHDR, type = ro;
CODE: load = CODE, type = ro, define = yes;
HUNK1HDR: load = HUNK1HDR, type = ro;
HUNK1: load = HUNK1, type = ro, define = yes;
MAINHDR: load = MAINHDR, type = ro;
MAIN: load = MAIN, type = ro, define = yes;
GAME_BGHDR: load = GAME_BGHDR, type = ro;
GAME_BG: load = GAME_BG, type = ro, define = yes;
STATS_NUMBERHDR: load = STATS_NUMBERHDR, type = ro;
Expand All @@ -33,5 +34,4 @@ SEGMENTS {
JMP_STATS_PER_LINE_CLEAR: load = JMP_STATS_PER_LINE_CLEAR, type = ro, define = yes;
DEFAULT_HIGH_SCORESHDR: load = DEFAULT_HIGH_SCORESHDR, type = ro;
DEFAULT_HIGH_SCORES: load = DEFAULT_HIGH_SCORES, type = ro, define = yes;
IPSEOF: load = IPSEOF, type = ro;
}
67 changes: 7 additions & 60 deletions tetris-mod.s → taus.s
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
;
; IPS Mod
; Tetris AUS mod: Actually Useful Stats
;

.include "build/tetris.inc"

IPSPRGOFFSET = -16+$8000

.segment "IPSHEADER"
.byte 'P', 'A', 'T', 'C', 'H'

.segment "IPSEOF"
.byte 'E', 'O', 'F'
.include "ips.inc"

.segment "HUNK1HDR"
.import __HUNK1_RUN__, __HUNK1_SIZE__
Expand All @@ -24,13 +17,13 @@ IPSPRGOFFSET = -16+$8000
jmp statsPerBlock
afterJmpResetStatMod:

.segment "MAINHDR"
.import __MAIN_RUN__, __MAIN_SIZE__
.segment "CODEHDR"
.import __CODE_RUN__, __CODE_SIZE__
.byte 0
.dbyt __MAIN_RUN__-IPSPRGOFFSET
.dbyt __MAIN_SIZE__
.dbyt __CODE_RUN__-IPSPRGOFFSET
.dbyt __CODE_SIZE__

.segment "MAIN"
.segment "CODE"

DHT_index = $00
DHT := statsByType + DHT_index * 2
Expand Down Expand Up @@ -252,17 +245,6 @@ divmod_checkDone:
cmp #$03


.segment "SKIP_LEGALHDR"
.import __SKIP_LEGAL_RUN__, __SKIP_LEGAL_SIZE__
.byte 0
.dbyt __SKIP_LEGAL_RUN__-IPSPRGOFFSET
.dbyt __SKIP_LEGAL_SIZE__

.segment "SKIP_LEGAL"

; Allow skipping legal screen
lda #$00

.segment "JMP_STATS_PER_LINE_CLEARHDR"
.import __JMP_STATS_PER_LINE_CLEAR_RUN__, __JMP_STATS_PER_LINE_CLEAR_SIZE__
.byte 0
Expand All @@ -274,38 +256,3 @@ divmod_checkDone:
; at end of addLineClearPoints, replaces "lda #0; sta completedLines"
jsr statsPerLineClear
nop

.segment "DEFAULT_HIGH_SCORESHDR"
.import __DEFAULT_HIGH_SCORES_RUN__, __DEFAULT_HIGH_SCORES_SIZE__
.byte 0
.dbyt __DEFAULT_HIGH_SCORES_RUN__-IPSPRGOFFSET
.dbyt __DEFAULT_HIGH_SCORES_SIZE__

.segment "DEFAULT_HIGH_SCORES"

; replace defaultHighScoresTable
; NAME
; # Convert ALPHA string to hex:
; list(map(lambda x: hex(ord(x)-64), "CHEATR"))
.byte $01,$13,$08,$01,$12,$01 ; "ASHARA"
.byte $05,$0D,$2A,$0A,$2B,$2B ; "EM.J "
.byte $05,$12,$09,$03,$2B,$2B ; "ERIC "
.byte $00,$00,$00,$00,$00,$00
.byte $01,$0C,$05,$18,$2B,$2B
.byte $14,$0F,$0E,$19,$2B,$2B
.byte $0E,$09,$0E,$14,$05,$0E
.byte $00,$00,$00,$00,$00,$00
; SCORE, in BCD
.byte $39,$97,$72
.byte $29,$51,$88
.byte $17,$30,$68
.byte $00,$00,$00
.byte $00,$20,$00
.byte $00,$10,$00
.byte $00,$05,$00
.byte $00,$00,$00
; LV, in binary
.byte $13,$12,$09,$00
.byte $09,$05,$00,$00
.byte $FF

File renamed without changes.
File renamed without changes.

0 comments on commit 1660d2e

Please sign in to comment.