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