Mercurial > public > hwos_code
annotate src/tft.asm @ 598:e1f0f5e3d4e4
BUGFIX: Internal deco planner did not display results in imperial units
author | heinrichsweikamp |
---|---|
date | Mon, 30 Jul 2018 19:45:53 +0200 |
parents | b455b31ce022 |
children | ca4556fb60b9 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
582 | 3 ; File tft.asm ## V2.97 |
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 | |
64 movwf PORTA ; Upper | |
65 movlw low_b | |
66 rcall TFT_DataWrite | |
67 endm | |
68 | |
69 | |
582 | 70 basic CODE |
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 |
95 ; movwf SSP2BUF ; Write to buffer to initiate new read | |
96 ; btfss SSP2STAT, BF ; Next byte ready ? | |
97 ; bra $-2 ; NO: wait... | |
98 ; movff SSP2BUF,win_width+1 | |
99 ; movwf SSP2BUF ; Write to buffer to initiate new read | |
100 ; btfss SSP2STAT, BF ; Next byte ready ? | |
101 ; bra $-2 ; NO: wait... | |
102 ; movff SSP2BUF,win_height | |
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. |
112 ; iorwf WREG ; Check height < 256 | |
113 ; bnz TFT_write_flash_image_failed | |
114 ; movf win_width+1,W ; Check width < 512 | |
115 ; andlw 0xFE | |
116 ; bnz TFT_write_flash_image_failed | |
151 | 117 ; |
582 | 118 ; ; Center image on win_top, win_left values |
119 ; bcf STATUS,C ; Clear carry | |
120 ; rrcf win_height,W ; And get height/2 | |
121 ; subwf win_top,F ; top -= height/2 | |
122 ; rrcf win_width+1,W ; Get 9th bit into carry | |
123 ; rrcf win_width+0,W ; Get width/2 (in 0..320 range) | |
124 ; bcf STATUS,C | |
125 ; rrcf WREG,W ; Get width/2 in 0..160 range | |
126 ; subwf win_leftx2,F ; left -= width/2 | |
151 | 127 ; |
582 | 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 | |
133 ; mulwf win_height ; Result in PRODL:H | |
134 ; movf win_width+1,W | |
135 ; bz TFT_write_flash_image_1 ; width > 8bits ? | |
136 ; movf win_height,W ; YES: add extra | |
137 ; addwf PRODH,F | |
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 |
144 ; Index_out 0x22 ; Frame Memory Data Write start | |
145 ; RS_H ; Data | |
151 | 146 ; |
147 ;TFT_write_flash_image_loop: | |
582 | 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 ; |
582 | 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 |
582 | 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 ; | |
582 | 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 | |
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: |
582 | 194 RS_L ; Command |
195 clrf PORTA ; Upper | |
196 bcf INTCON,GIE | |
197 movwf PORTH ; Lower | |
0 | 198 WR_L |
582 | 199 WR_H ; Tick |
200 bsf INTCON,GIE | |
201 return | |
0 | 202 |
582 | 203 global TFT_DataWrite |
0 | 204 TFT_DataWrite: |
582 | 205 RS_H ; Data |
206 bcf INTCON,GIE | |
207 movwf PORTH ; Lower | |
0 | 208 WR_L |
582 | 209 WR_H ; Tick |
210 bsf INTCON,GIE | |
0 | 211 return |
212 | |
213 ;============================================================================= | |
582 | 214 |
215 global TFT_ClearScreen | |
0 | 216 TFT_ClearScreen: |
582 | 217 Index_out 0x50 ; Window Horizontal Start Address |
218 Parameter_out 0x00, 0x00 ; 0-239 | |
219 Index_out 0x51 ; Window Horizontal End Address | |
220 Parameter_out 0x00, 0xEF ; 0-239 | |
221 Index_out 0x52 ; Window Vertical Start Address | |
222 Parameter_out 0x00, 0x00 ; 0-319 | |
223 Index_out 0x53 ; Window Vertical End Address | |
224 Parameter_out 0x01, 0x3F ; 0-319 | |
225 Index_out 0x20 ; Frame Memory Horizontal Address | |
226 Parameter_out 0x00, 0x00 ; 0-239 | |
227 Index_out 0x21 ; Frame Memory Vertical Address | |
228 Parameter_out 0x01, 0x3F ; 0-319 | |
0 | 229 |
582 | 230 Index_out 0x22 ; Frame Memory Data Write start |
0 | 231 |
582 | 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: | |
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 | |
247 WR_H ; Tick | |
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 | |
257 bra TFT_CmdWrite ; And return | |
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' |
582 | 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 | |
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 |
582 | 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 ? | |
353 bra TFT_boot2 ; Yes | |
360 | 354 |
582 | 355 btfss screen_type ; display1? |
356 bra TFT_boot1a ; no | |
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? |
364 bra TFT_boot2a ; no | |
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 | |
399 bra display0_config_write ; Write Config pair to Display | |
400 ; Delay ms or quit (return) | |
401 TBLRD*+ | |
402 tstfsz TABLAT ; End of config? | |
403 bra $+4 ; No | |
404 return ; Done. | |
405 movf TABLAT,W | |
406 call WAITMSX ; Wait WREG milliseconds | |
407 TBLRD*+ ; Dummy read (Third byte of delay command) | |
408 bra display0_init_loop ; Loop | |
0 | 409 |
582 | 410 display0_config_write: ; With command in WREG |
411 movf TABLAT,W | |
412 rcall TFT_CmdWrite ; Write command | |
413 TBLRD*+ ; Get config0 | |
414 movff TABLAT,PORTA | |
415 TBLRD*+ ; Get config1 | |
416 movf TABLAT,W | |
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: | |
582 | 426 ; clrf CCPR1L ; Backlight off |
427 ; [draw splash screen] | |
428 ; call TFT_DisplayFadeIn | |
429 | |
430 global TFT_Display_FadeIn | |
0 | 431 TFT_Display_FadeIn: |
582 | 432 movlw CCP1CON_VALUE ; See hwos.inc |
433 movwf CCP1CON | |
434 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor! | |
435 clrf CCPR1L ; Backlight off - to be sure | |
436 movff max_CCPR1L,PRODL | |
0 | 437 TFT_Display_FadeIn_0: |
582 | 438 incf CCPR1L,F ; Duty cycle |
439 WAITMS d'2' | |
440 decfsz PRODL,F | |
441 bra TFT_Display_FadeIn_0 | |
442 bcf tft_is_dimming ; dimming done. | |
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 |
452 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor! | |
0 | 453 TFT_Display_FadeOut_0: |
582 | 454 movff PRODL,CCPR1L ; Duty cycle |
455 WAITMS d'1' | |
456 decfsz PRODL,F | |
457 bra TFT_Display_FadeOut_0 | |
458 clrf CCPR1L | |
459 return | |
0 | 460 |
461 ;============================================================================= | |
462 | |
582 | 463 global box_std_block, box_black_block, box_color_block |
0 | 464 |
582 | 465 box_std_block: ; Use white color |
466 setf WREG | |
467 bra box_common | |
468 box_black_block: ; Use black color | |
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 | |
512 ; rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) | |
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 | |
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 | |
528 mullw 2 | |
529 infsnz PRODL ; +1 | |
530 incf PRODH | |
531 rcall pixel_write_col320 | |
532 bra half_pixel_write ; Note: Cmd 0x20 is mandatory, because | |
533 ; of the auto-increment going vertical | |
0 | 534 |
535 global pixel_write_col320 | |
536 pixel_write_col320: | |
582 | 537 btfsc screen_type ; display1? |
538 bra pixel_write_col320_d1 ; Yes | |
539 ; Display0 | |
540 btfss flip_screen ; 180° rotation? | |
541 bra pixel_write_noflip_H ; No | |
542 bra pixel_write_flip_H ; Yes | |
543 pixel_write_col320_d1: ; Display1 | |
544 btfsc flip_screen ; 180° rotation? | |
545 bra pixel_write_noflip_H ; Yes for d1 | |
546 pixel_write_flip_H: ; Flip d0 | |
547 movf PRODL,W ; 16bits 319 - PROD --> PROD | |
548 sublw LOW(.319) ; 319-W --> W | |
549 movwf PRODL | |
550 movf PRODH,W | |
551 btfss STATUS,C ; Borrow = /CARRY | |
552 incf WREG | |
553 sublw HIGH(.319) | |
554 movwf PRODH | |
151 | 555 |
556 pixel_write_noflip_H: | |
582 | 557 Index_out 0x21 ; Frame Memory Vertical Address |
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 | |
572 mullw .1 ; Copy row to PRODL (PRODH=0) | |
573 Index_out 0x20 ; Frame Memory Horizontal Address | |
574 rcall TFT_DataWrite_PROD | |
0 | 575 |
582 | 576 Index_out 0x22 ; Frame Memory Data Write start |
577 RS_H ; Data | |
578 bcf INTCON,GIE | |
579 movff win_color1,PORTA ; Upper | |
580 movff win_color2,PORTH ; Lower | |
581 WR_L | |
582 WR_H ; Tick | |
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: | |
582 | 593 clrf TABLAT ; Loop index. |
0 | 594 |
595 half_vertical_line_loop: | |
582 | 596 movf win_leftx2,W ; Init X position. |
597 mullw .2 | |
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 |
582 | 603 movf win_height,W ; Index reached height (Bank0 read) ? |
604 xorwf TABLAT,W | |
605 btfsc STATUS,Z ; Equals ? | |
606 return ; Yes: done. | |
607 movf win_top,W ; Y = top + index (Bank0 read) | |
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: | |
582 | 620 clrf TABLAT ; Loop index. |
0 | 621 |
622 half_horizontal_line_loop: | |
582 | 623 movf win_leftx2,W ; Init X position. |
624 mullw .2 | |
625 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) | |
626 movf win_width,W ; Index reached height (Bank0 read) ? | |
627 xorwf TABLAT,W | |
628 btfsc STATUS,Z ; Equals ? | |
629 return ; Yes: done. | |
630 movf win_top,W ; Y = top + index (Bank0 read) | |
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: |
582 | 642 ; RD_H ; Keep high |
643 RS_H ; Data | |
644 bcf INTCON,GIE | |
645 movff PRODH,PORTA ; Move high byte to PORTA | |
646 movff PRODL,PORTH ; Move low byte to PORTH | |
0 | 647 WR_L |
582 | 648 WR_H ; Tick |
649 bsf INTCON,GIE | |
0 | 650 return |
651 | |
652 TFT_DataRead_PROD: | |
582 | 653 Index_out 0x22 ; Frame Memory Data Read start |
360 | 654 TFT_CmdRead_PROD: |
582 | 655 setf TRISA ; PortA as input. |
656 setf TRISH ; PortH as input. | |
657 RS_H ; Data | |
658 WR_H ; Not write | |
659 RD_L ; Read! | |
660 nop | |
661 nop | |
662 nop | |
663 RD_H ; Tick | |
664 nop | |
665 nop | |
666 nop | |
667 RD_L ; Read! | |
668 nop | |
669 ;nop | |
670 ;nop | |
671 movff PORTA,PRODH | |
672 movff PORTH,PRODL | |
673 RD_H ; Tick | |
674 nop | |
675 clrf TRISA ; PortA as output | |
676 clrf TRISH ; PortH as output | |
0 | 677 return |
678 | |
679 ;============================================================================= | |
680 ; Output TFT Window Address commands. | |
681 ; Inputs : win_top, win_leftx2, win_height, win_width. | |
682 ; Output : PortA/PortH commands. | |
683 ; Trashed: PROD | |
582 | 684 |
685 global TFT_box_write | |
0 | 686 TFT_box_write: |
582 | 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 |
691 TFT_box_write_16bit_win_left: ; With column in PRODL:PRODH | |
692 btfsc screen_type ; display1? | |
693 bra TFT_box_write_16bit_win_left_d1 ; Yes | |
694 ; Display0 | |
695 btfsc flip_screen ; 180° rotation? | |
696 bra DISP_box_flip_H ; Yes | |
697 bra TFT_box_write_16bit_win_left_com ; No | |
698 TFT_box_write_16bit_win_left_d1: ; Display1 | |
699 btfss flip_screen ; 180° rotation? | |
700 bra DISP_box_flip_H ; No for d1 | |
701 ; Yes for d1 | |
361 | 702 TFT_box_write_16bit_win_left_com: |
582 | 703 ;---- Normal horizontal window --------------------------------------- |
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 |
582 | 717 Index_out 0x53 ; Window Vertical End Address |
718 rcall TFT_DataWrite_PROD | |
719 bra DISP_box_noflip_H | |
0 | 720 |
582 | 721 ;---- Flipped horizontal window -------------------------------------- |
151 | 722 DISP_box_flip_H: |
582 | 723 movf PRODL,W ; 16bits 319 - PROD --> PROD |
724 sublw LOW(.319) ; 319-W --> W | |
725 movwf PRODL | |
726 movf PRODH,W | |
727 btfss STATUS,C ; Borrow = /CARRY | |
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 |
582 | 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 |
582 | 737 movf win_width+0,W ; 16bits PROD - width --> PROD |
738 subwf PRODL,F ; PRODL - WREG --> PRODL | |
739 movf win_width+1,W | |
740 subwfb PRODH,F | |
741 infsnz PRODL ; PROD+1 --> PROD | |
742 incf PRODH | |
151 | 743 |
582 | 744 Index_out 0x52 ; Window Vertical End Address |
745 rcall TFT_DataWrite_PROD | |
151 | 746 |
747 DISP_box_noflip_H: | |
582 | 748 btfss flip_screen ; 180° rotation ? |
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 |
582 | 756 movwf PRODL ; top+height-1 --> PRODL (second byte) |
151 | 757 |
582 | 758 Index_out 0x50 ; Window Horizontal Start Address |
432 | 759 movf PRODH,W |
582 | 760 rcall TFT_DataWrite ; Lower (and tick) |
151 | 761 |
582 | 762 Index_out 0x51 ; Window Horizontal End Address |
763 movf PRODL,W | |
764 rcall TFT_DataWrite ; Lower (and tick) | |
765 | |
766 Index_out 0x20 ; Frame Memory Horizontal Address | |
432 | 767 movf PRODH,W |
582 | 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 | |
776 movwf PRODH ; First byte | |
0 | 777 |
432 | 778 movf PRODL,W |
582 | 779 sublw .239 ; 239-top |
780 movwf PRODL ; --> second byte. | |
0 | 781 |
582 | 782 Index_out 0x50 ; Window Horizontal Start Address |
432 | 783 movf PRODH,W |
582 | 784 rcall TFT_DataWrite ; Lower (and tick) |
0 | 785 |
582 | 786 Index_out 0x51 ; Window Horizontal End Address |
432 | 787 movf PRODL,W |
582 | 788 rcall TFT_DataWrite ; Lower (and tick) |
0 | 789 |
582 | 790 Index_out 0x20 ; Frame Memory Horizontal Address |
432 | 791 movf PRODL,W |
582 | 792 bra TFT_DataWrite ; Lower (and tick) and return |
793 | |
0 | 794 |
795 ;============================================================================= | |
796 ; TFT_frame : draw a frame around current box with current color. | |
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: | |
803 movff win_top,save_top ; Backup everything. | |
804 movff win_height,save_height | |
805 movff win_leftx2,save_left | |
806 movff win_width,save_width | |
0 | 807 |
582 | 808 ;---- TOP line ----------------------------------------------------------- |
809 movlw .1 ; row ~ height=1 | |
810 movwf win_height | |
811 rcall TFT_box | |
0 | 812 |
582 | 813 ;---- BOTTOM line -------------------------------------------------------- |
814 movff save_top,PRODL ; Get back top, | |
815 movff save_height,WREG ; and height | |
816 addwf PRODL,W ; top+height | |
817 decf WREG ; top+height-1 | |
818 movwf win_top ; top+height-1 --> top | |
819 rcall TFT_box | |
0 | 820 |
582 | 821 ;---- LEFT column -------------------------------------------------------- |
822 movff save_top,win_top ; Restore top/height. | |
823 movff save_height,win_height | |
824 movlw .1 ; column ~ width=1 | |
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 ;============================================================================= | |
842 ; TFT_box : fills current box with current color. | |
843 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 | |
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 | |
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 -------------------------------------------------------- |
862 Index_out 0x22 ; Frame Memory Data Write start | |
0 | 863 |
582 | 864 clrf PRODH ; Column counter. |
865 RS_H ; Data | |
0 | 866 |
582 | 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 |
582 | 872 movff win_color1,PORTA ; Upper |
873 movff win_color2,PORTH ; Lower | |
0 | 874 WR_L |
582 | 875 WR_H ; Tick |
876 | |
877 ; movff win_color1,PORTA ; Upper | |
878 ; movff win_color2,PORTH ; Lower | |
0 | 879 WR_L |
582 | 880 WR_H ; Tick |
881 bsf INTCON,GIE | |
882 decfsz PRODL,F ; row loop finished ? | |
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 | |
889 bra TFT_box4 ; No: just loop. | |
890 ; Yes: switch to black | |
891 clrf win_color1 | |
892 clrf win_color2 | |
0 | 893 TFT_box4: |
582 | 894 movf win_width+0,W ; compare ? |
895 xorwf PRODH,W | |
896 bnz TFT_box2 ; Loop not finished. | |
0 | 897 |
582 | 898 movlw 0x00 ; NOP, to stop window mode |
899 rcall TFT_CmdWrite | |
0 | 900 |
582 | 901 ; Reset bargraph mode... |
902 setf win_bargraph | |
903 return | |
0 | 904 |
905 ;============================================================================= | |
906 ;Converts 8Bit RGB b'RRRGGGBB' into 16Bit RGB b'RRRRRGGGGGGBBBBB' | |
907 | |
582 | 908 global TFT_set_color |
0 | 909 TFT_set_color: |
910 movwf tft_temp1 ; Get 8Bit RGB b'RRRGGGBB' | |
582 | 911 movwf tft_temp2 ; Copy |
0 | 912 |
913 ; Mask Bit 7,6,5,4,3,2 | |
914 movlw b'00000011' | |
915 andwf tft_temp2,F | |
916 | |
917 movlw b'00000000' | |
918 dcfsnz tft_temp2,F | |
919 movlw b'01010000' | |
920 dcfsnz tft_temp2,F | |
921 movlw b'10100000' | |
922 dcfsnz tft_temp2,F | |
923 movlw b'11111000' | |
924 movwf tft_temp3 ; Blue done. | |
925 | |
582 | 926 movff tft_temp1,tft_temp2 ; Copy |
0 | 927 ; Mask Bit 7,6,5,1,0 |
928 movlw b'00011100' | |
929 andwf tft_temp2,F | |
930 rrncf tft_temp2,F | |
931 rrncf tft_temp2,F | |
932 | |
933 movlw b'00000000' | |
934 dcfsnz tft_temp2,F | |
935 movlw b'00000100' | |
936 dcfsnz tft_temp2,F | |
937 movlw b'00001000' | |
938 dcfsnz tft_temp2,F | |
939 movlw b'00001100' | |
940 dcfsnz tft_temp2,F | |
941 movlw b'00010000' | |
942 dcfsnz tft_temp2,F | |
943 movlw b'00010100' | |
944 dcfsnz tft_temp2,F | |
945 movlw b'00100000' | |
946 dcfsnz tft_temp2,F | |
947 movlw b'00111111' | |
582 | 948 movwf tft_temp4 |
0 | 949 |
950 rrcf tft_temp4,F | |
951 rrcf tft_temp3,F | |
952 | |
953 rrcf tft_temp4,F | |
954 rrcf tft_temp3,F | |
955 | |
956 rrcf tft_temp4,F | |
582 | 957 rrcf tft_temp3,W ; tft_temp3 (b'GGGBBBBB') done. |
958 movwf win_color2 ; Set Color registers... | |
0 | 959 |
582 | 960 movff tft_temp1,tft_temp2 ; Copy |
0 | 961 clrf tft_temp1 |
962 | |
963 rrcf tft_temp4,F | |
964 rrcf tft_temp1,F | |
965 | |
966 rrcf tft_temp4,F | |
967 rrcf tft_temp1,F | |
968 | |
969 rrcf tft_temp4,F | |
582 | 970 rrcf tft_temp1,F ; Green done. |
0 | 971 |
972 ; Mask Bit 4,3,2,1,0 | |
973 movlw b'11100000' | |
974 andwf tft_temp2,F | |
975 | |
976 rrncf tft_temp2,F | |
977 rrncf tft_temp2,F | |
978 rrncf tft_temp2,F | |
979 rrncf tft_temp2,F | |
980 rrncf tft_temp2,F | |
981 | |
982 movlw b'00000000' | |
983 dcfsnz tft_temp2,F | |
984 movlw b'00000100' | |
985 dcfsnz tft_temp2,F | |
986 movlw b'00001000' | |
987 dcfsnz tft_temp2,F | |
988 movlw b'00001100' | |
989 dcfsnz tft_temp2,F | |
990 movlw b'00010000' | |
991 dcfsnz tft_temp2,F | |
992 movlw b'00010100' | |
993 dcfsnz tft_temp2,F | |
994 movlw b'00100000' | |
995 dcfsnz tft_temp2,F | |
996 movlw b'00111111' | |
582 | 997 movwf tft_temp4 |
0 | 998 |
999 rrcf tft_temp4,F | |
1000 rrcf tft_temp1,F | |
1001 | |
1002 rrcf tft_temp4,F | |
1003 rrcf tft_temp1,F | |
1004 | |
1005 rrcf tft_temp4,F | |
1006 rrcf tft_temp1,F | |
1007 | |
1008 rrcf tft_temp4,F | |
1009 rrcf tft_temp1,F | |
1010 | |
1011 rrcf tft_temp4,F | |
582 | 1012 rrcf tft_temp1,W ; Red done. |
1013 movwf win_color1 ; Set Color registers... | |
0 | 1014 return |
1015 | |
1016 ;============================================================================= | |
1017 ; Dump screen contents to the UART | |
1018 | |
582 | 1019 global TFT_dump_screen |
0 | 1020 TFT_dump_screen: |
582 | 1021 bsf no_sensor_int |
1022 movlw 'l' | |
1023 movwf TXREG ; Send command echo. | |
1024 call rs232_wait_tx ; wait for UART | |
1025 ;---- Send DISPLAY box command for the full screen window ------------------- | |
1026 Index_out 0x50 ; Window Horizontal Start Address | |
1027 Parameter_out 0x00, 0x00 ; 0-239 | |
1028 Index_out 0x51 ; Window Horizontal End Address | |
1029 Parameter_out 0x00, 0xEF ; 0-239 | |
1030 Index_out 0x52 ; Window Vertical Start Address | |
1031 Parameter_out 0x00, 0x00 ; 0-319 | |
1032 Index_out 0x53 ; Window Vertical End Address | |
1033 Parameter_out 0x01, 0x3F ; 0-319 | |
0 | 1034 |
582 | 1035 clrf ds_column |
1036 rcall dump_screen_pixel_reset | |
0 | 1037 dump_screen_1: |
582 | 1038 btg LEDr ; LED activity toggle |
1039 ; Dump even column | |
1040 movlw .240 ; 240 lines, once. | |
1041 movwf ds_line | |
0 | 1042 dump_screen_2: |
582 | 1043 Index_out 0x20 ; Frame Memory Horizontal Address |
1044 movff ds_line,WREG ; d'0' ... d'239' | |
1045 mullw .1 ; Copy row to PRODH:L | |
1046 rcall TFT_DataWrite_PROD | |
0 | 1047 |
582 | 1048 movff ds_column,WREG ; Init X position. |
1049 mullw 2 | |
1050 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) | |
0 | 1051 |
582 | 1052 rcall TFT_DataRead_PROD ; read pixel |
1053 rcall dump_screen_pixel | |
0 | 1054 |
582 | 1055 decfsz ds_line,F |
1056 bra dump_screen_2 | |
1057 rcall dump_screen_pixel_flush | |
0 | 1058 |
582 | 1059 ; Dump odd column |
1060 movlw .240 ; 240 lines, twice. | |
1061 movwf ds_line | |
0 | 1062 dump_screen_3: |
582 | 1063 Index_out 0x20 ; Frame Memory Horizontal Address |
1064 movff ds_line,WREG ; d'0' ... d'239' | |
1065 mullw 1 ; Copy row to PRODH:L | |
1066 rcall TFT_DataWrite_PROD | |
0 | 1067 |
582 | 1068 movff ds_column,WREG ; Init X position. |
1069 mullw 2 | |
1070 movlw .1 | |
1071 addwf PRODL,F | |
1072 movlw 0 | |
1073 addwfc PRODH,F ; +1 | |
1074 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) | |
0 | 1075 |
582 | 1076 rcall TFT_DataRead_PROD ; read pixel |
1077 rcall dump_screen_pixel | |
0 | 1078 |
582 | 1079 decfsz ds_line,F |
1080 bra dump_screen_3 | |
1081 rcall dump_screen_pixel_flush | |
0 | 1082 |
582 | 1083 incf ds_column,F |
1084 movlw .160 | |
1085 cpfseq ds_column | |
1086 bra dump_screen_1 | |
0 | 1087 |
582 | 1088 bcf no_sensor_int |
1089 clrf RCREG1 ; Clear receive buffer | |
1090 bcf RCSTA1,CREN ; Clear receiver status | |
1091 bsf RCSTA1,CREN | |
1092 bsf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
1093 return | |
0 | 1094 |
1095 | |
1096 ;============================================================================= | |
1097 ; Pixel compression | |
1098 ; | |
1099 ; Input: PRODH:L = pixel. | |
1100 ; Output: Compressed stream on output. | |
1101 ; Compressed format: | |
1102 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128). | |
1103 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1..64). | |
1104 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1..64). | |
582 | 1105 |
0 | 1106 dump_screen_pixel: |
582 | 1107 movf PRODH,W ; Compare pixel-high |
1108 xorwf ds_pixel+1,W | |
1109 bnz dump_screen_pixel_1 ; Different -> dump. | |
0 | 1110 |
582 | 1111 movf PRODL,W ; Compare pixel-low |
1112 xorwf ds_pixel+0,W | |
1113 bnz dump_screen_pixel_1 ; Different -> dump. | |
0 | 1114 |
582 | 1115 incf ds_count,F ; Same color: just increment. |
1116 return | |
0 | 1117 |
582 | 1118 dump_screen_pixel_1: ; Send (pixel,count) tuple |
1119 movf ds_count,W ; Is count zero ? | |
1120 bz dump_screen_pixel_2 ; Yes: skip sending. | |
0 | 1121 |
582 | 1122 movf ds_pixel+1,W ; This is a BLACK pixel ? |
1123 iorwf ds_pixel+0,W | |
1124 bz dump_screen_pix_black ; YES. | |
0 | 1125 |
582 | 1126 movf ds_pixel+1,W ; This is a white pixel ? |
1127 andwf ds_pixel+0,W | |
1128 incf WREG | |
1129 bz dump_screen_pix_white ; YES. | |
0 | 1130 |
582 | 1131 ; No: write the pixel itself... |
1132 movlw .64 ; Max color pixel on a single byte. | |
1133 cpfsgt ds_count ; Skip if count > 64 | |
1134 movf ds_count,W ; W <- min(64,count) | |
1135 subwf ds_count,F ; ds_count <- ds_count-W | |
1136 decf WREG ; Save as 0..63 | |
1137 iorlw b'10000000' ; MARK as a color pixel. | |
0 | 1138 |
582 | 1139 movwf TXREG |
1140 call rs232_wait_tx ; wait for UART | |
1141 movff ds_pixel+1,TXREG | |
1142 call rs232_wait_tx ; wait for UART | |
1143 movff ds_pixel+0,TXREG | |
1144 call rs232_wait_tx ; wait for UART | |
1145 bra dump_screen_pixel_1 | |
0 | 1146 |
1147 dump_screen_pixel_2: | |
582 | 1148 movff PRODH,ds_pixel+1 ; Save new pixel color |
1149 movff PRODL,ds_pixel+0 | |
1150 movlw 1 | |
1151 movwf ds_count ; And set count=1. | |
1152 return | |
0 | 1153 |
1154 dump_screen_pix_black: | |
582 | 1155 movlw .128 ; Max black pixel on a single byte. |
1156 cpfsgt ds_count ; Skip if count > 128 | |
1157 movf ds_count,W ; W <- min(128,count) | |
1158 subwf ds_count,F ; ds_count <- ds_count-W | |
1159 decf WREG ; Save as 0..127 | |
0 | 1160 dump_screen_pix_3: |
582 | 1161 movwf TXREG |
1162 call rs232_wait_tx | |
1163 bra dump_screen_pixel_1 ; More to dump ? | |
0 | 1164 |
1165 dump_screen_pix_white: | |
582 | 1166 movlw .64 ; Max white pixel on a single byte. |
1167 cpfsgt ds_count ; Skip if count > 64 | |
1168 movf ds_count,W ; W <- min(64,count) | |
1169 subwf ds_count,F ; ds_count <- ds_count-W | |
1170 decf WREG ; Save as 0..63 | |
1171 iorlw b'11000000' ; MARK as a compressed white. | |
1172 bra dump_screen_pix_3 | |
0 | 1173 |
1174 dump_screen_pixel_flush: | |
582 | 1175 clrf PRODH |
1176 clrf PRODL | |
1177 rcall dump_screen_pixel_1 ; Send it | |
0 | 1178 dump_screen_pixel_reset: |
582 | 1179 clrf ds_count ; But clear count. |
1180 return | |
0 | 1181 |
582 | 1182 END |