text.a65 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. .text
  2. #include "memmap.i65"
  3. .byt "===HIPRINT==="
  4. ; input:
  5. ; print_count
  6. ; print_x
  7. ; print_y
  8. ; print_src
  9. ; print_bank
  10. ; print_pal
  11. ;
  12. ; output:
  13. ; print_done (# of chars printed)
  14. ; print_over (char after print_count)
  15. hiprint:
  16. php
  17. sep #$20 : .as
  18. rep #$10 : .xl
  19. ldx print_src
  20. stx print_ptr
  21. lda print_bank
  22. sta print_ptr+2
  23. phb
  24. lda #$7e
  25. pha
  26. plb
  27. rep #$30 : .al : .xl
  28. lda print_pal
  29. and #$00ff
  30. xba
  31. asl
  32. asl
  33. ora #$2000
  34. sta print_temp
  35. lda print_count
  36. and #$00ff
  37. beq hiprint_end
  38. tay
  39. lda print_x
  40. and #$00ff
  41. sta print_x
  42. lda print_y
  43. and #$00ff
  44. asl
  45. asl
  46. asl
  47. asl
  48. asl
  49. asl
  50. clc
  51. adc print_x
  52. and #$fffe
  53. tax
  54. lda print_x
  55. lsr
  56. bcs hiprint_bg1
  57. hiprint_bg2
  58. lda [print_ptr]
  59. and #$00ff
  60. beq hiprint_end
  61. inc print_ptr
  62. asl
  63. ora print_temp
  64. sta !BG2_TILE_BUF, x
  65. dey
  66. beq hiprint_end
  67. hiprint_bg1
  68. lda [print_ptr]
  69. and #$00ff
  70. beq hiprint_end
  71. inc print_ptr
  72. asl
  73. ora print_temp
  74. sta !BG1_TILE_BUF, x
  75. inx
  76. inx
  77. dey
  78. beq hiprint_end
  79. bra hiprint_bg2
  80. hiprint_end
  81. plb
  82. sep #$20 : .as
  83. lda [print_ptr]
  84. sta print_over
  85. tya
  86. sec
  87. sbc print_count
  88. eor #$ff
  89. inc
  90. sta print_done
  91. plp
  92. rts
  93. loprint:
  94. rep #$30 : .xl : .al
  95. lda !print_x
  96. and #$00ff
  97. asl ;double the offset for WRAM addressing
  98. clc
  99. adc #!BG2_TILE_BUF
  100. sta !print_temp
  101. lda !print_y
  102. and #$00ff
  103. asl
  104. asl
  105. asl
  106. asl
  107. asl
  108. asl ;double the offset for WRAM addressing
  109. clc
  110. adc !print_temp
  111. ; we need to transfer to WRAM and from there to VRAM via DMA during VBLANK
  112. ; because VRAM can only be accessed during VBLANK and forced blanking.
  113. sta $2181
  114. sep #$20 : .as
  115. lda #$7f ;we really only need bit 0. full bank given for clarity
  116. sta $2183
  117. ldx !print_src
  118. lda !print_bank
  119. pha
  120. plb
  121. loprint_loop_inner
  122. lda !0,x
  123. beq loprint_end
  124. sta @$2180
  125. lda #$00
  126. adc #$00
  127. ora #$20
  128. sta @$2180
  129. inx
  130. bra loprint_loop_inner
  131. loprint_end
  132. lda #$00
  133. pha
  134. plb
  135. rts
  136. backup_screen:
  137. ; MVN: X=source, Y=dest, A=count
  138. ; imm1=srcbk, imm2=dstbk
  139. phb
  140. php
  141. rep #$30 : .xl : .al
  142. ldx #!BG1_TILE_BUF+64*9
  143. ldy #!BG1_TILE_BAK+64*9
  144. lda @textdmasize
  145. mvn ^BG1_TILE_BUF, ^BG1_TILE_BAK
  146. ldx #!BG2_TILE_BUF+64*9
  147. ldy #!BG2_TILE_BAK+64*9
  148. lda @textdmasize
  149. mvn ^BG2_TILE_BUF, ^BG2_TILE_BAK
  150. plp
  151. plb
  152. rts
  153. restore_screen:
  154. ; MVN: X=source, Y=dest, A=count
  155. ; imm1=srcbk, imm2=dstbk
  156. phb
  157. php
  158. rep #$30 : .xl : .al
  159. ldx #!BG1_TILE_BAK+64*9
  160. ldy #!BG1_TILE_BUF+64*9
  161. lda @textdmasize
  162. mvn ^BG1_TILE_BAK, ^BG1_TILE_BUF
  163. ldx #!BG2_TILE_BAK+64*9
  164. ldy #!BG2_TILE_BUF+64*9
  165. lda @textdmasize
  166. mvn ^BG2_TILE_BAK, ^BG2_TILE_BUF
  167. plp
  168. plb
  169. rts
  170. draw_window:
  171. phb
  172. php
  173. sep #$20 : .as
  174. ; draw upper border
  175. ; upper left corner
  176. lda @window_nw
  177. sta stringbuf
  178. ldx #!stringbuf
  179. inx
  180. lda window_w
  181. sta window_tmp
  182. stz window_tmp+1
  183. ldy window_tmp
  184. dey
  185. dey
  186. ; upper edge
  187. -
  188. lda @window_nh
  189. sta !0,x
  190. inx
  191. dey
  192. cpy #$0000
  193. bne -
  194. ; upper right corner
  195. lda @window_ne
  196. sta !0,x
  197. ; print to text buffer
  198. lda #$01
  199. sta print_pal
  200. lda window_x
  201. sta print_x
  202. lda window_y
  203. sta print_y
  204. lda #^stringbuf
  205. sta print_bank
  206. ldx #!stringbuf
  207. stx print_src
  208. lda window_w
  209. sta print_count
  210. jsr hiprint
  211. ; print window title
  212. lda print_x
  213. pha
  214. inc print_x
  215. inc print_x
  216. lda #^window_tl
  217. sta print_bank
  218. ldx #!window_tl
  219. stx print_src
  220. lda #$01
  221. sta print_count
  222. jsr hiprint
  223. inc print_x
  224. lda window_tbank
  225. sta print_bank
  226. ldx window_taddr
  227. stx print_src
  228. lda window_w
  229. sta print_count
  230. jsr hiprint
  231. lda print_done
  232. clc
  233. adc print_x
  234. sta print_x
  235. lda #^window_tr
  236. sta print_bank
  237. ldx #!window_tr
  238. stx print_src
  239. lda #$01
  240. sta print_count
  241. jsr hiprint
  242. lda window_w
  243. sta print_count
  244. pla
  245. sta print_x
  246. ; draw left+right borders + space inside window
  247. lda #^stringbuf
  248. sta print_bank
  249. ldx #!stringbuf
  250. stx print_src
  251. lda @window_wv
  252. sta stringbuf
  253. ldx #!stringbuf
  254. inx
  255. lda window_w
  256. sta window_tmp
  257. stz window_tmp+1
  258. ldy window_tmp
  259. dey
  260. dey
  261. -
  262. lda @space64
  263. sta !0,x
  264. inx
  265. dey
  266. cpy #$0000
  267. bne -
  268. lda @window_ev
  269. sta !0,x
  270. ; print to text buffer multiple times
  271. lda window_h
  272. sta window_tmp
  273. stz window_tmp+1
  274. ldy window_tmp
  275. dey
  276. dey
  277. -
  278. inc print_y
  279. phy
  280. jsr hiprint
  281. ply
  282. dey
  283. cpy #$0000
  284. bne -
  285. ; draw lower window border
  286. ; lower left corner
  287. lda @window_sw
  288. sta stringbuf
  289. ldx #!stringbuf
  290. inx
  291. lda window_w
  292. sta window_tmp
  293. stz window_tmp+1
  294. ldy window_tmp
  295. dey
  296. dey
  297. ; lower edge
  298. -
  299. lda @window_sh
  300. sta !0,x
  301. inx
  302. dey
  303. cpy #$0000
  304. bne -
  305. ; lower right corner
  306. lda @window_se
  307. sta !0,x
  308. ; print to text buffer
  309. inc print_y
  310. jsr hiprint
  311. plp
  312. plb
  313. rts