Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; Generic ExGFX Uploader v1.1.2
  3. ; coded by edit1754
  4. ;
  5. ; Table Format:
  6. ; dw $0105 : dw $3800 : dw $0203 <-- levelnumber, VRAM Addr / 2, ExGFX File Number
  7. ; You can have as many as you need in the table, and you can have more than one per level
  8. ; The table must end in "dw $FFFF"
  9. ;
  10. ; This patch can be used to upload layer 3 tilemaps, since ExGFX files are compressed
  11. ; with a format that's far more efficient than stripe image.
  12. ; (I may release a tutorial on how to do this).
  13. ;
  14. ; UPDATE 1.1.1: now restores compatiblity with ExGFX80-FF in LM1.7
  15. ; - if you need to use genericuploader.asm for a LM1.6 ROM for whatever reason,
  16. ; find: $0FF94F and replace with $0FF1DD
  17. ; find: $0FF950 and replace with $0FF1DE
  18. ;
  19. ; The maximum size of an ExGFX file is 0x1B00 (6912) bytes due to decompression buffer size.
  20. ;
  21. ; UPDATE 1.1.2: no longer integrates LC_LZ2 optimization patch
  22. ; - also moved restored hijack to REVERT_genericuploader.asm
  23. ; (APPLY THIS TO YOUR ROM FIRST IF YOU USED A VERSION BEFORE v1.1!!)
  24. ;
  25. ; ***REQUIRES LZ2 OPTIMIZATION PATCH FOR SIZE -> $8D CODE***
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27. header
  28. lorom
  29.  
  30. !FREESPACE = $38A3E4 ; CHANGE THIS
  31.  
  32. !GFXBuffer = $7EAD00 ; GFX Decompression buffer
  33.  
  34. !LevelNum = $010B ; Address used by levelnum.ips, don't change
  35.  
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37. ; levelnum.ips (disassembly) - credit goes to BMF for this
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39.  
  40. ORG $05D8B9
  41. JSR LevelNumCode
  42.  
  43. ORG $05DC46
  44. LevelNumCode: LDA.b $0E ; Load level number, 1st part of hijacked code
  45. STA.w !LevelNum ; Store it in free RAM
  46. ASL A ; 2nd part of hijacked code
  47. RTS
  48.  
  49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50. ; Hijacks
  51. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  52.  
  53. org $A9DA
  54. JSL Main
  55. NOP
  56.  
  57. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  58. ; Main Code
  59. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60.  
  61. org !FREESPACE
  62. reset bytes
  63.  
  64. !CodeSize = End-Start
  65. db "STAR"
  66. dw !CodeSize-$01
  67. dw !CodeSize-$01^$FFFF
  68. Start:
  69.  
  70. LevelTable:
  71. ;dw $0105 : dw $3800 : dw $0203 ; EXAMPLE (commented out)
  72. dw $FFFF
  73.  
  74. Main: LDA.b #$80 ; \ hijacked
  75. STA.w $2115 ; / code
  76. LDA.b $71 ; \ return if
  77. CMP.b #$0A ; | Mario is in a
  78. BEQ Return ; / no-Yoshi intro
  79. LDA $0100 ; \
  80. CMP.b #$12 ; | only if at
  81. BEQ InLevel ; | beginning of
  82. CMP #$04 ; | level
  83. BNE Return ; /
  84. InLevel: PHB : PHK : PLB ; back up B, K -> B
  85. REP #%00110000 ; 16-bit A/X/Y
  86. LDY.w #$0000 ; start Y at zero
  87. Loop: LDA.w LevelTable,y ; get level number
  88. CMP.w #$FFFF ; \ if #$FFFF
  89. BEQ EndLoop ; / then end
  90. CMP.w !LevelNum ; \ if not for this level,
  91. BNE Skip ; / then skip
  92. LDX.w LevelTable+2,y ; get VRAM address
  93. LDA.w LevelTable+4,y ; get ExGFX File Number
  94. JSR UploadGFXFile ; upload
  95. Skip: INY #6 ; next entry index
  96. BRA Loop ; loop
  97. EndLoop: SEP #%00110000 ; 8-bit A/X/Y
  98. PLB ; restore B
  99. Return: RTL
  100.  
  101. UploadGFXFile: PHY ; back up Y
  102. PHX ; back up X
  103. CMP.w #$0032 ; \ < 32, use code
  104. BCC GFX00to31 ; / for GFX 00-31
  105. CMP.w #$0080 ; \ still < 80,
  106. BCC UploadReturn ; / return
  107. CMP.w #$0100 ; \ > 100, use code
  108. BCS ExGFX100toFFF ; / for 100-FFF
  109. GFX80toFF: AND.w #$007F ; reset most significant bit
  110. STA.b $8A ; \
  111. ASL A ; | multiply by 3 using
  112. CLC ; | shift-add method
  113. ADC.b $8A ; /
  114. TAY ; -> Y
  115. LDA.l $0FF94F ; \
  116. STA.b $06 ; | $0FF94F-$0FF950 contains the pointer
  117. LDA.l $0FF950 ; | for the ExGFX table for 80-FF
  118. STA.b $07 ; /
  119. BRA FinishDecomp ; branch to next step
  120.  
  121. UploadReturn: PLX
  122. PLY
  123. RTS
  124.  
  125. GFX00to31: TAX ; ExGFX file -> X
  126. LDA.l $00B992,x ; \
  127. STA $8A ; | copy ExGFX
  128. LDA.l $00B9C4,x ; | pointer to
  129. STA $8B ; | $8A-$8C
  130. LDA.l $00B9F6,x ; |
  131. STA $8C ; /
  132. BRA FinishDecomp2 ; branch to next step
  133.  
  134. ExGFX100toFFF: ;SEC ; \ subtract #$100
  135. SBC.w #$0100 ; / SEC commented out because the BCS that branches here would only branch if the carry flag were already set
  136. STA.b $8A ; \
  137. ASL A ; | multiply result
  138. CLC ; | by 3 to get
  139. ADC.b $8A ; | index
  140. TAY ; /
  141. LDA.l $0FF873 ; \
  142. STA.b $06 ; | $0FF873-$0FF875 contans the pointer
  143. LDA.l $0FF874 ; | for the ExGFX table for 100-FFF
  144. STA.b $07 ; /
  145. FinishDecomp: LDA.b [$06],y ; \ Get low byte.
  146. STA.b $8A ; / and high byte
  147. INC.b $06 ; Increase pointer position by 1.
  148. BNE NoCrossBank ; \
  149. SEP #%00100000 ; | allow bank crossing
  150. INC $08 ; | (not sure if this is necessary here)
  151. REP #%00100000 ; /
  152. NoCrossBank: LDA.b [$06],y ; \ Get the high byte (again)
  153. STA.b $8B ; / and bank byte.
  154. FinishDecomp2: LDA.w #!GFXBuffer ; \ GFX buffer low
  155. STA.b $00 ; / and high byte
  156. SEP #%00100000 ; 8-bit A
  157. LDA.b #!GFXBuffer>>16 ; \ GFX buffer
  158. STA.b $02 ; / bank byte
  159. PHK ; \
  160. PEA.w Ret1-1 ; | local JSL to LZ2 routine
  161. PEA $84CE ; | (afterwards A/X/Y all 8-bit)
  162. JML $00B8DC ; /
  163. Ret1: REP.b #%00010000 ; 16-bit X/Y
  164. PLX ; \ restore X, X is the
  165. STX.w $2116 ; / VRAM destination
  166. LDA.b #%00000001 ; \ control
  167. STA.w $4300 ; / register
  168. LDA.b #$18 ; \ dma to
  169. STA.w $4301 ; / [21]18
  170. LDX.w #!GFXBuffer ; \
  171. STX.w $4302 ; | source
  172. LDA.b #!GFXBuffer>>16 ; | of data
  173. STA.w $4304 ; /
  174. LDX.b $8D ; \ size of decompressed
  175. STX.w $4305 ; / GFX File
  176. LDA.b #%00000001 ; \ start DMA
  177. STA.w $420B ; / transfer
  178. REP #%00100000 ; 16-bit A
  179. PLY ; restore Y
  180. RTS
  181. End:
  182. print "Insert Size: ",bytes," bytes"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement