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
|
|
161
|
623
|
162 movff PRODH,PORTA ; NO - move color high byte to PORTA
|
|
163 movff PRODL,PORTH ; - move color low byte to PORTH
|
0
|
164
|
623
|
165 color_image_pixel1_loop:
|
|
166 bcf tft_nwr ; toggle write signal
|
|
167 bsf tft_nwr ; ...
|
|
168 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
169 bra color_image_pixel1_loop ; loop if not zero
|
|
170 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
171 bra color_image_pixel1_loop ; loop if not zero
|
|
172 bra color_image_pixel_com ; all pixels transmitted
|
|
173
|
608
|
174 color_image_display2:
|
623
|
175 call convert_for_display2 ; convert 16 bit RGB b'RRRRRGGG GGGBBBBB'
|
|
176 ; into 24 bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00'
|
|
177 color_image_pixel2_loop:
|
|
178 movff win_color5,PORTH ; move upper byte to PORTH (DISPLAY is big endian)
|
|
179 bcf tft_nwr ; toggle write signal
|
|
180 bsf tft_nwr ; ...
|
|
181 movff win_color4,PORTH ; move high byte to PORTH
|
|
182 bcf tft_nwr ; toggle write signal
|
|
183 bsf tft_nwr ; ...
|
|
184 movff win_color3,PORTH ; move 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_pixel2_loop ; loop if not zero
|
|
189 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
190 bra color_image_pixel2_loop ; loop if not zero
|
628
|
191 bra color_image_pixel_com ; all pixels transmitted
|
|
192
|
|
193 color_image_display3:
|
|
194 movff PRODH,PORTH ; move color high byte to PORTH
|
|
195 bcf tft_nwr ; toggle write signal
|
|
196 bsf tft_nwr ; ...
|
|
197 movff PRODL,PORTH ; move color high byte to PORTH
|
|
198 bcf tft_nwr ; toggle write signal
|
|
199 bsf tft_nwr ; ...
|
|
200 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
201 bra color_image_display3 ; loop if not zero
|
|
202 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
203 bra color_image_display3 ; loop if not zero
|
|
204 ; bra color_image_pixel_com ; all pixels transmitted
|
604
|
205
|
623
|
206 color_image_pixel_com:
|
634
|
207 bsf INTCON,GIE ; re-enable all interrupts
|
623
|
208
|
|
209 tstfsz encoding_format ; image encoded in version 0 format?
|
|
210 bra color_image_loop_xy ; NO - loop to process next byte from image data
|
0
|
211
|
623
|
212 ; image encoding version 0 format: step counter
|
|
213 clrf WREG ; make a 24 bit decrement
|
|
214 decf overall_pixels+0 ; ...
|
|
215 subwfb overall_pixels+1,F ; ...
|
|
216 subwfb overall_pixels+2,F ; ...
|
|
217 bnn color_image_loop_xy ; all pixels done? NO - loop
|
|
218 return ; YES - done
|
0
|
219
|
604
|
220
|
634
|
221 ;-----------------------------------------------------------------------------
|
|
222 ; Helper Function - set up Pixel-Color Look-Up Table
|
|
223 ;
|
604
|
224 global get_colors
|
|
225 get_colors:
|
634
|
226 tblrd*+ ; read number of color indexes
|
|
227 movf TABLAT,W ; store in lo
|
623
|
228 tblrd*+ ; read image encoding format
|
|
229 movff TABLAT,encoding_format ; store encoding format
|
634
|
230 lfsr FSR2,buffer ; load base address of the look-up table
|
604
|
231 get_colors_loop:
|
623
|
232 tblrd*+ ; read color from stored image, low byte
|
|
233 btfss use_custom_colors ; shall use custom colors?
|
|
234 movff TABLAT,POSTINC2 ; NO - copy color read to buffer
|
|
235 tblrd*+ ; read color from stored image, high byte
|
|
236 btfss use_custom_colors ; shall use custom colors?
|
|
237 movff TABLAT,POSTINC2 ; NO - copy color read to buffer
|
|
238 decfsz WREG ; decrement loop counter, done?
|
|
239 bra get_colors_loop ; NO - loop
|
|
240 bcf use_custom_colors ; YES - clear custom colors request
|
|
241 return ; - done
|
604
|
242
|
634
|
243 ;-----------------------------------------------------------------------------
|
|
244
|
582
|
245 END
|