text.z80 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. ;===============================================================
  2. PutSM:
  3. ;===============================================================
  4. ;Inputs:
  5. ; hl points to the string to display
  6. ; bc is the size of the string
  7. ;===============================================================
  8. ld a,b \ or c \ ret z
  9. _:
  10. push bc
  11. push hl
  12. ld a,(hl)
  13. call PutSC
  14. pop hl
  15. pop bc
  16. cpi
  17. jp pe,-_
  18. ret
  19. GPutSS:
  20. ld (textRow),bc
  21. jr GPutS
  22. _:
  23. push hl
  24. call PutSC
  25. pop hl
  26. GPutS:
  27. ld a,(hl)
  28. inc hl
  29. or a
  30. jr nz,-_
  31. ret
  32. PutSC:
  33. ;Inputs:
  34. ; a is the char to draw
  35. ; (textRow) is the pixel row to draw at
  36. ; (textCol) is the text column to draw at (0 to 23)
  37. ;===============================================================
  38. call +_
  39. typewriter_delay:
  40. bit SlowTextFlag,(iy+InternalFlag)
  41. ret z
  42. push af
  43. push hl
  44. call GraphToLCD
  45. pop hl
  46. ld a,(TextPauseTime)
  47. ei
  48. halt
  49. dec a
  50. jr nz,$-2
  51. di
  52. pop af
  53. ret
  54. _:
  55. ld bc,(textmode)
  56. ld b,0
  57. ld hl,putc_LUT
  58. add hl,bc
  59. add hl,bc
  60. ld e,(hl)
  61. inc hl
  62. ld d,(hl)
  63. ex de,hl
  64. jp (hl)
  65. putc_LUT:
  66. .dw PutFS
  67. .dw VPutC
  68. .dw VPutSC
  69. .dw OmniCalcFont
  70. .dw VPutC_OS_small
  71. .dw VPutC_OS_large
  72. PutFS:
  73. push af
  74. ld bc,(textRow)
  75. ld a,b
  76. cp 24
  77. ld a,c
  78. jr c,+_
  79. ld b,0
  80. add a,6
  81. _:
  82. cp 3Bh
  83. jr c,+_
  84. sub 3Ch
  85. jr nc,+_
  86. add a,6
  87. _:
  88. ld c,a
  89. inc b
  90. ld (textRow),bc
  91. dec b
  92. ld hl,(FontPointer)
  93. pop af
  94. push bc
  95. ld b,0
  96. ld c,a
  97. add hl,bc
  98. add hl,bc
  99. adc hl,bc
  100. jp p,+_
  101. ld a,h
  102. add a,-$40
  103. ld h,a
  104. _:
  105. ld a,(font_ptr_page)
  106. ld bc,3
  107. adc a,b
  108. ld de,$8005
  109. call readarc
  110. pop bc
  111. ld a,b
  112. ld b,0
  113. ld h,b
  114. ld l,c
  115. add hl,hl
  116. add hl,bc
  117. add hl,hl
  118. add hl,hl
  119. rra
  120. push af
  121. ld c,a
  122. add hl,bc
  123. ld bc,(gbuf_temp)
  124. add hl,bc
  125. ld bc,060Ch
  126. pop af
  127. ld de,$8005
  128. jr c,PutRight
  129. ;===============================================================
  130. PutLeft:
  131. ;===============================================================
  132. ld a,(hl)
  133. and 15
  134. ld (hl),a
  135. ld a,(de)
  136. bit InvertTextFlag,(iy+UserFlags)
  137. jr z,+_
  138. cpl
  139. _:
  140. bit 0,b
  141. jr z,+_
  142. rlca \ rlca \ rlca \ rlca
  143. inc de
  144. _:
  145. and $F0
  146. or (hl)
  147. ld (hl),a
  148. ld a,b
  149. ld b,0
  150. add hl,bc
  151. ld b,a
  152. djnz PutLeft
  153. ret
  154. ;===============================================================
  155. PutRight:
  156. ;===============================================================
  157. ld a,(hl)
  158. and $F0
  159. ld (hl),a
  160. ld a,(de)
  161. bit InvertTextFlag,(iy+UserFlags)
  162. jr z,+_
  163. cpl
  164. _:
  165. bit 0,b
  166. jr nz,+_
  167. rlca \ rlca \ rlca \ rlca
  168. dec de
  169. _:
  170. inc de
  171. and 15
  172. or (hl)
  173. ld (hl),a
  174. ld a,b
  175. ld b,0
  176. add hl,bc
  177. ld b,a
  178. djnz PutRight
  179. ret
  180. OmniCalcFont:
  181. ;Inputs:
  182. ; A is the char to draw
  183. ld l,a
  184. ld h,0
  185. ld b,h
  186. ld c,l
  187. add hl,hl
  188. add hl,bc
  189. add hl,hl
  190. add hl,bc
  191. ld bc,(FontPointer)
  192. adc hl,bc
  193. jp p,+_
  194. ld a,h
  195. add a,-$40
  196. ld h,a
  197. _:
  198. ld a,(font_ptr_page)
  199. ld bc,7
  200. adc a,b
  201. ld de,$8005
  202. call readarc
  203. ld de,$8005
  204. ld b,7
  205. _:
  206. ld a,(hl)
  207. rlca
  208. rlca
  209. rlca
  210. ld (de),a
  211. inc e
  212. inc hl
  213. djnz -_
  214. ld de,$8005
  215. ld hl,0706h
  216. jr VputSCStepIn
  217. VPutSC:
  218. ;Inputs:
  219. ; A is the char to draw
  220. ld hl,(FontPointer)
  221. ld c,a
  222. ld b,0
  223. add hl,bc
  224. add hl,bc
  225. adc hl,bc ;*3
  226. jp p,+_
  227. ld a,h
  228. add a,-$40
  229. ld h,a
  230. _:
  231. ld a,(font_ptr_page)
  232. ld bc,3
  233. adc a,b
  234. ld de,$8005+6
  235. call readarc
  236. ld hl,$8005+6
  237. ld de,$8005
  238. ld b,3 ;3*2 Nibbles
  239. _:
  240. ld a,(hl)
  241. and $F0
  242. ld (de),a
  243. inc e
  244. ld a,(hl)
  245. rrca \ rrca
  246. rrca \ rrca
  247. and $F0
  248. ld (de),a
  249. inc e
  250. inc hl
  251. djnz -_
  252. ld de,$8005
  253. ld hl,0604h
  254. jr VputSCStepIn
  255. VPutC:
  256. ;Inputs:
  257. ; A is the char to draw
  258. ld hl,(FontPointer)
  259. ;The first byte is the height of the font
  260. ld e,(hl)
  261. inc hl
  262. ld d,0
  263. #ifdef INDEX_VFONT
  264. sub 32
  265. jr c,+_
  266. ld b,a
  267. ld hl,(vfont_index)
  268. sub 16
  269. jr c,+_
  270. ld b,a
  271. ld hl,(vfont_index+2)
  272. sub 16
  273. jr c,+_
  274. ld b,a
  275. ld hl,(vfont_index+4)
  276. sub 32
  277. jr c,+_
  278. ld b,a
  279. ld hl,(vfont_index+6)
  280. _:
  281. inc b
  282. call lookupchar_vfont
  283. #else
  284. ;E is the height, assume non-zero
  285. ;HL points to the font data
  286. ;B is the char
  287. ld b,a
  288. inc b
  289. jr vputc_loc_loop_end
  290. vputc_loc_loop:
  291. ld a,(hl)
  292. inc hl
  293. dec a
  294. jp m,vputc_loc_loop_end
  295. _:
  296. add hl,de
  297. sub 8
  298. jr nc,-_
  299. vputc_loc_loop_end:
  300. djnz vputc_loc_loop
  301. #endif
  302. ld d,e
  303. ld e,(hl)
  304. inc hl
  305. ex de,hl
  306. VputSCStepIn:
  307. bit InvertTextFlag,(iy+UserFlags)
  308. jr z,VputSCStepIn_postinvert
  309. ;need to invert the text data
  310. ;DE points to the sprite
  311. ;H is height
  312. ;L is width
  313. push hl
  314. ld b,h
  315. ;get the mask to invert with
  316. ld a,l
  317. ld hl,spritemask
  318. add a,l
  319. ld l,a
  320. jr nc,+_
  321. inc h
  322. _:
  323. ld c,(hl)
  324. ld hl,$8005
  325. _:
  326. ld a,(de)
  327. xor c
  328. ld (hl),a
  329. inc hl
  330. inc de
  331. djnz -_
  332. ld de,$8005
  333. pop hl
  334. VputSCStepIn_postinvert:
  335. push hl
  336. call upd_text_coord
  337. pop hl
  338. ld a,7
  339. add a,l
  340. and %11111000
  341. ret z
  342. rra
  343. rra
  344. rra
  345. ld l,a
  346. ld a,(OutputLogic)
  347. jp sprite
  348. upd_text_coord:
  349. ld bc,(TextRow)
  350. ld a,b \ add a,l
  351. cp 97
  352. jr c,+_
  353. ;We need to increment if font is variable-width or OS large font style
  354. ;I unintentionally organized the fonts so that odd-numbered fonts need an inc
  355. ld a,(textmode)
  356. rra
  357. ld a,c
  358. adc a,h \ ld c,a
  359. ld a,l \ ld b,0
  360. _:
  361. ld l,a
  362. ld a,c
  363. cp 58
  364. jr c,+_
  365. xor a
  366. ld c,a
  367. _:
  368. ld h,l
  369. ld l,a
  370. ld (TextRow),hl
  371. ret
  372. VPutC_OS_large:
  373. sub 1
  374. jr c,+_
  375. ld b,a
  376. ld a,$7F
  377. call OS_font_sub
  378. inc l
  379. inc h
  380. jp VputSCStepIn
  381. _:
  382. ld hl,$0700
  383. ret
  384. VPutC_OS_small:
  385. or a
  386. jr z,+_
  387. ld b,a
  388. ld a,3
  389. call OS_font_sub
  390. jp VputSCStepIn
  391. _:
  392. ld hl,$0600
  393. ret
  394. vput_space:
  395. call chardim
  396. ld h,c
  397. ld l,b
  398. push bc
  399. call upd_text_coord
  400. ;C is y
  401. ld e,b ;x
  402. pop hl
  403. ld d,h ;width
  404. ld b,l ;height
  405. ; If using text mode 0, need to multiply x by 4
  406. ld a,(textmode)
  407. or a
  408. jr nz,+_
  409. sla e
  410. sla e
  411. _:
  412. ld hl,rect_wbwf
  413. ld (next_page_call_address),hl
  414. jp next_page_call
  415. OS_font_sub:
  416. call os_char_ptr
  417. ld de,lfont_record
  418. ld bc,8
  419. call readarc
  420. ld hl,lFont_record
  421. ld a,8
  422. sub (hl)
  423. ld c,a
  424. _:
  425. ld hl,lFont_record+7
  426. ld b,7
  427. sla (hl)
  428. dec hl
  429. djnz $-3
  430. dec c
  431. jr nz,-_
  432. ld e,(hl)
  433. ex de,hl
  434. inc de
  435. ld h,6
  436. ret
  437. os_char_ptr:
  438. ld h,0
  439. ld l,b
  440. add hl,hl
  441. add hl,hl
  442. add hl,hl
  443. ld bc,(FontPointer)
  444. add hl,bc
  445. ret