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 ;
|
|
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
|
|
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
|
|
100 Index_out 0x22 ; frame memory data write start
|
0
|
101
|
|
102 color_image_loop_xy:
|
623
|
103 ; prepare to read next pixel count and color
|
|
104 clrf pixel_count+0 ; clear number of pixels
|
|
105 clrf pixel_count+1 ; ...
|
0
|
106
|
623
|
107 color_image_read_byte:
|
634
|
108 tblrd*+ ; get next image data byte
|
623
|
109 btfss TABLAT,7 ; high bit cleared ?
|
634
|
110 bra color_image_decode_color; YES - this is color data
|
|
111 ;bra color_image_decode_count; NO - this is pixel count data
|
582
|
112
|
623
|
113 color_image_decode_count:
|
|
114 ; decode pixel repetition count
|
|
115 rlcf TABLAT,F ; drop high bit
|
|
116 movlw .7 ; move 7 bits
|
|
117 color_image_decode_count_loop:
|
634
|
118 rlcf TABLAT,F ; get upper bit into carry
|
|
119 rlcf pixel_count+0,F ; push bit into pixel count (16 bit operation)
|
|
120 rlcf pixel_count+1,F ; ...
|
|
121 decfsz WREG ; decrement loop counter, all bits done?
|
623
|
122 bra color_image_decode_count_loop ; NO - loop
|
|
123 bra color_image_read_byte ; YES - decode next byte
|
|
124
|
|
125 color_image_decode_color:
|
|
126 ; check for end-of-image tag (color index = 0x7F) -- it is assumed that no version 0 image contains 127 colors...
|
|
127 movlw 0x7f ; encoding for end-of-image
|
|
128 cpfslt TABLAT ; color index < end-of-image tag?
|
|
129 return ; NO - done
|
0
|
130
|
634
|
131 ; translate color index into pixel color
|
623
|
132 lfsr FSR2,buffer ; set FSR2 pointer to base address of color table
|
|
133 rlncf TABLAT,W ; get color index * 2 into WREG
|
|
134 movwf FSR2L ; adjust pointer to selected color
|
|
135 movff POSTINC2,PRODL ; read color, low byte
|
|
136 movff POSTINC2,PRODH ; read color, high byte
|
582
|
137
|
623
|
138 tstfsz encoding_format ; image encoded in version 0 format?
|
|
139 bra color_image_pixel ; NO
|
634
|
140
|
623
|
141 ; image encoding version 0 format: subtract pixel count from the overall number of pixels to do
|
|
142 movf pixel_count+0,W ; YES - 24 bit subtraction, low byte
|
|
143 subwf overall_pixels+0,F ; ...
|
|
144 movf pixel_count+1,W ; ... high byte
|
|
145 subwfb overall_pixels+1,F ; ...
|
|
146 movlw .0 ; ... upper byte
|
|
147 subwfb overall_pixels+2,F ; ...
|
0
|
148
|
623
|
149 color_image_pixel:
|
634
|
150 ; prepare sending the pixels to display
|
623
|
151 infsnz pixel_count+0 ; increment pixel repetition count by 1
|
|
152 incf pixel_count+1 ; ...
|
|
153 incf pixel_count+1 ; because decrement is done first, increment high byte once more
|
|
154 bsf tft_rs,0 ; RS_H data
|
634
|
155 bcf INTCON,GIE ; disable all interrupts
|
623
|
156
|
|
157 btfsc screen_type2 ; display type 2 ?
|
|
158 bra color_image_display2 ; YES
|
628
|
159 btfsc screen_type3 ; display type 3 ?
|
|
160 bra color_image_display3 ; YES
|
648
|
161
|
|
162 ; Screen 1
|
|
163 btfsc less_io_cpu ; less I/O CPU?
|
|
164 bra color_image_pixel1_loop_less_io ; YES
|
|
165
|
623
|
166 movff PRODH,PORTA ; NO - move color high byte to PORTA
|
|
167 movff PRODL,PORTH ; - move color low byte to PORTH
|
0
|
168
|
623
|
169 color_image_pixel1_loop:
|
|
170 bcf tft_nwr ; toggle write signal
|
|
171 bsf tft_nwr ; ...
|
|
172 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
173 bra color_image_pixel1_loop ; loop if not zero
|
|
174 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
175 bra color_image_pixel1_loop ; loop if not zero
|
|
176 bra color_image_pixel_com ; all pixels transmitted
|
|
177
|
648
|
178 color_image_pixel1_loop_less_io:
|
|
179 movff PRODH,PORTA ; NO - move color high byte to PORTA
|
|
180 bcf tft_nwr ; toggle write signal
|
|
181 bsf tft_nwr ; ...
|
|
182 movff PRODL,PORTA ; - move color low byte to PORTH
|
|
183 bcf tft_nwr ; toggle write signal
|
|
184 bsf tft_nwr ; ...
|
|
185 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
186 bra color_image_pixel1_loop_less_io ; loop if not zero
|
|
187 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
188 bra color_image_pixel1_loop_less_io ; loop if not zero
|
|
189 bra color_image_pixel_com ; all pixels transmitted
|
|
190
|
608
|
191 color_image_display2:
|
623
|
192 call convert_for_display2 ; convert 16 bit RGB b'RRRRRGGG GGGBBBBB'
|
|
193 ; into 24 bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00'
|
|
194 color_image_pixel2_loop:
|
|
195 movff win_color5,PORTH ; move upper byte to PORTH (DISPLAY is big endian)
|
|
196 bcf tft_nwr ; toggle write signal
|
|
197 bsf tft_nwr ; ...
|
|
198 movff win_color4,PORTH ; move high byte to PORTH
|
|
199 bcf tft_nwr ; toggle write signal
|
|
200 bsf tft_nwr ; ...
|
|
201 movff win_color3,PORTH ; move low byte to PORTH
|
|
202 bcf tft_nwr ; toggle write signal
|
|
203 bsf tft_nwr ; ...
|
|
204 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
205 bra color_image_pixel2_loop ; loop if not zero
|
|
206 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
207 bra color_image_pixel2_loop ; loop if not zero
|
628
|
208 bra color_image_pixel_com ; all pixels transmitted
|
|
209
|
|
210 color_image_display3:
|
|
211 movff PRODH,PORTH ; move color high byte to PORTH
|
|
212 bcf tft_nwr ; toggle write signal
|
|
213 bsf tft_nwr ; ...
|
|
214 movff PRODL,PORTH ; move color high byte to PORTH
|
|
215 bcf tft_nwr ; toggle write signal
|
|
216 bsf tft_nwr ; ...
|
|
217 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
218 bra color_image_display3 ; loop if not zero
|
|
219 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
220 bra color_image_display3 ; loop if not zero
|
|
221 ; bra color_image_pixel_com ; all pixels transmitted
|
604
|
222
|
623
|
223 color_image_pixel_com:
|
634
|
224 bsf INTCON,GIE ; re-enable all interrupts
|
623
|
225
|
|
226 tstfsz encoding_format ; image encoded in version 0 format?
|
|
227 bra color_image_loop_xy ; NO - loop to process next byte from image data
|
0
|
228
|
623
|
229 ; image encoding version 0 format: step counter
|
|
230 clrf WREG ; make a 24 bit decrement
|
|
231 decf overall_pixels+0 ; ...
|
|
232 subwfb overall_pixels+1,F ; ...
|
|
233 subwfb overall_pixels+2,F ; ...
|
|
234 bnn color_image_loop_xy ; all pixels done? NO - loop
|
|
235 return ; YES - done
|
0
|
236
|
604
|
237
|
634
|
238 ;-----------------------------------------------------------------------------
|
|
239 ; Helper Function - set up Pixel-Color Look-Up Table
|
|
240 ;
|
604
|
241 global get_colors
|
|
242 get_colors:
|
634
|
243 tblrd*+ ; read number of color indexes
|
|
244 movf TABLAT,W ; store in lo
|
623
|
245 tblrd*+ ; read image encoding format
|
|
246 movff TABLAT,encoding_format ; store encoding format
|
634
|
247 lfsr FSR2,buffer ; load base address of the look-up table
|
604
|
248 get_colors_loop:
|
623
|
249 tblrd*+ ; read color from stored image, low byte
|
|
250 btfss use_custom_colors ; shall use custom colors?
|
|
251 movff TABLAT,POSTINC2 ; NO - copy color read to buffer
|
|
252 tblrd*+ ; read color from stored image, high byte
|
|
253 btfss use_custom_colors ; shall use custom colors?
|
|
254 movff TABLAT,POSTINC2 ; NO - copy color read to buffer
|
|
255 decfsz WREG ; decrement loop counter, done?
|
|
256 bra get_colors_loop ; NO - loop
|
|
257 bcf use_custom_colors ; YES - clear custom colors request
|
|
258 return ; - done
|
604
|
259
|
634
|
260 ;-----------------------------------------------------------------------------
|
|
261
|
582
|
262 END
|