;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; LibMandew ; ; ; ; Contains: ; ; - MarioXSprite ; ; who will win?!?! ; ; - SpinJumpDeath ; ; Default handling for sprites ; ; being killed with Spin Jump ; ; - StompCombo ; ; Increases the stomp combo ; ; and gives appropriate points. ; ; - StarDeath ; ; Default handling for killing ; ; enemies with a star/while being ; ; invincible. ; ; - SubHorzPos ; ; Difference in position ; ; between Mario and the sprite. ; ; - ExplodeBomb ; ; A wrapper which changes the ; ; Data Bank to Bank 02 and ; ; calls the Sprite Explosion ; ; subroutine from the vanilla ; ; code. ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; MarioXSprite ; ; Checks to see whether Mario ; ; is bopping an enemy from above or not. ; ; ; ; Before Calling: ; ; - This routine does *not* ; ; check for contact. It will ; ; only work if contact was comfirmed ; ; beforehand. ; ; - Clipping values must be set ; ; correctly. Avoid tempering with ; ; scratch RAM beforehand. ; ; ; ; Output: ; ; Carry Flag SET : Mario won. ; ; Carry Flag CLEAR : The sprite won. ; ; ; ; Code taken and commentated from parts ; ; of the "Default Mario/Sprite Interactions ; ; Routine" at $01A83B ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MarioXSprite: ; Y Speed LDA !190F,x AND #$10 ; "Can be jumped on with upwards Y Speed" BNE .clippingCheck ; If the sprite can't be jumped on with upwards Y Speed... LDA $7D ; Checks Player Y Speed BMI .SpriteWins ; If it's going upwards (negative), ; the sprite wins no contest. .clippingCheck ; Clipping check LDA #$14 ; Displacement of 20 pixels STA $01 ; Applied to Mario's "Y-Displacement" LDA $05 ; $05 is the Sprite's Y-Displacement low byte SEC SBC $01 ; Get the difference between the two. ROL $00 ; Keeps the Carry #1 in Bit 0 of $00 CMP $D3 ; Comparing [$05 SEC:SBC $01 to $D3] ; ($D3 is the Player's Y Position. PHP ; Push Carry Flag #2 onto the Stack LSR $00 ; Returns Carry #1 to the Carry Flag LDA $0B ; Sprite's Y displacement High Byte SBC #$00 ; Carry operation PLP ; Pulls Carry Flag #2 SBC $D4 ; minus Player's Y Position, high byte BMI .SpriteWins ; Mario wins SEC ; Set Carry (means Mario won) RTL .SpriteWins CLC ; Clear Carry (means the Sprite won) RTL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; SpinJumpDeath ; ; Default handling for when ; ; enemies are killed with a spinjump. ; ; ; ; Copied and commentated from the disassembly ; ; at $01A91C -- but only contains ; ; the code that kills the sprite. ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SpinJumpDeath: LDA #$04 STA !14C8,x ; Sprite Status: Spin-jump killed LDA #$1F STA $1540,x ; Display smoke cloud for 31 frames. JSL $07FC3B ; Create Spin Jump stars effect LDA #$08 STA $1DF9|!base2 ; Play Sound Effect LDA #$D8 STA $7D ; adjust Player's Y speed RTL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; StompCombo ; ; ; ; Increases the stomp combo ; ; and gives appropriate points. ; ; ; ; Code taken from the disassembly ; ; at $01AB46 ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; StompCombo: PHB ; wrapper PHK PLB JSR .StompComboRt PLB RTL .StompComboRt PHY ; Push Y LDA $1697|!base2 ; load up combo meter CLC ADC !1626,x ; Tally on the sprite's own combo ; (in case it's a shell, for example) INC $1697|!base2 ; Increment the combo meter directly TAY ; Transfer Combo+Sprite combo tally INY ; to Y. And then increment Y by 1. CPY #$08 ; Have we reached Max Combo Potential? BCS .StompComboNoSFX ; Yeah? Then no SFX here. LDA ComboSFX,y STA $1DF9|!base2 ; Play SFX .StompComboNoSFX TYA CMP #$08 ; BCC + ; Max it out at #$08 LDA #$08 ; + JSL $02ACE5 ; give points PLY ; Pull Y RTS ComboSFX: db $60,$13,$14,$15,$16,$17,$18,$19 ; note: the First byte in this table will never be used. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; StarDeath ; ; ; ; Taken from $01A847 in the ; ; disassembly. ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; StarDeath: PHB ; wrapper PHK PLB JSR .StarDeathRt PLB RTL .StarDeathRt JSL $01AB6F ; Display graphical effect INC $18D2|!base2 ; Increase Star Combo LDA $18D2|!base2 CMP #$08 ; BCC + ; LDA #$08 ; Max out at 8 STA $18D2|!base2 ; + JSL $02ACE5 ; give points LDY $18D2|!base2 ; CMP #$08 ; BCS + ; LDA ComboSFX,y ; STA $1DF9|!base2 ; Play appropriate SFX + LDA #$02 ; Sprite Status = killed STA !14C8,x ; (falling off screen) LDA #$D0 ; Give some horizontal momentum STA !AA,x ; JSL SubHorzPos ; Give sprite's X speed depending LDA DATA_01A839,y ; on which side mario touched STA !B6,x ; it from. RTL DATA_01A839: db $F0,$10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; SubHorzPos ; ; Code which checks in which direction ; ; Mario is in relation to the sprite. ; ; ; ; From $01AD30 in the disassembly. ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SubHorzPos: LDY #$00 ; Defaults to Right LDA $D1 ; Mario X pos SEC SBC !E4,x ; difference with Sprite X pos STA $0F ; Put that difference here LDA $D2 SBC !14E0,x ; time for the high bytes BPL + INY ; if it's negative then it's left instead + RTL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; ExplodeBomb ; ; A wrapper which changes the ; ; Data Bank to Bank 02 and ; ; calls the Sprite Explosion ; ; subroutine from the vanilla ; ; code. ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ExplodeBomb: PHB ; Push Current Data Bank LDA #$02 PHA PLB ; Pull "#$02" as the current data bank JSL $028086 ; call the routine in vanilla PLB ; Pull back the appropriate data bank RTL