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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
text EQUS "db $00," ; Start writing text.
next EQUS "db $4e," ; Move a line down.
line EQUS "db $4f," ; Start writing at the bottom line.
para EQUS "db $51," ; Start a new paragraph.
cont EQUS "db $55," ; Scroll to the next line.
done EQUS "db $57" ; End a text box.
prompt EQUS "db $58" ; Prompt the player to end a text box (initiating some other event).
page EQUS "db $49," ; Start a new Pokedex page.
dex EQUS "db $5f, $50" ; End a Pokedex entry.
homecall: MACRO
ld a, [H_LOADEDROMBANK]
push af
ld a, BANK(\1)
ld [H_LOADEDROMBANK], a
ld [MBC3RomBank], a
call \1
pop af
ld [H_LOADEDROMBANK], a
ld [MBC3RomBank], a
ENDM
callba: MACRO
ld b, BANK(\1)
ld hl, \1
call Bankswitch
ENDM
callab: MACRO
ld hl, \1
ld b, BANK(\1)
call Bankswitch
ENDM
;\1 = X
;\2 = Y
FuncCoord: MACRO
Coord = $C3A0 + 20 * \2 + \1
ENDM
;\1 = Map Width
;\2 = Rows above (Y-blocks)
;\3 = X movement (X-blocks)
EVENT_DISP: MACRO
dw (wOverworldMap + 7 + (\1) + ((\1) + 6) * ((\2) >> 1) + ((\3) >> 1)) ; Ev.Disp
db \2,\3 ;Y,X
ENDM
FLYWARP_DATA: MACRO
EVENT_DISP \1,\2,\3
db ((\2) & $01) ;sub-block Y
db ((\3) & $01) ;sub-block X
ENDM
; external map entry macro
EMAP: MACRO ; emap x-coordinate,y-coordinate,textpointer
; the appearance of towns and routes in the town map, indexed by map id
; nybble: y-coordinate
; nybble: x-coordinate
; word : pointer to map name
db (\1 + (\2 << 4))
dw \3
ENDM
; internal map entry macro
IMAP: MACRO ; imap mapid_less_than,x-coordinate,y-coordinate,textpointer
; the appearance of buildings and dungeons in the town map
; byte : maximum map id subject to this rule
; nybble: y-coordinate
; nybble: x-coordinate
; word : pointer to map name
db \1
db \2 + \3 << 4
dw \4
ENDM
; tilesets' headers macro
tileset: MACRO
db BANK(\2) ; BANK(GFX)
dw \1, \2, \3 ; Block, GFX, Coll
db \4, \5, \6 ; counter tiles
db \7 ; grass tile
db \8 ; permission (indoor, cave, outdoor)
ENDM
INDOOR EQU 0
CAVE EQU 1
OUTDOOR EQU 2
; macro for two nibbles
dn: MACRO
db (\1 << 4 | \2)
ENDM
; macro for putting a byte then a word
dbw: MACRO
db \1
dw \2
ENDM
; data format macros
RGB: MACRO
dw (\3 << 10 | \2 << 5 | \1)
ENDM
; text macros
TX_NUM: MACRO
; print a big-endian decimal number.
; \1: address to read from
; \2: number of bytes to read
; \3: number of digits to display
db $09
dw \1
db \2 << 4 | \3
ENDM
TX_FAR: MACRO
db $17
dw \1
db BANK(\1)
ENDM
; text engine command $1
TX_RAM: MACRO
; prints text to screen
; \1: RAM address to read from
db $1
dw \1
ENDM
TX_BCD: MACRO
db $2
dw \1
db \2
ENDM
; Predef macro.
PREDEF: MACRO
ld a, (\1 - PredefPointers) / 3
call Predef
ENDM
PREDEF_JUMP: MACRO
ld a, (\1 - PredefPointers) / 3
jp Predef
ENDM
;1_channel EQU $00
;2_channels EQU $40
;3_channels EQU $80
;4_channels EQU $C0
CH0 EQU 0
CH1 EQU 1
CH2 EQU 2
CH3 EQU 3
CH4 EQU 4
CH5 EQU 5
CH6 EQU 6
CH7 EQU 7
;Note Pitch
C_ EQU $0
C# EQU $1
D_ EQU $2
D# EQU $3
E_ EQU $4
F_ EQU $5
F# EQU $6
G_ EQU $7
G# EQU $8
A_ EQU $9
A# EQU $A
B_ EQU $B
;drum instruments
snare1 EQU $01
snare2 EQU $02
snare3 EQU $03
snare4 EQU $04
snare5 EQU $05
triangle1 EQU $06
triangle2 EQU $07
snare6 EQU $08
snare7 EQU $09
snare8 EQU $0a
snare9 EQU $0b
cymbal1 EQU $0c
cymbal2 EQU $0d
cymbal3 EQU $0e
mutedsnare1 EQU $0f
triangle3 EQU $10
mutedsnare2 EQU $11
mutedsnare3 EQU $12
mutedsnare4 EQU $13
unknownsfx0x10: MACRO
db $10
db \1
ENDM
unknownsfx0x20: MACRO
db $20 | \1
db \2
db \3
db \4
ENDM
unknownnoise0x20: MACRO
db $20 | \1
db \2
db \3
ENDM
;format: note pitch, length (in 16ths)
note: MACRO
db (\1 << 4) | (\2 - 1)
ENDM
;format: dnote length (in 16ths), instrument
dnote: MACRO
db $B0 | (\1 - 1)
db \2
ENDM
;format: rest length (in 16ths)
rest: MACRO
db $C0 | (\1 - 1)
ENDM
; format: notetype speed, volume, fade
notetype: MACRO
db $D0 | \1
db (\2 << 4) | \3
ENDM
dspeed: MACRO
db $D0 | \1
ENDM
octave: MACRO
db $E8 - \1
ENDM
togglecall: MACRO
db $E8
ENDM
;format: vibrato delay, rate, depth
vibrato: MACRO
db $EA
db \1
db (\2 << 4) | \3
ENDM
pitchbend: MACRO
db $EB
db \1
db \2
ENDM
duty: MACRO
db $EC
db \1
ENDM
tempo: MACRO
db $ED
db \1
db \2
ENDM
unknownmusic0xee: MACRO
db $EE
db \1
ENDM
stereopanning: MACRO
db $F0
db \1
ENDM
executemusic: MACRO
db $F8
ENDM
dutycycle: MACRO
db $FC
db \1
ENDM
;format: callchannel address
;callchannel: MACRO
; db $FD
; dw \1
;ENDM
;format: loopchannel count, address
;loopchannel: MACRO
; db $FE
; db \1
; dw \2
;ENDM
endchannel: MACRO
db $FF
ENDM
;\1 (byte) = connected map id
;\2 (byte) = connected map width
;\3 (byte) = connected map height
;\4 (byte) = x movement of connection strip
;\5 (byte) = connection strip offset
;\6 (byte) = width of connection strip
;\7 (word) = connected map blocks pointer
NORTH_MAP_CONNECTION: MACRO
db \1 ; map id
dw \7 + (\2 * (\3 - 3)) + \5; "Connection Strip" location
dw wOverworldMap + 3 + \4 ; current map position
db \6 ; width of connection strip
db \2 ; map width
db (\3 * 2) - 1 ; y alignment (y coordinate of player when entering map)
db (\4 - \5) * -2 ; x alignment (x coordinate of player when entering map)
dw wOverworldMap + 1 + (\3 * (\2 + 6)) ; window (position of the upper left block after entering the map)
ENDM
;\1 (byte) = connected map id
;\2 (byte) = connected map width
;\3 (byte) = x movement of connection strip
;\4 (byte) = connection strip offset
;\5 (byte) = width of connection strip
;\6 (word) = connected map blocks pointer
;\7 (byte) = current map width
;\8 (byte) = current map height
SOUTH_MAP_CONNECTION: MACRO
db \1 ; map id
dw \6 + \4 ; "Conection Strip" location
dw wOverworldMap + 3 + (\8 + 3) * (\7 + 6) + \3 ; current map positoin
db \5 ; width of connection strip
db \2 ; map width
db 0 ; y alignment (y coordinate of player when entering map)
db (\3 - \4) * -2 ; x alignment (x coordinate of player when entering map)
dw wOverworldMap + 7 + \2 ; window (position of the upper left block after entering the map)
ENDM
;\1 (byte) = connected map id
;\2 (byte) = connected map width
;\3 (byte) = y movement of connection strip
;\4 (byte) = connection strip offset
;\5 (byte) = height of connection strip
;\6 (word) = connected map blocks pointer
;\7 (byte) = current map width
EAST_MAP_CONNECTION: MACRO
db \1 ; map id
dw \6 + (\2 * \4) ; "Connection Strip" location
dw wOverworldMap - 3 + (\7 + 6) * (\3 + 4) ; current map position
db \5 ; height of connection strip
db \2 ; map width
db (\3 - \4) * -2 ; y alignment
db 0 ; x alignment
dw wOverworldMap + 7 + \2 ; window (position of the upper left block after entering the map)
ENDM
;\1 (byte) = connected map id
;\2 (byte) = connected map width
;\3 (byte) = y movement of connection strip
;\4 (byte) = connection strip offset
;\5 (byte) = height of connection strip
;\6 (word) = connected map blocks pointer
;\7 (byte) = current map width
WEST_MAP_CONNECTION: MACRO
db \1 ; map id
dw \6 + (\2 * \4) + \2 - 3 ; "Connection Strip" location
dw wOverworldMap + (\7 + 6) * (\3 + 3) ; current map position
db \5 ; height of connection strip
db \2 ; map width
db (\3 - \4) * -2 ; y alignment
db (\2 * 2) - 1 ; x alignment
dw wOverworldMap + 6 + (2 * \2) ; window (position of the upper left block after entring the map)
ENDM
|