comparison code_part1/OSTC_code_asm_part1/color_processor.asm @ 110:8aa8acada0fd

Display deco-type icon in surface mode.
author JeanDo
date Wed, 22 Dec 2010 03:23:55 +0100
parents
children 6a94f96e9cea
comparison
equal deleted inserted replaced
109:6e635bf5b7a7 110:8aa8acada0fd
1 ;=============================================================================
2 ;
3 ; File color_processor.asm
4 ;
5 ; Decompress and draw an image.
6 ;
7 ; This program is free software: you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation, either version 3 of the License, or
10 ; (at your option) any later version.
11 ;
12 ; This program is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
16 ;
17 ; You should have received a copy of the GNU General Public License
18 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ;
20 ; Copyright (c) 2010, JD Gascuel.
21 ;=============================================================================
22 ; HISTORY
23 ; 2010-12-13 : [jDG] Creation
24 ;
25 ; RATIONALS: The OSTC have a nice color screen, and a std geek attitude impose
26 ; to show off ... ;-)
27 ;
28 ; Inputs: TBLPTR points to the image description block.
29 ; win_top, win_leftx2 the Top/Leftx2 corner here to put the image.
30 ; Ouputs: None.
31 ; Trashed: TBLPTR, TABLAT, FSR2, PROD, aa_width, aa_height
32 ;
33 ; ImageBloc:
34 ; db widthx2, height
35 ; db nbColors, 0 ; Unused yet... Should be 0 to keep packing happy.
36 ; dw color0, color1, color2, color3, ...
37 ; db ...packed pixels...
38 ;
39 ; Limitations:
40 ; * nbColors should be <= 15.
41 ; * image width should be even.
42 ; * image left border should be on even position too.
43 ; Compressed format:
44 ; - Upper nibble = color, lower nibble = count-1.
45 ; - All bytes F* accumulates to make count larger than 16.
46 ; Eg. 00 is 1 pixel color 0
47 ; 07 is 8 pixels color 0
48 ; 70 is 1 pixel color 7
49 ; bf is 16 pixels of color .11
50 ; F1 F2 F3 04 is 0x1235 pixels of color 0.
51 ;
52 ;Temporary overlay (in bank 0)
53 img_width equ aa_width
54 img_height equ aa_height
55 img_top equ win_top
56 img_left equ win_leftx2
57 img_pixelsL equ aa_start+0
58 img_pixelsH equ aa_start+1
59 img_pixelsU equ aa_end+0
60 img_countL equ aa_end+1
61 img_countH equ aa_colorDiv+0
62 img_colors equ aa_colorDiv+1
63 colorTable equ letter
64
65 ;-----------------------------------------------------------------------------
66 ; Make an entry in the link map.
67 color_processor code
68
69 ;-----------------------------------------------------------------------------
70 color_image:
71 movlb HIGH(img_width) ; Switch to bank 0.
72
73 ;---- Get image parameters -------------------------------------------
74 tblrd*+
75 movff TABLAT,img_width
76 tblrd*+
77 movff TABLAT,img_height
78 tblrd*+
79 movff TABLAT,img_colors
80 tblrd*+
81 ;---- Copy color table -----------------------------------------------
82 movf img_colors,W
83 lfsr FSR2,colorTable
84 get_colors_loop:
85 tblrd*+
86 movff TABLAT,POSTINC2
87 tblrd*+
88 movff TABLAT,POSTINC2
89 decfsz WREG
90 bra get_colors_loop
91
92 ; Compute width * height * 2 : the number of pixels to write.
93 clrf img_pixelsU
94 movf img_width,W ; Compute number of pixels to draw
95 mulwf img_height ; 0 .. 160x240
96 bcf STATUS,C ; BEWARE: milw does not reset carry flag !
97 rlcf PRODL ; x2 --> 0 .. 320x240, might by > 0xFFFF
98 rlcf PRODH
99 movff PRODL, img_pixelsL
100 movff PRODH, img_pixelsH
101 rlcf img_pixelsU ; Get the upper bit in place.
102
103 ;---- Send window command --------------------------------------------
104 clrf img_width+1 ; x2 on width, for the true box size.
105 rlcf img_width+0
106 rlcf img_width+1
107 call aa_box_cmd
108 AA_CMD_WRITE 0x22
109
110 ;---- Decode pixels --------------------------------------------------
111 color_image_loop_xy:
112 ; Get pixel count
113 clrf img_countL
114 clrf img_countH
115
116 color_image_loop_count:
117 tblrd*+ ; Get one byte
118
119 movlw 0x0F ; Get count bits
120 andwf TABLAT,W
121 swapf WREG ; On top-4 bits of W
122 rlcf WREG ; Push topmost bit into img_count:2
123 rlcf img_countL
124 rlcf img_countH
125 rlcf WREG ; Push topmost bit into img_count:2
126 rlcf img_countL
127 rlcf img_countH
128 rlcf WREG ; Push topmost bit into img_count:2
129 rlcf img_countL
130 rlcf img_countH
131 rlcf WREG ; Push topmost bit into img_count:2
132 rlcf img_countL
133 rlcf img_countH
134
135 movf TABLAT,W ; Does the color-bits mark a big-count ?
136 andlw 0xF0
137 xorlw 0xF0
138 bz color_image_loop_count ; YES: loop for more count bits.
139
140 ; Get pixel color into PROD
141 xorlw 0xF0 ; Get back index.
142 swapf WREG ; Get color index to lower bits.
143 addwf WREG ; x2
144 addlw LOW(letter) ; 0x60 + 2 * .15 < 0x80.
145 movff WREG,FSR2L
146 movff POSTINC2,PRODL
147 movff POSTINC2,PRODH
148
149 ; Substract count-1 from the number of pixel we should do.
150 movf img_countL,W ; Make a 24bit substraction.
151 subwf img_pixelsL,F
152 movf img_countH,W
153 subwfb img_pixelsH,F
154 movlw 0
155 subwfb img_pixelsU,F
156
157 incf img_countL ; Get back the true count.
158 addwfc img_countH
159
160 ; Loop sending pixel color
161 incf img_countH ; Because we decrement first, should add one here !
162 color_image_loop_pixel:
163 AA_DATA_WRITE_PROD
164 decfsz img_countL
165 bra color_image_loop_pixel
166 decfsz img_countH
167 bra color_image_loop_pixel
168
169 ; And count (on a 17bit counter)
170 clrf WREG ; Make a 24bit decrement.
171 decf img_pixelsL
172 subwfb img_pixelsH,F
173 subwfb img_pixelsU,F
174
175 movf img_pixelsL,W ; Test if img_pixels == 0
176 iorwf img_pixelsH,W
177 iorwf img_pixelsU,W
178 bnz color_image_loop_xy ; NO: loop...
179
180 ;---- Closeup --------------------------------------------------------
181 AA_CMD_WRITE 0x00
182 return