print.asm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. ; vim:ts=4:sw=4:et:
  2. ; PRINT command routine
  3. ; Does not print attribute. Use PRINT_STR or PRINT_NUM for that
  4. ;
  5. #include once <sposn.asm>
  6. #include once <cls.asm>
  7. #include once <in_screen.asm>
  8. #include once <table_jump.asm>
  9. #include once <ink.asm>
  10. #include once <paper.asm>
  11. #include once <flash.asm>
  12. #include once <bright.asm>
  13. #include once <over.asm>
  14. #include once <inverse.asm>
  15. #include once <bold.asm>
  16. #include once <italic.asm>
  17. #include once <const.asm>
  18. #include once <attr.asm>
  19. ;
  20. ; Putting a comment starting with @INIT <address>
  21. ; will make the compiler to add a CALL to <address>
  22. ; It is useful for initialization routines.
  23. #init __PRINT_INIT
  24. ;
  25. __PRINT_INIT: ; To be called before program starts (initializes library)
  26. ;- PROC
  27. ;- ld hl, __PRINT_START
  28. ;- ld (PRINT_JUMP_STATE), hl
  29. ;- ld hl, 1821h
  30. ;- ld (MAXX), hl ; Sets current maxX and maxY
  31. eor z80_a ;- xor a
  32. ;- ld (FLAGS2), a
  33. rts ;- ret
  34. __PRINTCHAR:
  35. ; Print character store in accumulator (A register)
  36. ; Modifies H'L', B'C', A'F', D'E', A
  37. ;- LOCAL PO_GR_1
  38. ;- LOCAL __PRCHAR
  39. ;- LOCAL __PRINT_CONT
  40. ;- LOCAL __PRINT_CONT2
  41. ;- LOCAL __PRINT_JUMP
  42. ;- LOCAL __SRCADDR
  43. ;- LOCAL __PRINT_UDG
  44. ;- LOCAL __PRGRAPH
  45. ;- LOCAL __PRINT_START
  46. PRINT_JUMP_STATE EQU __PRINT_JUMP + 1
  47. __PRINT_JUMP:
  48. jmp __PRINT_START ;- jp __PRINT_START ; Where to jump. If we print 22 (AT), next two calls jumps to AT1 and AT2 respectively
  49. __PRINT_START:
  50. ;- cp ' '
  51. ;- jp c, __PRINT_SPECIAL ; Characters below ' ' are special ones
  52. ;- exx ; Switch to alternative registers
  53. ;- ex af, af' ; Saves a value (char to print) for later
  54. jsr __LOAD_S_POSN ;- call __LOAD_S_POSN
  55. ; At this point we have the new coord
  56. ;- ld hl, (SCREEN_ADDR)
  57. ;- ld a, d
  58. ;- ld c, a ; Saves it for later
  59. ;- and 0F8h ; Masks 3 lower bit ; zy
  60. ;- ld d, a
  61. ;- ld a, c ; Recovers it
  62. ;- and 07h ; MOD 7 ; y1
  63. ;- rrca
  64. ;- rrca
  65. ;- rrca
  66. ;- or e
  67. ;- ld e, a
  68. ;- add hl, de ; HL = Screen address + DE
  69. ;- ex de, hl ; DE = Screen address
  70. ;- ex af, af'
  71. ;- cp 80h ; Is it an UDG or a ?
  72. ;- jp c, __SRCADDR
  73. ;- cp 90h
  74. ;- jp nc, __PRINT_UDG
  75. ; Print a 8 bit pattern (80h to 8Fh)
  76. ;- ld b, a
  77. ;- call PO_GR_1 ; This ROM routine will generate the bit pattern at MEM0
  78. ;- ld hl, MEM0
  79. ;- jp __PRGRAPH
  80. PO_GR_1 EQU 0B38h
  81. __PRINT_UDG:
  82. ;- sub 90h ; Sub ASC code
  83. ;- ld bc, (UDG)
  84. ;- jp __PRGRAPH0
  85. __SOURCEADDR EQU (__SRCADDR + 1) ; Address of the pointer to chars source
  86. __SRCADDR:
  87. ;- ld bc, (CHARS)
  88. __PRGRAPH0:
  89. ;- add a, a ; A = a * 2 (since a < 80h) ; Thanks to Metalbrain at http://foro.speccy.org
  90. ;- ld l, a
  91. ;- ld h, 0 ; HL = a * 2 (accumulator)
  92. ;- add hl, hl
  93. ;- add hl, hl ; HL = a * 8
  94. ;- add hl, bc ; HL = CHARS address
  95. __PRGRAPH:
  96. ;- ex de, hl ; HL = Write Address, DE = CHARS address
  97. ;- bit 2, (iy + $47)
  98. ;- call nz, __BOLD
  99. ;- bit 4, (iy + $47)
  100. ;- call nz, __ITALIC
  101. ;- ld b, 8 ; 8 bytes per char
  102. __PRCHAR:
  103. ;- ld a, (de) ; DE *must* be ALWAYS source, and HL destiny
  104. PRINT_MODE: ; Which operation is used to write on the screen
  105. ;- ; Set it with:
  106. ;- ; LD A, <OPERATION>
  107. ;- ; LD (PRINT_MODE), A
  108. ;- ;
  109. ;- ; Available opertions:
  110. ;- ; NORMAL: 0h --> NOP ; OVER 0
  111. ;- ; XOR : AEh --> XOR (HL) ; OVER 1
  112. ;- ; OR : B6h --> OR (HL) ; PUTSPRITE
  113. ;- ; AND : A6h --> AND (HL) ; PUTMASK
  114. ;- nop ;
  115. INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
  116. ;- nop ; 2F -> CPL -> INVERSE 1
  117. ;- ld (hl), a
  118. ;- inc de
  119. ;- inc h ; Next line
  120. ;- djnz __PRCHAR
  121. jsr __LOAD_S_POSN ;- call __LOAD_S_POSN
  122. ;- push de
  123. jsr __SET_ATTR ;- call __SET_ATTR
  124. ;- pop de
  125. ;- inc e ; COL = COL + 1
  126. ;- ld hl, (MAXX)
  127. ;- ld a, e
  128. ;- dec l ; l = MAXX
  129. ;- cp l ; Lower than max?
  130. ;- jp c, __PRINT_CONT; Nothing to do
  131. jsr __PRINT_EOL1 ;- call __PRINT_EOL1
  132. ;- exx ; counteracts __PRINT_EOL1 exx
  133. jmp __PRINT_CONT2 ;- jp __PRINT_CONT2
  134. __PRINT_CONT:
  135. ;- call __SAVE_S_POSN
  136. __PRINT_CONT2:
  137. ;- exx
  138. rts ;- ret
  139. ; ------------- SPECIAL CHARS (< 32) -----------------
  140. __PRINT_SPECIAL: ; Jumps here if it is a special char
  141. ;- exx
  142. ;- ld hl, __PRINT_TABLE
  143. jmp JUMP_HL_PLUS_2A ;- jp JUMP_HL_PLUS_2A
  144. PRINT_EOL: ; Called WHENEVER there is no ";" at end of PRINT sentence
  145. ;- exx
  146. __PRINT_0Dh: ; Called WHEN printing CHR$(13)
  147. jsr __LOAD_S_POSN ;- call __LOAD_S_POSN
  148. __PRINT_EOL1: ; Another entry called from PRINT when next line required
  149. ;- ld e, 0
  150. __PRINT_EOL2:
  151. ;- ld a, d
  152. clc ;- inc a
  153. adc #$01
  154. __PRINT_AT1_END:
  155. ;- ld hl, (MAXY)
  156. cmp z80_l ;- cp l
  157. ;- jr c, __PRINT_EOL_END ; Carry if (MAXY) < d
  158. eor z80_a ;- xor a
  159. __PRINT_EOL_END:
  160. ;- ld d, a
  161. __PRINT_AT2_END:
  162. jsr __SAVE_S_POSN ;- call __SAVE_S_POSN
  163. lda z80_c ;- exx
  164. ldx z80_cp
  165. stx z80_c
  166. sta z80_cp
  167. lda z80_b
  168. ldx z80_bp
  169. stx z80_b
  170. sta z80_bp
  171. lda z80_e
  172. ldx z80_ep
  173. stx z80_e
  174. sta z80_ep
  175. lda z80_d
  176. ldx z80_dp
  177. stx z80_d
  178. sta z80_dp
  179. lda z80_l
  180. ldx z80_lp
  181. stx z80_l
  182. sta z80_lp
  183. lda z80_h
  184. ldx z80_hp
  185. stx z80_h
  186. sta z80_hp
  187. rts ;- ret
  188. __PRINT_COM:
  189. lda z80_c ;- exx
  190. ldx z80_cp
  191. stx z80_c
  192. sta z80_cp
  193. lda z80_b
  194. ldx z80_bp
  195. stx z80_b
  196. sta z80_bp
  197. lda z80_e
  198. ldx z80_ep
  199. stx z80_e
  200. sta z80_ep
  201. lda z80_d
  202. ldx z80_dp
  203. stx z80_d
  204. sta z80_dp
  205. lda z80_l
  206. ldx z80_lp
  207. stx z80_l
  208. sta z80_lp
  209. lda z80_h
  210. ldx z80_hp
  211. stx z80_h
  212. sta z80_hp
  213. ;- push hl
  214. lda z80_e ;- push de
  215. pha
  216. lda z80_d
  217. pha
  218. lda z80_c ;- push bc
  219. pha
  220. lda z80_b
  221. pha
  222. jsr PRINT_COMMA ;- call PRINT_COMMA
  223. pla ;- pop bc
  224. sta z80_b
  225. pla
  226. sta z80_c
  227. pla ;- pop de
  228. sta z80_d
  229. pla
  230. sta z80_e
  231. pla ;- pop hl
  232. sta z80_h
  233. pla
  234. sta z80_l
  235. rts ;- ret
  236. __PRINT_TAB:
  237. ;- ld hl, __PRINT_TAB1
  238. jmp __PRINT_SET_STATE ;- jp __PRINT_SET_STATE
  239. __PRINT_TAB1:
  240. ;- ld (MEM0), a
  241. ;- ld hl, __PRINT_TAB2
  242. ;- ld (PRINT_JUMP_STATE), hl
  243. rts ;- ret
  244. __PRINT_TAB2:
  245. ;- ld a, (MEM0) ; Load tab code (ignore the current one)
  246. lda z80_l ;- push hl
  247. pha
  248. lda z80_h
  249. pha
  250. lda z80_e ;- push de
  251. pha
  252. lda z80_d
  253. pha
  254. lda z80_c ;- push bc
  255. pha
  256. lda z80_b
  257. pha
  258. ;- ld hl, __PRINT_START
  259. ;- ld (PRINT_JUMP_STATE), hl
  260. jsr PRINT_TAB ;- call PRINT_TAB
  261. pla ;- pop bc
  262. sta z80_b
  263. pla
  264. sta z80_c
  265. ;- pop de
  266. ;- pop hl
  267. rts ;- ret
  268. __PRINT_NOP:
  269. __PRINT_RESTART:
  270. ;- ld hl, __PRINT_START
  271. ;- jp __PRINT_SET_STATE
  272. __PRINT_AT:
  273. ;- ld hl, __PRINT_AT1
  274. __PRINT_SET_STATE:
  275. ;- ld (PRINT_JUMP_STATE), hl ; Saves next entry call
  276. lda z80_c ;- exx
  277. ldx z80_cp
  278. stx z80_c
  279. sta z80_cp
  280. lda z80_b
  281. ldx z80_bp
  282. stx z80_b
  283. sta z80_bp
  284. lda z80_e
  285. ldx z80_ep
  286. stx z80_e
  287. sta z80_ep
  288. lda z80_d
  289. ldx z80_dp
  290. stx z80_d
  291. sta z80_dp
  292. lda z80_l
  293. ldx z80_lp
  294. stx z80_l
  295. sta z80_lp
  296. lda z80_h
  297. ldx z80_hp
  298. stx z80_h
  299. sta z80_hp
  300. rts ;- ret
  301. __PRINT_AT1: ; Jumps here if waiting for 1st parameter
  302. lda z80_c ;- exx
  303. ldx z80_cp
  304. stx z80_c
  305. sta z80_cp
  306. lda z80_b
  307. ldx z80_bp
  308. stx z80_b
  309. sta z80_bp
  310. lda z80_e
  311. ldx z80_ep
  312. stx z80_e
  313. sta z80_ep
  314. lda z80_d
  315. ldx z80_dp
  316. stx z80_d
  317. sta z80_dp
  318. lda z80_l
  319. ldx z80_lp
  320. stx z80_l
  321. sta z80_lp
  322. lda z80_h
  323. ldx z80_hp
  324. stx z80_h
  325. sta z80_hp
  326. ;- ld hl, __PRINT_AT2
  327. ;- ld (PRINT_JUMP_STATE), hl ; Saves next entry call
  328. jsr __LOAD_S_POSN ;- call __LOAD_S_POSN
  329. jmp __PRINT_AT1_END ;- jp __PRINT_AT1_END
  330. __PRINT_AT2:
  331. lda z80_c ;- exx
  332. ldx z80_cp
  333. stx z80_c
  334. sta z80_cp
  335. lda z80_b
  336. ldx z80_bp
  337. stx z80_b
  338. sta z80_bp
  339. lda z80_e
  340. ldx z80_ep
  341. stx z80_e
  342. sta z80_ep
  343. lda z80_d
  344. ldx z80_dp
  345. stx z80_d
  346. sta z80_dp
  347. lda z80_l
  348. ldx z80_lp
  349. stx z80_l
  350. sta z80_lp
  351. lda z80_h
  352. ldx z80_hp
  353. stx z80_h
  354. sta z80_hp
  355. ;- ld hl, __PRINT_START
  356. ;- ld (PRINT_JUMP_STATE), hl ; Saves next entry call
  357. jsr __LOAD_S_POSN ;- call __LOAD_S_POSN
  358. ;- ld e, a
  359. ;- ld hl, (MAXX)
  360. ;- cp (hl)
  361. ;- jr c, __PRINT_AT2_END
  362. ;- jr __PRINT_EOL1
  363. __PRINT_DEL:
  364. ;- call __LOAD_S_POSN ; Gets current screen position
  365. ;- dec e
  366. ;- ld a, -1
  367. ;- cp e
  368. ;- jp nz, __PRINT_AT2_END
  369. ;- ld hl, (MAXX)
  370. ;- ld e, l
  371. ;- dec e
  372. ;- dec e
  373. ;- dec d
  374. ;- cp d
  375. ;- jp nz, __PRINT_AT2_END
  376. ;- ld d, h
  377. ;- dec d
  378. jmp __PRINT_AT2_END ;- jp __PRINT_AT2_END
  379. __PRINT_INK:
  380. ;- ld hl, __PRINT_INK2
  381. jmp __PRINT_SET_STATE ;- jp __PRINT_SET_STATE
  382. __PRINT_INK2:
  383. ;- exx
  384. jsr INK_TMP ;- call INK_TMP
  385. jmp __PRINT_RESTART ;- jp __PRINT_RESTART
  386. __PRINT_PAP:
  387. ;- ld hl, __PRINT_PAP2
  388. jmp __PRINT_SET_STATE ;- jp __PRINT_SET_STATE
  389. __PRINT_PAP2:
  390. ;- exx
  391. jsr PAPER_TMP ;- call PAPER_TMP
  392. jmp __PRINT_RESTART ;- jp __PRINT_RESTART
  393. __PRINT_FLA:
  394. ;- ld hl, __PRINT_FLA2
  395. jmp __PRINT_SET_STATE ;- jp __PRINT_SET_STATE
  396. __PRINT_FLA2:
  397. ;- exx
  398. jsr FLASH_TMP ;- call FLASH_TMP
  399. jmp __PRINT_RESTART ;- jp __PRINT_RESTART
  400. __PRINT_BRI:
  401. ;- ld hl, __PRINT_BRI2
  402. jmp __PRINT_SET_STATE ;- jp __PRINT_SET_STATE
  403. __PRINT_BRI2:
  404. ;- exx
  405. jsr BRIGHT_TMP ;- call BRIGHT_TMP
  406. jmp __PRINT_RESTART ;- jp __PRINT_RESTART
  407. __PRINT_INV:
  408. ;- ld hl, __PRINT_INV2
  409. jmp __PRINT_SET_STATE ;- jp __PRINT_SET_STATE
  410. __PRINT_INV2:
  411. ;- exx
  412. jsr INVERSE_TMP ;- call INVERSE_TMP
  413. jmp __PRINT_RESTART ;- jp __PRINT_RESTART
  414. __PRINT_OVR:
  415. ;- ld hl, __PRINT_OVR2
  416. jmp __PRINT_SET_STATE ;- jp __PRINT_SET_STATE
  417. __PRINT_OVR2:
  418. ;- exx
  419. ;- call OVER_TMP
  420. jmp __PRINT_RESTART ;- jp __PRINT_RESTART
  421. __PRINT_BOLD:
  422. ;- ld hl, __PRINT_BOLD2
  423. jmp __PRINT_SET_STATE ;- jp __PRINT_SET_STATE
  424. __PRINT_BOLD2:
  425. ;- exx
  426. jsr BOLD_TMP ;- call BOLD_TMP
  427. jmp __PRINT_RESTART ;- jp __PRINT_RESTART
  428. __PRINT_ITA:
  429. ;- ld hl, __PRINT_ITA2
  430. jmp __PRINT_SET_STATE ;- jp __PRINT_SET_STATE
  431. __PRINT_ITA2:
  432. ;- exx
  433. jsr ITALIC_TMP ;- call ITALIC_TMP
  434. jmp __PRINT_RESTART ;- jp __PRINT_RESTART
  435. __BOLD:
  436. lda z80_l ;- push hl
  437. pha
  438. lda z80_h
  439. pha
  440. ;- ld hl, MEM0
  441. ;- ld b, 8
  442. __BOLD_LOOP:
  443. ;- ld a, (de)
  444. ;- ld c, a
  445. ;- rlca
  446. ;- or c
  447. ;- ld (hl), a
  448. ;- inc hl
  449. ;- inc de
  450. ;- djnz __BOLD_LOOP
  451. ;- pop hl
  452. ;- ld de, MEM0
  453. rts ;- ret
  454. __ITALIC:
  455. lda z80_l ;- push hl
  456. pha
  457. lda z80_h
  458. pha
  459. ;- ld hl, MEM0
  460. ;- ex de, hl
  461. ;- ld bc, 8
  462. ;- ldir
  463. ;- ld hl, MEM0
  464. ;- srl (hl)
  465. ;- inc hl
  466. ;- srl (hl)
  467. ;- inc hl
  468. ;- srl (hl)
  469. ;- inc hl
  470. ;- inc hl
  471. ;- inc hl
  472. ;- sla (hl)
  473. ;- inc hl
  474. ;- sla (hl)
  475. ;- inc hl
  476. ;- sla (hl)
  477. ;- pop hl
  478. ;- ld de, MEM0
  479. rts ;- ret
  480. PRINT_COMMA:
  481. jsr __LOAD_S_POSN ;- call __LOAD_S_POSN
  482. ;- ld a, e
  483. ;- and 16
  484. ;- add a, 16
  485. PRINT_TAB:
  486. ;- PROC
  487. ;- LOCAL LOOP, CONTINUE
  488. ;- inc a
  489. ;- call __LOAD_S_POSN ; e = current row
  490. lda z80_a ;- ld d,a
  491. sta z80_d
  492. ;- ld a, e
  493. ;- cp 21h
  494. ;- jr nz, CONTINUE
  495. ;- ld e, -1
  496. CONTINUE:
  497. ;- ld a, d
  498. ;- inc e
  499. ;- sub e ; A = A - E
  500. ;- and 31 ;
  501. ;- ret z ; Already at position E
  502. ;- ld b, a
  503. LOOP:
  504. ;- ld a, ' '
  505. ;- call __PRINTCHAR
  506. ;- djnz LOOP
  507. ;- ret
  508. ;- ENDP
  509. PRINT_AT: ; CHanges cursor to ROW, COL
  510. ;- ; COL in A register
  511. ;- ; ROW in stack
  512. ;- pop hl ; Ret address
  513. ;- ex (sp), hl ; callee H = ROW
  514. ;- ld l, a
  515. ;- ex de, hl
  516. jsr __IN_SCREEN ;- call __IN_SCREEN
  517. ;- ret nc ; Return if out of screen
  518. ;- jp __SAVE_S_POSN
  519. ;- LOCAL __PRINT_COM
  520. ;- LOCAL __BOLD
  521. ;- LOCAL __BOLD_LOOP
  522. ;- LOCAL __ITALIC
  523. ;- LOCAL __PRINT_EOL1
  524. ;- LOCAL __PRINT_EOL2
  525. ;- LOCAL __PRINT_AT1
  526. ;- LOCAL __PRINT_AT2
  527. ;- LOCAL __PRINT_AT2_END
  528. ;- LOCAL __PRINT_BOLD
  529. ;- LOCAL __PRINT_BOLD2
  530. ;- LOCAL __PRINT_ITA
  531. ;- LOCAL __PRINT_ITA2
  532. ;- LOCAL __PRINT_INK
  533. ;- LOCAL __PRINT_PAP
  534. ;- LOCAL __PRINT_SET_STATE
  535. ;- LOCAL __PRINT_TABLE
  536. ;- LOCAL __PRINT_TAB, __PRINT_TAB1, __PRINT_TAB2
  537. __PRINT_TABLE: ; Jump table for 0 .. 22 codes
  538. ;- DW __PRINT_NOP ; 0
  539. ;- DW __PRINT_NOP ; 1
  540. ;- DW __PRINT_NOP ; 2
  541. ;- DW __PRINT_NOP ; 3
  542. ;- DW __PRINT_NOP ; 4
  543. ;- DW __PRINT_NOP ; 5
  544. ;- DW __PRINT_COM ; 6 COMMA
  545. ;- DW __PRINT_NOP ; 7
  546. ;- DW __PRINT_DEL ; 8 DEL
  547. ;- DW __PRINT_NOP ; 9
  548. ;- DW __PRINT_NOP ; 10
  549. ;- DW __PRINT_NOP ; 11
  550. ;- DW __PRINT_NOP ; 12
  551. ;- DW __PRINT_0Dh ; 13
  552. ;- DW __PRINT_BOLD ; 14
  553. ;- DW __PRINT_ITA ; 15
  554. ;- DW __PRINT_INK ; 16
  555. ;- DW __PRINT_PAP ; 17
  556. ;- DW __PRINT_FLA ; 18
  557. ;- DW __PRINT_BRI ; 19
  558. ;- DW __PRINT_INV ; 20
  559. ;- DW __PRINT_OVR ; 21
  560. ;- DW __PRINT_AT ; 22 AT
  561. ;- DW __PRINT_TAB ; 23 TAB
  562. ;- ENDP