comparison code_part1/OSTC_code_asm_part1/aa_wordprocessor.asm @ 123:6a94f96e9cea

The big cleanup, again.
author JeanDo
date Thu, 30 Dec 2010 23:45:20 +0100
parents 14a074e1a375
children 8b75ba28d641
comparison
equal deleted inserted replaced
122:3003a8040b78 123:6a94f96e9cea
20 ; Copyright (c) 2010, JD Gascuel. 20 ; Copyright (c) 2010, JD Gascuel.
21 ;============================================================================= 21 ;=============================================================================
22 ; HISTORY 22 ; HISTORY
23 ; 2010-11-22 : [jDG] Creation. 23 ; 2010-11-22 : [jDG] Creation.
24 ; 2010-12-01 : [jDG] Adding 3bits antialiased fonts. 24 ; 2010-12-01 : [jDG] Adding 3bits antialiased fonts.
25 ; 2010-12-30 : [jDG] Revised to put temp into ACCESSRAM0
25 ; 26 ;
26 ; BUGS : 27 ; BUGS :
27 ; * If the three fonts are not in the same half of the PROM memory, TBLPTRU 28 ; * If the three fonts are not in the same half of the PROM memory, TBLPTRU
28 ; will be badly set, and font48 or font90 will display giberish... 29 ; will be badly set, and font48 or font90 will display giberish...
29 ;============================================================================= 30 ;=============================================================================
47 ; 48 ;
48 ; Available general purpose registers: 49 ; Available general purpose registers:
49 ; PRODH, PRODL (needed for array indexing) 50 ; PRODH, PRODL (needed for array indexing)
50 ; FSRx 12bits. Usefull as RAM pointers. 51 ; FSRx 12bits. Usefull as RAM pointers.
51 ;============================================================================= 52 ;=============================================================================
53 ; Temporary variables are overlayed in bank 0 ACCESS, used also by C-code
54 ; (p2_deco), MPLAB math abd stdlib libraries.
55
56 CBLOCK 0x000
57 aa_flags ; Various flags for aa_wordprocessor
58 aa_width:2 ; Width in pixels (0..319)
59 aa_bitlen ; Count of pixels when decoding bitmaps.
60 aa_start:2 ; PROM ptr to start of encoded bitmap
61 aa_end:2 ; and end of it.
62 aa_colorDiv:2 ; Current color, divided by 2 or 4
63 ENDC
52 64
53 ; Flags allocation: 65 ; Flags allocation:
54 #define aa_antialias aa_flags,0 66 #define aa_antialias aa_flags,0
55 #define aa_color_quart aa_flags,1 67 #define aa_color_quart aa_flags,1
56 #define aa_color_half aa_flags,2 68 #define aa_color_half aa_flags,2
57 69
58 ; Extracted from p3_wordprocessor includes:
59 #include aa_fonts.asm
60 aa_wp code ; Mark segment into the .map file
61
62 ;------------------------------------------------------------------------------ 70 ;------------------------------------------------------------------------------
63 ; Setup pointers for a char: 71 ; Setup pointers for a char:
64 ; Inputs WREG = char to draw, win_font 72 ; Inputs WREG = char to draw, win_font
65 ; Output aa_start, aa_end, aa_height, aa_flags 73 ; Output aa_start, aa_end, win_height, aa_flags
66 ; Trashed PRODH, PRODL, TBLPTR, TABLAT 74 ; Trashed PRODH, PRODL, TBLPTR, TABLAT
67 ; 75 ;
68 aa_char_setup: 76 aa_char_setup:
69 movwf PRODL,A ; save char into PROD for now. 77 movwf PRODL,A ; save char into PROD for now.
70 78
71 movf win_font,W,BANKED ; Get font number (updates Z flag) 79 movf win_font,W,BANKED ; Get font number (updates Z flag)
72 bnz aa_char_1 80 bnz aa_char_1
73 81
74 ; SMALL font ----------------------------------------------------- 82 ; SMALL font ---------------------------------------------------------
75 ; Font SMALL character folding... 83 ; Font SMALL character folding...
76 aa_char_0: 84 aa_char_0:
77 movlw LOW aa_font28_block 85 movlw LOW aa_font28_block
78 movwf TBLPTRL,A 86 movwf TBLPTRL,A
79 movlw HIGH aa_font28_block 87 movlw HIGH aa_font28_block
80 movwf TBLPTRH,A 88 movwf TBLPTRH,A
81 bra aa_char_3 89 bra aa_char_3
82 90
83 ; MEDIUM font ---------------------------------------------------- 91 ; MEDIUM font --------------------------------------------------------
84 aa_char_1: 92 aa_char_1:
85 decfsz WREG,A ; This is medium font ??? 93 decfsz WREG,A ; This is medium font ???
86 bra aa_char_2 94 bra aa_char_2
87 95
88 ; Font MEDIUM block: 96 ; Font MEDIUM block:
89 movlw LOW aa_font48_block 97 movlw LOW aa_font48_block
90 movwf TBLPTRL,A 98 movwf TBLPTRL,A
91 movlw HIGH aa_font48_block 99 movlw HIGH aa_font48_block
92 movwf TBLPTRH,A 100 movwf TBLPTRH,A
93 bra aa_char_3 101 bra aa_char_3
94 102
95 ; LARGE font ----------------------------------------------------- 103 ; LARGE font ---------------------------------------------------------
96 aa_char_2: 104 aa_char_2:
97 ; Font LARGE block: 105 ; Font LARGE block:
98 movlw LOW aa_font90_block 106 movlw LOW aa_font90_block
99 movwf TBLPTRL,A 107 movwf TBLPTRL,A
100 movlw HIGH aa_font90_block 108 movlw HIGH aa_font90_block
101 movwf TBLPTRH,A 109 movwf TBLPTRH,A
102 110
103 ; Execute font block --------------------------------------------- 111 ; Execute font block -------------------------------------------------
104 aa_char_3: 112 aa_char_3:
105 ; This is safe iff the three fonts are in the same code segment 113 ; This is safe iff the three fonts are in the same code segment
106 ; (and that segment do not span the 64K edge...) 114 ; (and that segment do not span the 64K edge...)
107 movlw UPPER aa_font28_block 115 movlw UPPER aa_font28_block
108 movwf TBLPTRU,A 116 movwf TBLPTRU,A
109 117
110 ; Proceed to character substitutions 118 ; Proceed to character substitutions
111 aa_char_30: 119 aa_char_30:
112 tblrd*+ ; Read FROM char 120 tblrd*+ ; Read FROM char
113 movf TABLAT,W ; Get it, and set Z,N 121 movf TABLAT,W ; Get it, and set Z,N
114 bz aa_char_32 ; Break at end of translations 122 bz aa_char_32 ; Break at end of translations
115 123
116 tblrd*+ ; Read TO char 124 tblrd*+ ; Read TO char
117 cpfseq PRODL,A ; FROM == current char ? 125 cpfseq PRODL,A ; FROM == current char ?
118 bra aa_char_30 ; Different: loop 126 bra aa_char_30 ; Different: loop
119 movff TABLAT, PRODL ; make substitution 127 movff TABLAT, PRODL ; make substitution
120 bra aa_char_30 ; Loop. 128 bra aa_char_30 ; Loop.
121 129
122 ; Make sure char is in the available range 130 ; Make sure char is in the available range
123 aa_char_32: 131 aa_char_32:
124 tblrd*+ ; Read first char 132 tblrd*+ ; Read first char
125 movf TABLAT,W ; get it. 133 movf TABLAT,W ; get it.
126 subwf PRODL,F ; (char - first) --> PRODL 134 subwf PRODL,F ; (char - first) --> PRODL
127 135
128 tblrd*+ ; Read nb chars 136 tblrd*+ ; Read nb chars
129 movf TABLAT,W ; nbchars --> WREG 137 movf TABLAT,W ; nbchars --> WREG
130 tblrd*+ ; Read default char 138 tblrd*+ ; Read default char
131 cpfslt PRODL ; if char > WREG ? 139 cpfslt PRODL ; if char > WREG ?
132 movff TABLAT,PRODL ; replace PRODL 140 movff TABLAT,PRODL ; replace PRODL
133 141
134 ; Decode font height and anti-aliasing mode 142 ; Decode font height and anti-aliasing mode
135 clrf aa_flags,BANKED ; Default to no AA 143 clrf aa_flags,ACCESS ; Default to no AA
136 tblrd*+ ; Read font height + AA flag 144 tblrd*+ ; Read font height + AA flag
137 movf TABLAT,W ; into WREG 145 movf TABLAT,W ; into WREG
138 bnn aa_char_34 ; High bit set ? 146 bnn aa_char_34 ; High bit set ?
139 bsf aa_antialias,BANKED ; YES : then the font is AA. 147 bsf aa_antialias,ACCESS ; YES : then the font is AA.
140 aa_char_34 148 aa_char_34:
141 andlw 0x7F ; Keep just font height, 149 andlw 0x7F ; Keep just font height,
142 movwf aa_height,BANKED ; then save it (its a register) 150 movwf win_height,BANKED ; then save it (its a register)
143 151
144 ; Set PROM pointer to the char index 152 ; Set PROM pointer to the char index
145 movf PRODL,W ; Read back char 153 movf PRODL,W ; Read back char
146 mullw 2 ; PROD = 2*(char - base), TBLPTR=idx 154 mullw 2 ; PROD = 2*(char - base), TBLPTR=idx
147 movf PRODL,W 155 movf PRODL,W
148 addwf TBLPTRL,F ; Add into TBLPTR (low byte) 156 addwf TBLPTRL,F ; Add into TBLPTR (low byte)
149 movf PRODH,W 157 movf PRODH,W
150 addwfc TBLPTRH,F ; and high byte. 158 addwfc TBLPTRH,F ; and high byte.
151 159
152 ; Read start and stop pointers 160 ; Read start and stop pointers
153 tblrd*+ ; aa_start = PROM16(*tblptr++) 161 tblrd*+ ; aa_start = PROM16(*tblptr++)
154 movff TABLAT,aa_start ; Read low byte 162 movff TABLAT,aa_start+0 ; Read low byte
155 tblrd*+ 163 tblrd*+
156 movff TABLAT,aa_start+1 ; and high byte 164 movff TABLAT,aa_start+1 ; and high byte
157 165
158 tblrd*+ ; aa_end = PROM16(*tblptr++) 166 tblrd*+ ; aa_end = PROM16(*tblptr++)
159 movff TABLAT,aa_end ; Read low byte 167 movff TABLAT,aa_end+0 ; Read low byte
160 tblrd*+ 168 tblrd*+
161 movff TABLAT,aa_end+1 ; and high byte 169 movff TABLAT,aa_end+1 ; and high byte
162 170
163 return 171 return
164 172
165 ;------------------------------------------------------------------------------ 173 ;------------------------------------------------------------------------------
166 ; Character width 174 ; Character width
167 ; Inputs aa_start, aa_end, aa_width, aa_height, aa_flags 175 ; Inputs aa_start, aa_end, aa_width, win_height, aa_flags
168 ; Output width added to aa_width 176 ; Output width added to aa_width
169 ; Trashed aa_bitlen, TBLPTR, TABLAT 177 ; Trashed aa_bitlen, TBLPTR, TABLAT
170 ; 178 ;
171 aa_char_width: 179 aa_char_width:
172 movff aa_start, TBLPTRL ; TBLPTR = aa_start 180 movff aa_start+0, TBLPTRL ; TBLPTR = aa_start
173 movff aa_start+1, TBLPTRH 181 movff aa_start+1, TBLPTRH
174 clrf aa_bitlen,BANKED ; clear reminders... 182 clrf aa_bitlen,ACCESS ; clear reminders...
175 183
176 ; Read bitmap byte, and decode length: 184 ; Read bitmap byte, and decode length:
177 aa_char_width_1: 185 aa_char_width_1:
178 ifdef AA_BYTE_SWAP 186 ifdef AA_BYTE_SWAP
179 btg TBLPTRL,0,A ; Toggle low ptr bit. 187 btg TBLPTRL,0,A ; Toggle low ptr bit.
180 tblrd* 188 tblrd*
181 movf TABLAT,W,A ; Store to WREG 189 movf TABLAT,W,A ; Store to WREG
182 btg TBLPTRL,0,A ; Get is back 190 btg TBLPTRL,0,A ; Get is back
183 tblrd*+ ; then increment (but trash TABLAT) 191 tblrd*+ ; then increment (but trash TABLAT)
184 movwf TABLAT,A ; Then restore copy to TABLAT. 192 movwf TABLAT,A ; Then restore copy to TABLAT.
185 else 193 else
186 tblrd*+ ; Normal read... 194 tblrd*+ ; Normal read...
187 movf TABLAT,W,A ; Store copy to WREG 195 movf TABLAT,W,A ; Store copy to WREG
188 endif 196 endif
189 btfss aa_antialias,BANKED ; Antialiased font ? 197 btfss aa_antialias,ACCESS ; Antialiased font ?
190 bra aa_char_width_10 ; No: always 7 bits count 198 bra aa_char_width_10 ; No: always 7 bits count
191 199
192 bn aa_char_width_10 ; Non-white pixels ? 200 bn aa_char_width_10 ; Non-white pixels ?
193 andlw 0x1F ; Yes : 5 bits count. 201 andlw 0x1F ; Yes : 5 bits count.
194 aa_char_width_10: 202 aa_char_width_10:
195 andlw 0x7F ; No: 7 bit count. 203 andlw 0x7F ; No: 7 bit count.
196 incf WREG,A ; WREG = repetition count 204 incf WREG,A ; WREG = repetition count
197 addwf aa_bitlen,F,BANKED ; Add remaining pixels from last code. 205 addwf aa_bitlen,F,ACCESS ; Add remaining pixels from last code.
198 206
199 movf aa_height,W,BANKED ; WREG = - height 207 movf win_height,W,BANKED ; WREG = - height
200 negf WREG,A 208 negf WREG,A
201 209
202 ; This is a hand-made division by successive substraction of height 210 ; This is a hand-made division by successive substraction of height
203 aa_char_width_2: 211 aa_char_width_2:
204 addwf aa_bitlen,F,BANKED ; Try to substract aa_height 212 addwf aa_bitlen,F,ACCESS ; Try to substract win_height
205 bn aa_char_width_3 ; If neg it was a bad idea... 213 bn aa_char_width_3 ; If neg it was a bad idea...
206 214
207 infsnz aa_width,F,BANKED ; Succeded: do a 12bit increment 215 infsnz aa_width+0,F,ACCESS ; Succeded: do a 16bit increment
208 incf aa_width+1,F,BANKED ; on the aa_width counter. 216 incf aa_width+1,F,ACCESS ; on the aa_width counter.
209 bra aa_char_width_2 ; and loop. 217 bra aa_char_width_2 ; and loop.
210 218
211 aa_char_width_3: 219 aa_char_width_3:
212 negf WREG,A ; WREG = +height 220 negf WREG,A ; WREG = +height
213 addwf aa_bitlen,F,BANKED ; Restore true reminder. 221 addwf aa_bitlen,F,ACCESS ; Restore true reminder.
214 222
215 ; Are we done ? 223 ; Are we done ?
216 movf TBLPTRL,W,A ; Compare TBLPTR to aa_end 224 movf TBLPTRL,W,A ; Compare TBLPTR to aa_end
217 cpfseq aa_end,BANKED 225 cpfseq aa_end+0,ACCESS
218 bra aa_char_width_1 ; Loop if LOW is different 226 bra aa_char_width_1 ; Loop if LOW is different
219 movf TBLPTRH,W,A 227 movf TBLPTRH,W,A
220 cpfseq aa_end+1,BANKED ; Loop to if HIGH is different 228 cpfseq aa_end+1,ACCESS ; Loop to if HIGH is different
221 bra aa_char_width_1 229 bra aa_char_width_1
222 230
223 return 231 return
224 232
225 ;------------------------------------------------------------------------------ 233 ;------------------------------------------------------------------------------
226 ; String width 234 ; String width
227 ; Inputs letter (SHOULD BE NULL TERMINATED) 235 ; Inputs letter (SHOULD BE NULL TERMINATED)
228 ; Output aa_width, aa_height 236 ; Output aa_width, win_height
229 ; Trashed PROD, TBLPTR, FSR2, aa_bitlen, aa_start, aa_end, aa_flags 237 ; Trashed PROD, TBLPTR, FSR2, aa_bitlen, aa_start, aa_end, aa_flags
230 ; 238 ;
231 aa_string_width: 239 aa_string_width:
232 lfsr FSR2, letter ; FSR2 pointer to start of string. 240 lfsr FSR2, letter ; FSR2 pointer to start of string.
233 241
234 clrf aa_width,BANKED ; Clear width sum. 242 clrf aa_width+0,ACCESS ; Clear width sum.
235 clrf aa_width+1,BANKED ; (12 bit counter) 243 clrf aa_width+1,ACCESS ; (16 bit counter)
236 244
237 aa_string_width_1: 245 aa_string_width_1:
238 movf POSTINC2,W,A ; WREG = *FSR2++ 246 movf POSTINC2,W,A ; WREG = *FSR2++
239 bz aa_string_width99 ; Exit if null byte encountered. 247 bz aa_string_width99 ; Exit if null byte encountered.
240 248
241 rcall aa_char_setup ; setup aa_start / aa_end 249 rcall aa_char_setup ; setup aa_start / aa_end
242 rcall aa_char_width ; sum-up width into aa_width 250 rcall aa_char_width ; sum-up width into aa_width
243 bra aa_string_width_1 ; and loop. 251 bra aa_string_width_1 ; and loop.
244 252
245 aa_string_width99: 253 aa_string_width99:
246 return 254 return
247 255
248 ;------------------------------------------------------------------------------ 256 ;------------------------------------------------------------------------------
249 ; Fast macros to write to OLED display. 257 ; Fast macros to write to OLED display.
250 ; Adding a call/return adds 3 words and a pipeline flush, hence make it 258 ; Adding a call/return adds 3 words and a pipeline flush, hence make it
251 ; nearly twice slower... 259 ; nearly twice slower...
253 ; Input : commande as macro parameter. 261 ; Input : commande as macro parameter.
254 ; Output : NONE 262 ; Output : NONE
255 ; Trash : WREG 263 ; Trash : WREG
256 ; 264 ;
257 AA_CMD_WRITE macro cmd 265 AA_CMD_WRITE macro cmd
258 movlw cmd 266 movlw cmd
259 bcf oled_rs ; Cmd mode 267 rcall PLED_CmdWrite
260 movwf PORTD,A 268 ; bcf oled_rs ; Cmd mode
261 bcf oled_rw ; Tick the clock 269 ; movwf PORTD,A
262 bsf oled_rw 270 ; bcf oled_rw ; Tick the clock
263 endm 271 ; bsf oled_rw
272 endm
264 ; 273 ;
265 ; Input : PRODH:L as 16bits data. 274 ; Input : PRODH:L as 16bits data.
266 ; Output : NONE 275 ; Output : NONE
267 ; Trash : NONE 276 ; Trash : NONE
268 ; 277 ;
269 AA_DATA_WRITE_PROD macro 278 AA_DATA_WRITE_PROD macro
270 bsf oled_rs ; Data mode 279 rcall PLED_DataWrite_PROD
271 movff PRODH,PORTD ; NOTE: OLED is BIGENDIAN! 280 ; bsf oled_rs ; Data mode
272 bcf oled_rw ; Tick the clock 281 ; movff PRODH,PORTD ; NOTE: OLED is BIGENDIAN!
273 bsf oled_rw 282 ; bcf oled_rw ; Tick the clock
274 movff PRODL,PORTD 283 ; bsf oled_rw
275 bcf oled_rw ; Tick the clock 284 ; movff PRODL,PORTD
276 bsf oled_rw 285 ; bcf oled_rw ; Tick the clock
277 endm 286 ; bsf oled_rw
287 endm
278 288
279 ;------------------------------------------------------------------------------ 289 ;------------------------------------------------------------------------------
280 ; Output OLED Window Address commands. 290 ; Output OLED Window Address commands.
281 ; Inputs : win_top, win_leftx2, aa_height, aa_width. 291 ; Inputs : win_top, win_leftx2, win_height, aa_width.
282 ; Output : PortD commands. 292 ; Output : PortD commands.
283 ; Trashed: PROD 293 ; Trashed: PROD
284 ; 294 ;
285 aa_box_cmd: 295 aa_box_cmd:
286 movf win_leftx2,W,BANKED ; Compute left = 2*leftx2 296 movf win_leftx2,W,BANKED ; Compute left = 2*leftx2
287 mullw 2 297 mullw 2
288 AA_CMD_WRITE 0x35 ; this is the left border 298 AA_CMD_WRITE 0x35 ; this is the left border
289 AA_DATA_WRITE_PROD 299 AA_DATA_WRITE_PROD
290 300
291 movf aa_width,W,BANKED ; right = left + width - 1 301 movf aa_width+0,W,ACCESS ; right = left + width - 1
292 addwf PRODL,F,A 302 addwf PRODL,F,A
293 movf aa_width+1,W,BANKED 303 movf aa_width+1,W,ACCESS
294 addwfc PRODH,F,A 304 addwfc PRODH,F,A
295 decf PRODL,F,A ; decrement result 305 decf PRODL,F,A ; decrement result
296 bc aa_box_cmd_1 ; No borrow (/Carry) ? skip propagating. 306 bc aa_box_cmd_1 ; No borrow (/Carry) ? skip propagating.
297 decf PRODH,F,A 307 decf PRODH,F,A
298 aa_box_cmd_1: 308 aa_box_cmd_1:
299 AA_CMD_WRITE 0x36 ; Write and the right border 309 AA_CMD_WRITE 0x36 ; Write and the right border
300 AA_DATA_WRITE_PROD 310 AA_DATA_WRITE_PROD
301 311
302 movf win_top,W,BANKED ; Write top / bottom window 312 movf win_top,W,BANKED ; Write top / bottom window
303 movwf PRODH,A ; (remember PRODH output first) 313 movwf PRODH,A ; (remember PRODH output first)
304 addwf aa_height,W,BANKED 314 addwf win_height,W,BANKED
305 decf WREG,A 315 decf WREG,A
306 movwf PRODL,A ; And PRODL is later... 316 movwf PRODL,A ; And PRODL is later...
307 AA_CMD_WRITE 0x37 317 AA_CMD_WRITE 0x37
308 AA_DATA_WRITE_PROD 318 AA_DATA_WRITE_PROD
309 319
310 movf win_top,W,BANKED ; Start ptr top 320 movf win_top,W,BANKED ; Start ptr top
311 mullw 1 ; Load into PRODH:L 321 mullw 1 ; Load into PRODH:L
312 AA_CMD_WRITE 0x20 322 AA_CMD_WRITE 0x20
313 AA_DATA_WRITE_PROD 323 AA_DATA_WRITE_PROD
314 324
315 movf win_leftx2,W,BANKED ; Start ptr left 325 movf win_leftx2,W,BANKED ; Start ptr left
316 mullw 2 326 mullw 2
317 AA_CMD_WRITE 0x21 327 AA_CMD_WRITE 0x21
318 AA_DATA_WRITE_PROD 328 AA_DATA_WRITE_PROD
319 329
320 return 330 return
321 331
322 ;------------------------------------------------------------------------------ 332 ;------------------------------------------------------------------------------
323 ; Decode a compressed char. 333 ; Decode a compressed char.
324 ; Inputs aa_start, aa_end, aa_height, win_invert, win_color1, win_color2 334 ; Inputs aa_start, aa_end, win_height, win_invert, win_color1, win_color2
325 ; Output none 335 ; Output none
326 ; Trashed TBLPTR, TABLAT, PROD, aa_bitlen, aa_flags, aa_colorDir:2 336 ; Trashed TBLPTR, TABLAT, PROD, aa_bitlen, aa_flags, aa_colorDir:2
327 ; 337 ;
328 aa_decode_char: 338 aa_decode_char:
329 movff aa_start, TBLPTRL ; TBLPTR = aa_start 339 movff aa_start+0, TBLPTRL ; TBLPTR = aa_start
330 movff aa_start+1, TBLPTRH 340 movff aa_start+1, TBLPTRH
331 341
332 ; Read bitmap byte, and decode color & length 342 ; Read bitmap byte, and decode color & length
333 aa_decode_1: 343 aa_decode_1:
334 ifdef AA_BYTE_SWAP 344 ifdef AA_BYTE_SWAP
335 btg TBLPTRL,0,A ; Toggle low ptr bit. 345 btg TBLPTRL,0,A ; Toggle low ptr bit.
336 tblrd* 346 tblrd*
337 movf TABLAT,W,A ; Store to WREG 347 movf TABLAT,W,A ; Store to WREG
338 btg TBLPTRL,0,A ; Get is back 348 btg TBLPTRL,0,A ; Get is back
339 tblrd*+ ; then increment (but trash TABLAT) 349 tblrd*+ ; then increment (but trash TABLAT)
340 movwf TABLAT,A ; Then restore copy to TABLAT. 350 movwf TABLAT,A ; Then restore copy to TABLAT.
341 else 351 else
342 tblrd*+ ; Normal read... 352 tblrd*+ ; Normal read...
343 movf TABLAT,W,A ; Store copy to WREG 353 movf TABLAT,W,A ; Store copy to WREG
344 endif 354 endif
345 btfss aa_antialias,BANKED ; Antialiased font ? 355 btfss aa_antialias,ACCESS ; Antialiased font ?
346 bra aa_decode_10 ; No: always 7 bits count 356 bra aa_decode_10 ; No: always 7 bits count
347 bn aa_decode_10 ; Non-white pixels ? 357 bn aa_decode_10 ; Non-white pixels ?
348 andlw 0x1F ; Yes : 5 bits count. 358 andlw 0x1F ; Yes : 5 bits count.
349 aa_decode_10: 359 aa_decode_10:
350 andlw 0x7F ; No: 7 bit count. 360 andlw 0x7F ; No: 7 bit count.
351 incf WREG,A 361 incf WREG,A
352 movwf aa_bitlen,BANKED ; repetition count --> aa_bitlen 362 movwf aa_bitlen,ACCESS ; repetition count --> aa_bitlen
353 363
354 ;---- COLOR DECODING --------------------------------------------- 364 ;---- COLOR DECODING -------------------------------------------------
355 ; 365 ;
356 ; Code Normal Inverse 366 ; Code Normal Inverse
357 ; 1xx 0% 100% : Managed by aa_decode_13 367 ; 1xx 0% 100% : Managed by aa_decode_13
358 ; 011 25% 75% 368 ; 011 25% 75%
359 ; 010 50% 50% 369 ; 010 50% 50%
360 ; 001 75% 25% 370 ; 001 75% 25%
361 ; 000 100% 0% : Managed by aa_decode_13 too. 371 ; 000 100% 0% : Managed by aa_decode_13 too.
362 ; 372 ;
363 movf TABLAT,W,A ; Get back code 373 movf TABLAT,W,A ; Get back code
364 btfss aa_antialias,BANKED ; Antialiased font ? 374 btfss aa_antialias,ACCESS ; Antialiased font ?
365 bra aa_decode_13 ; NO: 1bit case 375 bra aa_decode_13 ; NO: 1bit case
366 376
367 ; Asymetry test: 1xx code is another case for 1bit color. 377 ; Asymetry test: 1xx code is another case for 1bit color.
368 ; This have to be done before inverse video, because 378 ; This have to be done before inverse video, because
369 ; of the asymetric processing ! 379 ; of the asymetric processing !
370 bn aa_decode_13 ; decode as not-aa 380 bn aa_decode_13 ; decode as not-aa
371 381
372 ; Manage 000 special case too: 382 ; Manage 000 special case too:
373 andlw 0xE0 ; Select color bits 383 andlw 0xE0 ; Select color bits
374 bz aa_decode_13 ; That's a 000 ! 384 bz aa_decode_13 ; That's a 000 !
375 385
376 ; Apply reverse video, in a reversed way 386 ; Apply reverse video, in a reversed way
377 btfss win_invert,0 ; Inverse video mode ? 387 btfss win_invert,0 ; Inverse video mode ?
378 sublw 0x80 388 sublw 0x80
379 389
380 ; Move the two bits to aa_color_half and aa_color_quarter: 390 ; Move the two bits to aa_color_half and aa_color_quarter:
381 swapf WREG ; --> 0000.0LL0 byte 391 swapf WREG ; --> 0000.0LL0 byte
382 iorlw b'001' ; We are in AA mode, don't forget it ! 392 iorlw b'001' ; We are in AA mode, don't forget it !
383 movwf aa_flags ; save that to aa_color_(half/quad)/AA flags. 393 movwf aa_flags,ACCESS ; save that to aa_color_(half/quad)/AA flags.
384 394
385 ;---- 2 bit x RGB(16bits) computation ---------------------------- 395 ;---- 2 bit x RGB(16bits) computation --------------------------------
386 clrf PRODL ; We will accumulate result here... 396 clrf PRODL ; We will accumulate result here...
387 clrf PRODH 397 clrf PRODH
388 398
389 ; Take color div 2 into aa_colorDiv. Max red = 15/31 399 ; Take color div 2 into aa_colorDiv. Max red = 15/31
390 rrcf win_color1,W,BANKED ; xRRRRxGG 400 rrcf win_color1,W,BANKED ; xRRRRxGG
391 andlw b'01111011' ; 0RRRR0GG (don't change C) 401 andlw b'01111011' ; 0RRRR0GG (don't change C)
392 movwf aa_colorDiv+0,BANKED 402 movwf aa_colorDiv+0,ACCESS
393 rrcf win_color2,W,BANKED ; GGGxBBBB 403 rrcf win_color2,W,BANKED ; GGGxBBBB
394 andlw b'11101111' ; GGG0BBBB 404 andlw b'11101111' ; GGG0BBBB
395 movwf aa_colorDiv+1,BANKED 405 movwf aa_colorDiv+1,ACCESS
396 406
397 btfss aa_color_half 407 btfss aa_color_half,ACCESS
398 bra aa_decode_12 408 bra aa_decode_12
399 409
400 movff aa_colorDiv+0,PRODH ; Add color/2 if bit set. 410 movff aa_colorDiv+0,PRODH ; Add color/2 if bit set.
401 movff aa_colorDiv+1,PRODL ; OLED is big endian, so swap here. 411 movff aa_colorDiv+1,PRODL ; OLED is big endian, so swap here.
402 aa_decode_12: 412 aa_decode_12:
403 btfss aa_color_quart 413 btfss aa_color_quart,ACCESS
404 bra aa_decode_3 414 bra aa_decode_3
405 415
406 ; Divide it once again by 2. Max red = 7/31. 416 ; Divide it once again by 2. Max red = 7/31.
407 rrcf aa_colorDiv+0,W,BANKED ; xxRRRxxG 417 rrcf aa_colorDiv+0,W,ACCESS ; xxRRRxxG
408 andlw b'00111001' ; 00RRR00G (don't change C) 418 andlw b'00111001' ; 00RRR00G (don't change C)
409 movwf aa_colorDiv+0,BANKED 419 movwf aa_colorDiv+0,ACCESS
410 rrcf aa_colorDiv+1,W,BANKED ; GGGxxBBB 420 rrcf aa_colorDiv+1,W,ACCESS ; GGGxxBBB
411 andlw b'11100111' ; GGG00BBB 421 andlw b'11100111' ; GGG00BBB
412 movwf aa_colorDiv+1,BANKED 422 movwf aa_colorDiv+1,ACCESS
413 423
414 movf aa_colorDiv+1,W,BANKED ; Add color/4 424 movf aa_colorDiv+1,W,ACCESS ; Add color/4
415 addwf PRODL,F ; NOTE: 7/31+15/31=22/31, 425 addwf PRODL,F ; NOTE: 7/31+15/31=22/31,
416 movf aa_colorDiv+0,W,BANKED ; hence composants won't overlap. 426 movf aa_colorDiv+0,W,ACCESS ; hence composants won't overlap.
417 addwfc PRODH,F ; In right order, to propagate carry. 427 addwfc PRODH,F ; In right order, to propagate carry.
418 428
419 bra aa_decode_3 ; Done. 429 bra aa_decode_3 ; Done.
420 430
421 ; ---- Simple BLACK and WHITE cases ------------------------------ 431 ; ---- Simple BLACK and WHITE cases ------------------------------
422 aa_decode_13: ; Got a 1xx or a 000 code... 432 aa_decode_13: ; Got a 1xx or a 000 code...
423 btfsc win_invert,0 ; Inverse video mode ? 433 btfsc win_invert,0 ; Inverse video mode ?
424 xorlw 0x80 ; YES: invert levels. 434 xorlw 0x80 ; YES: invert levels.
425 bn aa_decode_2 ; Then test high bit. 435 bn aa_decode_2 ; Then test high bit.
426 436
427 ; WHITE pixel (ie. full color) 437 ; WHITE pixel (ie. full color)
428 movff win_color1,PRODH ; current draw color 438 movff win_color1,PRODH ; current draw color
429 movff win_color2,PRODL ; (rem: OLED is big endian) 439 movff win_color2,PRODL ; (rem: OLED is big endian)
430 bra aa_decode_3 440 bra aa_decode_3
431 441
432 aa_decode_2: 442 aa_decode_2:
433 clrf PRODH,A ; BLACK pixel 443 clrf PRODH,A ; BLACK pixel
434 clrf PRODL,A 444 clrf PRODL,A
435 445
436 aa_decode_3: 446 aa_decode_3:
437 ;---- PIXEL WRITE LOOP ------------------------------------------- 447 ;---- PIXEL WRITE LOOP -----------------------------------------------
438 AA_DATA_WRITE_PROD 448 AA_DATA_WRITE_PROD
439 decf aa_bitlen,BANKED 449 decf aa_bitlen,F,ACCESS
440 bnz aa_decode_3 450 bnz aa_decode_3
441 451
442 ;---- BYTE-CODE LOOP --------------------------------------------- 452 ;---- BYTE-CODE LOOP -------------------------------------------------
443 ; Are we done ? 453 ; Are we done ?
444 movf TBLPTRL,W,A ; Compare TBLPTR to aa_end 454 movf TBLPTRL,W,A ; Compare TBLPTR to aa_end
445 cpfseq aa_end,BANKED 455 cpfseq aa_end+0,ACCESS
446 bra aa_decode_1 ; Loop if LOW is different 456 bra aa_decode_1 ; Loop if LOW is different
447 movf TBLPTRH,W,A 457 movf TBLPTRH,W,A
448 cpfseq aa_end+1,BANKED ; Loop to if HIGH is different 458 cpfseq aa_end+1,ACCESS ; Loop to if HIGH is different
449 bra aa_decode_1 459 bra aa_decode_1
450 460
451 return 461 return
452 462
453 ;------------------------------------------------------------------------------ 463 ;------------------------------------------------------------------------------
454 ; Setup pointers for a char: 464 ; Setup pointers for a char:
455 ; Inputs : letter : string to print (SHOULD BE NULL TERMINATED) 465 ; Inputs : letter : string to print (SHOULD BE NULL TERMINATED)
456 ; Output : OLED commands on port D + clocks. 466 ; Output : OLED commands on port D + clocks.
457 ; 467 ;
458 aa_wordprocessor: 468 aa_wordprocessor:
459 ; Make sure context is well known 469 ; Make sure context is well known
460 movlb HIGH aa_start ; Switch to bank 0... 470 movlb HIGH win_top ; Switch to bank 0...
461 471
462 rcall aa_string_width ; Set aa_height, compute aa_width 472 rcall aa_string_width ; Set win_height, compute win_width
463 rcall aa_box_cmd ; Use that for the box. 473 rcall aa_box_cmd ; Use that for the box.
464 474
465 ; Restart the loop for each char to print 475 ; Restart the loop for each char to print
466 lfsr FSR2, letter ; FSR2 pointer to start of string. 476 lfsr FSR2, letter ; FSR2 pointer to start of string.
467 477
468 ; DATA bloc commande: 478 ; DATA bloc commande:
469 AA_CMD_WRITE 0x22 479 AA_CMD_WRITE 0x22
470 480
471 aa_wordprocessor_1: 481 aa_wordprocessor_1:
472 movf POSTINC2,W,A ; WREG = *FSR2++ 482 movf POSTINC2,W,A ; WREG = *FSR2++
473 bz aa_wordprocessor_99 ; Exit if null byte encountered. 483 bz aa_wordprocessor_99 ; Exit if null byte encountered.
474 484
475 rcall aa_char_setup ; setup aa_start / aa_end 485 rcall aa_char_setup ; setup aa_start / aa_end
476 rcall aa_decode_char ; sum-up width into aa_width 486 rcall aa_decode_char ; write pixels to screen
477 bra aa_wordprocessor_1 ; and loop. 487 bra aa_wordprocessor_1 ; and loop.
478 488
479 aa_wordprocessor_99: 489 aa_wordprocessor_99:
480 ; END of bloc commande 490 ; END of bloc commande
481 AA_CMD_WRITE 0x00 491 AA_CMD_WRITE 0x00
482 492
483 return 493 return