Advertisement
vladikcomper

Sonic 1 - Object 86 annotated

Aug 3rd, 2012
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ; ===========================================================================
  3. ; ---------------------------------------------------------------------------
  4. ; Object 86 - energy balls (FZ)
  5. ; ---------------------------------------------------------------------------
  6.  
  7. Obj86:                  ; XREF: Obj_Index
  8.         moveq   #0,d0
  9.         move.b  $24(a0),d0
  10.         move.w  Obj86_Index(pc,d0.w),d0
  11.         jmp Obj86_Index(pc,d0.w)
  12. ; ===========================================================================
  13. Obj86_Index:    dc.w Obj86_Main-Obj86_Index     ; $00
  14.         dc.w Obj86_Generator-Obj86_Index    ; $02
  15.         dc.w Obj86_MakeBalls-Obj86_Index    ; $04
  16.         dc.w Obj86_WaitBalls-Obj86_Index    ; $06
  17.         dc.w Obj86_EnergyBall-Obj86_Index   ; $08
  18. ; ===========================================================================
  19.  
  20. Obj86_Main:             ; XREF: Obj86_Index
  21.         move.w  #$2588,8(a0)
  22.         move.w  #$53C,$C(a0)
  23.         move.w  #$300,2(a0)
  24.         move.l  #Map_obj86,4(a0)
  25.         move.b  #0,$1C(a0)
  26.         move.b  #3,$18(a0)
  27.         move.b  #8,$17(a0)
  28.         move.b  #8,$16(a0)
  29.         move.b  #4,1(a0)
  30.         bset    #7,1(a0)
  31.         addq.b  #2,$24(a0)  ; => "Obj86_Generator"
  32.  
  33. ; ===========================================================================
  34. Obj86_Generator:                ; XREF: Obj86_Index
  35.  
  36.         ; Check if generator should explode (when boss defeated)
  37.         movea.l $34(a0),a1  ; load FZ boss object
  38.         cmpi.b  #6,$34(a1)  ; is FZ boss at routine #6?
  39.         bne.s   @0      ; if not, branch
  40.         move.b  #$3F,(a0)   ; replace generator with explosion
  41.         move.b  #0,$24(a0)
  42.         jmp DisplaySprite
  43.  
  44. ;loc_1A850:
  45. @0      move.b  #0,$1C(a0)      ; use animation #0
  46.         tst.b   $29(a0)         ; create balls flag set?
  47.         beq.s   Obj86_ProcessGenerator  ; if not, branch
  48.         addq.b  #2,$24(a0)      ; => "Obj86_MakeBalls"
  49.         move.b  #1,$1C(a0)      ; use animation #1
  50.         move.b  #$3E,$28(a0)
  51.  
  52. ;loc_1A86C:
  53. Obj86_ProcessGenerator:
  54.         ; Make generator solid
  55.         move.w  #$13,d1
  56.         move.w  #8,d2
  57.         move.w  #$11,d3
  58.         move.w  8(a0),d4
  59.         jsr SolidObject
  60.  
  61.         ; Check if generator should be deleted (when Sonic goes too far from it)
  62.         move.w  ($FFFFD008).w,d0    ; d0 = Sonic.X
  63.         sub.w   8(a0),d0        ; d0 = Sonic.X - Obj.X
  64.         bmi.s   Obj86_Animate       ; if Sonic's on left side from generator, branch
  65.         subi.w  #$140,d0        ; d0 = Sonic.X - Obj.X - 320
  66.         bmi.s   Obj86_Animate       ; if Sonic hasn't gone too far from generator, branch
  67.         tst.b   1(a0)           ; is generator out of screen?
  68.         bpl.w   Obj84_Delete        ; if yes, delete it
  69.  
  70. ;loc_1A89A:
  71. Obj86_Animate:
  72.         ; Animate generator
  73.         lea Ani_obj86(pc),a1
  74.         jsr AnimateSprite
  75.         jmp DisplaySprite
  76. ; ===========================================================================
  77.  
  78. Obj86_MakeBalls:            ; XREF: Obj86_Index
  79.         tst.b   $29(a0)     ; have the balls been created?
  80.         beq.w   @WaitBalls  ; if yes, branch
  81.         clr.b   $29(a0)     ; set that the balls are created
  82.         add.w   $30(a0),d0
  83.         andi.w  #$1E,d0
  84.         adda.w  d0,a2
  85.         addq.w  #4,$30(a0)
  86.         clr.w   $32(a0)     ; clear current ball number
  87.         moveq   #3,d2
  88.  
  89. Obj86_Loop:
  90.         ; Create an energy ball
  91.         jsr SingleObjLoad2      ; create new object
  92.         bne.w   @WaitBalls      ; if couldn't create, branch
  93.         move.b  #$86,(a1)
  94.         move.w  8(a0),8(a1)     ; copy x-pos
  95.         move.w  #$53C,$C(a1)        ; set y-pos
  96.         move.b  #8,$24(a1)      ; => "Obj86_EnergyBall"
  97.         move.w  #$2300,2(a1)
  98.         move.l  #Map_obj86a,4(a1)
  99.         move.b  #$C,$16(a1)
  100.         move.b  #$C,$17(a1)
  101.         move.b  #0,$20(a1)
  102.         move.b  #3,$18(a1)
  103.         move.w  #$3E,$28(a1)
  104.         move.b  #4,1(a1)
  105.         bset    #7,1(a1)
  106.         move.l  a0,$34(a1)      ; save parent object's address
  107.         jsr (RandomNumber).l
  108.         move.w  $32(a0),d1      ; d1 = BallNumber
  109.         muls.w  #-$4F,d1        ; d1 = BallNumber * (-$4F)
  110.         addi.w  #$2578,d1       ; d1 = BallNumber * (-$4F) + GeneratorXPos
  111.         andi.w  #$1F,d0         ; d0 = 0..$1F (Random Number)
  112.         subi.w  #$10,d0         ; d0 = 0..$1F - $10
  113.         add.w   d1,d0           ; d1 = BallNumber * (-$4F) + GeneratorXPos + 0..$1F - $10
  114.         move.w  d0,$30(a1)      ; set it as TargetPos
  115.         addq.w  #1,$32(a0)
  116.         move.w  $32(a0),$38(a0)
  117.         dbf d2,Obj86_Loop   ; repeat sequence 3 more times
  118.  
  119. ;loc_1A954:
  120. @WaitBalls:
  121.         ; Wait until all balls take their position
  122.         tst.w   $32(a0)     ; have all the balls moved to it's position?
  123.         bne.s   @0      ; if not, branch
  124.         addq.b  #2,$24(a0)  ; => "Obj86_WaitBalls"
  125.  
  126. @0      bra.w   Obj86_ProcessGenerator
  127. ; ===========================================================================
  128.  
  129. ;loc_1A962:             ; XREF: Obj86_Index
  130. Obj86_WaitBalls:
  131.         move.b  #2,$1C(a0)  ; use animation #2
  132.         tst.w   $38(a0)     ; have all the balls gone?
  133.         bne.s   @0      ; if not, branch
  134.         move.b  #2,$24(a0)  ; => "Obj86_Generator"
  135.         movea.l $34(a0),a1
  136.         move.w  #-1,$32(a1)
  137. @0      bra.w   Obj86_ProcessGenerator
  138. ; ===========================================================================
  139.  
  140. ;loc_1A982:             ; XREF: Obj86_Index
  141. Obj86_EnergyBall:
  142.         moveq   #0,d0
  143.         move.b  $25(a0),d0
  144.         move.w  Obj86_Index2(pc,d0.w),d0
  145.         jsr Obj86_Index2(pc,d0.w)
  146.         lea Ani_obj86a(pc),a1
  147.         jsr AnimateSprite
  148.         jmp DisplaySprite
  149. ; ===========================================================================
  150. Obj86_Index2:   dc.w @SetSpeeds-Obj86_Index2
  151.         dc.w @MoveToPosition-Obj86_Index2
  152.         dc.w @MoveToSonic-Obj86_Index2
  153. ; ===========================================================================
  154.  
  155. ;loc_1A9A6:             ; XREF: Obj86_Index2
  156. @SetSpeeds:
  157.         move.w  $30(a0),d0  ; d0 = TargetPos
  158.         sub.w   8(a0),d0    ; d0 = TargetPos - StartPos
  159.         asl.w   #4,d0       ; d0 = (TargetPos - StartPos) / 16
  160.         move.w  d0,$10(a0)  ; Xvel = (TargetPos - StartPos) / 16
  161.         move.w  #$B4,$28(a0)    ; set timer to #180 (3 seconds)
  162.         addq.b  #2,$25(a0)  ; => "@MoveToPosition"
  163.         rts
  164. ; ===========================================================================
  165.  
  166. ;loc_1A9C0:             ; XREF: Obj86_Index2
  167. @MoveToPosition:
  168.         tst.w   $10(a0)     ; has the ball stopped?
  169.         beq.s   @0      ; if yes, branch
  170.         jsr SpeedToPos  ; move ball to its position
  171.         move.w  8(a0),d0    ; d0 = CurrentPos
  172.         sub.w   $30(a0),d0  ; d0 = CurrentPos - TargetPos
  173.         bcc.s   @0      ; if ball hasn't reached TagetPos, branch
  174.         clr.w   $10(a0)     ; stop the ball
  175.         add.w   d0,8(a0)    ; fix X-position
  176.         movea.l $34(a0),a1  ; load generator object
  177.         subq.w  #1,$32(a1)  ; mark this ball moved to its position
  178.  
  179. @0      move.b  #0,$1C(a0)  ; use animation #0
  180.         subq.w  #1,$28(a0)
  181.         bne.s   @1
  182.         addq.b  #2,$25(a0)  ; => "@MoveToSonic"
  183.         move.b  #1,$1C(a0)  ; use animation #1
  184.         move.b  #$9A,$20(a0)
  185.         move.w  #$B4,$28(a0)    ; set timer to #180 (3 seconds)
  186.         moveq   #0,d0
  187.         move.w  ($FFFFD008).w,d0    ; d0 = Sonic.X
  188.         sub.w   8(a0),d0        ; d0 = Sonic.X - Obj.X
  189.         move.w  d0,$10(a0)      ; make ball move towards Sonic
  190.         move.w  #$140,$12(a0)       ; make ball go down
  191.  
  192. @1      rts
  193. ; ===========================================================================
  194.  
  195. ;loc_1AA1E:             ; XREF: Obj86_Index2
  196. @MoveToSonic:
  197.         jsr SpeedToPos  ; move ball
  198.         cmpi.w  #$5E0,$C(a0)    ; has the ball gone down the floor?
  199.         bcc.s   @DeleteBall ; if yes, branch
  200.         subq.w  #1,$28(a0)  ; check timer
  201.         beq.s   @DeleteBall ; if timer over, branch
  202.         rts
  203. @DeleteBall:
  204.         movea.l $34(a0),a1  ; load generator object
  205.         subq.w  #1,$38(a1)  ; make the ball as gone
  206.         bra.w   Obj84_Delete
  207. ; ===========================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement