1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
.segment "CODE"
;; The game is so simple that it can fit in both nametables. This scope has all
;; the functions and data that initializes and resets all of them properly.
.scope Assets
;; Initialize palettes and nametables.
.proc init
jsr init_palettes
;; Load the title screen on the first nametable.
lda #.lobyte(title_screen)
sta Globals::zp_arg0
lda #.hibyte(title_screen)
sta Globals::zp_arg1
ldx #$20
jsr load_screen_x
;; Ensure that the title looks as expected.
jsr prepare_for_title_screen
;; Load the main screen on the second nametable.
lda #.lobyte(main_screen)
sta Globals::zp_arg0
lda #.hibyte(main_screen)
sta Globals::zp_arg1
ldx #$28
jsr load_screen_x ;; TODO: jal
rts
.endproc
;; Load the 1KB worth of screen data located via the 16-bit pointer on
;; Globals::zp_arg{0,1}. Set the `x` register to the high byte of the
;; nametable to be used.
.proc load_screen_x
bit PPU::m_status
stx PPU::m_address
lda #$00
sta PPU::m_address
ldy #0
ldx #4
@loop:
lda (Globals::zp_arg0), y
sta PPU::m_data
iny
bne @loop
dex
beq @end
inc Globals::zp_arg1
jmp @loop
@end:
rts
.endproc
;; Performs all the needed tricks in order to get the first nametable as
;; expected.
.proc prepare_for_title_screen
bit PPU::m_status
lda #$23
sta PPU::m_address
lda #$C8
sta PPU::m_address
ldx #$10
@upper_title_bar_loop:
lda #%10101010
sta PPU::m_data
dex
bne @upper_title_bar_loop
;; Update 2nd palette for background. This is redundant upon entering
;; the game, but it makes sense after a game over.
lda #$3F
sta PPU::m_address
lda #$09
sta PPU::m_address
lda #$28
sta PPU::m_data
lda #$2C
sta PPU::m_data
lda #$16
sta PPU::m_data
;; Update 1st palette for foreground.
lda #$3F
sta PPU::m_address
lda #$11
sta PPU::m_address
lda #$30
sta PPU::m_data
lda #$10
sta PPU::m_data
lda #$30
sta PPU::m_data
rts
.endproc
;; Performs all the needed tricks in order to get the second nametable as
;; expected.
.proc prepare_for_main_screen
bit PPU::m_status
;; Update 2nd palette for background.
lda #$3F
sta PPU::m_address
lda #$09
sta PPU::m_address
lda #$14
sta PPU::m_data
lda #$2C
sta PPU::m_data
lda #$28
sta PPU::m_data
;; Update 1st palette for foreground.
lda #$3F
sta PPU::m_address
lda #$11
sta PPU::m_address
lda #$16
sta PPU::m_data
lda #$10
sta PPU::m_data
lda #$30
sta PPU::m_data
rts
.endproc
;; Copies all the palettes for our game into the proper PPU address.
.proc init_palettes
lda #$3F
sta PPU::m_address
lda #$00
sta PPU::m_address
ldx #0
@load_palettes_loop:
lda palettes, x
sta PPU::m_data
inx
cpx #$20
bne @load_palettes_loop
rts
palettes:
;; Background
;; 0: score
.byte $0F, $30, $2C, $28
;; 1: floating platforms
.byte $0F, $2C, $30, $2A
;; 2: ground
.byte $0F, $28, $2C, $16
;; 3: ship
.byte $0F, $16, $30, $00
;; TODO: fuel tank needs color $24
;; TODO: SUSE coin needs $0F, $16, $10, $18
;; Foreground
;; 0: player & ship
.byte $0F, $30, $10, $30
;; 1: enemy 1 & bonuses
.byte $0F, $16, $2C, $2A
;; 2: enemy 2, fuel & bonuses
.byte $0F, $16, $14, $28
;; 3: SUSE easter egg
.byte $0F, $16, $00, $2B
.endproc
;; Having 2KB for screen data is quite wasteful, but since it's such a
;; simple game, I have so much space left in the cartridge that I can go
;; bananas with it. This helps out loading the screen as we can go faster
;; and it is less error prone.
title_screen:
.incbin "../assets/title.nam"
main_screen:
.incbin "../assets/main.nam"
.endscope
.segment "CHARS"
.incbin "../assets/jetpac.chr"
|