Advertisement
Erik557

Untitled

Jun 5th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;=======================================================================================================
  2. ; This patch installs a custom sprite handler in the unused sprite slots.
  3. ; To make the sprite work correctly make sure to tweak its priperties as in the CFG file! (with Tweaker)
  4. ; You can even replace normal sprites with this method, not sure why would you though.
  5. ;=======================================================================================================
  6. ; By Erik557
  7. ;=======================================================================================================
  8.  
  9. org $01E2B0         ; In case you're using this for something (you probably aren't), change it to org $01FFBF
  10. InitCustom:
  11.     JSL InitHandler         ; Jumps to the actual INIT handler in the new bank
  12.     RTS
  13.    
  14. MainCustom:
  15.     autoclean JSL MainHandler   ; Jumps to the actual MAIN handler in the new bank
  16.     RTS
  17.    
  18. ;step 2: point to the handlers
  19. org $0181A1             ;\
  20.     dw InitCustom       ; | Sprite 12
  21. org $0185F0             ; |
  22.     dw MainCustom       ;/
  23.  
  24. org $0181E9             ;\
  25.     dw InitCustom       ; | Sprite 36
  26. org $018638             ; |
  27.     dw MainCustom       ;/
  28.  
  29. org $01824F             ;\
  30.     dw InitCustom       ; | Sprite 69
  31. org $01869E             ; |
  32.     dw MainCustom       ;/
  33.  
  34. org $018287             ;\
  35.     dw InitCustom       ; | Sprite 85
  36. org $0186D6             ; |
  37.     dw MainCustom       ;/
  38.  
  39. org $01828D             ;\
  40.     dw InitCustom       ; | Sprite 88
  41. org $0186DC             ; | (winged cage, uncomment if you plan to use this)
  42.     dw MainCustom       ;/
  43.  
  44. org $0182A9             ;\
  45.     dw InitCustom       ; | Sprite 96
  46. org $0186F8             ; | (chargin' chuck, but it's a clone)
  47.     dw MainCustom       ;/
  48.    
  49. freecode
  50. InitHandler:
  51.     PHB                 ;\
  52.     PHK                 ; | Setup data bank
  53.     PLB                 ;/
  54.     LDA $9E,x           ; Pretty shitty code pointer (unlike the Bank 3 handler, this one can't be optimized)
  55.     CMP #$36            ;\ Sprite 36
  56.     BEQ .Sprite36       ;/
  57.     CMP #$69            ;\ Sprite 69
  58.     BEQ .Sprite69       ;/
  59.     CMP #$85            ; and so on...
  60.     BEQ .Sprite85
  61.     CMP #$88            ;\ If you commented sprite 88 in the above code, comment this one too.
  62.     BEQ .Sprite88       ;/
  63.     CMP #$96
  64.     BEQ .Sprite96
  65.     JSR InitSprite12    ; Sprite 12
  66. .Return
  67.     PLB                 ; Retrieve data bank
  68.     RTL
  69.  
  70. .Sprite36
  71.     JSR InitSprite36
  72.     BRA .Return
  73. .Sprite69
  74.     JSR InitSprite69
  75.     BRA .Return
  76. .Sprite85
  77.     JSR InitSprite85
  78.     BRA .Return
  79. .Sprite88
  80.     JSR InitSprite88
  81.     BRA .Return
  82. .Sprite96
  83.     JSR InitSprite96
  84.     BRA .Return
  85.  
  86. MainHandler:
  87.     PHB                 ;\
  88.     PHK                 ; | Setup data bank
  89.     PLB                 ;/
  90.     LDA $9E,x           ; This is the same as the above.
  91.     CMP #$36
  92.     BEQ .Sprite36
  93.     CMP #$69
  94.     BEQ .Sprite69
  95.     CMP #$85
  96.     BEQ .Sprite85
  97.     CMP #$88            ;\ If you commented sprite 88 in the above code, comment this one too.
  98.     BEQ .Sprite88       ;/
  99.     CMP #$96
  100.     BEQ .Sprite96
  101.     JSR MainSprite12
  102. .Return
  103.     PLB                 ; Retrieve data bank
  104.     RTL
  105.  
  106. .Sprite36
  107.     JSR MainSprite36
  108.     BRA .Return
  109. .Sprite69
  110.     JSR MainSprite69
  111.     BRA .Return
  112. .Sprite85
  113.     JSR MainSprite85
  114.     BRA .Return
  115. .Sprite88
  116.     JSR MainSprite88
  117.     BRA .Return
  118. .Sprite96
  119.     JSR MainSprite96
  120.     BRA .Return
  121.  
  122. incsrc SpriteCode.asm   ; This is the actual sprite code file.
  123.  
  124. =======================================================================================================================
  125. ;========================================================================
  126. ; The sprite code runs here.
  127. ; You should put the actual sprite code in here.
  128. ; Shared subroutines can be JSL'd to, I included imamelia's patch for it.
  129. ;========================================================================
  130. ; I included an example sprite, a venus fire plant.
  131. ;========================================================================
  132.  
  133.  
  134.     incsrc subroutinedefs.asm
  135.  
  136. ; Init sprite routines.
  137.    
  138. InitSprite12:
  139.     RTS
  140. InitSprite36:
  141.     LDA $E4,x
  142.     CLC
  143.     ADC #$08
  144.     STA $E4,x
  145.     DEC $D8,x
  146.     LDA $D8,x
  147.     CMP #$FF
  148.     BNE +
  149.     DEC $14D4,x
  150. +   RTS
  151. InitSprite69:
  152.     RTS
  153. InitSprite85:
  154.     RTS
  155. InitSprite88:
  156.     RTS
  157. InitSprite96:
  158.     RTS
  159.  
  160. ; Main sprite routines.
  161.  
  162. MainSprite12:
  163.     RTS
  164.  
  165. MainSprite36:
  166.     LDA $1594,x
  167.     BNE .LABEL24
  168.     LDA $64
  169.     PHA
  170.     LDA $15D0,x
  171.     BNE .LABEL23
  172.     LDA #$10
  173.     STA $64
  174. .LABEL23
  175.     JSR .SUB_GFX
  176.     PLA
  177.     STA $64
  178. .LABEL24
  179.     JSL !SubOffscreenX3
  180.     LDA $9D
  181.     BNE .RETURN27
  182.     LDA $1594,x
  183.     BNE .LABEL25
  184.     JSL $01803A
  185.  
  186. .LABEL25
  187.     JSR SUB_GET_X_DIFF
  188.     JSR SUB_GET_Y_DIFF
  189.                                        
  190.     LDA $C2,x
  191.     AND #$03
  192.     TAY
  193.     LDA $1540,x
  194.     BEQ .LABEL28
  195.     PHY
  196.     CPY #$02
  197.     BNE .NO_FIRE
  198.     JSR SUB_FIRE_THROW
  199. .NO_FIRE
  200.     PLY
  201.     LDA .Y_SPEED,y
  202.     STA $AA,x
  203.     JSL $01801A
  204. .RETURN27
  205.     RTS
  206. .LABEL28
  207.     LDA $C2,x
  208.     AND #$03
  209.     STA $00
  210.     BNE .LABEL29
  211.     JSR SUB_HORZ_POS1
  212.     LDA $0F
  213.     CLC
  214.     ADC #$1B
  215.     CMP #$37
  216.     LDA #$01
  217.     STA $1594,x
  218.     BCC .LABEL30
  219. .LABEL29
  220.     STZ $1594,x
  221.     LDY $00
  222.     LDA .TIME_IN_POS,y
  223.     STA $1540,x
  224.     INC $C2,x
  225. .LABEL30
  226.     RTS
  227.  
  228. .Y_SPEED
  229.     db $00,$F0,$00,$10
  230. .TIME_IN_POS
  231.     db $20,$68,$20,$48
  232.  
  233. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  234. ; graphics routine
  235. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  236.  
  237. .TILEMAP
  238.     db $CE,$80,$CE,$80
  239. .VERT_DISP
  240.     db $10,$00,$10,$00
  241. .PROPERTIES
  242.     db $08,$08,$08,$88
  243.  
  244. .SUB_GFX
  245.     JSL !GetDrawInfo
  246.  
  247.     LDA $151C,x
  248.     ASL A
  249.     STA $03
  250.     LDA $157C,x
  251.     AND #$01
  252.     STA $02
  253.     PHX
  254.  
  255.     LDX #$01
  256. .LOOP_START
  257.     PHX
  258.     TXA
  259.     ORA $03
  260.     PHA
  261.     LDA $00
  262.     STA $0300,y
  263.                        
  264.     PLX
  265.     LDA $01
  266.     CLC
  267.     ADC .VERT_DISP,x
  268.     STA $0301,y
  269.  
  270.     LDA .TILEMAP,x
  271.     STA $0302,y
  272.  
  273.     LDA .PROPERTIES,x
  274.     LDX $02
  275.     BNE .NO_FLIP
  276.     ORA #$40
  277. .NO_FLIP
  278.     ORA #$20
  279.     STA $0303,y
  280.  
  281.     TYA
  282.     LSR #2
  283.     TAX
  284.     LDA #$02
  285.     STA $0460,x
  286.                        
  287.     PLX
  288.     INY #4
  289.     DEX
  290.     BPL .LOOP_START
  291.  
  292.     PLX
  293.     LDY #$FF
  294.     LDA #$01
  295.     JSL $01B7B3
  296.     RTS
  297.  
  298.  
  299. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  300. ; fire spit routine
  301. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  302.  
  303. SUB_FIRE_THROW:
  304.     LDA $15A0,x
  305.     ORA $186C,x
  306.     BNE .LABEL6
  307. .ONE_SHOT
  308.     LDA $1540,x
  309.     CMP #$34
  310.     BEQ .SPIT
  311.     RTS
  312.  
  313. .SPIT
  314.     LDY #$E8
  315.     LDA $157C,x
  316.     AND #$01
  317.     BNE .LABEL9
  318.     LDY #$18
  319. .LABEL9
  320.     STY $00
  321.     LDY #$07
  322. .LABEL8
  323.     LDA $170B,y
  324.     BEQ .LABEL7
  325.     DEY
  326.     BPL .LABEL8
  327.     RTS
  328.  
  329. .LABEL7
  330.     LDA #$02
  331.     STA $170B,y
  332.  
  333.     LDA $E4,x
  334.     CLC
  335.     ADC #$05
  336.     STA $171F,y
  337.     LDA $14E0,x
  338.     ADC #$00
  339.     STA $1733,y
  340.  
  341.     LDA $D8,x
  342.     CLC
  343.     ADC #$05
  344.     STA $1715,y
  345.     LDA $14D4,x
  346.     ADC #$00
  347.     STA $1729,y
  348.  
  349.     PHX
  350.     LDA $151C,x
  351.     ASL #2
  352.     ORA $157C,x
  353.     TAX
  354.     LDA .Y_FIRE,x
  355.     STA $173D,y
  356.     PLX
  357.  
  358.     PHX
  359.     LDA $157C,x
  360.     TAX
  361.     LDA .X_FIRE,x
  362.     STA $1747,y
  363.     PLX
  364.  
  365. .LABEL6
  366.     RTS
  367.  
  368. .Y_FIRE
  369.     db $0C,$0C,$06,$06,$F4,$F4,$FA,$FA
  370. .X_FIRE
  371.     db $0C,$F4,$10,$F0
  372.  
  373. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  374. ; difference in y position
  375. ; sets 151C if mario is above plant
  376. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  377.  
  378. SUB_GET_Y_DIFF:
  379.     LDY #$00
  380.     LDA $D3
  381.     PHA
  382.     CLC
  383.     ADC #$10
  384.     STA $D3
  385.     LDA $D4
  386.     PHA
  387.     ADC #$00
  388.     STA $D4
  389.  
  390.     LDA $D3
  391.     SEC
  392.     SBC $D8,x
  393.     STA $0E
  394.     LDA $D4
  395.     SBC $14D4,x
  396.     BPL .LABEL14
  397.     INY
  398. .LABEL14
  399.     TYA
  400.     STA $151C,x
  401.                        
  402.     PLA
  403.     STA $D4
  404.     PLA
  405.     STA $D3
  406.                        
  407.     RTS
  408.  
  409.  
  410. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  411. ; difference in x position
  412. ; sets 157C to 00 through 03 depending on the relative position of mario to the plant
  413. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
  414.  
  415. SUB_GET_X_DIFF:
  416.     LDY #$00
  417.     LDA $D1
  418.     SEC
  419.     SBC $E4,x
  420.     STA $0F
  421.     LDA $D2
  422.     SBC $14E0,x
  423.     BPL .TO_RIGHT
  424. .TO_LEFT
  425.     INY
  426.     LDA $0F
  427.     CMP #$B0
  428.     BCS .SET_VAL
  429.     INY #2
  430.     BRA .SET_VAL
  431. .TO_RIGHT
  432.     LDA $0F
  433.     CMP #$50
  434.     BCC .SET_VAL
  435.     INY
  436.     INY
  437. .SET_VAL
  438.     TYA
  439.     STA $157C,x
  440.     RTS
  441.                    
  442. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  443. ; AD30 - horizontal mario/sprite check
  444. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  445.  
  446. SUB_HORZ_POS1:
  447.     LDY #$00
  448.     LDA $D1
  449.     SEC
  450.     SBC $E4,x
  451.     STA $0F
  452.     LDA $D2
  453.     SBC $14E0,x
  454.     BPL .TO_RIGHT2
  455.     INY
  456. .TO_RIGHT2
  457.     RTS
  458.                    
  459. MainSprite69:
  460.     RTS
  461. MainSprite85:
  462.     RTS
  463. MainSprite88:
  464.     RTS
  465. MainSprite96:
  466.     RTS
  467.    
  468. print "Sprite code found at $",pc
  469. print " ",bytes," bytes used."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement