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