0
|
1 ;=============================================================================
|
|
2 ;
|
582
|
3 ; File File color_processor.asm ## V2.98
|
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:
|
|
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 ;
|
|
47 ; Note: Some variables (win_width, win_height) are in BANK0 !
|
582
|
48 basic CODE
|
|
49 global color_image
|
0
|
50 color_image:
|
582
|
51 banksel common ; Bank1, just to be sure...
|
0
|
52
|
582
|
53 ;---- Get image parameters -------------------------------------------
|
|
54 tblrd*+
|
|
55 movff TABLAT,win_width
|
|
56 tblrd*+
|
|
57 movff TABLAT,win_height
|
|
58 tblrd*+
|
|
59 movff TABLAT,lo ; image colors
|
|
60 tblrd*+ ; Skip one byte (future flags ?)
|
|
61 ;---- Copy color table -----------------------------------------------
|
|
62 movf lo,W
|
|
63 lfsr FSR2,buffer
|
|
64 get_colors_loop:
|
|
65 tblrd*+
|
|
66 movff TABLAT,POSTINC2
|
|
67 tblrd*+
|
|
68 movff TABLAT,POSTINC2
|
|
69 decfsz WREG
|
|
70 bra get_colors_loop
|
|
71
|
|
72 ; Compute width * height * 2 : the number of pixels to write.
|
|
73 clrf img_pixels+2
|
|
74 movf win_width,W ; Compute number of pixels to draw
|
|
75 mulwf win_height ; 0 .. 160x240
|
|
76 bcf STATUS,C ; BEWARE: mulwf does not reset carry flag !
|
|
77 rlcf PRODL ; x2 --> 0 .. 320x240, might be > 0xFFFF
|
|
78 rlcf PRODH
|
|
79 movff PRODL, img_pixels+0
|
|
80 movff PRODH, img_pixels+1
|
|
81 rlcf img_pixels+2 ; Get the upper bit in place
|
0
|
82
|
582
|
83 clrf WREG ; Decrement count to ease end detection
|
|
84 decf img_pixels+0,F
|
|
85 subwfb img_pixels+1,F
|
|
86 subwfb img_pixels+2,F
|
0
|
87
|
582
|
88 ;---- Send window command --------------------------------------------
|
|
89 clrf win_width+1 ; x2 on width, for the true box size
|
|
90 rlcf win_width+0
|
|
91 rlcf win_width+1
|
|
92 call TFT_box_write
|
|
93 Index_out 0x22
|
0
|
94
|
582
|
95 ;---- Decode pixels --------------------------------------------------
|
0
|
96 color_image_loop_xy:
|
582
|
97 ; Get pixel count
|
|
98 clrf img_count+0
|
|
99 clrf img_count+1
|
0
|
100
|
582
|
101 ;---- Decode repetition count
|
0
|
102 color_image_decode_1:
|
582
|
103 tblrd*+ ; Get one byte
|
0
|
104
|
582
|
105 btfss TABLAT,7 ; High bit cleared ?
|
|
106 bra color_image_decode_2 ; YES: this is a color byte
|
|
107
|
|
108 rlcf TABLAT,F ; Drop high bit.
|
|
109 movlw .7 ; Move 7 bits
|
0
|
110 color_image_decode_3:
|
582
|
111 rlcf TABLAT,F ; Get bit into carry
|
|
112 rlcf img_count+0,F ; Push into pixel count
|
|
113 rlcf img_count+1,F
|
|
114 decfsz WREG
|
|
115 bra color_image_decode_3 ; and loop for each 7 bits
|
|
116 bra color_image_decode_1 ; Decode next byte
|
0
|
117
|
|
118 color_image_decode_2:
|
582
|
119 ;---- Get pixel color into PROD
|
|
120 movf TABLAT,W ; Get color index
|
|
121 addwf WREG ; *2
|
|
122 lfsr FSR2,buffer ; Reinitialize color table
|
|
123 movff WREG,FSR2L ; LOW(buffer) == 0
|
|
124 movff POSTINC2,PRODL
|
|
125 movff POSTINC2,PRODH
|
|
126
|
|
127 ; Subtract count-1 from the number of pixel we should do.
|
|
128 movf img_count+0,W ; Make a 24bit subtraction
|
|
129 subwf img_pixels+0,F
|
|
130 movf img_count+1,W
|
|
131 subwfb img_pixels+1,F
|
|
132 movlw 0
|
|
133 subwfb img_pixels+2,F
|
0
|
134
|
|
135 color_image_not_over:
|
582
|
136 infsnz img_count+0 ; Increment count
|
|
137 incf img_count+1
|
0
|
138
|
582
|
139 ; Loop sending pixel color
|
|
140 incf img_count+1 ; Because we decrement first, should add one here !
|
|
141 bsf tft_rs,0 ; RS_H Data
|
|
142 movff PRODH,PORTA ; Move high byte to PORTA
|
|
143 movff PRODL,PORTH ; Move low byte to PORTH
|
|
144 bcf INTCON,GIE
|
0
|
145 color_image_loop_pixel:
|
582
|
146 bcf tft_nwr,0 ; WR_L
|
|
147 bsf tft_nwr,0 ; WR_H Tick
|
|
148 decfsz img_count+0
|
|
149 bra color_image_loop_pixel
|
|
150 decfsz img_count+1
|
|
151 bra color_image_loop_pixel
|
|
152 bsf INTCON,GIE
|
|
153
|
|
154 ; And count (on a 24bit counter)
|
|
155 clrf WREG ; Make a 24bit decrement
|
|
156 decf img_pixels+0
|
|
157 subwfb img_pixels+1,F
|
|
158 subwfb img_pixels+2,F
|
0
|
159
|
582
|
160 bnn color_image_loop_xy ; Not finished ? loop...
|
0
|
161
|
582
|
162 ;---- Closeup --------------------------------------------------------
|
|
163 Index_out 0x00
|
|
164 return
|
0
|
165
|
582
|
166 END
|