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