0
|
1 ;=============================================================================
|
|
2 ;
|
623
|
3 ; File File color_processor.asm combined next generation V3.03.2
|
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
|
|
62
|
|
63 color_proc CODE
|
0
|
64
|
|
65 ;-----------------------------------------------------------------------------
|
604
|
66
|
582
|
67 global color_image
|
0
|
68 color_image:
|
623
|
69 tblrd*+ ; read image width (in true width / 2)
|
|
70 movff TABLAT,win_width
|
|
71 tblrd*+ ; read image height
|
|
72 movff TABLAT,win_height
|
|
73 rcall get_colors ; read the colors
|
0
|
74
|
623
|
75 tstfsz encoding_format ; image encoded in version 0 format?
|
|
76 bra color_image_1 ; NO
|
582
|
77
|
623
|
78 ; image encoding version 0 format: compute the overall number of pixels - 1 to draw
|
|
79 movf win_width,W ; get width into WREG
|
|
80 mulwf win_height ; multiply by hight
|
|
81 movff PRODL,overall_pixels+0 ; store product, low byte
|
|
82 movff PRODH,overall_pixels+1 ; ... high byte
|
|
83 clrf overall_pixels+2 ; clear upper byte
|
|
84 bcf STATUS,C ; clear carry flag
|
|
85 rlcf overall_pixels+0 ; multiply by 2 via shift left, low byte
|
|
86 rlcf overall_pixels+1 ; ... high byte
|
|
87 rlcf overall_pixels+2 ; ... upper byte
|
|
88 clrf WREG ; decrement by 1 to ease all pixel done detection
|
|
89 decf overall_pixels+0,F ; ...
|
|
90 subwfb overall_pixels+1,F ; ...
|
|
91 subwfb overall_pixels+2,F ; ...
|
0
|
92
|
623
|
93 color_image_1:
|
|
94 clrf win_width+1 ; clear width, high byte
|
|
95 bcf STATUS,C ; clear carry flag
|
|
96 rlcf win_width+0 ; multiply width x 2 to get the true box width
|
|
97 rlcf win_width+1 ; ...
|
|
98 call TFT_box_write ; set output box
|
|
99 Index_out 0x22 ; frame memory data write start
|
0
|
100
|
|
101 color_image_loop_xy:
|
623
|
102 ; prepare to read next pixel count and color
|
|
103 clrf pixel_count+0 ; clear number of pixels
|
|
104 clrf pixel_count+1 ; ...
|
0
|
105
|
623
|
106 color_image_read_byte:
|
|
107 tblrd*+ ; get next byte
|
|
108 btfss TABLAT,7 ; high bit cleared ?
|
|
109 bra color_image_decode_color; YES - this is a color byte
|
|
110 ;bra color_image_decode_count; NO - this is a pixel count byte
|
582
|
111
|
623
|
112 color_image_decode_count:
|
|
113 ; decode pixel repetition count
|
|
114 rlcf TABLAT,F ; drop high bit
|
|
115 movlw .7 ; move 7 bits
|
|
116 color_image_decode_count_loop:
|
|
117 rlcf TABLAT,F ; get upper bit into carry
|
|
118 rlcf pixel_count+0,F ; push bit into pixel count (16 bit operation)
|
|
119 rlcf pixel_count+1,F ; ...
|
|
120 decfsz WREG ; decrement loop counter, all bits done?
|
|
121 bra color_image_decode_count_loop ; NO - loop
|
|
122 bra color_image_read_byte ; YES - decode next byte
|
|
123
|
|
124 color_image_decode_color:
|
|
125 ; check for end-of-image tag (color index = 0x7F) -- it is assumed that no version 0 image contains 127 colors...
|
|
126 movlw 0x7f ; encoding for end-of-image
|
|
127 cpfslt TABLAT ; color index < end-of-image tag?
|
|
128 return ; NO - done
|
0
|
129
|
623
|
130 ; get pixel color into PROD
|
|
131 lfsr FSR2,buffer ; set FSR2 pointer to base address of color table
|
|
132 rlncf TABLAT,W ; get color index * 2 into WREG
|
|
133 movwf FSR2L ; adjust pointer to selected color
|
|
134 movff POSTINC2,PRODL ; read color, low byte
|
|
135 movff POSTINC2,PRODH ; read color, high byte
|
582
|
136
|
623
|
137 tstfsz encoding_format ; image encoded in version 0 format?
|
|
138 bra color_image_pixel ; NO
|
|
139 ; image encoding version 0 format: subtract pixel count from the overall number of pixels to do
|
|
140 movf pixel_count+0,W ; YES - 24 bit subtraction, low byte
|
|
141 subwf overall_pixels+0,F ; ...
|
|
142 movf pixel_count+1,W ; ... high byte
|
|
143 subwfb overall_pixels+1,F ; ...
|
|
144 movlw .0 ; ... upper byte
|
|
145 subwfb overall_pixels+2,F ; ...
|
0
|
146
|
623
|
147 color_image_pixel:
|
|
148 ; prepare sending of pixels to display
|
|
149 infsnz pixel_count+0 ; increment pixel repetition count by 1
|
|
150 incf pixel_count+1 ; ...
|
|
151 incf pixel_count+1 ; because decrement is done first, increment high byte once more
|
|
152 bsf tft_rs,0 ; RS_H data
|
|
153 bcf INTCON,GIE ; disable global interrupts
|
|
154
|
|
155 btfsc screen_type2 ; display type 2 ?
|
|
156 bra color_image_display2 ; YES
|
|
157 movff PRODH,PORTA ; NO - move color high byte to PORTA
|
|
158 movff PRODL,PORTH ; - move color low byte to PORTH
|
0
|
159
|
623
|
160 color_image_pixel1_loop:
|
|
161 bcf tft_nwr ; toggle write signal
|
|
162 bsf tft_nwr ; ...
|
|
163 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
164 bra color_image_pixel1_loop ; loop if not zero
|
|
165 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
166 bra color_image_pixel1_loop ; loop if not zero
|
|
167 bra color_image_pixel_com ; all pixels transmitted
|
|
168
|
608
|
169 color_image_display2:
|
623
|
170 call convert_for_display2 ; convert 16 bit RGB b'RRRRRGGG GGGBBBBB'
|
|
171 ; into 24 bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00'
|
|
172 color_image_pixel2_loop:
|
|
173 movff win_color5,PORTH ; move upper byte to PORTH (DISPLAY is big endian)
|
|
174 bcf tft_nwr ; toggle write signal
|
|
175 bsf tft_nwr ; ...
|
|
176 movff win_color4,PORTH ; move high byte to PORTH
|
|
177 bcf tft_nwr ; toggle write signal
|
|
178 bsf tft_nwr ; ...
|
|
179 movff win_color3,PORTH ; move low byte to PORTH
|
|
180 bcf tft_nwr ; toggle write signal
|
|
181 bsf tft_nwr ; ...
|
|
182 decfsz pixel_count+0 ; decrement pixel counter, low byte
|
|
183 bra color_image_pixel2_loop ; loop if not zero
|
|
184 decfsz pixel_count+1 ; decrement pixel counter, high byte
|
|
185 bra color_image_pixel2_loop ; loop if not zero
|
604
|
186
|
623
|
187 color_image_pixel_com:
|
|
188 bsf INTCON,GIE ; re-enable global interrupts
|
|
189
|
|
190 tstfsz encoding_format ; image encoded in version 0 format?
|
|
191 bra color_image_loop_xy ; NO - loop to process next byte from image data
|
0
|
192
|
623
|
193 ; image encoding version 0 format: step counter
|
|
194 clrf WREG ; make a 24 bit decrement
|
|
195 decf overall_pixels+0 ; ...
|
|
196 subwfb overall_pixels+1,F ; ...
|
|
197 subwfb overall_pixels+2,F ; ...
|
|
198 bnn color_image_loop_xy ; all pixels done? NO - loop
|
|
199 return ; YES - done
|
0
|
200
|
604
|
201
|
|
202 global get_colors
|
|
203 get_colors:
|
|
204 tblrd*+ ; read number of image colors
|
|
205 movff TABLAT,lo ; store in lo
|
|
206 movf lo,W
|
623
|
207 tblrd*+ ; read image encoding format
|
|
208 movff TABLAT,encoding_format ; store encoding format
|
604
|
209 lfsr FSR2,buffer ; set up buffer as storage for the colors
|
|
210 get_colors_loop:
|
623
|
211 tblrd*+ ; read color from stored image, low byte
|
|
212 btfss use_custom_colors ; shall use custom colors?
|
|
213 movff TABLAT,POSTINC2 ; NO - copy color read to buffer
|
|
214 tblrd*+ ; read color from stored image, high byte
|
|
215 btfss use_custom_colors ; shall use custom colors?
|
|
216 movff TABLAT,POSTINC2 ; NO - copy color read to buffer
|
|
217 decfsz WREG ; decrement loop counter, done?
|
|
218 bra get_colors_loop ; NO - loop
|
|
219 bcf use_custom_colors ; YES - clear custom colors request
|
|
220 return ; - done
|
604
|
221
|
582
|
222 END
|