-
Notifications
You must be signed in to change notification settings - Fork 1
/
Defines.asm
executable file
·263 lines (220 loc) · 5.78 KB
/
Defines.asm
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
; ===============
; Project defines
; ===============
; Hardware defines
include "hardware.inc"
; ================
; Global constants
; ================
sys_DMG equ 0
sys_GBP equ 1
sys_SGB equ 2
sys_SGB2 equ 3
sys_GBC equ 4
sys_GBA equ 5
btnA equ 0
btnB equ 1
btnSelect equ 2
btnStart equ 3
btnRight equ 4
btnLeft equ 5
btnUp equ 6
btnDown equ 7
_A equ 1
_B equ 2
_Select equ 4
_Start equ 8
_Right equ 16
_Left equ 32
_Up equ 64
_Down equ 128
; ==========================
; Project-specific constants
; ==========================
; TODO: Remove this
TILESET_TEST equ 0
; ======
; Macros
; ======
; Copy a tileset to a specified VRAM address.
; USAGE: CopyTileset [tileset],[VRAM address],[number of tiles to copy]
CopyTileset: macro
ld bc,$10*\3 ; number of tiles to copy
ld hl,\1 ; address of tiles to copy
ld de,$8000+\2 ; address to copy to
call _CopyRAM
endm
; Same as CopyTileset, but waits for VRAM accessibility.
CopyTilesetSafe: macro
ld bc,$10*\3 ; number of tiles to copy
ld hl,\1 ; address of tiles to copy
ld de,$8000+\2 ; address to copy to
call _CopyTilesetSafe
endm
; Copy a 1BPP tileset to a specified VRAM address.
; USAGE: CopyTileset1BPP [tileset],[VRAM address],[number of tiles to copy]
CopyTileset1BPP: macro
ld bc,$10*\3 ; number of tiles to copy
ld hl,\1 ; address of tiles to copy
ld de,$8000+\2 ; address to copy to
call _CopyTileset1BPP
endm
; Same as CopyTileset1BPP, but waits for VRAM accessibility.
CopyTileset1BPPSafe: macro
ld bc,$10*\3 ; number of tiles to copy
ld hl,\1 ; address of tiles to copy
ld de,$8000+\2 ; address to copy to
call _CopyTileset1BPPSafe
endm
; Loads a DMG palette.
; USAGE: SetPal <rBGP/rOBP0/rOBP1>,(color 1),(color 2),(color 3),(color 4)
SetDMGPal: macro
ld a,(\2 + (\3 << 2) + (\4 << 4) + (\5 << 6))
ldh [\1],a
endm
; Defines a Game Boy Color RGB palette.
; USAGE: RGB <red>,<green>,<blue>
RGB: macro
dw \1+(\2<<5)+(\3<<10)
endm
; Wait for VRAM accessibility.
WaitForVRAM: macro
ldh a,[rSTAT]
and STATF_BUSY
jr nz,@-4
endm
string: macro
db \1,0
endm
; Loads appropriate ROM bank for a block of data and loads its pointer into a given register.
; Trashes B.
ldfar: macro
ld b,bank(\2)
rst Bankswitch
ld \1,\2
endm
; Loads appropriate ROM bank for a routine and executes it.
; Trashes B.
farcall: macro
ld b,bank(\1)
rst Bankswitch
call \1
endm
resbank: macro
ldh a,[sys_LastBank]
ldh [sys_CurrentBank],a
ld [rROMB0],a
endm
bankptr: macro
db bank(\1)
dw \1
endm
djnz: macro
dec b
jr nz,\1
endm
lb: macro
ld \1,\2<<8 | \3
endm
dbp: macro
.str\@
db \1
.str\@_end
rept \2-(.str\@_end-.str\@)
db \3
endr
endm
dbw: macro
db \1
dw \2
endm
dwb2: macro
db bank(\1)
dw \1
db bank(\2)
dw \2
endm
dwb3: macro
db bank(\1)
dw \1
db bank(\2)
dw \2
db bank(\3)
dw \3
endm
if DebugMode
debugmsg: macro
ld d,d
jr .\@
dw $6464
dw 0
db \1,0
dw 0
dw 0
.\@
endm
endc
const_def: macro
const_value = 0
endm
const: macro
if "\1" != "skip"
\1 equ const_value
endc
const_value = const_value + 1
ENDM
PlaySFX: macro
ld a,bank(SFX_\1)
ld hl,SFX_\1
call VGMSFX_Init
endm
tmcoord: macro
ld hl,sys_TilemapBuffer + ((\2*20) | \1)
endm
; === Project-specific macros ===
; =========
; Variables
; =========
section "Variables",wram0,align[8]
OAMBuffer: ds 40*4 ; 40 sprites, 4 bytes each
.end
sys_GBType: db ; 0 = DMG, 1 = GBC, 2 = GBA
sys_ResetTimer: db
sys_CurrentFrame: db ; incremented each frame, used for timing
sys_btnPress: db ; buttons pressed this frame
sys_btnHold: db ; buttons held
sys_btnRelease: db ; buttons released this frame
sys_VBlankFlag: db
sys_LCDCFlag: db
sys_TimerFlag: db
sys_SerialFlag: db
sys_JoypadFlag: db
sys_PauseGame: db
sys_SleepModeTimer: db
sys_SecondsUntilSleep: db
sys_EmuCheck: db
sys_EnableParallax: db
sys_EnableHDMA: db
sys_TilemapBuffer: ds 20*18
sys_StringBuffer: ds 32
; project-specific
section "Zeropage",hram
OAM_DMA: ds 16
tempAF: dw
tempBC: dw
tempDE: dw
tempHL: dw
tempSP: dw
sys_CurrentBank: db
sys_LastBank: db
sys_TempBank1: db
sys_TempBank2: db
sys_TempBank3: db
sys_TempCounter: db
sys_TempSVBK: db
sys_HDMA1: db
sys_HDMA2: db
sys_HDMA3: db
sys_HDMA4: db
sys_HDMA5: db
sys_HDMABank: db