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
|
582
|
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 movff PRODH,PORTA ; Move high byte to PORTA
|
|
136 movff PRODL,PORTH ; Move low byte to PORTH
|
|
137 bcf INTCON,GIE
|
0
|
138 color_image_loop_pixel:
|
582
|
139 bcf tft_nwr,0 ; WR_L
|
|
140 bsf tft_nwr,0 ; WR_H Tick
|
|
141 decfsz img_count+0
|
|
142 bra color_image_loop_pixel
|
|
143 decfsz img_count+1
|
|
144 bra color_image_loop_pixel
|
|
145 bsf INTCON,GIE
|
604
|
146
|
582
|
147 ; And count (on a 24bit counter)
|
|
148 clrf WREG ; Make a 24bit decrement
|
|
149 decf img_pixels+0
|
|
150 subwfb img_pixels+1,F
|
|
151 subwfb img_pixels+2,F
|
0
|
152
|
582
|
153 bnn color_image_loop_xy ; Not finished ? loop...
|
0
|
154
|
582
|
155 ;---- Closeup --------------------------------------------------------
|
|
156 Index_out 0x00
|
|
157 return
|
0
|
158
|
604
|
159
|
|
160 global get_colors
|
|
161 get_colors:
|
|
162 tblrd*+ ; read number of image colors
|
|
163 movff TABLAT,lo ; store in lo
|
|
164 tblrd*+ ; skip one spare byte (future flags ?)
|
|
165 movf lo,W
|
|
166 lfsr FSR2,buffer ; set up buffer as storage for the colors
|
|
167 get_colors_loop:
|
|
168 tblrd*+
|
|
169 btfss use_custom_colors ; shall custom colors be used?
|
|
170 movff TABLAT,POSTINC2 ; NO
|
|
171 tblrd*+
|
|
172 btfss use_custom_colors ; shall custom colors be used?
|
|
173 movff TABLAT,POSTINC2 ; NO
|
|
174 decfsz WREG
|
|
175 bra get_colors_loop
|
|
176
|
|
177 bcf use_custom_colors ; clear custom colors request
|
|
178 return
|
|
179
|
582
|
180 END
|