copy2.asm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. FarCopyData2::
  2. ; Identical to FarCopyData, but uses hROMBankTemp
  3. ; as temp space instead of wBuffer.
  4. ld [hROMBankTemp], a
  5. ld a, [H_LOADEDROMBANK]
  6. push af
  7. ld a, [hROMBankTemp]
  8. ld [H_LOADEDROMBANK], a
  9. ld [MBC1RomBank], a
  10. call CopyData
  11. pop af
  12. ld [H_LOADEDROMBANK], a
  13. ld [MBC1RomBank], a
  14. ret
  15. FarCopyData3::
  16. ; Copy bc bytes from a:de to hl.
  17. ld [hROMBankTemp], a
  18. ld a, [H_LOADEDROMBANK]
  19. push af
  20. ld a, [hROMBankTemp]
  21. ld [H_LOADEDROMBANK], a
  22. ld [MBC1RomBank], a
  23. push hl
  24. push de
  25. push de
  26. ld d, h
  27. ld e, l
  28. pop hl
  29. call CopyData
  30. pop de
  31. pop hl
  32. pop af
  33. ld [H_LOADEDROMBANK], a
  34. ld [MBC1RomBank], a
  35. ret
  36. FarCopyDataDouble::
  37. ; Expand bc bytes of 1bpp image data
  38. ; from a:hl to 2bpp data at de.
  39. ld [hROMBankTemp], a
  40. ld a, [H_LOADEDROMBANK]
  41. push af
  42. ld a, [hROMBankTemp]
  43. ld [H_LOADEDROMBANK], a
  44. ld [MBC1RomBank], a
  45. .loop
  46. ld a, [hli]
  47. ld [de], a
  48. inc de
  49. ld [de], a
  50. inc de
  51. dec bc
  52. ld a, c
  53. or b
  54. jr nz, .loop
  55. pop af
  56. ld [H_LOADEDROMBANK], a
  57. ld [MBC1RomBank], a
  58. ret
  59. CopyVideoData::
  60. ; Wait for the next VBlank, then copy c 2bpp
  61. ; tiles from b:de to hl, 8 tiles at a time.
  62. ; This takes c/8 frames.
  63. ld a, [H_AUTOBGTRANSFERENABLED]
  64. push af
  65. xor a ; disable auto-transfer while copying
  66. ld [H_AUTOBGTRANSFERENABLED], a
  67. ld a, [H_LOADEDROMBANK]
  68. ld [hROMBankTemp], a
  69. ld a, b
  70. ld [H_LOADEDROMBANK], a
  71. ld [MBC1RomBank], a
  72. ld a, e
  73. ld [H_VBCOPYSRC], a
  74. ld a, d
  75. ld [H_VBCOPYSRC + 1], a
  76. ld a, l
  77. ld [H_VBCOPYDEST], a
  78. ld a, h
  79. ld [H_VBCOPYDEST + 1], a
  80. .loop
  81. ld a, c
  82. cp 8
  83. jr nc, .keepgoing
  84. .done
  85. ld [H_VBCOPYSIZE], a
  86. call DelayFrame
  87. ld a, [hROMBankTemp]
  88. ld [H_LOADEDROMBANK], a
  89. ld [MBC1RomBank], a
  90. pop af
  91. ld [H_AUTOBGTRANSFERENABLED], a
  92. ret
  93. .keepgoing
  94. ld a, 8
  95. ld [H_VBCOPYSIZE], a
  96. call DelayFrame
  97. ld a, c
  98. sub 8
  99. ld c, a
  100. jr .loop
  101. CopyVideoDataDouble::
  102. ; Wait for the next VBlank, then copy c 1bpp
  103. ; tiles from b:de to hl, 8 tiles at a time.
  104. ; This takes c/8 frames.
  105. ld a, [H_AUTOBGTRANSFERENABLED]
  106. push af
  107. xor a ; disable auto-transfer while copying
  108. ld [H_AUTOBGTRANSFERENABLED], a
  109. ld a, [H_LOADEDROMBANK]
  110. ld [hROMBankTemp], a
  111. ld a, b
  112. ld [H_LOADEDROMBANK], a
  113. ld [MBC1RomBank], a
  114. ld a, e
  115. ld [H_VBCOPYDOUBLESRC], a
  116. ld a, d
  117. ld [H_VBCOPYDOUBLESRC + 1], a
  118. ld a, l
  119. ld [H_VBCOPYDOUBLEDEST], a
  120. ld a, h
  121. ld [H_VBCOPYDOUBLEDEST + 1], a
  122. .loop
  123. ld a, c
  124. cp 8
  125. jr nc, .keepgoing
  126. .done
  127. ld [H_VBCOPYDOUBLESIZE], a
  128. call DelayFrame
  129. ld a, [hROMBankTemp]
  130. ld [H_LOADEDROMBANK], a
  131. ld [MBC1RomBank], a
  132. pop af
  133. ld [H_AUTOBGTRANSFERENABLED], a
  134. ret
  135. .keepgoing
  136. ld a, 8
  137. ld [H_VBCOPYDOUBLESIZE], a
  138. call DelayFrame
  139. ld a, c
  140. sub 8
  141. ld c, a
  142. jr .loop
  143. ClearScreenArea::
  144. ; Clear tilemap area cxb at hl.
  145. ld a, " " ; blank tile
  146. ld de, 20 ; screen width
  147. .y
  148. push hl
  149. push bc
  150. .x
  151. ld [hli], a
  152. dec c
  153. jr nz, .x
  154. pop bc
  155. pop hl
  156. add hl, de
  157. dec b
  158. jr nz, .y
  159. ret
  160. CopyScreenTileBufferToVRAM::
  161. ; Copy wTileMap to the BG Map starting at b * $100.
  162. ; This is done in thirds of 6 rows, so it takes 3 frames.
  163. ld c, 6
  164. ld hl, $600 * 0
  165. coord de, 0, 6 * 0
  166. call .setup
  167. call DelayFrame
  168. ld hl, $600 * 1
  169. coord de, 0, 6 * 1
  170. call .setup
  171. call DelayFrame
  172. ld hl, $600 * 2
  173. coord de, 0, 6 * 2
  174. call .setup
  175. jp DelayFrame
  176. .setup
  177. ld a, d
  178. ld [H_VBCOPYBGSRC+1], a
  179. call GetRowColAddressBgMap
  180. ld a, l
  181. ld [H_VBCOPYBGDEST], a
  182. ld a, h
  183. ld [H_VBCOPYBGDEST+1], a
  184. ld a, c
  185. ld [H_VBCOPYBGNUMROWS], a
  186. ld a, e
  187. ld [H_VBCOPYBGSRC], a
  188. ret
  189. ClearScreen::
  190. ; Clear wTileMap, then wait
  191. ; for the bg map to update.
  192. ld bc, 20 * 18
  193. inc b
  194. coord hl, 0, 0
  195. ld a, " "
  196. .loop
  197. ld [hli], a
  198. dec c
  199. jr nz, .loop
  200. dec b
  201. jr nz, .loop
  202. jp Delay3