comparison src/tft.asm @ 604:ca4556fb60b9

bump to 2.99beta, work on 3.00 stable
author heinrichsweikamp
date Thu, 22 Nov 2018 19:47:26 +0100
parents b455b31ce022
children d866684249bd
comparison
equal deleted inserted replaced
603:00b24fb4324d 604:ca4556fb60b9
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File tft.asm ## V2.97 3 ; File tft.asm ## V2.99c
4 ; 4 ;
5 ; Managing the TFT screen 5 ; Managing the TFT screen
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
59 rcall TFT_CmdWrite 59 rcall TFT_CmdWrite
60 endm 60 endm
61 61
62 Parameter_out macro high_b, low_b 62 Parameter_out macro high_b, low_b
63 movlw high_b 63 movlw high_b
64 movwf PORTA ; Upper 64 movwf PORTA ; upper
65 movlw low_b 65 movlw low_b
66 rcall TFT_DataWrite 66 rcall TFT_DataWrite
67 endm 67 endm
68 68
69 69
70 basic CODE 70 tft CODE
71 71
72 ;;============================================================================= 72 ;;=============================================================================
73 ;; TFT_write_flash_image 73 ;; TFT_write_flash_image
74 ;; 74 ;;
75 ;; Inputs: FSR2 = EEPROM address / 256 75 ;; Inputs: FSR2 = EEPROM address / 256
90 ; ; Read header: width and height 90 ; ; Read header: width and height
91 ; global TFT_write_flash_image_addr 91 ; global TFT_write_flash_image_addr
92 ;TFT_write_flash_image_addr: 92 ;TFT_write_flash_image_addr:
93 ; call ext_flash_read_block_start 93 ; call ext_flash_read_block_start
94 ; movff SSP2BUF,win_width+0 94 ; movff SSP2BUF,win_width+0
95 ; movwf SSP2BUF ; Write to buffer to initiate new read 95 ; movwf SSP2BUF ; write to buffer to initiate new read
96 ; btfss SSP2STAT, BF ; Next byte ready ? 96 ; btfss SSP2STAT, BF ; next byte ready ?
97 ; bra $-2 ; NO: wait... 97 ; bra $-2 ; NO - wait...
98 ; movff SSP2BUF,win_width+1 98 ; movff SSP2BUF,win_width+1
99 ; movwf SSP2BUF ; Write to buffer to initiate new read 99 ; movwf SSP2BUF ; write to buffer to initiate new read
100 ; btfss SSP2STAT, BF ; Next byte ready ? 100 ; btfss SSP2STAT, BF ; next byte ready ?
101 ; bra $-2 ; NO: wait... 101 ; bra $-2 ; NO - wait...
102 ; movff SSP2BUF,win_height 102 ; movff SSP2BUF,win_height
103 ; movwf SSP2BUF ; Write to buffer to initiate new read 103 ; movwf SSP2BUF ; write to buffer to initiate new read
104 ; btfss SSP2STAT, BF ; Next byte ready ? 104 ; btfss SSP2STAT, BF ; next byte ready ?
105 ; bra $-2 ; NO: wait... 105 ; bra $-2 ; NO - wait...
106 ; movff SSP2BUF,WREG ; drop 4th byte. 106 ; movff SSP2BUF,WREG ; drop 4th byte
107 ; movwf SSP2BUF ; Write to buffer to initiate new read 107 ; movwf SSP2BUF ; write to buffer to initiate new read
108 ; btfss SSP2STAT, BF ; Next byte ready ? 108 ; btfss SSP2STAT, BF ; next byte ready ?
109 ; bra $-2 ; NO: wait... 109 ; bra $-2 ; NO - wait...
110 ; 110 ;
111 ; ; Sanity check on header to avoid badly uploaded images. 111 ; ; Sanity check on header to avoid badly uploaded images.
112 ; iorwf WREG ; Check height < 256 112 ; iorwf WREG ; check height < 256
113 ; bnz TFT_write_flash_image_failed 113 ; bnz TFT_write_flash_image_failed
114 ; movf win_width+1,W ; Check width < 512 114 ; movf win_width+1,W ; check width < 512
115 ; andlw 0xFE 115 ; andlw 0xFE
116 ; bnz TFT_write_flash_image_failed 116 ; bnz TFT_write_flash_image_failed
117 ; 117 ;
118 ; ; Center image on win_top, win_left values 118 ; ; Center image on win_top, win_left values
119 ; bcf STATUS,C ; Clear carry 119 ; bcf STATUS,C ; clear carry
120 ; rrcf win_height,W ; And get height/2 120 ; rrcf win_height,W ; and get height/2
121 ; subwf win_top,F ; top -= height/2 121 ; subwf win_top,F ; top -= height/2
122 ; rrcf win_width+1,W ; Get 9th bit into carry 122 ; rrcf win_width+1,W ; get 9th bit into carry
123 ; rrcf win_width+0,W ; Get width/2 (in 0..320 range) 123 ; rrcf win_width+0,W ; get width/2 (in 0..320 range)
124 ; bcf STATUS,C 124 ; bcf STATUS,C
125 ; rrcf WREG,W ; Get width/2 in 0..160 range 125 ; rrcf WREG,W ; get width/2 in 0..160 range
126 ; subwf win_leftx2,F ; left -= width/2 126 ; subwf win_leftx2,F ; left -= width/2
127 ; 127 ;
128 ; rcall TFT_box_write ; Inputs : win_top, win_leftx2, win_height, win_width(in 1..320 range) 128 ; rcall TFT_box_write ; inputs : win_top, win_leftx2, win_height, win_width (in 1..320 range)
129 ; 129 ;
130 ; ; Compute number of pixels to move (result on 17 bits !) 130 ; ; Compute number of pixels to move (result on 17 bits !)
131 ; clrf TBLPTRU 131 ; clrf TBLPTRU
132 ; movf win_width+0,W 132 ; movf win_width+0,W
133 ; mulwf win_height ; Result in PRODL:H 133 ; mulwf win_height ; result in PRODL:H
134 ; movf win_width+1,W 134 ; movf win_width+1,W
135 ; bz TFT_write_flash_image_1 ; width > 8bits ? 135 ; bz TFT_write_flash_image_1 ; width > 8bits ?
136 ; movf win_height,W ; YES: add extra 136 ; movf win_height,W ; YES - add extra
137 ; addwf PRODH,F 137 ; addwf PRODH,F
138 ; rlcf TBLPTRU ; And carry into upper register. 138 ; rlcf TBLPTRU ; and carry into upper register
139 ;TFT_write_flash_image_1: 139 ;TFT_write_flash_image_1:
140 ; incf PRODH,F ; pre-condition nested loops 140 ; incf PRODH,F ; pre-condition nested loops
141 ; incf TBLPTRU,F 141 ; incf TBLPTRU,F
142 ; 142 ;
143 ; ; Write pixels 143 ; ; Write pixels
144 ; Index_out 0x22 ; Frame Memory Data Write start 144 ; Index_out 0x22 ; frame memory data write start
145 ; RS_H ; Data 145 ; RS_H ; data
146 ; 146 ;
147 ;TFT_write_flash_image_loop: 147 ;TFT_write_flash_image_loop:
148 ; btfss SSP2STAT, BF ; Buffer full? 148 ; btfss SSP2STAT, BF ; buffer full?
149 ; bra $-2 ; NO: wait... 149 ; bra $-2 ; NO - wait...
150 ; movff SSP2BUF,PORTH ; Read lo 150 ; movff SSP2BUF,PORTH ; read lo
151 ; movwf SSP2BUF ; Write to buffer to initiate new read 151 ; movwf SSP2BUF ; write to buffer to initiate new read
152 ; 152 ;
153 ; btfss SSP2STAT, BF ; Buffer full? 153 ; btfss SSP2STAT, BF ; buffer full?
154 ; bra $-2 ; NO: wait... 154 ; bra $-2 ; NO - wait...
155 ; movff SSP2BUF,PORTA ; And read hi 155 ; movff SSP2BUF,PORTA ; and read hi
156 ; movwf SSP2BUF ; Write to buffer to initiate new read 156 ; movwf SSP2BUF ; write to buffer to initiate new read
157 ; WR_L 157 ; WR_L
158 ; WR_H ; Write 1 Pixel 158 ; WR_H ; write 1 pixel
159 ; 159 ;
160 ; decfsz PRODL,F 160 ; decfsz PRODL,F
161 ; bra TFT_write_flash_image_loop 161 ; bra TFT_write_flash_image_loop
162 ; decfsz PRODH,F 162 ; decfsz PRODH,F
163 ; bra TFT_write_flash_image_loop 163 ; bra TFT_write_flash_image_loop
164 ; decfsz TBLPTRU,F 164 ; decfsz TBLPTRU,F
165 ; bra TFT_write_flash_image_loop 165 ; bra TFT_write_flash_image_loop
166 ; 166 ;
167 ; btfss SSP2STAT, BF ; Buffer full? 167 ; btfss SSP2STAT, BF ; buffer full?
168 ; bra $-2 ; No, wait 168 ; bra $-2 ; NO - wait
169 ; movf SSP2BUF,W ; Read dummy byte 169 ; movf SSP2BUF,W ; read dummy byte
170 ; 170 ;
171 ; bsf flash_ncs ; CS=1 171 ; bsf flash_ncs ; CS=1
172 ; movlw 0x00 ; NOP, to stop window mode 172 ; movlw 0x00 ; NOP, to stop window mode
173 ; bra TFT_CmdWrite ; This routine "returns" 173 ; bra TFT_CmdWrite ; this routine "returns"
174 ; 174 ;
175 ; ;---- Draw a 4x4 red square in place of missing images... 175 ; ;---- Draw a 4x4 red square in place of missing images...
176 ;TFT_write_flash_image_failed: 176 ;TFT_write_flash_image_failed:
177 ; movlw -1 177 ; movlw -1
178 ; addwf win_leftx2,F 178 ; addwf win_leftx2,F
189 ; 189 ;
190 ;;============================================================================= 190 ;;=============================================================================
191 191
192 global TFT_CmdWrite 192 global TFT_CmdWrite
193 TFT_CmdWrite: 193 TFT_CmdWrite:
194 RS_L ; Command 194 RS_L ; command
195 clrf PORTA ; Upper 195 clrf PORTA ; upper
196 bcf INTCON,GIE 196 bcf INTCON,GIE
197 movwf PORTH ; Lower 197 movwf PORTH ; lower
198 WR_L 198 WR_L
199 WR_H ; Tick 199 WR_H ; tick
200 bsf INTCON,GIE 200 bsf INTCON,GIE
201 return 201 return
202 202
203 global TFT_DataWrite 203 global TFT_DataWrite
204 TFT_DataWrite: 204 TFT_DataWrite:
205 RS_H ; Data 205 RS_H ; data
206 bcf INTCON,GIE 206 bcf INTCON,GIE
207 movwf PORTH ; Lower 207 movwf PORTH ; lower
208 WR_L 208 WR_L
209 WR_H ; Tick 209 WR_H ; tick
210 bsf INTCON,GIE 210 bsf INTCON,GIE
211 return 211 return
212 212
213 ;============================================================================= 213 ;=============================================================================
214 214
215 global TFT_ClearScreen 215 global TFT_ClearScreen
216 TFT_ClearScreen: 216 TFT_ClearScreen:
217 Index_out 0x50 ; Window Horizontal Start Address 217 Index_out 0x50 ; window horizontal start address
218 Parameter_out 0x00, 0x00 ; 0-239 218 Parameter_out 0x00, 0x00 ; 0-239
219 Index_out 0x51 ; Window Horizontal End Address 219 Index_out 0x51 ; window horizontal end address
220 Parameter_out 0x00, 0xEF ; 0-239 220 Parameter_out 0x00, 0xEF ; 0-239
221 Index_out 0x52 ; Window Vertical Start Address 221 Index_out 0x52 ; window vertical start address
222 Parameter_out 0x00, 0x00 ; 0-319 222 Parameter_out 0x00, 0x00 ; 0-319
223 Index_out 0x53 ; Window Vertical End Address 223 Index_out 0x53 ; window vertical end address
224 Parameter_out 0x01, 0x3F ; 0-319 224 Parameter_out 0x01, 0x3F ; 0-319
225 Index_out 0x20 ; Frame Memory Horizontal Address 225 Index_out 0x20 ; frame memory horizontal address
226 Parameter_out 0x00, 0x00 ; 0-239 226 Parameter_out 0x00, 0x00 ; 0-239
227 Index_out 0x21 ; Frame Memory Vertical Address 227 Index_out 0x21 ; frame memory vertical address
228 Parameter_out 0x01, 0x3F ; 0-319 228 Parameter_out 0x01, 0x3F ; 0-319
229 229
230 Index_out 0x22 ; Frame Memory Data Write start 230 Index_out 0x22 ; frame memory data write start
231 231
232 RD_H ; Not Read 232 RD_H ; not read
233 RS_H ; Data 233 RS_H ; data
234 NCS_L ; Not CS 234 NCS_L ; not CS
235 clrf PORTH ; Data Lower 235 clrf PORTH ; data lower
236 236
237 movlw d'10' 237 movlw d'10'
238 movwf tft_temp3 238 movwf tft_temp3
239 TFT_ClearScreen2: 239 TFT_ClearScreen2:
240 movlw d'30' 240 movlw d'30'
241 movwf tft_temp2 241 movwf tft_temp2
242 TFT_ClearScreen3: 242 TFT_ClearScreen3:
243 clrf tft_temp1 ; 30*10*256=76800 Pixels -> Clear complete 240*320 243 clrf tft_temp1 ; 30*10*256=76800 pixels -> clear complete 240*320
244 bcf INTCON,GIE 244 bcf INTCON,GIE
245 TFT_ClearScreen4: 245 TFT_ClearScreen4:
246 WR_L 246 WR_L
247 WR_H ; Tick 247 WR_H ; tick
248 decfsz tft_temp1,F 248 decfsz tft_temp1,F
249 bra TFT_ClearScreen4 249 bra TFT_ClearScreen4
250 bsf INTCON,GIE 250 bsf INTCON,GIE
251 decfsz tft_temp2,F 251 decfsz tft_temp2,F
252 bra TFT_ClearScreen3 252 bra TFT_ClearScreen3
253 decfsz tft_temp3,F 253 decfsz tft_temp3,F
254 bra TFT_ClearScreen2 254 bra TFT_ClearScreen2
255 255
256 movlw 0x00 ; NOP, to stop window mode 256 movlw 0x00 ; NOP, to stop window mode
257 bra TFT_CmdWrite ; And return 257 bra TFT_CmdWrite ; and return
258 258
259 259
260 ;============================================================================= 260 ;=============================================================================
261 261
262 global TFT_DisplayOff 262 global TFT_DisplayOff
304 WAITMS d'5' 304 WAITMS d'5'
305 bcf tft_nreset 305 bcf tft_nreset
306 WAITMS d'5' 306 WAITMS d'5'
307 bsf tft_nreset 307 bsf tft_nreset
308 WAITMS d'150' 308 WAITMS d'150'
309 bsf lightsen_power ; Supply power to light sensor 309 bsf lightsen_power ; supply power to light sensor
310 310
311 ; Data Transfer Synchronization 311 ; Data Transfer Synchronization
312 Parameter_out 0x00, 0x00 312 Parameter_out 0x00, 0x00
313 Parameter_out 0x00, 0x00 313 Parameter_out 0x00, 0x00
314 314
317 movwf TBLPTRL 317 movwf TBLPTRL
318 movlw 0xF7 318 movlw 0xF7
319 movwf TBLPTRH 319 movwf TBLPTRH
320 movlw 0x01 320 movlw 0x01
321 movwf TBLPTRU 321 movwf TBLPTRU
322 TBLRD*+ ; Reads .110 for cR and USB OSTC3, .0 for BLE (2 and 3), and .2 for display1 OSTC 322 TBLRD*+ ; reads .110 for cR and USB OSTC3, .0 for BLE (2 and 3), and .2 for display1 OSTC
323 movlw 0x02 323 movlw 0x02
324 cpfseq TABLAT 324 cpfseq TABLAT
325 bra TFT_boot_0 ; Display0 325 bra TFT_boot_0 ; display0
326 326
327 TFT_boot_1: 327 TFT_boot_1:
328 ; Init through config table... 328 ; Init through config table...
329 movlw 0x74 329 movlw 0x74
330 movwf TBLPTRL 330 movwf TBLPTRL
348 TFT_boot_com: 348 TFT_boot_com:
349 rcall display0_init_loop 349 rcall display0_init_loop
350 350
351 Index_out 0x03 351 Index_out 0x03
352 btfsc flip_screen ; 180° rotation ? 352 btfsc flip_screen ; 180° rotation ?
353 bra TFT_boot2 ; Yes 353 bra TFT_boot2 ; YES
354 354
355 btfss screen_type ; display1? 355 btfss screen_type ; display1?
356 bra TFT_boot1a ; no 356 bra TFT_boot1a ; NO
357 Parameter_out 0x10, 0x00 ; display1 357 Parameter_out 0x10, 0x00 ; display1
358 bra TFT_boot3 358 bra TFT_boot3
359 TFT_boot1a: 359 TFT_boot1a:
360 Parameter_out 0x50, 0x20 ; display0 360 Parameter_out 0x50, 0x20 ; display0
361 bra TFT_boot3 361 bra TFT_boot3
362 TFT_boot2: 362 TFT_boot2:
363 btfss screen_type ; display1? 363 btfss screen_type ; display1?
364 bra TFT_boot2a ; no 364 bra TFT_boot2a ; NO
365 Parameter_out 0x10, 0x30 ; display1 365 Parameter_out 0x10, 0x30 ; display1
366 bra TFT_boot3 366 bra TFT_boot3
367 TFT_boot2a: 367 TFT_boot2a:
368 Parameter_out 0x50, 0x10 ; display0 368 Parameter_out 0x50, 0x10 ; display0
369 TFT_boot3: 369 TFT_boot3:
394 394
395 display0_init_loop: 395 display0_init_loop:
396 TBLRD*+ 396 TBLRD*+
397 movlw 0xFF 397 movlw 0xFF
398 cpfseq TABLAT 398 cpfseq TABLAT
399 bra display0_config_write ; Write Config pair to Display 399 bra display0_config_write ; write config pair to display
400 ; Delay ms or quit (return) 400 ; Delay ms or quit (return)
401 TBLRD*+ 401 TBLRD*+
402 tstfsz TABLAT ; End of config? 402 tstfsz TABLAT ; end of config?
403 bra $+4 ; No 403 bra $+4 ; NO
404 return ; Done. 404 return ; YES - done
405 movf TABLAT,W 405 movf TABLAT,W
406 call WAITMSX ; Wait WREG milliseconds 406 call WAITMSX ; wait WREG milliseconds
407 TBLRD*+ ; Dummy read (Third byte of delay command) 407 TBLRD*+ ; dummy read (Third byte of delay command)
408 bra display0_init_loop ; Loop 408 bra display0_init_loop ; loop
409 409
410 display0_config_write: ; With command in WREG 410 display0_config_write: ; with command in WREG
411 movf TABLAT,W 411 movf TABLAT,W
412 rcall TFT_CmdWrite ; Write command 412 rcall TFT_CmdWrite ; write command
413 TBLRD*+ ; Get config0 413 TBLRD*+ ; get config0
414 movff TABLAT,PORTA 414 movff TABLAT,PORTA
415 TBLRD*+ ; Get config1 415 TBLRD*+ ; get config1
416 movf TABLAT,W 416 movf TABLAT,W
417 rcall TFT_DataWrite ; Write config 417 rcall TFT_DataWrite ; write config
418 bra display0_init_loop ; Loop 418 bra display0_init_loop ; loop
419 419
420 420
421 ;============================================================================= 421 ;=============================================================================
422 ; Smooth lighting-up of the display: 422 ; Smooth lighting-up of the display:
423 ; 423 ;
424 ; Trashes: WREG, PRODL 424 ; Trashes: WREG, PRODL
425 ; Typical usage: 425 ; Typical usage:
426 ; clrf CCPR1L ; Backlight off 426 ; clrf CCPR1L ; backlight off
427 ; [draw splash screen] 427 ; [draw splash screen]
428 ; call TFT_DisplayFadeIn 428 ; call TFT_DisplayFadeIn
429 429
430 global TFT_Display_FadeIn 430 global TFT_Display_FadeIn
431 TFT_Display_FadeIn: 431 TFT_Display_FadeIn:
432 movlw CCP1CON_VALUE ; See hwos.inc 432 movlw CCP1CON_VALUE ; see hwos.inc
433 movwf CCP1CON 433 movwf CCP1CON
434 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor! 434 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor
435 clrf CCPR1L ; Backlight off - to be sure 435 clrf CCPR1L ; backlight off - to be sure
436 movff max_CCPR1L,PRODL 436 movff max_CCPR1L,PRODL
437 TFT_Display_FadeIn_0: 437 TFT_Display_FadeIn_0:
438 incf CCPR1L,F ; Duty cycle 438 incf CCPR1L,F ; duty cycle
439 WAITMS d'2' 439 WAITMS d'2'
440 decfsz PRODL,F 440 decfsz PRODL,F
441 bra TFT_Display_FadeIn_0 441 bra TFT_Display_FadeIn_0
442 bcf tft_is_dimming ; dimming done. 442 bcf tft_is_dimming ; dimming done
443 return 443 return
444 444
445 ;============================================================================= 445 ;=============================================================================
446 ; Smooth lighting-off of the display: 446 ; Smooth lighting-off of the display:
447 ; Trashes: WREG, PRODL 447 ; Trashes: WREG, PRODL
448 448
449 global TFT_Display_FadeOut 449 global TFT_Display_FadeOut
450 TFT_Display_FadeOut: 450 TFT_Display_FadeOut:
451 movff max_CCPR1L,PRODL 451 movff max_CCPR1L,PRODL
452 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor! 452 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor
453 TFT_Display_FadeOut_0: 453 TFT_Display_FadeOut_0:
454 movff PRODL,CCPR1L ; Duty cycle 454 movff PRODL,CCPR1L ; duty cycle
455 WAITMS d'1' 455 WAITMS d'1'
456 decfsz PRODL,F 456 decfsz PRODL,F
457 bra TFT_Display_FadeOut_0 457 bra TFT_Display_FadeOut_0
458 clrf CCPR1L 458 clrf CCPR1L
459 return 459 return
460 460
461 ;============================================================================= 461 ;=============================================================================
462 462
463 global box_std_block, box_black_block, box_color_block 463 global box_std_block, box_black_block, box_color_block
464 464
465 box_std_block: ; Use white color 465 box_std_block: ; use white color
466 setf WREG 466 setf WREG
467 bra box_common 467 bra box_common
468 box_black_block: ; Use black color 468 box_black_block: ; use black color
469 clrf WREG 469 clrf WREG
470 box_common: 470 box_common:
471 box_color_block: 471 box_color_block:
472 rcall TFT_set_color 472 rcall TFT_set_color
473 VARARGS_BEGIN 473 VARARGS_BEGIN
507 ; 507 ;
508 ; global init_pixel_write 508 ; global init_pixel_write
509 ;init_pixel_write: 509 ;init_pixel_write:
510 ; movf win_leftx2,W 510 ; movf win_leftx2,W
511 ; mullw 2 511 ; mullw 2
512 ; rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) 512 ; rcall pixel_write_col320 ; start address vertical (.0 - .319)
513 ; setf WREG 513 ; setf WREG
514 ; bra TFT_set_color 514 ; bra TFT_set_color
515 515
516 ;----------------------------------------------------------------------------- 516 ;-----------------------------------------------------------------------------
517 ; Writes two half-pixels at position (win_top,win_leftx2) 517 ; Writes two half-pixels at position (win_top,win_leftx2)
520 520
521 global pixel_write 521 global pixel_write
522 pixel_write: 522 pixel_write:
523 movf win_leftx2,W 523 movf win_leftx2,W
524 mullw 2 ; win_leftx2 x 2 -> PRODH:PRODL 524 mullw 2 ; win_leftx2 x 2 -> PRODH:PRODL
525 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) 525 rcall pixel_write_col320 ; start address vertical (.0 - .319)
526 rcall half_pixel_write ; Write this half-one. 526 rcall half_pixel_write ; write this half-one
527 movf win_leftx2,W ; Address of next one 527 movf win_leftx2,W ; address of next one
528 mullw 2 528 mullw 2
529 infsnz PRODL ; +1 529 infsnz PRODL ; +1
530 incf PRODH 530 incf PRODH
531 rcall pixel_write_col320 531 rcall pixel_write_col320
532 bra half_pixel_write ; Note: Cmd 0x20 is mandatory, because 532 bra half_pixel_write ; note: Cmd 0x20 is mandatory, because
533 ; of the auto-increment going vertical 533 ; of the auto-increment going vertical
534 534
535 global pixel_write_col320 535 global pixel_write_col320
536 pixel_write_col320: 536 pixel_write_col320:
537 btfsc screen_type ; display1? 537 btfsc screen_type ; display1?
538 bra pixel_write_col320_d1 ; Yes 538 bra pixel_write_col320_d1 ; YES
539 ; Display0 539 ; Display0
540 btfss flip_screen ; 180° rotation? 540 btfss flip_screen ; 180° rotation?
541 bra pixel_write_noflip_H ; No 541 bra pixel_write_noflip_H ; NO
542 bra pixel_write_flip_H ; Yes 542 bra pixel_write_flip_H ; YES
543 pixel_write_col320_d1: ; Display1 543 pixel_write_col320_d1: ; Display1
544 btfsc flip_screen ; 180° rotation? 544 btfsc flip_screen ; 180° rotation?
545 bra pixel_write_noflip_H ; Yes for d1 545 bra pixel_write_noflip_H ; YES for d1
546 pixel_write_flip_H: ; Flip d0 546 pixel_write_flip_H: ; flip d0
547 movf PRODL,W ; 16bits 319 - PROD --> PROD 547 movf PRODL,W ; 16 bits 319 - PROD --> PROD
548 sublw LOW(.319) ; 319-W --> W 548 sublw LOW(.319) ; 319-W --> W
549 movwf PRODL 549 movwf PRODL
550 movf PRODH,W 550 movf PRODH,W
551 btfss STATUS,C ; Borrow = /CARRY 551 btfss STATUS,C ; borrow = /CARRY
552 incf WREG 552 incf WREG
553 sublw HIGH(.319) 553 sublw HIGH(.319)
554 movwf PRODH 554 movwf PRODH
555 555
556 pixel_write_noflip_H: 556 pixel_write_noflip_H:
557 Index_out 0x21 ; Frame Memory Vertical Address 557 Index_out 0x21 ; frame memory vertical address
558 bra TFT_DataWrite_PROD ; and return... 558 bra TFT_DataWrite_PROD ; and return...
559 559
560 ;----------------------------------------------------------------------------- 560 ;-----------------------------------------------------------------------------
561 ; Writes one half-pixel at position (win_top,win_leftx2). 561 ; Writes one half-pixel at position (win_top,win_leftx2).
562 ; Inputs: win_leftx2, win_top, win_color:2 562 ; Inputs: win_leftx2, win_top, win_color:2
567 movf win_top,W ; d'0' ... d'239' 567 movf win_top,W ; d'0' ... d'239'
568 ; Variant with Y position in WREG. 568 ; Variant with Y position in WREG.
569 half_pixel_write_1: 569 half_pixel_write_1:
570 btfss flip_screen ; 180° rotation? 570 btfss flip_screen ; 180° rotation?
571 sublw .239 ; 239-Y --> Y 571 sublw .239 ; 239-Y --> Y
572 mullw .1 ; Copy row to PRODL (PRODH=0) 572 mullw .1 ; copy row to PRODL (PRODH=0)
573 Index_out 0x20 ; Frame Memory Horizontal Address 573 Index_out 0x20 ; frame memory horizontal address
574 rcall TFT_DataWrite_PROD 574 rcall TFT_DataWrite_PROD
575 575
576 Index_out 0x22 ; Frame Memory Data Write start 576 Index_out 0x22 ; frame memory data write start
577 RS_H ; Data 577 RS_H ; data
578 bcf INTCON,GIE 578 bcf INTCON,GIE
579 movff win_color1,PORTA ; Upper 579 movff win_color1,PORTA ; upper
580 movff win_color2,PORTH ; Lower 580 movff win_color2,PORTH ; lower
581 WR_L 581 WR_L
582 WR_H ; Tick 582 WR_H ; tick
583 bsf INTCON,GIE 583 bsf INTCON,GIE
584 return 584 return
585 585
586 ;----------------------------------------------------------------------------- 586 ;-----------------------------------------------------------------------------
587 ; Writes a vertical line of half-pixel at position (win_top,win_leftx2,win_height). 587 ; Writes a vertical line of half-pixel at position (win_top,win_leftx2,win_height).
588 ; Inputs: win_leftx2, win_top, win_height, win_color:2 588 ; Inputs: win_leftx2, win_top, win_height, win_color:2
589 ; Trashed: WREG, PROD, TABLAT, TBLPTRL 589 ; Trashed: WREG, PROD, TABLAT, TBLPTRL
590 590
591 global half_vertical_line 591 global half_vertical_line
592 half_vertical_line: 592 half_vertical_line:
593 clrf TABLAT ; Loop index. 593 clrf TABLAT ; loop index
594 594
595 half_vertical_line_loop: 595 half_vertical_line_loop:
596 movf win_leftx2,W ; Init X position. 596 movf win_leftx2,W ; init X position
597 mullw .2 597 mullw .2
598 movf TABLAT,W ; Get loop index 598 movf TABLAT,W ; get loop index
599 andlw .1 ; Just low bit 599 andlw .1 ; just low bit
600 xorwf PRODL,F ; And use it to jitter current X position 600 xorwf PRODL,F ; and use it to jitter current X position
601 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) 601 rcall pixel_write_col320 ; start address vertical (.0 - .319)
602 602
603 movf win_height,W ; Index reached height (Bank0 read) ? 603 movf win_height,W ; index reached height (bank0 read) ?
604 xorwf TABLAT,W 604 xorwf TABLAT,W
605 btfsc STATUS,Z ; Equals ? 605 btfsc STATUS,Z ; Equal ?
606 return ; Yes: done. 606 return ; YES - done
607 movf win_top,W ; Y = top + index (Bank0 read) 607 movf win_top,W ; Y = top + index (bank0 read)
608 addwf TABLAT,W 608 addwf TABLAT,W
609 rcall half_pixel_write_1 609 rcall half_pixel_write_1
610 incf TABLAT,F ; index++ 610 incf TABLAT,F ; index++
611 bra half_vertical_line_loop 611 bra half_vertical_line_loop
612 612
615 ; Inputs: win_leftx2, win_top, win_width, win_color:2 615 ; Inputs: win_leftx2, win_top, win_width, win_color:2
616 ; Trashed: WREG, PROD, TABLAT, TBLPTRL 616 ; Trashed: WREG, PROD, TABLAT, TBLPTRL
617 617
618 global half_horizontal_line 618 global half_horizontal_line
619 half_horizontal_line: 619 half_horizontal_line:
620 clrf TABLAT ; Loop index. 620 clrf TABLAT ; loop index
621 621
622 half_horizontal_line_loop: 622 half_horizontal_line_loop:
623 movf win_leftx2,W ; Init X position. 623 movf win_leftx2,W ; init X position
624 mullw .2 624 mullw .2
625 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) 625 rcall pixel_write_col320 ; start address vertical (.0 - .319)
626 movf win_width,W ; Index reached height (Bank0 read) ? 626 movf win_width,W ; index reached height (bank0 read) ?
627 xorwf TABLAT,W 627 xorwf TABLAT,W
628 btfsc STATUS,Z ; Equals ? 628 btfsc STATUS,Z ; equal ?
629 return ; Yes: done. 629 return ; YES - done
630 movf win_top,W ; Y = top + index (Bank0 read) 630 movf win_top,W ; Y = top + index (bank0 read)
631 addwf TABLAT,W 631 addwf TABLAT,W
632 rcall half_pixel_write_1 632 rcall half_pixel_write_1
633 incf TABLAT,F ; index++ 633 incf TABLAT,F ; index++
634 bra half_horizontal_line_loop 634 bra half_horizontal_line_loop
635 635
637 ;----------------------------------------------------------------------------- 637 ;-----------------------------------------------------------------------------
638 ; TFT Data Cmd via W 638 ; TFT Data Cmd via W
639 639
640 global TFT_DataWrite_PROD 640 global TFT_DataWrite_PROD
641 TFT_DataWrite_PROD: 641 TFT_DataWrite_PROD:
642 ; RD_H ; Keep high 642 ; RD_H ; keep high
643 RS_H ; Data 643 RS_H ; data
644 bcf INTCON,GIE 644 bcf INTCON,GIE
645 movff PRODH,PORTA ; Move high byte to PORTA 645 movff PRODH,PORTA ; move high byte to PORTA
646 movff PRODL,PORTH ; Move low byte to PORTH 646 movff PRODL,PORTH ; move low byte to PORTH
647 WR_L 647 WR_L
648 WR_H ; Tick 648 WR_H ; tick
649 bsf INTCON,GIE 649 bsf INTCON,GIE
650 return 650 return
651 651
652 TFT_DataRead_PROD: 652 TFT_DataRead_PROD:
653 Index_out 0x22 ; Frame Memory Data Read start 653 Index_out 0x22 ; frame memory data read start
654 TFT_CmdRead_PROD: 654 TFT_CmdRead_PROD:
655 setf TRISA ; PortA as input. 655 setf TRISA ; port A as input
656 setf TRISH ; PortH as input. 656 setf TRISH ; port H as input
657 RS_H ; Data 657 RS_H ; data
658 WR_H ; Not write 658 WR_H ; not write
659 RD_L ; Read! 659 RD_L ; read
660 nop 660 nop
661 nop 661 nop
662 nop 662 nop
663 RD_H ; Tick 663 RD_H ; tick
664 nop 664 nop
665 nop 665 nop
666 nop 666 nop
667 RD_L ; Read! 667 RD_L ; read
668 nop 668 nop
669 ;nop 669 ;nop
670 ;nop 670 ;nop
671 movff PORTA,PRODH 671 movff PORTA,PRODH
672 movff PORTH,PRODL 672 movff PORTH,PRODL
673 RD_H ; Tick 673 RD_H ; tick
674 nop 674 nop
675 clrf TRISA ; PortA as output 675 clrf TRISA ; port A as output
676 clrf TRISH ; PortH as output 676 clrf TRISH ; port H as output
677 return 677 return
678 678
679 ;============================================================================= 679 ;=============================================================================
680 ; Output TFT Window Address commands. 680 ; Output TFT Window Address commands
681 ; Inputs : win_top, win_leftx2, win_height, win_width. 681 ; Inputs : win_top, win_leftx2, win_height, win_width
682 ; Output : PortA/PortH commands. 682 ; Output : PortA/PortH commands
683 ; Trashed: PROD 683 ; Trashed: PROD
684 684
685 global TFT_box_write 685 global TFT_box_write
686 TFT_box_write: 686 TFT_box_write:
687 movf win_leftx2,W ; Compute left = 2*leftx2 --> PROD 687 movf win_leftx2,W ; compute left = 2 * leftx2 --> PROD
688 mullw 2 688 mullw 2
689 689
690 global TFT_box_write_16bit_win_left 690 global TFT_box_write_16bit_win_left
691 TFT_box_write_16bit_win_left: ; With column in PRODL:PRODH 691 TFT_box_write_16bit_win_left: ; Wwth column in PRODL:PRODH
692 btfsc screen_type ; display1? 692 btfsc screen_type ; display1?
693 bra TFT_box_write_16bit_win_left_d1 ; Yes 693 bra TFT_box_write_16bit_win_left_d1 ; YES
694 ; Display0 694 ; Display0
695 btfsc flip_screen ; 180° rotation? 695 btfsc flip_screen ; 180° rotation?
696 bra DISP_box_flip_H ; Yes 696 bra DISP_box_flip_H ; YES
697 bra TFT_box_write_16bit_win_left_com ; No 697 bra TFT_box_write_16bit_win_left_com ; NO
698 TFT_box_write_16bit_win_left_d1: ; Display1 698 TFT_box_write_16bit_win_left_d1: ; Display1
699 btfss flip_screen ; 180° rotation? 699 btfss flip_screen ; 180° rotation?
700 bra DISP_box_flip_H ; No for d1 700 bra DISP_box_flip_H ; NO for d1
701 ; Yes for d1 701 ; Yes for d1
702 TFT_box_write_16bit_win_left_com: 702 TFT_box_write_16bit_win_left_com:
703 ;---- Normal horizontal window --------------------------------------- 703 ;---- Normal horizontal window ---------------------------------------
704 Index_out 0x52 ; Window Vertical Start Address 704 Index_out 0x52 ; window vertical start address
705 rcall TFT_DataWrite_PROD ; Output left 705 rcall TFT_DataWrite_PROD ; output left
706 Index_out 0x21 ; Frame Memory Vertical Address 706 Index_out 0x21 ; frame memory vertical address
707 rcall TFT_DataWrite_PROD ; Output left 707 rcall TFT_DataWrite_PROD ; output left
708 708
709 movf win_width+0,W ; right = left + width - 1 709 movf win_width+0,W ; right = left + width - 1
710 addwf PRODL,F 710 addwf PRODL,F
711 movf win_width+1,W 711 movf win_width+1,W
712 addwfc PRODH,F 712 addwfc PRODH,F
713 decf PRODL,F ; decrement result 713 decf PRODL,F ; decrement result
714 btfss STATUS,C 714 btfss STATUS,C
715 decf PRODH,F 715 decf PRODH,F
716 716
717 Index_out 0x53 ; Window Vertical End Address 717 Index_out 0x53 ; window vertical end address
718 rcall TFT_DataWrite_PROD 718 rcall TFT_DataWrite_PROD
719 bra DISP_box_noflip_H 719 bra DISP_box_noflip_H
720 720
721 ;---- Flipped horizontal window -------------------------------------- 721 ;---- Flipped horizontal window --------------------------------------
722 DISP_box_flip_H: 722 DISP_box_flip_H:
723 movf PRODL,W ; 16bits 319 - PROD --> PROD 723 movf PRODL,W ; 16 bits 319 - PROD --> PROD
724 sublw LOW(.319) ; 319-W --> W 724 sublw LOW(.319) ; 319 - WREG --> WREG
725 movwf PRODL 725 movwf PRODL
726 movf PRODH,W 726 movf PRODH,W
727 btfss STATUS,C ; Borrow = /CARRY 727 btfss STATUS,C ; borrow = /CARRY
728 incf WREG 728 incf WREG
729 sublw HIGH(.319) 729 sublw HIGH(.319)
730 movwf PRODH 730 movwf PRODH
731 731
732 Index_out 0x53 ; Window Vertical Start Address 732 Index_out 0x53 ; window vertical start address
733 rcall TFT_DataWrite_PROD ; Output left 733 rcall TFT_DataWrite_PROD ; output left
734 Index_out 0x21 ; Frame Memory Vertical Address 734 Index_out 0x21 ; frame memory vertical address
735 rcall TFT_DataWrite_PROD ; Output left 735 rcall TFT_DataWrite_PROD ; output left
736 736
737 movf win_width+0,W ; 16bits PROD - width --> PROD 737 movf win_width+0,W ; 16 bits PROD - width --> PROD
738 subwf PRODL,F ; PRODL - WREG --> PRODL 738 subwf PRODL,F ; PRODL - WREG --> PRODL
739 movf win_width+1,W 739 movf win_width+1,W
740 subwfb PRODH,F 740 subwfb PRODH,F
741 infsnz PRODL ; PROD+1 --> PROD 741 infsnz PRODL ; PROD + 1 --> PROD
742 incf PRODH 742 incf PRODH
743 743
744 Index_out 0x52 ; Window Vertical End Address 744 Index_out 0x52 ; window vertical end address
745 rcall TFT_DataWrite_PROD 745 rcall TFT_DataWrite_PROD
746 746
747 DISP_box_noflip_H: 747 DISP_box_noflip_H:
748 btfss flip_screen ; 180° rotation ? 748 btfss flip_screen ; 180° rotation ?
749 bra TFT_box_noflip_V ; No. 749 bra TFT_box_noflip_V ; NO
750 750
751 ;---- Flipped vertical window ----------------------------------------- 751 ;---- Flipped vertical window -----------------------------------------
752 movff win_top,PRODH ; top --> PRODH (first byte) 752 movff win_top,PRODH ; top --> PRODH (first byte)
753 movf win_height,W 753 movf win_height,W
754 addwf PRODH,W 754 addwf PRODH,W
755 decf WREG 755 decf WREG
756 movwf PRODL ; top+height-1 --> PRODL (second byte) 756 movwf PRODL ; top + height - 1 --> PRODL (second byte)
757 757
758 Index_out 0x50 ; Window Horizontal Start Address 758 Index_out 0x50 ; window horizontal start address
759 movf PRODH,W 759 movf PRODH,W
760 rcall TFT_DataWrite ; Lower (and tick) 760 rcall TFT_DataWrite ; lower (and tick)
761 761
762 Index_out 0x51 ; Window Horizontal End Address 762 Index_out 0x51 ; window horizontal end address
763 movf PRODL,W 763 movf PRODL,W
764 rcall TFT_DataWrite ; Lower (and tick) 764 rcall TFT_DataWrite ; lower (and tick)
765 765
766 Index_out 0x20 ; Frame Memory Horizontal Address 766 Index_out 0x20 ; frame memory horizontal address
767 movf PRODH,W 767 movf PRODH,W
768 bra TFT_DataWrite ; Lower (and tick) and return 768 bra TFT_DataWrite ; lower (and tick) and return
769 769
770 TFT_box_noflip_V: 770 TFT_box_noflip_V:
771 ;---- Normal vertical window ---------------------------------------- 771 ;---- Normal vertical window ----------------------------------------
772 movff win_top,PRODL 772 movff win_top,PRODL
773 movf win_height,W 773 movf win_height,W
774 addwf PRODL,W 774 addwf PRODL,W
775 sublw .240 ; 240 - top - height 775 sublw .240 ; 240 - top - height
776 movwf PRODH ; First byte 776 movwf PRODH ; first byte
777 777
778 movf PRODL,W 778 movf PRODL,W
779 sublw .239 ; 239-top 779 sublw .239 ; 239 - top
780 movwf PRODL ; --> second byte. 780 movwf PRODL ; --> second byte
781 781
782 Index_out 0x50 ; Window Horizontal Start Address 782 Index_out 0x50 ; window horizontal start address
783 movf PRODH,W 783 movf PRODH,W
784 rcall TFT_DataWrite ; Lower (and tick) 784 rcall TFT_DataWrite ; lower (and tick)
785 785
786 Index_out 0x51 ; Window Horizontal End Address 786 Index_out 0x51 ; window horizontal end address
787 movf PRODL,W 787 movf PRODL,W
788 rcall TFT_DataWrite ; Lower (and tick) 788 rcall TFT_DataWrite ; lower (and tick)
789 789
790 Index_out 0x20 ; Frame Memory Horizontal Address 790 Index_out 0x20 ; frame memory horizontal address
791 movf PRODL,W 791 movf PRODL,W
792 bra TFT_DataWrite ; Lower (and tick) and return 792 bra TFT_DataWrite ; lower (and tick) and return
793 793
794 794
795 ;============================================================================= 795 ;=============================================================================
796 ; TFT_frame : draw a frame around current box with current color. 796 ; TFT_frame : draw a frame around current box with current color
797 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 797 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2
798 ; Outputs: (none) 798 ; Outputs: (none)
799 ; Trashed: WREG, PROD, aa_start:2, aa_end:2 799 ; Trashed: WREG, PROD, aa_start:2, aa_end:2
800 800
801 global TFT_frame 801 global TFT_frame
802 TFT_frame: 802 TFT_frame:
803 movff win_top,save_top ; Backup everything. 803 movff win_top,save_top ; backup everything
804 movff win_height,save_height 804 movff win_height,save_height
805 movff win_leftx2,save_left 805 movff win_leftx2,save_left
806 movff win_width,save_width 806 movff win_width,save_width
807 807
808 ;---- TOP line ----------------------------------------------------------- 808 ;---- TOP line -----------------------------------------------------------
809 movlw .1 ; row ~ height=1 809 movlw .1 ; row ~ height = 1
810 movwf win_height 810 movwf win_height
811 rcall TFT_box 811 rcall TFT_box
812 812
813 ;---- BOTTOM line -------------------------------------------------------- 813 ;---- BOTTOM line --------------------------------------------------------
814 movff save_top,PRODL ; Get back top, 814 movff save_top,PRODL ; get back top
815 movff save_height,WREG ; and height 815 movff save_height,WREG ; get back height
816 addwf PRODL,W ; top+height 816 addwf PRODL,W ; top + height
817 decf WREG ; top+height-1 817 decf WREG ; top + height - 1
818 movwf win_top ; top+height-1 --> top 818 movwf win_top ; top + height - 1 --> top
819 rcall TFT_box 819 rcall TFT_box
820 820
821 ;---- LEFT column -------------------------------------------------------- 821 ;---- LEFT column --------------------------------------------------------
822 movff save_top,win_top ; Restore top/height. 822 movff save_top,win_top ; restore top/height
823 movff save_height,win_height 823 movff save_height,win_height
824 movlw .1 ; column ~ width=1 824 movlw .1 ; column ~ width = 1
825 movwf win_width+0 825 movwf win_width+0
826 rcall TFT_box 826 rcall TFT_box
827 827
828 ;---- RIGHT column ------------------------------------------------------- 828 ;---- RIGHT column -------------------------------------------------------
829 movff save_left,WREG 829 movff save_left,WREG
837 movff save_left,win_leftx2 837 movff save_left,win_leftx2
838 movff save_width,win_width 838 movff save_width,win_width
839 return 839 return
840 840
841 ;============================================================================= 841 ;=============================================================================
842 ; TFT_box : fills current box with current color. 842 ; TFT_box: fills current box with current color
843 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 843 ; Inputs : win_top, win_leftx2, win_height, win_width, win_color1, win_color2
844 ; Outputs: (none) 844 ; Outputs: (none)
845 ; Trashed: WREG, PROD 845 ; Trashed: WREG, PROD
846 846
847 global TFT_box 847 global TFT_box
848 TFT_box: 848 TFT_box:
849 ;---- Define Window ------------------------------------------------------ 849 ;---- Define Window ------------------------------------------------------
850 bcf STATUS,C 850 bcf STATUS,C
851 rlcf win_width+0,F 851 rlcf win_width+0,F
852 rlcf win_width+1,F ; x2 852 rlcf win_width+1,F ; x2
853 rcall TFT_box_write ; Setup box 853 rcall TFT_box_write ; setup box
854 854
855 global TFT_box_16bit_win_left 855 global TFT_box_16bit_win_left
856 TFT_box_16bit_win_left: 856 TFT_box_16bit_win_left:
857 bcf STATUS,C 857 bcf STATUS,C
858 rrcf win_width+1,F ; width /= 2 858 rrcf win_width+1,F ; width /= 2
859 rrcf win_width+0,F 859 rrcf win_width+0,F
860 860
861 ;---- Fill Window -------------------------------------------------------- 861 ;---- Fill Window --------------------------------------------------------
862 Index_out 0x22 ; Frame Memory Data Write start 862 Index_out 0x22 ; frame memory data write start
863 863
864 clrf PRODH ; Column counter. 864 clrf PRODH ; column counter
865 RS_H ; Data 865 RS_H ; data
866 866
867 TFT_box2: ; Loop height times 867 TFT_box2: ; loop height times
868 movff win_height,PRODL 868 movff win_height,PRODL
869 869
870 TFT_box3: ; loop width times 870 TFT_box3: ; loop width times
871 bcf INTCON,GIE 871 bcf INTCON,GIE
872 movff win_color1,PORTA ; Upper 872 movff win_color1,PORTA ; upper
873 movff win_color2,PORTH ; Lower 873 movff win_color2,PORTH ; lower
874 WR_L 874 WR_L
875 WR_H ; Tick 875 WR_H ; tick
876 876
877 ; movff win_color1,PORTA ; Upper 877 ; movff win_color1,PORTA ; upper
878 ; movff win_color2,PORTH ; Lower 878 ; movff win_color2,PORTH ; lower
879 WR_L 879 WR_L
880 WR_H ; Tick 880 WR_H ; tick
881 bsf INTCON,GIE 881 bsf INTCON,GIE
882 decfsz PRODL,F ; row loop finished ? 882 decfsz PRODL,F ; row loop finished ?
883 bra TFT_box3 ; No: continue. 883 bra TFT_box3 ; NO - continue
884 884
885 incf PRODH,F ; column count ++ 885 incf PRODH,F ; column count ++
886 886
887 movf win_bargraph,W ; current column == bargraph ? 887 movf win_bargraph,W ; current column == bargraph ?
888 cpfseq PRODH 888 cpfseq PRODH
889 bra TFT_box4 ; No: just loop. 889 bra TFT_box4 ; NO - just loop
890 ; Yes: switch to black 890 clrf win_color1 ; Yes - switch to black
891 clrf win_color1 891 clrf win_color2 ; - ...
892 clrf win_color2
893 TFT_box4: 892 TFT_box4:
894 movf win_width+0,W ; compare ? 893 movf win_width+0,W ; compare ?
895 xorwf PRODH,W 894 xorwf PRODH,W
896 bnz TFT_box2 ; Loop not finished. 895 bnz TFT_box2 ; Loop not finished
897 896
898 movlw 0x00 ; NOP, to stop window mode 897 movlw 0x00 ; NOP, to stop window mode
899 rcall TFT_CmdWrite 898 rcall TFT_CmdWrite
900 899
901 ; Reset bargraph mode... 900 ; reset bargraph mode...
902 setf win_bargraph 901 setf win_bargraph
903 return 902 return
904 903
905 ;============================================================================= 904 ;=============================================================================
906 ;Converts 8Bit RGB b'RRRGGGBB' into 16Bit RGB b'RRRRRGGGGGGBBBBB' 905 ; Converts 8 bit RGB b'RRRGGGBB' into 16 bit RGB b'RRRRRGGGGGGBBBBB'
907 906
908 global TFT_set_color 907 global TFT_set_color
909 TFT_set_color: 908 TFT_set_color:
910 movwf tft_temp1 ; Get 8Bit RGB b'RRRGGGBB' 909 movwf tft_temp1 ; get 8 Bit RGB b'RRRGGGBB'
911 movwf tft_temp2 ; Copy 910 movwf tft_temp2 ; copy
912 911
913 ; Mask Bit 7,6,5,4,3,2 912 ; mask bit 7,6,5,4,3,2
914 movlw b'00000011' 913 movlw b'00000011'
915 andwf tft_temp2,F 914 andwf tft_temp2,F
916 915
917 movlw b'00000000' 916 movlw b'00000000'
918 dcfsnz tft_temp2,F 917 dcfsnz tft_temp2,F
919 movlw b'01010000' 918 movlw b'01010000'
920 dcfsnz tft_temp2,F 919 dcfsnz tft_temp2,F
921 movlw b'10100000' 920 movlw b'10100000'
922 dcfsnz tft_temp2,F 921 dcfsnz tft_temp2,F
923 movlw b'11111000' 922 movlw b'11111000'
924 movwf tft_temp3 ; Blue done. 923 movwf tft_temp3 ; blue done
925 924
926 movff tft_temp1,tft_temp2 ; Copy 925 movff tft_temp1,tft_temp2 ; copy
927 ; Mask Bit 7,6,5,1,0 926 ; mask bit 7,6,5,1,0
928 movlw b'00011100' 927 movlw b'00011100'
929 andwf tft_temp2,F 928 andwf tft_temp2,F
930 rrncf tft_temp2,F 929 rrncf tft_temp2,F
931 rrncf tft_temp2,F 930 rrncf tft_temp2,F
932 931
952 951
953 rrcf tft_temp4,F 952 rrcf tft_temp4,F
954 rrcf tft_temp3,F 953 rrcf tft_temp3,F
955 954
956 rrcf tft_temp4,F 955 rrcf tft_temp4,F
957 rrcf tft_temp3,W ; tft_temp3 (b'GGGBBBBB') done. 956 rrcf tft_temp3,W ; tft_temp3 (b'GGGBBBBB') done
958 movwf win_color2 ; Set Color registers... 957 movwf win_color2 ; set color registers...
959 958
960 movff tft_temp1,tft_temp2 ; Copy 959 movff tft_temp1,tft_temp2 ; copy
961 clrf tft_temp1 960 clrf tft_temp1
962 961
963 rrcf tft_temp4,F 962 rrcf tft_temp4,F
964 rrcf tft_temp1,F 963 rrcf tft_temp1,F
965 964
966 rrcf tft_temp4,F 965 rrcf tft_temp4,F
967 rrcf tft_temp1,F 966 rrcf tft_temp1,F
968 967
969 rrcf tft_temp4,F 968 rrcf tft_temp4,F
970 rrcf tft_temp1,F ; Green done. 969 rrcf tft_temp1,F ; green done
971 970
972 ; Mask Bit 4,3,2,1,0 971 ; mask bit 4,3,2,1,0
973 movlw b'11100000' 972 movlw b'11100000'
974 andwf tft_temp2,F 973 andwf tft_temp2,F
975 974
976 rrncf tft_temp2,F 975 rrncf tft_temp2,F
977 rrncf tft_temp2,F 976 rrncf tft_temp2,F
998 997
999 rrcf tft_temp4,F 998 rrcf tft_temp4,F
1000 rrcf tft_temp1,F 999 rrcf tft_temp1,F
1001 1000
1002 rrcf tft_temp4,F 1001 rrcf tft_temp4,F
1003 rrcf tft_temp1,F 1002 rrcf tft_temp1,F
1004 1003
1005 rrcf tft_temp4,F 1004 rrcf tft_temp4,F
1006 rrcf tft_temp1,F 1005 rrcf tft_temp1,F
1007 1006
1008 rrcf tft_temp4,F 1007 rrcf tft_temp4,F
1009 rrcf tft_temp1,F 1008 rrcf tft_temp1,F
1010 1009
1011 rrcf tft_temp4,F 1010 rrcf tft_temp4,F
1012 rrcf tft_temp1,W ; Red done. 1011 rrcf tft_temp1,W ; red done
1013 movwf win_color1 ; Set Color registers... 1012 movwf win_color1 ; set color registers
1014 return 1013 return
1015 1014
1016 ;============================================================================= 1015 ;=============================================================================
1017 ; Dump screen contents to the UART 1016 ; Dump screen contents to the UART
1018 1017
1018 IFDEF _screendump
1019
1020 global TFT_dump_screen_check
1019 global TFT_dump_screen 1021 global TFT_dump_screen
1020 TFT_dump_screen: 1022 TFT_dump_screen_check:
1023 btfss vusb_in ; USB (still) plugged in?
1024 bcf enable_screen_dumps ; NO - clear flag
1025 call rs232_get_byte ; try to read data from RS232
1026 btfsc rs232_receive_overflow ; anything received?
1027 return ; NO - return
1028 movlw "l" ; YES - load coding for screendump command
1029 cpfseq RCREG1 ; screendump command received?
1030 return ; NO - return
1031 TFT_dump_screen: ; YES
1021 bsf no_sensor_int 1032 bsf no_sensor_int
1022 movlw 'l' 1033 movlw 'l'
1023 movwf TXREG ; Send command echo. 1034 movwf TXREG ; send command echo
1024 call rs232_wait_tx ; wait for UART 1035 call rs232_wait_tx ; wait for UART
1036
1025 ;---- Send DISPLAY box command for the full screen window ------------------- 1037 ;---- Send DISPLAY box command for the full screen window -------------------
1026 Index_out 0x50 ; Window Horizontal Start Address 1038 Index_out 0x50 ; window horizontal start address
1027 Parameter_out 0x00, 0x00 ; 0-239 1039 Parameter_out 0x00, 0x00 ; 0-239
1028 Index_out 0x51 ; Window Horizontal End Address 1040 Index_out 0x51 ; window horizontal end address
1029 Parameter_out 0x00, 0xEF ; 0-239 1041 Parameter_out 0x00, 0xEF ; 0-239
1030 Index_out 0x52 ; Window Vertical Start Address 1042 Index_out 0x52 ; window vertical start address
1031 Parameter_out 0x00, 0x00 ; 0-319 1043 Parameter_out 0x00, 0x00 ; 0-319
1032 Index_out 0x53 ; Window Vertical End Address 1044 Index_out 0x53 ; window vertical end address
1033 Parameter_out 0x01, 0x3F ; 0-319 1045 Parameter_out 0x01, 0x3F ; 0-319
1034 1046
1035 clrf ds_column 1047 clrf ds_column
1036 rcall dump_screen_pixel_reset 1048 rcall dump_screen_pixel_reset
1037 dump_screen_1: 1049 dump_screen_1:
1038 btg LEDr ; LED activity toggle 1050 btg LEDr ; LED activity toggle
1039 ; Dump even column 1051 ; Dump even column
1040 movlw .240 ; 240 lines, once. 1052 movlw .240 ; 240 lines, once
1041 movwf ds_line 1053 movwf ds_line
1042 dump_screen_2: 1054 dump_screen_2:
1043 Index_out 0x20 ; Frame Memory Horizontal Address 1055 Index_out 0x20 ; frame memory horizontal address
1044 movff ds_line,WREG ; d'0' ... d'239' 1056 movff ds_line,WREG ; d'0' ... d'239'
1045 mullw .1 ; Copy row to PRODH:L 1057 mullw .1 ; copy row to PRODH:L
1046 rcall TFT_DataWrite_PROD 1058 rcall TFT_DataWrite_PROD
1047 1059
1048 movff ds_column,WREG ; Init X position. 1060 movff ds_column,WREG ; Init X position
1049 mullw 2 1061 mullw 2
1050 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) 1062 rcall pixel_write_col320 ; start address vertical (.0 - .319)
1051 1063
1052 rcall TFT_DataRead_PROD ; read pixel 1064 rcall TFT_DataRead_PROD ; read pixel
1053 rcall dump_screen_pixel 1065 rcall dump_screen_pixel
1054 1066
1055 decfsz ds_line,F 1067 decfsz ds_line,F
1056 bra dump_screen_2 1068 bra dump_screen_2
1057 rcall dump_screen_pixel_flush 1069 rcall dump_screen_pixel_flush
1058 1070
1059 ; Dump odd column 1071 ; Dump odd column
1060 movlw .240 ; 240 lines, twice. 1072 movlw .240 ; 240 lines, twice
1061 movwf ds_line 1073 movwf ds_line
1062 dump_screen_3: 1074 dump_screen_3:
1063 Index_out 0x20 ; Frame Memory Horizontal Address 1075 Index_out 0x20 ; frame memory horizontal address
1064 movff ds_line,WREG ; d'0' ... d'239' 1076 movff ds_line,WREG ; d'0' ... d'239'
1065 mullw 1 ; Copy row to PRODH:L 1077 mullw 1 ; copy row to PRODH:L
1066 rcall TFT_DataWrite_PROD 1078 rcall TFT_DataWrite_PROD
1067 1079
1068 movff ds_column,WREG ; Init X position. 1080 movff ds_column,WREG ; init X position
1069 mullw 2 1081 mullw 2
1070 movlw .1 1082 movlw .1
1071 addwf PRODL,F 1083 addwf PRODL,F
1072 movlw 0 1084 movlw 0
1073 addwfc PRODH,F ; +1 1085 addwfc PRODH,F ; +1
1074 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) 1086 rcall pixel_write_col320 ; start address vertical (.0 - .319)
1075 1087
1076 rcall TFT_DataRead_PROD ; read pixel 1088 rcall TFT_DataRead_PROD ; read pixel
1077 rcall dump_screen_pixel 1089 rcall dump_screen_pixel
1078 1090
1079 decfsz ds_line,F 1091 decfsz ds_line,F
1084 movlw .160 1096 movlw .160
1085 cpfseq ds_column 1097 cpfseq ds_column
1086 bra dump_screen_1 1098 bra dump_screen_1
1087 1099
1088 bcf no_sensor_int 1100 bcf no_sensor_int
1089 clrf RCREG1 ; Clear receive buffer 1101 clrf RCREG1 ; clear receive buffer
1090 bcf RCSTA1,CREN ; Clear receiver status 1102 bcf RCSTA1,CREN ; clear receiver status
1091 bsf RCSTA1,CREN 1103 bsf RCSTA1,CREN
1092 bsf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) 1104 bsf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (screen dump)
1093 return 1105 return
1106
1107 ENDIF
1094 1108
1095 1109
1096 ;============================================================================= 1110 ;=============================================================================
1097 ; Pixel compression 1111 ; Pixel compression
1098 ; 1112 ;
1099 ; Input: PRODH:L = pixel. 1113 ; Input : PRODH:L = pixel
1100 ; Output: Compressed stream on output. 1114 ; Output: Compressed stream on output.
1101 ; Compressed format: 1115 ; Compressed format:
1102 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128). 1116 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128)
1103 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1..64). 1117 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1.. 64)
1104 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1..64). 1118 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1.. 64)
1119
1120 IFDEF _screendump
1105 1121
1106 dump_screen_pixel: 1122 dump_screen_pixel:
1107 movf PRODH,W ; Compare pixel-high 1123 movf PRODH,W ; compare pixel-high
1108 xorwf ds_pixel+1,W 1124 xorwf ds_pixel+1,W
1109 bnz dump_screen_pixel_1 ; Different -> dump. 1125 bnz dump_screen_pixel_1 ; different -> dump
1110 1126
1111 movf PRODL,W ; Compare pixel-low 1127 movf PRODL,W ; compare pixel-low
1112 xorwf ds_pixel+0,W 1128 xorwf ds_pixel+0,W
1113 bnz dump_screen_pixel_1 ; Different -> dump. 1129 bnz dump_screen_pixel_1 ; different -> dump
1114 1130
1115 incf ds_count,F ; Same color: just increment. 1131 incf ds_count,F ; same color: just increment
1116 return 1132 return
1117 1133
1118 dump_screen_pixel_1: ; Send (pixel,count) tuple 1134 dump_screen_pixel_1: ; send (pixel,count) tuple
1119 movf ds_count,W ; Is count zero ? 1135 movf ds_count,W ; is count zero ?
1120 bz dump_screen_pixel_2 ; Yes: skip sending. 1136 bz dump_screen_pixel_2 ; YES - skip sending
1121 1137
1122 movf ds_pixel+1,W ; This is a BLACK pixel ? 1138 movf ds_pixel+1,W ; is this a BLACK pixel ?
1123 iorwf ds_pixel+0,W 1139 iorwf ds_pixel+0,W
1124 bz dump_screen_pix_black ; YES. 1140 bz dump_screen_pix_black ; YES
1125 1141
1126 movf ds_pixel+1,W ; This is a white pixel ? 1142 movf ds_pixel+1,W ; is this a white pixel ?
1127 andwf ds_pixel+0,W 1143 andwf ds_pixel+0,W
1128 incf WREG 1144 incf WREG
1129 bz dump_screen_pix_white ; YES. 1145 bz dump_screen_pix_white ; YES
1130 1146
1131 ; No: write the pixel itself... 1147 ; No: write the pixel itself...
1132 movlw .64 ; Max color pixel on a single byte. 1148 movlw .64 ; max color pixel on a single byte
1133 cpfsgt ds_count ; Skip if count > 64 1149 cpfsgt ds_count ; skip if count > 64
1134 movf ds_count,W ; W <- min(64,count) 1150 movf ds_count,W ; W <- min(64,count)
1135 subwf ds_count,F ; ds_count <- ds_count-W 1151 subwf ds_count,F ; ds_count <- ds_count-W
1136 decf WREG ; Save as 0..63 1152 decf WREG ; save as 0..63
1137 iorlw b'10000000' ; MARK as a color pixel. 1153 iorlw b'10000000' ; mark as a color pixel
1138 1154
1139 movwf TXREG 1155 movwf TXREG
1140 call rs232_wait_tx ; wait for UART 1156 call rs232_wait_tx ; wait for UART
1141 movff ds_pixel+1,TXREG 1157 movff ds_pixel+1,TXREG
1142 call rs232_wait_tx ; wait for UART 1158 call rs232_wait_tx ; wait for UART
1143 movff ds_pixel+0,TXREG 1159 movff ds_pixel+0,TXREG
1144 call rs232_wait_tx ; wait for UART 1160 call rs232_wait_tx ; wait for UART
1145 bra dump_screen_pixel_1 1161 bra dump_screen_pixel_1
1146 1162
1147 dump_screen_pixel_2: 1163 dump_screen_pixel_2:
1148 movff PRODH,ds_pixel+1 ; Save new pixel color 1164 movff PRODH,ds_pixel+1 ; save new pixel color
1149 movff PRODL,ds_pixel+0 1165 movff PRODL,ds_pixel+0
1150 movlw 1 1166 movlw 1
1151 movwf ds_count ; And set count=1. 1167 movwf ds_count ; and set count=1
1152 return 1168 return
1153 1169
1154 dump_screen_pix_black: 1170 dump_screen_pix_black:
1155 movlw .128 ; Max black pixel on a single byte. 1171 movlw .128 ; max black pixel on a single byte
1156 cpfsgt ds_count ; Skip if count > 128 1172 cpfsgt ds_count ; skip if count > 128
1157 movf ds_count,W ; W <- min(128,count) 1173 movf ds_count,W ; W <- min(128,count)
1158 subwf ds_count,F ; ds_count <- ds_count-W 1174 subwf ds_count,F ; ds_count <- ds_count-W
1159 decf WREG ; Save as 0..127 1175 decf WREG ; save as 0..127
1160 dump_screen_pix_3: 1176 dump_screen_pix_3:
1161 movwf TXREG 1177 movwf TXREG
1162 call rs232_wait_tx 1178 call rs232_wait_tx
1163 bra dump_screen_pixel_1 ; More to dump ? 1179 bra dump_screen_pixel_1 ; more to dump ?
1164 1180
1165 dump_screen_pix_white: 1181 dump_screen_pix_white:
1166 movlw .64 ; Max white pixel on a single byte. 1182 movlw .64 ; max white pixel on a single byte
1167 cpfsgt ds_count ; Skip if count > 64 1183 cpfsgt ds_count ; skip if count > 64
1168 movf ds_count,W ; W <- min(64,count) 1184 movf ds_count,W ; W <- min(64,count)
1169 subwf ds_count,F ; ds_count <- ds_count-W 1185 subwf ds_count,F ; ds_count <- ds_count-W
1170 decf WREG ; Save as 0..63 1186 decf WREG ; Save as 0..63
1171 iorlw b'11000000' ; MARK as a compressed white. 1187 iorlw b'11000000' ; mark as a compressed white
1172 bra dump_screen_pix_3 1188 bra dump_screen_pix_3
1173 1189
1174 dump_screen_pixel_flush: 1190 dump_screen_pixel_flush:
1175 clrf PRODH 1191 clrf PRODH
1176 clrf PRODL 1192 clrf PRODL
1177 rcall dump_screen_pixel_1 ; Send it 1193 rcall dump_screen_pixel_1 ; send it
1178 dump_screen_pixel_reset: 1194 dump_screen_pixel_reset:
1179 clrf ds_count ; But clear count. 1195 clrf ds_count ; clear count
1180 return 1196 return
1197
1198 ENDIF
1181 1199
1182 END 1200 END