text.a65 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. .text
  2. #include "memmap.i65"
  3. hiprint:
  4. sep #$20 : .as
  5. lda print_count
  6. sta print_count_tmp
  7. rep #$30 : .xl : .al
  8. stz print_done
  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. ora #$20
  63. sta @$2180
  64. lda @print_done
  65. inc
  66. sta @print_done
  67. inx
  68. lda !0,x
  69. beq print_loop2
  70. inx
  71. lda !0,x
  72. beq print_loop2
  73. lda @print_count_tmp
  74. dec
  75. dec
  76. sta @print_count_tmp
  77. beq print_loop2
  78. bmi print_loop2
  79. bra print_loop_inner
  80. print_loop2
  81. lda @print_count
  82. dec
  83. sta @print_count_tmp
  84. lda #$00
  85. pha
  86. plb
  87. rep #$30 : .al : .xl
  88. ply ; source addr
  89. iny
  90. pla ; offset from tilemap start
  91. plx ; other tilemap addr
  92. stx !print_temp
  93. clc
  94. adc !print_temp ; tilemap+offset
  95. sta $2181
  96. tyx
  97. sep #$20 : .as
  98. lda print_bank
  99. pha
  100. plb
  101. print_loop2_inner
  102. lda !0,x
  103. asl
  104. sta @$2180
  105. lda @print_pal
  106. asl
  107. asl
  108. adc #$00
  109. ora #$20
  110. sta @$2180
  111. lda @print_done
  112. inc
  113. sta @print_done
  114. inx
  115. lda !0,x
  116. beq print_end
  117. inx
  118. lda !0,x
  119. beq print_end
  120. lda @print_count_tmp
  121. dec
  122. dec
  123. sta @print_count_tmp
  124. beq print_end
  125. bmi print_end
  126. bra print_loop2_inner
  127. print_end
  128. lda #$00
  129. pha
  130. plb
  131. rts
  132. loprint:
  133. rep #$30 : .xl : .al
  134. lda !print_x
  135. and #$00ff
  136. asl ;double the offset for WRAM addressing
  137. clc
  138. adc #!BG2_TILE_BUF
  139. sta !print_temp
  140. lda !print_y
  141. and #$00ff
  142. asl
  143. asl
  144. asl
  145. asl
  146. asl
  147. asl ;double the offset for WRAM addressing
  148. clc
  149. adc !print_temp
  150. ; we need to transfer to WRAM and from there to VRAM via DMA during VBLANK
  151. ; because VRAM can only be accessed during VBLANK and forced blanking.
  152. sta $2181
  153. sep #$20 : .as
  154. lda #$7f ;we really only need bit 0. full bank given for clarity
  155. sta $2183
  156. ldx !print_src
  157. lda !print_bank
  158. pha
  159. plb
  160. loprint_loop_inner
  161. lda !0,x
  162. beq loprint_end
  163. sta @$2180
  164. lda #$00
  165. adc #$00
  166. ora #$20
  167. sta @$2180
  168. inx
  169. bra loprint_loop_inner
  170. loprint_end
  171. lda #$00
  172. pha
  173. plb
  174. rts
  175. backup_screen:
  176. ; MVN: X=source, Y=dest, A=count
  177. ; imm1=srcbk, imm2=dstbk
  178. phb
  179. php
  180. rep #$30 : .xl : .al
  181. ldx #!BG1_TILE_BUF+64*9
  182. ldy #!BG1_TILE_BAK+64*9
  183. lda @textdmasize
  184. mvn ^BG1_TILE_BUF, ^BG1_TILE_BAK
  185. ldx #!BG2_TILE_BUF+64*9
  186. ldy #!BG2_TILE_BAK+64*9
  187. lda @textdmasize
  188. mvn ^BG2_TILE_BUF, ^BG2_TILE_BAK
  189. plp
  190. plb
  191. rts
  192. restore_screen:
  193. ; MVN: X=source, Y=dest, A=count
  194. ; imm1=srcbk, imm2=dstbk
  195. phb
  196. php
  197. rep #$30 : .xl : .al
  198. ldx #!BG1_TILE_BAK+64*9
  199. ldy #!BG1_TILE_BUF+64*9
  200. lda @textdmasize
  201. mvn ^BG1_TILE_BAK, ^BG1_TILE_BUF
  202. ldx #!BG2_TILE_BAK+64*9
  203. ldy #!BG2_TILE_BUF+64*9
  204. lda @textdmasize
  205. mvn ^BG2_TILE_BAK, ^BG2_TILE_BUF
  206. plp
  207. plb
  208. rts
  209. draw_window:
  210. phb
  211. php
  212. sep #$20 : .as
  213. ; draw upper border
  214. ; upper left corner
  215. lda @window_nw
  216. sta stringbuf
  217. ldx #!stringbuf
  218. inx
  219. lda window_w
  220. sta window_tmp
  221. stz window_tmp+1
  222. ldy window_tmp
  223. dey
  224. dey
  225. ; upper edge
  226. -
  227. lda @window_nh
  228. sta !0,x
  229. inx
  230. dey
  231. cpy #$0000
  232. bne -
  233. ; upper right corner
  234. lda @window_ne
  235. sta !0,x
  236. ; print to text buffer
  237. lda #$01
  238. sta print_pal
  239. lda window_x
  240. sta print_x
  241. lda window_y
  242. sta print_y
  243. lda #^stringbuf
  244. sta print_bank
  245. ldx #!stringbuf
  246. stx print_src
  247. lda window_w
  248. sta print_count
  249. jsr hiprint
  250. ; print window title
  251. inc print_x
  252. inc print_x
  253. lda window_tbank
  254. sta print_bank
  255. ldx window_taddr
  256. stx print_src
  257. jsr hiprint
  258. dec print_x
  259. dec print_x
  260. ; draw left+right borders + space inside window
  261. lda #^stringbuf
  262. sta print_bank
  263. ldx #!stringbuf
  264. stx print_src
  265. lda @window_wv
  266. sta stringbuf
  267. ldx #!stringbuf
  268. inx
  269. lda window_w
  270. sta window_tmp
  271. stz window_tmp+1
  272. ldy window_tmp
  273. dey
  274. dey
  275. -
  276. lda @space64
  277. sta !0,x
  278. inx
  279. dey
  280. cpy #$0000
  281. bne -
  282. lda @window_ev
  283. sta !0,x
  284. ; print to text buffer multiple times
  285. lda window_h
  286. sta window_tmp
  287. stz window_tmp+1
  288. ldy window_tmp
  289. dey
  290. dey
  291. -
  292. inc print_y
  293. phy
  294. jsr hiprint
  295. ply
  296. dey
  297. cpy #$0000
  298. bne -
  299. ; draw lower window border
  300. ; lower left corner
  301. lda @window_sw
  302. sta stringbuf
  303. ldx #!stringbuf
  304. inx
  305. lda window_w
  306. sta window_tmp
  307. stz window_tmp+1
  308. ldy window_tmp
  309. dey
  310. dey
  311. ; lower edge
  312. -
  313. lda @window_sh
  314. sta !0,x
  315. inx
  316. dey
  317. cpy #$0000
  318. bne -
  319. ; lower right corner
  320. lda @window_se
  321. sta !0,x
  322. ; print to text buffer
  323. inc print_y
  324. jsr hiprint
  325. plp
  326. plb
  327. rts