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