asm_macros.asm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. lb: MACRO ; r, hi, lo
  2. ld \1, (\2) << 8 + ((\3) & $ff)
  3. ENDM
  4. homecall: MACRO
  5. ld a, [H_LOADEDROMBANK]
  6. push af
  7. ld a, BANK(\1)
  8. ld [H_LOADEDROMBANK], a
  9. ld [MBC1RomBank], a
  10. call \1
  11. pop af
  12. ld [H_LOADEDROMBANK], a
  13. ld [MBC1RomBank], a
  14. ENDM
  15. farcall EQUS "callba"
  16. callba: MACRO
  17. ld b, BANK(\1)
  18. ld hl, \1
  19. call Bankswitch
  20. ENDM
  21. callab: MACRO
  22. ld hl, \1
  23. ld b, BANK(\1)
  24. call Bankswitch
  25. ENDM
  26. jpba: MACRO
  27. ld b, BANK(\1)
  28. ld hl, \1
  29. jp Bankswitch
  30. ENDM
  31. jpab: MACRO
  32. ld hl, \1
  33. ld b, BANK(\1)
  34. jp Bankswitch
  35. ENDM
  36. validateCoords: MACRO
  37. IF \1 >= SCREEN_WIDTH
  38. fail "x coord out of range"
  39. ENDC
  40. IF \2 >= SCREEN_HEIGHT
  41. fail "y coord out of range"
  42. ENDC
  43. ENDM
  44. ;\1 = r
  45. ;\2 = X
  46. ;\3 = Y
  47. ;\4 = which tilemap (optional)
  48. coord: MACRO
  49. validateCoords \2, \3
  50. IF _NARG >= 4
  51. ld \1, \4 + SCREEN_WIDTH * \3 + \2
  52. ELSE
  53. ld \1, wTileMap + SCREEN_WIDTH * \3 + \2
  54. ENDC
  55. ENDM
  56. ;\1 = X
  57. ;\2 = Y
  58. ;\3 = which tilemap (optional)
  59. aCoord: MACRO
  60. validateCoords \1, \2
  61. IF _NARG >= 3
  62. ld a, [\3 + SCREEN_WIDTH * \2 + \1]
  63. ELSE
  64. ld a, [wTileMap + SCREEN_WIDTH * \2 + \1]
  65. ENDC
  66. ENDM
  67. ;\1 = X
  68. ;\2 = Y
  69. ;\3 = which tilemap (optional)
  70. Coorda: MACRO
  71. validateCoords \1, \2
  72. IF _NARG >= 3
  73. ld [\3 + SCREEN_WIDTH * \2 + \1], a
  74. ELSE
  75. ld [wTileMap + SCREEN_WIDTH * \2 + \1], a
  76. ENDC
  77. ENDM
  78. ;\1 = X
  79. ;\2 = Y
  80. ;\3 = which tilemap (optional)
  81. dwCoord: MACRO
  82. validateCoords \1, \2
  83. IF _NARG >= 3
  84. dw \3 + SCREEN_WIDTH * \2 + \1
  85. ELSE
  86. dw wTileMap + SCREEN_WIDTH * \2 + \1
  87. ENDC
  88. ENDM
  89. ;\1 = r
  90. ;\2 = X
  91. ;\3 = Y
  92. ;\4 = map width
  93. overworldMapCoord: MACRO
  94. ld \1, wOverworldMap + ((\2) + 3) + (((\3) + 3) * ((\4) + (3 * 2)))
  95. ENDM
  96. ; macro for two nibbles
  97. dn: MACRO
  98. db (\1 << 4 | \2)
  99. ENDM
  100. ; macro for putting a byte then a word
  101. dbw: MACRO
  102. db \1
  103. dw \2
  104. ENDM
  105. dba: MACRO
  106. dbw BANK(\1), \1
  107. ENDM
  108. dwb: MACRO
  109. dw \1
  110. db \2
  111. ENDM
  112. dab: MACRO
  113. dwb \1, BANK(\1)
  114. ENDM
  115. dbbw: MACRO
  116. db \1, \2
  117. dw \3
  118. ENDM
  119. ; Predef macro.
  120. predef_const: MACRO
  121. const \1PredefID
  122. ENDM
  123. add_predef: MACRO
  124. \1Predef::
  125. db BANK(\1)
  126. dw \1
  127. ENDM
  128. predef_id: MACRO
  129. ld a, (\1Predef - PredefPointers) / 3
  130. ENDM
  131. predef: MACRO
  132. predef_id \1
  133. call Predef
  134. ENDM
  135. predef_jump: MACRO
  136. predef_id \1
  137. jp Predef
  138. ENDM
  139. tx_pre_const: MACRO
  140. const \1_id
  141. ENDM
  142. add_tx_pre: MACRO
  143. \1_id:: dw \1
  144. ENDM
  145. db_tx_pre: MACRO
  146. db (\1_id - TextPredefs) / 2 + 1
  147. ENDM
  148. tx_pre_id: MACRO
  149. ld a, (\1_id - TextPredefs) / 2 + 1
  150. ENDM
  151. tx_pre: MACRO
  152. tx_pre_id \1
  153. call PrintPredefTextID
  154. ENDM
  155. tx_pre_jump: MACRO
  156. tx_pre_id \1
  157. jp PrintPredefTextID
  158. ENDM