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