Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.04 KB | None | 0 0
  1. ;@xkas
  2.  
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ;;
  5. ;; Alternate Yoshi Coin Counter, by imamelia
  6. ;;
  7. ;; This patch installs a numerical Yoshi coin counter on the status bar that replaces
  8. ;; the normal one. It is 3 digits, so it can go up to 999. The coins also save to SRAM,
  9. ;; so each coin can be collected only once. But please read the readme.
  10. ;;
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12.  
  13. header
  14. lorom
  15.  
  16. !Freespace = $218000
  17.  
  18. !RAM_TotalYCoins = $7F9C80 ; the total number of Yoshi coins that have been collected (16-bit)
  19. !SRAM_TotalYCoins = $7003FA ; SRAM for the total number of Yoshi coins that have been collected (6 bytes)
  20. !RAM_CoinFlags = $7FB600 ; flags for each individual coin, 0x600 bytes' worth of free RAM
  21. !SRAM_CoinFlags = $700E00 ; SRAM for the coin flags, 0x600 bytes per file (0x1200 bytes total)
  22. !OWLevel = $13BF ; the current overworld level
  23. ; (should be changed only if you are using the Extra Overworld Level RAM patch)
  24. !Points = $0A ; the points/lives to give for each Yoshi coin before the last
  25. !Points2 = $0D ; the points/lives to give for the last Yoshi coin
  26. ; 00 = 0, 01 = 10, 02 = 20, 03 = 40, 04 = 80, 05 = 100, 06 = 200, 07 = 400, 08 = 800, 09 = 1000,
  27. ; 0A = 2000, 0B = 4000, 0C = 8000, 0D = 1-Up, 0E = 2-Up, 0F = 3-Up, 10 = 5-Up (may glitch)
  28. !SBDigit1 = $0F01 ; the position of the ones digit on the status bar (can be 24-bit)
  29. !SBDigit10 = $0F00 ; the position of the tens digit on the status bar (can be 24-bit)
  30. !SBDigit100 = $0EFF ; the position of the hundreds digit on the status bar (can be 24-bit)
  31. !SBCoin = $0EFE ; the position of the coin symbol on the status bar (can be 24-bit)
  32.  
  33. org $008FD8 ; the routine that draws Yoshi coins onto the status bar
  34. JML YCoinStatusBar ;
  35.  
  36. org $00F343 ; the routine that increments the Yoshi coin counter and resets it if necessary
  37. JML YCoinNumber ;
  38.  
  39. org $00F377 ; the routine that gives you an extra life when you have enough Yoshi coins
  40. JML YCoinLives ;
  41.  
  42. org $0DB2CA ; the routine that creates the Yoshi coin object in the first place
  43. JML YCoinObject ;
  44.  
  45. org $009D22 ; part of the load game routine
  46. JML LoadCoinFlags ;
  47.  
  48. org $009BD2 ; part of the save game routine
  49. JML SaveCoinFlags ;
  50.  
  51. org $00A5F3
  52. JML ClearSRAM ; clear the coin flags in SRAM
  53. NOP #2 ;
  54.  
  55. org $00FFD8 ; SRAM size
  56. db $08 ; expand the SRAM to $700000-$701FFF
  57.  
  58. org !Freespace
  59.  
  60. reset bytes
  61.  
  62. db "STAR"
  63. dw EndCode-StartCode-$01
  64. dw EndCode-StartCode-$01^$FFFF
  65.  
  66. StartCode:
  67.  
  68. YCoinStatusBar:
  69.  
  70. REP #$20 ; set A to 16-bit mode
  71. LDA !RAM_TotalYCoins ; take the total number of Yoshi coins collected
  72. PHX ;
  73. PHY ;
  74. JSR HexToDecLong ; and convert it to decimal
  75. STA !SBDigit1 ; store the ones digit
  76. CPX #$00 ; if the hundreds digit is 0...
  77. BNE NotZero ;
  78. LDX #$FC ; make it a space instead
  79. CPY #$00 ; if the tens digit is 0...
  80. BNE NotZero ;
  81. LDY #$FC ; make it a space instead
  82. NotZero: ;
  83. TYA ;
  84. STA !SBDigit10 ; store the tens digit
  85. TXA ;
  86. STA !SBDigit100 ; store the hundreds digit
  87. PLY ;
  88. PLX ;
  89. LDA #$2E ; store the coin symbol
  90. STA !SBCoin ; (you can comment out these two lines if you don't want it there)
  91. JML $008FF9 ;
  92.  
  93. YCoinLives: ;
  94.  
  95. PHX ; preserve the contents of X
  96. PHY ; and Y
  97. PHB ;
  98. PHK ;
  99. PLB ;
  100. LDY #!Points ; default point value
  101. LDX !OWLevel ; load the overworld level
  102. LDA $1422 ; check the current number of Yoshi coins collected
  103. CMP TotalNumber,x ; if it has not reached the total number in the level...
  104. BCC LessThanTotal ; use the default point value
  105. LDY #!Points2 ; if all of them have been collected, use the other point value
  106. LessThanTotal: ;
  107. CPY #$00 ; if the point value is 0...
  108. BEQ NoPoints ; don't give any points
  109. TYA ;
  110. PLB
  111. PLY
  112. PLX
  113. JML $00F38A ; jump back to the rest of the normal routine
  114. NoPoints: ;
  115. PLY
  116. PLX
  117. PLB ;
  118. JML $00F3B1 ;
  119.  
  120. YCoinNumber: ;
  121.  
  122. INC $1422 ; increment the coins collected in the current level
  123. REP #$20 ; set A to 16-bit mode
  124. LDA !RAM_TotalYCoins ; check the total number of coins collected
  125. CMP #$03E7 ; if it has reached 999...
  126. BEQ NoIncTotal ; don't let it go any higher
  127. INC ;
  128. STA !RAM_TotalYCoins ;
  129. NoIncTotal: ;
  130. SEP #$20 ;
  131.  
  132. PHX ;
  133. LDA $9A ; X position of contact with the block
  134. AND #$70 ; in terms of 8 tiles
  135. LSR #4 ;
  136. STA $06 ; X position on the screen = *bit* index (00-07)
  137. LDA $5B ; check whether the level is vertical or horizontal
  138. LSR ; if bit 0 of $5B is set...
  139. BCS Vertical ; then the level is vertical
  140. LDA $9B ; base the high byte on the player's X position
  141. BRA StoreHighByte ;
  142. Vertical: ; if the level is vertical...
  143. LDA $99 ; base the high byte on the player's Y position
  144. StoreHighByte: ;
  145. AND #$0F ; 4 bits for the screen number (the 5th bit is cleared)
  146. STA $07 ;
  147. STZ $08 ; clear the next byte
  148. LDA !OWLevel ; overworld level
  149. REP #$20 ;
  150. AND.w #$00FF ; clear the high byte of A
  151. ASL #4 ;
  152. ORA $07 ; overworld level + low 4 bits of screen number
  153. STA $07 ; = resulting *byte* index
  154. SEP #$20 ;
  155. LDX $06 ; load the index from the player's X position
  156. LDA $028000,x ; set a particular coin flag (bitwise)
  157. REP #$10 ; set X to 16-bit as well
  158. LDX $07 ; get an index from 0-600 based on the level number and screen number
  159. ORA !RAM_CoinFlags,x ;
  160. STA !RAM_CoinFlags,x ;
  161. SEP #$10 ;
  162. PLX ;
  163. JML $00F358 ; finish up with the regular code
  164.  
  165. YCoinObject:
  166.  
  167. LDA $1BA1 ; the current screen the loading routine is on
  168. AND #$0F ;
  169. STA $06 ;
  170. STZ $07 ;
  171. LDA !OWLevel ;
  172. REP #$30 ;
  173. AND.w #$00FF ;
  174. ASL #4 ; get the overworld level x16
  175. ORA $06 ; add in the screen bits
  176. TAX ;
  177. SEP #$20 ;
  178. LDA !RAM_CoinFlags,x ; check a particular byte of coin flags
  179. SEP #$10 ;
  180. PHA ;
  181. LDA $57 ; check the object's position within the subscreen
  182. AND #$07 ;
  183. TAX ;
  184. PLA ;
  185. AND $028000,x ; check a single flag to see if it is set or not
  186. BNE YCoinCollected ; if set, the coin has already been collected
  187. LDY $57 ;
  188. LDA #$2D ;
  189. STA [$6B],y ;
  190. LDA #$00 ;
  191. STA [$6E],y ;
  192. TYA ;
  193. CLC ;
  194. ADC #$10 ;
  195. TAY ;
  196. LDA #$2E ;
  197. STA [$6B],y ;
  198. LDA #$00 ;
  199. STA [$6E],y ;
  200. YCoinCollected: ;
  201. JML $0DB335 ;
  202.  
  203. SaveCoinFlags:
  204.  
  205. XBA ;
  206. LDA $009CCE,x ; restore hijacked code
  207. PHA ; preserve this to prevent it getting overwritten
  208. PHX ;
  209. PHY ;
  210. PHP ;
  211. REP #$30 ;
  212. PHX ;
  213. TXA ;
  214. ASL ;
  215. TAX ;
  216. LDA !RAM_TotalYCoins ;
  217. STA !SRAM_TotalYCoins,x ;
  218. PLX ;
  219. LDA.w #$05FE ;
  220. DEX ;
  221. BMI $06 ;
  222. CLC ;
  223. ADC #$0600 ;
  224. BRA $F7 ;
  225.  
  226. TAX ;
  227. LDA.w #!RAM_CoinFlags ;
  228. STA $00 ;
  229. LDA.w #!RAM_CoinFlags/$10000 ; set up a pointer
  230. STA $02 ;
  231. LDY #$05FE ;
  232. SaveLoop: ;
  233. LDA [$00],y ;
  234. STA !SRAM_CoinFlags,x ;
  235. DEX ;
  236. DEX ;
  237. DEY ;
  238. DEY ;
  239. BPL SaveLoop
  240.  
  241. PLP ;
  242. PLY ;
  243. PLX ;
  244. PLA ;
  245. JML $009BD6 ;
  246.  
  247. LoadCoinFlags: ;
  248.  
  249. SEP #$10 ;
  250. LDY #$12 ; restore hijacked code
  251. PHY
  252. PHP ;
  253. REP #$30 ;
  254. LDA $010A ;
  255. AND.w #$00FF ;
  256. PHA ;
  257. ASL ;
  258. TAX ;
  259. LDA !SRAM_TotalYCoins,x ;
  260. STA !RAM_TotalYCoins ;
  261. PLA ;
  262. TAX ;
  263. LDA #$05FE ;
  264. DEX ;
  265. BMI $06 ;
  266. CLC ;
  267. ADC #$0600 ;
  268. BRA $F7 ;
  269.  
  270. TAX ;
  271. LDA.w #!RAM_CoinFlags ;
  272. STA $00 ;
  273. LDA.w #!RAM_CoinFlags/$10000 ; set up a pointer
  274. STA $02 ;
  275. LDY #$05FE ;
  276. LoadLoop: ;
  277. LDA !SRAM_CoinFlags,x ;
  278. STA [$00],y ;
  279. DEX ;
  280. DEX ;
  281. DEY ;
  282. DEY ;
  283. BPL LoadLoop
  284.  
  285. PLP ;
  286. PLY ;
  287. JML $009D26 ;
  288.  
  289. ClearSRAM:
  290.  
  291. PHP ;
  292. SEP #$30 ;
  293. LDA $0109 ;
  294. CMP #$E9 ;
  295. BNE NoClear ;
  296. PHX ; preserve the value of X
  297. PHY ; and Y
  298. LDA $010A ; save file number
  299. ASL ; x2
  300. STA $00 ; into scratch
  301. ASL ; x4
  302. CLC ;
  303. ADC $00 ; x6
  304. XBA ;
  305. REP #$30 ;
  306. AND #$FF00 ; save file x600
  307. CLC ;
  308. ADC #$05FE ;
  309. TAX ;
  310. LDA.w #!RAM_CoinFlags ;
  311. STA $00 ;
  312. LDA.w #!RAM_CoinFlags/$10000 ; set up a pointer
  313. STA $02 ;
  314. LDY #$05FE ; 0x600 bytes to clear
  315. LDA.w #$0000 ;
  316. SRAMClearLoop: ;
  317. STA !SRAM_CoinFlags,x ; set the coin flags to zero
  318. STA [$00],y ;
  319. DEX ;
  320. DEX ;
  321. DEY ;
  322. DEY ;
  323. BPL SRAMClearLoop ; loop if Y hasn't dropped below zero
  324. STA !RAM_TotalYCoins ;
  325. SEP #$30 ;
  326. PLY ;
  327. PLX ;
  328. NoClear: ;
  329. PLP ;
  330. PEA $93F3 ;
  331. JML $008494 ;
  332.  
  333. HexToDecLong: ;
  334.  
  335. LDX #$00
  336. LDY #$00
  337.  
  338. HexDecLoop1:
  339.  
  340. CMP.w #$0064
  341. BCC HexDecLoop2
  342. SBC.w #$0064
  343. INX
  344. BRA HexDecLoop1
  345.  
  346. HexDecLoop2:
  347.  
  348. CMP.w #$000A
  349. BCC EndHexDec
  350. SBC.w #$000A
  351. INY
  352. BRA HexDecLoop2
  353.  
  354. EndHexDec:
  355.  
  356. SEP #$20
  357. RTS
  358.  
  359. TotalNumber: ; the total number of Yoshi coins in each level
  360.  
  361. db $04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04 ; levels 0-F
  362. db $04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04 ; levels 10-1F
  363. db $04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04 ; levels 20-24 and 101-10B
  364. db $04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04 ; levels 10C-11B
  365. db $04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04 ; levels 11C-12B
  366. db $04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04 ; levels 12C-13B
  367.  
  368. print "This patch uses ",bytes," bytes."
  369.  
  370. EndCode:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement