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