This repository was archived by the owner on Sep 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDefines.asm
More file actions
executable file
·263 lines (220 loc) · 5.5 KB
/
Defines.asm
File metadata and controls
executable file
·263 lines (220 loc) · 5.5 KB
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
; ================
def sys_DMG equ 0
def sys_GBP equ 1
def sys_SGB equ 2
def sys_SGB2 equ 3
def sys_GBC equ 4
def sys_GBA equ 5
def btnA equ 0
def btnB equ 1
def btnSelect equ 2
def btnStart equ 3
def btnRight equ 4
def btnLeft equ 5
def btnUp equ 6
def btnDown equ 7
def _A equ 1
def _B equ 2
def _Select equ 4
def _Start equ 8
def _Right equ 16
def _Left equ 32
def _Up equ 64
def _Down equ 128
; ==========================
; Project-specific constants
; ==========================
; TODO: Remove this
def TILESET_TEST equ 0
; ======
; Macros
; ======
; Copy a tileset to a specified VRAM address.
; USAGE: CopyTileset [tileset],[VRAM address],[number of tiles to copy]
macro CopyTileset
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.
macro CopyTilesetSafe
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]
macro CopyTileset1BPP
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.
macro CopyTileset1BPPSafe
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)
macro SetDMGPal
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>
macro RGB
dw \1+(\2<<5)+(\3<<10)
endm
; Wait for VRAM accessibility.
macro WaitForVRAM
ldh a,[rSTAT]
and STATF_BUSY
jr nz,@-4
endm
macro string
db \1,0
endm
; Loads appropriate ROM bank for a block of data and loads its pointer into a given register.
; Trashes B.
macro ldfar
ld b,bank(\2)
rst Bankswitch
ld \1,\2
endm
; Loads appropriate ROM bank for a routine and executes it.
; Trashes B.
macro farcall
ld b,bank(\1)
rst Bankswitch
call \1
endm
macro resbank
ldh a,[sys_LastBank]
ldh [sys_CurrentBank],a
ld [rROMB0],a
endm
macro bankptr
db bank(\1)
dw \1
endm
macro djnz
dec b
jr nz,\1
endm
macro lb
ld \1,\2<<8 | \3
endm
macro dbp
.str\@
db \1
.str\@_end
rept \2-(.str\@_end-.str\@)
db \3
endr
endm
macro dbw
db \1
dw \2
endm
macro dwb2
db bank(\1)
dw \1
db bank(\2)
dw \2
endm
macro dwb3
db bank(\1)
dw \1
db bank(\2)
dw \2
db bank(\3)
dw \3
endm
if DebugMode
macro debugmsg
ld d,d
jr .\@
dw $6464
dw 0
db \1,0
dw 0
dw 0
.\@
endm
endc
macro const_def
def const_value = 0
endm
macro const
if "\1" != "skip"
def \1 equ const_value
endc
def const_value = const_value + 1
endm
macro PlaySFX
ld a,bank(SFX_\1)
ld hl,SFX_\1
call VGMSFX_Init
endm
macro tmcoord
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