home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / testi / corsoasm / sorgenti_darkcoder / vari / ansprites.s next >
Encoding:
Text File  |  1995-12-06  |  11.7 KB  |  457 lines

  1.  
  2. ; Animazione degli sprite.
  3. ; Original version: Autore sconosciuto
  4. ; Fixed version: Randy/Ram Jam
  5.  
  6.  
  7.     SECTION    xxxx,CODE
  8.  
  9. ;    Include    "DaWorkBench.s"    ; togliere il ; prima di salvare con "WO"
  10.  
  11. *****************************************************************************
  12.     include    "startup2.s"    ; Salva Copperlist Etc.
  13. *****************************************************************************
  14.  
  15.         ;5432109876543210
  16. DMASET    EQU    %1000001110100000    ; copper,bitplane,sprites
  17.  
  18. Waitdisk    EQU    10
  19.  
  20. CopiedSprites    EQU    20
  21.  
  22. START:
  23.  
  24. ; Puntiamo il biplane azzerato
  25.  
  26.     MOVE.L    #PLANE,d0
  27.     LEA    BPLPOINTERS,A1
  28.     move.w    d0,6(a1)
  29.     swap    d0
  30.     move.w    d0,2(a1)
  31.  
  32. ; Puntiamo gli sprites
  33.  
  34.     MOVE.L    #BBUFFER,D0      ; indirizzo dove sono copiati gli sprite
  35.     LEA    SpritePointers,A1 ; indirizzo puntatori nella copperlist.
  36.     moveq    #8-1,d1          ; 8 sprites
  37. Ploop:
  38.     move.w    d0,6(a1)
  39.     swap    d0
  40.     move.w    d0,2(a1)
  41.     swap    d0
  42.     add.l    #68,d0
  43.     addq.w    #8,a1
  44.     dbra    d1,Ploop
  45.  
  46.     lea    BBUFFER,a1    ; destinazione
  47.     moveq    #CopiedSprites-1,d1    ; numero di copie
  48.     bsr.w    sprite_copy    ; Copia lo sprite 21 volte nel buffer
  49.  
  50.     lea    $dff000,a5
  51.     MOVE.W    #DMASET,$96(a5)        ; DMACON - abilita bitplane, copper
  52.                     ; e sprites.
  53.     move.l    #COPPER,$80(a5)        ; Puntiamo la nostra COP
  54.     move.w    d0,$88(a5)        ; Facciamo partire la COP
  55.     move.w    #0,$1fc(a5)        ; Disattiva l'AGA
  56.     move.w    #$c00,$106(a5)        ; Disattiva l'AGA
  57.     move.w    #$11,$10c(a5)        ; Disattiva l'AGA
  58.  
  59. mouse:
  60.     MOVE.L    #$1ff00,d1    ; bit per la selezione tramite AND
  61.     MOVE.L    #$12c00,d2    ; linea da aspettare = $12c
  62. Waity1:
  63.     MOVE.L    4(A5),D0    ; VPOSR e VHPOSR - $dff004/$dff006
  64.     ANDI.L    D1,D0        ; Seleziona solo i bit della pos. verticale
  65.     CMPI.L    D2,D0        ; aspetta la linea $010
  66.     BNE.S    Waity1
  67. Waity2:
  68.     MOVE.L    4(A5),D0    ; VPOSR e VHPOSR - $dff004/$dff006
  69.     ANDI.L    D1,D0        ; Seleziona solo i bit della pos. verticale
  70.     CMPI.L    D2,D0        ; aspetta la linea $010
  71.     Beq.S    Waity2
  72.  
  73.     btst    #2,$16(A5)    ; Tasto destro premuto?
  74.     beq.s    NonSpri
  75.  
  76.     bsr.w    doanim
  77.  
  78.     lea    $dff000,a5    ; rimetti $dff000 in a5
  79.  
  80. NonSpri:
  81.     btst    #6,$bfe001    ; tasti sin. mouse premuto?
  82.     bne.s    mouse
  83.     rts
  84.  
  85. *****************************************************************************
  86. ; Routine che provvede all'animazione degli sprite, secondo le tabelle
  87. *****************************************************************************
  88.  
  89. doanim:
  90.     subq.w    #1,countera    ; waitcounter -1
  91.     tst.w    countera    ; siamo arrivati a 0?
  92.     bne.s    StessaAnim    ; Se non ancora, ok... altrimenti...
  93.     move.l    actionptr(PC),a0 ; Prossima animazione dalla tab!
  94.     cmp.w    #-1,(a0)    ; Siamo alla fine della tab?
  95.     bne.s    Nonripart1    ; Se non ancora, ok
  96.     move.l    #action,actionptr ; altrimenti riparti da capo
  97.     move.l    actionptr(PC),a0 ; dalla prima animazione...
  98. Nonripart1:
  99.     move.w    (a0),countera    ; leffi il tempo di durata dell'animazione
  100.     move.w    2(a0),speedx    ; la velocita' X
  101.     move.w    4(a0),speedy    ; la velocita' Y
  102.     move.l    6(a0),xptrs    ; la tabella X
  103.     move.l    10(a0),yptrs    ; la tabella Y
  104.     add.l    #14,actionptr    ; Fai puntare alla prossima anim il pointer
  105. StessaAnim:
  106.     move.l    xptrs(PC),a0    ; flugbahnx
  107.     move.l    yptrs(PC),a1    ; flugbahny
  108.     moveq    #8-1,d7        ; numero sprites = 8
  109.     moveq    #0,d2
  110.     moveq    #0,d3
  111.     move.w    speedx(PC),d5    ; d5 = addx
  112.     move.w    speedy(PC),d6    ; d6 = addy
  113. animloop:
  114.     move.w    (a0),d2        ; val da tabx
  115.     move.w    (a1),d3        ; val da taby
  116.     add.w    d5,d2        ; aggiungi lo speedX
  117.     cmp.w    #360,d2        ; abbiamo superato 360?
  118.     blt.s    nomax
  119.     sub.w    #360,d2        ; se si, scaliamo
  120. nomax:
  121.     move.w    d2,(a0)+    ; salva X
  122.     add.w    d6,d3        ; aggiungi lo speedy al taby
  123.     cmp.w    #360,d3        ; superato 360?
  124.     blt.s    nomax2
  125.     sub.w    #360,d3        ; se si, scala
  126. nomax2:
  127.     move.w    d3,(a1)+    ; salva Y
  128.     lea    sinus(PC),a2
  129.     move    (a2,d2.w),d0    ; prendi il val X da sintab
  130.     lea    cosinus(PC),a2
  131.     move    (a2,d3.w),d1    ; prendi il val Y da costab
  132.     movem.l    d0-d7/a0-a6,-(a7)
  133.     mulu.w    #68,d7        ; actualsprite*68 = offset giusto per sprite
  134.     lea    BBUFFER+7*68,a1    ; indirizzo ultimo sprite
  135.     sub.l    d7,a1        ; subbiamo per trovare l'assress sprite ok
  136.     moveq    #0,d3        ; 0 = non attacched
  137.     moveq    #16,d2        ; Altezza sprite
  138.     add.l    #127+10,d0    ; centra X
  139.     add.l    #43,d1        ; centra Y
  140.     bsr.w    spr_control
  141.     movem.l    (a7)+,d0-d7/a0-a6
  142.     dbra    d7,animloop
  143.     rts
  144.  
  145.  
  146. *****************************************************************************
  147. ; Routine copia gli sprites nel buffer. Da 1 sprite se ne fanno XX        *
  148. *****************************************************************************
  149.  
  150. sprite_copy:
  151.     lea    sprite1,a0    ; sorgente: uno sprite
  152.     moveq    #68/4,d0    ; ogni sprite e' lungo 68 bytes
  153. Copy_loop:
  154.     move.l    (a0)+,(a1)+    ; da sprite a destinazione (buf)
  155.     subq.w    #1,d0
  156.     bne.s Copy_loop
  157.     dbra d1,sprite_copy    ; fai d1 copie
  158.     rts
  159.  
  160. actionptr:    dc.l    action
  161. xptrs:        dc.l    x2ptr
  162. yptrs:        dc.l    y2ptr
  163. countera:    dc.w    1
  164. speedx:        dc.w    4
  165. speedy:        dc.w    4
  166.  
  167. ;*****************************************************************************
  168. ; Routine di controllo degli sprite TEDESCA!. Parametri:
  169. ;
  170. ; A1 = Indirizzo dello sprite
  171. ; D0 = X Koordinate (0-512) (127 = minimo)
  172. ; D1 = Y koordinate (0-512) (43  = minimo)
  173. ; D2 = altezza dello Sprite
  174. ; D3 = (0 = Normale , 1 = Attached)
  175. ;*****************************************************************************
  176.  
  177. Spr_Control:
  178.     movem.l    d0-d3/a1,-(a7)    ; Register retten
  179.     cmp.w    #512,d0        ; x >= 512 
  180.     bge.s    lab3         ; ja  --> to end 
  181.     add.w    d1,d2    
  182.     cmp.w    #512,d2        ; y >= 512
  183.     bge.s    Lab3        ; ja  --> to end
  184.     cmp.b    #01,d3        ; test ob Attach Sprite
  185.     bne.s    Lab0        ; nein -->
  186.     bset.b    #7,3(a1)    ; sonst Attach Bit setzen
  187.     bra.s    Lab1        ; weiter
  188. Lab0:
  189.     bclr.b    #7,3(a1)    ; Attach Bit Loeschen
  190. Lab1:
  191.     lsr.w    #1,d0        ; X Position 1 Bit nach rechts schiften
  192.     bcs.s    Sethorz        ; Bit 0 gesetzt gewesen -->
  193.     bclr.b    #0,3(a1)    ; sonst Bit 0 der X Position setzen
  194.     bra.s    Lab10        ; weiter
  195. Sethorz:
  196.     bset.b    #0,3(a1)    ; Bit 0 der X Position loeschen
  197. Lab10:
  198.     move.b    d0,1(a1)    ; ermittelten Wert ablegen
  199.     move.b    d1,(a1)        ; Y Position ablegen
  200.     btst.l    #8,d1        ; Bit 8 in Y Position gesetzt
  201.     beq.s    Yclr        ; nein -->
  202.     bset.b    #2,3(a1)    ; sonst Bit 8 eintragen
  203.     bra.s    lab2        ; weiter
  204. Yclr:
  205.     bclr.b    #2,3(a1)    ; Bit 8 als geloescht eintragen
  206. Lab2:
  207.     move.b    d2,2(a1)    ; Spritealtezza eintragen
  208.     btst.l    #8,d2        ; ist Bit 8 gesetzt
  209.     beq.s    Ystopclr    ; nein -->    
  210.     bset.b    #1,3(a1)    ; sonst Bit 8 als gesetzt eintragen
  211.     bra.s    lab3        ; weiter
  212. Ystopclr:
  213.     bclr.b    #1,3(a1)    ; Bit 8 als geloescht eintragen
  214. Lab3:
  215.     movem.l    (a7)+,d0-d3/a1    ; Register wiederherstellen
  216.     rts            ; zurueck
  217.  
  218.  
  219. *****************************************************************************
  220. ; La tabella con le caratteristiche delle varie animazioni in sequenza        *
  221. *****************************************************************************
  222.  
  223. Action:    
  224.     dc.w    100,2,4        ; Tempo durata, SpeedX, SpeedY (num. pari!)
  225.     dc.l    x10ptr,y10ptr    ; puntatore tabx, puntatore tabY
  226.  
  227.     dc.w    100,4,2
  228.     dc.l    x2ptr,y2ptr
  229.  
  230.     dc.w    100,6,2
  231.     dc.l    x2ptr,y2ptr
  232.  
  233.     dc.w    100,8,2
  234.     dc.l    x2ptr,y2ptr
  235.  
  236.     dc.w    100,10,2
  237.     dc.l    x2ptr,y2ptr
  238.  
  239.     dc.w    100,10,4
  240.     dc.l    x2ptr,y2ptr
  241.  
  242.     dc.w    150,2,4
  243.     dc.l    x4ptr,y4ptr
  244.  
  245.     dc.w    200,4,2
  246.     dc.l    x4ptr,y4ptr
  247.  
  248.     dc.w    200,2,2
  249.     dc.l    x6ptr,y6ptr
  250.  
  251.     dc.w    150,4,2
  252.     dc.l    x6ptr,y6ptr
  253.  
  254.     dc.w    200,4,4
  255.     dc.l    x8ptr,y8ptr
  256.  
  257.     dc.w    150,2,4
  258.     dc.l    x8ptr,y8ptr
  259.  
  260.     dc.w    200,4,2
  261.     dc.l    x1ptr,y1ptr
  262.  
  263.     dc.w    150,4,4
  264.     dc.l    x1ptr,y1ptr
  265.  
  266.     dc.w    200,6,2
  267.     dc.l    x3ptr,y3ptr
  268.  
  269.     dc.w    50,8,2
  270.     dc.l    x3ptr,y3ptr
  271.  
  272.     dc.w    200,2,10
  273.     dc.l    x5ptr,y5ptr
  274.  
  275.     dc.w    100,2,2
  276.     dc.l    x2ptr,y2ptr
  277.  
  278.     dc.w    200,4,4
  279.     dc.l    x7ptr,y7ptr
  280.  
  281.     dc.w    150,4,4
  282.     dc.l    x9ptr,y9ptr
  283.  
  284.     dc.w    $FFFF        ; flag di fine tab
  285.  
  286. ;
  287. ;******** END OF ANIMATION SEQUENCE DATA *********
  288. ;
  289.  
  290. *****************************************************************************
  291. ; Le varie tabelle di X e Y add
  292. *****************************************************************************
  293.  
  294. x2ptr:        dc.w    0,46,90,134,180,224,270,314
  295. y2ptr:        dc.w    0,46,90,134,180,224,270,314
  296.  
  297. x4ptr:        dc.w    0,36,72,108,144,180,216,252,288,324
  298. y4ptr:        dc.w    36,72,108,144,180,216,252,288,324,0
  299.  
  300. x6ptr:        dc.w    0,8,16,24,32,40,48,56,64,72
  301. y6ptr:        dc.w    48,64,80,96,112,128,144,160,176,192
  302.  
  303. x8ptr:        dc.w    0,16,32,48,64,80,96,112,128,144
  304. y8ptr:        dc.w    48,64,80,96,112,128,144,160,176,192
  305.  
  306. x1ptr:        dc.w    0,36,72,108,144,180,216,252,288,324
  307. y1ptr:        dc.w    48,64,80,96,112,128,144,160,176,192
  308.  
  309. x3ptr:        dc.w    0,10,20,30,40,50,60,70,80,90
  310. y3ptr:        dc.w    0,36,72,108,144,180,216,252,288,324
  311.  
  312. x5ptr:        dc.w    0,2,4,6,8,10,12,14,16,18
  313. y5ptr:        dc.w    0,10,20,30,40,50,60,70,80,90
  314.  
  315. x7ptr:        dc.w    0,216,72,128,64,324,108,96,160,288
  316. y7ptr:        dc.w    288,160,96,108,324,64,128,72,216,0
  317.  
  318. y9ptr:        dc.w    80,96,112,128,144,160,176,192,208,224
  319. x9ptr:        dc.w    0,36,72,108,144,180,216,252,288,324
  320.  
  321. x10ptr:        dc.w    0,10,20,30,40,50,10,340
  322. y10ptr:        dc.w    0,10,20,30,40,50,340,10
  323.  
  324. *****************************************************************************
  325. ; Le tabelle SIN/COS per le traiettorie curve
  326. *****************************************************************************
  327.  
  328. sinus:
  329.     dc.w    140,143,147,150,154,157,161,164,167,171
  330.     dc.w    174,177,181,184,187,190,193,196,199,202
  331.     dc.w    204,207,209,212,214,217,219,221,223,225
  332.     dc.w    227,228,230,231,233,234,235,236,237,238
  333.     dc.w    238,239,239,240,240,240,240,240,239,239
  334.     dc.w    238,238,237,236,235,234,233,231,230,228
  335.     dc.w    227,225,223,221,219,217,214,212,209,207
  336.     dc.w    204,202,199,196,193,190,187,184,181,177
  337.     dc.w    174,171,167,164,161,157,154,150,147,143
  338.     dc.w    140,137,133,130,126,123,119,116,112,109
  339.     dc.w    106,103,99,96,93,90,87,84,81,78,76,73,71
  340.     dc.w    68,66,63,61,59,57,55,53,52,50,49,47,46,45
  341.     dc.w    44,43,42,42,41,41,40,40,40,40,40,41,41
  342.     dc.w    42,42,43,44,45,46,47,49,50,52,53,55,57
  343.     dc.w    59,61,63,66,68,71,73,76,78,81,84,87,90
  344.     dc.w    93,96,99,103,106,109,112,116,119,123,126
  345.     dc.w    130,133,137
  346. ;
  347. cosinus:
  348.     dc.w    168,168,168,168,167,167,166,166,165,164,163
  349.     dc.w    162,161,160,158,157,155,154,152,150,149,147
  350.     dc.w    145,143,141,138,136,134,131,129,127,124,121
  351.     dc.w    119,116,113,111,108,105,102,99,97,94,91,88
  352.     dc.w    85,82,79,76,73,71,68,65,62,59,57,54,51,49
  353.     dc.w    46,44,41,39,36,34,32,29,27,25,23,21,20,18
  354.     dc.w    16,15,13,12,10,9,8,7,6,5,4,4,3,3,2,2,2,2
  355.     dc.w    2,2,2,3,3,4,4,5,6,7,8,9,10,12,13,15,16
  356.     dc.w    18,20,21,23,25,27,29,32,34,36,39,41,44,46
  357.     dc.w    49,51,54,57,59,62,65,68,71,73,76,79,82,85
  358.     dc.w    88,91,94,97,99,102,105,108,111,113,116,119
  359.     dc.w    121,124,127,129,131,134,136,138,141,143,145
  360.     dc.w    147,149,150,152,154,155,157,158,160,161,162
  361.     dc.w    163,164,165,166,166,167,167,168,168,168
  362. endsi:
  363.  
  364.  
  365. *****************************************************************************
  366. ; I dati di 1 sprite, che saranno copiati 8 volte nel buffer in chip ram
  367. *****************************************************************************
  368.  
  369. sprite1:            ; dati dello sprite
  370.     dc.w 0,0
  371.     dc.w $07c0,0
  372.     dc.w $1010,$0fe0
  373.     dc.w $3798,$0fe0
  374.     dc.w $6fdc,$1fe0
  375.     dc.w $6f1c,$1fe0
  376.     dc.w $e77e,$1f80
  377.     dc.w $f0fe,$0f00
  378.     dc.w $fffe,$0000
  379.     dc.w $fffe,$0000
  380.     dc.w $fffe,$0000
  381.     dc.w $7ffc,$0000
  382.     dc.w $7ffc,$0000
  383.     dc.w $3ff8,$0000
  384.     dc.w $1ff0,$0000
  385.     dc.w $07c0,$0000
  386.     dc.w 0,0        ; fine sprite
  387.  
  388. *****************************************************************************
  389.  
  390.     section    gfx,data_C
  391.  
  392. copper:
  393.     dc.w    $8e,$2c81    ; diwstart
  394.     dc.w    $90,$2cc1    ; diwstop
  395.     dc.w    $92,$38        ; ddfstart
  396.     dc.w    $94,$d0        ; ddfstop
  397.  
  398. SpritePointers:
  399.     dc.w    $120,0,$122,0,$124,0,$126,0,$128,0,$12a,0,$12c,0,$12e,0
  400.     dc.w    $130,0,$132,0,$134,0,$136,0,$138,0,$13a,0,$13c,0,$13e,0
  401.  
  402.     dc.w    $108,0    ; bpl1mod
  403.     dc.w    $10a,0    ; bpl2mod
  404.     dc.w    $102,0    ; bplcon1
  405.     dc.w    $104,0    ; bplcon2
  406.  
  407. BPLPOINTERS:
  408.     dc.w    $e0,0,$e2,0    ; plane 1
  409.  
  410.     dc.w    $100,$1200    ; bplcon0 - 1 plane lowres
  411.  
  412.     dc.w    $180,0        ; color0 - nero
  413.     dc.w    $182,$fff    ; color1 - bianco
  414.  
  415.     DC.W    $180,$000,$182,$000
  416.  
  417. ; Colori degli sprite - da color17 a color31
  418.  
  419.     dc.w $1a2,$4d0    ;  Colori sprite 0,1 (verde)
  420.     dc.w $1a4,$ad8
  421.     dc.w $1a6,$ffe
  422.     dc.w $1a8,$4f0
  423.  
  424.     dc.w $1aa,$fe1    ; Colori sprite 2,3 (giallo)
  425.     dc.w $1ac,$fe4
  426.     dc.w $1ae,$ffe
  427.     dc.w $1b0,$fe2
  428.  
  429.     dc.w $1b2,$d20    ; Colori sprite 4,5 (rosso)
  430.     dc.w $1b4,$d88
  431.     dc.w $1b6,$ffe
  432.     dc.w $1b8,$f10
  433.  
  434.     dc.w $1ba,$40d    ; Colori sprite 6,7 (blu)
  435.     dc.w $1bc,$a8d
  436.     dc.w $1be,$fef
  437.     dc.w $1c0,$40f
  438.  
  439.     dc.w $ffff,$fffe    ; Fine della copperlist
  440.  
  441.  
  442. ; ****************************************************************************
  443.  
  444.     section    spritezz,bss_C
  445.  
  446.  
  447. BBUFFER:
  448.     ds.b    68*CopiedSprites
  449.  
  450. ; ****************************************************************************
  451.  
  452.     section    grafica,bss_C
  453.  
  454. plane:
  455.     ds.b    40*256    ; 1 plane lowres "nero" come sfondo.
  456.  
  457.