annotate src/aa_wordprocessor.asm @ 212:5fd93901b735

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