forked from hatschky/pokecarde
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmacros.asm
318 lines (290 loc) · 4.21 KB
/
macros.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
; some Z80 opcodes aren’t supported by Game Boy,
; but are used in e-Reader programs
; ld [\1], hl
LD_IND_HL: MACRO
db $22, (\1 & $FF), (\1 >> 8)
ENDM
; ld [\1], a
LD_IND_A: MACRO
db $32, (\1 & $FF), (\1 >> 8)
ENDM
; ld hl, [\1]
LD_HL_IND: MACRO
db $2A, (\1 & $FF), (\1 >> 8)
ENDM
; ld a, [\1]
LD_A_IND: MACRO
db $3A
dw \1
ENDM
waita: MACRO
ld a, \1
db $76
ENDM
; ld [hl], a
LD_IND_HL_A: MACRO
db $77
ENDM
; ld a, [hl]
LD_IND_A_HL: MACRO
db $7E
ENDM
; ld c, [hl]
LD_IND_C_HL: MACRO
db $4E
ENDM
; ld b, [hl]
LD_IND_B_HL: MACRO
db $46
ENDM
; ld l, [hl]
LD_IND_L_HL: MACRO
db $6E
ENDM
; ld e, [hl]
LD_IND_E_HL: MACRO
db $5E
ENDM
; ld d, [hl]
LD_IND_D_HL: MACRO
db $56
ENDM
; ld [hl], c
LD_IND_HL_C: MACRO
db $71
ENDM
; ld [hl], b
LD_IND_HL_B: MACRO
db $70
ENDM
; ld a, [de]
LD_IND_A_DE: MACRO
db $1A
ENDM
; add a, [hl]
ADD_A_HL_IND: MACRO
db $86
ENDM
EX_DE_HL: MACRO
db $EB
ENDM
wait: MACRO
db $D3, \1
ENDM
API: MACRO
db ($C7 + (\1 & $100) >> 5), (\1 & $FF) ; $C7 for API $0xx, $CF for API $1xx
ENDM
dd: MACRO
dw (\1) & $FFFF
dw (\1) >> 16
ENDM
RGB: MACRO
dw (\1) | ((\2) << 5) | ((\3) << 10)
ENDM
GBAPTR: MACRO
dd $02000000 + \1 - ScriptBaseAddress
ENDM
Insert_Prologue: MACRO
db "GameFreak inc."
db 0,0,0,0,0,0
dd \1
db \2
REPT 8 - STRLEN(\2)
db 0
ENDR
db 0,0,0,0,$01,$55
db 0,0,0,0
db \3
db 0
db "GameFreak inc."
db 0,0
ENDM
Mystery_Event: MACRO
ScriptBaseAddress EQU $100
SECTION "mysteryevent", ROM0[$100]
db $01
dd $02000000
db REGION,0,REGION,0,0,0,$04,0,$80,$01,0,0
ENDM
REGION_JP EQU $01
REGION_EN EQU $02
REGION_FR EQU $03 ; ?
REGION_IT EQU $04 ; ?
REGION_DE EQU $05 ; !
REGION_ES EQU $07 ; ¿?
; types of card data
END_OF_CHUNKS EQU $02
LOADING_MESSAGE EQU $03
SET_LOAD_STATUS EQU $04
PRELOAD_SCRIPT EQU $05
IN_GAME_SCRIPT EQU $06
CUSTOM_BERRY EQU $07
AWARD_RIBBON EQU $08
NATIONAL_POKEDEX EQU $09
ADD_RARE_WORD EQU $0A
MIX_RECORDS_ITEM EQU $0B
GIVE_POKEMON EQU $0C
BATTLE_TRAINER EQU $0D
CLOCK_ADJUSTMENT EQU $0E
CHECKSUM_BYTES EQU $0F ; don’t use this
CHECKSUM_CRC EQU $10 ; use this instead
DOME_TRAINER EQU $11 ; Battle Dome trainer
; an FF byte followed by 00s will flag the end of the program so that it can
; be extracted automatically from the Game Boy ROM that rgbds tries to build
EOF: MACRO
db $FF
ENDM
; names for some API functions based on Martin Korth’s GBATEK
; http://problemkaputt.de/gbatek.htm
FadeIn: MACRO
ld a, \1
API $000
ENDM
SetBackgroundAutoScroll: MACRO
ld bc, \1
ld de, \2
xor a
API $012
ENDM
SetBackgroundMode: MACRO
ld e, \1
push de
xor a
API $019
ENDM
API_02C: MACRO
ld hl, $0000
push hl
ld bc, \1
ld de, \2
IF \3 == 0
xor a ; save a byte
ELSE
ld a, \3
ENDC
API $02C
ENDM
LoadCustomBackground: MACRO
ld de, \1
IF \2 == 0
xor a ; save a byte
ELSE
ld a, \2
ENDC
API $02D
ENDM
SetSpritePos: MACRO
ld bc, \3
ld de, \2
LD_HL_IND \1
API $032
ENDM
SpriteShow: MACRO
LD_HL_IND \1
API $046
ENDM
SpriteHide: MACRO
LD_HL_IND \1
API $047
ENDM
SpriteMirrorToggle: MACRO
ld e, \1
LD_HL_IND \2
API $048
ENDM
CreateCustomSprite: MACRO
ld e, \2
ld hl, \3
API $04D
LD_IND_HL \1
ENDM
SpriteAutoScaleUntilSize: MACRO
ld c, \2
ld de, \3
LD_HL_IND \1
API $05B
ENDM
SetBackgroundPalette: MACRO
ld c, \1
ld de, \2
ld hl, \3
API $07E
ENDM
API_084: MACRO
ld l, \4
push hl
ld bc, \3
ld de, \2
LD_HL_IND \1
API $084
ENDM
CreateRegion: MACRO
ld bc, (\2 << 8 + \3)
ld de, (\4 << 8 + \5)
ld hl, (\6 << 8 + \7)
API $090
LD_IND_A \1
ENDM
SetRegionColor: MACRO
ld e, \2
LD_A_IND \1
API $091
ENDM
CLEAR_REGION: MACRO
LD_A_IND \1
API $092
ENDM
SetTextColor: MACRO
ld de, (\2 << 8 + \3)
LD_A_IND \1
API $098
ENDM
DrawText: MACRO
CLEAR_REGION \1
ld bc, \2
ld de, (\3 << 8 + \4)
LD_A_IND \1
API $099
ENDM
SetTextSize: MACRO
API $09A
ENDM
API_09B: MACRO
ld de, \2
LD_A_IND \1
API $09B
ENDM
GetTextWidth: MACRO
ld de, \2
LD_A_IND \1
API $0C0
ENDM
API_0C7: MACRO
ld hl, \1
API $0C7
ENDM
EXIT: MACRO
API $100
ENDM
API_106: MACRO
ld de, \1
ld hl, \2
API $106
ENDM
SOUND_PAUSE: MACRO
API $116
ENDM
IS_SOUND_PLAYING: MACRO
API $08D
ld b, $00
ld e, $01
ld hl, $0006
API $119
ld a, \1
EXIT
ENDM
API_121: MACRO
ld de, $0000
ld hl, $0000
API $121
ENDM