text.a65 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. .text
  2. #include "memmap.i65"
  3. hiprint:
  4. sep #$20 : .as
  5. lda print_count
  6. sta print_count_tmp
  7. stz print_done
  8. rep #$30 : .xl : .al
  9. lda print_x
  10. and #$00ff
  11. lsr
  12. bcs print_bg1
  13. ldx #!BG1_TILE_BUF ; for 2nd loop
  14. phx
  15. ldx #!BG2_TILE_BUF ; for 1st loop
  16. phx
  17. bra print_bg_cont
  18. print_bg1
  19. ldx #!BG2_TILE_BUF+2 ; for 2nd loop
  20. phx
  21. ldx #!BG1_TILE_BUF ; for 1st loop da whoop
  22. phx
  23. bra print_bg_cont
  24. print_bg_cont
  25. sta !print_temp
  26. lda !print_y
  27. and #$00ff
  28. asl
  29. asl
  30. asl
  31. asl
  32. asl
  33. clc
  34. adc !print_temp
  35. asl ; double the offset for WRAM addressing
  36. tay ; zonday
  37. plx
  38. phy ; offset from tilemap start
  39. stx !print_temp
  40. clc
  41. adc !print_temp
  42. ; we need to transfer to WRAM and from there to VRAM via DMA during VBLANK
  43. ; because VRAM can only be accessed during VBLANK and forced blanking.
  44. sta $2181
  45. sep #$20 : .as
  46. lda #$7f ;we really only need bit 0. full bank given for clarity
  47. sta $2183
  48. print_loop
  49. ldx !print_src
  50. lda !print_bank
  51. pha
  52. plb
  53. phx ; source addr
  54. print_loop_inner
  55. lda !0,x
  56. asl
  57. sta @$2180
  58. lda @print_pal
  59. asl
  60. asl
  61. adc #$00
  62. sta @$2180
  63. lda @print_done
  64. inc
  65. sta @print_done
  66. inx
  67. lda !0,x
  68. beq print_loop2
  69. inx
  70. lda !0,x
  71. beq print_loop2
  72. lda @print_count_tmp
  73. dec
  74. dec
  75. sta @print_count_tmp
  76. beq print_loop2
  77. bmi print_loop2
  78. bra print_loop_inner
  79. print_loop2
  80. lda @print_count
  81. dec
  82. sta @print_count_tmp
  83. lda #$00
  84. pha
  85. plb
  86. rep #$30 : .al : .xl
  87. ply ; source addr
  88. iny
  89. pla ; offset from tilemap start
  90. plx ; other tilemap addr
  91. stx !print_temp
  92. clc
  93. adc !print_temp ; tilemap+offset
  94. sta $2181
  95. tyx
  96. sep #$20 : .as
  97. lda print_bank
  98. pha
  99. plb
  100. print_loop2_inner
  101. lda !0,x
  102. asl
  103. sta @$2180
  104. lda @print_pal
  105. asl
  106. asl
  107. adc #$00
  108. sta @$2180
  109. lda @print_done
  110. inc
  111. sta @print_done
  112. inx
  113. lda !0,x
  114. beq print_end
  115. inx
  116. lda !0,x
  117. beq print_end
  118. lda @print_count_tmp
  119. dec
  120. dec
  121. sta @print_count_tmp
  122. beq print_end
  123. bmi print_end
  124. bra print_loop2_inner
  125. print_end
  126. lda #$00
  127. pha
  128. plb
  129. rts
  130. loprint:
  131. rep #$30 : .xl : .al
  132. lda !print_x
  133. and #$00ff
  134. asl ;double the offset for WRAM addressing
  135. clc
  136. adc #!BG2_TILE_BUF
  137. sta !print_temp
  138. lda !print_y
  139. and #$00ff
  140. asl
  141. asl
  142. asl
  143. asl
  144. asl
  145. asl ;double the offset for WRAM addressing
  146. clc
  147. adc !print_temp
  148. ; we need to transfer to WRAM and from there to VRAM via DMA during VBLANK
  149. ; because VRAM can only be accessed during VBLANK and forced blanking.
  150. sta $2181
  151. sep #$20 : .as
  152. lda #$7f ;we really only need bit 0. full bank given for clarity
  153. sta $2183
  154. ldx !print_src
  155. lda !print_bank
  156. pha
  157. plb
  158. loprint_loop_inner
  159. lda !0,x
  160. beq loprint_end
  161. sta @$2180
  162. lda #$00
  163. adc #$00
  164. ora #$20
  165. sta @$2180
  166. inx
  167. bra loprint_loop_inner
  168. loprint_end
  169. lda #$00
  170. pha
  171. plb
  172. rts