0
|
1 ;=============================================================================
|
|
2 ;
|
|
3 ; File File color_processor.asm
|
|
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.
|
|
18 ; Ouputs: None.
|
|
19 ; Trashed: TBLPTR, TABLAT, FSR2, PROD, win_width, win_height
|
|
20 ;
|
|
21 ; ImageBloc:
|
|
22 ; db widthx2, height
|
|
23 ; db nbColors, 0 ; Unused yet... Should be 0 to keep packing happy.
|
|
24 ; dw color0, color1, color2, color3, ...
|
|
25 ; db ...packed pixels...
|
|
26 ;
|
|
27 ; Limitations:
|
|
28 ; * nbColors should be <= 15.
|
|
29 ; * image width should be even.
|
|
30 ; * image left border should be on even position too.
|
|
31 ; Compressed format:
|
|
32 ; - Upper nibble = color, lower nibble = count-1.
|
|
33 ; - All bytes F* accumulates to make count larger than 16.
|
|
34 ; Eg. 00 is 1 pixel color 0
|
|
35 ; 07 is 8 pixels color 0
|
|
36 ; 70 is 1 pixel color 7
|
|
37 ; bf is 16 pixels of color .11
|
|
38 ; F1 F2 F3 04 is 0x1235 pixels of color 0.
|
|
39 ;
|
|
40 ;-----------------------------------------------------------------------------
|
|
41
|
275
|
42 #include "hwos.inc"
|
0
|
43 #include "tft.inc"
|
|
44
|
|
45 ;-----------------------------------------------------------------------------
|
|
46 ; Temporary overlay (in bank 1).
|
|
47
|
|
48 CBLOCK tmp ; Data overlay in reserved tmp area.
|
|
49 img_colors:1
|
|
50 img_pixels:3
|
|
51 img_count:2
|
|
52 ; Reserved to tmp+0x07...
|
|
53 ENDC
|
|
54
|
|
55 ;-----------------------------------------------------------------------------
|
|
56 ;
|
|
57 ; Note: Some variables (win_width, win_height) are in BANK0 !
|
|
58 basic CODE
|
|
59 global color_image
|
|
60 color_image:
|
|
61 banksel win_width ; Bank1, just to be sure...
|
|
62
|
|
63 ;---- Get image parameters -------------------------------------------
|
|
64 tblrd*+
|
|
65 movff TABLAT,win_width
|
|
66 tblrd*+
|
|
67 movff TABLAT,win_height
|
|
68 tblrd*+
|
|
69 movff TABLAT,img_colors
|
|
70 tblrd*+ ; Skip one byte (future flags ?)
|
|
71 ;---- Copy color table -----------------------------------------------
|
|
72 movf img_colors,W
|
|
73 lfsr FSR2,buffer
|
|
74 get_colors_loop:
|
|
75 tblrd*+
|
|
76 movff TABLAT,POSTINC2
|
|
77 tblrd*+
|
|
78 movff TABLAT,POSTINC2
|
|
79 decfsz WREG
|
|
80 bra get_colors_loop
|
|
81
|
|
82 ; Compute width * height * 2 : the number of pixels to write.
|
|
83 clrf img_pixels+2
|
|
84 movf win_width,W ; Compute number of pixels to draw
|
|
85 mulwf win_height ; 0 .. 160x240
|
|
86 bcf STATUS,C ; BEWARE: mulwf does not reset carry flag !
|
|
87 rlcf PRODL ; x2 --> 0 .. 320x240, might be > 0xFFFF
|
|
88 rlcf PRODH
|
|
89 movff PRODL, img_pixels+0
|
|
90 movff PRODH, img_pixels+1
|
|
91 rlcf img_pixels+2 ; Get the upper bit in place.
|
|
92
|
|
93 clrf WREG ; Decrement count to ease end detection.
|
|
94 decf img_pixels+0,F
|
|
95 subwfb img_pixels+1,F
|
|
96 subwfb img_pixels+2,F
|
|
97
|
|
98 ;---- Send window command --------------------------------------------
|
|
99 clrf win_width+1 ; x2 on width, for the true box size.
|
|
100 rlcf win_width+0
|
|
101 rlcf win_width+1
|
|
102 call TFT_box_write
|
|
103 Index_out 0x22
|
|
104
|
|
105 ;---- Decode pixels --------------------------------------------------
|
|
106 color_image_loop_xy:
|
|
107 ; Get pixel count
|
|
108 clrf img_count+0
|
|
109 clrf img_count+1
|
|
110
|
|
111 ;---- Decode repetition count
|
|
112 color_image_decode_1:
|
|
113 tblrd*+ ; Get one byte
|
|
114
|
|
115 btfss TABLAT,7 ; High bit cleared ?
|
|
116 bra color_image_decode_2 ; YES: this is a color byte.
|
|
117
|
|
118 rlcf TABLAT,F ; Drop high bit.
|
|
119 movlw .7 ; Move 7 bits
|
|
120 color_image_decode_3:
|
|
121 rlcf TABLAT,F ; Get bit into carry
|
|
122 rlcf img_count+0,F ; Push into pixel count
|
|
123 rlcf img_count+1,F
|
|
124 decfsz WREG
|
|
125 bra color_image_decode_3 ; and loop foreach 7 bits.
|
|
126
|
|
127 bra color_image_decode_1 ; Decode next byte.
|
|
128
|
|
129 color_image_decode_2:
|
|
130 ;---- Get pixel color into PROD
|
|
131 movf TABLAT,W ; Get color index.
|
|
132 addwf WREG ; *2
|
|
133 lfsr FSR2,buffer ; Reinitialize color table.
|
|
134 movff WREG,FSR2L ; LOW(buffer) == 0
|
|
135 movff POSTINC2,PRODL
|
|
136 movff POSTINC2,PRODH
|
|
137
|
|
138 ; Substract count-1 from the number of pixel we should do.
|
|
139 movf img_count+0,W ; Make a 24bit substraction.
|
|
140 subwf img_pixels+0,F
|
|
141 movf img_count+1,W
|
|
142 subwfb img_pixels+1,F
|
|
143 movlw 0
|
|
144 subwfb img_pixels+2,F
|
|
145
|
|
146 color_image_not_over:
|
|
147 infsnz img_count+0 ; Increment count.
|
|
148 incf img_count+1
|
|
149
|
|
150 ; Loop sending pixel color
|
|
151 incf img_count+1 ; Because we decrement first, should add one here !
|
|
152 bsf tft_rs,0 ; RS_H ; Data
|
|
153 movff PRODH,PORTA ; Move high byte to PORTA
|
|
154 movff PRODL,PORTH ; Move low byte to PORTH
|
436
|
155 bcf INTCON,GIE
|
0
|
156 color_image_loop_pixel:
|
|
157 bcf tft_nwr,0 ; WR_L
|
|
158 bsf tft_nwr,0 ; WR_H ; Tick
|
|
159 decfsz img_count+0
|
|
160 bra color_image_loop_pixel
|
|
161 decfsz img_count+1
|
|
162 bra color_image_loop_pixel
|
436
|
163 bsf INTCON,GIE
|
0
|
164
|
|
165 ; And count (on a 24bit counter)
|
|
166 clrf WREG ; Make a 24bit decrement.
|
|
167 decf img_pixels+0
|
|
168 subwfb img_pixels+1,F
|
|
169 subwfb img_pixels+2,F
|
|
170
|
|
171 bnn color_image_loop_xy ; Not finished ? loop...
|
|
172
|
|
173 ;---- Closeup --------------------------------------------------------
|
|
174 Index_out 0x00
|
|
175 return
|
|
176
|
|
177 end |