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
|
; Constant enumeration is useful for monsters, items, moves, etc.
const_def: MACRO
if _NARG >= 1
const_value = \1
else
const_value = 0
endc
ENDM
const: MACRO
\1 EQU const_value
const_value = const_value + 1
ENDM
; data format macros
percent EQUS "* $ff / 100"
bcd2: MACRO
dn ((\1) / 1000) % 10, ((\1) / 100) % 10
dn ((\1) / 10) % 10, (\1) % 10
ENDM
bcd3: MACRO
dn ((\1) / 100000) % 10, ((\1) / 10000) % 10
dn ((\1) / 1000) % 10, ((\1) / 100) % 10
dn ((\1) / 10) % 10, (\1) % 10
ENDM
coins equs "bcd2"
money equs "bcd3"
;\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
dn \2, \1
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 + 1
dn \3, \2
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
RGB: MACRO
dw (\3 << 10 | \2 << 5 | \1)
ENDM
WALK EQU $FE
STAY EQU $FF
DOWN EQU $D0
UP EQU $D1
LEFT EQU $D2
RIGHT EQU $D3
NONE EQU $FF
;\1 sprite id
;\2 x position
;\3 y position
;\4 movement (WALK/STAY)
;\5 range or direction
;\6 text id
;\7 items only: item id
;\7 trainers only: trainer class/pokemon id
;\8 trainers only: trainer number/pokemon level
object: MACRO
db \1
db \3 + 4
db \2 + 4
db \4
db \5
IF (_NARG > 7)
db TRAINER | \6
db \7
db \8
ELSE
IF (_NARG > 6)
db ITEM | \6
db \7
ELSE
db \6
ENDC
ENDC
ENDM
;\1 x position
;\2 y position
;\3 destination warp id
;\4 destination map (-1 = wLastMap)
warp: MACRO
db \2, \1, \3, \4
ENDM
;\1 x position
;\2 y position
;\3 sign id
sign: MACRO
db \2, \1, \3
ENDM
;\1 x position
;\2 y position
;\3 map width
warp_to: MACRO
EVENT_DISP \3, \2, \1
ENDM
map_header: MACRO
;\1: map name
;\2: map id
;\3: tileset
;\4: connections: combo of NORTH, SOUTH, WEST, and/or EAST, or 0 for none
CURRENT_MAP_WIDTH = \2_WIDTH
CURRENT_MAP_HEIGHT = \2_HEIGHT
CURRENT_MAP_OBJECT EQUS "\1_Object"
\1_h::
db \3
db CURRENT_MAP_HEIGHT, CURRENT_MAP_WIDTH
dw \1_Blocks
dw \1_TextPointers
dw \1_Script
db \4
ENDM
end_map_header: MACRO
dw CURRENT_MAP_OBJECT
PURGE CURRENT_MAP_WIDTH
PURGE CURRENT_MAP_HEIGHT
PURGE CURRENT_MAP_OBJECT
ENDM
; Connections go in order: north, south, west, east
connection: MACRO
;\1: direction
;\2: map name
;\3: map id
;\4: offset of the target map relative to the current map
; (x offset for east/west, y offset for north/south)
; Calculate tile offsets for source (current) and target maps
_src = 0
_tgt = (\4) + 3
if _tgt < 2
_src = -_tgt
_tgt = 0
endc
if "\1" == "north"
_blk = \3_WIDTH * (\3_HEIGHT - 3) + _src
_map = _tgt
_win = (\3_WIDTH + 6) * \3_HEIGHT + 1
_y = \3_HEIGHT * 2 - 1
_x = (\4) * -2
_len = CURRENT_MAP_WIDTH + 3 - (\4)
if _len > \3_WIDTH
_len = \3_WIDTH
endc
elif "\1" == "south"
_blk = _src
_map = (CURRENT_MAP_WIDTH + 6) * (CURRENT_MAP_HEIGHT + 3) + _tgt
_win = \3_WIDTH + 7
_y = 0
_x = (\4) * -2
_len = CURRENT_MAP_WIDTH + 3 - (\4)
if _len > \3_WIDTH
_len = \3_WIDTH
endc
elif "\1" == "west"
_blk = (\3_WIDTH * _src) + \3_WIDTH - 3
_map = (CURRENT_MAP_WIDTH + 6) * _tgt
_win = (\3_WIDTH + 6) * 2 - 6
_y = (\4) * -2
_x = \3_WIDTH * 2 - 1
_len = CURRENT_MAP_HEIGHT + 3 - (\4)
if _len > \3_HEIGHT
_len = \3_HEIGHT
endc
elif "\1" == "east"
_blk = (\3_WIDTH * _src)
_map = (CURRENT_MAP_WIDTH + 6) * _tgt + CURRENT_MAP_WIDTH + 3
_win = \3_WIDTH + 7
_y = (\4) * -2
_x = 0
_len = CURRENT_MAP_HEIGHT + 3 - (\4)
if _len > \3_HEIGHT
_len = \3_HEIGHT
endc
else
fail "Invalid direction for 'connection'."
endc
db \3
dw \2_Blocks + _blk
dw wOverworldMap + _map
db _len - _src
db \3_WIDTH
db _y, _x
dw wOverworldMap + _win
ENDM
tmlearn: MACRO
x = 0
REPT _NARG
IF \1 != 0
x = x | (1 << ((\1 - 1) % 8))
ENDC
SHIFT
ENDR
db x
ENDM
|