text.z80 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. ld a,(font_ptr_page)
  101. jp p,+_
  102. or a
  103. jr z,+_
  104. set 6,h
  105. res 7,h
  106. inc a
  107. _:
  108. ld bc,3
  109. ld de,$8005
  110. call readarc
  111. pop bc
  112. ld a,b
  113. ld b,0
  114. ld h,b
  115. ld l,c
  116. add hl,hl
  117. add hl,bc
  118. add hl,hl
  119. add hl,hl
  120. rra
  121. push af
  122. ld c,a
  123. add hl,bc
  124. ld bc,(gbuf_temp)
  125. add hl,bc
  126. ld bc,060Ch
  127. pop af
  128. ld de,$8005
  129. jr c,PutRight
  130. ;===============================================================
  131. PutLeft:
  132. ;===============================================================
  133. ld a,(hl)
  134. and 15
  135. ld (hl),a
  136. ld a,(de)
  137. bit InvertTextFlag,(iy+UserFlags)
  138. jr z,+_
  139. cpl
  140. _:
  141. bit 0,b
  142. jr z,+_
  143. rlca \ rlca \ rlca \ rlca
  144. inc de
  145. _:
  146. and $F0
  147. or (hl)
  148. ld (hl),a
  149. ld a,b
  150. ld b,0
  151. add hl,bc
  152. ld b,a
  153. djnz PutLeft
  154. ret
  155. ;===============================================================
  156. PutRight:
  157. ;===============================================================
  158. ld a,(hl)
  159. and $F0
  160. ld (hl),a
  161. ld a,(de)
  162. bit InvertTextFlag,(iy+UserFlags)
  163. jr z,+_
  164. cpl
  165. _:
  166. bit 0,b
  167. jr nz,+_
  168. rlca \ rlca \ rlca \ rlca
  169. dec de
  170. _:
  171. inc de
  172. and 15
  173. or (hl)
  174. ld (hl),a
  175. ld a,b
  176. ld b,0
  177. add hl,bc
  178. ld b,a
  179. djnz PutRight
  180. ret
  181. OmniCalcFont:
  182. ;Inputs:
  183. ; A is the char to draw
  184. ld l,a
  185. ld h,0
  186. ld b,h
  187. ld c,l
  188. add hl,hl
  189. add hl,bc
  190. add hl,hl
  191. add hl,bc
  192. ld bc,(FontPointer)
  193. adc hl,bc
  194. ld a,(font_ptr_page)
  195. jp p,+_
  196. or a
  197. jr z,+_
  198. set 6,h
  199. res 7,h
  200. inc a
  201. _:
  202. ld bc,7
  203. ld de,$8005
  204. call readarc
  205. ld hl,0706h
  206. ld b,h
  207. _:
  208. dec e
  209. ld a,(de)
  210. rlca
  211. rlca
  212. rlca
  213. ld (de),a
  214. djnz -_
  215. jr VputSCStepIn
  216. VPutSC:
  217. ;Inputs:
  218. ; A is the char to draw
  219. ld hl,(FontPointer)
  220. ld c,a
  221. ld b,0
  222. add hl,bc
  223. add hl,bc
  224. adc hl,bc ;*3
  225. ld a,(font_ptr_page)
  226. jp p,+_
  227. or a
  228. jr z,+_
  229. set 6,h
  230. res 7,h
  231. inc a
  232. _:
  233. ld bc,3
  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. inc de
  391. jp VputSCStepIn
  392. _:
  393. ld hl,$0600
  394. ret
  395. vput_space:
  396. call chardim
  397. ld h,c
  398. ld l,b
  399. push bc
  400. call upd_text_coord
  401. ;C is y
  402. ld e,b ;x
  403. pop hl
  404. ld d,h ;width
  405. ld b,l ;height
  406. ; If using text mode 0, need to multiply x by 4
  407. ld a,(textmode)
  408. or a
  409. jr nz,+_
  410. sla e
  411. sla e
  412. _:
  413. ld hl,rect_wbwf
  414. ld (next_page_call_address),hl
  415. jp next_page_call
  416. OS_font_sub:
  417. call os_char_ptr
  418. ld de,lfont_record
  419. ld bc,8
  420. call readarc
  421. ld hl,lFont_record
  422. ld a,8
  423. sub (hl)
  424. ld c,a
  425. _:
  426. ld hl,lFont_record+7
  427. ld b,7
  428. sla (hl)
  429. dec hl
  430. djnz $-3
  431. dec c
  432. jr nz,-_
  433. ld e,(hl)
  434. ex de,hl
  435. inc de
  436. ld h,6
  437. ret
  438. os_char_ptr:
  439. ld h,0
  440. ld l,b
  441. add hl,hl
  442. add hl,hl
  443. add hl,hl
  444. ld bc,(FontPointer)
  445. add hl,bc
  446. ret