Advertisement
Guest User

BlueKoopa SA1

a guest
Aug 6th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;=============================================================
  2. ; Blue Parakoopa
  3. ; Description: A parakoopa that flies on a circular style.
  4. ;
  5. ; Uses first extra bit: YES
  6. ; If the extra bit is clear, the sprite will rotate clockwise,
  7. ; and if it's set, it will rotate counterclockwise.
  8. ;=============================================================
  9. ; By Erik557
  10. ; Based on Alcaro's works, though I used none of his code.
  11. ;=============================================================
  12.  
  13.        !Radius = $20        ; radius of the circle
  14.  
  15. ;=================================
  16. ; INIT and MAIN Wrappers
  17. ;=================================
  18. ; !C2   xlow    those 4 tables will be used to preserve location
  19. ; !1504 xhigh
  20. ; !1510 ylow
  21. ; !160E yhigh
  22. print "INIT ",pc
  23.        JSL $01ACF9          ;\ Get starting frame
  24.        STA !1570,x          ;/
  25.        %SubHorzPos()        ;\
  26.        TYA                  ; | Face player
  27.        STA !157C,x          ;/
  28.  
  29.        LDA #!Radius         ;\ set ball n' chain radius
  30.        STA !1594,x          ;/
  31.        STZ !151C,x          ;\ !151C is the high byte
  32.        STZ !1FD6,x          ;/ !1FD6 is the low byte
  33.     LDA #$FF
  34.         STA !C2,x
  35.         STA !1504,x
  36.         STA !1510,x
  37.         STA !160E,x
  38. RTL
  39.  
  40. print "MAIN ",pc
  41.        PHB : PHK : PLB      ; set data bank
  42.        JSR Override
  43.        LDA !14C8,x
  44.        CMP #$07
  45.        BEQ YoshiSwallow
  46.        JSR BlueParatroopa   ; Main Routine
  47.        PLB                  ; restore
  48. RTL
  49.  
  50. ;========================
  51. ; Main routine
  52. ;========================
  53. Override:
  54.     LDY #$01    ; number of states to override -1
  55.     LDA !14C8,x
  56. -
  57.     CMP .states,y
  58.     BEQ .override
  59.     DEY
  60.     BPL -
  61.     LDA !7FAB34,x
  62.     AND #$7F
  63.     STA !7FAB34,x
  64.     RTS
  65. .states         ; statuses to override (including 08)
  66.     db $07,$08
  67. .override
  68.     LDA !7FAB34,x
  69.     ORA #$80
  70.     STA !7FAB34,x
  71.     RTS
  72. YoshiSwallow:
  73.     LDA #$06
  74.            STA !9E,x
  75.     JSL $07F7D2
  76.     LDA #$07
  77.            STA !14C8,x
  78.     PLB
  79.     RTL
  80. DrawGFX:                    ;\ Draw the sprite
  81.        PHB                  ; |\
  82.        LDA #$01             ; | | set data bank to 01
  83.        PHA                  ; | |
  84.        PLB                  ; |/
  85.        PHK                  ; |\
  86.        PEA.w .drawn-1       ; | | jsl to 018bc3
  87.        PEA.w $0180CA-1      ; | |
  88.        JML $018BC3          ; |/
  89. .drawn                      ;/
  90.        PLB                  ; restore data bank
  91.        RTS                  ; return
  92.  
  93. BlueParatroopa:
  94.        LDY #$00
  95.        %SubOffScreen()
  96.        LDA $9D
  97.        BNE .LockedSprites
  98.  
  99. .NotTurning
  100.        INC !1570,x          ;\
  101.        LDA !1570,x          ; |
  102.        LSR #3               ; | set animation frame
  103.        AND #$01             ; |
  104.        STA !1602,x          ;/
  105.  
  106.        LDA $14
  107.        AND #$01
  108.        BNE .LockedSprites
  109.  
  110.        LDA !7FAB10,x        ;\ use extra bits to determine direction of rotation
  111.        LDY #$04             ; | (original uses sprite x position)
  112.        AND #$04             ; |
  113.        BNE .CounterClock    ; |
  114.        LDY #$FC             ; |
  115. .CounterClock               ; |
  116.        TYA                  ; |
  117.        LDY #$00             ; |
  118.        CMP #$00             ; |
  119.        BPL +                ; |
  120.        DEY                  ;/
  121. +      CLC                  ;\ update angle depending on direction of rotation
  122.        ADC !1FD6,x          ; | !1602,x is used to store the low byte of the ball n' chain angle
  123.        STA !1FD6,x          ; |
  124.        TYA                  ; |
  125.        ADC !151C,x          ; | and !151C,x for the high byte
  126.        AND #$01             ; |
  127.        STA !151C,x          ; |
  128. .LockedSprites
  129.        LDA !151C,x          ; |
  130.        STA $01              ; | $00-$01 = ball n' chain angle
  131.        LDA !1FD6,x          ; |
  132.        STA $00              ;/
  133.  
  134.        REP #$30             ; set 16-bit mode for accumulator and registers
  135.  
  136.        LDA $00              ;\ $02-$03 = ball n' chain angle + 90 degrees
  137.        CLC                  ; |
  138.        ADC #$0080           ; |
  139.        AND #$01FF           ; |
  140.        STA $02              ;/
  141.  
  142.        LDA $00              ;\ $04-$05 = cosines of ball n' chain angle
  143.        AND #$00FF           ; |
  144.        ASL                  ; |
  145.        TAX                  ; |
  146.        LDA $07F7DB,x        ; | this is SMW's trigonometry table
  147.        STA $04              ;/
  148.  
  149.        LDA $02              ;\ $06-$07 = cosines of ball n' chain angle + 90 degrees = sines for ball n' chain angle
  150.        AND #$00FF           ; |
  151.        ASL                  ; |
  152.        TAX                  ; |
  153.        LDA $07F7DB,x        ; |
  154.        STA $06              ;/
  155.  
  156.        SEP #$30             ; set 8-bit mode for accumulator and registers
  157.  
  158.        LDX $15E9|!Base2            ; get sprite index
  159.        PHA
  160.        XBA
  161.        BEQ .NotFlip
  162.  
  163.        LDA !15AC,x          ;\ don't turn is this is already set
  164.        BNE .NotFlip         ;/
  165.        LDA #$08            
  166.        STA !15AC,x
  167.        LDA !157C,x
  168.        EOR #$01
  169.        STA !157C,x
  170. .NotFlip
  171. if !SA1 = 1
  172.         PLA
  173.         LDY $05
  174.         BNE .NoMultCos
  175.         STZ $09
  176.         LDA !1594,x
  177.         STZ $08
  178.         STZ $2250
  179.         LDA $04
  180.         STA $2251
  181.         LDA $08
  182.         STA $2253
  183.         STZ $2254
  184.         NOP : BRA $00
  185.         ASL $2306
  186.         LDA $2307
  187.         ADC #$00
  188. .NoMultCos
  189.         LSR $01
  190.         BCC .NotInvertCos
  191.         EOR #$FF
  192.         INC
  193. .NotInvertCos
  194.         STA $04
  195.         LDY $07
  196.         BNE .NoMultSin
  197.         STZ $09
  198.         LDA !1594,x
  199.         STZ $08
  200.         STZ $2250
  201.         LDA $06
  202.         STA $2251
  203.         LDA $08
  204.         STA $2253
  205.         STZ $2254
  206.         NOP : BRA $00
  207.         ASL $2306
  208.         LDA $2307
  209.         ADC #$00
  210. .NoMultSin
  211.         LSR $03
  212.         BCC .NotInvertSin
  213.         EOR #$FF
  214.         INC
  215. .NotInvertSin
  216.         STA $06
  217.  
  218. else
  219.        PLA
  220.        LDA $04              ;\ multiply the cosine...
  221.        STA $4202            ; |
  222.        LDA !1594,x          ; |
  223.        LDY $05              ; |\ if $05 is 1, no need to do the multiplication
  224.        BNE .NoMultCos       ; |/
  225.        STA $4203            ; | ...with radius of circle (!1594,x)
  226.        NOP #4               ;/ waste some cycles while the result is calculated
  227.        ASL $4216            ; Product/Remainder Result (Low Byte)
  228.        LDA $4217            ; Product/Remainder Result (High Byte)
  229.        ADC #$00      
  230. .NoMultCos
  231.        LSR $01              ;\ if the high byte of the angle was set...
  232.        BCC .NotInvertCos    ; |
  233.        EOR #$FF             ; | ...then invert the cosine
  234.        INC                  ;/
  235. .NotInvertCos
  236.        STA $04              
  237.  
  238.        LDA $06              ;\ multiply the sine...
  239.        STA $4202            ; |
  240.        LDA !1594,x          ; |
  241.        LDY $07              ; |\ if $07 is 1, no need to do the multiplication
  242.        BNE .NoMultSin       ; |/
  243.        STA $4203            ; | ...with raidus of circle (!1594,x)
  244.        NOP #4               ;/ waste some cycles while the result is calculated
  245.        ASL $4216            ; Product/Remainder Result (Low Byte)
  246.        LDA $4217            ; Product/Remainder Result (High Byte)
  247.        ADC #$00      
  248. .NoMultSin
  249.        LSR $03              ;\ if the high byte of the angle was set...
  250.        BCC .NotInvertSin    ; |
  251.        EOR #$FF             ; | ...then invert the sine
  252.        INC                  ;/            
  253. .NotInvertSin
  254.        STA $06              
  255. endif
  256.     LDA !15D0,x ; Am I being eaten?
  257.     BEQ .NotEaten
  258.     JSR DrawGFX          ; GFX routine
  259.     RTS
  260. .NotEaten
  261.  
  262. ;;;START CIRCLE
  263.     ; at first, primary will hold center, and seconary will hold #$FF.
  264.     ; but after then, primary will hold tangential, and secondary will hold center.
  265.     ; here will assign the primary = secondary;
  266. ; !E4 = !C2 xlow    those 4 tables will be used to preserve location
  267. ; !14E0 = !1504 xhigh
  268. ; !D8 = !1510   ylow
  269. ; !14D4 !160E   yhigh
  270.     LDA !C2,x
  271.     AND !1504,x
  272.     AND !1510,x
  273.     AND !160E,x
  274.     CMP #$FF
  275.     BEQ .DontUseSecondary
  276.  
  277.     LDA !1504,x          ;\ Primary location will hold center.
  278.     STA !14E0,x                 ; |
  279.     LDA !C2,x            ; |
  280.     STA !E4,x                 ; |
  281.     LDA !160E,x          ; |
  282.     STA !14D4,x                 ; |
  283.     LDA !1510,x             ; |
  284.     STA !D8,x                ;/
  285.     BRA .StartCircle
  286. .DontUseSecondary
  287.        LDA !14E0,x          ;\  Now Secondary location will hold center.
  288.        STA !1504,x                 ; |
  289.        LDA !E4,x            ; |
  290.        STA !C2,x                 ; |
  291.        LDA !14D4,x          ; |
  292.        STA !160E,x                 ; |
  293.        LDA !D8,x            ; |
  294.        STA !1510,x                 ;/
  295. .StartCircle
  296.        STZ $00              ;\
  297.        LDA $04              ; |   x offset low byte
  298.        BPL +                ; |
  299.        DEC $00              ; |
  300. +      CLC                  ; |
  301.        ADC !E4,x            ; | + x position of rotation center low byte
  302.        STA !E4,x            ;/  = sprite x position low byte
  303.  
  304.        PHP                  ;\
  305.        PHA                  ; |
  306.        SEC                  ; |
  307.        SBC !1534,x          ; |
  308.        STA !1528,x          ; |
  309.        PLA                  ; |
  310.        STA !1534,x          ; |
  311.        PLP                  ;/
  312.  
  313.        LDA !14E0,x          ;\    x position of rotation center high byte
  314.        ADC $00              ; | + adjustment for screen boundaries
  315.        STA !14E0,x          ;/  = x position of sprite high byte
  316.  
  317.        STZ $01              ;\
  318.        LDA $06              ; |   y offset low byte
  319.        BPL +                ; |
  320.        DEC $01              ; |
  321. +      CLC                  ; |
  322.        ADC !D8,x            ; | + y position of rotation center low byte
  323.        STA !D8,x            ;/  = sprite y position low byte
  324.  
  325.        LDA !14D4,x          ;\    y position of center of rotation high byte
  326.        ADC $01              ; | + adjustment for screen boundaries
  327.        STA !14D4,x          ;/  = sprite y position high byte
  328.  
  329.        JSR DrawGFX          ; GFX routine
  330.        JSL $018032          ; interact with sprites
  331.  
  332.        JSL $01A7DC          ;\
  333.        BCS .Int             ; | interact with mario
  334. -      JMP .ReturnInteract  ;/ if not in contact, return
  335.  
  336. .Int
  337.        LDA $9D
  338.        BNE -
  339.  
  340.        LDA $1490|!Base2
  341.        BEQ +
  342.        JMP .Star
  343.  
  344. +
  345.  
  346.     JSR CapeCollision
  347.     BNE .Cape
  348.  
  349.  
  350.        LDA $0E
  351.        CMP #$E6
  352.        BMI +
  353.        JMP .Hurt
  354.  
  355. +      JSL $01AB99
  356.  
  357.        LDA $140D|!Base2
  358.        ORA $187A|!Base2
  359.        BEQ +
  360.        JMP .SpinKill
  361.  
  362. +      JSL $01AA33
  363.        LDA #$06
  364.        STA !9E,x
  365.        LDA !15F6,x
  366.        AND #$0E
  367.        STA $0D
  368.        JSL $07F7D2
  369.        LDA !15F6,x
  370.        AND #$F1
  371.        ORA $0D
  372.        STA !15F6,x
  373.        STZ $AA,x
  374.  
  375.        PHY
  376.        LDA $1697|!Base2
  377.        CLC
  378.        ADC !1626,x
  379.        INC $1697|!Base2
  380.        TAY
  381.        INY
  382.        CPY #$08
  383.        BCS +
  384.        LDA KillSFX,y
  385.        STA $1DF9|!Base2
  386. +      TYA
  387.        CMP #$08
  388.        BCC +
  389.        LDA #$08
  390. +      JSL $02ACE5
  391.        PLY
  392.  
  393.        RTS
  394.  
  395. .Cape
  396.  
  397.        LDA $0E
  398.        CMP #$35
  399.        BEQ +
  400.        JSL $01AB6F
  401.  
  402. +      LDA #$00
  403.        JSL $02ACE5
  404.        LDA #$09
  405.        STA !14C8,x
  406.        ASL !15F6,x
  407.        SEC
  408.        ROR !15F6,x
  409.        LDA #$06
  410.        STA !9E,x
  411.        JSL $07F7D2
  412.  
  413.        LDA #$FF
  414.        STA !1540,x
  415.        STZ !1558,x
  416.        LDA #$C0
  417.        LDY $0E
  418.        BEQ +
  419.        LDA #$B0
  420.        CPY #$02
  421.        BNE +
  422.        LDA #$C0
  423. +      STA !AA,x
  424.  
  425.        %SubHorzPos()
  426.        LDA StunSpeeds,y
  427.        STA !B6,x
  428.        TYA
  429.        EOR #$01
  430.        STA !157C,x
  431.        BRA .ReturnInteract
  432.  
  433. .Hurt
  434.        JSL $00F5B7
  435.        LDX $15E9|!Base2
  436.        %SubHorzPos()
  437.        TYA
  438.        STA !157C,x
  439.        BRA .ReturnInteract
  440.  
  441. .SpinKill
  442.        LDA #$04
  443.        STA !14C8,x
  444.        LDA #$08
  445.        STA $1DF9|!Base2
  446.        JSL $07FC3B
  447.        LDA #$F8
  448.        STA $7D
  449.  
  450. .ReturnInteract
  451.        LDX $15E9|!Base2
  452.        RTS                  ; return
  453. ;;; END CIRCLE
  454. .Star
  455.        JSL $01AB6F
  456.        INC $18D2|!Base2
  457.        LDA $18D2|!Base2
  458.        CMP #$08
  459.        BCC +
  460.        LDA #$08
  461.        STA $18D2|!Base2
  462. +      JSL $02ACE5
  463.        LDY $18D2|!Base2
  464.        CPY #$08
  465.        BCS +
  466.        LDA KillSFX,y
  467.        STA $1DF9|!Base2
  468. +      LDA #$02
  469.        STA !14C8,x
  470.        LDA #$D0
  471.        STA !AA,x
  472.        %SubHorzPos()
  473.        LDA KillSpeeds,y
  474.        STA !B6,x
  475.        LDA #$04
  476.        STA !9E,x
  477.        RTS
  478.  
  479. KillSFX:
  480.        db $00,$13,$14,$15,$16,$17,$18,$19
  481. KillSpeeds:
  482.        db $F0,$10
  483. StunSpeeds:
  484.        db $F8,$08
  485.        
  486. ;==================
  487.   CapeCollision:
  488. ;==================
  489.  
  490.        LDA $13E8|!Base2
  491.        BEQ .NoContact
  492.        LDA !15D0,x
  493.        ORA !1FE2,x
  494.        BNE .NoContact
  495.        LDA !1632,x
  496.        PHY
  497.        LDY $74
  498.        BEQ +
  499.        EOR #$01
  500. +      PLY
  501.        EOR $13F9|!Base2
  502.        BNE .NoContact
  503.        JSL $03B69F
  504.        LDA $13E9|!Base2
  505.        SEC
  506.        SBC #$02
  507.        STA $00
  508.        LDA $13EA|!Base2
  509.        SBC #$00
  510.        STA $08
  511.        LDA #$14
  512.        STA $02
  513.        LDA $13EB|!Base2
  514.        STA $01
  515.        LDA $13EC|!Base2
  516.        STA $09
  517.        LDA #$10
  518.        STA $03
  519.        JSL $03B72B
  520.        BCC .NoContact
  521.        LDA #$01
  522. .NoContact
  523.        LDA #$00
  524.        RTS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement