comparison src/aa_wordprocessor.asm @ 623:c40025d8e750

3.03 beta released
author heinrichsweikamp
date Mon, 03 Jun 2019 14:01:48 +0200
parents d866684249bd
children cd58f7fc86db
comparison
equal deleted inserted replaced
622:02d1386429a6 623:c40025d8e750
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File aa_wordprocessor.asm ## V2.99e 3 ; File aa_wordprocessor.asm combined next generation V3.03.1
4 ; 4 ;
5 ; Anti-aliased word processor 5 ; Anti-aliased word processor
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
27 ; + 2.2 KB aa_font90 27 ; + 2.2 KB aa_font90
28 ; = 7.9 KB including fonts 28 ; = 7.9 KB including fonts
29 ; 29 ;
30 ; Input registers: 30 ; Input registers:
31 ; buffer:26 String to print 31 ; buffer:26 String to print
32 ; win_font Font size (0=tiny, 1=small, 2=medium, 3=large) 32 ; win_font Font size (0=tiny, 1=small, 2=std, 3=medium, 4=large, 5=XL)
33 ; win_color1:2 16bits unpacked color 33 ; win_color1:2 16bits unpacked color
34 ; win_top, win_leftx2 Position on screen 34 ; win_top, win_leftx2 Position on screen
35 ; win_inverse Inverse video mode 35 ; win_inverse Inverse video mode
36 ; 36 ;
37 ; Available general purpose registers: 37 ; Available general purpose registers:
38 ; PRODH, PRODL needed for array indexing) 38 ; PRODH, PRODL needed for array indexing
39 ; FSRx 12bits. Useful as RAM pointers. 39 ; FSRx 12bits, used for indirect addressing
40 ;============================================================================= 40 ;=============================================================================
41 41
42 #include "hwos.inc" 42 #include "hwos.inc"
43 #include "tft.inc" 43 #include "tft.inc"
44 44
45 extern aa_font16_block 45 extern aa_font16_block
46 extern aa_font28_block 46 extern aa_font28_block
47 extern aa_font36_block 47 extern aa_font34_block
48 extern aa_font48_block 48 extern aa_font48_block
49 extern aa_font90_block 49 extern aa_font90_block
50 50
51 IFDEF _huge_font
52 extern aa_font92_block
53 ENDIF
54
51 extern convert_for_display2 55 extern convert_for_display2
52 56
57
53 aa_word CODE 58 aa_word CODE
59
60 ;=============================================================================
54 61
55 ;------------------------------------------------------------------------------ 62 ;------------------------------------------------------------------------------
56 ; Setup pointers for a char: 63 ; Setup pointers for a char:
57 ; Inputs WREG = char to draw, win_font 64 ; Inputs WREG = char to draw, win_font
58 ; Output aa_start, aa_end, win_height, aa_flags 65 ; Output aa_start, aa_end, win_height, AA_flags
59 ; Trashed PRODH, PRODL, TBLPTR, TABLAT 66 ; Trashed PRODH, PRODL, TBLPTR, TABLAT
60 ; 67 ;
61
62 aa_char_setup: 68 aa_char_setup:
63 movwf PRODL ; save char into PROD for now 69 movwf PRODL ; save char into PROD for now
64 movf win_font,W ; get font number (updates Z flag) 70 movf win_font,W ; get font number (updates Z flag)
65 bnz aa_char_1 71 bnz aa_char_1 ; requested tiny font? (bra of no)
66 72
67 ; TINY font --------------------------------------------------------- 73 ; 0: TINY font -------------------------------------------------------
68 ; Font TINY character folding... 74 ; Font TINY character folding...
69 aa_char_0: 75 aa_char_0:
70 movlw LOW aa_font16_block 76 movlw LOW aa_font16_block
71 movwf TBLPTRL 77 movwf TBLPTRL
72 movlw HIGH aa_font16_block 78 movlw HIGH aa_font16_block
73 movwf TBLPTRH 79 movwf TBLPTRH
74 movlw UPPER aa_font16_block 80 movlw UPPER aa_font16_block
75 movwf TBLPTRU 81 movwf TBLPTRU
76 bra aa_char_99 82 bra aa_char_99
77 83
78 ; SMALL font --------------------------------------------------------- 84 ; 1: SMALL font ------------------------------------------------------
79 ; Font SMALL character folding... 85 ; Font SMALL character folding...
80 aa_char_1: 86 aa_char_1:
81 decfsz WREG ; requested small font? 87 decfsz WREG ; requested small font?
82 bra aa_char_2 ; NO 88 bra aa_char_2 ; NO
83 movlw LOW aa_font28_block 89 movlw LOW aa_font28_block
84 movwf TBLPTRL 90 movwf TBLPTRL
85 movlw HIGH aa_font28_block 91 movlw HIGH aa_font28_block
86 movwf TBLPTRH 92 movwf TBLPTRH
87 movlw UPPER aa_font28_block 93 movlw UPPER aa_font28_block
88 movwf TBLPTRU 94 movwf TBLPTRU
89 bra aa_char_99 95 bra aa_char_99
90 96
91 ; STD font ----------------------------------------------------------- 97 ; 2: STD font --------------------------------------------------------
92 ; Font SMALL character folding... 98 ; Font STANDARD character folding...
93 aa_char_2: 99 aa_char_2:
94 decfsz WREG ; requested std font? 100 decfsz WREG ; requested std font?
95 bra aa_char_3 ; NO 101 bra aa_char_3 ; NO
96 movlw LOW aa_font36_block 102 movlw LOW aa_font34_block
97 movwf TBLPTRL 103 movwf TBLPTRL
98 movlw HIGH aa_font36_block 104 movlw HIGH aa_font34_block
99 movwf TBLPTRH 105 movwf TBLPTRH
100 movlw UPPER aa_font36_block 106 movlw UPPER aa_font34_block
101 movwf TBLPTRU 107 movwf TBLPTRU
102 bra aa_char_99 108 bra aa_char_99
103 109
104 ; MEDIUM font -------------------------------------------------------- 110 ; 3: MEDIUM font -----------------------------------------------------
105 aa_char_3: 111 aa_char_3:
106 decfsz WREG ; requested medium font? 112 decfsz WREG ; requested medium font?
107 bra aa_char_4 ; NO 113 bra aa_char_4 ; NO
108 movlw LOW aa_font48_block 114 movlw LOW aa_font48_block
109 movwf TBLPTRL 115 movwf TBLPTRL
110 movlw HIGH aa_font48_block 116 movlw HIGH aa_font48_block
111 movwf TBLPTRH 117 movwf TBLPTRH
112 movlw UPPER aa_font48_block 118 movlw UPPER aa_font48_block
113 movwf TBLPTRU 119 movwf TBLPTRU
114 bra aa_char_99 120 bra aa_char_99
115 121
116 ; LARGE font --------------------------------------------------------- 122 ; 4: LARGE font ------------------------------------------------------
117 aa_char_4: 123 aa_char_4:
118 ; no to all above - must be large font then... 124 IFDEF _huge_font
119 movlw LOW aa_font90_block 125 decfsz WREG ; requested large font?
120 movwf TBLPTRL 126 bra aa_char_5 ; NO
121 movlw HIGH aa_font90_block 127 ENDIF
128 movlw LOW aa_font90_block
129 movwf TBLPTRL
130 movlw HIGH aa_font90_block
122 movwf TBLPTRH 131 movwf TBLPTRH
123 movlw UPPER aa_font90_block 132 movlw UPPER aa_font90_block
124 movwf TBLPTRU 133 movwf TBLPTRU
134 bra aa_char_99
135
136 IFDEF _huge_font
137 ; 5: XTRA LARGE font -------------------------------------------------
138 aa_char_5:
139 movlw LOW aa_font92_block
140 movwf TBLPTRL
141 movlw HIGH aa_font92_block
142 movwf TBLPTRH
143 movlw UPPER aa_font92_block
144 movwf TBLPTRU
145 ENDIF
125 146
126 ; Execute font block ------------------------------------------------- 147 ; Execute font block -------------------------------------------------
127 aa_char_99: 148 aa_char_99:
128 ; This is safe if the three fonts are in the same code segment 149 ; This is safe if all fonts are in the same code segment
129 ; (and that segment do not span the 64K edge...) 150 ; (and that segment does not span the 64K edge...)
130 movlw UPPER aa_font16_block 151 movlw UPPER aa_font16_block
131 movwf TBLPTRU 152 movwf TBLPTRU
132 153
133 ; Proceed to character substitutions 154 ; Proceed to character substitutions
134 aa_char_30: 155 aa_char_30:
135 tblrd*+ ; read FROM char 156 tblrd*+ ; read FROM char
136 movf TABLAT,W ; get it, and set Z,N 157 movf TABLAT,W ; get it, and set Z,N
137 bz aa_char_32 ; break at end of translations 158 bz aa_char_32 ; branch if end of translation table reached
138 159
139 tblrd*+ ; read TO char 160 tblrd*+ ; read TO char
140 cpfseq PRODL ; FROM == current char ? 161 cpfseq PRODL ; FROM == current char ?
141 bra aa_char_30 ; different -> loop 162 bra aa_char_30 ; different -> loop
142 movff TABLAT, PRODL ; make substitution 163 movff TABLAT, PRODL ; make substitution
152 tblrd*+ ; read default char 173 tblrd*+ ; read default char
153 cpfslt PRODL ; char > WREG ? 174 cpfslt PRODL ; char > WREG ?
154 movff TABLAT,PRODL ; replace PRODL 175 movff TABLAT,PRODL ; replace PRODL
155 176
156 ; Decode font height and anti-aliasing mode 177 ; Decode font height and anti-aliasing mode
157 clrf aa_flags ; default to no AA 178 bcf aa_antialias ; default to no AA
158 tblrd*+ ; read font height + AA flag 179 tblrd*+ ; read font height + AA flag
159 movf TABLAT,W ; into WREG 180 movf TABLAT,W ; into WREG
160 bnn aa_char_34 ; high bit set ? 181 bnn aa_char_34 ; high bit set ?
161 bsf aa_antialias ; YES - then the font is AA 182 bsf aa_antialias ; YES - then the font is AA
162 aa_char_34: 183 aa_char_34:
182 tblrd*+ 203 tblrd*+
183 movff TABLAT,aa_end+1 ; and high byte 204 movff TABLAT,aa_end+1 ; and high byte
184 205
185 return 206 return
186 207
208
187 ;------------------------------------------------------------------------------ 209 ;------------------------------------------------------------------------------
188 ; Character width 210 ; Character width
189 ; Inputs aa_start, aa_end, win_width, win_height, aa_flags 211 ; Input aa_start, aa_end, win_width, win_height, AA_flags
190 ; Output width added to win_width 212 ; Output width added to win_width
191 ; Trashed aa_bitlen, TBLPTR, TABLAT 213 ; Trashed aa_bitlen, TBLPTR, TABLAT
192 ; 214 ;
193 aa_char_width: 215 aa_char_width:
194 movff aa_start+0, TBLPTRL ; TBLPTR = aa_start 216 movff aa_start+0, TBLPTRL ; TBLPTR = aa_start
195 movff aa_start+1, TBLPTRH 217 movff aa_start+1, TBLPTRH
196 clrf aa_bitlen ; clear reminders... 218 clrf aa_bitlen ; clear reminders...
243 movf TBLPTRH,W 265 movf TBLPTRH,W
244 cpfseq aa_end+1 ; loop to if HIGH is different 266 cpfseq aa_end+1 ; loop to if HIGH is different
245 bra aa_char_width_1 267 bra aa_char_width_1
246 return 268 return
247 269
270
248 ;------------------------------------------------------------------------------ 271 ;------------------------------------------------------------------------------
249 ; String width 272 ; String width
250 ; Inputs buffer (SHOULD BE NULL TERMINATED) 273 ; Input buffer (SHOULD BE NULL TERMINATED)
251 ; Output win_width, win_height 274 ; Output win_width, win_height
252 ; Trashed PROD, TBLPTR, FSR2, aa_bitlen, aa_start, aa_end, aa_flags 275 ; Trashed PROD, TBLPTR, FSR2, aa_bitlen, aa_start, aa_end, AA_flags
253 ; 276 ;
254 aa_string_width: 277 aa_string_width:
255 lfsr FSR2, buffer ; FSR2 pointer to start of string 278 lfsr FSR2, buffer ; FSR2 pointer to start of string
256 clrf win_width+0 ; clear width sum 279 clrf win_width+0 ; clear width sum
257 clrf win_width+1 ; (16 bit counter) 280 clrf win_width+1 ; (16 bit counter)
265 bra aa_string_width_1 ; and loop 288 bra aa_string_width_1 ; and loop
266 289
267 aa_string_width99: 290 aa_string_width99:
268 return 291 return
269 292
293
270 ;------------------------------------------------------------------------------ 294 ;------------------------------------------------------------------------------
271 ; Decode a compressed char. 295 ; Decode a compressed char
272 ; Inputs aa_start, aa_end, win_height, win_invert, win_color1, win_color2 296 ; Input aa_start, aa_end, win_height, win_invert, win_color1, win_color2
273 ; Output none 297 ; Output none
274 ; Trashed TBLPTR, TABLAT, PROD, aa_bitlen, aa_flags, aa_colorDir:2 298 ; Trashed TBLPTR, TABLAT, PROD, aa_bitlen, AA_flags, aa_colorDir:2
275 ; 299 ;
276 aa_decode_char: 300 aa_decode_char:
277 movff aa_start+0, TBLPTRL ; TBLPTR = aa_start 301 movff aa_start+0, TBLPTRL ; TBLPTR = aa_start
278 movff aa_start+1, TBLPTRH 302 movff aa_start+1, TBLPTRH
279 303
318 ; This have to be done before inverse video, because 342 ; This have to be done before inverse video, because
319 ; of the asymmetric processing! 343 ; of the asymmetric processing!
320 bn aa_decode_13 ; decode as none-aa 344 bn aa_decode_13 ; decode as none-aa
321 345
322 ; Manage 000 special case too: 346 ; Manage 000 special case too:
323 andlw 0xE0 ; select color bits 347 andlw 0xE0 ; select color bits, is it a 000 ?
324 bz aa_decode_13 ; that's a 000 ! 348 bz aa_decode_13 ; YES
325 349
326 ; Apply reverse video, in a reversed way 350 ; Apply reverse video, in a reversed way
327 btfss win_invert ; inverse video mode? 351 btfss win_invert ; inverse video mode?
328 sublw 0x80 ; NO 352 sublw 0x80 ; NO
329 353
330 ; Move the two bits to aa_color_half and aa_color_quarter: 354 ; Extract color quarter and color half information
331 swapf WREG ; --> 0000.0LL0 byte 355 bsf aa_antialias ; set AA mode
332 iorlw b'001' ; we are in AA mode, don't forget it! 356 bcf aa_color_quarter ; default to no color quarter
333 movwf aa_flags ; save that to aa_color_(half/quad)/AA flags 357 btfsc WREG,5 ; color quarter encoded?
358 bsf aa_color_quarter ; YES - set flag
359 bcf aa_color_half ; default to no color half
360 btfsc WREG,6 ; color half encoded?
361 bsf aa_color_half ; YES - set flag
334 362
335 ;---- 2 bit x RGB(16bits) computation -------------------------------- 363 ;---- 2 bit x RGB(16bits) computation --------------------------------
336 clrf PRODL ; we will accumulate result here... 364 clrf PRODL ; we will accumulate result here...
337 clrf PRODH 365 clrf PRODH
338 366
348 bra aa_decode_12 376 bra aa_decode_12
349 377
350 movff aa_temp+0,PRODH ; add color/2 if bit set 378 movff aa_temp+0,PRODH ; add color/2 if bit set
351 movff aa_temp+1,PRODL ; TFT is big endian, so swap here 379 movff aa_temp+1,PRODL ; TFT is big endian, so swap here
352 aa_decode_12: 380 aa_decode_12:
353 btfss aa_color_quart 381 btfss aa_color_quarter
354 bra aa_decode_3 382 bra aa_decode_3
355 383
356 ; Divide it once again by 2. Max red = 7/31. 384 ; Divide it once again by 2. Max red = 7/31.
357 rrcf aa_temp+0,W ; xxRRRxxG 385 rrcf aa_temp+0,W ; xxRRRxxG
358 andlw b'00111001' ; 00RRR00G (don't change C) 386 andlw b'00111001' ; 00RRR00G (don't change C)
364 movf aa_temp+1,W ; add color/4 392 movf aa_temp+1,W ; add color/4
365 addwf PRODL,F ; NOTE: 7/31+15/31=22/31, 393 addwf PRODL,F ; NOTE: 7/31+15/31=22/31,
366 movf aa_temp+0,W ; hence components won't overlap 394 movf aa_temp+0,W ; hence components won't overlap
367 addwfc PRODH,F ; in right order, to propagate carry 395 addwfc PRODH,F ; in right order, to propagate carry
368 396
369 aa_decode_12b: 397 aa_decode_12b:
370 btfss screen_type2 ; Display 2? 398 btfss screen_type2 ; display 2?
371 bra aa_decode_3 ; No, Done. 399 bra aa_decode_3 ; NO - done
372 400
373 call convert_for_display2 ; Convert 16Bit RGB b'RRRRRGGG GGGBBBBB' into 24Bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00' 401 call convert_for_display2 ; convert 16 bit RGB b'RRRRRGGG GGGBBBBB' into 24 bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00'
374 402
375 bra aa_decode_3 ; Done. 403 bra aa_decode_3 ; done
376 404
377 ; ---- Simple BLACK and WHITE cases ------------------------------ 405 ; ---- Simple BLACK and WHITE cases ------------------------------
378 aa_decode_13: ; Got a 1xx or a 000 code... 406 aa_decode_13: ; got a 1xx or a 000 code...
379 btfsc win_invert ; Inverse video mode ? 407 btfsc win_invert ; inverse video mode ?
380 xorlw 0x80 ; YES: invert levels. 408 xorlw 0x80 ; YES - invert levels
381 bn aa_decode_2 ; Then test high bit. 409 bn aa_decode_2 ; then test high bit
382 410
383 ; WHITE pixel (ie. full color) 411 ; WHITE pixel (i.e. full color)
384 movff win_color1,PRODH ; current draw color 412 movff win_color1,PRODH ; current draw color
385 movff win_color2,PRODL ; (rem: DISPLAY is big endian) 413 movff win_color2,PRODL ; remark: DISPLAY is big endian
386 bra aa_decode_12b 414 bra aa_decode_12b
387 415
388 aa_decode_2: 416 aa_decode_2:
389 clrf PRODH ; BLACK pixel 417 clrf PRODH ; BLACK pixel
390 clrf PRODL 418 clrf PRODL
391 clrf win_color5 419 clrf win_color5
392 clrf win_color4 420 clrf win_color4
393 clrf win_color3 421 clrf win_color3
394 422
395 aa_decode_3: 423 aa_decode_3:
396 ;---- PIXEL WRITE LOOP ----------------------------------------------- 424 ;---- PIXEL WRITE LOOP -----------------------------------------------
397 bsf tft_rs ; Data! 425 bsf tft_rs ; Data!
398 426
399 btfsc screen_type2 ; Display 2? 427 btfsc screen_type2 ; display 2 ?
400 bra aa_decode_3_display2 ; Yes 428 bra aa_decode_3_display2 ; YES
401 429
402 movff PRODH,PORTA ; Move high byte to PORTA 430 movff PRODH,PORTA ; move high byte to PORTA
403 movff PRODL,PORTH ; Move low byte to PORTH 431 movff PRODL,PORTH ; move low byte to PORTH
404 aa_decode_3_display0and1: 432 aa_decode_3_display0and1:
405 bcf tft_nwr 433 bcf tft_nwr
406 bsf tft_nwr ; Tick 434 bsf tft_nwr ; tick
407 decf aa_bitlen,F 435 decf aa_bitlen,F
408 bnz aa_decode_3_display0and1 436 bnz aa_decode_3_display0and1
409 bra aa_decode_3_done 437 bra aa_decode_3_done
410 438
411 aa_decode_3_display2: 439 aa_decode_3_display2:
412 movff win_color5,PORTH ; Move high byte to PORTH (DISPLAY is bigendian) 440 movff win_color5,PORTH ; move high byte to PORTH (DISPLAY is big endian)
413 bcf tft_nwr 441 bcf tft_nwr
414 bsf tft_nwr ; Tick 442 bsf tft_nwr ; tick
415 movff win_color4,PORTH ; Move low byte to PORTH 443 movff win_color4,PORTH ; move low byte to PORTH
416 bcf tft_nwr 444 bcf tft_nwr
417 bsf tft_nwr ; Tick 445 bsf tft_nwr ; tick
418 movff win_color3,PORTH ; Move low(est) byte to PORTH 446 movff win_color3,PORTH ; move low(est) byte to PORTH
419 bcf tft_nwr 447 bcf tft_nwr
420 bsf tft_nwr ; Tick 448 bsf tft_nwr ; tick
421 decf aa_bitlen,F 449 decf aa_bitlen,F
422 bnz aa_decode_3_display2 450 bnz aa_decode_3_display2
423 451
424 aa_decode_3_done: 452 aa_decode_3_done:
425 ;---- BYTE-CODE LOOP ------------------------------------------------- 453 ;---- BYTE-CODE LOOP -------------------------------------------------
426 ; Are we done ? 454 ; are we done ?
427 movf TBLPTRL,W ; Compare TBLPTR to aa_end 455 movf TBLPTRL,W ; compare TBLPTR with aa_end
428 cpfseq aa_end+0 456 cpfseq aa_end+0
429 bra aa_decode_1 ; Loop if LOW is different 457 bra aa_decode_1 ; loop if LOW is different
430 movf TBLPTRH,W 458 movf TBLPTRH,W
431 cpfseq aa_end+1 ; Loop to if HIGH is different 459 cpfseq aa_end+1 ; loop to if HIGH is different
432 bra aa_decode_1 460 bra aa_decode_1
433 return 461 return
462
434 463
435 ;------------------------------------------------------------------------------ 464 ;------------------------------------------------------------------------------
436 ; Setup pointers for a char: 465 ; Setup pointers for a char:
437 ; Inputs : buffer : string to print (SHOULD BE NULL TERMINATED) 466 ; Inputs : buffer : string to print (NULL TERMINATED)
438 ; Output : TFT commands on port D + clocks. 467 ; Output : TFT commands on port D + clocks
439 ; 468 ;
440 global aa_wordprocessor ; callable from C-code 469 global aa_wordprocessor ; callable from C-code
441 aa_wordprocessor: 470 aa_wordprocessor:
442 banksel win_font ; bank1, just to be sure
443 rcall aa_string_width ; set win_height, compute win_width:2 471 rcall aa_string_width ; set win_height, compute win_width:2
444 call TFT_box_write ; use that for the box 472 call TFT_box_write ; use that for the box
445 473
446 ; Restart the loop for each char to print 474 ; Restart the loop for each char to print
447 lfsr FSR2, buffer ; FSR2 pointer to start of string 475 lfsr FSR2, buffer ; FSR2 points to the start of the string
448 476
449 ; DATA block command 477 ; DATA block command
450 Index_out 0x22 ; index_out is a macro defined in tft.inc 478 Index_out 0x22 ; index_out is a macro defined in tft.inc
451 479
452 aa_wordprocessor_1: 480 aa_wordprocessor_1:
453 movf POSTINC2,W ; WREG = *FSR2++ 481 movf POSTINC2,W ; WREG = *FSR2++
454 bz aa_wordprocessor_99 ; exit if null byte encountered 482 bz aa_wordprocessor_99 ; exit if null byte encountered
455 483
456 rcall aa_char_setup ; setup aa_start / aa_end 484 rcall aa_char_setup ; setup aa_start / aa_end
457 rcall aa_decode_char ; write pixels to screen 485 rcall aa_decode_char ; write pixels to screen
458 bra aa_wordprocessor_1 ; and loop 486 bra aa_wordprocessor_1 ; and loop