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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 172 - (show annotations)
Sat Nov 28 13:10:37 2009 UTC (10 years ago) by dbug
File size: 7897 byte(s)
Added the source code of "Save The Earth", the Atari STe demo presented at Kindergarden 2009
1
2 enable_debug_curves equ 0
3
4 SECTION TEXT
5
6 even
7
8 rsreset
9
10 curve_start_x rs.w 1
11 curve_start_y rs.w 1
12 curve_midle_x rs.w 1
13 curve_midle_y rs.w 1
14 curve_final_x rs.w 1
15 curve_final_y rs.w 1
16 curve_lenght rs.w 1
17 curve_offset rs.w 1
18 _curve_max_ equ __RS
19
20 CurveData ds.l _curve_max_
21
22
23
24 ; Input:
25 ; a0=pointer on a curve parameter
26 ; Ouput:
27 ; d0=x
28 ; d1=y
29 BezierInterpolate
30 COLORHELP #$077
31 movem.l d2/d3,-(sp)
32
33 ; Right median point
34 move curve_final_x(a0),d0
35 sub curve_midle_x(a0),d0
36 muls curve_offset(a0),d0
37 divs curve_lenght(a0),d0
38 add curve_midle_x(a0),d0
39
40 move curve_final_y(a0),d1
41 sub curve_midle_y(a0),d1
42 muls curve_offset(a0),d1
43 divs curve_lenght(a0),d1
44 add curve_midle_y(a0),d1
45
46 ; Left median point
47 move curve_midle_x(a0),d2
48 sub curve_start_x(a0),d2
49 muls curve_offset(a0),d2
50 divs curve_lenght(a0),d2
51 add curve_start_x(a0),d2
52
53 move curve_midle_y(a0),d3
54 sub curve_start_y(a0),d3
55 muls curve_offset(a0),d3
56 divs curve_lenght(a0),d3
57 add curve_start_y(a0),d3
58
59 ; Final point
60 sub d2,d0
61 muls curve_offset(a0),d0
62 divs curve_lenght(a0),d0
63 add d2,d0
64
65 sub d3,d1
66 muls curve_offset(a0),d1
67 divs curve_lenght(a0),d1
68 add d3,d1
69
70 movem.l (sp)+,d2/d3
71 rts
72
73
74 ifne enable_debug_curves
75
76 ; Compute in 2 the average of 1 and 3
77 MEDIANPOINT macro
78 move.l \1,\2 ; 4
79 add.l \3,\2 ; 8
80 lsr.l #1,\2 ; 8+2=12
81 and.w #$7FFF,\2 ; 8
82 ; Total=4+8+12+8=32 nops
83 endm
84
85 MEDIANPOINT_D7 macro
86 move.l \1,d7 ; 4
87 add.l \3,d7 ; 8
88 lsr.l #1,d7 ; 8+2=12
89 and.w #$7FFF,d7 ; 8
90 move.l d7,\2
91 ; Total=4+8+12+8=32 nops
92 endm
93
94 ; 14*32=448 nops
95
96 ; a0/a1/a2
97 ; generates d3=d0|d1
98 ; generated d4=d1|d2
99 ComputeCurveLevel0
100 move.l a0,(a6)+ ; First point
101
102 ; d0,d1,d2,d3,d4,d5,d6,d7 are free
103 MEDIANPOINT a0,d0,a1
104 MEDIANPOINT a1,d1,a2
105
106 ; d2,d3,d4,d5,d6,d7 are free
107 MEDIANPOINT a0,d2,d0
108 MEDIANPOINT d0,d3,d1
109 MEDIANPOINT d1,d4,a2
110
111 ; d0,d1,d5,d6,d7 are free
112 MEDIANPOINT a0,d0,d2
113 MEDIANPOINT d2,d1,d3
114 MEDIANPOINT d3,d5,d4
115 MEDIANPOINT d4,d6,a2
116
117 ; d2,d3,d4,d7 are free
118 MEDIANPOINT a0,d2,d0
119 MEDIANPOINT d0,d3,d1
120 MEDIANPOINT d1,d4,d5
121 MEDIANPOINT d5,d7,d6
122 MEDIANPOINT d6,d0,a2
123
124 ; d1,d5,d6 are free
125 MEDIANPOINT a0,d1,d2
126 MEDIANPOINT d2,d5,d3
127 MEDIANPOINT d3,d6,d4
128 MEDIANPOINT d4,d2,d7
129 MEDIANPOINT d7,d3,d0
130 MEDIANPOINT d0,d4,a2
131
132 ; d0,d7 are free
133 MEDIANPOINT_D7 a0,a1,d1
134 MEDIANPOINT_D7 d1,a3,d5
135 MEDIANPOINT_D7 d5,a4,d6
136 MEDIANPOINT_D7 d6,a5,d2
137 MEDIANPOINT_D7 d2,d0,d3
138 MEDIANPOINT_D7 d3,d1,d4
139 MEDIANPOINT_D7 d4,d2,a2
140
141 ; d3,d4,d5,d6 are free
142 MEDIANPOINT a0,d3,a1
143 MEDIANPOINT a1,d4,a3
144 MEDIANPOINT a3,d5,a4
145 MEDIANPOINT a4,d6,a5
146 MEDIANPOINT_D7 a5,a1,d0
147 MEDIANPOINT_D7 d0,a3,d1
148 MEDIANPOINT_D7 d1,a4,d2
149 MEDIANPOINT_D7 d2,a5,a2
150
151 ; d0,d1,d2 are free
152
153 move.l d3,(a6)+
154 move.l d4,(a6)+
155 move.l d5,(a6)+
156 move.l d6,(a6)+
157 move.l a1,(a6)+
158 move.l a3,(a6)+
159 move.l a4,(a6)+
160 move.l a5,(a6)+
161
162 move.l a2,(a6)+ ; Last point
163
164 rts
165
166 NBPOINT equ 256
167
168 curve_start dc.w 80,20
169 curve_mid dc.w 250,250
170 curve_end dc.w 350,90
171
172 _CurveStart
173 ds.l NBPOINT
174 _CurveEnd
175 ds.l 100
176
177
178
179 ComputeCurveWithInterpolation
180 move curve_start+0,d0 ; p0x
181 move curve_start+2,d1 ; p0y
182
183 move curve_mid+0,d2 ; p1x
184 move curve_mid+2,d3 ; p1y
185
186 move curve_end+0,d4 ; p2x
187 move curve_end+2,d5 ; p2y
188
189 move d2,d6
190 sub d0,d6
191 move d6,dx01
192
193 move d3,d6
194 sub d1,d6
195 move d6,dy01
196
197 move d4,d6
198 sub d2,d6
199 move d6,dx12
200
201 move d5,d6
202 sub d3,d6
203 move d6,dy12
204
205 moveq #0,d7
206 .interpolate_loop
207
208 ; Left median point
209 move dx01,d6
210 ext.l d6
211 muls d7,d6
212 divs #NBPOINT,d6
213 add curve_start+0,d6
214 move d6,p01x
215
216 move dy01,d6
217 ext.l d6
218 muls d7,d6
219 divs #NBPOINT,d6
220 add curve_start+2,d6
221 move d6,p01y
222
223 ; Right median point
224 move dx12,d6
225 ext.l d6
226 muls d7,d6
227 divs #NBPOINT,d6
228 add curve_mid+0,d6
229 move d6,p12x
230
231 move dy12,d6
232 ext.l d6
233 muls d7,d6
234 divs #NBPOINT,d6
235 add curve_mid+2,d6
236 move d6,p12y
237
238 ; Median line size
239 move p12x,d6
240 sub p01x,d6
241 move d6,dx0112
242
243 move p12y,d6
244 sub p01y,d6
245 move d6,dy0112
246
247 ; Final point
248 move dx0112,d6
249 ext.l d6
250 muls d7,d6
251 divs #NBPOINT,d6
252 add p01x,d6
253 move d6,(a6)+
254
255 move dy0112,d6
256 ext.l d6
257 muls d7,d6
258 divs #NBPOINT,d6
259 add p01y,d6
260 move d6,(a6)+
261
262 add #1,d7
263 cmp #NBPOINT,d7
264 bne .interpolate_loop
265
266 rts
267
268
269 DrawTestCurve
270 ;
271 ; Compute the curve
272 ;
273 lea _CurveStart,a6
274 move.l curve_start,a0
275 move.l curve_mid,a1
276 move.l curve_end,a2
277 ;bsr ComputeCurveLevel0
278 bsr ComputeCurveWithInterpolation
279
280 ;
281 ; Draw the points
282 ;
283 lea _CurveStart,a0
284 .draw_points
285 moveq.l #0,d0
286 moveq.l #0,d1
287 moveq.l #0,d2
288 moveq.l #0,d3
289
290 move (a0)+,d0 ; x0
291 move (a0)+,d1 ; y0
292
293 ;bsr DrawPixel
294
295 move 0(a0),d2 ; x1
296 move 2(a0),d3 ; y1
297 bsr DrawLine
298
299 cmp.l #_CurveEnd-4,a0
300 bne.s .draw_points
301 rts
302 endc
303
304
305 ; d0.w=x0
306 ; d1.w=y0
307 ; d2.w=x1
308 ; d3.w=y1
309 DrawLine
310 ;illegal
311
312 moveq.l #1,d4 ; ix
313 sub.w d0,d2 ; dx
314 bpl.s .dx_positive
315 .dx_negative
316 neg.w d2 ; abs(dx)
317 moveq.l #-1,d4
318 .dx_positive
319
320 moveq.l #1,d5 ; iy
321 sub.w d1,d3 ; dy
322 bpl.s .dy_positive
323 .dy_negative
324 neg.w d3 ; abs(dy)
325 moveq.l #-1,d5
326 .dy_positive
327
328 ; d0=x0
329 ; d1=x1
330 ; d2=abs(dx)
331 ; d3=abs(dy)
332 ; d4=ix
333 ; d5=iy
334 ; d6=err
335
336 cmp.w d2,d3
337 bhi.s DrawVertical
338
339 DrawHorizontal
340 move d2,d6
341
342 move d3,d7
343 add d3,d7
344 sub d2,d7
345
346 add d3,d3
347 add d2,d2
348
349 .horizontal_loop
350 bsr DrawPixel
351 tst.w d7
352 bmi .skip
353 sub d2,d7
354 add d5,d1
355 .skip
356 add d3,d7
357 add d4,d0
358 dbra d6,.horizontal_loop
359 rts
360
361 DrawVertical
362 move d3,d6
363
364 move d2,d7
365 add d2,d7
366 sub d3,d7
367
368 add d3,d3
369 add d2,d2
370
371 .vertical_loop
372 bsr DrawPixel
373 tst.w d7
374 bmi .skip
375 sub d3,d7
376 add d4,d0
377 .skip
378 add d2,d7
379 add d5,d1
380 dbra d6,.vertical_loop
381 rts
382
383
384 ; d0.b=color index
385 SetPixelColor
386 lea _AdrDrawPixel,a0
387
388 moveq #$81,d1
389 lsr #1,d0
390 bcs .skip_p0
391 moveq #$c3,d1
392 .skip_p0
393 move.b d1,0(a0)
394
395 moveq #$81,d1
396 lsr #1,d0
397 bcs .skip_p1
398 moveq #$c3,d1
399 .skip_p1
400 move.b d1,2(a0)
401
402 moveq #$81,d1
403 lsr #1,d0
404 bcs .skip_p2
405 moveq #$c3,d1
406 .skip_p2
407 move.b d1,4(a0)
408
409 moveq #$81,d1
410 lsr #1,d0
411 bcs .skip_p3
412 moveq #$c3,d1
413 .skip_p3
414 move.b d1,6(a0)
415
416 ; Note: Could also be done with a table of 16 entries, each with 4 bytes containing eithe $81 or $c3,
417 ; then just load the right long value, and use movep.l to write the four values.
418 rts
419
420 ;TablePixelmask
421 ; dc.b $81,$81,$81,$81
422
423 ; $81=10000001
424 ; $C3=11000011
425
426 ; d0.w=x
427 ; d1.w=y
428 DrawPixel
429 movem.l d0-a6,-(sp)
430
431 and #511,d0
432 and #255,d1
433
434 move.l ptr_scr_1,a0
435
436 moveq.l #0,d2
437
438 move.w d0,d2
439 lsr.w #4,d2
440 lsl.w #3,d2
441 add.w d2,a0
442
443 mulu blit_stride,d1
444 add.l d1,a0
445
446 and.w #15,d0
447
448 lea PixelMask,a3
449 add d0,a3
450 add d0,a3
451 move (a3),d0
452 move d0,d1
453 not d1
454
455 ; or.w d0,(a0)+ ; 8158
456 ; and.w d1,(a0)+ ; c358
457
458 _AdrDrawPixel
459 or.w d0,(a0)+
460 or.w d0,(a0)+
461 or.w d0,(a0)+
462 or.w d0,(a0)+
463
464 movem.l (sp)+,d0-a6
465 rts
466
467
468 ifne enable_debug_curves
469
470 DrawPixel_OldAndCrappy
471 movem.l d0-a6,-(sp)
472
473 and #511,d0
474 and #255,d1
475
476 move.l ptr_scr_1,a1
477
478 moveq.l #0,d2
479
480 move.w d0,d2
481 lsr.w #4,d2
482 lsl.w #3,d2
483 add.w d2,a1
484
485 mulu blit_stride,d1
486 add.l d1,a1
487
488 and.w #15,d0
489
490 lea PixelMask,a3
491 add d0,a3
492 add d0,a3
493 move (a3),d0
494
495 or.w d0,6(a1)
496 not.w d0
497 and.w d0,0(a1)
498 and.w d0,2(a1)
499 and.w d0,4(a1)
500
501 movem.l (sp)+,d0-a6
502 rts
503
504 endc
505
506
507 SECTION DATA
508
509 even
510
511 PixelMask
512 pixl set $8000
513 REPT 16
514 dc.w pixl
515 pixl set pixl/2
516 ENDR
517
518
519 SECTION BSS
520
521 even
522
523 ifne enable_debug_curves
524
525 dx01 ds.w 1
526 dy01 ds.w 1
527
528 dx12 ds.w 1
529 dy12 ds.w 1
530
531 p01x ds.w 1
532 p01y ds.w 1
533
534 p12x ds.w 1
535 p12y ds.w 1
536
537 dx0112 ds.w 1
538 dy0112 ds.w 1
539
540 endc
541
542
543
544

  ViewVC Help
Powered by ViewVC 1.1.26