Mercurial > public > hwos_code
annotate src/tft.asm @ 604:ca4556fb60b9
bump to 2.99beta, work on 3.00 stable
author | heinrichsweikamp |
---|---|
date | Thu, 22 Nov 2018 19:47:26 +0100 |
parents | b455b31ce022 |
children | d866684249bd |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
604 | 3 ; File tft.asm ## V2.99c |
0 | 4 ; |
5 ; Managing the TFT screen | |
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 "external_flash.inc" | |
16 #include "tft_outputs.inc" | |
17 #include "eeprom_rs232.inc" | |
18 | |
19 ;============================================================================= | |
20 ; Basic bit-level macros | |
21 | |
582 | 22 RD_H macro |
23 bsf tft_rd,0 | |
24 endm | |
0 | 25 |
582 | 26 RD_L macro |
27 bcf tft_rd,0 | |
28 endm | |
0 | 29 |
582 | 30 RS_H macro |
31 bsf tft_rs,0 | |
32 endm | |
0 | 33 |
582 | 34 RS_L macro |
35 bcf tft_rs,0 | |
36 endm | |
0 | 37 |
582 | 38 NCS_H macro |
39 bsf tft_cs,0 | |
40 endm | |
0 | 41 |
582 | 42 NCS_L macro |
43 bcf tft_cs,0 | |
44 endm | |
0 | 45 |
582 | 46 WR_H macro |
47 bsf tft_nwr,0 | |
48 endm | |
0 | 49 |
582 | 50 WR_L macro |
51 bcf tft_nwr,0 | |
52 endm | |
0 | 53 |
54 ;============================================================================= | |
582 | 55 ; Byte-level macros |
56 | |
0 | 57 Index_out macro low_b |
58 movlw low_b | |
59 rcall TFT_CmdWrite | |
60 endm | |
61 | |
62 Parameter_out macro high_b, low_b | |
63 movlw high_b | |
604 | 64 movwf PORTA ; upper |
0 | 65 movlw low_b |
66 rcall TFT_DataWrite | |
67 endm | |
68 | |
69 | |
604 | 70 tft CODE |
582 | 71 |
151 | 72 ;;============================================================================= |
73 ;; TFT_write_flash_image | |
74 ;; | |
75 ;; Inputs: FSR2 = EEPROM address / 256 | |
582 | 76 ;; win_left, win_top : image CENTER position |
151 | 77 ;; Outputs: win_height, win_width. |
582 | 78 ;; image copied on screen. |
151 | 79 ;; Trashed: PROD, hi, lo |
80 ;; | |
81 ; global TFT_write_flash_image | |
82 ;TFT_write_flash_image: | |
582 | 83 ; ; Get back the full 24bit EEPROM address |
84 ; clrf ext_flash_address+0 | |
85 ; movff FSR2L,ext_flash_address+1 | |
86 ; movf FSR2H,W | |
87 ; iorlw 0x30 | |
88 ; movwf ext_flash_address+2 | |
151 | 89 ; |
582 | 90 ; ; Read header: width and height |
91 ; global TFT_write_flash_image_addr | |
151 | 92 ;TFT_write_flash_image_addr: |
93 ; call ext_flash_read_block_start | |
582 | 94 ; movff SSP2BUF,win_width+0 |
604 | 95 ; movwf SSP2BUF ; write to buffer to initiate new read |
96 ; btfss SSP2STAT, BF ; next byte ready ? | |
97 ; bra $-2 ; NO - wait... | |
582 | 98 ; movff SSP2BUF,win_width+1 |
604 | 99 ; movwf SSP2BUF ; write to buffer to initiate new read |
100 ; btfss SSP2STAT, BF ; next byte ready ? | |
101 ; bra $-2 ; NO - wait... | |
582 | 102 ; movff SSP2BUF,win_height |
604 | 103 ; movwf SSP2BUF ; write to buffer to initiate new read |
104 ; btfss SSP2STAT, BF ; next byte ready ? | |
105 ; bra $-2 ; NO - wait... | |
106 ; movff SSP2BUF,WREG ; drop 4th byte | |
107 ; movwf SSP2BUF ; write to buffer to initiate new read | |
108 ; btfss SSP2STAT, BF ; next byte ready ? | |
109 ; bra $-2 ; NO - wait... | |
151 | 110 ; |
582 | 111 ; ; Sanity check on header to avoid badly uploaded images. |
604 | 112 ; iorwf WREG ; check height < 256 |
582 | 113 ; bnz TFT_write_flash_image_failed |
604 | 114 ; movf win_width+1,W ; check width < 512 |
582 | 115 ; andlw 0xFE |
116 ; bnz TFT_write_flash_image_failed | |
151 | 117 ; |
582 | 118 ; ; Center image on win_top, win_left values |
604 | 119 ; bcf STATUS,C ; clear carry |
120 ; rrcf win_height,W ; and get height/2 | |
582 | 121 ; subwf win_top,F ; top -= height/2 |
604 | 122 ; rrcf win_width+1,W ; get 9th bit into carry |
123 ; rrcf win_width+0,W ; get width/2 (in 0..320 range) | |
582 | 124 ; bcf STATUS,C |
604 | 125 ; rrcf WREG,W ; get width/2 in 0..160 range |
582 | 126 ; subwf win_leftx2,F ; left -= width/2 |
151 | 127 ; |
604 | 128 ; rcall TFT_box_write ; inputs : win_top, win_leftx2, win_height, win_width (in 1..320 range) |
0 | 129 ; |
582 | 130 ; ; Compute number of pixels to move (result on 17 bits !) |
131 ; clrf TBLPTRU | |
132 ; movf win_width+0,W | |
604 | 133 ; mulwf win_height ; result in PRODL:H |
582 | 134 ; movf win_width+1,W |
135 ; bz TFT_write_flash_image_1 ; width > 8bits ? | |
604 | 136 ; movf win_height,W ; YES - add extra |
582 | 137 ; addwf PRODH,F |
604 | 138 ; rlcf TBLPTRU ; and carry into upper register |
151 | 139 ;TFT_write_flash_image_1: |
582 | 140 ; incf PRODH,F ; pre-condition nested loops |
141 ; incf TBLPTRU,F | |
151 | 142 ; |
582 | 143 ; ; Write pixels |
604 | 144 ; Index_out 0x22 ; frame memory data write start |
145 ; RS_H ; data | |
151 | 146 ; |
147 ;TFT_write_flash_image_loop: | |
604 | 148 ; btfss SSP2STAT, BF ; buffer full? |
149 ; bra $-2 ; NO - wait... | |
150 ; movff SSP2BUF,PORTH ; read lo | |
151 ; movwf SSP2BUF ; write to buffer to initiate new read | |
151 | 152 ; |
604 | 153 ; btfss SSP2STAT, BF ; buffer full? |
154 ; bra $-2 ; NO - wait... | |
155 ; movff SSP2BUF,PORTA ; and read hi | |
156 ; movwf SSP2BUF ; write to buffer to initiate new read | |
151 | 157 ; WR_L |
604 | 158 ; WR_H ; write 1 pixel |
151 | 159 ; |
160 ; decfsz PRODL,F | |
161 ; bra TFT_write_flash_image_loop | |
162 ; decfsz PRODH,F | |
163 ; bra TFT_write_flash_image_loop | |
164 ; decfsz TBLPTRU,F | |
165 ; bra TFT_write_flash_image_loop | |
166 ; | |
604 | 167 ; btfss SSP2STAT, BF ; buffer full? |
168 ; bra $-2 ; NO - wait | |
169 ; movf SSP2BUF,W ; read dummy byte | |
151 | 170 ; |
582 | 171 ; bsf flash_ncs ; CS=1 |
172 ; movlw 0x00 ; NOP, to stop window mode | |
604 | 173 ; bra TFT_CmdWrite ; this routine "returns" |
151 | 174 ; |
175 ; ;---- Draw a 4x4 red square in place of missing images... | |
176 ;TFT_write_flash_image_failed: | |
582 | 177 ; movlw -1 |
178 ; addwf win_leftx2,F | |
179 ; movlw -2 | |
180 ; addwf win_top,F | |
181 ; movlw 2 | |
182 ; movwf win_width+0 | |
183 ; clrf win_width+1 | |
184 ; movlw 4 | |
185 ; movwf win_height | |
186 ; movlw color_red | |
187 ; rcall TFT_set_color | |
188 ; goto TFT_box | |
151 | 189 ; |
190 ;;============================================================================= | |
0 | 191 |
582 | 192 global TFT_CmdWrite |
0 | 193 TFT_CmdWrite: |
604 | 194 RS_L ; command |
195 clrf PORTA ; upper | |
582 | 196 bcf INTCON,GIE |
604 | 197 movwf PORTH ; lower |
0 | 198 WR_L |
604 | 199 WR_H ; tick |
582 | 200 bsf INTCON,GIE |
201 return | |
0 | 202 |
582 | 203 global TFT_DataWrite |
0 | 204 TFT_DataWrite: |
604 | 205 RS_H ; data |
582 | 206 bcf INTCON,GIE |
604 | 207 movwf PORTH ; lower |
0 | 208 WR_L |
604 | 209 WR_H ; tick |
582 | 210 bsf INTCON,GIE |
0 | 211 return |
212 | |
213 ;============================================================================= | |
582 | 214 |
215 global TFT_ClearScreen | |
0 | 216 TFT_ClearScreen: |
604 | 217 Index_out 0x50 ; window horizontal start address |
582 | 218 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 219 Index_out 0x51 ; window horizontal end address |
582 | 220 Parameter_out 0x00, 0xEF ; 0-239 |
604 | 221 Index_out 0x52 ; window vertical start address |
582 | 222 Parameter_out 0x00, 0x00 ; 0-319 |
604 | 223 Index_out 0x53 ; window vertical end address |
582 | 224 Parameter_out 0x01, 0x3F ; 0-319 |
604 | 225 Index_out 0x20 ; frame memory horizontal address |
582 | 226 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 227 Index_out 0x21 ; frame memory vertical address |
582 | 228 Parameter_out 0x01, 0x3F ; 0-319 |
0 | 229 |
604 | 230 Index_out 0x22 ; frame memory data write start |
0 | 231 |
604 | 232 RD_H ; not read |
233 RS_H ; data | |
234 NCS_L ; not CS | |
235 clrf PORTH ; data lower | |
0 | 236 |
237 movlw d'10' | |
238 movwf tft_temp3 | |
239 TFT_ClearScreen2: | |
240 movlw d'30' | |
241 movwf tft_temp2 | |
242 TFT_ClearScreen3: | |
604 | 243 clrf tft_temp1 ; 30*10*256=76800 pixels -> clear complete 240*320 |
582 | 244 bcf INTCON,GIE |
0 | 245 TFT_ClearScreen4: |
246 WR_L | |
604 | 247 WR_H ; tick |
0 | 248 decfsz tft_temp1,F |
249 bra TFT_ClearScreen4 | |
582 | 250 bsf INTCON,GIE |
0 | 251 decfsz tft_temp2,F |
252 bra TFT_ClearScreen3 | |
253 decfsz tft_temp3,F | |
254 bra TFT_ClearScreen2 | |
582 | 255 |
256 movlw 0x00 ; NOP, to stop window mode | |
604 | 257 bra TFT_CmdWrite ; and return |
582 | 258 |
0 | 259 |
260 ;============================================================================= | |
582 | 261 |
262 global TFT_DisplayOff | |
0 | 263 TFT_DisplayOff: |
582 | 264 clrf CCPR1L ; PWM OFF |
0 | 265 clrf PORTA |
582 | 266 clrf PORTH |
267 RD_L ; LOW | |
0 | 268 nop |
582 | 269 RS_L ; LOW |
0 | 270 bcf tft_nwr |
271 nop | |
272 bcf tft_cs | |
273 nop | |
274 bcf tft_nreset | |
275 WAITMS d'1' | |
276 bsf tft_power ; inverted... | |
277 bcf lightsen_power ; power-down light sensor | |
278 return | |
279 | |
280 ; ----------------------------- | |
281 ; TFT boot | |
282 ; ----------------------------- | |
582 | 283 |
284 global TFT_boot | |
0 | 285 TFT_boot: |
286 clrf PORTA | |
287 clrf PORTH | |
288 RD_L ; LOW | |
289 bcf tft_nwr | |
290 nop | |
291 bcf tft_cs | |
292 nop | |
293 bcf tft_nreset | |
294 WAITMS d'1' | |
295 bcf tft_power ; inverted... | |
296 WAITMS d'1' | |
297 | |
298 RD_H ; Keep high | |
299 WR_H ; | |
300 NCS_L ; Not CS | |
301 | |
302 WAITMS d'2' | |
303 bsf tft_nreset | |
461 | 304 WAITMS d'5' |
305 bcf tft_nreset | |
306 WAITMS d'5' | |
307 bsf tft_nreset | |
0 | 308 WAITMS d'150' |
604 | 309 bsf lightsen_power ; supply power to light sensor |
0 | 310 |
582 | 311 ; Data Transfer Synchronization |
0 | 312 Parameter_out 0x00, 0x00 |
313 Parameter_out 0x00, 0x00 | |
582 | 314 |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
315 ; Get screentype from Bootloader-Info |
582 | 316 movlw 0x7B |
317 movwf TBLPTRL | |
318 movlw 0xF7 | |
319 movwf TBLPTRH | |
320 movlw 0x01 | |
321 movwf TBLPTRU | |
604 | 322 TBLRD*+ ; reads .110 for cR and USB OSTC3, .0 for BLE (2 and 3), and .2 for display1 OSTC |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
323 movlw 0x02 |
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
324 cpfseq TABLAT |
604 | 325 bra TFT_boot_0 ; display0 |
360 | 326 |
327 TFT_boot_1: | |
582 | 328 ; Init through config table... |
329 movlw 0x74 | |
330 movwf TBLPTRL | |
331 movlw 0xF7 | |
332 movwf TBLPTRH | |
333 movlw 0x01 | |
334 movwf TBLPTRU | |
335 bsf screen_type | |
336 bra TFT_boot_com | |
360 | 337 |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
338 TFT_boot_0: |
582 | 339 ; Init through config table... |
340 movlw LOW display0_config_table | |
341 movwf TBLPTRL | |
342 movlw HIGH display0_config_table | |
343 movwf TBLPTRH | |
344 movlw UPPER display0_config_table | |
345 movwf TBLPTRU | |
346 bcf screen_type | |
347 | |
360 | 348 TFT_boot_com: |
582 | 349 rcall display0_init_loop |
0 | 350 |
582 | 351 Index_out 0x03 |
352 btfsc flip_screen ; 180° rotation ? | |
604 | 353 bra TFT_boot2 ; YES |
360 | 354 |
582 | 355 btfss screen_type ; display1? |
604 | 356 bra TFT_boot1a ; NO |
582 | 357 Parameter_out 0x10, 0x00 ; display1 |
358 bra TFT_boot3 | |
360 | 359 TFT_boot1a: |
582 | 360 Parameter_out 0x50, 0x20 ; display0 |
361 bra TFT_boot3 | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
362 TFT_boot2: |
582 | 363 btfss screen_type ; display1? |
604 | 364 bra TFT_boot2a ; NO |
582 | 365 Parameter_out 0x10, 0x30 ; display1 |
366 bra TFT_boot3 | |
360 | 367 TFT_boot2a: |
582 | 368 Parameter_out 0x50, 0x10 ; display0 |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
369 TFT_boot3: |
0 | 370 Index_out 0x22 |
225
31088352ee32
BUGFIX: Show dives with >999mins divetime correctly
heinrichsweikamp
parents:
152
diff
changeset
|
371 rcall TFT_ClearScreen |
0 | 372 Index_out 0x07 |
312 | 373 Parameter_out 0x01, 0x33 |
0 | 374 return |
375 | |
376 display0_config_table: | |
582 | 377 ; Reg, Dat0, Dat1 or 0xFF,0x00,0x00 for end |
378 db 0xA4,0x00,0x01,0xFF,.002,0x00 | |
379 db 0x09,0x00,0x01,0x92,0x04,0x00 | |
380 db 0x93,0x04,0x02,0x94,0x00,0x02 | |
381 db 0x07,0x00,0x00,0x10,0x04,0x30 | |
382 db 0x11,0x02,0x37,0x12,0x11,0x8D | |
383 db 0x13,0x11,0x00,0x01,0x01,0x00 | |
384 db 0x02,0x02,0x00,0x03,0x50,0x20 | |
385 db 0x0A,0x00,0x08,0x0D,0x00,0x00 | |
386 db 0x0E,0x00,0x30,0xFF,.151,0x00 | |
387 db 0x12,0x11,0xBD,0x20,0x00,0x00 | |
388 db 0x21,0x00,0x00,0x30,0x06,0x02 | |
389 db 0x31,0x56,0x0D,0x32,0x05,0x07 | |
390 db 0x33,0x06,0x09,0x34,0x00,0x00 | |
391 db 0x35,0x09,0x06,0x36,0x57,0x05 | |
392 db 0x37,0x0D,0x06,0x38,0x02,0x06 | |
393 db 0x39,0x00,0x00,0xFF,0x00,0x00 | |
0 | 394 |
395 display0_init_loop: | |
582 | 396 TBLRD*+ |
397 movlw 0xFF | |
398 cpfseq TABLAT | |
604 | 399 bra display0_config_write ; write config pair to display |
582 | 400 ; Delay ms or quit (return) |
401 TBLRD*+ | |
604 | 402 tstfsz TABLAT ; end of config? |
403 bra $+4 ; NO | |
404 return ; YES - done | |
582 | 405 movf TABLAT,W |
604 | 406 call WAITMSX ; wait WREG milliseconds |
407 TBLRD*+ ; dummy read (Third byte of delay command) | |
408 bra display0_init_loop ; loop | |
0 | 409 |
604 | 410 display0_config_write: ; with command in WREG |
582 | 411 movf TABLAT,W |
604 | 412 rcall TFT_CmdWrite ; write command |
413 TBLRD*+ ; get config0 | |
582 | 414 movff TABLAT,PORTA |
604 | 415 TBLRD*+ ; get config1 |
582 | 416 movf TABLAT,W |
604 | 417 rcall TFT_DataWrite ; write config |
418 bra display0_init_loop ; loop | |
0 | 419 |
420 | |
421 ;============================================================================= | |
422 ; Smooth lighting-up of the display: | |
423 ; | |
424 ; Trashes: WREG, PRODL | |
425 ; Typical usage: | |
604 | 426 ; clrf CCPR1L ; backlight off |
582 | 427 ; [draw splash screen] |
428 ; call TFT_DisplayFadeIn | |
429 | |
430 global TFT_Display_FadeIn | |
0 | 431 TFT_Display_FadeIn: |
604 | 432 movlw CCP1CON_VALUE ; see hwos.inc |
582 | 433 movwf CCP1CON |
604 | 434 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor |
435 clrf CCPR1L ; backlight off - to be sure | |
582 | 436 movff max_CCPR1L,PRODL |
0 | 437 TFT_Display_FadeIn_0: |
604 | 438 incf CCPR1L,F ; duty cycle |
582 | 439 WAITMS d'2' |
440 decfsz PRODL,F | |
441 bra TFT_Display_FadeIn_0 | |
604 | 442 bcf tft_is_dimming ; dimming done |
582 | 443 return |
0 | 444 |
445 ;============================================================================= | |
446 ; Smooth lighting-off of the display: | |
447 ; Trashes: WREG, PRODL | |
582 | 448 |
449 global TFT_Display_FadeOut | |
0 | 450 TFT_Display_FadeOut: |
582 | 451 movff max_CCPR1L,PRODL |
604 | 452 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor |
0 | 453 TFT_Display_FadeOut_0: |
604 | 454 movff PRODL,CCPR1L ; duty cycle |
582 | 455 WAITMS d'1' |
456 decfsz PRODL,F | |
457 bra TFT_Display_FadeOut_0 | |
458 clrf CCPR1L | |
459 return | |
0 | 460 |
461 ;============================================================================= | |
462 | |
604 | 463 global box_std_block, box_black_block, box_color_block |
0 | 464 |
604 | 465 box_std_block: ; use white color |
582 | 466 setf WREG |
467 bra box_common | |
604 | 468 box_black_block: ; use black color |
582 | 469 clrf WREG |
0 | 470 box_common: |
471 box_color_block: | |
582 | 472 rcall TFT_set_color |
473 VARARGS_BEGIN | |
474 VARARGS_GET8 win_top | |
475 VARARGS_GET8 win_height | |
476 VARARGS_GET8 win_leftx2 | |
477 VARARGS_GET8 win_width | |
478 VARARGS_END | |
479 bra TFT_box | |
0 | 480 |
481 ;----------------------------------------------------------------------------- | |
482 | |
582 | 483 global box_frame_std, box_frame_common, box_frame_color, box_frame_color16 |
0 | 484 |
485 box_frame_std: | |
582 | 486 setf WREG |
487 rcall TFT_set_color | |
0 | 488 box_frame_common: |
582 | 489 VARARGS_BEGIN |
490 VARARGS_GET8 win_top | |
491 VARARGS_GET8 win_height | |
492 VARARGS_GET8 win_leftx2 | |
493 VARARGS_GET8 win_width | |
494 VARARGS_END | |
495 bra TFT_frame | |
0 | 496 box_frame_color: |
582 | 497 rcall TFT_set_color |
0 | 498 box_frame_color16: |
582 | 499 bra box_frame_common |
0 | 500 |
434 | 501 ;;============================================================================= |
502 ;; Init for half_pixel_write | |
503 ;; Set column register on TFT device, and current color. | |
504 ;; Inputs: win_leftx2 | |
505 ;; Outputs: win_color:2 | |
506 ;; Trashed: WREG, PROD | |
582 | 507 ; |
508 ; global init_pixel_write | |
434 | 509 ;init_pixel_write: |
582 | 510 ; movf win_leftx2,W |
511 ; mullw 2 | |
604 | 512 ; rcall pixel_write_col320 ; start address vertical (.0 - .319) |
582 | 513 ; setf WREG |
514 ; bra TFT_set_color | |
0 | 515 |
516 ;----------------------------------------------------------------------------- | |
517 ; Writes two half-pixels at position (win_top,win_leftx2) | |
518 ; Inputs: win_leftx2, win_top, win_color:2 | |
519 ; Trashed: WREG, PROD | |
582 | 520 |
521 global pixel_write | |
0 | 522 pixel_write: |
582 | 523 movf win_leftx2,W |
524 mullw 2 ; win_leftx2 x 2 -> PRODH:PRODL | |
604 | 525 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
526 rcall half_pixel_write ; write this half-one | |
527 movf win_leftx2,W ; address of next one | |
582 | 528 mullw 2 |
529 infsnz PRODL ; +1 | |
530 incf PRODH | |
531 rcall pixel_write_col320 | |
604 | 532 bra half_pixel_write ; note: Cmd 0x20 is mandatory, because |
582 | 533 ; of the auto-increment going vertical |
0 | 534 |
535 global pixel_write_col320 | |
536 pixel_write_col320: | |
582 | 537 btfsc screen_type ; display1? |
604 | 538 bra pixel_write_col320_d1 ; YES |
582 | 539 ; Display0 |
540 btfss flip_screen ; 180° rotation? | |
604 | 541 bra pixel_write_noflip_H ; NO |
542 bra pixel_write_flip_H ; YES | |
582 | 543 pixel_write_col320_d1: ; Display1 |
544 btfsc flip_screen ; 180° rotation? | |
604 | 545 bra pixel_write_noflip_H ; YES for d1 |
546 pixel_write_flip_H: ; flip d0 | |
547 movf PRODL,W ; 16 bits 319 - PROD --> PROD | |
582 | 548 sublw LOW(.319) ; 319-W --> W |
549 movwf PRODL | |
550 movf PRODH,W | |
604 | 551 btfss STATUS,C ; borrow = /CARRY |
582 | 552 incf WREG |
553 sublw HIGH(.319) | |
554 movwf PRODH | |
151 | 555 |
556 pixel_write_noflip_H: | |
604 | 557 Index_out 0x21 ; frame memory vertical address |
582 | 558 bra TFT_DataWrite_PROD ; and return... |
0 | 559 |
560 ;----------------------------------------------------------------------------- | |
561 ; Writes one half-pixel at position (win_top,win_leftx2). | |
562 ; Inputs: win_leftx2, win_top, win_color:2 | |
563 ; Trashed: WREG, PROD | |
582 | 564 |
565 global half_pixel_write | |
0 | 566 half_pixel_write: |
582 | 567 movf win_top,W ; d'0' ... d'239' |
568 ; Variant with Y position in WREG. | |
0 | 569 half_pixel_write_1: |
582 | 570 btfss flip_screen ; 180° rotation? |
571 sublw .239 ; 239-Y --> Y | |
604 | 572 mullw .1 ; copy row to PRODL (PRODH=0) |
573 Index_out 0x20 ; frame memory horizontal address | |
582 | 574 rcall TFT_DataWrite_PROD |
0 | 575 |
604 | 576 Index_out 0x22 ; frame memory data write start |
577 RS_H ; data | |
582 | 578 bcf INTCON,GIE |
604 | 579 movff win_color1,PORTA ; upper |
580 movff win_color2,PORTH ; lower | |
582 | 581 WR_L |
604 | 582 WR_H ; tick |
582 | 583 bsf INTCON,GIE |
584 return | |
0 | 585 |
586 ;----------------------------------------------------------------------------- | |
587 ; Writes a vertical line of half-pixel at position (win_top,win_leftx2,win_height). | |
588 ; Inputs: win_leftx2, win_top, win_height, win_color:2 | |
589 ; Trashed: WREG, PROD, TABLAT, TBLPTRL | |
582 | 590 |
0 | 591 global half_vertical_line |
592 half_vertical_line: | |
604 | 593 clrf TABLAT ; loop index |
0 | 594 |
595 half_vertical_line_loop: | |
604 | 596 movf win_leftx2,W ; init X position |
582 | 597 mullw .2 |
604 | 598 movf TABLAT,W ; get loop index |
599 andlw .1 ; just low bit | |
600 xorwf PRODL,F ; and use it to jitter current X position | |
601 rcall pixel_write_col320 ; start address vertical (.0 - .319) | |
0 | 602 |
604 | 603 movf win_height,W ; index reached height (bank0 read) ? |
582 | 604 xorwf TABLAT,W |
604 | 605 btfsc STATUS,Z ; Equal ? |
606 return ; YES - done | |
607 movf win_top,W ; Y = top + index (bank0 read) | |
582 | 608 addwf TABLAT,W |
609 rcall half_pixel_write_1 | |
610 incf TABLAT,F ; index++ | |
611 bra half_vertical_line_loop | |
0 | 612 |
613 ;----------------------------------------------------------------------------- | |
614 ; Writes a horizontal line of half-pixel at position (win_top,win_leftx2,win_width). | |
615 ; Inputs: win_leftx2, win_top, win_width, win_color:2 | |
616 ; Trashed: WREG, PROD, TABLAT, TBLPTRL | |
582 | 617 |
0 | 618 global half_horizontal_line |
619 half_horizontal_line: | |
604 | 620 clrf TABLAT ; loop index |
0 | 621 |
622 half_horizontal_line_loop: | |
604 | 623 movf win_leftx2,W ; init X position |
582 | 624 mullw .2 |
604 | 625 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
626 movf win_width,W ; index reached height (bank0 read) ? | |
582 | 627 xorwf TABLAT,W |
604 | 628 btfsc STATUS,Z ; equal ? |
629 return ; YES - done | |
630 movf win_top,W ; Y = top + index (bank0 read) | |
582 | 631 addwf TABLAT,W |
632 rcall half_pixel_write_1 | |
633 incf TABLAT,F ; index++ | |
634 bra half_horizontal_line_loop | |
0 | 635 |
636 | |
637 ;----------------------------------------------------------------------------- | |
638 ; TFT Data Cmd via W | |
582 | 639 |
640 global TFT_DataWrite_PROD | |
0 | 641 TFT_DataWrite_PROD: |
604 | 642 ; RD_H ; keep high |
643 RS_H ; data | |
582 | 644 bcf INTCON,GIE |
604 | 645 movff PRODH,PORTA ; move high byte to PORTA |
646 movff PRODL,PORTH ; move low byte to PORTH | |
0 | 647 WR_L |
604 | 648 WR_H ; tick |
582 | 649 bsf INTCON,GIE |
0 | 650 return |
651 | |
652 TFT_DataRead_PROD: | |
604 | 653 Index_out 0x22 ; frame memory data read start |
360 | 654 TFT_CmdRead_PROD: |
604 | 655 setf TRISA ; port A as input |
656 setf TRISH ; port H as input | |
657 RS_H ; data | |
658 WR_H ; not write | |
659 RD_L ; read | |
582 | 660 nop |
661 nop | |
662 nop | |
604 | 663 RD_H ; tick |
582 | 664 nop |
665 nop | |
666 nop | |
604 | 667 RD_L ; read |
582 | 668 nop |
669 ;nop | |
670 ;nop | |
671 movff PORTA,PRODH | |
672 movff PORTH,PRODL | |
604 | 673 RD_H ; tick |
582 | 674 nop |
604 | 675 clrf TRISA ; port A as output |
676 clrf TRISH ; port H as output | |
0 | 677 return |
678 | |
679 ;============================================================================= | |
604 | 680 ; Output TFT Window Address commands |
681 ; Inputs : win_top, win_leftx2, win_height, win_width | |
682 ; Output : PortA/PortH commands | |
0 | 683 ; Trashed: PROD |
582 | 684 |
685 global TFT_box_write | |
0 | 686 TFT_box_write: |
604 | 687 movf win_leftx2,W ; compute left = 2 * leftx2 --> PROD |
432 | 688 mullw 2 |
0 | 689 |
582 | 690 global TFT_box_write_16bit_win_left |
604 | 691 TFT_box_write_16bit_win_left: ; Wwth column in PRODL:PRODH |
582 | 692 btfsc screen_type ; display1? |
604 | 693 bra TFT_box_write_16bit_win_left_d1 ; YES |
582 | 694 ; Display0 |
695 btfsc flip_screen ; 180° rotation? | |
604 | 696 bra DISP_box_flip_H ; YES |
697 bra TFT_box_write_16bit_win_left_com ; NO | |
582 | 698 TFT_box_write_16bit_win_left_d1: ; Display1 |
699 btfss flip_screen ; 180° rotation? | |
604 | 700 bra DISP_box_flip_H ; NO for d1 |
582 | 701 ; Yes for d1 |
361 | 702 TFT_box_write_16bit_win_left_com: |
582 | 703 ;---- Normal horizontal window --------------------------------------- |
604 | 704 Index_out 0x52 ; window vertical start address |
705 rcall TFT_DataWrite_PROD ; output left | |
706 Index_out 0x21 ; frame memory vertical address | |
707 rcall TFT_DataWrite_PROD ; output left | |
0 | 708 |
582 | 709 movf win_width+0,W ; right = left + width - 1 |
432 | 710 addwf PRODL,F |
711 movf win_width+1,W | |
712 addwfc PRODH,F | |
582 | 713 decf PRODL,F ; decrement result |
714 btfss STATUS,C | |
432 | 715 decf PRODH,F |
0 | 716 |
604 | 717 Index_out 0x53 ; window vertical end address |
582 | 718 rcall TFT_DataWrite_PROD |
719 bra DISP_box_noflip_H | |
0 | 720 |
582 | 721 ;---- Flipped horizontal window -------------------------------------- |
151 | 722 DISP_box_flip_H: |
604 | 723 movf PRODL,W ; 16 bits 319 - PROD --> PROD |
724 sublw LOW(.319) ; 319 - WREG --> WREG | |
582 | 725 movwf PRODL |
726 movf PRODH,W | |
604 | 727 btfss STATUS,C ; borrow = /CARRY |
582 | 728 incf WREG |
729 sublw HIGH(.319) | |
730 movwf PRODH | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
731 |
604 | 732 Index_out 0x53 ; window vertical start address |
733 rcall TFT_DataWrite_PROD ; output left | |
734 Index_out 0x21 ; frame memory vertical address | |
735 rcall TFT_DataWrite_PROD ; output left | |
151 | 736 |
604 | 737 movf win_width+0,W ; 16 bits PROD - width --> PROD |
582 | 738 subwf PRODL,F ; PRODL - WREG --> PRODL |
739 movf win_width+1,W | |
740 subwfb PRODH,F | |
604 | 741 infsnz PRODL ; PROD + 1 --> PROD |
582 | 742 incf PRODH |
151 | 743 |
604 | 744 Index_out 0x52 ; window vertical end address |
582 | 745 rcall TFT_DataWrite_PROD |
151 | 746 |
747 DISP_box_noflip_H: | |
582 | 748 btfss flip_screen ; 180° rotation ? |
604 | 749 bra TFT_box_noflip_V ; NO |
151 | 750 |
582 | 751 ;---- Flipped vertical window ----------------------------------------- |
752 movff win_top,PRODH ; top --> PRODH (first byte) | |
753 movf win_height,W | |
754 addwf PRODH,W | |
432 | 755 decf WREG |
604 | 756 movwf PRODL ; top + height - 1 --> PRODL (second byte) |
151 | 757 |
604 | 758 Index_out 0x50 ; window horizontal start address |
432 | 759 movf PRODH,W |
604 | 760 rcall TFT_DataWrite ; lower (and tick) |
151 | 761 |
604 | 762 Index_out 0x51 ; window horizontal end address |
582 | 763 movf PRODL,W |
604 | 764 rcall TFT_DataWrite ; lower (and tick) |
582 | 765 |
604 | 766 Index_out 0x20 ; frame memory horizontal address |
432 | 767 movf PRODH,W |
604 | 768 bra TFT_DataWrite ; lower (and tick) and return |
151 | 769 |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
770 TFT_box_noflip_V: |
582 | 771 ;---- Normal vertical window ---------------------------------------- |
772 movff win_top,PRODL | |
773 movf win_height,W | |
774 addwf PRODL,W | |
775 sublw .240 ; 240 - top - height | |
604 | 776 movwf PRODH ; first byte |
0 | 777 |
432 | 778 movf PRODL,W |
604 | 779 sublw .239 ; 239 - top |
780 movwf PRODL ; --> second byte | |
0 | 781 |
604 | 782 Index_out 0x50 ; window horizontal start address |
432 | 783 movf PRODH,W |
604 | 784 rcall TFT_DataWrite ; lower (and tick) |
0 | 785 |
604 | 786 Index_out 0x51 ; window horizontal end address |
432 | 787 movf PRODL,W |
604 | 788 rcall TFT_DataWrite ; lower (and tick) |
0 | 789 |
604 | 790 Index_out 0x20 ; frame memory horizontal address |
432 | 791 movf PRODL,W |
604 | 792 bra TFT_DataWrite ; lower (and tick) and return |
582 | 793 |
0 | 794 |
795 ;============================================================================= | |
604 | 796 ; TFT_frame : draw a frame around current box with current color |
0 | 797 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 |
798 ; Outputs: (none) | |
799 ; Trashed: WREG, PROD, aa_start:2, aa_end:2 | |
800 | |
582 | 801 global TFT_frame |
802 TFT_frame: | |
604 | 803 movff win_top,save_top ; backup everything |
582 | 804 movff win_height,save_height |
805 movff win_leftx2,save_left | |
806 movff win_width,save_width | |
0 | 807 |
582 | 808 ;---- TOP line ----------------------------------------------------------- |
604 | 809 movlw .1 ; row ~ height = 1 |
582 | 810 movwf win_height |
811 rcall TFT_box | |
0 | 812 |
582 | 813 ;---- BOTTOM line -------------------------------------------------------- |
604 | 814 movff save_top,PRODL ; get back top |
815 movff save_height,WREG ; get back height | |
816 addwf PRODL,W ; top + height | |
817 decf WREG ; top + height - 1 | |
818 movwf win_top ; top + height - 1 --> top | |
582 | 819 rcall TFT_box |
0 | 820 |
582 | 821 ;---- LEFT column -------------------------------------------------------- |
604 | 822 movff save_top,win_top ; restore top/height |
582 | 823 movff save_height,win_height |
604 | 824 movlw .1 ; column ~ width = 1 |
582 | 825 movwf win_width+0 |
826 rcall TFT_box | |
827 | |
828 ;---- RIGHT column ------------------------------------------------------- | |
829 movff save_left,WREG | |
830 movff save_width,PRODL | |
831 addwf PRODL,W | |
832 decf WREG | |
833 movwf win_leftx2 | |
834 rcall TFT_box | |
835 | |
836 ;---- Restore everything ------------------------------------------------- | |
837 movff save_left,win_leftx2 | |
838 movff save_width,win_width | |
839 return | |
0 | 840 |
841 ;============================================================================= | |
604 | 842 ; TFT_box: fills current box with current color |
843 ; Inputs : win_top, win_leftx2, win_height, win_width, win_color1, win_color2 | |
0 | 844 ; Outputs: (none) |
845 ; Trashed: WREG, PROD | |
846 | |
582 | 847 global TFT_box |
0 | 848 TFT_box: |
582 | 849 ;---- Define Window ------------------------------------------------------ |
850 bcf STATUS,C | |
851 rlcf win_width+0,F | |
852 rlcf win_width+1,F ; x2 | |
604 | 853 rcall TFT_box_write ; setup box |
0 | 854 |
582 | 855 global TFT_box_16bit_win_left |
83 | 856 TFT_box_16bit_win_left: |
582 | 857 bcf STATUS,C |
858 rrcf win_width+1,F ; width /= 2 | |
859 rrcf win_width+0,F | |
0 | 860 |
582 | 861 ;---- Fill Window -------------------------------------------------------- |
604 | 862 Index_out 0x22 ; frame memory data write start |
0 | 863 |
604 | 864 clrf PRODH ; column counter |
865 RS_H ; data | |
0 | 866 |
604 | 867 TFT_box2: ; loop height times |
0 | 868 movff win_height,PRODL |
869 | |
582 | 870 TFT_box3: ; loop width times |
436 | 871 bcf INTCON,GIE |
604 | 872 movff win_color1,PORTA ; upper |
873 movff win_color2,PORTH ; lower | |
0 | 874 WR_L |
604 | 875 WR_H ; tick |
582 | 876 |
604 | 877 ; movff win_color1,PORTA ; upper |
878 ; movff win_color2,PORTH ; lower | |
0 | 879 WR_L |
604 | 880 WR_H ; tick |
582 | 881 bsf INTCON,GIE |
882 decfsz PRODL,F ; row loop finished ? | |
604 | 883 bra TFT_box3 ; NO - continue |
0 | 884 |
582 | 885 incf PRODH,F ; column count ++ |
0 | 886 |
582 | 887 movf win_bargraph,W ; current column == bargraph ? |
888 cpfseq PRODH | |
604 | 889 bra TFT_box4 ; NO - just loop |
890 clrf win_color1 ; Yes - switch to black | |
891 clrf win_color2 ; - ... | |
0 | 892 TFT_box4: |
582 | 893 movf win_width+0,W ; compare ? |
894 xorwf PRODH,W | |
604 | 895 bnz TFT_box2 ; Loop not finished |
0 | 896 |
582 | 897 movlw 0x00 ; NOP, to stop window mode |
898 rcall TFT_CmdWrite | |
0 | 899 |
604 | 900 ; reset bargraph mode... |
582 | 901 setf win_bargraph |
902 return | |
0 | 903 |
904 ;============================================================================= | |
604 | 905 ; Converts 8 bit RGB b'RRRGGGBB' into 16 bit RGB b'RRRRRGGGGGGBBBBB' |
0 | 906 |
582 | 907 global TFT_set_color |
0 | 908 TFT_set_color: |
604 | 909 movwf tft_temp1 ; get 8 Bit RGB b'RRRGGGBB' |
910 movwf tft_temp2 ; copy | |
0 | 911 |
604 | 912 ; mask bit 7,6,5,4,3,2 |
0 | 913 movlw b'00000011' |
914 andwf tft_temp2,F | |
915 | |
916 movlw b'00000000' | |
917 dcfsnz tft_temp2,F | |
918 movlw b'01010000' | |
919 dcfsnz tft_temp2,F | |
920 movlw b'10100000' | |
921 dcfsnz tft_temp2,F | |
922 movlw b'11111000' | |
604 | 923 movwf tft_temp3 ; blue done |
0 | 924 |
604 | 925 movff tft_temp1,tft_temp2 ; copy |
926 ; mask bit 7,6,5,1,0 | |
0 | 927 movlw b'00011100' |
928 andwf tft_temp2,F | |
929 rrncf tft_temp2,F | |
930 rrncf tft_temp2,F | |
931 | |
932 movlw b'00000000' | |
933 dcfsnz tft_temp2,F | |
934 movlw b'00000100' | |
935 dcfsnz tft_temp2,F | |
936 movlw b'00001000' | |
937 dcfsnz tft_temp2,F | |
938 movlw b'00001100' | |
939 dcfsnz tft_temp2,F | |
940 movlw b'00010000' | |
941 dcfsnz tft_temp2,F | |
942 movlw b'00010100' | |
943 dcfsnz tft_temp2,F | |
944 movlw b'00100000' | |
945 dcfsnz tft_temp2,F | |
946 movlw b'00111111' | |
582 | 947 movwf tft_temp4 |
0 | 948 |
949 rrcf tft_temp4,F | |
950 rrcf tft_temp3,F | |
951 | |
952 rrcf tft_temp4,F | |
953 rrcf tft_temp3,F | |
954 | |
955 rrcf tft_temp4,F | |
604 | 956 rrcf tft_temp3,W ; tft_temp3 (b'GGGBBBBB') done |
957 movwf win_color2 ; set color registers... | |
0 | 958 |
604 | 959 movff tft_temp1,tft_temp2 ; copy |
0 | 960 clrf tft_temp1 |
961 | |
962 rrcf tft_temp4,F | |
963 rrcf tft_temp1,F | |
964 | |
965 rrcf tft_temp4,F | |
966 rrcf tft_temp1,F | |
967 | |
968 rrcf tft_temp4,F | |
604 | 969 rrcf tft_temp1,F ; green done |
0 | 970 |
604 | 971 ; mask bit 4,3,2,1,0 |
0 | 972 movlw b'11100000' |
973 andwf tft_temp2,F | |
974 | |
975 rrncf tft_temp2,F | |
976 rrncf tft_temp2,F | |
977 rrncf tft_temp2,F | |
978 rrncf tft_temp2,F | |
979 rrncf tft_temp2,F | |
980 | |
981 movlw b'00000000' | |
982 dcfsnz tft_temp2,F | |
983 movlw b'00000100' | |
984 dcfsnz tft_temp2,F | |
985 movlw b'00001000' | |
986 dcfsnz tft_temp2,F | |
987 movlw b'00001100' | |
988 dcfsnz tft_temp2,F | |
989 movlw b'00010000' | |
990 dcfsnz tft_temp2,F | |
991 movlw b'00010100' | |
992 dcfsnz tft_temp2,F | |
993 movlw b'00100000' | |
994 dcfsnz tft_temp2,F | |
995 movlw b'00111111' | |
582 | 996 movwf tft_temp4 |
0 | 997 |
998 rrcf tft_temp4,F | |
999 rrcf tft_temp1,F | |
1000 | |
1001 rrcf tft_temp4,F | |
604 | 1002 rrcf tft_temp1,F |
0 | 1003 |
1004 rrcf tft_temp4,F | |
1005 rrcf tft_temp1,F | |
1006 | |
1007 rrcf tft_temp4,F | |
1008 rrcf tft_temp1,F | |
1009 | |
1010 rrcf tft_temp4,F | |
604 | 1011 rrcf tft_temp1,W ; red done |
1012 movwf win_color1 ; set color registers | |
0 | 1013 return |
1014 | |
1015 ;============================================================================= | |
1016 ; Dump screen contents to the UART | |
1017 | |
604 | 1018 IFDEF _screendump |
1019 | |
1020 global TFT_dump_screen_check | |
582 | 1021 global TFT_dump_screen |
604 | 1022 TFT_dump_screen_check: |
1023 btfss vusb_in ; USB (still) plugged in? | |
1024 bcf enable_screen_dumps ; NO - clear flag | |
1025 call rs232_get_byte ; try to read data from RS232 | |
1026 btfsc rs232_receive_overflow ; anything received? | |
1027 return ; NO - return | |
1028 movlw "l" ; YES - load coding for screendump command | |
1029 cpfseq RCREG1 ; screendump command received? | |
1030 return ; NO - return | |
1031 TFT_dump_screen: ; YES | |
582 | 1032 bsf no_sensor_int |
1033 movlw 'l' | |
604 | 1034 movwf TXREG ; send command echo |
582 | 1035 call rs232_wait_tx ; wait for UART |
604 | 1036 |
582 | 1037 ;---- Send DISPLAY box command for the full screen window ------------------- |
604 | 1038 Index_out 0x50 ; window horizontal start address |
582 | 1039 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 1040 Index_out 0x51 ; window horizontal end address |
582 | 1041 Parameter_out 0x00, 0xEF ; 0-239 |
604 | 1042 Index_out 0x52 ; window vertical start address |
582 | 1043 Parameter_out 0x00, 0x00 ; 0-319 |
604 | 1044 Index_out 0x53 ; window vertical end address |
582 | 1045 Parameter_out 0x01, 0x3F ; 0-319 |
0 | 1046 |
582 | 1047 clrf ds_column |
1048 rcall dump_screen_pixel_reset | |
0 | 1049 dump_screen_1: |
582 | 1050 btg LEDr ; LED activity toggle |
1051 ; Dump even column | |
604 | 1052 movlw .240 ; 240 lines, once |
582 | 1053 movwf ds_line |
0 | 1054 dump_screen_2: |
604 | 1055 Index_out 0x20 ; frame memory horizontal address |
582 | 1056 movff ds_line,WREG ; d'0' ... d'239' |
604 | 1057 mullw .1 ; copy row to PRODH:L |
582 | 1058 rcall TFT_DataWrite_PROD |
0 | 1059 |
604 | 1060 movff ds_column,WREG ; Init X position |
582 | 1061 mullw 2 |
604 | 1062 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
0 | 1063 |
582 | 1064 rcall TFT_DataRead_PROD ; read pixel |
1065 rcall dump_screen_pixel | |
0 | 1066 |
582 | 1067 decfsz ds_line,F |
1068 bra dump_screen_2 | |
1069 rcall dump_screen_pixel_flush | |
0 | 1070 |
582 | 1071 ; Dump odd column |
604 | 1072 movlw .240 ; 240 lines, twice |
582 | 1073 movwf ds_line |
0 | 1074 dump_screen_3: |
604 | 1075 Index_out 0x20 ; frame memory horizontal address |
582 | 1076 movff ds_line,WREG ; d'0' ... d'239' |
604 | 1077 mullw 1 ; copy row to PRODH:L |
582 | 1078 rcall TFT_DataWrite_PROD |
0 | 1079 |
604 | 1080 movff ds_column,WREG ; init X position |
582 | 1081 mullw 2 |
1082 movlw .1 | |
1083 addwf PRODL,F | |
1084 movlw 0 | |
1085 addwfc PRODH,F ; +1 | |
604 | 1086 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
0 | 1087 |
582 | 1088 rcall TFT_DataRead_PROD ; read pixel |
1089 rcall dump_screen_pixel | |
0 | 1090 |
582 | 1091 decfsz ds_line,F |
1092 bra dump_screen_3 | |
1093 rcall dump_screen_pixel_flush | |
0 | 1094 |
582 | 1095 incf ds_column,F |
1096 movlw .160 | |
1097 cpfseq ds_column | |
1098 bra dump_screen_1 | |
0 | 1099 |
582 | 1100 bcf no_sensor_int |
604 | 1101 clrf RCREG1 ; clear receive buffer |
1102 bcf RCSTA1,CREN ; clear receiver status | |
582 | 1103 bsf RCSTA1,CREN |
604 | 1104 bsf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (screen dump) |
582 | 1105 return |
0 | 1106 |
604 | 1107 ENDIF |
1108 | |
0 | 1109 |
1110 ;============================================================================= | |
1111 ; Pixel compression | |
1112 ; | |
604 | 1113 ; Input : PRODH:L = pixel |
0 | 1114 ; Output: Compressed stream on output. |
1115 ; Compressed format: | |
604 | 1116 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128) |
1117 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1.. 64) | |
1118 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1.. 64) | |
1119 | |
1120 IFDEF _screendump | |
582 | 1121 |
0 | 1122 dump_screen_pixel: |
604 | 1123 movf PRODH,W ; compare pixel-high |
582 | 1124 xorwf ds_pixel+1,W |
604 | 1125 bnz dump_screen_pixel_1 ; different -> dump |
0 | 1126 |
604 | 1127 movf PRODL,W ; compare pixel-low |
582 | 1128 xorwf ds_pixel+0,W |
604 | 1129 bnz dump_screen_pixel_1 ; different -> dump |
0 | 1130 |
604 | 1131 incf ds_count,F ; same color: just increment |
582 | 1132 return |
0 | 1133 |
604 | 1134 dump_screen_pixel_1: ; send (pixel,count) tuple |
1135 movf ds_count,W ; is count zero ? | |
1136 bz dump_screen_pixel_2 ; YES - skip sending | |
0 | 1137 |
604 | 1138 movf ds_pixel+1,W ; is this a BLACK pixel ? |
582 | 1139 iorwf ds_pixel+0,W |
604 | 1140 bz dump_screen_pix_black ; YES |
0 | 1141 |
604 | 1142 movf ds_pixel+1,W ; is this a white pixel ? |
582 | 1143 andwf ds_pixel+0,W |
1144 incf WREG | |
604 | 1145 bz dump_screen_pix_white ; YES |
0 | 1146 |
582 | 1147 ; No: write the pixel itself... |
604 | 1148 movlw .64 ; max color pixel on a single byte |
1149 cpfsgt ds_count ; skip if count > 64 | |
582 | 1150 movf ds_count,W ; W <- min(64,count) |
1151 subwf ds_count,F ; ds_count <- ds_count-W | |
604 | 1152 decf WREG ; save as 0..63 |
1153 iorlw b'10000000' ; mark as a color pixel | |
0 | 1154 |
582 | 1155 movwf TXREG |
1156 call rs232_wait_tx ; wait for UART | |
1157 movff ds_pixel+1,TXREG | |
1158 call rs232_wait_tx ; wait for UART | |
1159 movff ds_pixel+0,TXREG | |
1160 call rs232_wait_tx ; wait for UART | |
1161 bra dump_screen_pixel_1 | |
0 | 1162 |
1163 dump_screen_pixel_2: | |
604 | 1164 movff PRODH,ds_pixel+1 ; save new pixel color |
582 | 1165 movff PRODL,ds_pixel+0 |
1166 movlw 1 | |
604 | 1167 movwf ds_count ; and set count=1 |
582 | 1168 return |
0 | 1169 |
1170 dump_screen_pix_black: | |
604 | 1171 movlw .128 ; max black pixel on a single byte |
1172 cpfsgt ds_count ; skip if count > 128 | |
582 | 1173 movf ds_count,W ; W <- min(128,count) |
1174 subwf ds_count,F ; ds_count <- ds_count-W | |
604 | 1175 decf WREG ; save as 0..127 |
0 | 1176 dump_screen_pix_3: |
582 | 1177 movwf TXREG |
1178 call rs232_wait_tx | |
604 | 1179 bra dump_screen_pixel_1 ; more to dump ? |
0 | 1180 |
1181 dump_screen_pix_white: | |
604 | 1182 movlw .64 ; max white pixel on a single byte |
1183 cpfsgt ds_count ; skip if count > 64 | |
582 | 1184 movf ds_count,W ; W <- min(64,count) |
1185 subwf ds_count,F ; ds_count <- ds_count-W | |
1186 decf WREG ; Save as 0..63 | |
604 | 1187 iorlw b'11000000' ; mark as a compressed white |
582 | 1188 bra dump_screen_pix_3 |
0 | 1189 |
1190 dump_screen_pixel_flush: | |
582 | 1191 clrf PRODH |
1192 clrf PRODL | |
604 | 1193 rcall dump_screen_pixel_1 ; send it |
0 | 1194 dump_screen_pixel_reset: |
604 | 1195 clrf ds_count ; clear count |
582 | 1196 return |
0 | 1197 |
604 | 1198 ENDIF |
1199 | |
582 | 1200 END |