comparison src/tft.asm @ 623:c40025d8e750

3.03 beta released
author heinrichsweikamp
date Mon, 03 Jun 2019 14:01:48 +0200
parents d866684249bd
children cd58f7fc86db
comparison
equal deleted inserted replaced
622:02d1386429a6 623:c40025d8e750
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File tft.asm ## V2.99c 3 ; File tft.asm combined next generation V3.03.2
4 ; 4 ;
5 ; Managing the TFT screen 5 ; low-level Display Outputs
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
9 ; HISTORY 9 ; HISTORY
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code. 10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code.
68 68
69 69
70 tft CODE 70 tft CODE
71 71
72 ;;============================================================================= 72 ;;=============================================================================
73 ;; TFT_write_flash_image
74 ;;
75 ;; Inputs: FSR2 = EEPROM address / 256
76 ;; win_left, win_top : image CENTER position
77 ;; Outputs: win_height, win_width.
78 ;; image copied on screen.
79 ;; Trashed: PROD, hi, lo
80 ;;
81 ; global TFT_write_flash_image
82 ;TFT_write_flash_image:
83 ; ; Get back the full 24bit EEPROM address
84 ; clrf ext_flash_address+0
85 ; movff FSR2L,ext_flash_address+1
86 ; movf FSR2H,W
87 ; iorlw 0x30
88 ; movwf ext_flash_address+2
89 ;
90 ; ; Read header: width and height
91 ; global TFT_write_flash_image_addr
92 ;TFT_write_flash_image_addr:
93 ; call ext_flash_read_block_start
94 ; movff SSP2BUF,win_width+0
95 ; movwf SSP2BUF ; write to buffer to initiate new read
96 ; btfss SSP2STAT, BF ; next byte ready ?
97 ; bra $-2 ; NO - wait...
98 ; movff SSP2BUF,win_width+1
99 ; movwf SSP2BUF ; write to buffer to initiate new read
100 ; btfss SSP2STAT, BF ; next byte ready ?
101 ; bra $-2 ; NO - wait...
102 ; movff SSP2BUF,win_height
103 ; movwf SSP2BUF ; write to buffer to initiate new read
104 ; btfss SSP2STAT, BF ; next byte ready ?
105 ; bra $-2 ; NO - wait...
106 ; movff SSP2BUF,WREG ; drop 4th byte
107 ; movwf SSP2BUF ; write to buffer to initiate new read
108 ; btfss SSP2STAT, BF ; next byte ready ?
109 ; bra $-2 ; NO - wait...
110 ;
111 ; ; Sanity check on header to avoid badly uploaded images.
112 ; iorwf WREG ; check height < 256
113 ; bnz TFT_write_flash_image_failed
114 ; movf win_width+1,W ; check width < 512
115 ; andlw 0xFE
116 ; bnz TFT_write_flash_image_failed
117 ;
118 ; ; Center image on win_top, win_left values
119 ; bcf STATUS,C ; clear carry
120 ; rrcf win_height,W ; and get height/2
121 ; subwf win_top,F ; top -= height/2
122 ; rrcf win_width+1,W ; get 9th bit into carry
123 ; rrcf win_width+0,W ; get width/2 (in 0..320 range)
124 ; bcf STATUS,C
125 ; rrcf WREG,W ; get width/2 in 0..160 range
126 ; subwf win_leftx2,F ; left -= width/2
127 ;
128 ; rcall TFT_box_write ; inputs : win_top, win_leftx2, win_height, win_width (in 1..320 range)
129 ;
130 ; ; Compute number of pixels to move (result on 17 bits !)
131 ; clrf TBLPTRU
132 ; movf win_width+0,W
133 ; mulwf win_height ; result in PRODL:H
134 ; movf win_width+1,W
135 ; bz TFT_write_flash_image_1 ; width > 8bits ?
136 ; movf win_height,W ; YES - add extra
137 ; addwf PRODH,F
138 ; rlcf TBLPTRU ; and carry into upper register
139 ;TFT_write_flash_image_1:
140 ; incf PRODH,F ; pre-condition nested loops
141 ; incf TBLPTRU,F
142 ;
143 ; ; Write pixels
144 ; Index_out 0x22 ; frame memory data write start
145 ; RS_H ; data
146 ;
147 ;TFT_write_flash_image_loop:
148 ; btfss SSP2STAT, BF ; buffer full?
149 ; bra $-2 ; NO - wait...
150 ; movff SSP2BUF,PORTH ; read lo
151 ; movwf SSP2BUF ; write to buffer to initiate new read
152 ;
153 ; btfss SSP2STAT, BF ; buffer full?
154 ; bra $-2 ; NO - wait...
155 ; movff SSP2BUF,PORTA ; and read hi
156 ; movwf SSP2BUF ; write to buffer to initiate new read
157 ; WR_L
158 ; WR_H ; write 1 pixel
159 ;
160 ; decfsz PRODL,F
161 ; bra TFT_write_flash_image_loop
162 ; decfsz PRODH,F
163 ; bra TFT_write_flash_image_loop
164 ; decfsz TBLPTRU,F
165 ; bra TFT_write_flash_image_loop
166 ;
167 ; btfss SSP2STAT, BF ; buffer full?
168 ; bra $-2 ; NO - wait
169 ; movf SSP2BUF,W ; read dummy byte
170 ;
171 ; bsf flash_ncs ; CS=1
172 ; movlw 0x00 ; NOP, to stop window mode
173 ; bra TFT_CmdWrite ; this routine "returns"
174 ;
175 ; ;---- Draw a 4x4 red square in place of missing images...
176 ;TFT_write_flash_image_failed:
177 ; movlw -1
178 ; addwf win_leftx2,F
179 ; movlw -2
180 ; addwf win_top,F
181 ; movlw 2
182 ; movwf win_width+0
183 ; clrf win_width+1
184 ; movlw 4
185 ; movwf win_height
186 ; movlw color_red
187 ; rcall TFT_set_color
188 ; goto TFT_box
189 ;
190 ;;=============================================================================
191
192 73
193 global TFT_ClearScreen 74 global TFT_ClearScreen
194 TFT_ClearScreen: 75 TFT_ClearScreen:
195 btfsc screen_type2 76 btfsc screen_type2 ; screen type ?
196 bra TFT_ClearScreen_display2 77 bra TFT_ClearScreen_display2; YES
78
197 Index_out 0x50 ; window horizontal start address 79 Index_out 0x50 ; window horizontal start address
198 Parameter_out 0x00, 0x00 ; 0-239 80 Parameter_out 0x00, 0x00 ; 0-239
199 Index_out 0x51 ; window horizontal end address 81 Index_out 0x51 ; window horizontal end address
200 Parameter_out 0x00, 0xEF ; 0-239 82 Parameter_out 0x00, 0xEF ; 0-239
201 Index_out 0x52 ; window vertical start address 83 Index_out 0x52 ; window vertical start address
234 bra TFT_ClearScreen2 116 bra TFT_ClearScreen2
235 117
236 movlw 0x00 ; NOP, to stop window mode 118 movlw 0x00 ; NOP, to stop window mode
237 bra TFT_CmdWrite ; and return 119 bra TFT_CmdWrite ; and return
238 120
239 TFT_ClearScreen_display2: 121 TFT_ClearScreen_display2:
240 ; Column Address start 122 movlw 0x02 ; column address start
241 movlw 0x02
242 rcall TFT_CmdWrite 123 rcall TFT_CmdWrite
243 movlw 0x00 124 movlw 0x00
244 rcall TFT_DataWrite 125 rcall TFT_DataWrite
245 movlw 0x03 126 movlw 0x03
246 rcall TFT_CmdWrite 127 rcall TFT_CmdWrite
247 movlw 0x00 128 movlw 0x00
248 rcall TFT_DataWrite 129 rcall TFT_DataWrite
249 130
250 ; Column Address end 131 movlw 0x04 ; column address end
251 movlw 0x04
252 rcall TFT_CmdWrite 132 rcall TFT_CmdWrite
253 movlw 0x00 133 movlw 0x00
254 rcall TFT_DataWrite 134 rcall TFT_DataWrite
255 movlw 0x05 135 movlw 0x05
256 rcall TFT_CmdWrite 136 rcall TFT_CmdWrite
257 movlw 0xEF 137 movlw 0xEF
258 rcall TFT_DataWrite 138 rcall TFT_DataWrite
259 139
260 ; Row address start 140 movlw 0x06 ; row address start
261 movlw 0x06
262 rcall TFT_CmdWrite 141 rcall TFT_CmdWrite
263 movlw 0x00 142 movlw 0x00
264 rcall TFT_DataWrite 143 rcall TFT_DataWrite
265 movlw 0x07 144 movlw 0x07
266 rcall TFT_CmdWrite 145 rcall TFT_CmdWrite
267 movlw 0x00 146 movlw 0x00
268 rcall TFT_DataWrite 147 rcall TFT_DataWrite
269 148
270 ; Row address end 149 movlw 0x08 ; row address end
271 movlw 0x08
272 rcall TFT_CmdWrite 150 rcall TFT_CmdWrite
273 movlw 0x01 151 movlw 0x01
274 rcall TFT_DataWrite 152 rcall TFT_DataWrite
275 movlw 0x09 153 movlw 0x09
276 rcall TFT_CmdWrite 154 rcall TFT_CmdWrite
277 movlw 0x3F 155 movlw 0x3F
278 rcall TFT_DataWrite 156 rcall TFT_DataWrite
279 157
280 movlw 0x22 ; Start Writing Data to GRAM 158 movlw 0x22 ; start writing data to GRAM
281 rcall TFT_CmdWrite 159 rcall TFT_CmdWrite
282 160
283 bsf tft_rs ; Data! 161 bsf tft_rs ; data!
284 162
285 movlw .160 163 movlw .160
286 movwf PRODH 164 movwf PRODH
287 clrf PORTH 165 clrf PORTH
288 TFT_ClearScreen2_display2: 166 TFT_ClearScreen_display2_loop1:
289 movlw .240 167 movlw .240
290 movwf PRODL 168 movwf PRODL
291 TFT_ClearScreen3_display2: 169 TFT_ClearScreen_display2_loop2:
292 bcf tft_nwr 170 bcf tft_nwr
293 bsf tft_nwr ; Upper 171 bsf tft_nwr ; upper
294 bcf tft_nwr 172 bcf tft_nwr
295 bsf tft_nwr ; High 173 bsf tft_nwr ; high
296 bcf tft_nwr 174 bcf tft_nwr
297 bsf tft_nwr ; Lower 175 bsf tft_nwr ; lower
298 bcf tft_nwr 176 bcf tft_nwr
299 bsf tft_nwr ; Upper 177 bsf tft_nwr ; upper
300 bcf tft_nwr 178 bcf tft_nwr
301 bsf tft_nwr ; High 179 bsf tft_nwr ; high
302 bcf tft_nwr 180 bcf tft_nwr
303 bsf tft_nwr ; Lower 181 bsf tft_nwr ; lower
304 decfsz PRODL,F 182 decfsz PRODL,F
305 bra TFT_ClearScreen3_display2 183 bra TFT_ClearScreen_display2_loop2
306 decfsz PRODH,F 184 decfsz PRODH,F
307 bra TFT_ClearScreen2_display2 185 bra TFT_ClearScreen_display2_loop1
308 return 186 return
309 187
310 ;============================================================================= 188 ;=============================================================================
311 189
312 global TFT_DisplayOff 190 global TFT_DisplayOff
313 TFT_DisplayOff: 191 TFT_DisplayOff:
314 clrf CCP1CON ; stop PWM 192 clrf CCP1CON ; stop PWM
315 bcf PORTC,2 ; Pull PWM out to GND 193 bcf PORTC,2 ; pull PWM out to GND
316 clrf PORTA 194 clrf PORTA
317 clrf PORTH 195 clrf PORTH
318 RD_L ; LOW 196 RD_L ; LOW
319 RS_L ; LOW 197 RS_L ; LOW
320 bcf tft_nwr 198 bcf tft_nwr
321 bcf tft_cs 199 bcf tft_cs
322 bcf tft_nreset 200 bcf tft_nreset
323 bsf tft_power ; inverted... 201 bsf tft_power ; inverted...
324 bcf lightsen_power ; power-down light sensor 202 bcf lightsen_power ; power-down light sensor
325 return 203 return
326 204
327 ; ----------------------------- 205 ; -----------------------------
328 ; TFT boot 206 ; TFT boot
329 ; ----------------------------- 207 ; -----------------------------
330 208
331 global TFT_boot 209 global TFT_boot
332 TFT_boot: 210 TFT_boot:
333 clrf CCP1CON ; stop PWM 211 ; switch off backlight
334 bcf PORTC,2 ; Pull PWM out to GND 212 clrf CCP1CON ; stop PWM
213 bcf PORTC,2 ; pull PWM out to GND
214
335 clrf PORTA 215 clrf PORTA
336 clrf PORTH 216 clrf PORTH
337 RD_L ; LOW 217 RD_L ; LOW
338 bcf tft_nwr 218 bcf tft_nwr
339 nop 219 nop
359 239
360 ; Data Transfer Synchronization 240 ; Data Transfer Synchronization
361 Parameter_out 0x00, 0x00 241 Parameter_out 0x00, 0x00
362 Parameter_out 0x00, 0x00 242 Parameter_out 0x00, 0x00
363 243
364 btfsc screen_type2 ; Display 2 244 btfsc screen_type2 ; display type 2 ?
365 bra TFT_boot_screen2 245 bra TFT_boot_screen2 ; YES
366 246
367 ; Get screentype from Bootloader-Info 247 ; Get screen type from Bootloader-Info
368 movlw 0x7B 248 movlw 0x7B
369 movwf TBLPTRL 249 movwf TBLPTRL
370 movlw 0xF7 250 movlw 0xF7
371 movwf TBLPTRH 251 movwf TBLPTRH
372 movlw 0x01 252 movlw 0x01
373 movwf TBLPTRU 253 movwf TBLPTRU
374 TBLRD*+ ; reads .110 for cR and USB OSTC3, .0 for BLE (2 and 3), and .2 for display1 OSTC 254 TBLRD*+ ; reads 0x6E for cR and USB OSTC3, 0x00 for BLE (2 and 3), and 0x02 for display 1 OSTC
375 movlw 0x02 255 movlw 0x02 ; coding for display 1
376 cpfseq TABLAT 256 cpfseq TABLAT ; display 1 ?
377 bra TFT_boot_0 ; display0 257 bra TFT_boot_0 ; NO - display 0
378 258
379 TFT_boot_1: 259 TFT_boot_1:
380 ; Init through config table... 260 ; Init through config table...
381 movlw 0x74 261 movlw 0x74
382 movwf TBLPTRL 262 movwf TBLPTRL
446 326
447 display0_init_loop: 327 display0_init_loop:
448 TBLRD*+ 328 TBLRD*+
449 movlw 0xFF 329 movlw 0xFF
450 cpfseq TABLAT 330 cpfseq TABLAT
451 bra display0_config_write ; write config pair to display 331 bra display0_config_write ; write configuration data pair to display
452 ; Delay ms or quit (return) 332 ; Delay ms or quit (return)
453 TBLRD*+ 333 TBLRD*+
454 tstfsz TABLAT ; end of config? 334 tstfsz TABLAT ; end of configuration data?
455 bra $+4 ; NO 335 bra $+4 ; NO
456 return ; YES - done 336 return ; YES - done
457 movf TABLAT,W 337 movf TABLAT,W
458 call WAITMSX ; wait WREG milliseconds 338 call WAITMSX ; wait WREG milliseconds
459 TBLRD*+ ; dummy read (Third byte of delay command) 339 TBLRD*+ ; dummy read (Third byte of delay command)
464 rcall TFT_CmdWrite ; write command 344 rcall TFT_CmdWrite ; write command
465 TBLRD*+ ; get config0 345 TBLRD*+ ; get config0
466 movff TABLAT,PORTA 346 movff TABLAT,PORTA
467 TBLRD*+ ; get config1 347 TBLRD*+ ; get config1
468 movf TABLAT,W 348 movf TABLAT,W
469 rcall TFT_DataWrite ; write config 349 rcall TFT_DataWrite ; write configuration
470 bra display0_init_loop ; loop 350 bra display0_init_loop ; loop
471 351
352
472 TFT_boot_screen2: 353 TFT_boot_screen2:
473 bsf tft_nwr ; release bus. 354 bsf tft_nwr ; release bus
474 rcall display1_init ; Init sequence 355 rcall display1_init ; initialization sequence
475 356
476 btfss flip_screen ; 180° rotation ? 357 btfss flip_screen ; 180° rotation?
477 bra TFT_ClearScreen ; No, done. Clearscreen and return 358 bra TFT_ClearScreen ; NO - done: clear screen and return
478 ; flip the GRAM 359 ; flip the GRAM
479 Index_out 0x16 360 Index_out 0x16
480 movlw 0x48 ; Flip image in the GRAM (Very elegant with display2...) 361 movlw 0x48 ; flip image in the GRAM (very elegant with display 2...)
481 rcall TFT_DataWrite ; Write config 362 rcall TFT_DataWrite ; Write configuration
482 bra TFT_ClearScreen ; Clearscreen and return 363 bra TFT_ClearScreen ; clear screen and return
483
484 364
485 display1_init: 365 display1_init:
486 movlw LOW 0x1F8BC 366 movlw LOW (0x1F8BC )
487 movwf TBLPTRL 367 movwf TBLPTRL
488 movlw HIGH 0x1F8BC 368 movlw HIGH (0x1F8BC & 0xFFFF)
489 movwf TBLPTRH 369 movwf TBLPTRH
490 movlw UPPER 0x1F8BC 370 movlw UPPER (0x1F8BC )
491 movwf TBLPTRU 371 movwf TBLPTRU
492 display1_init_loop: 372 display1_init_loop:
493 TBLRD*+ 373 TBLRD*+
494 movlw 0xFF 374 movlw 0xFF ; coding for end of configuration or wait step
495 cpfseq TABLAT 375 cpfseq TABLAT
496 bra display1_config_write ; Write Config pair to Display 376 bra display1_config_write ; write configuration pair to display
497 ; Delay ms or quit (return) 377 ; Delay ms or quit (return)
498 TBLRD*+ 378 TBLRD*+
499 tstfsz TABLAT ; End of config? 379 tstfsz TABLAT ; end of configuration?
500 bra $+4 ; No 380 bra $+4 ; NO - skip return
501 return ; Done. 381 return ; YES - done
502 movf TABLAT,W 382 movf TABLAT,W ; read waiting time
503 call WAITMSX ; Wait WREG milliseconds 383 call WAITMSX ; wait WREG milliseconds
504 bra display1_init_loop ; Loop 384 bra display1_init_loop ; loop
505 385 display1_config_write: ; with command in WREG
506 display1_config_write: ; With command in WREG 386 movf TABLAT,W
507 movf TABLAT,W 387 rcall TFT_CmdWrite ; write command
508 rcall TFT_CmdWrite ; Write command 388 TBLRD*+ ; get configuration
509 TBLRD*+ ; Get config 389 movf TABLAT,W
510 movf TABLAT,W 390 rcall TFT_DataWrite ; write configuration
511 rcall TFT_DataWrite ; Write config 391 bra display1_init_loop ; loop
512 bra display1_init_loop ; Loop
513 392
514 393
515 ;============================================================================= 394 ;=============================================================================
516 395
517 global TFT_CmdWrite 396 global TFT_CmdWrite
518 TFT_CmdWrite: 397 TFT_CmdWrite:
519 RS_L ; command 398 RS_L ; command
520 btfsc screen_type2 399 btfsc screen_type2
521 bra TFT_CmdWrite_screen2 400 bra TFT_CmdWrite_screen2
522 clrf PORTA ; upper 401 clrf PORTA ; upper
523 bcf INTCON,GIE 402 bcf INTCON,GIE
524 movwf PORTH ; lower 403 movwf PORTH ; lower
525 WR_L 404 WR_L
526 WR_H ; tick 405 WR_H ; tick
527 bsf INTCON,GIE 406 bsf INTCON,GIE
528 return 407 return
529 TFT_CmdWrite_screen2: 408 TFT_CmdWrite_screen2:
530 movwf PORTH ; Lower 409 movwf PORTH ; lower
531 WR_L 410 WR_L
532 WR_H ; Tick 411 WR_H ; tick
533 return; 412 return;
534 413
535 global TFT_DataWrite 414 global TFT_DataWrite
536 TFT_DataWrite: 415 TFT_DataWrite:
537 RS_H ; data 416 RS_H ; data
538 btfsc screen_type2 417 btfsc screen_type2
539 bra TFT_DataWrite_screen2 418 bra TFT_DataWrite_screen2
540 bcf INTCON,GIE 419 bcf INTCON,GIE
541 movwf PORTH ; lower 420 movwf PORTH ; lower
542 WR_L 421 WR_L
543 WR_H ; tick 422 WR_H ; tick
544 bsf INTCON,GIE 423 bsf INTCON,GIE
545 return 424 return
546 TFT_DataWrite_screen2: 425 TFT_DataWrite_screen2:
547 movwf PORTH ; Lower 426 movwf PORTH ; lower
548 WR_L 427 WR_L
549 WR_H ; Tick 428 WR_H ; tick
550 return 429 return
430
551 431
552 ;============================================================================= 432 ;=============================================================================
553
554 ; Smooth lighting-up of the display: 433 ; Smooth lighting-up of the display:
555 ; 434 ;
556 ; Trashes: WREG, PRODL 435 ; Trashes: WREG, PRODL
557 ; Typical usage: 436 ; Typical usage:
558 ; clrf CCPR1L ; backlight off 437 ; clrf CCPR1L ; backlight off
559 ; [draw splash screen] 438 ; [draw splash screen]
560 ; call TFT_DisplayFadeIn 439 ; call TFT_DisplayFadeIn
561 440
562 global TFT_Display_FadeIn 441 global TFT_Display_FadeIn
563 TFT_Display_FadeIn: 442 TFT_Display_FadeIn:
564 movlw CCP1CON_VALUE ; see hwos.inc 443 movlw CCP1CON_VALUE ; get configuration
565 movwf CCP1CON 444 movwf CCP1CON ; set configuration
566 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor 445 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor
567 clrf CCPR1L ; backlight off - to be sure 446 clrf CCPR1L ; backlight off - to be sure
568 movff max_CCPR1L,PRODL 447 movff max_CCPR1L,PRODL
569 TFT_Display_FadeIn_0: 448 TFT_Display_FadeIn_0:
570 incf CCPR1L,F ; duty cycle 449 incf CCPR1L,F ; duty cycle
571 WAITMS d'2' 450 WAITMS d'2'
572 decfsz PRODL,F 451 decfsz PRODL,F
573 bra TFT_Display_FadeIn_0 452 bra TFT_Display_FadeIn_0
574 bcf tft_is_dimming ; dimming done 453 bcf tft_is_dimming ; dimming done
575 return 454 return
576 455
577 ;============================================================================= 456 ;=============================================================================
578 ; Smooth lighting-off of the display: 457 ; Smooth lighting-off of the display:
594 473
595 global box_std_block, box_black_block, box_color_block 474 global box_std_block, box_black_block, box_color_block
596 475
597 box_std_block: ; use white color 476 box_std_block: ; use white color
598 setf WREG 477 setf WREG
599 bra box_common 478 bra box_common
600 box_black_block: ; use black color 479 box_black_block: ; use black color
601 clrf WREG 480 clrf WREG
602 box_common: 481 box_common:
603 box_color_block: 482 box_color_block:
604 rcall TFT_set_color 483 rcall TFT_set_color
651 ; Trashed: WREG, PROD 530 ; Trashed: WREG, PROD
652 531
653 global pixel_write 532 global pixel_write
654 pixel_write: 533 pixel_write:
655 movf win_leftx2,W 534 movf win_leftx2,W
656 mullw 2 ; win_leftx2 x 2 -> PRODH:PRODL 535 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL
657 rcall pixel_write_col320 ; start address vertical (.0 - .319) 536 rcall pixel_write_col320 ; start address vertical (.0 - .319)
658 rcall half_pixel_write ; write this half-one 537 rcall half_pixel_write ; write this half-one
659 movf win_leftx2,W ; address of next one 538 movf win_leftx2,W ; address of next one
660 mullw 2 539 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL
661 infsnz PRODL ; +1 540 INCI PROD ; PROD++
662 incf PRODH
663 rcall pixel_write_col320 541 rcall pixel_write_col320
664 bra half_pixel_write ; note: Cmd 0x20 is mandatory, because 542 bra half_pixel_write ; note: Cmd 0x20 is mandatory, because
665 ; of the auto-increment going vertical 543 ; of the auto-increment going vertical
666 544
667 global pixel_write_col320 545 global pixel_write_col320
668 pixel_write_col320: 546 pixel_write_col320:
669 btfsc screen_type2 ; display2? 547 btfsc screen_type2 ; display type 2 ?
670 bra pixel_write_col320_d2 ; Yes 548 bra pixel_write_col320_d2 ; YES
671 btfsc screen_type ; display1? 549 btfsc screen_type ; NO - display type 1 ?
672 bra pixel_write_col320_d1 ; YES 550 bra pixel_write_col320_d1 ; YES
673 ; Display0 551 ; NO - display type 0
674 btfss flip_screen ; 180° rotation? 552 btfss flip_screen ; 180° rotation?
675 bra pixel_write_noflip_H ; NO 553 bra pixel_write_noflip_H ; NO
676 bra pixel_write_flip_H ; YES 554 bra pixel_write_flip_H ; YES
677 pixel_write_col320_d1: ; Display1 555 pixel_write_col320_d1: ; display type 1
678 btfsc flip_screen ; 180° rotation? 556 btfsc flip_screen ; 180° rotation?
679 bra pixel_write_noflip_H ; YES for d1 557 bra pixel_write_noflip_H ; YES
680 pixel_write_flip_H: ; flip d0 558 pixel_write_flip_H: ; flip d0
681 movf PRODL,W ; 16 bits 319 - PROD --> PROD 559 movf PRODL,W ; 16 bits 319 - PROD --> PROD
682 sublw LOW(.319) ; 319-W --> W 560 sublw LOW .319 ; 319-W --> W
683 movwf PRODL 561 movwf PRODL
684 movf PRODH,W 562 movf PRODH,W
685 btfss STATUS,C ; borrow = /CARRY 563 btfss STATUS,C ; borrow = /CARRY
686 incf WREG 564 incf WREG
687 sublw HIGH(.319) 565 sublw HIGH .319
688 movwf PRODH 566 movwf PRODH
689 567
690 pixel_write_noflip_H: 568 pixel_write_noflip_H:
691 Index_out 0x21 ; frame memory vertical address 569 Index_out 0x21 ; frame memory vertical address
692 bra TFT_DataWrite_PROD ; and return... 570 bra TFT_DataWrite_PROD ; and return...
693 571
694 pixel_write_col320_d2: 572 pixel_write_col320_d2:
695 movlw 0x06 573 movlw 0x06
696 rcall TFT_CmdWrite 574 rcall TFT_CmdWrite
697 movf PRODH,W 575 movf PRODH,W
698 rcall TFT_DataWrite 576 rcall TFT_DataWrite
699 movlw 0x07 577 movlw 0x07
700 rcall TFT_CmdWrite 578 rcall TFT_CmdWrite
701 movf PRODL,W 579 movf PRODL,W
702 rcall TFT_DataWrite 580 rcall TFT_DataWrite
703 581
704 incf PRODL,F 582 incf PRODL,F
705 movlw .0 583 movlw .0
706 addwfc PRODH,F ;+1 584 addwfc PRODH,F ; +1
707 585
708 movlw 0x08 586 movlw 0x08
709 rcall TFT_CmdWrite 587 rcall TFT_CmdWrite
710 movf PRODH,W 588 movf PRODH,W
711 rcall TFT_DataWrite 589 rcall TFT_DataWrite
712 movlw 0x09 590 movlw 0x09
713 rcall TFT_CmdWrite 591 rcall TFT_CmdWrite
714 movf PRODL,W 592 movf PRODL,W
715 bra TFT_DataWrite ; And return... 593 bra TFT_DataWrite ; ... and return
716 594
717 ;----------------------------------------------------------------------------- 595 ;-----------------------------------------------------------------------------
718 ; Writes one half-pixel at position (win_top,win_leftx2). 596 ; Writes one half-pixel at position (win_top,win_leftx2).
719 ; Inputs: win_leftx2, win_top, win_color:2 597 ; Inputs: win_leftx2, win_top, win_color:2
720 ; Trashed: WREG, PROD 598 ; Trashed: WREG, PROD
722 global half_pixel_write 600 global half_pixel_write
723 half_pixel_write: 601 half_pixel_write:
724 movf win_top,W ; d'0' ... d'239' 602 movf win_top,W ; d'0' ... d'239'
725 ; Variant with Y position in WREG. 603 ; Variant with Y position in WREG.
726 half_pixel_write_1: 604 half_pixel_write_1:
727 btfsc screen_type2 605 btfsc screen_type2 ; screen tpe 2 ?
728 bra half_pixel_write_1_display1 ; Yes. 606 bra half_pixel_write_1_display1 ; YES
729 607
730 btfss flip_screen ; 180° rotation? 608 btfss flip_screen ; 180° rotation?
731 sublw .239 ; 239-Y --> Y 609 sublw .239 ; 239-Y --> Y
732 mullw .1 ; copy row to PRODL (PRODH=0) 610 mullw .1 ; copy row to PRODL (PRODH=0)
733 Index_out 0x20 ; frame memory horizontal address 611 Index_out 0x20 ; frame memory horizontal address
742 WR_H ; tick 620 WR_H ; tick
743 bsf INTCON,GIE 621 bsf INTCON,GIE
744 return 622 return
745 623
746 half_pixel_write_1_display1: 624 half_pixel_write_1_display1:
747 mullw 1 ; Copy row to PRODL (PRODH=0) 625 mullw 1 ; copy row to PRODL (PRODH=0)
748 ; Row address start 626 ; Row address start
749 movlw 0x02 627 movlw 0x02
750 rcall TFT_CmdWrite 628 rcall TFT_CmdWrite
751 movlw .0 629 movlw .0
752 rcall TFT_DataWrite 630 rcall TFT_DataWrite
753 movlw 0x03 631 movlw 0x03
754 rcall TFT_CmdWrite 632 rcall TFT_CmdWrite
755 movf PRODL,W 633 movf PRODL,W
756 rcall TFT_DataWrite 634 rcall TFT_DataWrite
757 635
758 incf PRODL,F 636 incf PRODL,F
759 637
760 movlw 0x04 638 movlw 0x04
761 rcall TFT_CmdWrite 639 rcall TFT_CmdWrite
762 movlw .0 640 movlw .0
763 rcall TFT_DataWrite 641 rcall TFT_DataWrite
764 movlw 0x05 642 movlw 0x05
765 rcall TFT_CmdWrite 643 rcall TFT_CmdWrite
766 movf PRODL,W 644 movf PRODL,W
767 rcall TFT_DataWrite 645 rcall TFT_DataWrite
768 646
769 movff win_color1,PRODH 647 movff win_color1,PRODH
770 movff win_color2,PRODL 648 movff win_color2,PRODL
771 rcall convert_for_display2 649 rcall convert_for_display2
772 650
773 movlw 0x22 ; Start Writing Data to GRAM 651 movlw 0x22 ; start writing data to GRAM
774 rcall TFT_CmdWrite 652 rcall TFT_CmdWrite
775 RS_H ; Data 653 RS_H ; data
776 movff win_color5, PORTH 654 movff win_color5, PORTH
777 WR_L 655 WR_L
778 WR_H ; Tick 656 WR_H ; tick
779 movff win_color4, PORTH 657 movff win_color4, PORTH
780 WR_L 658 WR_L
781 WR_H ; Tick 659 WR_H ; tick
782 movff win_color3, PORTH 660 movff win_color3, PORTH
783 WR_L 661 WR_L
784 WR_H ; Tick 662 WR_H ; tick
785 return 663 return
786 664
787 ;----------------------------------------------------------------------------- 665 ;-----------------------------------------------------------------------------
788 ; Writes a vertical line of half-pixel at position (win_top,win_leftx2,win_height). 666 ; Writes a vertical line of half-pixel at position (win_top,win_leftx2,win_height).
789 ; Inputs: win_leftx2, win_top, win_height, win_color:2 667 ; Inputs: win_leftx2, win_top, win_height, win_color:2
790 ; Trashed: WREG, PROD, TABLAT, TBLPTRL 668 ; Trashed: WREG, PROD, TABLAT, TBLPTRL
793 half_vertical_line: 671 half_vertical_line:
794 clrf TABLAT ; loop index 672 clrf TABLAT ; loop index
795 673
796 half_vertical_line_loop: 674 half_vertical_line_loop:
797 movf win_leftx2,W ; init X position 675 movf win_leftx2,W ; init X position
798 mullw .2 676 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL
799 movf TABLAT,W ; get loop index 677 movf TABLAT,W ; get loop index
800 andlw .1 ; just low bit 678 andlw .1 ; just low bit
801 xorwf PRODL,F ; and use it to jitter current X position 679 xorwf PRODL,F ; and use it to jitter current X position
802 rcall pixel_write_col320 ; start address vertical (.0 - .319) 680 rcall pixel_write_col320 ; start address vertical (.0 - .319)
803 681
820 half_horizontal_line: 698 half_horizontal_line:
821 clrf TABLAT ; loop index 699 clrf TABLAT ; loop index
822 700
823 half_horizontal_line_loop: 701 half_horizontal_line_loop:
824 movf win_leftx2,W ; init X position 702 movf win_leftx2,W ; init X position
825 mullw .2 703 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL
826 rcall pixel_write_col320 ; start address vertical (.0 - .319) 704 rcall pixel_write_col320 ; start address vertical (.0 - .319)
827 movf win_width,W ; index reached height (bank0 read) ? 705 movf win_width,W ; index reached height (bank0 read) ?
828 xorwf TABLAT,W 706 xorwf TABLAT,W
829 btfsc STATUS,Z ; equal ? 707 btfsc STATUS,Z ; equal ?
830 return ; YES - done 708 return ; YES - done
834 incf TABLAT,F ; index++ 712 incf TABLAT,F ; index++
835 bra half_horizontal_line_loop 713 bra half_horizontal_line_loop
836 714
837 715
838 ;----------------------------------------------------------------------------- 716 ;-----------------------------------------------------------------------------
839 ; TFT Data Cmd via W 717 ; TFT Data Command via W
840 718
841 global TFT_DataWrite_PROD 719 global TFT_DataWrite_PROD
842 TFT_DataWrite_PROD: 720 TFT_DataWrite_PROD:
843 ; RD_H ; keep high 721 ; RD_H ; keep high
844 RS_H ; data 722 RS_H ; data
845 btfsc screen_type2 723 btfsc screen_type2 ; screen type 2 ?
846 bra TFT_DataWrite_PROD_display2 724 bra TFT_DataWrite_PROD_display2 ; YES
847 bcf INTCON,GIE 725 bcf INTCON,GIE ; NO -
848 movff PRODH,PORTA ; move high byte to PORTA 726 movff PRODH,PORTA ; - move high byte to PORTA
849 movff PRODL,PORTH ; move low byte to PORTH 727 movff PRODL,PORTH ; - move low byte to PORTH
850 WR_L 728 WR_L ; - tick
851 WR_H ; tick 729 WR_H ; - tack
852 bsf INTCON,GIE 730 bsf INTCON,GIE ; -
853 return 731 return ; - done
854 732
855 TFT_DataWrite_PROD_display2: 733 TFT_DataWrite_PROD_display2:
856 movff PRODH,PORTH ; Move high byte to PORTH (DISPLAY is bigendian) 734 movff PRODH,PORTH ; move high byte to PORTH (display 2 is big endian)
857 WR_L 735 WR_L ; tick
858 WR_H 736 WR_H ; tack
859 movff PRODL,PORTH ; Move low byte to PORTH 737 movff PRODL,PORTH ; move low byte to PORTH
860 WR_L 738 WR_L ; tick
861 WR_H 739 WR_H ; tack
862 movff win_color3,PORTH ; Move low(est) byte to PORTH 740 movff win_color3,PORTH ; move low(est) byte to PORTH
863 WR_L 741 WR_L ; tick
864 WR_H 742 WR_H ; tack
865 return 743 return ; done
744
866 745
867 TFT_DataRead_PROD: 746 TFT_DataRead_PROD:
868 Index_out 0x22 ; frame memory data read start 747 Index_out 0x22 ; frame memory data read start
869 TFT_CmdRead_PROD: 748 TFT_CmdRead_PROD:
870 setf TRISA ; port A as input 749 setf TRISA ; port A as input
897 ; Output : PortA/PortH commands 776 ; Output : PortA/PortH commands
898 ; Trashed: PROD 777 ; Trashed: PROD
899 778
900 global TFT_box_write 779 global TFT_box_write
901 TFT_box_write: 780 TFT_box_write:
902 movf win_leftx2,W ; compute left = 2 * leftx2 --> PROD 781 movf win_leftx2,W ; compute left = 2 * leftx2 --> PROD
903 mullw 2 782 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL
904 783
905 btfsc screen_type2 784 btfsc screen_type2 ; screen type 2 ?
906 bra TFT_box_write_display2 785 bra TFT_box_write_display2 ; YES
907 786
908 global TFT_box_write_16bit_win_left 787 global TFT_box_write_16bit_win_left
909 TFT_box_write_16bit_win_left: ; Wwth column in PRODL:PRODH 788 TFT_box_write_16bit_win_left: ; with column in PRODL:PRODH
910 btfsc screen_type ; display1? 789 btfsc screen_type ; screen type 1 ?
911 bra TFT_box_write_16bit_win_left_d1 ; YES 790 bra TFT_box_write_16bit_win_left_d1 ; YES
912 ; Display0 791 ; screen type 0
913 btfsc flip_screen ; 180° rotation? 792 btfsc flip_screen ; 180° rotation?
914 bra DISP_box_flip_H ; YES 793 bra DISP_box_flip_H ; YES
915 bra TFT_box_write_16bit_win_left_com ; NO 794 bra TFT_box_write_16bit_win_left_com ; NO
916 TFT_box_write_16bit_win_left_d1: ; Display1 795 TFT_box_write_16bit_win_left_d1: ; Display1
917 btfss flip_screen ; 180° rotation? 796 btfss flip_screen ; 180° rotation?
918 bra DISP_box_flip_H ; NO for d1 797 bra DISP_box_flip_H ; NO
919 ; Yes for d1 798 TFT_box_write_16bit_win_left_com: ; YES for screen type 1, NO for type 0
920 TFT_box_write_16bit_win_left_com:
921 ;---- Normal horizontal window --------------------------------------- 799 ;---- Normal horizontal window ---------------------------------------
922 Index_out 0x52 ; window vertical start address 800 Index_out 0x52 ; window vertical start address
923 rcall TFT_DataWrite_PROD ; output left 801 rcall TFT_DataWrite_PROD ; output left
924 Index_out 0x21 ; frame memory vertical address 802 Index_out 0x21 ; frame memory vertical address
925 rcall TFT_DataWrite_PROD ; output left 803 rcall TFT_DataWrite_PROD ; output left
926 804
927 movf win_width+0,W ; right = left + width - 1 805 movf win_width+0,W ; right = left + width - 1
928 addwf PRODL,F 806 addwf PRODL,F
929 movf win_width+1,W 807 movf win_width+1,W
930 addwfc PRODH,F 808 addwfc PRODH,F
931 decf PRODL,F ; decrement result 809 decf PRODL,F ; right--
932 btfss STATUS,C 810 btfss STATUS,C
933 decf PRODH,F 811 decf PRODH,F
934 812
935 Index_out 0x53 ; window vertical end address 813 Index_out 0x53 ; window vertical end address
936 rcall TFT_DataWrite_PROD 814 rcall TFT_DataWrite_PROD
937 bra DISP_box_noflip_H 815 bra DISP_box_noflip_H
938 816
939 ;---- Flipped horizontal window -------------------------------------- 817 ;---- Flipped horizontal window --------------------------------------
940 DISP_box_flip_H: 818 DISP_box_flip_H:
819 ; calculate new coordinate
941 movf PRODL,W ; 16 bits 319 - PROD --> PROD 820 movf PRODL,W ; 16 bits 319 - PROD --> PROD
942 sublw LOW(.319) ; 319 - WREG --> WREG 821 sublw LOW .319 ; 319 - WREG --> WREG
943 movwf PRODL 822 movwf PRODL
944 movf PRODH,W 823 movf PRODH,W
945 btfss STATUS,C ; borrow = /CARRY 824 btfss STATUS,C ; borrow = /CARRY
946 incf WREG 825 incf WREG
947 sublw HIGH(.319) 826 sublw HIGH .319
948 movwf PRODH 827 movwf PRODH
949 828
950 Index_out 0x53 ; window vertical start address 829 Index_out 0x53 ; window vertical start address
951 rcall TFT_DataWrite_PROD ; output left 830 rcall TFT_DataWrite_PROD ; output left
952 Index_out 0x21 ; frame memory vertical address 831 Index_out 0x21 ; frame memory vertical address
953 rcall TFT_DataWrite_PROD ; output left 832 rcall TFT_DataWrite_PROD ; output left
954 833
834 ; calculate new coordinate
955 movf win_width+0,W ; 16 bits PROD - width --> PROD 835 movf win_width+0,W ; 16 bits PROD - width --> PROD
956 subwf PRODL,F ; PRODL - WREG --> PRODL 836 subwf PRODL,F ; PRODL - WREG --> PRODL
957 movf win_width+1,W 837 movf win_width+1,W
958 subwfb PRODH,F 838 subwfb PRODH,F
959 infsnz PRODL ; PROD + 1 --> PROD 839 INCI PROD ; PROD++
960 incf PRODH
961 840
962 Index_out 0x52 ; window vertical end address 841 Index_out 0x52 ; window vertical end address
963 rcall TFT_DataWrite_PROD 842 rcall TFT_DataWrite_PROD
964 843
965 DISP_box_noflip_H: 844 DISP_box_noflip_H:
966 btfss flip_screen ; 180° rotation ? 845 btfss flip_screen ; 180° rotation ?
967 bra TFT_box_noflip_V ; NO 846 bra TFT_box_noflip_V ; NO
968 847
969 ;---- Flipped vertical window ----------------------------------------- 848 ;---- Flipped vertical window -----------------------------------------
849 ; calculate new coordinate
970 movff win_top,PRODH ; top --> PRODH (first byte) 850 movff win_top,PRODH ; top --> PRODH (first byte)
971 movf win_height,W 851 movf win_height,W
972 addwf PRODH,W 852 addwf PRODH,W
973 decf WREG 853 decf WREG
974 movwf PRODL ; top + height - 1 --> PRODL (second byte) 854 movwf PRODL ; top + height - 1 --> PRODL (second byte)
1007 887
1008 Index_out 0x20 ; frame memory horizontal address 888 Index_out 0x20 ; frame memory horizontal address
1009 movf PRODL,W 889 movf PRODL,W
1010 bra TFT_DataWrite ; lower (and tick) and return 890 bra TFT_DataWrite ; lower (and tick) and return
1011 891
892
1012 TFT_box_write_display2: 893 TFT_box_write_display2:
1013 movlw 0x06 894 movlw 0x06
1014 rcall TFT_CmdWrite 895 rcall TFT_CmdWrite
1015 movf PRODH,W 896 movf PRODH,W
1016 rcall TFT_DataWrite 897 rcall TFT_DataWrite
1017 movlw 0x07 898 movlw 0x07
1018 rcall TFT_CmdWrite 899 rcall TFT_CmdWrite
1019 movf PRODL,W 900 movf PRODL,W
1020 rcall TFT_DataWrite 901 rcall TFT_DataWrite
1021 902
1022 movf win_width+0,W ; right = left + width - 1 903 movf win_width+0,W ; right = left + width - 1
1023 addwf PRODL,F 904 addwf PRODL,F
1024 movf win_width+1,W 905 movf win_width+1,W
1025 addwfc PRODH,F 906 addwfc PRODH,F
1026 decf PRODL,F,A ; decrement result 907 decf PRODL,F,A ; decrement result
1027 btfss STATUS,C 908 btfss STATUS,C
1028 decf PRODH,F,A 909 decf PRODH,F,A
1029 910
1030 movlw 0x08 911 movlw 0x08
1031 rcall TFT_CmdWrite 912 rcall TFT_CmdWrite
1032 movf PRODH,W 913 movf PRODH,W
1033 rcall TFT_DataWrite 914 rcall TFT_DataWrite
1034 movlw 0x09 915 movlw 0x09
1035 rcall TFT_CmdWrite 916 rcall TFT_CmdWrite
1036 movf PRODL,W 917 movf PRODL,W
1037 rcall TFT_DataWrite 918 rcall TFT_DataWrite
1038 919
1039 ;---- Normal vertical window ----------------------------------------- 920 ;---- Normal vertical window -----------------------------------------
1040 ; Output (top) (bottom) 921 ; Output (top) (bottom)
1041 movff win_top,PRODH ; top --> PRODH (first byte) 922 movff win_top,PRODH ; top --> PRODH (first byte)
1042 movff win_height,WREG 923 movf win_height,W
1043 addwf PRODH,W 924 addwf PRODH,W
1044 decf WREG 925 decf WREG
1045 movwf PRODL ; top+height-1 --> PRODL (second byte) 926 movwf PRODL ; top+height-1 --> PRODL (second byte)
1046 927
1047 movlw 0x02 928 movlw 0x02
1048 rcall TFT_CmdWrite 929 rcall TFT_CmdWrite
1049 movlw 0x00 930 movlw 0x00
1050 rcall TFT_DataWrite 931 rcall TFT_DataWrite
1051 movlw 0x03 932 movlw 0x03
1052 rcall TFT_CmdWrite 933 rcall TFT_CmdWrite
1053 movf PRODH,W 934 movf PRODH,W
1054 rcall TFT_DataWrite 935 rcall TFT_DataWrite
1055 936
1056 movlw 0x04 937 movlw 0x04
1057 rcall TFT_CmdWrite 938 rcall TFT_CmdWrite
1058 movlw 0x00 939 movlw 0x00
1059 rcall TFT_DataWrite 940 rcall TFT_DataWrite
1060 movlw 0x05 941 movlw 0x05
1061 rcall TFT_CmdWrite 942 rcall TFT_CmdWrite
1062 movf PRODL,W 943 movf PRODL,W
1063 bra TFT_DataWrite ; and return 944 bra TFT_DataWrite ; ... and return
1064
1065 945
1066 ;============================================================================= 946 ;=============================================================================
1067 ; TFT_frame : draw a frame around current box with current color 947 ; TFT_frame : draw a frame around current box with current color
1068 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 948 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2
1069 ; Outputs: (none) 949 ; Outputs: (none)
1070 ; Trashed: WREG, PROD, aa_start:2, aa_end:2 950 ; Trashed: WREG, PROD, aa_start:2, aa_end:2
1071 951
1072 global TFT_frame 952 global TFT_frame
1073 TFT_frame: 953 TFT_frame:
1074 movff win_top,save_top ; backup everything 954 movff win_top,tft_save_top ; backup everything
1075 movff win_height,save_height 955 movff win_height,tft_save_height
1076 movff win_leftx2,save_left 956 movff win_leftx2,tft_save_left
1077 movff win_width,save_width 957 movff win_width,tft_save_width
1078 958
1079 ;---- TOP line ----------------------------------------------------------- 959 ;---- TOP line -----------------------------------------------------------
1080 movlw .1 ; row ~ height = 1 960 movlw .1 ; row ~ height = 1
1081 movwf win_height 961 movwf win_height
1082 rcall TFT_box 962 rcall TFT_box
1083 963
1084 ;---- BOTTOM line -------------------------------------------------------- 964 ;---- BOTTOM line --------------------------------------------------------
1085 movff save_top,PRODL ; get back top 965 movff tft_save_top,PRODL ; get back top
1086 movff save_height,WREG ; get back height 966 movff tft_save_height,WREG ; get back height
1087 addwf PRODL,W ; top + height 967 addwf PRODL,W ; top + height
1088 decf WREG ; top + height - 1 968 decf WREG ; top + height - 1
1089 movwf win_top ; top + height - 1 --> top 969 movwf win_top ; top + height - 1 --> top
1090 rcall TFT_box 970 rcall TFT_box
1091 971
1092 ;---- LEFT column -------------------------------------------------------- 972 ;---- LEFT column --------------------------------------------------------
1093 movff save_top,win_top ; restore top/height 973 movff tft_save_top,win_top ; restore top/height
1094 movff save_height,win_height 974 movff tft_save_height,win_height
1095 movlw .1 ; column ~ width = 1 975 movlw .1 ; column ~ width = 1
1096 movwf win_width+0 976 movwf win_width+0
1097 rcall TFT_box 977 rcall TFT_box
1098 978
1099 ;---- RIGHT column ------------------------------------------------------- 979 ;---- RIGHT column -------------------------------------------------------
1100 movff save_left,WREG 980 movff tft_save_left,WREG
1101 movff save_width,PRODL 981 movff tft_save_width,PRODL
1102 addwf PRODL,W 982 addwf PRODL,W
1103 decf WREG 983 decf WREG
1104 movwf win_leftx2 984 movwf win_leftx2
1105 rcall TFT_box 985 rcall TFT_box
1106 986
1107 ;---- Restore everything ------------------------------------------------- 987 ;---- Restore everything -------------------------------------------------
1108 movff save_left,win_leftx2 988 movff tft_save_left,win_leftx2
1109 movff save_width,win_width 989 movff tft_save_width,win_width
1110 return 990 return
1111 991
1112 ;============================================================================= 992 ;=============================================================================
1113 ; TFT_box: fills current box with current color 993 ; TFT_box: fills current box with current color
1114 ; Inputs : win_top, win_leftx2, win_height, win_width, win_color1, win_color2 994 ; Inputs : win_top, win_leftx2, win_height, win_width, win_color1, win_color2
1115 ; Outputs: (none) 995 ; Outputs: (none)
1116 ; Trashed: WREG, PROD 996 ; Trashed: WREG, PROD
1117 997
1118 global TFT_box 998 global TFT_box
1119 TFT_box: 999 TFT_box:
1120 btfsc screen_type2 1000 btfsc screen_type2 ; display type 2 ?
1121 bra TFT_box_display2 1001 bra TFT_box_display2 ; YES
1002
1122 ;---- Define Window ------------------------------------------------------ 1003 ;---- Define Window ------------------------------------------------------
1123 bcf STATUS,C 1004 bcf STATUS,C
1124 rlcf win_width+0,F 1005 rlcf win_width+0,F
1125 rlcf win_width+1,F ; x2 1006 rlcf win_width+1,F ; x2
1126 rcall TFT_box_write ; setup box 1007 rcall TFT_box_write ; setup box
1139 1020
1140 TFT_box2: ; loop height times 1021 TFT_box2: ; loop height times
1141 movff win_height,PRODL 1022 movff win_height,PRODL
1142 1023
1143 TFT_box3: ; loop width times 1024 TFT_box3: ; loop width times
1144 bcf INTCON,GIE 1025 bcf INTCON,GIE
1145 movff win_color1,PORTA ; upper 1026 movff win_color1,PORTA ; upper
1146 movff win_color2,PORTH ; lower 1027 movff win_color2,PORTH ; lower
1147 WR_L 1028 WR_L
1148 WR_H ; tick 1029 WR_H ; tick
1149 1030
1163 clrf win_color1 ; Yes - switch to black 1044 clrf win_color1 ; Yes - switch to black
1164 clrf win_color2 ; - ... 1045 clrf win_color2 ; - ...
1165 TFT_box4: 1046 TFT_box4:
1166 movf win_width+0,W ; compare ? 1047 movf win_width+0,W ; compare ?
1167 xorwf PRODH,W 1048 xorwf PRODH,W
1168 bnz TFT_box2 ; Loop not finished 1049 bnz TFT_box2 ; loop not finished
1169 1050
1170 movlw 0x00 ; NOP, to stop window mode 1051 movlw 0x00 ; NOP, to stop window mode
1171 rcall TFT_CmdWrite 1052 rcall TFT_CmdWrite
1172 1053
1173 ; reset bargraph mode... 1054 ; reset bargraph mode...
1174 setf win_bargraph 1055 setf win_bargraph
1175 return 1056 return
1057
1176 TFT_box_display2: 1058 TFT_box_display2:
1177 ;---- Define Window ------------------------------------------------------ 1059 ;---- Define Window ------------------------------------------------------
1178 bcf STATUS,C 1060 bcf STATUS,C
1179 rlcf win_width+0,F 1061 rlcf win_width+0,F
1180 rlcf win_width+1,F ; x2 1062 rlcf win_width+1,F ; x2
1181 rcall TFT_box_write ; Setup box 1063 rcall TFT_box_write ; setup box
1182 1064
1183 bcf STATUS,C 1065 bcf STATUS,C
1184 rrcf win_width+1,F ; width /= 2 1066 rrcf win_width+1,F ; width /= 2
1185 rrcf win_width+0,F 1067 rrcf win_width+0,F
1186 1068
1187 movff win_color1,PRODH 1069 movff win_color1,PRODH
1188 movff win_color2,PRODL 1070 movff win_color2,PRODL
1189 rcall convert_for_display2 1071 rcall convert_for_display2
1190 ;---- Fill Window -------------------------------------------------------- 1072 ;---- Fill Window --------------------------------------------------------
1191 Index_out 0x22 ; Frame Memory Data Write start 1073 Index_out 0x22 ; frame memory data write start
1192 1074
1193 clrf PRODH ; Column counter. 1075 clrf PRODH ; column counter
1194 RS_H ; Data 1076 RS_H ; data
1195 1077
1196 TFT_box2_display2: ; Loop height times 1078 TFT_box2_display2: ; loop height times
1197 movff win_height,PRODL 1079 movff win_height,PRODL
1198 1080 TFT_box3_display2: ; loop width times
1199 TFT_box3_display2: ; loop width times
1200 movff win_color5,PORTH 1081 movff win_color5,PORTH
1201 bcf tft_nwr 1082 bcf tft_nwr
1202 bsf tft_nwr ; Upper 1083 bsf tft_nwr ; upper
1203 movff win_color4,PORTH 1084 movff win_color4,PORTH
1204 bcf tft_nwr 1085 bcf tft_nwr
1205 bsf tft_nwr ; High 1086 bsf tft_nwr ; high
1206 movff win_color3,PORTH 1087 movff win_color3,PORTH
1207 bcf tft_nwr 1088 bcf tft_nwr
1208 bsf tft_nwr ; Lower 1089 bsf tft_nwr ; low
1209 1090
1210 movff win_color5,PORTH 1091 movff win_color5,PORTH
1211 bcf tft_nwr 1092 bcf tft_nwr
1212 bsf tft_nwr ; Upper 1093 bsf tft_nwr ; upper
1213 movff win_color4,PORTH 1094 movff win_color4,PORTH
1214 bcf tft_nwr 1095 bcf tft_nwr
1215 bsf tft_nwr ; High 1096 bsf tft_nwr ; high
1216 movff win_color3,PORTH 1097 movff win_color3,PORTH
1217 bcf tft_nwr 1098 bcf tft_nwr
1218 bsf tft_nwr ; Lower 1099 bsf tft_nwr ; low
1219 decfsz PRODL,F ; row loop finished ? 1100 decfsz PRODL,F ; row loop finished?
1220 bra TFT_box3_display2 ; No: continue. 1101 bra TFT_box3_display2 ; NO - loop
1221 1102 incf PRODH,F ; YES - column count ++
1222 incf PRODH,F ; column count ++ 1103 movf win_bargraph,W ; - get bargraph width
1223 1104 cpfseq PRODH ; - current column = bargraph ?
1224 movf win_bargraph,W ; current column == bargraph ? 1105 bra TFT_box4_display2 ; NO
1225 cpfseq PRODH 1106 clrf win_color5 ; YES - switch to black
1226 bra TFT_box4_display2 ; No: just loop. 1107 clrf win_color4 ; - ...
1227 1108 clrf win_color3 ; - ...
1228 ; Yes: switch to black
1229 clrf win_color5
1230 clrf win_color4
1231 clrf win_color3
1232 TFT_box4_display2: 1109 TFT_box4_display2:
1233 movf win_width+0,W 1110 movf win_width+0,W ; get width
1234 cpfseq PRODH 1111 cpfseq PRODH ; width loop finished ?
1235 bra TFT_box2_display2 1112 bra TFT_box2_display2 ; NO - loop
1236 1113 setf win_bargraph ; YES - reset bargraph mode
1237 ; Reset bargraph mode... 1114 return ; - done
1238 setf win_bargraph
1239 return
1240
1241 1115
1242 ;============================================================================= 1116 ;=============================================================================
1243 ; Converts 8 bit RGB b'RRRGGGBB' into 16 bit RGB b'RRRRRGGGGGGBBBBB' 1117 ; Convert 8 bit RGB b'RRRGGGBB' into 16 bit RGB b'RRRRRGGGGGGBBBBB'
1244 1118
1245 global TFT_set_color 1119 global TFT_set_color
1246 TFT_set_color: 1120 TFT_set_color:
1247 movwf tft_temp1 ; get 8 Bit RGB b'RRRGGGBB' 1121 movwf tft_temp1 ; get 8 Bit RGB b'RRRGGGBB'
1248 movwf tft_temp2 ; copy 1122 movwf tft_temp2 ; copy
1347 1221
1348 rrcf tft_temp4,F 1222 rrcf tft_temp4,F
1349 rrcf tft_temp1,W ; red done 1223 rrcf tft_temp1,W ; red done
1350 movwf win_color1 ; set color registers 1224 movwf win_color1 ; set color registers
1351 return 1225 return
1352 1226
1227
1353 global convert_for_display2 1228 global convert_for_display2
1354 convert_for_display2: ; Convert 16Bit RGB b'RRRRRGGG GGGBBBBB' into 24Bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00' 1229 convert_for_display2: ; convert 16 bit RGB b'RRRRRGGG GGGBBBBB' into 24 bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00'
1355 ; PRODH PRODL win_color5 win_color4 win_color3 1230 ; PRODH PRODL win_color5 win_color4 win_color3
1356 ; Red 1231 ; Red
1357 movff PRODH,win_color5 ; = RRRRRGGG 1232 movff PRODH,win_color5 ; = RRRRRGGG
1358 bcf win_color5,2 ; = RRRRR0GG 1233 bcf win_color5,2 ; = RRRRR0GG
1359 btfsc win_color5,7 1234 btfsc win_color5,7
1360 bsf win_color5,2 ; = RRRRR1GG ; Lower two bits ignored from screen! 1235 bsf win_color5,2 ; = RRRRR1GG the lower two bits are ignored by the screen
1361 ; Blue 1236 ; Blue
1362 movff PRODL,win_color3 1237 movff PRODL,win_color3
1363 rrcf win_color3,F ; = UGGGBBBB (And the LSB-Blue in Carry) 1238 rrcf win_color3,F ; = UGGGBBBB and the LSB-blue into carry
1364 swapf win_color3,F ; = BBBBUGGG 1239 swapf win_color3,F ; = BBBBUGGG
1365 bcf win_color3,3 ; = BBBB0GGG 1240 bcf win_color3,3 ; = BBBB0GGG
1366 btfsc STATUS,C 1241 btfsc STATUS,C
1367 bsf win_color3,3 ; = BBBB1GGG 1242 bsf win_color3,3 ; = BBBB1GGG
1368 bcf win_color3,2 ; = BBBBB0GG 1243 bcf win_color3,2 ; = BBBBB0GG
1369 btfsc win_color3,7 1244 btfsc win_color3,7
1370 bsf win_color3,2 ; = BBBBB1GG 1245 bsf win_color3,2 ; = BBBBB1GG
1371 ; Green 1246 ; Green
1372 rrcf PRODH,F 1247 rrcf PRODH,F
1373 rrcf PRODL,F 1248 rrcf PRODL,F
1374 rrcf PRODH,F 1249 rrcf PRODH,F
1375 rrcf PRODL,F 1250 rrcf PRODL,F
1376 rrcf PRODH,F 1251 rrcf PRODH,F
1377 rrcf PRODL,F ; = GGGGGGBB ; Lower two bits ignored from screen! 1252 rrcf PRODL,F ; = GGGGGGBB the lower two bits are ignored by the screen
1378 movff PRODL,win_color4 1253 movff PRODL,win_color4
1379 return 1254 return
1380 1255
1381 1256
1382 ;============================================================================= 1257 ;=============================================================================
1258
1259 IFDEF _screendump
1260
1261 ;-----------------------------------------------------------------------------
1383 ; Dump screen contents to the UART 1262 ; Dump screen contents to the UART
1384 1263 ;
1385 IFDEF _screendump
1386
1387 global TFT_dump_screen_check 1264 global TFT_dump_screen_check
1388 global TFT_dump_screen 1265 global TFT_dump_screen
1389 TFT_dump_screen_check: 1266 TFT_dump_screen_check:
1390 btfss vusb_in ; USB (still) plugged in? 1267 btfss vusb_in ; USB (still) plugged in?
1391 bcf enable_screen_dumps ; NO - clear flag 1268 bcf screen_dump_avail ; NO - disable screen dump function
1392 call rs232_get_byte ; try to read data from RS232 1269 call rs232_get_byte ; try to read data from RS232
1393 btfsc rs232_receive_overflow ; anything received? 1270 btfsc rs232_rx_timeout ; anything received?
1394 return ; NO - return 1271 return ; NO - return
1395 movlw "l" ; YES - load coding for screendump command 1272 movlw "l" ; YES - load coding for screen dump command
1396 cpfseq RCREG1 ; screendump command received? 1273 cpfseq RCREG1 ; screen dump command received?
1397 return ; NO - return 1274 return ; NO - return
1398 TFT_dump_screen: ; YES 1275
1399 bsf no_sensor_int 1276 TFT_dump_screen:
1400 movlw 'l' 1277 btfsc screen_type2 ; is this an OSTC with a screen of type 2?
1401 movwf TXREG ; send command echo 1278 return ; YES - not supported
1402 call rs232_wait_tx ; wait for UART 1279 bsf block_sensor_interrupt ; NO - disable sensor interrupts
1280 movlw 'l' ; - prepare response
1281 movwf TXREG ; - send response
1282 call rs232_wait_tx ; - wait for UART
1403 1283
1404 ;---- Send DISPLAY box command for the full screen window ------------------- 1284 ;---- Send DISPLAY box command for the full screen window -------------------
1405 Index_out 0x50 ; window horizontal start address 1285 Index_out 0x50 ; window horizontal start address
1406 Parameter_out 0x00, 0x00 ; 0-239 1286 Parameter_out 0x00, 0x00 ; 0-239
1407 Index_out 0x51 ; window horizontal end address 1287 Index_out 0x51 ; window horizontal end address
1422 Index_out 0x20 ; frame memory horizontal address 1302 Index_out 0x20 ; frame memory horizontal address
1423 movff ds_line,WREG ; d'0' ... d'239' 1303 movff ds_line,WREG ; d'0' ... d'239'
1424 mullw .1 ; copy row to PRODH:L 1304 mullw .1 ; copy row to PRODH:L
1425 rcall TFT_DataWrite_PROD 1305 rcall TFT_DataWrite_PROD
1426 1306
1427 movff ds_column,WREG ; Init X position 1307 movff ds_column,WREG ; initialize X position
1428 mullw 2 1308 mullw .2 ; ds_column x 2 -> PRODH:PRODL
1429 rcall pixel_write_col320 ; start address vertical (.0 - .319) 1309 rcall pixel_write_col320 ; start address vertical (.0 - .319)
1430 1310
1431 rcall TFT_DataRead_PROD ; read pixel 1311 rcall TFT_DataRead_PROD ; read pixel
1432 rcall dump_screen_pixel 1312 rcall dump_screen_pixel
1433 1313
1439 movlw .240 ; 240 lines, twice 1319 movlw .240 ; 240 lines, twice
1440 movwf ds_line 1320 movwf ds_line
1441 dump_screen_3: 1321 dump_screen_3:
1442 Index_out 0x20 ; frame memory horizontal address 1322 Index_out 0x20 ; frame memory horizontal address
1443 movff ds_line,WREG ; d'0' ... d'239' 1323 movff ds_line,WREG ; d'0' ... d'239'
1444 mullw 1 ; copy row to PRODH:L 1324 mullw .1 ; copy row to PRODH:L
1445 rcall TFT_DataWrite_PROD 1325 rcall TFT_DataWrite_PROD
1446 1326
1447 movff ds_column,WREG ; init X position 1327 movff ds_column,WREG ; initialize X position
1448 mullw 2 1328 mullw .2 ; ds_column x 2 -> PRODH:PRODL
1449 movlw .1 1329 INCI PROD ; PROD++
1450 addwf PRODL,F
1451 movlw 0
1452 addwfc PRODH,F ; +1
1453 rcall pixel_write_col320 ; start address vertical (.0 - .319) 1330 rcall pixel_write_col320 ; start address vertical (.0 - .319)
1454 1331
1455 rcall TFT_DataRead_PROD ; read pixel 1332 rcall TFT_DataRead_PROD ; read pixel
1456 rcall dump_screen_pixel 1333 rcall dump_screen_pixel
1457 1334
1462 incf ds_column,F 1339 incf ds_column,F
1463 movlw .160 1340 movlw .160
1464 cpfseq ds_column 1341 cpfseq ds_column
1465 bra dump_screen_1 1342 bra dump_screen_1
1466 1343
1467 bcf no_sensor_int 1344 bcf block_sensor_interrupt ; re-enable sensor interrupts
1468 clrf RCREG1 ; clear receive buffer 1345 clrf RCREG1 ; clear receive buffer
1469 bcf RCSTA1,CREN ; clear receiver status 1346 bcf RCSTA1,CREN ; clear receiver status
1470 bsf RCSTA1,CREN 1347 bsf RCSTA1,CREN
1471 bsf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (screen dump) 1348 bsf screen_dump_avail ; enable screen dump function
1472 return 1349 return
1473 1350
1474 ENDIF 1351 ;-----------------------------------------------------------------------------
1475
1476
1477 ;=============================================================================
1478 ; Pixel compression 1352 ; Pixel compression
1479 ; 1353 ;
1480 ; Input : PRODH:L = pixel 1354 ; Input : PRODH:L = pixel
1481 ; Output: Compressed stream on output. 1355 ; Output: Compressed stream on output.
1482 ; Compressed format: 1356 ; Compressed format:
1483 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128) 1357 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128)
1484 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1.. 64) 1358 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1.. 64)
1485 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1.. 64) 1359 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1.. 64)
1486 1360 ;
1487 IFDEF _screendump
1488
1489 dump_screen_pixel: 1361 dump_screen_pixel:
1490 movf PRODH,W ; compare pixel-high 1362 movf PRODH,W ; compare pixel-high
1491 xorwf ds_pixel+1,W 1363 xorwf ds_pixel+1,W
1492 bnz dump_screen_pixel_1 ; different -> dump 1364 bnz dump_screen_pixel_1 ; different -> dump
1493 1365
1538 movlw .128 ; max black pixel on a single byte 1410 movlw .128 ; max black pixel on a single byte
1539 cpfsgt ds_count ; skip if count > 128 1411 cpfsgt ds_count ; skip if count > 128
1540 movf ds_count,W ; W <- min(128,count) 1412 movf ds_count,W ; W <- min(128,count)
1541 subwf ds_count,F ; ds_count <- ds_count-W 1413 subwf ds_count,F ; ds_count <- ds_count-W
1542 decf WREG ; save as 0..127 1414 decf WREG ; save as 0..127
1415
1543 dump_screen_pix_3: 1416 dump_screen_pix_3:
1544 movwf TXREG 1417 movwf TXREG
1545 call rs232_wait_tx 1418 call rs232_wait_tx
1546 bra dump_screen_pixel_1 ; more to dump ? 1419 bra dump_screen_pixel_1 ; more to dump ?
1547 1420
1560 rcall dump_screen_pixel_1 ; send it 1433 rcall dump_screen_pixel_1 ; send it
1561 dump_screen_pixel_reset: 1434 dump_screen_pixel_reset:
1562 clrf ds_count ; clear count 1435 clrf ds_count ; clear count
1563 return 1436 return
1564 1437
1565 ENDIF 1438 ENDIF ; _screendump
1439
1440 ;=============================================================================
1566 1441
1567 END 1442 END