data_macros.asm 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. ; Constant enumeration is useful for monsters, items, moves, etc.
  2. const_def: MACRO
  3. const_value = 0
  4. ENDM
  5. const: MACRO
  6. \1 EQU const_value
  7. const_value = const_value + 1
  8. ENDM
  9. ; data format macros
  10. percent EQUS "* $ff / 100"
  11. bcd2: MACRO
  12. dn ((\1) / 1000) % 10, ((\1) / 100) % 10
  13. dn ((\1) / 10) % 10, (\1) % 10
  14. ENDM
  15. bcd3: MACRO
  16. dn ((\1) / 100000) % 10, ((\1) / 10000) % 10
  17. dn ((\1) / 1000) % 10, ((\1) / 100) % 10
  18. dn ((\1) / 10) % 10, (\1) % 10
  19. ENDM
  20. coins equs "bcd2"
  21. money equs "bcd3"
  22. ;\1 = Map Width
  23. ;\2 = Rows above (Y-blocks)
  24. ;\3 = X movement (X-blocks)
  25. EVENT_DISP: MACRO
  26. dw (wOverworldMap + 7 + (\1) + ((\1) + 6) * ((\2) >> 1) + ((\3) >> 1)) ; Ev.Disp
  27. db \2,\3 ;Y,X
  28. ENDM
  29. FLYWARP_DATA: MACRO
  30. EVENT_DISP \1,\2,\3
  31. db ((\2) & $01) ;sub-block Y
  32. db ((\3) & $01) ;sub-block X
  33. ENDM
  34. ; external map entry macro
  35. EMAP: MACRO ; emap x-coordinate,y-coordinate,textpointer
  36. ; the appearance of towns and routes in the town map, indexed by map id
  37. ; nybble: y-coordinate
  38. ; nybble: x-coordinate
  39. ; word : pointer to map name
  40. dn \2, \1
  41. dw \3
  42. ENDM
  43. ; internal map entry macro
  44. IMAP: MACRO ; imap mapid_less_than,x-coordinate,y-coordinate,textpointer
  45. ; the appearance of buildings and dungeons in the town map
  46. ; byte : maximum map id subject to this rule
  47. ; nybble: y-coordinate
  48. ; nybble: x-coordinate
  49. ; word : pointer to map name
  50. db \1 + 1
  51. dn \3, \2
  52. dw \4
  53. ENDM
  54. ; tilesets' headers macro
  55. tileset: MACRO
  56. db BANK(\2) ; BANK(GFX)
  57. dw \1, \2, \3 ; Block, GFX, Coll
  58. db \4, \5, \6 ; counter tiles
  59. db \7 ; grass tile
  60. db \8 ; permission (indoor, cave, outdoor)
  61. ENDM
  62. INDOOR EQU 0
  63. CAVE EQU 1
  64. OUTDOOR EQU 2
  65. RGB: MACRO
  66. dw (\3 << 10 | \2 << 5 | \1)
  67. ENDM
  68. WALK EQU $FE
  69. STAY EQU $FF
  70. DOWN EQU $D0
  71. UP EQU $D1
  72. LEFT EQU $D2
  73. RIGHT EQU $D3
  74. NONE EQU $FF
  75. ;\1 sprite id
  76. ;\2 x position
  77. ;\3 y position
  78. ;\4 movement (WALK/STAY)
  79. ;\5 range or direction
  80. ;\6 text id
  81. ;\7 items only: item id
  82. ;\7 trainers only: trainer class/pokemon id
  83. ;\8 trainers only: trainer number/pokemon level
  84. object: MACRO
  85. db \1
  86. db \3 + 4
  87. db \2 + 4
  88. db \4
  89. db \5
  90. IF (_NARG > 7)
  91. db TRAINER | \6
  92. db \7
  93. db \8
  94. ELSE
  95. IF (_NARG > 6)
  96. db ITEM | \6
  97. db \7
  98. ELSE
  99. db \6
  100. ENDC
  101. ENDC
  102. ENDM
  103. ;\1 x position
  104. ;\2 y position
  105. ;\3 destination warp id
  106. ;\4 destination map (-1 = wLastMap)
  107. warp: MACRO
  108. db \2, \1, \3, \4
  109. ENDM
  110. ;\1 x position
  111. ;\2 y position
  112. ;\3 sign id
  113. sign: MACRO
  114. db \2, \1, \3
  115. ENDM
  116. ;\1 x position
  117. ;\2 y position
  118. ;\3 map width
  119. warp_to: MACRO
  120. EVENT_DISP \3, \2, \1
  121. ENDM
  122. ;\1 (byte) = current map id
  123. ;\2 (byte) = connected map id
  124. ;\3 (byte) = x movement of connection strip
  125. ;\4 (byte) = connection strip offset
  126. ;\5 (word) = connected map blocks pointer
  127. NORTH_MAP_CONNECTION: MACRO
  128. db \2 ; map id
  129. dw \5 + (\2_WIDTH * (\2_HEIGHT - 3)) + \4; "Connection Strip" location
  130. dw wOverworldMap + 3 + \3 ; current map position
  131. IF (\1_WIDTH < \2_WIDTH)
  132. db \1_WIDTH - \3 + 3 ; width of connection strip
  133. ELSE
  134. db \2_WIDTH - \4 ; width of connection strip
  135. ENDC
  136. db \2_WIDTH ; map width
  137. db (\2_HEIGHT * 2) - 1 ; y alignment (y coordinate of player when entering map)
  138. db (\3 - \4) * -2 ; x alignment (x coordinate of player when entering map)
  139. dw wOverworldMap + 1 + (\2_HEIGHT * (\2_WIDTH + 6)) ; window (position of the upper left block after entering the map)
  140. ENDM
  141. ;\1 (byte) = current map id
  142. ;\2 (byte) = connected map id
  143. ;\3 (byte) = x movement of connection strip
  144. ;\4 (byte) = connection strip offset
  145. ;\5 (word) = connected map blocks pointer
  146. ;\6 (flag) = add 3 to width of connection strip (why?)
  147. SOUTH_MAP_CONNECTION: MACRO
  148. db \2 ; map id
  149. dw \5 + \4 ; "Connection Strip" location
  150. dw wOverworldMap + 3 + (\1_HEIGHT + 3) * (\1_WIDTH + 6) + \3 ; current map position
  151. IF (\1_WIDTH < \2_WIDTH)
  152. IF (_NARG > 5)
  153. db \1_WIDTH - \3 + 3 ; width of connection strip
  154. ELSE
  155. db \1_WIDTH - \3 ; width of connection strip
  156. ENDC
  157. ELSE
  158. db \2_WIDTH - \4 ; width of connection strip
  159. ENDC
  160. db \2_WIDTH ; map width
  161. db 0 ; y alignment (y coordinate of player when entering map)
  162. db (\3 - \4) * -2 ; x alignment (x coordinate of player when entering map)
  163. dw wOverworldMap + 7 + \2_WIDTH ; window (position of the upper left block after entering the map)
  164. ENDM
  165. ;\1 (byte) = current map id
  166. ;\2 (byte) = connected map id
  167. ;\3 (byte) = y movement of connection strip
  168. ;\4 (byte) = connection strip offset
  169. ;\5 (word) = connected map blocks pointer
  170. WEST_MAP_CONNECTION: MACRO
  171. db \2 ; map id
  172. dw \5 + (\2_WIDTH * \4) + \2_WIDTH - 3 ; "Connection Strip" location
  173. dw wOverworldMap + (\1_WIDTH + 6) * (\3 + 3) ; current map position
  174. IF (\1_HEIGHT < \2_HEIGHT)
  175. db \1_HEIGHT - \3 + 3 ; height of connection strip
  176. ELSE
  177. db \2_HEIGHT - \4 ; height of connection strip
  178. ENDC
  179. db \2_WIDTH ; map width
  180. db (\3 - \4) * -2 ; y alignment
  181. db (\2_WIDTH * 2) - 1 ; x alignment
  182. dw wOverworldMap + 6 + (2 * \2_WIDTH) ; window (position of the upper left block after entering the map)
  183. ENDM
  184. ;\1 (byte) = current map id
  185. ;\2 (byte) = connected map id
  186. ;\3 (byte) = y movement of connection strip
  187. ;\4 (byte) = connection strip offset
  188. ;\5 (word) = connected map blocks pointer
  189. ;\6 (flag) = add 3 to height of connection strip (why?)
  190. EAST_MAP_CONNECTION: MACRO
  191. db \2 ; map id
  192. dw \5 + (\2_WIDTH * \4) ; "Connection Strip" location
  193. dw wOverworldMap - 3 + (\1_WIDTH + 6) * (\3 + 4) ; current map position
  194. IF (\1_HEIGHT < \2_HEIGHT)
  195. IF (_NARG > 5)
  196. db \1_HEIGHT - \3 + 3 ; height of connection strip
  197. ELSE
  198. db \1_HEIGHT - \3 ; height of connection strip
  199. ENDC
  200. ELSE
  201. db \2_HEIGHT - \4 ; height of connection strip
  202. ENDC
  203. db \2_WIDTH ; map width
  204. db (\3 - \4) * -2 ; y alignment
  205. db 0 ; x alignment
  206. dw wOverworldMap + 7 + \2_WIDTH ; window (position of the upper left block after entering the map)
  207. ENDM
  208. tmlearn: MACRO
  209. x = 0
  210. REPT _NARG
  211. IF \1 != 0
  212. x = x | (1 << ((\1 - 1) % 8))
  213. ENDC
  214. SHIFT
  215. ENDR
  216. db x
  217. ENDM