Mercurial > public > hwos_code
annotate src/tft.asm @ 650:bc214815deb2
3.19/10.75 release
author | heinrichsweikamp |
---|---|
date | Sun, 28 Aug 2022 13:13:38 +0200 |
parents | aeca5717d9eb |
children | 75e90cd0c2c3 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
634 | 3 ; File tft.asm combined next generation V3.09.4n |
0 | 4 ; |
623 | 5 ; low-level Display Outputs |
0 | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code. | |
11 | |
275 | 12 #include "hwos.inc" |
0 | 13 #include "wait.inc" |
14 #include "varargs.inc" | |
15 #include "tft_outputs.inc" | |
16 #include "eeprom_rs232.inc" | |
17 | |
634 | 18 ;----------------------------------------------------------------------------- |
0 | 19 ; Basic bit-level macros |
20 | |
582 | 21 RD_H macro |
22 bsf tft_rd,0 | |
23 endm | |
0 | 24 |
582 | 25 RD_L macro |
26 bcf tft_rd,0 | |
27 endm | |
0 | 28 |
582 | 29 RS_H macro |
30 bsf tft_rs,0 | |
31 endm | |
0 | 32 |
582 | 33 RS_L macro |
34 bcf tft_rs,0 | |
35 endm | |
0 | 36 |
582 | 37 NCS_H macro |
38 bsf tft_cs,0 | |
39 endm | |
0 | 40 |
582 | 41 NCS_L macro |
42 bcf tft_cs,0 | |
43 endm | |
0 | 44 |
582 | 45 WR_H macro |
46 bsf tft_nwr,0 | |
47 endm | |
0 | 48 |
582 | 49 WR_L macro |
50 bcf tft_nwr,0 | |
51 endm | |
0 | 52 |
634 | 53 ;----------------------------------------------------------------------------- |
582 | 54 ; Byte-level macros |
55 | |
0 | 56 Index_out macro low_b |
57 movlw low_b | |
58 rcall TFT_CmdWrite | |
59 endm | |
60 | |
61 Parameter_out macro high_b, low_b | |
62 movlw high_b | |
604 | 63 movwf PORTA ; upper |
0 | 64 movlw low_b |
65 rcall TFT_DataWrite | |
66 endm | |
67 | |
634 | 68 ;============================================================================= |
604 | 69 tft CODE |
634 | 70 ;============================================================================= |
582 | 71 |
72 global TFT_ClearScreen | |
0 | 73 TFT_ClearScreen: |
628 | 74 btfsc screen_type2 ; screen type 2? |
623 | 75 bra TFT_ClearScreen_display2; YES |
628 | 76 btfsc screen_type3 ; screen type 3? |
77 bra TFT_ClearScreen_display3; YES | |
623 | 78 |
604 | 79 Index_out 0x50 ; window horizontal start address |
582 | 80 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 81 Index_out 0x51 ; window horizontal end address |
582 | 82 Parameter_out 0x00, 0xEF ; 0-239 |
604 | 83 Index_out 0x52 ; window vertical start address |
582 | 84 Parameter_out 0x00, 0x00 ; 0-319 |
604 | 85 Index_out 0x53 ; window vertical end address |
582 | 86 Parameter_out 0x01, 0x3F ; 0-319 |
604 | 87 Index_out 0x20 ; frame memory horizontal address |
582 | 88 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 89 Index_out 0x21 ; frame memory vertical address |
582 | 90 Parameter_out 0x01, 0x3F ; 0-319 |
0 | 91 |
604 | 92 Index_out 0x22 ; frame memory data write start |
0 | 93 |
604 | 94 RD_H ; not read |
95 RS_H ; data | |
96 NCS_L ; not CS | |
648 | 97 |
98 btfsc less_io_cpu ; less I/O CPU? | |
99 clrf PORTA ; YES, data lower | |
100 btfss less_io_cpu ; less I/O CPU? | |
101 clrf PORTH ; NO, data lower | |
0 | 102 |
103 movlw d'10' | |
104 movwf tft_temp3 | |
105 TFT_ClearScreen2: | |
106 movlw d'30' | |
107 movwf tft_temp2 | |
108 TFT_ClearScreen3: | |
604 | 109 clrf tft_temp1 ; 30*10*256=76800 pixels -> clear complete 240*320 |
582 | 110 bcf INTCON,GIE |
0 | 111 TFT_ClearScreen4: |
112 WR_L | |
604 | 113 WR_H ; tick |
648 | 114 btfss less_io_cpu ; less I/O CPU? |
115 bra TFT_ClearScreen5 ; NO | |
116 WR_L | |
117 WR_H ; tick | |
118 WR_L | |
119 WR_H ; tick | |
120 WR_L | |
121 WR_H ; tick | |
122 TFT_ClearScreen5: | |
0 | 123 decfsz tft_temp1,F |
124 bra TFT_ClearScreen4 | |
582 | 125 bsf INTCON,GIE |
0 | 126 decfsz tft_temp2,F |
127 bra TFT_ClearScreen3 | |
128 decfsz tft_temp3,F | |
129 bra TFT_ClearScreen2 | |
582 | 130 |
131 movlw 0x00 ; NOP, to stop window mode | |
604 | 132 bra TFT_CmdWrite ; and return |
582 | 133 |
623 | 134 TFT_ClearScreen_display2: |
135 movlw 0x02 ; column address start | |
608 | 136 rcall TFT_CmdWrite |
137 movlw 0x00 | |
138 rcall TFT_DataWrite | |
139 movlw 0x03 | |
140 rcall TFT_CmdWrite | |
141 movlw 0x00 | |
142 rcall TFT_DataWrite | |
143 | |
623 | 144 movlw 0x04 ; column address end |
608 | 145 rcall TFT_CmdWrite |
146 movlw 0x00 | |
147 rcall TFT_DataWrite | |
148 movlw 0x05 | |
149 rcall TFT_CmdWrite | |
150 movlw 0xEF | |
151 rcall TFT_DataWrite | |
152 | |
623 | 153 movlw 0x06 ; row address start |
608 | 154 rcall TFT_CmdWrite |
155 movlw 0x00 | |
156 rcall TFT_DataWrite | |
157 movlw 0x07 | |
158 rcall TFT_CmdWrite | |
159 movlw 0x00 | |
160 rcall TFT_DataWrite | |
161 | |
623 | 162 movlw 0x08 ; row address end |
608 | 163 rcall TFT_CmdWrite |
164 movlw 0x01 | |
165 rcall TFT_DataWrite | |
166 movlw 0x09 | |
167 rcall TFT_CmdWrite | |
168 movlw 0x3F | |
169 rcall TFT_DataWrite | |
170 | |
623 | 171 movlw 0x22 ; start writing data to GRAM |
608 | 172 rcall TFT_CmdWrite |
173 | |
628 | 174 movlw .160 ; 160 x 240 x 6 = 230400 ticks |
175 TFT_ClearScreen_display2_loop0: | |
623 | 176 bsf tft_rs ; data! |
608 | 177 movwf PRODH |
178 clrf PORTH | |
623 | 179 TFT_ClearScreen_display2_loop1: |
608 | 180 movlw .240 |
181 movwf PRODL | |
623 | 182 TFT_ClearScreen_display2_loop2: |
608 | 183 bcf tft_nwr |
623 | 184 bsf tft_nwr ; upper |
608 | 185 bcf tft_nwr |
623 | 186 bsf tft_nwr ; high |
608 | 187 bcf tft_nwr |
623 | 188 bsf tft_nwr ; lower |
608 | 189 bcf tft_nwr |
623 | 190 bsf tft_nwr ; upper |
608 | 191 bcf tft_nwr |
623 | 192 bsf tft_nwr ; high |
608 | 193 bcf tft_nwr |
623 | 194 bsf tft_nwr ; lower |
608 | 195 decfsz PRODL,F |
623 | 196 bra TFT_ClearScreen_display2_loop2 |
608 | 197 decfsz PRODH,F |
623 | 198 bra TFT_ClearScreen_display2_loop1 |
199 return | |
0 | 200 |
628 | 201 TFT_ClearScreen_display3: |
202 movlw 0x35 ; vertical start address HIGH:LOW | |
203 rcall TFT_CmdWrite | |
631 | 204 mullw 0 |
628 | 205 rcall TFT_DataWrite_PROD |
206 | |
207 movlw 0x36 ; vertical end address HIGH:LOW | |
208 rcall TFT_CmdWrite | |
209 movlw 0x01 | |
210 rcall TFT_DataWrite | |
211 movlw 0x3F | |
212 rcall TFT_DataWrite | |
213 | |
214 movlw 0x37 ; horizontal address START:END | |
215 rcall TFT_CmdWrite | |
216 movlw 0x00 | |
217 rcall TFT_DataWrite | |
218 movlw 0xEF | |
219 rcall TFT_DataWrite | |
220 | |
221 movlw 0x20 ; start address horizontal (.0 - .239) | |
222 rcall TFT_CmdWrite | |
223 rcall TFT_DataWrite_PROD | |
224 | |
225 movlw 0x21 ; start address vertical (.0 - .319) | |
226 rcall TFT_CmdWrite | |
227 rcall TFT_DataWrite_PROD | |
228 | |
229 movlw 0x22 ; start writing data to GRAM | |
230 rcall TFT_CmdWrite | |
231 | |
232 movlw .107 ; 107 x 240 x 6 = 154080 ticks (153600 would be enough) | |
233 bra TFT_ClearScreen_display2_loop0 | |
234 | |
235 | |
582 | 236 global TFT_DisplayOff |
0 | 237 TFT_DisplayOff: |
628 | 238 bcf lightsen_power ; power-down light sensor |
631 | 239 btfsc screen_type3 ; screen type 3 ? |
240 bra TFT_DisplayOff_display3 ; YES - screen needs special power-down sequence | |
241 clrf CCP1CON ; NO - stop PWM | |
242 bcf PORTC,2 ; - pull PWM out to GND | |
0 | 243 clrf PORTA |
582 | 244 clrf PORTH |
623 | 245 RD_L ; LOW |
246 RS_L ; LOW | |
640 | 247 WR_L |
248 NCS_L | |
623 | 249 bcf tft_nreset |
250 bsf tft_power ; inverted... | |
628 | 251 return |
252 | |
253 TFT_DisplayOff_display3: | |
254 movlw 0x05 | |
255 rcall TFT_CmdWrite | |
256 movlw 0x00 | |
257 rcall TFT_DataWrite | |
258 movlw 0x00 | |
259 rcall TFT_DataWrite | |
260 WAITMS d'32' | |
261 clrf CCP1CON ; stop PWM | |
262 bcf PORTC,2 ; pull PWM out to GND | |
263 WAITMS d'32' | |
264 movlw 0x10 | |
265 rcall TFT_CmdWrite | |
266 movlw 0x00 | |
267 rcall TFT_DataWrite | |
268 movlw 0x01 | |
269 rcall TFT_DataWrite | |
270 WAITMS d'100' | |
271 clrf PORTH | |
272 bcf tft_nwr | |
273 bcf tft_cs | |
274 bcf tft_nreset | |
275 WAITMS d'10' | |
276 bsf tft_power ; inverted... | |
0 | 277 return |
278 | |
279 ; ----------------------------- | |
280 ; TFT boot | |
281 ; ----------------------------- | |
582 | 282 |
283 global TFT_boot | |
0 | 284 TFT_boot: |
623 | 285 ; switch off backlight |
286 clrf CCP1CON ; stop PWM | |
287 bcf PORTC,2 ; pull PWM out to GND | |
288 | |
0 | 289 clrf PORTA |
290 clrf PORTH | |
628 | 291 |
0 | 292 RD_L ; LOW |
293 nop | |
628 | 294 WR_L |
295 nop | |
296 NCS_L ; Not CS | |
0 | 297 nop |
298 bcf tft_nreset | |
299 WAITMS d'1' | |
300 bcf tft_power ; inverted... | |
301 WAITMS d'1' | |
302 RD_H ; Keep high | |
628 | 303 nop |
0 | 304 WAITMS d'2' |
305 bsf tft_nreset | |
461 | 306 WAITMS d'5' |
307 bcf tft_nreset | |
308 WAITMS d'5' | |
309 bsf tft_nreset | |
0 | 310 WAITMS d'150' |
628 | 311 WR_H ; release bus |
604 | 312 bsf lightsen_power ; supply power to light sensor |
0 | 313 |
628 | 314 btfsc screen_type3 ; display type 3 ? |
315 bra TFT_boot_screen3 ; YES | |
316 | |
582 | 317 ; Data Transfer Synchronization |
0 | 318 Parameter_out 0x00, 0x00 |
319 Parameter_out 0x00, 0x00 | |
582 | 320 |
623 | 321 btfsc screen_type2 ; display type 2 ? |
322 bra TFT_boot_screen2 ; YES | |
608 | 323 |
623 | 324 ; Get screen type from Bootloader-Info |
582 | 325 movlw 0x7B |
326 movwf TBLPTRL | |
327 movlw 0xF7 | |
328 movwf TBLPTRH | |
329 movlw 0x01 | |
330 movwf TBLPTRU | |
623 | 331 TBLRD*+ ; reads 0x6E for cR and USB OSTC3, 0x00 for BLE (2 and 3), and 0x02 for display 1 OSTC |
332 movlw 0x02 ; coding for display 1 | |
333 cpfseq TABLAT ; display 1 ? | |
334 bra TFT_boot_0 ; NO - display 0 | |
360 | 335 |
336 TFT_boot_1: | |
582 | 337 ; Init through config table... |
338 movlw 0x74 | |
339 movwf TBLPTRL | |
340 movlw 0xF7 | |
341 movwf TBLPTRH | |
342 movlw 0x01 | |
343 movwf TBLPTRU | |
628 | 344 bsf screen_type1 |
582 | 345 bra TFT_boot_com |
360 | 346 |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
347 TFT_boot_0: |
582 | 348 ; Init through config table... |
349 movlw LOW display0_config_table | |
350 movwf TBLPTRL | |
351 movlw HIGH display0_config_table | |
352 movwf TBLPTRH | |
353 movlw UPPER display0_config_table | |
354 movwf TBLPTRU | |
648 | 355 btfss less_io_cpu ; less I/O CPU? |
356 bcf screen_type1 ; NO | |
582 | 357 |
360 | 358 TFT_boot_com: |
582 | 359 rcall display0_init_loop |
0 | 360 |
582 | 361 Index_out 0x03 |
362 btfsc flip_screen ; 180° rotation ? | |
604 | 363 bra TFT_boot2 ; YES |
360 | 364 |
628 | 365 btfss screen_type1 ; display1? |
604 | 366 bra TFT_boot1a ; NO |
582 | 367 Parameter_out 0x10, 0x00 ; display1 |
368 bra TFT_boot3 | |
360 | 369 TFT_boot1a: |
582 | 370 Parameter_out 0x50, 0x20 ; display0 |
371 bra TFT_boot3 | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
372 TFT_boot2: |
628 | 373 btfss screen_type1 ; display1? |
604 | 374 bra TFT_boot2a ; NO |
582 | 375 Parameter_out 0x10, 0x30 ; display1 |
376 bra TFT_boot3 | |
360 | 377 TFT_boot2a: |
582 | 378 Parameter_out 0x50, 0x10 ; display0 |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
379 TFT_boot3: |
0 | 380 Index_out 0x22 |
225
31088352ee32
BUGFIX: Show dives with >999mins divetime correctly
heinrichsweikamp
parents:
152
diff
changeset
|
381 rcall TFT_ClearScreen |
0 | 382 Index_out 0x07 |
312 | 383 Parameter_out 0x01, 0x33 |
0 | 384 return |
385 | |
386 display0_config_table: | |
582 | 387 ; Reg, Dat0, Dat1 or 0xFF,0x00,0x00 for end |
388 db 0xA4,0x00,0x01,0xFF,.002,0x00 | |
389 db 0x09,0x00,0x01,0x92,0x04,0x00 | |
390 db 0x93,0x04,0x02,0x94,0x00,0x02 | |
391 db 0x07,0x00,0x00,0x10,0x04,0x30 | |
392 db 0x11,0x02,0x37,0x12,0x11,0x8D | |
393 db 0x13,0x11,0x00,0x01,0x01,0x00 | |
394 db 0x02,0x02,0x00,0x03,0x50,0x20 | |
395 db 0x0A,0x00,0x08,0x0D,0x00,0x00 | |
396 db 0x0E,0x00,0x30,0xFF,.151,0x00 | |
397 db 0x12,0x11,0xBD,0x20,0x00,0x00 | |
398 db 0x21,0x00,0x00,0x30,0x06,0x02 | |
399 db 0x31,0x56,0x0D,0x32,0x05,0x07 | |
400 db 0x33,0x06,0x09,0x34,0x00,0x00 | |
401 db 0x35,0x09,0x06,0x36,0x57,0x05 | |
402 db 0x37,0x0D,0x06,0x38,0x02,0x06 | |
403 db 0x39,0x00,0x00,0xFF,0x00,0x00 | |
0 | 404 |
405 display0_init_loop: | |
582 | 406 TBLRD*+ |
407 movlw 0xFF | |
408 cpfseq TABLAT | |
623 | 409 bra display0_config_write ; write configuration data pair to display |
582 | 410 ; Delay ms or quit (return) |
411 TBLRD*+ | |
623 | 412 tstfsz TABLAT ; end of configuration data? |
604 | 413 bra $+4 ; NO |
414 return ; YES - done | |
582 | 415 movf TABLAT,W |
604 | 416 call WAITMSX ; wait WREG milliseconds |
417 TBLRD*+ ; dummy read (Third byte of delay command) | |
418 bra display0_init_loop ; loop | |
0 | 419 |
604 | 420 display0_config_write: ; with command in WREG |
582 | 421 movf TABLAT,W |
604 | 422 rcall TFT_CmdWrite ; write command |
423 TBLRD*+ ; get config0 | |
582 | 424 movff TABLAT,PORTA |
604 | 425 TBLRD*+ ; get config1 |
582 | 426 movf TABLAT,W |
623 | 427 rcall TFT_DataWrite ; write configuration |
604 | 428 bra display0_init_loop ; loop |
0 | 429 |
623 | 430 |
608 | 431 TFT_boot_screen2: |
623 | 432 rcall display1_init ; initialization sequence |
608 | 433 |
623 | 434 btfss flip_screen ; 180° rotation? |
435 bra TFT_ClearScreen ; NO - done: clear screen and return | |
436 ; flip the GRAM | |
437 Index_out 0x16 | |
438 movlw 0x48 ; flip image in the GRAM (very elegant with display 2...) | |
439 rcall TFT_DataWrite ; Write configuration | |
440 bra TFT_ClearScreen ; clear screen and return | |
608 | 441 |
628 | 442 TFT_boot_screen3: |
443 rcall display1_init ; init sequence | |
444 rcall TFT_ClearScreen | |
445 setf CCPR1L ; duty cycle, 255 is required for OLED | |
446 ; Set brightness | |
646 | 447 movff brightness,PRODL ; =0: Eco, =1:Medium, =2:Full |
628 | 448 incf PRODL,F ; +1 |
449 dcfsnz PRODL,F | |
450 rcall TFT_display3_low | |
451 dcfsnz PRODL,F | |
452 rcall TFT_display3_med | |
453 dcfsnz PRODL,F | |
454 rcall TFT_display3_high | |
455 ; ToDo: Flip.... | |
456 return | |
457 | |
608 | 458 display1_init: |
623 | 459 movlw LOW (0x1F8BC ) |
460 movwf TBLPTRL | |
461 movlw HIGH (0x1F8BC & 0xFFFF) | |
462 movwf TBLPTRH | |
463 movlw UPPER (0x1F8BC ) | |
464 movwf TBLPTRU | |
608 | 465 display1_init_loop: |
623 | 466 TBLRD*+ |
467 movlw 0xFF ; coding for end of configuration or wait step | |
468 cpfseq TABLAT | |
469 bra display1_config_write ; write configuration pair to display | |
470 ; Delay ms or quit (return) | |
471 TBLRD*+ | |
472 tstfsz TABLAT ; end of configuration? | |
473 bra $+4 ; NO - skip return | |
474 return ; YES - done | |
475 movf TABLAT,W ; read waiting time | |
476 call WAITMSX ; wait WREG milliseconds | |
477 bra display1_init_loop ; loop | |
478 display1_config_write: ; with command in WREG | |
479 movf TABLAT,W | |
480 rcall TFT_CmdWrite ; write command | |
481 TBLRD*+ ; get configuration | |
482 movf TABLAT,W | |
483 rcall TFT_DataWrite ; write configuration | |
628 | 484 btfss screen_type3 ; screen 3 ? |
485 bra display1_init_loop ; NO - loop | |
486 ; Screen 3 gets another byte from the table | |
487 TBLRD*+ ; get configuration | |
488 movf TABLAT,W | |
489 rcall TFT_DataWrite ; write configuration | |
623 | 490 bra display1_init_loop ; loop |
608 | 491 |
623 | 492 |
493 global TFT_CmdWrite | |
608 | 494 TFT_CmdWrite: |
495 RS_L ; command | |
628 | 496 ; btfsc screen_type2 |
497 ; bra TFT_CmdWrite_screen2 | |
608 | 498 clrf PORTA ; upper |
499 bcf INTCON,GIE | |
648 | 500 btfsc less_io_cpu ; less I/O CPU? |
501 bra TFT_CmdWrite_less_io ; YES | |
608 | 502 movwf PORTH ; lower |
503 WR_L | |
504 WR_H ; tick | |
505 bsf INTCON,GIE | |
506 return | |
628 | 507 ;TFT_CmdWrite_screen2: |
508 ; movwf PORTH ; lower | |
509 ; WR_L | |
510 ; WR_H ; tick | |
511 ; return; | |
608 | 512 |
648 | 513 TFT_CmdWrite_less_io: |
514 WR_L | |
515 WR_H ; tick | |
516 movwf PORTA ; lower | |
517 WR_L | |
518 WR_H ; tick | |
519 bsf INTCON,GIE | |
520 return | |
521 | |
608 | 522 global TFT_DataWrite |
523 TFT_DataWrite: | |
524 RS_H ; data | |
628 | 525 ; btfsc screen_type2 |
526 ; bra TFT_DataWrite_screen2 | |
608 | 527 bcf INTCON,GIE |
648 | 528 btfsc less_io_cpu ; less I/O CPU? |
529 bra TFT_DataWrite_less_io ; YES | |
623 | 530 movwf PORTH ; lower |
608 | 531 WR_L |
532 WR_H ; tick | |
533 bsf INTCON,GIE | |
534 return | |
628 | 535 ;TFT_DataWrite_screen2: |
536 ; movwf PORTH ; lower | |
537 ; WR_L | |
538 ; WR_H ; tick | |
539 ; return | |
648 | 540 TFT_DataWrite_less_io: |
541 WR_L | |
542 WR_H ; tick | |
543 movwf PORTA ; lower | |
544 WR_L | |
545 WR_H ; tick | |
546 bsf INTCON,GIE | |
547 return | |
608 | 548 |
623 | 549 |
634 | 550 ;----------------------------------------------------------------------------- |
0 | 551 ; Smooth lighting-up of the display: |
552 ; | |
553 ; Trashes: WREG, PRODL | |
554 ; Typical usage: | |
604 | 555 ; clrf CCPR1L ; backlight off |
582 | 556 ; [draw splash screen] |
557 ; call TFT_DisplayFadeIn | |
634 | 558 ; |
582 | 559 global TFT_Display_FadeIn |
0 | 560 TFT_Display_FadeIn: |
623 | 561 movlw CCP1CON_VALUE ; get configuration |
562 movwf CCP1CON ; set configuration | |
604 | 563 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor |
628 | 564 btfsc screen_type3 |
634 | 565 bra TFT_Display_FadeIn_1 |
604 | 566 clrf CCPR1L ; backlight off - to be sure |
582 | 567 movff max_CCPR1L,PRODL |
0 | 568 TFT_Display_FadeIn_0: |
604 | 569 incf CCPR1L,F ; duty cycle |
582 | 570 WAITMS d'2' |
571 decfsz PRODL,F | |
623 | 572 bra TFT_Display_FadeIn_0 |
604 | 573 bcf tft_is_dimming ; dimming done |
582 | 574 return |
628 | 575 TFT_Display_FadeIn_1: |
576 setf CCPR1L | |
577 return | |
0 | 578 |
634 | 579 ;----------------------------------------------------------------------------- |
0 | 580 ; Smooth lighting-off of the display: |
581 ; Trashes: WREG, PRODL | |
634 | 582 ; |
582 | 583 global TFT_Display_FadeOut |
0 | 584 TFT_Display_FadeOut: |
582 | 585 movff max_CCPR1L,PRODL |
604 | 586 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor |
628 | 587 btfsc screen_type3 |
640 | 588 return ; Do not fade out screen type 3 |
0 | 589 TFT_Display_FadeOut_0: |
604 | 590 movff PRODL,CCPR1L ; duty cycle |
582 | 591 WAITMS d'1' |
592 decfsz PRODL,F | |
593 bra TFT_Display_FadeOut_0 | |
628 | 594 TFT_Display_FadeOut_1: |
582 | 595 clrf CCPR1L |
596 return | |
0 | 597 |
634 | 598 ;----------------------------------------------------------------------------- |
599 ; OLED brightness control | |
600 ; | |
628 | 601 TFT_display3_high: ; 0x01F8F8 |
602 movlw LOW (0x01F8F8 ) | |
603 movwf TBLPTRL | |
604 movlw HIGH (0x01F8F8 & 0xFFFF) | |
605 movwf TBLPTRH | |
606 movlw UPPER (0x01F8F8 ) | |
607 movwf TBLPTRU | |
608 bra display1_init_loop ; and return | |
609 | |
610 TFT_display3_med: ; 0x01F91C | |
611 movlw LOW (0x01F91C ) | |
612 movwf TBLPTRL | |
613 movlw HIGH (0x01F91C & 0xFFFF) | |
614 movwf TBLPTRH | |
615 movlw UPPER (0x01F91C ) | |
616 movwf TBLPTRU | |
617 bra display1_init_loop ; and return | |
618 | |
619 TFT_display3_low: ; 0x01F8D4 | |
620 movlw LOW (0x01F8D4 ) | |
621 movwf TBLPTRL | |
622 movlw HIGH (0x01F8D4 & 0xFFFF) | |
623 movwf TBLPTRH | |
624 movlw UPPER (0x01F8D4 ) | |
625 movwf TBLPTRU | |
626 bra display1_init_loop ; and return | |
627 | |
0 | 628 |
634 | 629 ;----------------------------------------------------------------------------- |
630 ; colored (filled) Boxes | |
631 ; | |
632 global box_std_block, box_black_block, box_color_block, box_color | |
0 | 633 |
604 | 634 box_std_block: ; use white color |
582 | 635 setf WREG |
634 | 636 bra box_color_block |
604 | 637 box_black_block: ; use black color |
582 | 638 clrf WREG |
634 | 639 box_color_block: ; use color from WREG |
582 | 640 rcall TFT_set_color |
641 VARARGS_BEGIN | |
642 VARARGS_GET8 win_top | |
643 VARARGS_GET8 win_height | |
644 VARARGS_GET8 win_leftx2 | |
645 VARARGS_GET8 win_width | |
646 VARARGS_END | |
647 bra TFT_box | |
0 | 648 |
634 | 649 box_color: ; use color from WREG and pre-set coordinates |
650 rcall TFT_set_color | |
651 bra TFT_box | |
0 | 652 |
653 | |
634 | 654 ;----------------------------------------------------------------------------- |
655 ; colored Frames | |
656 ; | |
657 global box_frame_std, box_frame_color | |
658 | |
659 box_frame_std: ; use white color | |
582 | 660 setf WREG |
634 | 661 box_frame_color: ; use color from WREG |
582 | 662 rcall TFT_set_color |
663 VARARGS_BEGIN | |
664 VARARGS_GET8 win_top | |
665 VARARGS_GET8 win_height | |
666 VARARGS_GET8 win_leftx2 | |
667 VARARGS_GET8 win_width | |
668 VARARGS_END | |
669 bra TFT_frame | |
634 | 670 |
0 | 671 |
634 | 672 ; ;----------------------------------------------------------------------------- |
673 ; ; Init for half_pixel_write | |
674 ; ; Set column register on TFT device, and current color. | |
675 ; ; Inputs: win_leftx2 | |
676 ; ; Outputs: win_color_1/_2 | |
677 ; ; Trashed: WREG, PROD | |
678 ; ; | |
679 ; ; global init_pixel_write | |
680 ; ;init_pixel_write: | |
681 ; ; movf win_leftx2,W | |
682 ; ; mullw 2 | |
683 ; ; rcall pixel_write_col320 ; start address vertical (.0 - .319) | |
684 ; ; setf WREG | |
685 ; ; bra TFT_set_color | |
686 | |
0 | 687 |
688 ;----------------------------------------------------------------------------- | |
634 | 689 ; Draw two half-pixels at position (win_top,win_leftx2) |
690 ; Inputs: win_leftx2, win_top, win_color_1/_2 | |
0 | 691 ; Trashed: WREG, PROD |
634 | 692 ; |
582 | 693 global pixel_write |
0 | 694 pixel_write: |
582 | 695 movf win_leftx2,W |
623 | 696 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
604 | 697 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
698 rcall half_pixel_write ; write this half-one | |
628 | 699 |
604 | 700 movf win_leftx2,W ; address of next one |
623 | 701 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
702 INCI PROD ; PROD++ | |
582 | 703 rcall pixel_write_col320 |
628 | 704 bra half_pixel_write ; and return... note: cmd 0x20 is mandatory, because |
582 | 705 ; of the auto-increment going vertical |
0 | 706 |
707 global pixel_write_col320 | |
708 pixel_write_col320: | |
628 | 709 btfsc screen_type2 ; display type 2 ? |
710 bra pixel_write_col320_d2 ; YES | |
711 btfsc screen_type1 ; display type 1 ? | |
712 bra pixel_write_col320_d1 ; YES | |
713 btfsc screen_type3 ; display type 3 ? | |
714 bra pixel_write_col320_d3 ; YES | |
715 ; NO to all - display type 0 | |
582 | 716 btfss flip_screen ; 180° rotation? |
604 | 717 bra pixel_write_noflip_H ; NO |
718 bra pixel_write_flip_H ; YES | |
623 | 719 pixel_write_col320_d1: ; display type 1 |
582 | 720 btfsc flip_screen ; 180° rotation? |
623 | 721 bra pixel_write_noflip_H ; YES |
604 | 722 pixel_write_flip_H: ; flip d0 |
723 movf PRODL,W ; 16 bits 319 - PROD --> PROD | |
623 | 724 sublw LOW .319 ; 319-W --> W |
582 | 725 movwf PRODL |
726 movf PRODH,W | |
604 | 727 btfss STATUS,C ; borrow = /CARRY |
582 | 728 incf WREG |
623 | 729 sublw HIGH .319 |
582 | 730 movwf PRODH |
151 | 731 |
732 pixel_write_noflip_H: | |
604 | 733 Index_out 0x21 ; frame memory vertical address |
582 | 734 bra TFT_DataWrite_PROD ; and return... |
0 | 735 |
608 | 736 pixel_write_col320_d2: |
623 | 737 movlw 0x06 |
738 rcall TFT_CmdWrite | |
739 movf PRODH,W | |
740 rcall TFT_DataWrite | |
741 movlw 0x07 | |
742 rcall TFT_CmdWrite | |
743 movf PRODL,W | |
744 rcall TFT_DataWrite | |
608 | 745 |
623 | 746 incf PRODL,F |
747 movlw .0 | |
748 addwfc PRODH,F ; +1 | |
608 | 749 |
623 | 750 movlw 0x08 |
751 rcall TFT_CmdWrite | |
752 movf PRODH,W | |
753 rcall TFT_DataWrite | |
754 movlw 0x09 | |
755 rcall TFT_CmdWrite | |
756 movf PRODL,W | |
757 bra TFT_DataWrite ; ... and return | |
608 | 758 |
628 | 759 pixel_write_col320_d3: |
760 movlw 0x21 ; start address vertical (.0 - .319) | |
761 rcall TFT_CmdWrite | |
762 bra TFT_DataWrite_PROD ; and return... | |
763 | |
0 | 764 ;----------------------------------------------------------------------------- |
634 | 765 ; Write one half-pixel at position (win_top,win_leftx2). |
766 ; Inputs: win_leftx2, win_top, win_color_1/_2 | |
0 | 767 ; Trashed: WREG, PROD |
634 | 768 ; |
582 | 769 global half_pixel_write |
0 | 770 half_pixel_write: |
628 | 771 movf win_top,W ; d'0' ... d'239' |
772 ; Variant with Y position in WREG | |
0 | 773 half_pixel_write_1: |
628 | 774 btfsc screen_type2 ; display type 2 ? |
775 bra half_pixel_write_1_display2 ; YES | |
776 btfsc screen_type3 ; display type 3 ? | |
777 bra half_pixel_write_1_display3 ; YES | |
608 | 778 |
628 | 779 half_pixel_write_1_display1: |
582 | 780 btfss flip_screen ; 180° rotation? |
781 sublw .239 ; 239-Y --> Y | |
604 | 782 mullw .1 ; copy row to PRODL (PRODH=0) |
783 Index_out 0x20 ; frame memory horizontal address | |
582 | 784 rcall TFT_DataWrite_PROD |
0 | 785 |
604 | 786 Index_out 0x22 ; frame memory data write start |
787 RS_H ; data | |
582 | 788 bcf INTCON,GIE |
648 | 789 movff win_color1,PORTA ; upper |
790 btfsc less_io_cpu ; less I/O CPU? | |
791 bra half_pixel_write_1_display1_l_io ; YES | |
792 movff win_color2,PORTH ; lower | |
582 | 793 WR_L |
648 | 794 WR_H ; tick |
582 | 795 bsf INTCON,GIE |
796 return | |
0 | 797 |
648 | 798 half_pixel_write_1_display1_l_io: |
799 WR_L | |
800 WR_H ; tick | |
801 movff win_color2,PORTA ; lower | |
802 WR_L | |
803 WR_H ; tick | |
804 bsf INTCON,GIE | |
805 return | |
806 | |
628 | 807 half_pixel_write_1_display2: |
623 | 808 mullw 1 ; copy row to PRODL (PRODH=0) |
809 ; Row address start | |
810 movlw 0x02 | |
811 rcall TFT_CmdWrite | |
812 movlw .0 | |
813 rcall TFT_DataWrite | |
814 movlw 0x03 | |
815 rcall TFT_CmdWrite | |
816 movf PRODL,W | |
817 rcall TFT_DataWrite | |
608 | 818 |
623 | 819 incf PRODL,F |
608 | 820 |
623 | 821 movlw 0x04 |
822 rcall TFT_CmdWrite | |
823 movlw .0 | |
824 rcall TFT_DataWrite | |
825 movlw 0x05 | |
826 rcall TFT_CmdWrite | |
827 movf PRODL,W | |
828 rcall TFT_DataWrite | |
608 | 829 |
830 movff win_color1,PRODH | |
831 movff win_color2,PRODL | |
832 rcall convert_for_display2 | |
833 | |
623 | 834 movlw 0x22 ; start writing data to GRAM |
835 rcall TFT_CmdWrite | |
836 RS_H ; data | |
837 movff win_color5, PORTH | |
608 | 838 WR_L |
623 | 839 WR_H ; tick |
840 movff win_color4, PORTH | |
608 | 841 WR_L |
623 | 842 WR_H ; tick |
843 movff win_color3, PORTH | |
608 | 844 WR_L |
623 | 845 WR_H ; tick |
846 return | |
608 | 847 |
628 | 848 half_pixel_write_1_display3: |
849 mullw 1 ; copy row to PRODL (PRODH=0) | |
850 | |
851 movlw 0x20 ; horizontal address START:END | |
852 rcall TFT_CmdWrite | |
853 rcall TFT_DataWrite_PROD | |
854 | |
855 movlw 0x22 ; start writing data to GRAM | |
856 rcall TFT_CmdWrite | |
857 RS_H ; data | |
858 movff win_color1, PORTH | |
859 WR_L | |
860 WR_H ; tick | |
861 movff win_color2, PORTH | |
862 WR_L | |
863 WR_H ; tick | |
864 return ; done | |
865 | |
0 | 866 ;----------------------------------------------------------------------------- |
634 | 867 ; Draw a vertical line of half-pixel at position (win_top,win_leftx2,win_height). |
868 ; Inputs: win_leftx2, win_top, win_height, win_color_1/_2 | |
0 | 869 ; Trashed: WREG, PROD, TABLAT, TBLPTRL |
634 | 870 ; |
0 | 871 global half_vertical_line |
872 half_vertical_line: | |
604 | 873 clrf TABLAT ; loop index |
0 | 874 |
875 half_vertical_line_loop: | |
604 | 876 movf win_leftx2,W ; init X position |
623 | 877 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
604 | 878 movf TABLAT,W ; get loop index |
879 andlw .1 ; just low bit | |
880 xorwf PRODL,F ; and use it to jitter current X position | |
881 rcall pixel_write_col320 ; start address vertical (.0 - .319) | |
0 | 882 |
604 | 883 movf win_height,W ; index reached height (bank0 read) ? |
582 | 884 xorwf TABLAT,W |
604 | 885 btfsc STATUS,Z ; Equal ? |
886 return ; YES - done | |
887 movf win_top,W ; Y = top + index (bank0 read) | |
582 | 888 addwf TABLAT,W |
889 rcall half_pixel_write_1 | |
890 incf TABLAT,F ; index++ | |
891 bra half_vertical_line_loop | |
0 | 892 |
893 ;----------------------------------------------------------------------------- | |
634 | 894 ; Draw a horizontal line of half-pixel at position (win_top,win_leftx2,win_width). |
895 ; Inputs: win_leftx2, win_top, win_width, win_color_1/_2 | |
0 | 896 ; Trashed: WREG, PROD, TABLAT, TBLPTRL |
634 | 897 ; |
0 | 898 global half_horizontal_line |
899 half_horizontal_line: | |
604 | 900 clrf TABLAT ; loop index |
0 | 901 |
902 half_horizontal_line_loop: | |
604 | 903 movf win_leftx2,W ; init X position |
623 | 904 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
604 | 905 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
906 movf win_width,W ; index reached height (bank0 read) ? | |
582 | 907 xorwf TABLAT,W |
604 | 908 btfsc STATUS,Z ; equal ? |
909 return ; YES - done | |
910 movf win_top,W ; Y = top + index (bank0 read) | |
582 | 911 addwf TABLAT,W |
912 rcall half_pixel_write_1 | |
913 incf TABLAT,F ; index++ | |
914 bra half_horizontal_line_loop | |
0 | 915 |
916 | |
917 ;----------------------------------------------------------------------------- | |
634 | 918 ; TFT Data Command |
919 ; | |
0 | 920 TFT_DataWrite_PROD: |
623 | 921 ; RD_H ; keep high |
922 RS_H ; data | |
923 btfsc screen_type2 ; screen type 2 ? | |
924 bra TFT_DataWrite_PROD_display2 ; YES | |
628 | 925 btfsc screen_type3 ; screen type 3 ? |
926 bra TFT_DataWrite_PROD_display2 ; YES | |
623 | 927 bcf INTCON,GIE ; NO - |
928 movff PRODH,PORTA ; - move high byte to PORTA | |
648 | 929 btfsc less_io_cpu ; less I/O CPU? |
930 bra TFT_DataWrite_PROD_less_io ; YES | |
623 | 931 movff PRODL,PORTH ; - move low byte to PORTH |
932 WR_L ; - tick | |
933 WR_H ; - tack | |
934 bsf INTCON,GIE ; - | |
935 return ; - done | |
0 | 936 |
648 | 937 TFT_DataWrite_PROD_less_io: |
938 WR_L | |
939 WR_H ; tick | |
940 movff PRODL,PORTA ; - move low byte to PORTH | |
941 WR_L ; - tick | |
942 WR_H ; - tack | |
943 bsf INTCON,GIE ; - | |
944 return ; - done | |
945 | |
608 | 946 TFT_DataWrite_PROD_display2: |
623 | 947 movff PRODH,PORTH ; move high byte to PORTH (display 2 is big endian) |
948 WR_L ; tick | |
949 WR_H ; tack | |
950 movff PRODL,PORTH ; move low byte to PORTH | |
951 WR_L ; tick | |
952 WR_H ; tack | |
628 | 953 btfsc screen_type3 ; screen type 3 ? |
954 return ; YES - done | |
955 movff win_color3,PORTH ; NO - move low(est) byte to PORTH | |
956 WR_L ; - tick | |
957 WR_H ; - tack | |
958 return ; - done | |
623 | 959 |
608 | 960 |
0 | 961 TFT_DataRead_PROD: |
604 | 962 Index_out 0x22 ; frame memory data read start |
360 | 963 TFT_CmdRead_PROD: |
604 | 964 setf TRISA ; port A as input |
965 setf TRISH ; port H as input | |
966 RS_H ; data | |
967 WR_H ; not write | |
968 RD_L ; read | |
582 | 969 nop |
970 nop | |
971 nop | |
604 | 972 RD_H ; tick |
582 | 973 nop |
974 nop | |
975 nop | |
604 | 976 RD_L ; read |
582 | 977 nop |
978 ;nop | |
979 ;nop | |
980 movff PORTA,PRODH | |
981 movff PORTH,PRODL | |
604 | 982 RD_H ; tick |
582 | 983 nop |
604 | 984 clrf TRISA ; port A as output |
985 clrf TRISH ; port H as output | |
0 | 986 return |
987 | |
634 | 988 ;----------------------------------------------------------------------------- |
604 | 989 ; Output TFT Window Address commands |
990 ; Inputs : win_top, win_leftx2, win_height, win_width | |
991 ; Output : PortA/PortH commands | |
0 | 992 ; Trashed: PROD |
634 | 993 ; |
582 | 994 global TFT_box_write |
0 | 995 TFT_box_write: |
634 | 996 movf win_leftx2,W ; compute left = 2 * leftx2 --> PROD |
997 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL | |
0 | 998 |
634 | 999 btfsc screen_type2 ; screen type 2 ? |
1000 bra TFT_box_write_display2 ; YES | |
1001 btfsc screen_type3 ; screen type 3 ? | |
1002 bra TFT_box_write_display3 ; YES | |
1003 btfsc screen_type1 ; screen type 1 ? | |
1004 bra TFT_box_write_display1 ; YES | |
608 | 1005 |
623 | 1006 ; screen type 0 |
634 | 1007 TFT_box_write_display0: |
1008 btfsc flip_screen ; 180° rotation? | |
1009 bra TFT_box_do_flip_H ; YES | |
1010 bra TFT_box_no_flip_H ; NO | |
1011 | |
1012 ; screen type 1 | |
1013 TFT_box_write_display1: | |
1014 btfss flip_screen ; 180° rotation? | |
1015 bra TFT_box_do_flip_H ; NO | |
1016 ;bra TFT_box_no_flip_H ; YES | |
1017 | |
582 | 1018 ;---- Normal horizontal window --------------------------------------- |
634 | 1019 TFT_box_no_flip_H: |
604 | 1020 Index_out 0x52 ; window vertical start address |
1021 rcall TFT_DataWrite_PROD ; output left | |
1022 Index_out 0x21 ; frame memory vertical address | |
1023 rcall TFT_DataWrite_PROD ; output left | |
0 | 1024 |
582 | 1025 movf win_width+0,W ; right = left + width - 1 |
432 | 1026 addwf PRODL,F |
1027 movf win_width+1,W | |
1028 addwfc PRODH,F | |
623 | 1029 decf PRODL,F ; right-- |
582 | 1030 btfss STATUS,C |
432 | 1031 decf PRODH,F |
0 | 1032 |
604 | 1033 Index_out 0x53 ; window vertical end address |
582 | 1034 rcall TFT_DataWrite_PROD |
634 | 1035 bra TFT_box_common_H |
0 | 1036 |
582 | 1037 ;---- Flipped horizontal window -------------------------------------- |
634 | 1038 TFT_box_do_flip_H: |
623 | 1039 ; calculate new coordinate |
604 | 1040 movf PRODL,W ; 16 bits 319 - PROD --> PROD |
623 | 1041 sublw LOW .319 ; 319 - WREG --> WREG |
582 | 1042 movwf PRODL |
1043 movf PRODH,W | |
604 | 1044 btfss STATUS,C ; borrow = /CARRY |
582 | 1045 incf WREG |
623 | 1046 sublw HIGH .319 |
582 | 1047 movwf PRODH |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
1048 |
604 | 1049 Index_out 0x53 ; window vertical start address |
1050 rcall TFT_DataWrite_PROD ; output left | |
1051 Index_out 0x21 ; frame memory vertical address | |
1052 rcall TFT_DataWrite_PROD ; output left | |
151 | 1053 |
623 | 1054 ; calculate new coordinate |
604 | 1055 movf win_width+0,W ; 16 bits PROD - width --> PROD |
582 | 1056 subwf PRODL,F ; PRODL - WREG --> PRODL |
1057 movf win_width+1,W | |
1058 subwfb PRODH,F | |
623 | 1059 INCI PROD ; PROD++ |
151 | 1060 |
604 | 1061 Index_out 0x52 ; window vertical end address |
582 | 1062 rcall TFT_DataWrite_PROD |
151 | 1063 |
634 | 1064 TFT_box_common_H: |
582 | 1065 btfss flip_screen ; 180° rotation ? |
634 | 1066 bra TFT_box_no_flip_V ; NO |
1067 ;bra TFT_box_do_flip_V ; YES | |
151 | 1068 |
582 | 1069 ;---- Flipped vertical window ----------------------------------------- |
634 | 1070 TFT_box_do_flip_V: |
623 | 1071 ; calculate new coordinate |
582 | 1072 movff win_top,PRODH ; top --> PRODH (first byte) |
1073 movf win_height,W | |
1074 addwf PRODH,W | |
432 | 1075 decf WREG |
604 | 1076 movwf PRODL ; top + height - 1 --> PRODL (second byte) |
151 | 1077 |
604 | 1078 Index_out 0x50 ; window horizontal start address |
432 | 1079 movf PRODH,W |
604 | 1080 rcall TFT_DataWrite ; lower (and tick) |
151 | 1081 |
604 | 1082 Index_out 0x51 ; window horizontal end address |
582 | 1083 movf PRODL,W |
604 | 1084 rcall TFT_DataWrite ; lower (and tick) |
582 | 1085 |
604 | 1086 Index_out 0x20 ; frame memory horizontal address |
432 | 1087 movf PRODH,W |
604 | 1088 bra TFT_DataWrite ; lower (and tick) and return |
151 | 1089 |
582 | 1090 ;---- Normal vertical window ---------------------------------------- |
634 | 1091 TFT_box_no_flip_V: |
582 | 1092 movff win_top,PRODL |
1093 movf win_height,W | |
1094 addwf PRODL,W | |
1095 sublw .240 ; 240 - top - height | |
604 | 1096 movwf PRODH ; first byte |
0 | 1097 |
432 | 1098 movf PRODL,W |
604 | 1099 sublw .239 ; 239 - top |
1100 movwf PRODL ; --> second byte | |
0 | 1101 |
604 | 1102 Index_out 0x50 ; window horizontal start address |
432 | 1103 movf PRODH,W |
604 | 1104 rcall TFT_DataWrite ; lower (and tick) |
0 | 1105 |
604 | 1106 Index_out 0x51 ; window horizontal end address |
432 | 1107 movf PRODL,W |
604 | 1108 rcall TFT_DataWrite ; lower (and tick) |
0 | 1109 |
604 | 1110 Index_out 0x20 ; frame memory horizontal address |
432 | 1111 movf PRODL,W |
604 | 1112 bra TFT_DataWrite ; lower (and tick) and return |
582 | 1113 |
608 | 1114 |
623 | 1115 TFT_box_write_display2: |
631 | 1116 ; setup left border |
623 | 1117 movlw 0x06 |
1118 rcall TFT_CmdWrite | |
1119 movf PRODH,W | |
1120 rcall TFT_DataWrite | |
1121 movlw 0x07 | |
1122 rcall TFT_CmdWrite | |
1123 movf PRODL,W | |
1124 rcall TFT_DataWrite | |
608 | 1125 |
623 | 1126 movf win_width+0,W ; right = left + width - 1 |
1127 addwf PRODL,F | |
1128 movf win_width+1,W | |
1129 addwfc PRODH,F | |
631 | 1130 decf PRODL,F ; decrement result |
623 | 1131 btfss STATUS,C |
631 | 1132 decf PRODH,F |
608 | 1133 |
631 | 1134 ; setup right border |
623 | 1135 movlw 0x08 |
1136 rcall TFT_CmdWrite | |
1137 movf PRODH,W | |
1138 rcall TFT_DataWrite | |
1139 movlw 0x09 | |
1140 rcall TFT_CmdWrite | |
1141 movf PRODL,W | |
1142 rcall TFT_DataWrite | |
1143 | |
1144 ;---- Normal vertical window ----------------------------------------- | |
1145 ; Output (top) (bottom) | |
1146 movff win_top,PRODH ; top --> PRODH (first byte) | |
1147 movf win_height,W | |
1148 addwf PRODH,W | |
1149 decf WREG | |
1150 movwf PRODL ; top+height-1 --> PRODL (second byte) | |
608 | 1151 |
623 | 1152 movlw 0x02 |
1153 rcall TFT_CmdWrite | |
1154 movlw 0x00 | |
1155 rcall TFT_DataWrite | |
1156 movlw 0x03 | |
1157 rcall TFT_CmdWrite | |
1158 movf PRODH,W | |
1159 rcall TFT_DataWrite | |
608 | 1160 |
623 | 1161 movlw 0x04 |
1162 rcall TFT_CmdWrite | |
1163 movlw 0x00 | |
1164 rcall TFT_DataWrite | |
1165 movlw 0x05 | |
1166 rcall TFT_CmdWrite | |
1167 movf PRODL,W | |
1168 bra TFT_DataWrite ; ... and return | |
0 | 1169 |
628 | 1170 TFT_box_write_display3: |
1171 ;---- Normal horizontal window --------------------------------------- | |
1172 ; Output 0x35 left, | |
631 | 1173 ; 0x36 right == left + width - 1. |
628 | 1174 |
1175 Index_out 0x35 ; window vertical start address | |
1176 rcall TFT_DataWrite_PROD ; output left | |
1177 Index_out 0x21 ; also the horizontal first pix coordinate | |
1178 rcall TFT_DataWrite_PROD ; output left | |
1179 | |
631 | 1180 movf win_width+0,W ; right = left + width - 1 |
628 | 1181 addwf PRODL,F |
631 | 1182 movf win_width+1,W |
628 | 1183 addwfc PRODH,F |
631 | 1184 decf PRODL,F ; decrement result |
634 | 1185 btfss STATUS,C |
631 | 1186 decf PRODH,F |
628 | 1187 |
631 | 1188 Index_out 0x36 ; write and the right border |
628 | 1189 rcall TFT_DataWrite_PROD |
1190 | |
1191 ;---- Normal vertical window ----------------------------------------- | |
1192 ; Output 0x37 (top) (bottom) | |
1193 movff win_top,PRODH ; top --> PRODH (first byte) | |
1194 movff win_height,WREG | |
1195 addwf PRODH,W | |
1196 decf WREG | |
1197 movwf PRODL ; top + height - 1 --> PRODL (second byte) | |
1198 | |
1199 Index_out 0x37 | |
1200 rcall TFT_DataWrite_PROD | |
1201 | |
1202 movff PRODH,PRODL | |
1203 clrf PRODH ; start pixel V coord == top. | |
1204 Index_out 0x20 | |
1205 bra TFT_DataWrite_PROD ; and return... | |
1206 | |
1207 | |
634 | 1208 ;----------------------------------------------------------------------------- |
604 | 1209 ; TFT_frame : draw a frame around current box with current color |
0 | 1210 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 |
1211 ; Outputs: (none) | |
1212 ; Trashed: WREG, PROD, aa_start:2, aa_end:2 | |
634 | 1213 ; |
582 | 1214 global TFT_frame |
1215 TFT_frame: | |
623 | 1216 movff win_top,tft_save_top ; backup everything |
1217 movff win_height,tft_save_height | |
1218 movff win_leftx2,tft_save_left | |
631 | 1219 movff win_width+0,tft_save_width |
0 | 1220 |
582 | 1221 ;---- TOP line ----------------------------------------------------------- |
623 | 1222 movlw .1 ; row ~ height = 1 |
582 | 1223 movwf win_height |
1224 rcall TFT_box | |
0 | 1225 |
582 | 1226 ;---- BOTTOM line -------------------------------------------------------- |
623 | 1227 movff tft_save_top,PRODL ; get back top |
1228 movff tft_save_height,WREG ; get back height | |
1229 addwf PRODL,W ; top + height | |
1230 decf WREG ; top + height - 1 | |
1231 movwf win_top ; top + height - 1 --> top | |
582 | 1232 rcall TFT_box |
0 | 1233 |
582 | 1234 ;---- LEFT column -------------------------------------------------------- |
623 | 1235 movff tft_save_top,win_top ; restore top/height |
1236 movff tft_save_height,win_height | |
1237 movlw .1 ; column ~ width = 1 | |
582 | 1238 movwf win_width+0 |
1239 rcall TFT_box | |
1240 | |
1241 ;---- RIGHT column ------------------------------------------------------- | |
623 | 1242 movff tft_save_left,WREG |
1243 movff tft_save_width,PRODL | |
582 | 1244 addwf PRODL,W |
1245 decf WREG | |
1246 movwf win_leftx2 | |
1247 rcall TFT_box | |
1248 | |
1249 ;---- Restore everything ------------------------------------------------- | |
623 | 1250 movff tft_save_left,win_leftx2 |
631 | 1251 movff tft_save_width,win_width+0 |
582 | 1252 return |
0 | 1253 |
634 | 1254 ;----------------------------------------------------------------------------- |
604 | 1255 ; TFT_box: fills current box with current color |
1256 ; Inputs : win_top, win_leftx2, win_height, win_width, win_color1, win_color2 | |
0 | 1257 ; Outputs: (none) |
1258 ; Trashed: WREG, PROD | |
634 | 1259 ; |
582 | 1260 global TFT_box |
0 | 1261 TFT_box: |
582 | 1262 ;---- Define Window ------------------------------------------------------ |
1263 bcf STATUS,C | |
1264 rlcf win_width+0,F | |
1265 rlcf win_width+1,F ; x2 | |
604 | 1266 rcall TFT_box_write ; setup box |
0 | 1267 |
582 | 1268 bcf STATUS,C |
1269 rrcf win_width+1,F ; width /= 2 | |
1270 rrcf win_width+0,F | |
0 | 1271 |
582 | 1272 ;---- Fill Window -------------------------------------------------------- |
604 | 1273 Index_out 0x22 ; frame memory data write start |
1274 clrf PRODH ; column counter | |
1275 RS_H ; data | |
0 | 1276 |
628 | 1277 btfsc screen_type2 ; display type 2 ? |
1278 bra TFT_box_display2 ; YES | |
1279 btfsc screen_type3 ; display type 3 ? | |
1280 bra TFT_box_display3 ; YES | |
1281 | |
604 | 1282 TFT_box2: ; loop height times |
0 | 1283 movff win_height,PRODL |
1284 | |
582 | 1285 TFT_box3: ; loop width times |
623 | 1286 bcf INTCON,GIE |
604 | 1287 movff win_color1,PORTA ; upper |
648 | 1288 btfsc less_io_cpu ; less I/O CPU? |
1289 bra TFT_box3_less_io ; YES | |
604 | 1290 movff win_color2,PORTH ; lower |
634 | 1291 WR_L ; tick |
1292 WR_H ; ... | |
1293 WR_L ; tick | |
1294 WR_H ; ... | |
582 | 1295 bsf INTCON,GIE |
1296 decfsz PRODL,F ; row loop finished ? | |
604 | 1297 bra TFT_box3 ; NO - continue |
0 | 1298 |
582 | 1299 incf PRODH,F ; column count ++ |
628 | 1300 movf win_bargraph,W ; get width of active bargraph part |
1301 cpfseq PRODH ; current column == end of active bargraph ? | |
604 | 1302 bra TFT_box4 ; NO - just loop |
628 | 1303 clrf win_color1 ; YES - switch to black |
604 | 1304 clrf win_color2 ; - ... |
0 | 1305 TFT_box4: |
628 | 1306 movf win_width+0,W ; get total bargraph width |
1307 xorwf PRODH,W ; all columns done? | |
1308 bnz TFT_box2 ; NO - loop | |
0 | 1309 |
582 | 1310 movlw 0x00 ; NOP, to stop window mode |
1311 rcall TFT_CmdWrite | |
0 | 1312 |
604 | 1313 ; reset bargraph mode... |
582 | 1314 setf win_bargraph |
1315 return | |
623 | 1316 |
648 | 1317 TFT_box3_less_io: |
1318 WR_L ; tick | |
1319 WR_H ; ... | |
1320 movff win_color2,PORTA ; lower | |
1321 WR_L ; tick | |
1322 WR_H ; ... | |
1323 movff win_color1,PORTA ; upper | |
1324 WR_L ; tick | |
1325 WR_H ; ... | |
1326 movff win_color2,PORTA ; lower | |
1327 WR_L ; tick | |
1328 WR_H ; ... | |
1329 bsf INTCON,GIE | |
1330 decfsz PRODL,F ; row loop finished ? | |
1331 bra TFT_box3 ; NO - continue | |
1332 | |
1333 incf PRODH,F ; column count ++ | |
1334 movf win_bargraph,W ; get width of active bargraph part | |
1335 cpfseq PRODH ; current column == end of active bargraph ? | |
1336 bra TFT_box4 ; NO - just loop | |
1337 clrf win_color1 ; YES - switch to black | |
1338 clrf win_color2 ; - ... | |
1339 bra TFT_box4 ; NO - just loop | |
1340 | |
608 | 1341 TFT_box_display2: |
628 | 1342 ; Screen 2 |
608 | 1343 movff win_color1,PRODH |
1344 movff win_color2,PRODL | |
1345 rcall convert_for_display2 | |
631 | 1346 clrf PRODH ; column counter |
623 | 1347 TFT_box2_display2: ; loop height times |
608 | 1348 movff win_height,PRODL |
623 | 1349 TFT_box3_display2: ; loop width times |
608 | 1350 movff win_color5,PORTH |
623 | 1351 bcf tft_nwr |
1352 bsf tft_nwr ; upper | |
608 | 1353 movff win_color4,PORTH |
1354 bcf tft_nwr | |
623 | 1355 bsf tft_nwr ; high |
608 | 1356 movff win_color3,PORTH |
1357 bcf tft_nwr | |
623 | 1358 bsf tft_nwr ; low |
608 | 1359 |
1360 movff win_color5,PORTH | |
1361 bcf tft_nwr | |
623 | 1362 bsf tft_nwr ; upper |
608 | 1363 movff win_color4,PORTH |
1364 bcf tft_nwr | |
623 | 1365 bsf tft_nwr ; high |
608 | 1366 movff win_color3,PORTH |
1367 bcf tft_nwr | |
623 | 1368 bsf tft_nwr ; low |
1369 decfsz PRODL,F ; row loop finished? | |
1370 bra TFT_box3_display2 ; NO - loop | |
1371 incf PRODH,F ; YES - column count ++ | |
1372 movf win_bargraph,W ; - get bargraph width | |
1373 cpfseq PRODH ; - current column = bargraph ? | |
1374 bra TFT_box4_display2 ; NO | |
1375 clrf win_color5 ; YES - switch to black | |
1376 clrf win_color4 ; - ... | |
1377 clrf win_color3 ; - ... | |
608 | 1378 TFT_box4_display2: |
623 | 1379 movf win_width+0,W ; get width |
1380 cpfseq PRODH ; width loop finished ? | |
1381 bra TFT_box2_display2 ; NO - loop | |
1382 setf win_bargraph ; YES - reset bargraph mode | |
1383 return ; - done | |
0 | 1384 |
628 | 1385 TFT_box_display3: |
1386 ; Screen 3 | |
1387 TFT_box2_display3: ; loop height times | |
1388 movff win_height,PRODL | |
1389 TFT_box3_display3: ; loop width times | |
1390 movff win_color1,PORTH | |
1391 bcf tft_nwr | |
1392 bsf tft_nwr ; upper | |
1393 movff win_color2,PORTH | |
1394 bcf tft_nwr | |
1395 bsf tft_nwr ; high | |
1396 movff win_color1,PORTH | |
1397 bcf tft_nwr | |
1398 bsf tft_nwr ; low | |
1399 movff win_color2,PORTH | |
1400 bcf tft_nwr | |
1401 bsf tft_nwr ; upper | |
1402 decfsz PRODL,F ; row loop finished? | |
1403 bra TFT_box3_display3 ; NO - loop | |
1404 incf PRODH,F ; YES - column count ++ | |
1405 movf win_bargraph,W ; - get bargraph width | |
1406 cpfseq PRODH ; - current column = bargraph ? | |
1407 bra TFT_box4_display3 ; NO | |
1408 clrf win_color1 ; Yes - switch to black | |
1409 clrf win_color2 ; - ... | |
1410 TFT_box4_display3: | |
1411 movf win_width+0,W ; get width | |
1412 cpfseq PRODH ; width loop finished ? | |
1413 bra TFT_box2_display3 ; NO - loop | |
1414 setf win_bargraph ; YES - reset bargraph mode | |
1415 return | |
1416 | |
0 | 1417 |
634 | 1418 ;----------------------------------------------------------------------------- |
1419 ; Convert 8 bit RGB b'RRRGGGBB' into 16 bit RGB b'RRRRRGGGGGGBBBBB' | |
1420 ; WREG win_color1 win_color2 | |
582 | 1421 global TFT_set_color |
0 | 1422 TFT_set_color: |
631 | 1423 movwf tft_temp1 ; get 8 bit RGB b'RRRGGGBB' into tft_temp1... |
634 | 1424 movwf tft_temp2 ; ... and tft_temp2 |
0 | 1425 |
604 | 1426 ; mask bit 7,6,5,4,3,2 |
0 | 1427 movlw b'00000011' |
1428 andwf tft_temp2,F | |
1429 | |
1430 movlw b'00000000' | |
1431 dcfsnz tft_temp2,F | |
1432 movlw b'01010000' | |
1433 dcfsnz tft_temp2,F | |
1434 movlw b'10100000' | |
1435 dcfsnz tft_temp2,F | |
1436 movlw b'11111000' | |
604 | 1437 movwf tft_temp3 ; blue done |
0 | 1438 |
604 | 1439 movff tft_temp1,tft_temp2 ; copy |
1440 ; mask bit 7,6,5,1,0 | |
0 | 1441 movlw b'00011100' |
1442 andwf tft_temp2,F | |
1443 rrncf tft_temp2,F | |
1444 rrncf tft_temp2,F | |
1445 | |
1446 movlw b'00000000' | |
1447 dcfsnz tft_temp2,F | |
1448 movlw b'00000100' | |
1449 dcfsnz tft_temp2,F | |
1450 movlw b'00001000' | |
1451 dcfsnz tft_temp2,F | |
1452 movlw b'00001100' | |
1453 dcfsnz tft_temp2,F | |
1454 movlw b'00010000' | |
1455 dcfsnz tft_temp2,F | |
1456 movlw b'00010100' | |
1457 dcfsnz tft_temp2,F | |
1458 movlw b'00100000' | |
1459 dcfsnz tft_temp2,F | |
1460 movlw b'00111111' | |
582 | 1461 movwf tft_temp4 |
0 | 1462 |
1463 rrcf tft_temp4,F | |
1464 rrcf tft_temp3,F | |
1465 | |
1466 rrcf tft_temp4,F | |
1467 rrcf tft_temp3,F | |
1468 | |
1469 rrcf tft_temp4,F | |
604 | 1470 rrcf tft_temp3,W ; tft_temp3 (b'GGGBBBBB') done |
1471 movwf win_color2 ; set color registers... | |
0 | 1472 |
604 | 1473 movff tft_temp1,tft_temp2 ; copy |
0 | 1474 clrf tft_temp1 |
1475 | |
1476 rrcf tft_temp4,F | |
1477 rrcf tft_temp1,F | |
1478 | |
1479 rrcf tft_temp4,F | |
1480 rrcf tft_temp1,F | |
1481 | |
1482 rrcf tft_temp4,F | |
604 | 1483 rrcf tft_temp1,F ; green done |
0 | 1484 |
604 | 1485 ; mask bit 4,3,2,1,0 |
0 | 1486 movlw b'11100000' |
1487 andwf tft_temp2,F | |
1488 | |
1489 rrncf tft_temp2,F | |
1490 rrncf tft_temp2,F | |
1491 rrncf tft_temp2,F | |
1492 rrncf tft_temp2,F | |
1493 rrncf tft_temp2,F | |
1494 | |
1495 movlw b'00000000' | |
1496 dcfsnz tft_temp2,F | |
1497 movlw b'00000100' | |
1498 dcfsnz tft_temp2,F | |
1499 movlw b'00001000' | |
1500 dcfsnz tft_temp2,F | |
1501 movlw b'00001100' | |
1502 dcfsnz tft_temp2,F | |
1503 movlw b'00010000' | |
1504 dcfsnz tft_temp2,F | |
1505 movlw b'00010100' | |
1506 dcfsnz tft_temp2,F | |
1507 movlw b'00100000' | |
1508 dcfsnz tft_temp2,F | |
1509 movlw b'00111111' | |
582 | 1510 movwf tft_temp4 |
0 | 1511 |
1512 rrcf tft_temp4,F | |
1513 rrcf tft_temp1,F | |
1514 | |
1515 rrcf tft_temp4,F | |
604 | 1516 rrcf tft_temp1,F |
0 | 1517 |
1518 rrcf tft_temp4,F | |
1519 rrcf tft_temp1,F | |
1520 | |
1521 rrcf tft_temp4,F | |
1522 rrcf tft_temp1,F | |
1523 | |
1524 rrcf tft_temp4,F | |
604 | 1525 rrcf tft_temp1,W ; red done |
648 | 1526 ; tft_temp1 (b'RRRRRGGG') done |
1527 movwf win_color1 ; set color registers... | |
0 | 1528 return |
623 | 1529 |
1530 | |
608 | 1531 global convert_for_display2 |
623 | 1532 convert_for_display2: ; convert 16 bit RGB b'RRRRRGGG GGGBBBBB' into 24 bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00' |
1533 ; PRODH PRODL win_color5 win_color4 win_color3 | |
1534 ; Red | |
1535 movff PRODH,win_color5 ; = RRRRRGGG | |
1536 bcf win_color5,2 ; = RRRRR0GG | |
1537 btfsc win_color5,7 | |
1538 bsf win_color5,2 ; = RRRRR1GG the lower two bits are ignored by the screen | |
1539 ; Blue | |
1540 movff PRODL,win_color3 | |
1541 rrcf win_color3,F ; = UGGGBBBB and the LSB-blue into carry | |
1542 swapf win_color3,F ; = BBBBUGGG | |
1543 bcf win_color3,3 ; = BBBB0GGG | |
608 | 1544 btfsc STATUS,C |
623 | 1545 bsf win_color3,3 ; = BBBB1GGG |
1546 bcf win_color3,2 ; = BBBBB0GG | |
1547 btfsc win_color3,7 | |
1548 bsf win_color3,2 ; = BBBBB1GG | |
1549 ; Green | |
1550 rrcf PRODH,F | |
1551 rrcf PRODL,F | |
1552 rrcf PRODH,F | |
1553 rrcf PRODL,F | |
1554 rrcf PRODH,F | |
1555 rrcf PRODL,F ; = GGGGGGBB the lower two bits are ignored by the screen | |
1556 movff PRODL,win_color4 | |
608 | 1557 return |
623 | 1558 |
0 | 1559 |
634 | 1560 ;----------------------------------------------------------------------------- |
0 | 1561 |
604 | 1562 IFDEF _screendump |
1563 | |
623 | 1564 ;----------------------------------------------------------------------------- |
1565 ; Dump screen contents to the UART | |
1566 ; | |
604 | 1567 global TFT_dump_screen_check |
1568 TFT_dump_screen_check: | |
1569 btfss vusb_in ; USB (still) plugged in? | |
623 | 1570 bcf screen_dump_avail ; NO - disable screen dump function |
631 | 1571 |
1572 SERIAL_CC_RECEIVE WREG ; try to read a byte from RS232 | |
623 | 1573 btfsc rs232_rx_timeout ; anything received? |
631 | 1574 return ; NO - done |
1575 xorlw "l" ; YES - exclusive-or with coding of screen dump command | |
1576 tstfsz WREG ; - screen dump command received? | |
604 | 1577 return ; NO - return |
631 | 1578 ;bra TFT_dump_screen ; YES - serve screen dump request |
623 | 1579 |
631 | 1580 global TFT_dump_screen |
623 | 1581 TFT_dump_screen: |
1582 btfsc screen_type2 ; is this an OSTC with a screen of type 2? | |
631 | 1583 return ; YES - not supported, abort |
623 | 1584 bsf block_sensor_interrupt ; NO - disable sensor interrupts |
631 | 1585 SERIAL_LC_SEND 'l' ; - send command acknowledge |
1586 | |
604 | 1587 |
582 | 1588 ;---- Send DISPLAY box command for the full screen window ------------------- |
604 | 1589 Index_out 0x50 ; window horizontal start address |
582 | 1590 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 1591 Index_out 0x51 ; window horizontal end address |
582 | 1592 Parameter_out 0x00, 0xEF ; 0-239 |
604 | 1593 Index_out 0x52 ; window vertical start address |
582 | 1594 Parameter_out 0x00, 0x00 ; 0-319 |
604 | 1595 Index_out 0x53 ; window vertical end address |
582 | 1596 Parameter_out 0x01, 0x3F ; 0-319 |
0 | 1597 |
582 | 1598 clrf ds_column |
1599 rcall dump_screen_pixel_reset | |
0 | 1600 dump_screen_1: |
582 | 1601 btg LEDr ; LED activity toggle |
631 | 1602 ; dump even column |
604 | 1603 movlw .240 ; 240 lines, once |
582 | 1604 movwf ds_line |
0 | 1605 dump_screen_2: |
604 | 1606 Index_out 0x20 ; frame memory horizontal address |
582 | 1607 movff ds_line,WREG ; d'0' ... d'239' |
604 | 1608 mullw .1 ; copy row to PRODH:L |
582 | 1609 rcall TFT_DataWrite_PROD |
0 | 1610 |
623 | 1611 movff ds_column,WREG ; initialize X position |
1612 mullw .2 ; ds_column x 2 -> PRODH:PRODL | |
604 | 1613 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
0 | 1614 |
582 | 1615 rcall TFT_DataRead_PROD ; read pixel |
1616 rcall dump_screen_pixel | |
0 | 1617 |
582 | 1618 decfsz ds_line,F |
1619 bra dump_screen_2 | |
1620 rcall dump_screen_pixel_flush | |
0 | 1621 |
631 | 1622 ; dump odd column |
604 | 1623 movlw .240 ; 240 lines, twice |
582 | 1624 movwf ds_line |
0 | 1625 dump_screen_3: |
604 | 1626 Index_out 0x20 ; frame memory horizontal address |
582 | 1627 movff ds_line,WREG ; d'0' ... d'239' |
623 | 1628 mullw .1 ; copy row to PRODH:L |
582 | 1629 rcall TFT_DataWrite_PROD |
0 | 1630 |
623 | 1631 movff ds_column,WREG ; initialize X position |
1632 mullw .2 ; ds_column x 2 -> PRODH:PRODL | |
1633 INCI PROD ; PROD++ | |
604 | 1634 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
0 | 1635 |
582 | 1636 rcall TFT_DataRead_PROD ; read pixel |
631 | 1637 rcall dump_screen_pixel ; compress and send pixel |
0 | 1638 |
582 | 1639 decfsz ds_line,F |
1640 bra dump_screen_3 | |
1641 rcall dump_screen_pixel_flush | |
0 | 1642 |
582 | 1643 incf ds_column,F |
1644 movlw .160 | |
1645 cpfseq ds_column | |
1646 bra dump_screen_1 | |
0 | 1647 |
623 | 1648 bcf block_sensor_interrupt ; re-enable sensor interrupts |
604 | 1649 clrf RCREG1 ; clear receive buffer |
1650 bcf RCSTA1,CREN ; clear receiver status | |
631 | 1651 bsf RCSTA1,CREN ; ... |
623 | 1652 bsf screen_dump_avail ; enable screen dump function |
582 | 1653 return |
0 | 1654 |
623 | 1655 ;----------------------------------------------------------------------------- |
0 | 1656 ; Pixel compression |
1657 ; | |
604 | 1658 ; Input : PRODH:L = pixel |
0 | 1659 ; Output: Compressed stream on output. |
1660 ; Compressed format: | |
604 | 1661 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128) |
1662 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1.. 64) | |
1663 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1.. 64) | |
623 | 1664 ; |
0 | 1665 dump_screen_pixel: |
604 | 1666 movf PRODH,W ; compare pixel-high |
582 | 1667 xorwf ds_pixel+1,W |
604 | 1668 bnz dump_screen_pixel_1 ; different -> dump |
0 | 1669 |
604 | 1670 movf PRODL,W ; compare pixel-low |
582 | 1671 xorwf ds_pixel+0,W |
604 | 1672 bnz dump_screen_pixel_1 ; different -> dump |
0 | 1673 |
604 | 1674 incf ds_count,F ; same color: just increment |
582 | 1675 return |
0 | 1676 |
604 | 1677 dump_screen_pixel_1: ; send (pixel,count) tuple |
1678 movf ds_count,W ; is count zero ? | |
1679 bz dump_screen_pixel_2 ; YES - skip sending | |
0 | 1680 |
604 | 1681 movf ds_pixel+1,W ; is this a BLACK pixel ? |
582 | 1682 iorwf ds_pixel+0,W |
604 | 1683 bz dump_screen_pix_black ; YES |
0 | 1684 |
604 | 1685 movf ds_pixel+1,W ; is this a white pixel ? |
582 | 1686 andwf ds_pixel+0,W |
1687 incf WREG | |
604 | 1688 bz dump_screen_pix_white ; YES |
0 | 1689 |
582 | 1690 ; No: write the pixel itself... |
604 | 1691 movlw .64 ; max color pixel on a single byte |
1692 cpfsgt ds_count ; skip if count > 64 | |
582 | 1693 movf ds_count,W ; W <- min(64,count) |
1694 subwf ds_count,F ; ds_count <- ds_count-W | |
604 | 1695 decf WREG ; save as 0..63 |
1696 iorlw b'10000000' ; mark as a color pixel | |
0 | 1697 |
631 | 1698 SERIAL_CC_SEND WREG ; send byte in WREG |
1699 SERIAL_CC_SEND ds_pixel+1 ; send bytes in ds_pixel, high byte first | |
1700 SERIAL_CC_SEND ds_pixel+0 ; low byte last | |
1701 | |
582 | 1702 bra dump_screen_pixel_1 |
0 | 1703 |
1704 dump_screen_pixel_2: | |
604 | 1705 movff PRODH,ds_pixel+1 ; save new pixel color |
582 | 1706 movff PRODL,ds_pixel+0 |
1707 movlw 1 | |
604 | 1708 movwf ds_count ; and set count=1 |
582 | 1709 return |
0 | 1710 |
1711 dump_screen_pix_black: | |
604 | 1712 movlw .128 ; max black pixel on a single byte |
1713 cpfsgt ds_count ; skip if count > 128 | |
582 | 1714 movf ds_count,W ; W <- min(128,count) |
1715 subwf ds_count,F ; ds_count <- ds_count-W | |
604 | 1716 decf WREG ; save as 0..127 |
623 | 1717 |
0 | 1718 dump_screen_pix_3: |
631 | 1719 SERIAL_CC_SEND WREG ; send byte in WREG |
604 | 1720 bra dump_screen_pixel_1 ; more to dump ? |
0 | 1721 |
1722 dump_screen_pix_white: | |
604 | 1723 movlw .64 ; max white pixel on a single byte |
1724 cpfsgt ds_count ; skip if count > 64 | |
582 | 1725 movf ds_count,W ; W <- min(64,count) |
1726 subwf ds_count,F ; ds_count <- ds_count-W | |
631 | 1727 decf WREG ; save as 0..63 |
604 | 1728 iorlw b'11000000' ; mark as a compressed white |
631 | 1729 bra dump_screen_pix_3 ; send pixel |
0 | 1730 |
1731 dump_screen_pixel_flush: | |
582 | 1732 clrf PRODH |
1733 clrf PRODL | |
604 | 1734 rcall dump_screen_pixel_1 ; send it |
0 | 1735 dump_screen_pixel_reset: |
604 | 1736 clrf ds_count ; clear count |
582 | 1737 return |
0 | 1738 |
623 | 1739 ENDIF ; _screendump |
1740 | |
634 | 1741 ;----------------------------------------------------------------------------- |
604 | 1742 |
582 | 1743 END |