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