0
|
1 ;=============================================================================
|
|
2 ;
|
604
|
3 ; File File color_processor.asm ## V2.98c
|
0
|
4 ;
|
|
5 ; Decompress and draw an image.
|
|
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 ;
|
|
13 ; RATIONALS: The OSTC have a nice color screen, and a std geek attitude impose
|
|
14 ; to show off ... ;-)
|
|
15 ;
|
|
16 ; Inputs: TBLPTR points to the image description block.
|
|
17 ; win_top, win_leftx2 the Top/Leftx2 corner here to put the image.
|
582
|
18 ; Outputs: None.
|
0
|
19 ; Trashed: TBLPTR, TABLAT, FSR2, PROD, win_width, win_height
|
|
20 ;
|
|
21 ; ImageBloc:
|
604
|
22 ; db widthx2, height
|
|
23 ; db nbColors, 0 ; 0 = unused yet, should remain 0 to keep packing happy
|
0
|
24 ; dw color0, color1, color2, color3, ...
|
604
|
25 ; db packed pixels...
|
0
|
26 ;
|
|
27 ; Limitations:
|
604
|
28 ; * nbColors <= 127
|
|
29 ; * image width should be even
|
|
30 ; * image left border should be on even position, too
|
|
31 ;
|
0
|
32 ; Compressed format:
|
604
|
33 ; - 1-3 bytes pixel count, followed by 1 byte pixel color
|
|
34 ; - bit 7 = 1: byte holds pixel count in bits 6-0
|
|
35 ; - bit 7 = 0: byte holds pixel color in bits 6-0
|
|
36 ; - all pixel count bytes accumulate:
|
|
37 ; - 1 byte pixel count: 1xxxxxxx -> 7 bit pixel count
|
|
38 ; - 2 bytes pixel count: 1yyyyyyy 1xxxxxxx -> 14 bit pixel count
|
|
39 ; - 3 bytes pixel count: 1zzzzzzz 1yyyyyyy 1xxxxxxx -> 21 bit pixel count
|
|
40 ;
|
|
41 ; Pixels are written column by column from left to right, with columns down first.
|
0
|
42 ;
|
|
43 ;-----------------------------------------------------------------------------
|
|
44
|
604
|
45 #include "hwos.inc"
|
|
46 #include "tft.inc"
|
|
47
|
|
48 color_proc CODE
|
0
|
49
|
|
50 ;-----------------------------------------------------------------------------
|
604
|
51 ; Note: some variables (win_width, win_height) are in BANK 0 !
|
|
52
|
582
|
53 global color_image
|
0
|
54 color_image:
|
604
|
55 banksel common ; Bank 1, just to be sure...
|
0
|
56
|
604
|
57 ;---- Get image size -----------------------------------------------
|
582
|
58 tblrd*+
|
|
59 movff TABLAT,win_width
|
|
60 tblrd*+
|
|
61 movff TABLAT,win_height
|
|
62
|
|
63 ; Compute width * height * 2 : the number of pixels to write.
|
|
64 clrf img_pixels+2
|
|
65 movf win_width,W ; Compute number of pixels to draw
|
|
66 mulwf win_height ; 0 .. 160x240
|
604
|
67 bcf STATUS,C ; BEWARE: mulwf does not reset carry flag!
|
582
|
68 rlcf PRODL ; x2 --> 0 .. 320x240, might be > 0xFFFF
|
|
69 rlcf PRODH
|
|
70 movff PRODL, img_pixels+0
|
|
71 movff PRODH, img_pixels+1
|
|
72 rlcf img_pixels+2 ; Get the upper bit in place
|
0
|
73
|
582
|
74 clrf WREG ; Decrement count to ease end detection
|
|
75 decf img_pixels+0,F
|
|
76 subwfb img_pixels+1,F
|
|
77 subwfb img_pixels+2,F
|
0
|
78
|
582
|
79 ;---- Send window command --------------------------------------------
|
|
80 clrf win_width+1 ; x2 on width, for the true box size
|
|
81 rlcf win_width+0
|
|
82 rlcf win_width+1
|
|
83 call TFT_box_write
|
|
84 Index_out 0x22
|
0
|
85
|
604
|
86 ;---- Read the colors ------------------------------------------------
|
|
87 rcall get_colors
|
|
88
|
582
|
89 ;---- Decode pixels --------------------------------------------------
|
0
|
90 color_image_loop_xy:
|
582
|
91 ; Get pixel count
|
|
92 clrf img_count+0
|
|
93 clrf img_count+1
|
0
|
94
|
582
|
95 ;---- Decode repetition count
|
0
|
96 color_image_decode_1:
|
582
|
97 tblrd*+ ; Get one byte
|
0
|
98
|
582
|
99 btfss TABLAT,7 ; High bit cleared ?
|
|
100 bra color_image_decode_2 ; YES: this is a color byte
|
|
101
|
|
102 rlcf TABLAT,F ; Drop high bit.
|
|
103 movlw .7 ; Move 7 bits
|
0
|
104 color_image_decode_3:
|
582
|
105 rlcf TABLAT,F ; Get bit into carry
|
|
106 rlcf img_count+0,F ; Push into pixel count
|
|
107 rlcf img_count+1,F
|
|
108 decfsz WREG
|
|
109 bra color_image_decode_3 ; and loop for each 7 bits
|
|
110 bra color_image_decode_1 ; Decode next byte
|
0
|
111
|
|
112 color_image_decode_2:
|
582
|
113 ;---- Get pixel color into PROD
|
|
114 movf TABLAT,W ; Get color index
|
|
115 addwf WREG ; *2
|
|
116 lfsr FSR2,buffer ; Reinitialize color table
|
|
117 movff WREG,FSR2L ; LOW(buffer) == 0
|
|
118 movff POSTINC2,PRODL
|
|
119 movff POSTINC2,PRODH
|
|
120
|
|
121 ; Subtract count-1 from the number of pixel we should do.
|
|
122 movf img_count+0,W ; Make a 24bit subtraction
|
|
123 subwf img_pixels+0,F
|
|
124 movf img_count+1,W
|
|
125 subwfb img_pixels+1,F
|
|
126 movlw 0
|
|
127 subwfb img_pixels+2,F
|
0
|
128
|
582
|
129 infsnz img_count+0 ; Increment count
|
|
130 incf img_count+1
|
0
|
131
|
608
|
132 ; Loop sending pixel color
|
|
133 incf img_count+1 ; Because we decrement first, should add one here !
|
|
134 bsf tft_rs,0 ; RS_H ; Data
|
|
135 bcf INTCON,GIE
|
|
136
|
|
137 color_image_loop_pixel:
|
|
138 btfsc screen_type2 ; Display 2?
|
|
139 bra color_image_display2 ; Yes
|
|
140
|
|
141 movff PRODH,PORTA ; Move high byte to PORTA
|
|
142 movff PRODL,PORTH ; Move low byte to PORTH
|
|
143 bcf tft_nwr
|
|
144 bsf tft_nwr
|
|
145 decfsz img_count+0
|
|
146 bra color_image_loop_pixel
|
|
147 decfsz img_count+1
|
|
148 bra color_image_loop_pixel
|
|
149 bra color_image_loop_pixel2
|
|
150
|
|
151 color_image_display2:
|
|
152 extern convert_for_display2
|
|
153 call convert_for_display2 ; Convert 16Bit RGB b'RRRRRGGG GGGBBBBB' into 24Bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00'
|
|
154 color_image_display2_loop:
|
|
155 movff win_color5,PORTH ; Move high byte to PORTH (DISPLAY is bigendian)
|
|
156 bcf tft_nwr
|
|
157 bsf tft_nwr
|
|
158 movff win_color4,PORTH ; Move low byte to PORTH
|
|
159 bcf tft_nwr
|
|
160 bsf tft_nwr
|
|
161 movff win_color3,PORTH ; Move low(est) byte to PORTH
|
|
162 bcf tft_nwr
|
|
163 bsf tft_nwr
|
|
164 decfsz img_count+0
|
|
165 bra color_image_display2_loop
|
|
166 decfsz img_count+1
|
|
167 bra color_image_display2_loop
|
604
|
168
|
608
|
169 color_image_loop_pixel2:
|
|
170 bsf INTCON,GIE
|
|
171 ; And count (on a 24bit counter)
|
|
172 clrf WREG ; Make a 24bit decrement.
|
|
173 decf img_pixels+0
|
|
174 subwfb img_pixels+1,F
|
|
175 subwfb img_pixels+2,F
|
0
|
176
|
608
|
177 bnn color_image_loop_xy ; Not finished ? loop...
|
0
|
178
|
608
|
179 ;---- Closeup --------------------------------------------------------
|
|
180 ; Index_out 0x00
|
|
181 return
|
0
|
182
|
604
|
183
|
|
184 global get_colors
|
|
185 get_colors:
|
|
186 tblrd*+ ; read number of image colors
|
|
187 movff TABLAT,lo ; store in lo
|
|
188 tblrd*+ ; skip one spare byte (future flags ?)
|
|
189 movf lo,W
|
|
190 lfsr FSR2,buffer ; set up buffer as storage for the colors
|
|
191 get_colors_loop:
|
|
192 tblrd*+
|
|
193 btfss use_custom_colors ; shall custom colors be used?
|
|
194 movff TABLAT,POSTINC2 ; NO
|
|
195 tblrd*+
|
|
196 btfss use_custom_colors ; shall custom colors be used?
|
|
197 movff TABLAT,POSTINC2 ; NO
|
|
198 decfsz WREG
|
|
199 bra get_colors_loop
|
|
200
|
|
201 bcf use_custom_colors ; clear custom colors request
|
|
202 return
|
|
203
|
582
|
204 END
|