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