Advertisement
Guest User

SMW ASM EXAMPLE

a guest
Aug 7th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. header
  2. lorom
  3. ; -------------------------------------------
  4. ; Patches
  5. ; -------------------------------------------
  6. ; Mushroom Item
  7. org $01C510
  8.     db $00, 00, 00, 00 ; Disable mushroom giveing item
  9. org $01C515
  10.     db $00 ; Disable flower giveing mushroom
  11. org $01C51C
  12.     db $00 ; Disable feather giveing mushroom
  13. org $01C524
  14.     db $00, 00, 00, 00 ; Mushroom always trys to make you big
  15. org $01C561
  16.     JML Mushroom    ; New Mushroom pickup code
  17. ; -------------------------------------------
  18. org $008F49 ; hijack status bar routine
  19. JSL new_routine ; for the hurt/heal routine
  20.  
  21. ; Status Bar
  22. org $8FC8   ; Change Mario/Luigi text to health
  23. JML Healthbar
  24.  
  25. org $05CC1A ;Get rid of Mario at course clear since we use that for other GFX.
  26.     db $FC,$2C,$FC,$2C,$FC,$2C,$FC,$2C,$FC,$2C
  27. org $05CC61 ;and do the same for Luigi (Though it's best to use this patch for one player)
  28.     db $FC,$FC,$FC,$FC,$FC
  29.  
  30. org $00D129 ; Eliminate powerdown animation and jump to flash routine
  31.     db $EA,$EA,$EA,$80
  32.  
  33. ;We disable the bonus star routine here so we can use it for HP!
  34. org $008F5E
  35.     nop #21
  36.  
  37. org $009E4B ;Disable bonus game if bonus stars are 100     
  38.     nop #3
  39. ;Patches to move the bonus star counter (from Aiyo's code)
  40. org $008F9D
  41.     nop #40
  42. org $009053
  43.      nop #3
  44. org $009068
  45.     nop #3
  46. ; -------------------------------------------
  47. ; Map Mode Code
  48. org $9E2C
  49. JML Newgame     ; When starting a new game from titlescreen
  50. NOP
  51. NOP
  52.  
  53. org $0491DB
  54. JML Startlevel  ; Whenever you enter a level
  55. NOP
  56.  
  57. org $A0E6
  58. JSL Endlevel    ; Whenever you go back to the map
  59. ; -------------------------------------------
  60. org $F606
  61. JML Death
  62.  
  63. org $00F5B3 ;if mario falls down a hole, reroute to new death routine.
  64.     db $06
  65.  
  66. org $F5D5
  67. JML Hit
  68. org $F5F8
  69. NOP         ; Disable item box getting used when hurt
  70. NOP
  71. NOP
  72. NOP
  73.  
  74. org $F600
  75. NOP         ; Disable power up takeing when hurt (we do this elsewhere)
  76. NOP
  77. ; -------------------------------------------
  78. org $8C89 ; Status bar rearangeing
  79.     db $FC, $2C, $3E, $2C, $3E, $2C, $3E, $2C, $3E, $2C, $3E, $2C, $3E, $2C, $3E, $2C
  80.     db $FC, $2C, $42, $38, $40, $38, $41, $38, $4A, $38, $FC, $38, $FC, $38, $4A, $78
  81.     db $76, $38, $26, $38, $FC, $38, $27, $3C, $27, $3C, $27, $3C, $FC, $38, $2E, $3C
  82.     db $26, $38, $FC, $38, $27, $38, $27, $38, $30, $38, $31, $38, $32, $38, $33, $38
  83.     db $FC, $38, $FC, $38, $FC, $38, $FC, $38, $43, $38, $27, $38, $27, $38, $4A, $38
  84.     db $FC, $38, $FC, $38, $4A, $78, $FC, $3C, $FC, $3C, $FC, $3C, $FC, $3C, $FC, $38
  85.     db $FC, $38, $FC, $38, $FC, $38, $FC, $38, $FC, $38, $FC, $38
  86. org $8E6F ; Time
  87.     LDA $0F31
  88.     STA $0F0C
  89.     LDA $0F32
  90.     STA $0F0D
  91.     LDA $0F33
  92.     STA $0F0E
  93. org $8E8C ; Score?
  94.     STA $0EFC,x
  95. org $8F55 ; Lives
  96.     STX $0F1E
  97.     STA $0F1F
  98. org $8FEF ; Dragon Coins
  99.     STA $0F24,x
  100. ; -------------------------------------------
  101. org $F2E0 ; Midway Point Healing/Powerup
  102.     JML Midwayheal
  103.     NOP
  104.     NOP
  105.     NOP
  106.     NOP
  107. ; -------------------------------------------
  108. org $0FFA01     ; address to put code
  109. ; -------------------------------------------
  110. db "STAR"       ; Write RATS tag
  111. dw Endcodeblock-Startcodeblock
  112. dw Endcodeblock-Startcodeblock^#$FFFF
  113. ; -------------------------------------------
  114. Startcodeblock:     ; code starts here
  115. ; -------------------------------------------
  116. ; defines
  117.  
  118. !Health = $0DC4
  119. !MaxHealth = $0DC5
  120. !MarioHealth = $0F44
  121. !LuigiHealth = $0F45
  122. !MarioHeartsFound = $1F2C
  123. !LuigiHeartsFound = $1F2D
  124. !Powerup = $19
  125. !MarioPowerup = $0DB8
  126. !LuigiPowerup = $0DB8
  127. !knockSpeed1 = $29
  128. !knockSpeed2 = $D7
  129.  
  130. ; -------------------------------------------
  131. Hit:
  132.  
  133. LDA #$38            ;play hurt
  134. STA $1DFc           ;sound
  135. LDA $0670           ;If user has set custom hit decrement
  136. CMP #$02            ;in cusom sprite contact routine
  137. BEQ custom_HP           ;skip default HP dealt.
  138. LDA #$01            ;set the hurt flag so we can dec HP
  139. STA $0670           ;in the heal/hurt routine
  140.  
  141. LDA #$14            ;set the inc/dec RAM
  142. STA $1900           ;to 20 in Hex
  143. custom_HP:
  144.     LDA !Powerup        ;Powerup is always      \
  145.     CMP #$01        ;big if not hurt        |
  146.     BMI Endhit      ;Branch to knocbkack    |-remove this block to keep current powerup
  147.     LDA #$01        ;Get rid of flower      |
  148.     STA !Powerup        ;or cape if you have them   /
  149. Endhit:             ;this is the knockback code
  150. LDA #!knockSpeed2
  151.     STA $7D
  152.    
  153.     LDA $76
  154.     BNE Other
  155.    
  156.     LDA #!knockSpeed1
  157.     STA $7B
  158.     BRA Next
  159.    
  160. Other:
  161.     LDA #!knockSpeed2
  162.     STA $7B
  163. Next:
  164. JML $00F5DD
  165. rtl
  166. ; -------------------------------------------
  167. Healthbar:
  168.     LDX #$08
  169.     HeathBarFillLoop:
  170.         TXA
  171.         CMP !Health
  172.         BPL Empty
  173.         Full:
  174.             LDA #$3F
  175.             BRA Set
  176.         Empty:
  177.             CMP !MaxHealth
  178.             BPL Blank
  179.             LDA #$3E
  180.             BRA Set
  181.         Blank:
  182.             LDA #$3D
  183.         Set:
  184.             STA $0EF8,x
  185.             DEX
  186.             BPL HeathBarFillLoop
  187.  
  188.     JML $008FD8
  189.  
  190. ; -------------------------------------------
  191. Mushroom:
  192.  
  193. STZ $0670       ;Zero the hurt flag. A well timed shroom can save your life!
  194. LDA #$0A        ;Play mushroom sound
  195. STA $1dF9
  196. LDA #$14        ;set the HP inc/dec RAM
  197. STA $1900       ;to 20
  198.  
  199. LDA $0F48       ;If HP is 99
  200. CMP #$63        ;Check to see if health bar is full
  201. BMI nocheckitem     ;otherwise return
  202. LDA $0DC4       ;Is health bar
  203. CMP $0DC5       ;Full?
  204. BPL checkitem       ;if not, check for item
  205. nocheckitem:
  206. JML $01C608
  207. checkitem:
  208. LDA $0DC2       ;item in the box
  209. CMP #$00        ;No?
  210. BNE Endmush     ;if so, return
  211. LDA #$01        ;if not, and HP+health are full
  212. STA $0DC2       ;put a mushroom in the box
  213. Endmush:
  214. JML $01C608
  215. ; -------------------------------------------
  216. Newgame:
  217.  
  218.     STA $0DBE
  219.     STZ $0DBF  
  220.     LDX $0DB2
  221.     STZ !Health
  222.     STZ !MaxHealth
  223.     LDA #$01
  224.     STA !Powerup ; Start big
  225.     LDA #$63
  226.     STA $0F48
  227.     STA $0DB8
  228.     STA $0DB9
  229.     STZ $0DC1
  230.     JML $009E37
  231. ; -------------------------------------------
  232. Startlevel:
  233.     PHY
  234.     LDY #$01
  235.     LDA #$01
  236.         BitCount:
  237.         BIT !MarioHeartsFound,x
  238.         BEQ NotSet
  239.         INY
  240.         NotSet:
  241.         ROL
  242.         BCC BitCount
  243.     STY !MaxHealth
  244.     LDA !MarioHealth,x
  245.     BNE HasHealth
  246.     TYA
  247.     STA !MarioHealth,x
  248.     HasHealth:
  249.     STA !Health
  250.     PLY
  251.     LDA #$02
  252.     STA $0DB1
  253.     JML $0491E0
  254. ; -------------------------------------------
  255. Endlevel:
  256.     LDA !MaxHealth ; Skip this on init
  257.     BEQ .Skip
  258.     LDA !Health
  259.     BNE .Alive
  260.     .Dead
  261.         LDA #$01
  262.         STA !Powerup
  263.         STA !MarioPowerup,x
  264.         LDA #$63        ;Most metroid games start with 30 HP after death
  265.         STA $0F48       ;Change value here to #$1E for 30, otherwise, we do 99
  266.         LDA #$01        ;Full tanks after death -1. Metroid does 0
  267.         STA !Health     ;Change #$01 to $0DC5 to do all tanks full.
  268.  
  269.     .Alive
  270.         STA !MarioHealth,x
  271. ;LDA $19
  272. ;BEQ .dead
  273.     .Skip
  274.         LDA #$03
  275.         STA $44
  276.         RTL
  277. ; -------------------------------------------
  278. Midwayheal:
  279.  
  280.         LDA !MaxHealth      ;midway points heal you fully
  281.         STA !Health     ;add semicolons to these to lines to use just the next two
  282.         LDA #$63        ;This heals HP to 99
  283.         STA $0F48       ;Semicolon these two to just heal all health bars
  284.     JML $00F2E8
  285.  
  286. ;--------------------------
  287. ; Hurt and Heal code + new status bar stuff
  288. ;------------------------
  289. new_routine:
  290.         PHX                         ;> Save whatever's in X for later
  291.         LDA $0F48               ;\ Load HP (stars)
  292.         JSL HexToDec            ;| Jump to HEX->DEC converter
  293.         STA $0F1B               ;| store ones into status bar
  294.         STX $0F1A           ;| store tens into status bar
  295. PLX
  296.  
  297. LDA $0670       ;If hurt flag
  298. CMP #$00        ;is set
  299. BNE hurt            ;then go to decrease routine
  300.  
  301. LDA $1900       ;If bonus star inc/dec RAM is zero
  302. BEQ stop            ;then stop
  303.  
  304. LDA $0DC4       ;If health
  305. CMP $0DC5       ;isn't equal to MaxHealth
  306. BMI dontcheck       ;don't check for Max HP
  307. LDA $0F48       ;If HP counter
  308. CMP #$63        ;is 99
  309. BEQ stop2           ;jump to zero increase flag
  310. BRA increasing      ;otherwise, increase HP
  311. dontcheck:
  312. LDA $0F48       ;If HP counter
  313. CMP #$64        ;is 100
  314. BPL reset           ;Jump to rollover code
  315. increasing:
  316. LDA $14         ;increase
  317. AND #$00        ;HP
  318. BNE stop            ;every
  319. INC $0F48       ;frame
  320. DEC $1900       ;and decrease the inc/dec flag, too.
  321. BRA stop            ;and stop.
  322. reset:
  323. LDA $0DC4       ;if health
  324. CMP $0DC5       ;is full
  325. BPL dontinc     ;don't increase health bar
  326. INC $0DC4       ;otherwise, increase with HP rollover
  327. dontinc:
  328. STZ $0F48       ;zero HP for rollover
  329. BRA stop
  330. stop2:
  331. STZ $1900       ;Zero the inc/dec flag if Max HP and health
  332. stop:
  333. lda $0dbe
  334. inc
  335. RTL
  336.  
  337. hurt:
  338.  
  339. LDA $1900       ;if the inc/dec flag is zero
  340. BEQ stop3       ;then stop decreasing HP
  341. LDA $0F48       ;If the HP
  342. CMP #$01        ;is less than 1
  343. BMI remove      ;rollover and remove a health bar
  344.  
  345. LDA $14         ;decrease
  346. AND #$00        ;HP
  347. BNE stop3       ;every
  348. DEC $0F48       ;frame
  349. DEC $1900       ;and decrease the inc/dec flag, too.
  350.  
  351. BRA stop3       ;and zero the hurt flag
  352. remove:
  353. LDA $0DC4       ;if the health bar is zero
  354. CMP #$01
  355. BEQ Death       ;and HP is too, kill Mario.
  356. DEC $0DC4       ;otherwise, decrease health bar with rollover
  357. LDA #$64        ;set new rollover
  358. STA $0F48       ;to 99
  359. stop3:
  360. LDA $1900       ;stop the inc/dec flag
  361. BNE nozero
  362. STZ $0670       ;zero the hurt flag
  363. nozero:
  364. lda $0dbe
  365. inc
  366. RTL
  367.  
  368. Death:
  369. STZ $0670
  370. STZ $1900
  371. STZ $0F48
  372. STZ $0DC4
  373. LDA #$09
  374. STA $1DFB
  375.  
  376. LDA #$90
  377. STA $7d
  378. JML $00F60F
  379. lda $0dbe
  380. inc
  381. RTL
  382.  
  383. HexToDec:                                    ;HEX->DEC converter
  384.                      LDX #$00                ;> Set X to 0
  385.                      LDY #$00                ;> Set Y to 0
  386. StartCompare1:
  387.                      CMP #$64                ;\
  388.                      BCC StartCompare2       ; |While A >= 100:
  389.                      SBC #$64                ; |Decrease A by 100
  390.                      INY                     ; |Increase Y by 1
  391.                      BRA StartCompare1       ;/
  392. StartCompare2:
  393.                      CMP #$0A                ;\
  394.                      BCC ReturnLong          ; |While A >= 10:
  395.                      SBC #$0A                ; |Decrease A by 10
  396.                      INX                     ; |Increase X by 1
  397.                      BRA StartCompare2       ;/
  398. ReturnLong:
  399.                      RTL
  400. ; -------------------------------------------
  401. Endcodeblock:       ; code ends here   
  402. ; -------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement