0
|
1 ;=============================================================================
|
|
2 ;
|
634
|
3 ; File File color_processor.asm * combined next generation V3.09.4l
|
0
|
4 ;
|
623
|
5 ; Decompress and draw an image
|
0
|
6 ;
|
654
|
7 ; Copyright (c) 2011, JD Gascuel, heinrichs weikamp gmbh, all right reserved.
|
0
|
8 ;=============================================================================
|
|
9 ; HISTORY
|
|
10 ; 2010-12-13 : [jDG] Creation.
|
|
11 ; 2010-12-30 : [jDG] Revised to put temp into ACCESSRAM0
|
|
12 ;
|
623
|
13 ; RATIONALS: The OSTC has a nice color screen, and a std geek attitude impose
|
0
|
14 ; to show off ... ;-)
|
|
15 ;
|
623
|
16 ; Inputs TBLPTR points to the image description block.
|
|
17 ; win_top, win_leftx2 the Top/Leftx2 corner here to put the image.
|
|
18 ; Outputs None
|
|
19 ; Trashed TBLPTR, TABLAT, FSR2, PROD, win_width, win_height
|
0
|
20 ;
|
|
21 ; ImageBloc:
|
604
|
22 ; db widthx2, height
|
623
|
23 ; db nbColors, encoding version
|
0
|
24 ; dw color0, color1, color2, color3, ...
|
604
|
25 ; db packed pixels...
|
0
|
26 ;
|
|
27 ; Limitations:
|
623
|
28 ; * nbColors <= 126
|
|
29 ; * image width is even
|
|
30 ; * image left border is on even column, too
|
604
|
31 ;
|
623
|
32 ;
|
|
33 ; Compressed format in encoding version 0 and 1:
|
|
34 ; ----------------------------------------------
|
|
35 ; - 1-3 bytes pixel repetition count, followed by 1 byte pixel color
|
604
|
36 ; - bit 7 = 1: byte holds pixel count in bits 6-0
|
|
37 ; - bit 7 = 0: byte holds pixel color in bits 6-0
|
|
38 ; - all pixel count bytes accumulate:
|
|
39 ; - 1 byte pixel count: 1xxxxxxx -> 7 bit pixel count
|
|
40 ; - 2 bytes pixel count: 1yyyyyyy 1xxxxxxx -> 14 bit pixel count
|
|
41 ; - 3 bytes pixel count: 1zzzzzzz 1yyyyyyy 1xxxxxxx -> 21 bit pixel count
|
|
42 ;
|
623
|
43 ; A pixel repetition count of 0 means one single pixel will be drawn,
|
|
44 ; a repetition count of 1 means two pixels will be drawn, and so on.
|
|
45 ; The image is done when all pixels as of width x high parameters have been printed.
|
|
46 ;
|
|
47 ;
|
|
48 ; Compressed format in encoding version 1:
|
|
49 ; ----------------------------------------
|
|
50 ; As above, but the image is done when a color index equaling 127 is encountered.
|
|
51 ;
|
|
52 ;
|
604
|
53 ; Pixels are written column by column from left to right, with columns down first.
|
0
|
54 ;
|
|
55 ;-----------------------------------------------------------------------------
|
|
56
|
604
|
57 #include "hwos.inc"
|
|
58 #include "tft.inc"
|
|
59
|
623
|
60 extern convert_for_display2
|
|
61
|
634
|
62 ;=============================================================================
|
623
|
63 color_proc CODE
|
634
|
64 ;=============================================================================
|
0
|
65
|
|
66 ;-----------------------------------------------------------------------------
|
634
|
67 ; Print a colored Bitmap Image
|
|
68 ;
|
582
|
69 global color_image
|
0
|
70 color_image:
|
623
|
71 tblrd*+ ; read image width (in true width / 2)
|
634
|
72 movff TABLAT,win_width+0 ; store in win_width, low byte
|
|
73 clrf win_width+1 ; clear win_width, high byte
|
623
|
74 tblrd*+ ; read image height
|
634
|
75 movff TABLAT,win_height ; store in win_height
|
623
|
76 rcall get_colors ; read the colors
|
|
77 tstfsz encoding_format ; image encoded in version 0 format?
|
|
78 bra color_image_1 ; NO
|
582
|
79
|
634
|
80 ; image encoding version 0 format: compute overall number of pixels - 1
|
|
81 movf win_width,W ; get image width (/2) into WREG
|
|
82 mulwf win_height ; multiply with image hight
|
623
|
83 movff PRODL,overall_pixels+0 ; store product, low byte
|
|
84 movff PRODH,overall_pixels+1 ; ... high byte
|
634
|
85 clrf overall_pixels+2 ; clear product, upper byte
|
623
|
86 bcf STATUS,C ; clear carry flag
|
|
87 rlcf overall_pixels+0 ; multiply by 2 via shift left, low byte
|
|
88 rlcf overall_pixels+1 ; ... high byte
|
|
89 rlcf overall_pixels+2 ; ... upper byte
|
|
90 clrf WREG ; decrement by 1 to ease all pixel done detection
|
|
91 decf overall_pixels+0,F ; ...
|
|
92 subwfb overall_pixels+1,F ; ...
|
|
93 subwfb overall_pixels+2,F ; ...
|
0
|
94
|
623
|
95 color_image_1:
|
|
96 bcf STATUS,C ; clear carry flag
|
|
97 rlcf win_width+0 ; multiply width x 2 to get the true box width
|
|
98 rlcf win_width+1 ; ...
|
|
99 call TFT_box_write ; set output box
|
654
|
100 movlw 0x22 ; frame memory data write start
|
|
101 btfsc screen_type4
|
|
102 movlw 0x2C ; Start Writing Data to GRAM (Display 4)
|
|
103 call TFT_CmdWrite
|
0
|
104 color_image_loop_xy:
|
623
|
105 ; prepare to read next pixel count and color
|
|
106 clrf pixel_count+0 ; clear number of pixels
|
|
107 clrf pixel_count+1 ; ...
|
0
|
108
|
623
|
109 color_image_read_byte:
|
634
|
110 tblrd*+ ; get next image data byte
|
623
|
111 btfss TABLAT,7 ; high bit cleared ?
|
634
|
112 bra color_image_decode_color; YES - this is color data
|
|
113 ;bra color_image_decode_count; NO - this is pixel count data
|
582
|
114
|
623
|
115 color_image_decode_count:
|
|
116 ; decode pixel repetition count
|
|
117 rlcf TABLAT,F ; drop high bit
|
|
118 movlw .7 ; move 7 bits
|
|
119 color_image_decode_count_loop:
|
634
|
120 rlcf TABLAT,F ; get upper bit into carry
|
|
121 rlcf pixel_count+0,F ; push bit into pixel count (16 bit operation)
|
|
122 rlcf pixel_count+1,F ; ...
|
|
123 decfsz WREG ; decrement loop counter, all bits done?
|
623
|
124 bra color_image_decode_count_loop ; NO - loop
|
|
125 bra color_image_read_byte ; YES - decode next byte
|
|
126
|
|
127 color_image_decode_color:
|
|
128 ; check for end-of-image tag (color index = 0x7F) -- it is assumed that no version 0 image contains 127 colors...
|
|
129 movlw 0x7f ; encoding for end-of-image
|
|
130 cpfslt TABLAT ; color index < end-of-image tag?
|
|
131 return ; NO - done
|
0
|
132
|
634
|
133 ; translate color index into pixel color
|
623
|
134 lfsr FSR2,buffer ; set FSR2 pointer to base address of color table
|
|
135 rlncf TABLAT,W ; get color index * 2 into WREG
|
|
136 movwf FSR2L ; adjust pointer to selected color
|
|
137 movff POSTINC2,PRODL ; read color, low byte
|
|
138 movff POSTINC2,PRODH ; read color, high byte
|
582
|
139
|
623
|
140 tstfsz encoding_format ; image encoded in version 0 format?
|
|
141 bra color_image_pixel ; NO
|
634
|
142
|
623
|
143 ; image encoding version 0 format: subtract pixel count from the overall number of pixels to do
|
|
144 movf pixel_count+0,W ; YES - 24 bit subtraction, low byte
|
|
145 subwf overall_pixels+0,F ; ...
|
|
146 movf pixel_count+1,W ; ... high byte
|
|
147 subwfb overall_pixels+1,F ; ...
|
|
148 movlw .0 ; ... upper byte
|
|
149 subwfb overall_pixels+2,F ; ...
|
0
|
150
|
623
|
151 color_image_pixel:
|
634
|
152 ; prepare sending the pixels to display
|
623
|
153 infsnz pixel_count+0 ; increment pixel repetition count by 1
|
|
154 incf pixel_count+1 ; ...
|
|
155 incf pixel_count+1 ; because decrement is done first, increment high byte once more
|
|
156 bsf tft_rs,0 ; RS_H data
|
634
|
157 bcf INTCON,GIE ; disable all interrupts
|
623
|
158
|
|
159 btfsc screen_type2 ; display type 2 ?
|
|
160 bra color_image_display2 ; YES
|
628
|
161 btfsc screen_type3 ; display type 3 ?
|
|
162 bra color_image_display3 ; YES
|
648
|
163
|
654
|
164 ; Screen 0 or 1 or 4
|
648
|
165 btfsc less_io_cpu ; less I/O CPU?
|
|
166 bra color_image_pixel1_loop_less_io ; YES
|
|
167
|
623
|
168 movff PRODH,PORTA ; NO - move color high byte to PORTA
|
|
169 movff PRODL,PORTH ; - move color low byte to PORTH
|
0
|
170
|
623
|
171 color_image_pixel1_loop:
|
|
172 bcf tft_nwr ; toggle write signal
|
|
173 bsf tft_nwr ; ...
|
|
174 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
175 bra color_image_pixel1_loop ; loop if not zero
|
|
176 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
177 bra color_image_pixel1_loop ; loop if not zero
|
|
178 bra color_image_pixel_com ; all pixels transmitted
|
|
179
|
648
|
180 color_image_pixel1_loop_less_io:
|
|
181 movff PRODH,PORTA ; NO - move color high byte to PORTA
|
|
182 bcf tft_nwr ; toggle write signal
|
|
183 bsf tft_nwr ; ...
|
|
184 movff PRODL,PORTA ; - move color low byte to PORTH
|
|
185 bcf tft_nwr ; toggle write signal
|
|
186 bsf tft_nwr ; ...
|
|
187 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
188 bra color_image_pixel1_loop_less_io ; loop if not zero
|
|
189 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
190 bra color_image_pixel1_loop_less_io ; loop if not zero
|
|
191 bra color_image_pixel_com ; all pixels transmitted
|
|
192
|
608
|
193 color_image_display2:
|
623
|
194 call convert_for_display2 ; convert 16 bit RGB b'RRRRRGGG GGGBBBBB'
|
|
195 ; into 24 bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00'
|
|
196 color_image_pixel2_loop:
|
|
197 movff win_color5,PORTH ; move upper byte to PORTH (DISPLAY is big endian)
|
|
198 bcf tft_nwr ; toggle write signal
|
|
199 bsf tft_nwr ; ...
|
|
200 movff win_color4,PORTH ; move high byte to PORTH
|
|
201 bcf tft_nwr ; toggle write signal
|
|
202 bsf tft_nwr ; ...
|
|
203 movff win_color3,PORTH ; move low byte to PORTH
|
|
204 bcf tft_nwr ; toggle write signal
|
|
205 bsf tft_nwr ; ...
|
|
206 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
207 bra color_image_pixel2_loop ; loop if not zero
|
|
208 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
209 bra color_image_pixel2_loop ; loop if not zero
|
628
|
210 bra color_image_pixel_com ; all pixels transmitted
|
|
211
|
|
212 color_image_display3:
|
|
213 movff PRODH,PORTH ; move color high byte to PORTH
|
|
214 bcf tft_nwr ; toggle write signal
|
|
215 bsf tft_nwr ; ...
|
|
216 movff PRODL,PORTH ; move color high byte to PORTH
|
|
217 bcf tft_nwr ; toggle write signal
|
|
218 bsf tft_nwr ; ...
|
|
219 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
220 bra color_image_display3 ; loop if not zero
|
|
221 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
222 bra color_image_display3 ; loop if not zero
|
|
223 ; bra color_image_pixel_com ; all pixels transmitted
|
604
|
224
|
623
|
225 color_image_pixel_com:
|
634
|
226 bsf INTCON,GIE ; re-enable all interrupts
|
623
|
227
|
|
228 tstfsz encoding_format ; image encoded in version 0 format?
|
|
229 bra color_image_loop_xy ; NO - loop to process next byte from image data
|
0
|
230
|
623
|
231 ; image encoding version 0 format: step counter
|
|
232 clrf WREG ; make a 24 bit decrement
|
|
233 decf overall_pixels+0 ; ...
|
|
234 subwfb overall_pixels+1,F ; ...
|
|
235 subwfb overall_pixels+2,F ; ...
|
|
236 bnn color_image_loop_xy ; all pixels done? NO - loop
|
|
237 return ; YES - done
|
0
|
238
|
604
|
239
|
634
|
240 ;-----------------------------------------------------------------------------
|
|
241 ; Helper Function - set up Pixel-Color Look-Up Table
|
|
242 ;
|
604
|
243 global get_colors
|
|
244 get_colors:
|
634
|
245 tblrd*+ ; read number of color indexes
|
|
246 movf TABLAT,W ; store in lo
|
623
|
247 tblrd*+ ; read image encoding format
|
|
248 movff TABLAT,encoding_format ; store encoding format
|
634
|
249 lfsr FSR2,buffer ; load base address of the look-up table
|
604
|
250 get_colors_loop:
|
623
|
251 tblrd*+ ; read color from stored image, low byte
|
|
252 btfss use_custom_colors ; shall use custom colors?
|
|
253 movff TABLAT,POSTINC2 ; NO - copy color read to buffer
|
|
254 tblrd*+ ; read color from stored image, high byte
|
|
255 btfss use_custom_colors ; shall use custom colors?
|
|
256 movff TABLAT,POSTINC2 ; NO - copy color read to buffer
|
|
257 decfsz WREG ; decrement loop counter, done?
|
|
258 bra get_colors_loop ; NO - loop
|
|
259 bcf use_custom_colors ; YES - clear custom colors request
|
|
260 return ; - done
|
604
|
261
|
634
|
262 ;-----------------------------------------------------------------------------
|
|
263
|
582
|
264 END
|