/[projet1]/public/atari/demos/defenceforce/savetheearth/palette.s
Defence Force logotype

Contents of /public/atari/demos/defenceforce/savetheearth/palette.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 172 - (show annotations)
Sat Nov 28 13:10:37 2009 UTC (10 years, 2 months ago) by dbug
File size: 7319 byte(s)
Added the source code of "Save The Earth", the Atari STe demo presented at Kindergarden 2009
1
2
3 ;
4 ; Transforms a PC like RGB 24 bits colors
5 ; in a STE color.
6 ; \1 = red
7 ; \2 = green
8 ; \3 = blue
9 MAKERGB macro
10 var_r set (((\1)&255)>>4)
11 var_g set (((\2)&255)>>4)
12 var_b set (((\3)&255)>>4)
13 var_r set ((var_r>>1)+((var_r&1)<<3))
14 var_g set ((var_g>>1)+((var_g&1)<<3))
15 var_b set ((var_b>>1)+((var_b&1)<<3))
16 dc.w (((var_r)&15)<<8)+(((var_g)&15)<<4)+((var_b)&15)
17 endm
18
19 ;
20 ; Transforms a STF like colors in a STE color.
21 ; \1 = red
22 ; \2 = green
23 ; \3 = blue
24 MAKECOLOR macro
25 var_r set (\1)
26 var_g set (\2)
27 var_b set (\3)
28 var_r set ((var_r>>1)+((var_r&1)<<3))
29 var_g set ((var_g>>1)+((var_g&1)<<3))
30 var_b set ((var_b>>1)+((var_b&1)<<3))
31 dc.w (((var_r)&15)<<8)+(((var_g)&15)<<4)+((var_b)&15)
32 endm
33
34
35 SECTION TEXT
36
37 WaitEndOfFade
38 loop_wait_end_of_fade
39 bsr WaitVbl
40 _AdrEndOfFadeRoutine=*+2
41 jsr DummyRoutine
42
43 move.b palette_fade_counter,d0
44 bne.s loop_wait_end_of_fade
45 bsr WaitVbl
46 rts
47
48 ; a0=source palette
49 PaletteSet
50 movem.l a0/a1,-(sp)
51 ; Need that one to avoid the issue with the last grey palette generated by the subtitles...
52 lea palette_vbl_fade,a0 ; 12/3
53 lea $ffff8240.w,a1 ; 8/2
54 move.l (a0)+,(a1)+ ; 20/5
55 move.l (a0)+,(a1)+ ; 20/5
56 move.l (a0)+,(a1)+ ; 20/5
57 move.l (a0)+,(a1)+ ; 20/5
58 move.l (a0)+,(a1)+ ; 20/5
59 move.l (a0)+,(a1)+ ; 20/5
60 move.l (a0)+,(a1)+ ; 20/5
61 move.l (a0)+,(a1)+ ; 20/5
62 movem.l (sp)+,a0/a1
63 rts
64
65
66 ;
67 ; a0 -> start palette
68 ; a1 -> end palette
69 ; a2 -> destination palettes
70 ; d7 -> number of colors
71 ;
72 ComputeFullGradient
73 move.l a2,-(sp)
74 bsr ComputeGradient
75
76 move.l (sp)+,a0
77 .loop
78 bsr ApplyGradient
79 tst palette_fade_counter
80 bne.s .loop
81 rts
82
83 ;
84 ; a0 -> start palette
85 ; a1 -> end palette
86 ; d7 -> number of colors
87 ;
88 ComputeGradient
89 ;
90 ; Compute fixed point increment values
91 ;
92 lea palette_source_rgb,a2 ; Source palette and increments stored as separated components
93 lea table_to_stf,a3 ; Conversion table from STE encoding to linear
94 subq.l #1,d7
95 move.w d7,palette_fade_color_count
96 .loop_color
97 ; Read source and destination colors
98 move.w (a0)+,d0
99 move.w (a1)+,d1
100
101 ; Blue component
102 move d0,d2
103 and #%1111,d2
104 moveq #0,d5
105 move.b (a3,d2.w),d5 ; Source BLUE STE to linear conversion
106 swap d5
107
108 move d1,d2
109 and #%1111,d2
110 moveq #0,d6
111 move.b (a3,d2.w),d6 ; Destination BLUE STE to linear conversion
112 swap d6
113 sub.l d5,d6
114 asr.l #4,d6
115 move.l d6,(a2)+ ; Store increment
116 move.l d5,(a2)+ ; Store base color
117
118 ; Green component
119 lsr #4,d0
120 move d0,d2
121 and.w #%1111,d2
122 moveq #0,d5
123 move.b (a3,d2.w),d5
124 swap d5
125
126 lsr #4,d1
127 move d1,d2
128 and #%1111,d2
129 moveq #0,d6
130 move.b (a3,d2.w),d6
131 swap d6
132 sub.l d5,d6
133 asr.l #4,d6
134 move.l d6,(a2)+ ; Store increment
135 move.l d5,(a2)+ ; Store base color
136
137 ; Red component
138 lsr #4,d0
139 move d0,d2
140 and #%1111,d2
141 moveq #0,d5
142 move.b (a3,d2.w),d5
143 swap d5
144
145 lsr #4,d1
146 move d1,d2
147 and #%1111,d2
148 moveq #0,d6
149 move.b (a3,d2.w),d6
150 swap d6
151 sub.l d5,d6
152 asr.l #4,d6
153 move.l d6,(a2)+ ; Store increment
154 move.l d5,(a2)+ ; Store base color
155
156 dbra d7,.loop_color
157
158 move.b #16,palette_fade_counter
159 rts
160
161
162 ;
163 ; Then do the fade
164 ; a0=adress of destination palette
165 ApplyGradient
166 move.b palette_fade_counter,d0
167 beq.s .done
168 .continue_gradient
169 subq #1,d0
170 move.b d0,palette_fade_counter
171
172 lea palette_source_rgb,a1
173 lea table_to_ste,a2
174
175 move.w palette_fade_color_count,d7
176 .loop_color
177 move.l (a1)+,d0 ; Blue increment
178 add.l (a1),d0 ; + Blue base color
179 move.l d0,(a1)+ ; Store new Blue
180
181 move.l (a1)+,d1 ; Green increment
182 add.l (a1),d1 ; + Green base color
183 move.l d1,(a1)+ ; Store new Green
184
185 move.l (a1)+,d2 ; Red increment
186 add.l (a1),d2 ; + Red base color
187 move.l d2,(a1)+ ; Store new Red
188
189 swap d0
190 swap d1
191 swap d2
192
193 move.b 0(a2,d2.w),(a0)+ ; Red to STE
194 move.b 16(a2,d1.w),d2 ; Green to STE
195 or.b 0(a2,d0.w),d2 ; Blue to STE
196 move.b d2,(a0)+ ; Write final color
197
198 dbra d7,.loop_color
199 .done
200 rts
201
202
203 ; Input:
204 ; d0 - start RGB values (eg: 255,255,255)
205 ; d1 - end RGB values (eg: 0,0,0)
206 ; a2 - destination buffer (eg: buffer_background_color)
207 ; d7 - number of steps (ie: number of colors)
208 ;
209 ; Output:
210 ; All registers are restored to the initial value, excepted
211 ; a2 which points to the end of the buffer. This way things
212 ; can be daisy chained nicely.
213 CreateBackgroundGradient
214 movem.l d0-d7/a0/a1/a3/a4,-(sp)
215
216 lea palette_start_colors,a0
217 movep.l d0,1(a0)
218 movem.w 2(a0),d3/d4/d5 ; Source red/green/blue
219
220 lea palette_delta_colors,a1
221 movep.l d1,1(a1)
222 moveq #0,d1
223 movep.l d1,0(a1) ; Need to clear the low byte to clean previous computation results
224
225 sub.w d3,2(a1) ; Delta red
226 sub.w d4,4(a1) ; Delta green
227 sub.w d5,6(a1) ; Delta blue
228
229 lea table_to_ste,a3 ; +0: normal table, +16: shifted by 4
230
231 moveq #0,d6 ; current index
232 .loop
233 movem.w 2(a1),d0/d1/d2 ; red/green/blue deltas
234
235 muls d6,d0
236 divs d7,d0
237 add d3,d0 ; Red start
238
239 muls d6,d1
240 divs d7,d1
241 add d4,d1 ; Green start
242
243 muls d6,d2
244 divs d7,d2
245 add d5,d2 ; Blue start
246
247 lsr.b #4,d2
248 lsr.b #4,d1
249 lsr.b #4,d0
250
251 move.b 0(a3,d0.w),(a2)+ ; Red to STE
252 move.b 16(a3,d1.w),d0 ; Green to STE
253 or.b 0(a3,d2.w),d0 ; Blue to STE
254 move.b d0,(a2)+ ; Write final color
255
256 addq #1,d6
257
258 cmp d6,d7
259 bne.s .loop
260
261 movem.l (sp)+,d0-d7/a0/a1/a3/a4
262 rts
263
264
265 ; a0 - Source buffer (r,g,b components)
266 ; a1 - Target buffer (16 bits colors, STE interleaved format)
267 ; d7 - Number of colors
268 RawToSt
269 ;
270 ; First generate the 16 bits picture from the 24 bits
271 ;
272 lea table_to_ste,a2
273
274 ;move.w #170*8,d7
275 .loop
276 move.b (a0)+,d0 ; R 111xxxxx
277 move.b (a0)+,d1 ; G
278 move.b (a0)+,d2 ; B
279
280 ; Let's get it a bit darker for the visibility
281 ;lsr.b #1,d0
282 ;lsr.b #1,d1
283 ;lsr.b #1,d2
284
285 lsr.b #4,d0
286 and #15,d0
287 move.b (a2,d0),d0
288
289 lsr.b #4,d1
290 and.w #15,d1
291 move.b (a2,d1),d1
292
293 lsr.b #4,d2
294 and.w #15,d2
295 move.b (a2,d2),d2
296
297 lsl.w #8,d0
298 lsl.w #4,d1
299 or.w d1,d0
300 or.w d2,d0
301
302 move d0,(a1)+
303
304 dbra d7,.loop
305 rts
306
307
308 even
309
310 SECTION DATA
311
312 table_to_stf
313 dc.b 0
314 dc.b 2
315 dc.b 4
316 dc.b 6
317 dc.b 8
318 dc.b 10
319 dc.b 12
320 dc.b 14
321 dc.b 1
322 dc.b 3
323 dc.b 5
324 dc.b 7
325 dc.b 9
326 dc.b 11
327 dc.b 13
328 dc.b 15
329
330 table_to_ste
331 dc.b 0
332 dc.b 8
333 dc.b 1
334 dc.b 9
335 dc.b 2
336 dc.b 10
337 dc.b 3
338 dc.b 11
339 dc.b 4
340 dc.b 12
341 dc.b 5
342 dc.b 13
343 dc.b 6
344 dc.b 14
345 dc.b 7
346 dc.b 15
347
348 table_to_ste_shifted
349 dc.b (0<<4)
350 dc.b (8<<4)
351 dc.b (1<<4)
352 dc.b (9<<4)
353 dc.b (2<<4)
354 dc.b (10<<4)
355 dc.b (3<<4)
356 dc.b (11<<4)
357 dc.b (4<<4)
358 dc.b (12<<4)
359 dc.b (5<<4)
360 dc.b (13<<4)
361 dc.b (6<<4)
362 dc.b (14<<4)
363 dc.b (7<<4)
364 dc.b (15<<4)
365
366 GreyPalette
367 var set 0
368 REPT 16
369 MAKECOLOR var,var,var
370 var set var+1
371 ENDR
372
373 even
374
375 SECTION BSS
376
377 palette_vbl_fade ds.w 16
378
379 even
380
381 palette_source_rgb ds.l 16*6 ; RGB components of palettes about to be faded
382 palette_fade_color_count ds.w 1 ; How many colors do we want to fade (max 256)
383 palette_fade_counter ds.b 1
384
385 even
386
387 palette_start_colors ds.w 3+1 ; Signed value, start component values
388 palette_delta_colors ds.w 3+1 ; Signed value, difference between end and start component values
389
390 even
391
392
393

  ViewVC Help
Powered by ViewVC 1.1.26