0
|
1 ;=============================================================================
|
|
2 ;
|
604
|
3 ; File aa_wordprocessor.asm ## V2.99e
|
0
|
4 ;
|
|
5 ; Anti-aliased word processor
|
|
6 ;
|
|
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
|
|
8 ;=============================================================================
|
|
9 ; HISTORY
|
604
|
10 ; 2010-11-22 : [jDG] Creation
|
|
11 ; 2010-12-01 : [jDG] Adding 3bits anti-aliased fonts
|
0
|
12 ; 2010-12-30 : [jDG] Revised to put temp into ACCESSRAM0
|
|
13 ; 2012-08-12 : [mH] Moved font28 into bootloader section 0x1C000
|
|
14 ;
|
|
15 ; BUGS :
|
|
16 ; * If the three fonts are not in the same half of the PROM memory, TBLPTRU
|
582
|
17 ; will be badly set, and font48 or font90 will display gibberish...
|
0
|
18 ;=============================================================================
|
|
19 ;
|
|
20 ; MEMORY FOOTPRINT:
|
|
21 ;------------------
|
|
22 ;
|
582
|
23 ; wp_wordprocessor : 8 KB, including fonts
|
|
24 ; aa_wordprocessor : 0.5 KB code
|
|
25 ; + 3.5 KB aa_font28 (reduced to 99 chars)
|
|
26 ; + 1.6 KB aa_font48
|
|
27 ; + 2.2 KB aa_font90
|
|
28 ; = 7.9 KB including fonts
|
0
|
29 ;
|
|
30 ; Input registers:
|
582
|
31 ; buffer:26 String to print
|
|
32 ; win_font Font size (0=tiny, 1=small, 2=medium, 3=large)
|
|
33 ; win_color1:2 16bits unpacked color
|
|
34 ; win_top, win_leftx2 Position on screen
|
|
35 ; win_inverse Inverse video mode
|
0
|
36 ;
|
|
37 ; Available general purpose registers:
|
582
|
38 ; PRODH, PRODL needed for array indexing)
|
|
39 ; FSRx 12bits. Useful as RAM pointers.
|
0
|
40 ;=============================================================================
|
|
41
|
275
|
42 #include "hwos.inc"
|
0
|
43 #include "tft.inc"
|
|
44
|
582
|
45 extern aa_font16_block
|
|
46 extern aa_font28_block
|
|
47 extern aa_font36_block
|
|
48 extern aa_font48_block
|
|
49 extern aa_font90_block
|
0
|
50
|
608
|
51 extern convert_for_display2
|
|
52
|
604
|
53 aa_word CODE
|
|
54
|
0
|
55 ;------------------------------------------------------------------------------
|
|
56 ; Setup pointers for a char:
|
582
|
57 ; Inputs WREG = char to draw, win_font
|
|
58 ; Output aa_start, aa_end, win_height, aa_flags
|
|
59 ; Trashed PRODH, PRODL, TBLPTR, TABLAT
|
0
|
60 ;
|
604
|
61
|
0
|
62 aa_char_setup:
|
582
|
63 movwf PRODL ; save char into PROD for now
|
604
|
64 movf win_font,W ; get font number (updates Z flag)
|
582
|
65 bnz aa_char_1
|
0
|
66
|
582
|
67 ; TINY font ---------------------------------------------------------
|
|
68 ; Font TINY character folding...
|
0
|
69 aa_char_0:
|
582
|
70 movlw LOW aa_font16_block
|
|
71 movwf TBLPTRL
|
|
72 movlw HIGH aa_font16_block
|
|
73 movwf TBLPTRH
|
|
74 movlw UPPER aa_font16_block
|
|
75 movwf TBLPTRU
|
|
76 bra aa_char_99
|
0
|
77
|
582
|
78 ; SMALL font ---------------------------------------------------------
|
|
79 ; Font SMALL character folding...
|
|
80 aa_char_1:
|
604
|
81 decfsz WREG ; requested small font?
|
|
82 bra aa_char_2 ; NO
|
582
|
83 movlw LOW aa_font28_block
|
|
84 movwf TBLPTRL
|
|
85 movlw HIGH aa_font28_block
|
|
86 movwf TBLPTRH
|
|
87 movlw UPPER aa_font28_block
|
|
88 movwf TBLPTRU
|
|
89 bra aa_char_99
|
0
|
90
|
582
|
91 ; STD font -----------------------------------------------------------
|
|
92 ; Font SMALL character folding...
|
|
93 aa_char_2:
|
604
|
94 decfsz WREG ; requested std font?
|
|
95 bra aa_char_3 ; NO
|
582
|
96 movlw LOW aa_font36_block
|
|
97 movwf TBLPTRL
|
|
98 movlw HIGH aa_font36_block
|
|
99 movwf TBLPTRH
|
|
100 movlw UPPER aa_font36_block
|
|
101 movwf TBLPTRU
|
|
102 bra aa_char_99
|
0
|
103
|
582
|
104 ; MEDIUM font --------------------------------------------------------
|
0
|
105 aa_char_3:
|
604
|
106 decfsz WREG ; requested medium font?
|
|
107 bra aa_char_4 ; NO
|
582
|
108 movlw LOW aa_font48_block
|
|
109 movwf TBLPTRL
|
|
110 movlw HIGH aa_font48_block
|
|
111 movwf TBLPTRH
|
|
112 movlw UPPER aa_font48_block
|
|
113 movwf TBLPTRU
|
|
114 bra aa_char_99
|
0
|
115
|
582
|
116 ; LARGE font ---------------------------------------------------------
|
0
|
117 aa_char_4:
|
604
|
118 ; no to all above - must be large font then...
|
582
|
119 movlw LOW aa_font90_block
|
|
120 movwf TBLPTRL
|
|
121 movlw HIGH aa_font90_block
|
|
122 movwf TBLPTRH
|
|
123 movlw UPPER aa_font90_block
|
|
124 movwf TBLPTRU
|
0
|
125
|
582
|
126 ; Execute font block -------------------------------------------------
|
|
127 aa_char_99:
|
|
128 ; This is safe if the three fonts are in the same code segment
|
|
129 ; (and that segment do not span the 64K edge...)
|
|
130 movlw UPPER aa_font16_block
|
|
131 movwf TBLPTRU
|
|
132
|
|
133 ; Proceed to character substitutions
|
0
|
134 aa_char_30:
|
604
|
135 tblrd*+ ; read FROM char
|
|
136 movf TABLAT,W ; get it, and set Z,N
|
|
137 bz aa_char_32 ; break at end of translations
|
0
|
138
|
604
|
139 tblrd*+ ; read TO char
|
|
140 cpfseq PRODL ; FROM == current char ?
|
|
141 bra aa_char_30 ; different -> loop
|
582
|
142 movff TABLAT, PRODL ; make substitution
|
604
|
143 bra aa_char_30 ; loop
|
0
|
144
|
582
|
145 ; Make sure char is in the available range
|
|
146 aa_char_32:
|
604
|
147 tblrd*+ ; read first char
|
582
|
148 movf TABLAT,W ; get it
|
|
149 subwf PRODL,F ; (char - first) --> PRODL
|
604
|
150 tblrd*+ ; read nb chars
|
582
|
151 movf TABLAT,W ; nbchars --> WREG
|
604
|
152 tblrd*+ ; read default char
|
|
153 cpfslt PRODL ; char > WREG ?
|
582
|
154 movff TABLAT,PRODL ; replace PRODL
|
0
|
155
|
582
|
156 ; Decode font height and anti-aliasing mode
|
604
|
157 clrf aa_flags ; default to no AA
|
|
158 tblrd*+ ; read font height + AA flag
|
582
|
159 movf TABLAT,W ; into WREG
|
604
|
160 bnn aa_char_34 ; high bit set ?
|
|
161 bsf aa_antialias ; YES - then the font is AA
|
0
|
162 aa_char_34:
|
604
|
163 andlw 0x7F ; keep just font height,
|
|
164 movwf win_height ; then save it (its a register)
|
0
|
165
|
582
|
166 ; Set PROM pointer to the char index
|
604
|
167 movf PRODL,W ; read back char
|
582
|
168 mullw 2 ; PROD = 2*(char - base), TBLPTR=idx
|
|
169 movf PRODL,W
|
604
|
170 addwf TBLPTRL,F ; add into TBLPTR (low byte)
|
582
|
171 movf PRODH,W
|
|
172 addwfc TBLPTRH,F ; and high byte
|
0
|
173
|
582
|
174 ; Read start and stop pointers
|
|
175 tblrd*+ ; aa_start = PROM16(*tblptr++)
|
604
|
176 movff TABLAT,aa_start+0 ; read low byte
|
582
|
177 tblrd*+
|
|
178 movff TABLAT,aa_start+1 ; and high byte
|
0
|
179
|
582
|
180 tblrd*+ ; aa_end = PROM16(*tblptr++)
|
604
|
181 movff TABLAT,aa_end+0 ; read low byte
|
582
|
182 tblrd*+
|
|
183 movff TABLAT,aa_end+1 ; and high byte
|
0
|
184
|
582
|
185 return
|
0
|
186
|
|
187 ;------------------------------------------------------------------------------
|
|
188 ; Character width
|
|
189 ; Inputs aa_start, aa_end, win_width, win_height, aa_flags
|
|
190 ; Output width added to win_width
|
|
191 ; Trashed aa_bitlen, TBLPTR, TABLAT
|
|
192 ;
|
|
193 aa_char_width:
|
582
|
194 movff aa_start+0, TBLPTRL ; TBLPTR = aa_start
|
|
195 movff aa_start+1, TBLPTRH
|
|
196 clrf aa_bitlen ; clear reminders...
|
0
|
197
|
604
|
198 ; Read bitmap byte, and decode length:
|
0
|
199 aa_char_width_1:
|
582
|
200
|
|
201 ifdef AA_BYTE_SWAP
|
604
|
202 btg TBLPTRL ; toggle low ptr bit
|
0
|
203 tblrd*
|
604
|
204 movf TABLAT,W ; store to WREG
|
|
205 btg TBLPTRL ; get is back
|
582
|
206 tblrd*+ ; then increment (but trash TABLAT)
|
604
|
207 movwf TABLAT ; then restore copy to TABLAT
|
582
|
208 else
|
604
|
209 tblrd*+ ; normal read...
|
|
210 movf TABLAT,W ; store copy to WREG
|
582
|
211 endif
|
|
212
|
604
|
213 btfss aa_antialias ; anti-aliased font ?
|
|
214 bra aa_char_width_10 ; NO - always 7 bit count
|
0
|
215
|
604
|
216 bn aa_char_width_10 ; none-white pixels?
|
|
217 andlw 0x1F ; YES - 5 bit count
|
0
|
218 aa_char_width_10:
|
604
|
219 andlw 0x7F ; NO - 7 bit count
|
582
|
220 incf WREG ; WREG = repetition count
|
604
|
221 addwf aa_bitlen,F ; add remaining pixels from last code
|
582
|
222
|
604
|
223 movf win_height,W ; WREG -= height
|
582
|
224 negf WREG
|
0
|
225
|
582
|
226 ; This is a hand-made division by successive subtraction of height
|
0
|
227 aa_char_width_2:
|
604
|
228 addwf aa_bitlen,F ; try to subtract win_height
|
|
229 bn aa_char_width_3 ; if neg it was a bad idea...
|
0
|
230
|
604
|
231 infsnz win_width+0,F ; succeeded: do a 16 bit increment
|
582
|
232 incf win_width+1,F ; on the win_width counter
|
|
233 bra aa_char_width_2 ; and loop
|
0
|
234
|
|
235 aa_char_width_3:
|
582
|
236 negf WREG ; WREG = +height
|
604
|
237 addwf aa_bitlen,F ; restore true reminder
|
0
|
238
|
582
|
239 ; Are we done ?
|
604
|
240 movf TBLPTRL,W ; compare TBLPTR to aa_end
|
582
|
241 cpfseq aa_end+0
|
604
|
242 bra aa_char_width_1 ; loop if LOW is different
|
582
|
243 movf TBLPTRH,W
|
604
|
244 cpfseq aa_end+1 ; loop to if HIGH is different
|
582
|
245 bra aa_char_width_1
|
|
246 return
|
0
|
247
|
|
248 ;------------------------------------------------------------------------------
|
|
249 ; String width
|
582
|
250 ; Inputs buffer (SHOULD BE NULL TERMINATED)
|
|
251 ; Output win_width, win_height
|
|
252 ; Trashed PROD, TBLPTR, FSR2, aa_bitlen, aa_start, aa_end, aa_flags
|
0
|
253 ;
|
|
254 aa_string_width:
|
582
|
255 lfsr FSR2, buffer ; FSR2 pointer to start of string
|
604
|
256 clrf win_width+0 ; clear width sum
|
582
|
257 clrf win_width+1 ; (16 bit counter)
|
0
|
258
|
|
259 aa_string_width_1:
|
582
|
260 movf POSTINC2,W ; WREG = *FSR2++
|
604
|
261 bz aa_string_width99 ; exit if null byte encountered
|
0
|
262
|
582
|
263 rcall aa_char_setup ; setup aa_start / aa_end
|
|
264 rcall aa_char_width ; sum-up width into win_width
|
|
265 bra aa_string_width_1 ; and loop
|
0
|
266
|
|
267 aa_string_width99:
|
582
|
268 return
|
0
|
269
|
|
270 ;------------------------------------------------------------------------------
|
|
271 ; Decode a compressed char.
|
582
|
272 ; Inputs aa_start, aa_end, win_height, win_invert, win_color1, win_color2
|
|
273 ; Output none
|
|
274 ; Trashed TBLPTR, TABLAT, PROD, aa_bitlen, aa_flags, aa_colorDir:2
|
0
|
275 ;
|
|
276 aa_decode_char:
|
582
|
277 movff aa_start+0, TBLPTRL ; TBLPTR = aa_start
|
|
278 movff aa_start+1, TBLPTRH
|
0
|
279
|
582
|
280 ; Read bitmap byte, and decode color & length
|
0
|
281 aa_decode_1:
|
582
|
282
|
|
283 ifdef AA_BYTE_SWAP
|
604
|
284 btg TBLPTRL ; toggle low ptr bit
|
0
|
285 tblrd*
|
604
|
286 movf TABLAT,W ; store to WREG
|
|
287 btg TBLPTRL ; get is back
|
582
|
288 tblrd*+ ; then increment (but trash TABLAT)
|
604
|
289 movwf TABLAT ; then restore copy to TABLAT
|
582
|
290 else
|
604
|
291 tblrd*+ ; normal read...
|
|
292 movf TABLAT,W ; store copy to WREG
|
582
|
293 endif
|
0
|
294
|
604
|
295 btfss aa_antialias ; anti-aliased font?
|
|
296 bra aa_decode_10 ; NO - always 7 bit count
|
|
297 bn aa_decode_10 ; none-white pixels?
|
|
298 andlw 0x1F ; Yes - 5 bit count
|
582
|
299 aa_decode_10:
|
604
|
300 andlw 0x7F ; NO - 7 bit count
|
582
|
301 incf WREG
|
|
302 movwf aa_bitlen ; repetition count --> aa_bitlen
|
0
|
303
|
582
|
304 ;---- COLOR DECODING -------------------------------------------------
|
|
305 ;
|
|
306 ; Code Normal Inverse
|
604
|
307 ; 1xx 0% 100% : Managed by aa_decode_13
|
582
|
308 ; 011 25% 75%
|
|
309 ; 010 50% 50%
|
|
310 ; 001 75% 25%
|
604
|
311 ; 000 100% 0% : Managed by aa_decode_13, too
|
582
|
312 ;
|
604
|
313 movf TABLAT,W ; get back code
|
|
314 btfss aa_antialias ; anti-aliased font?
|
|
315 bra aa_decode_13 ; NO - 1 bit case
|
0
|
316
|
582
|
317 ; Asymmetry test: 1xx code is another case for 1bit color.
|
|
318 ; This have to be done before inverse video, because
|
604
|
319 ; of the asymmetric processing!
|
|
320 bn aa_decode_13 ; decode as none-aa
|
0
|
321
|
582
|
322 ; Manage 000 special case too:
|
604
|
323 andlw 0xE0 ; select color bits
|
|
324 bz aa_decode_13 ; that's a 000 !
|
582
|
325
|
|
326 ; Apply reverse video, in a reversed way
|
604
|
327 btfss win_invert ; inverse video mode?
|
|
328 sublw 0x80 ; NO
|
0
|
329
|
582
|
330 ; Move the two bits to aa_color_half and aa_color_quarter:
|
|
331 swapf WREG ; --> 0000.0LL0 byte
|
604
|
332 iorlw b'001' ; we are in AA mode, don't forget it!
|
582
|
333 movwf aa_flags ; save that to aa_color_(half/quad)/AA flags
|
0
|
334
|
582
|
335 ;---- 2 bit x RGB(16bits) computation --------------------------------
|
604
|
336 clrf PRODL ; we will accumulate result here...
|
582
|
337 clrf PRODH
|
0
|
338
|
582
|
339 ; Take color div 2 into aa_temp. Max red = 15/31
|
604
|
340 rrcf win_color1,W ; xRRRRxGG
|
582
|
341 andlw b'01111011' ; 0RRRR0GG (don't change C)
|
|
342 movwf aa_temp+0
|
604
|
343 rrcf win_color2,W ; GGGxBBBB
|
582
|
344 andlw b'11101111' ; GGG0BBBB
|
|
345 movwf aa_temp+1
|
0
|
346
|
582
|
347 btfss aa_color_half
|
|
348 bra aa_decode_12
|
0
|
349
|
604
|
350 movff aa_temp+0,PRODH ; add color/2 if bit set
|
582
|
351 movff aa_temp+1,PRODL ; TFT is big endian, so swap here
|
0
|
352 aa_decode_12:
|
582
|
353 btfss aa_color_quart
|
|
354 bra aa_decode_3
|
0
|
355
|
582
|
356 ; Divide it once again by 2. Max red = 7/31.
|
|
357 rrcf aa_temp+0,W ; xxRRRxxG
|
|
358 andlw b'00111001' ; 00RRR00G (don't change C)
|
|
359 movwf aa_temp+0
|
|
360 rrcf aa_temp+1,W ; GGGxxBBB
|
|
361 andlw b'11100111' ; GGG00BBB
|
|
362 movwf aa_temp+1
|
0
|
363
|
604
|
364 movf aa_temp+1,W ; add color/4
|
582
|
365 addwf PRODL,F ; NOTE: 7/31+15/31=22/31,
|
|
366 movf aa_temp+0,W ; hence components won't overlap
|
604
|
367 addwfc PRODH,F ; in right order, to propagate carry
|
0
|
368
|
608
|
369 aa_decode_12b:
|
|
370 btfss screen_type2 ; Display 2?
|
|
371 bra aa_decode_3 ; No, Done.
|
|
372
|
|
373 call convert_for_display2 ; Convert 16Bit RGB b'RRRRRGGG GGGBBBBB' into 24Bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00'
|
|
374
|
|
375 bra aa_decode_3 ; Done.
|
0
|
376
|
608
|
377 ; ---- Simple BLACK and WHITE cases ------------------------------
|
|
378 aa_decode_13: ; Got a 1xx or a 000 code...
|
|
379 btfsc win_invert ; Inverse video mode ?
|
|
380 xorlw 0x80 ; YES: invert levels.
|
|
381 bn aa_decode_2 ; Then test high bit.
|
0
|
382
|
608
|
383 ; WHITE pixel (ie. full color)
|
|
384 movff win_color1,PRODH ; current draw color
|
|
385 movff win_color2,PRODL ; (rem: DISPLAY is big endian)
|
|
386 bra aa_decode_12b
|
0
|
387
|
|
388 aa_decode_2:
|
608
|
389 clrf PRODH ; BLACK pixel
|
|
390 clrf PRODL
|
|
391 clrf win_color5
|
|
392 clrf win_color4
|
|
393 clrf win_color3
|
0
|
394
|
|
395 aa_decode_3:
|
608
|
396 ;---- PIXEL WRITE LOOP -----------------------------------------------
|
|
397 bsf tft_rs ; Data!
|
|
398
|
|
399 btfsc screen_type2 ; Display 2?
|
|
400 bra aa_decode_3_display2 ; Yes
|
582
|
401
|
608
|
402 movff PRODH,PORTA ; Move high byte to PORTA
|
|
403 movff PRODL,PORTH ; Move low byte to PORTH
|
|
404 aa_decode_3_display0and1:
|
|
405 bcf tft_nwr
|
|
406 bsf tft_nwr ; Tick
|
582
|
407 decf aa_bitlen,F
|
608
|
408 bnz aa_decode_3_display0and1
|
|
409 bra aa_decode_3_done
|
0
|
410
|
608
|
411 aa_decode_3_display2:
|
|
412 movff win_color5,PORTH ; Move high byte to PORTH (DISPLAY is bigendian)
|
|
413 bcf tft_nwr
|
|
414 bsf tft_nwr ; Tick
|
|
415 movff win_color4,PORTH ; Move low byte to PORTH
|
|
416 bcf tft_nwr
|
|
417 bsf tft_nwr ; Tick
|
|
418 movff win_color3,PORTH ; Move low(est) byte to PORTH
|
|
419 bcf tft_nwr
|
|
420 bsf tft_nwr ; Tick
|
|
421 decf aa_bitlen,F
|
|
422 bnz aa_decode_3_display2
|
|
423
|
|
424 aa_decode_3_done:
|
|
425 ;---- BYTE-CODE LOOP -------------------------------------------------
|
|
426 ; Are we done ?
|
|
427 movf TBLPTRL,W ; Compare TBLPTR to aa_end
|
|
428 cpfseq aa_end+0
|
|
429 bra aa_decode_1 ; Loop if LOW is different
|
|
430 movf TBLPTRH,W
|
|
431 cpfseq aa_end+1 ; Loop to if HIGH is different
|
|
432 bra aa_decode_1
|
|
433 return
|
0
|
434
|
|
435 ;------------------------------------------------------------------------------
|
|
436 ; Setup pointers for a char:
|
|
437 ; Inputs : buffer : string to print (SHOULD BE NULL TERMINATED)
|
|
438 ; Output : TFT commands on port D + clocks.
|
|
439 ;
|
604
|
440 global aa_wordprocessor ; callable from C-code
|
0
|
441 aa_wordprocessor:
|
604
|
442 banksel win_font ; bank1, just to be sure
|
|
443 rcall aa_string_width ; set win_height, compute win_width:2
|
|
444 call TFT_box_write ; use that for the box
|
0
|
445
|
582
|
446 ; Restart the loop for each char to print
|
|
447 lfsr FSR2, buffer ; FSR2 pointer to start of string
|
0
|
448
|
582
|
449 ; DATA block command
|
604
|
450 Index_out 0x22 ; index_out is a macro defined in tft.inc
|
0
|
451
|
|
452 aa_wordprocessor_1:
|
582
|
453 movf POSTINC2,W ; WREG = *FSR2++
|
604
|
454 bz aa_wordprocessor_99 ; exit if null byte encountered
|
0
|
455
|
582
|
456 rcall aa_char_setup ; setup aa_start / aa_end
|
|
457 rcall aa_decode_char ; write pixels to screen
|
|
458 bra aa_wordprocessor_1 ; and loop
|
0
|
459
|
|
460 aa_wordprocessor_99:
|
582
|
461 ; END of bloc command
|
|
462 Index_out 0x00
|
|
463 return
|
0
|
464
|
582
|
465 END
|