daily pastebin goal
18%
SHARE
TWEET

Retry

Romano338 Aug 10th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;!freeram: timer1
  2. ;!freeram+1: timer2
  3. ;!freeram+2: timer3
  4. ;!freeram+3: respawn location1
  5. ;!freeram+4: respawn location2
  6. ;!freeram+5: is respawning? (after death)
  7. ;!freeram+6: music that has to be reloaded after respawn
  8. ;!freeram+7: music sped up? (hurry up)
  9. ;!freeram+8: door dest1 (candidate of freeram+3, for door/pipe checkpoint)
  10. ;!freeram+9: door dest2 (candidate of freeram+4, for door/pipe checkpoint)
  11. ;!freeram+10: music played right before the death jingle
  12. ;!freeram+11: music registered(freeram+6) latest midway value (for mmp)
  13.  
  14.  
  15. !sa1    = 0
  16. !dp = $0000
  17. !addr   = $0000
  18. !bank   = $800000
  19. !bank8  = $80
  20. !7ED000 = $7ED000       ; $7ED000 if LoROM, $40D000 if SA-1 ROM.
  21.  
  22. if read1($00FFD5) == $23
  23.     sa1rom
  24.     !sa1    = 1
  25.     !dp = $3000
  26.     !addr   = $6000
  27.     !bank   = $000000
  28.     !bank8  = $00
  29.     !7ED000 = $40D000       ; $7ED000 if LoROM, $40D000 if SA-1 ROM.
  30. endif
  31.  
  32.  
  33.  
  34. org $00A1DF
  35. autoclean JSL Prompt
  36.  
  37. org $0085D2
  38. autoclean JML LoadScrnImage
  39.  
  40. org $00F5B2
  41. autoclean JSL DeathSFX_pit
  42.  
  43. org $00F606
  44. autoclean JML DeathSFX
  45.  
  46. org $008E5B
  47. autoclean JML HurryFlag
  48.  
  49. org $00A28A
  50. autoclean JML Request
  51.  
  52. ; earlier than GeneralInit (between object & sprite)
  53. org $05D8E6
  54. autoclean JML GeneralInit0
  55.  
  56. org $0091A6
  57. autoclean JML GeneralInit
  58.  
  59. org $02A768
  60. autoclean JML YoshiInit
  61.  
  62. org $05D7BD
  63. autoclean JML EntranceInit0
  64.  
  65. org $05D7D4
  66. autoclean JML EntranceInit
  67.  
  68. org $00F2E8
  69. autoclean JML MidbarHijack
  70.  
  71. org $0DA691
  72. autoclean JML MidbarSpawn
  73.  
  74. org $05D9D7
  75. autoclean JML CheckMidwayEntrance
  76.  
  77. org $0096CB
  78. autoclean JML InitCheckpointRam
  79.  
  80. org $05D9EC
  81. autoclean JML VanillaMidwayDestFix
  82.  
  83.  
  84. ; copy pasted from uberasm ($010B hack)
  85. ORG $05D8B7
  86. BRA +
  87. NOP #3;the levelnum patch goes here in many ROMs, just skip over it
  88. +
  89. REP #$30
  90.     LDA $0E    
  91.     STA $010B|!addr
  92.     ASL    
  93.     CLC    
  94.     ADC $0E    
  95.     TAY    
  96.     LDA.w $E000,Y
  97.     STA $65    
  98.     LDA.w $E001,Y
  99.     STA $66    
  100.     LDA.w $E600,Y
  101.     STA $68    
  102.     LDA.w $E601,Y
  103.     STA $69    
  104.     BRA +
  105. ORG $05D8E0
  106.     +
  107.  
  108.  
  109. freecode
  110.  
  111. Table:
  112. incsrc retry_table.asm
  113.  
  114. Prompt:
  115.     ; save prompt
  116.     CMP #$08
  117.     BEQ .3
  118.     CMP #$0C
  119.     BEQ .3
  120.     CMP #$09
  121.     BCS Retry
  122.     JSL $05B10C|!bank
  123.     RTL
  124. .3
  125.     INC $1426|!addr
  126.     STZ $41
  127.     STZ $42
  128.     STZ $43
  129.     LDA #$80
  130.     TRB $0D9F|!addr
  131.     RTL
  132.  
  133. FastRetry:
  134.     CMP #$0E
  135.     BEQ Retry_5
  136.     LDX $1B88|!addr
  137.     LDA.l Retry_dest,x
  138.     CMP $1B89|!addr
  139.     BEQ Retry_sub2
  140.     STA $1B89|!addr
  141.     BRA Retry_sub
  142.  
  143.  
  144. Retry:
  145.     CMP #$0D
  146.     BCS FastRetry
  147.     CMP #$0A
  148.     BNE .4
  149.  
  150. .5
  151. ;A
  152.     LDA $1B87|!addr
  153.     PHA
  154.     JSR .choose
  155.     PLA
  156.     CMP $1B87|!addr
  157.     BEQ +
  158.     STA $1B87|!addr
  159.     INC $1426|!addr
  160. +
  161.     RTL
  162.  
  163. .dest
  164.     db $48,$00
  165. .spd
  166.     db $06,$FA
  167.  
  168. .4
  169. ;9,B
  170.     LDX $1B88|!addr
  171.     LDA $1B89|!addr
  172.     CMP.l .dest,x
  173.     BNE ++
  174. ;box complete
  175. .sub2
  176.     INC $1426|!addr
  177.     LDA $1426|!addr
  178.     CMP #$0A
  179.     BEQ +++
  180.     CMP #$0E
  181.     BNE +
  182. +++
  183. ;9
  184.     LDA #$01
  185.     STA $13D5|!addr
  186.     STZ $22
  187.     STZ $23
  188.     STZ $24
  189.     STZ $25
  190.     LDY #$1E
  191.     STY $12 ; stripe image = save prompt
  192. +
  193.     AND #$03
  194.     BEQ +
  195. ;9
  196.     RTL
  197. +
  198. ;B
  199.     ; terminate
  200.     STZ $1426|!addr
  201.     STZ $1B88|!addr
  202.     STZ $41
  203.     STZ $42
  204.     STZ $43
  205.     LDA #$80
  206.     TRB $0D9F|!addr
  207.     LDA #$02
  208.     STA $44
  209.     RTL
  210. ++
  211. ;box creating
  212.     CLC
  213.     ADC.l .spd,x
  214.     STA $1B89|!addr
  215. .sub
  216.     CLC
  217.     ADC #$80
  218.     XBA
  219.     REP #$10
  220.     LDX #$016E
  221.     LDA #$FF
  222. -
  223.     STA $04F0|!addr,x
  224.     STZ $04F1|!addr,x
  225.     DEX
  226.     DEX
  227.     BPL -
  228.     SEP #$10
  229.     LDA $1B89|!addr
  230.     LSR
  231.     ADC $1B89|!addr
  232.     LSR
  233.     AND #$FE
  234.     TAX
  235.     LDA #$80
  236.     SEC
  237.     SBC $1B89|!addr
  238.     REP #$20
  239.     LDY #$48
  240. -
  241.     CPY #$00
  242.     BMI +
  243.     STA $0548|!addr,y
  244. +
  245.     STA $0590|!addr,x
  246.     DEY
  247.     DEY
  248.     DEX
  249.     DEX
  250.     BPL -
  251.     SEP #$20
  252.     LDA #$22
  253.     STA $41
  254.     STA $43
  255.     LDA #$22
  256.     STA $44
  257.     LDA #$80
  258.     TSB $0D9F|!addr
  259.     RTL
  260.  
  261. .choose
  262.     LDY #$00
  263.     JSR .cursor
  264.     TXA
  265.     BEQ +
  266.  
  267.     ; no is selected
  268.     PHX
  269.     JSR GetPromptType
  270.     PLX
  271.     CMP #$02
  272.     BNE ++
  273.     LDA #$3E    ; extra frames
  274.     STA $1496|!addr
  275.     LDA.l $00F60B|!bank
  276.     STA $1DFB|!addr
  277.     LDA.l $008075|!bank
  278.     CMP #$5C
  279.     BEQ ++      ; amk
  280.     LDA #$FF
  281.     STA $0DDA|!addr
  282. ++
  283.     JSL $009C13|!bank
  284.     RTS
  285. +
  286.     ; yes is selected
  287.     JSR ResetLevel
  288.     JSL $009C13|!bank
  289.     RTS
  290.  
  291. .cursor
  292.     INC $1B91|!addr
  293.  
  294.     PHB
  295.     LDA.b #$00|!bank8
  296.     PHA
  297.     PLB
  298.  
  299.     PHK
  300.     PEA .pos-1
  301.     PEA $9BAE
  302.     JML $009E82|!bank
  303. .pos
  304.     PLB
  305.  
  306.     LDX $1B92|!addr
  307.     LDA $16
  308.     AND #$90
  309.     BNE +
  310.     LDA $18
  311.     BPL ++
  312. +
  313.     LDA #$01
  314.     STA $1DFC|!addr
  315.     BRA +
  316. ++
  317.     PLA
  318.     PLA
  319.     LDA $16
  320.     AND #$20
  321.     LSR
  322.     LSR
  323.     LSR
  324.     ORA $16
  325.     AND #$0C
  326.     BEQ ++
  327.     LDY #$06
  328.     STY $1DFC|!addr
  329.     STZ $1B91|!addr
  330.     LSR
  331.     LSR
  332.     TAY
  333.  
  334.     PHB
  335.     LDA #$00|!bank8
  336.     PHA
  337.     PLB
  338.     TXA
  339.     ADC $9AC7,y
  340.     PLB
  341.     CMP #$00
  342.  
  343.     BPL +++
  344.     LDA $8A
  345.     DEC
  346. +++
  347.     CMP $8A
  348.     BCC ++++
  349. +
  350.     LDA #$00
  351. ++++
  352.     STA $1B92|!addr
  353. ++
  354.     RTS
  355.  
  356.  
  357. ResetLevel:
  358.     ; 1) set screen exit
  359.     LDA $5B
  360.     LSR
  361.     BCC .horz
  362.     LDY $97
  363.     BRA +
  364. .horz
  365.     LDY $95
  366. +
  367.     CPY #$00
  368.     BPL .positive
  369.     LDY #$00
  370.     BRA .ok
  371. .positive
  372.     CPY #$20
  373.     BMI .ok
  374.     LDY #$1F
  375. .ok
  376.     LDA.l $05DAA3|!bank
  377.     CMP #$5C
  378.     BNE .non_mmp
  379.     JSR CalcMMP
  380. .non_mmp
  381.     LDA !freeram+3
  382.     STA $19B8|!addr,y
  383.     LDA !freeram+4
  384.     STA $19D8|!addr,y
  385.  
  386.     LDA #$01
  387.     STA !freeram+5
  388.     LDA #$00
  389.     STA !freeram+7
  390.     LDA #$06
  391.     STA $71
  392.     STZ $1496|!addr
  393.     STZ $89
  394.     STZ $88
  395.  
  396.     ; 2) item memory & sprite reload
  397.     LDX #$7F
  398. -
  399.     STZ $19F8|!addr,x
  400.     STZ $1A78|!addr,x
  401.     STZ $1AF8|!addr,x
  402.     STZ $1938|!addr,x   ; sprite reload
  403.     DEX
  404.     BPL -
  405.  
  406.     ; 3) timer, music, lives, etc
  407.     LDA #$1E
  408.     STA $0DC0|!addr
  409.     STZ $1420|!addr
  410.     STZ $1422|!addr
  411.     STZ $1432|!addr ; directional coin from a question box
  412.     STZ $14AF|!addr ; ON/OFF
  413.     STZ $1B94|!addr ; bonus game sprite
  414.     STZ $1B95|!addr ; yoshi wing
  415.     STZ $1B96|!addr ; side exit
  416.     STZ $1B9A|!addr ; flying turn blocks(forest of illusion)
  417.     STZ $1B9F|!addr ; reznor bridge
  418.     ; mode 7 values for the boss
  419.     ; do it later
  420.     ;REP #$20
  421.     ;STZ $36
  422.     ;STZ $38
  423.     ;STZ $3A
  424.     ;STZ $3C
  425.     ;SEP #$20
  426.     LDA !freeram
  427.     STA $0F31|!addr
  428.     LDA !freeram+1
  429.     STA $0F32|!addr
  430.     LDA !freeram+2
  431.     STA $0F33|!addr
  432.  
  433.     ; yoshi drum
  434.     LDA #$03
  435.     STA $1DFA|!addr
  436.  
  437.     LDA.l $008075|!bank
  438.     CMP #$5C
  439.     BEQ .amk
  440.  
  441.     ; non addmusic (dont need to consider sample overhead)
  442.     LDA $0DDA|!addr ; after the death jingle, this value will always be $FF
  443.     CMP !freeram+6
  444.     BEQ .musicend
  445.     STZ $0DDA|!addr
  446.     BRA .musicend
  447. .amk
  448.     LDA $0DDA|!addr
  449.     CMP #$FF    ; death, kaizo trap, etc
  450.     BEQ .spec
  451.     ; normal case: $0DDA preserved
  452.     LDA !freeram+6
  453.     CMP $0DDA|!addr
  454.     BNE .musicend
  455.     BRA .bypass
  456. .spec
  457.     LDA $1DFB|!addr
  458.     CMP #$01    ; death
  459.     BEQ +
  460.     ; kaizo trap -> order reload (maybe improved, but not major)
  461.     LDA #$00
  462.     STA !addmusick_ram_addr
  463.     STA $1DFB|!addr
  464. +
  465.     ; death jingle
  466.     LDA !freeram+6
  467.     CMP !freeram+10
  468.     BNE .musicend
  469. .bypass
  470.     LDA.l $05DAA3|!bank
  471.     CMP #$5C
  472.     BNE .non_mmp2
  473.     ; when !freeram+6 was unreliable due to the outside mmp then force to load the sample (maybe improved, but not major)
  474.     JSR CalcMMPNum
  475.     CMP !freeram+11
  476.     BNE .musicend
  477. .non_mmp2
  478.     LDA #$01
  479.     STA !addmusick_ram_addr+1
  480. .musicend
  481.  
  482.     STZ $141A|!addr
  483.     if !loose_lives
  484.         DEC $0DBE|!addr
  485.     endif
  486.     RTS
  487.  
  488.  
  489. CalcEntrance:
  490.     PHX
  491.     LDA $13BF|!addr
  492.     CMP #$25
  493.     BCC +
  494.     CLC
  495.     ADC #$DC
  496. +
  497.     STA !freeram+3
  498.     LDA #$00
  499.     ADC #$00
  500.     STA !freeram+4
  501.     LDX $13BF|!addr
  502.     LDA $1EA2|!addr,x
  503.     AND #$40
  504.     BNE +
  505.     LDA $13CE|!addr
  506.     BEQ ++
  507. +
  508.     LDA !freeram+4
  509.     ORA #$0C
  510.     STA !freeram+4
  511.     BRA +++
  512. ++
  513.     LDA !freeram+4
  514.     ORA #$04
  515.     STA !freeram+4
  516. +++
  517.     PLX
  518.     RTS
  519.  
  520.  
  521. HardSave:
  522.     LDA.l $05DAA3|!bank
  523.     CMP #$5C
  524.     BEQ .skip_mmp
  525.  
  526.     PHX
  527.     LDA $13BF|!addr
  528.     ASL
  529.     TAX
  530.     REP #$20
  531.     LDA.l !freeram+3
  532.     STA.l !freeram_checkpoint,x
  533.     SEP #$20
  534.     PLX
  535. .skip_mmp
  536.     RTS
  537.  
  538.  
  539. LoadScrnImage:
  540.     LDY $12
  541.     CPY #$1E
  542.     BNE .orig
  543.     LDA $0100|!addr
  544.     CMP #$14
  545.     BNE .orig
  546.     LDA.b #.stripe
  547.     STA $00
  548.     LDA.b #.stripe>>8
  549.     STA $01
  550.     LDA.b #.stripe>>16
  551.     STA $02
  552.     JML $0085E3|!bank
  553. .orig
  554.     LDA $84D0,y
  555.     JML $0085D7|!bank
  556. .stripe
  557.     db $51,$CD,$00,$09
  558.     db $1B,$38,$0E,$38,$1D,$38,$1B,$38,$22,$38  ;RETRY
  559.  
  560.     db $52,$0D,$00,$07
  561.     db $0E,$38,$21,$38,$12,$38,$1D,$38  ;EXIT
  562.  
  563.     db $FF
  564.  
  565.  
  566. DeathSFX:
  567.     LDA #$90
  568.     STA $7D
  569. .pit
  570.     LDA !freeram+7
  571.     BNE .orig
  572.     if !loose_lives
  573.         LDA $0DBE|!addr
  574.         BEQ .orig
  575.     endif
  576.     PHX
  577.     JSR GetPromptType
  578.     PLX
  579.     CMP #$02
  580.     BCC .orig
  581.     CMP #$04
  582.     BCS .orig
  583.     LDA #!death_sfx
  584.     STA !death_sfx_bank|!addr
  585.     JML $00F614|!bank
  586. .orig
  587.     LDA $0DDA|!addr
  588.     STA !freeram+10
  589.     LDA.l $00F60B|!bank ; death jingle
  590.     STA $1DFB|!addr
  591.     JML $00F60F|!bank
  592.  
  593.  
  594. HurryFlag:
  595.     LDA #$FF
  596.     STA $1DF9|!addr
  597.     LDA #$01
  598.     STA !freeram+7
  599.     JML $008E60|!bank
  600.  
  601.  
  602. Request:
  603.     if !loose_lives
  604.         LDA $0DBE|!addr
  605.         BEQ .orig
  606.     endif
  607.     ; make sure mario is dying
  608.     LDA $71
  609.     CMP #$09
  610.     BNE .orig
  611.  
  612.     ; skip the first frame
  613.     LDA $1496|!addr
  614.     CMP #$31
  615.     BNE +
  616.     ; extra frames
  617.     LDA #$22
  618.     STA $1496|!addr
  619.     BRA .orig
  620. +
  621.     CMP #$30
  622.     BCS .orig
  623.  
  624.     JSR GetPromptType
  625.     CMP #$03
  626.     BCC .prompt
  627.     CMP #$04
  628.     BCS .orig
  629.     ; automatically yes
  630.     JSR .kaizo_trap
  631.     JSR ResetLevel
  632.     BRA .orig
  633. .prompt
  634.     ; iggy/larry -> fast
  635.     LDA $0D9B|!addr
  636.     CMP #$80
  637.     BEQ .fast
  638.     ; key press -> fast
  639.     LDA $16
  640.     ORA $18
  641.     BPL ++
  642. .fast
  643.     LDA $1496|!addr
  644.     CMP #$23
  645.     BCC .orig
  646.     LDA #$0C
  647.     STA $1426|!addr ; request fast retry
  648.     LDA #$22
  649.     STA $1496|!addr
  650.     BRA +++
  651. ++
  652.     LDA $1496|!addr
  653.     CMP #$23
  654.     BNE .orig
  655.     LDA #$08
  656.     STA $1426|!addr ; request retry
  657.     DEC $1496|!addr
  658. +++
  659.     JSR .settings
  660. .orig
  661.     LDA $0D9B|!addr
  662.     BPL +
  663.     JML $00A28F|!bank
  664. +
  665.     JML $00A295|!bank
  666. .settings
  667.     LDA $0D9B|!addr
  668.     BPL +
  669.     ; special mode (boss)
  670.     STZ $0D9B|!addr
  671.     ; window for boss battles
  672.     LDA #$15
  673.     STA $212C
  674.     STA $212E
  675.     STZ $212D
  676.     STZ $212F
  677.     ; bg color to black
  678.     STZ $0701|!addr
  679.     STZ $0702|!addr
  680.     LDA $13FC|!addr
  681.     CMP #$04
  682.     BNE .kaizo_trap
  683.     ; reznor battle -> erase all fireballs
  684.     PHX
  685.     LDX #$09
  686. -
  687.     LDA $170B|!addr,x
  688.     CMP #$02
  689.     BNE .f
  690.     STZ $170B|!addr,x
  691. .f
  692.     DEX
  693.     BPL -
  694.     PLX
  695.     BRA .kaizo_trap
  696. +
  697.     ; normal mode
  698.     ; window (main/sub)
  699.     LDA #$15
  700.     STA $212C
  701.     STA $212E
  702.     LDA #$02
  703.     STA $212D
  704.     STA $212F
  705. .kaizo_trap
  706.     STZ $1492|!addr
  707.     STZ $1493|!addr
  708.     STZ $1494|!addr
  709.     STZ $1495|!addr
  710.     STZ $1B99|!addr
  711.     RTS
  712.  
  713.  
  714. GetPromptType:
  715.     LDX $13BF|!addr
  716.     BNE +
  717.     LDA #$04
  718.     RTS
  719. +
  720.     LDA.l Table_effect,x
  721.     CMP #$01
  722.     BCS .not_default
  723.     LDA.b #(!default_prompt_type+1)
  724. .not_default
  725.     RTS
  726.  
  727.  
  728. GeneralInit0:       ; earlier than GeneralInit
  729.     PHY
  730.     PHP
  731.     SEP #$20
  732.  
  733.     LDA $141A|!addr
  734.     BNE +
  735.     ; initialize this ram when entering from the map
  736.     LDA #$00
  737.     STA !freeram+5  ; zero because we don't want to trigger yoshi init & initial facing init
  738.     BRA ++
  739. +
  740.     LDA.l $05DAA3|!bank
  741.     CMP #$5C
  742.     BEQ .skip_mmp
  743.  
  744.     LDA !freeram+5
  745.     BNE ++
  746.     REP #$10
  747.     LDX $010B|!addr
  748.     LDA.l Table_checkpoint,x
  749.     SEP #$10
  750.     CMP #$02
  751.     BCC ++
  752.     LDA !freeram+8
  753.     STA !freeram+3
  754.     LDA !freeram+9
  755.     STA !freeram+4
  756.     JSR HardSave
  757.     ; too early for amk
  758.     ;LDA #$05
  759.     ;STA $1DF9|!addr
  760.     LDX $13BF|!addr
  761.     LDA $1EA2|!addr,x
  762.     ORA #$40
  763.     STA $1EA2|!addr,x
  764. .skip_mmp
  765. ++
  766.  
  767.     LDA !freeram+5
  768.     BEQ +
  769.     LDA $1B9B|!addr ; do not touch if $1B9B is set already (hence no effect on parked yoshi)
  770.     BNE +
  771.     ; only for respawning(after death just in case) && not a castle level
  772.     STZ $0DC1|!addr
  773. +
  774.  
  775.     PLP
  776.     PLY
  777.     LDA #$0000
  778.     SEP #$20
  779.     JML $05D8EB|!bank
  780.  
  781.  
  782. GeneralInit:
  783.     LDA $141A|!addr
  784.     BNE +
  785.     ; first entrance (from ow)
  786.     LDA #$00
  787.     STA !freeram+7
  788.  
  789.     LDA.l $05DAA3|!bank
  790.     CMP #$5C
  791.     BEQ .skip_mmp
  792.     PHX
  793.     LDX $13BF|!addr
  794.     LDA $1EA2|!addr,x
  795.     AND #$40
  796.     BEQ .set_dest
  797.     TXA
  798.     ASL
  799.     TAX
  800.     REP #$20
  801.     LDA.l !freeram_checkpoint,x
  802.     STA.l !freeram+3
  803.     SEP #$20
  804.     BRA .end_dest
  805. .set_dest
  806.     JSR CalcEntrance
  807. .end_dest
  808.     PLX
  809. .skip_mmp
  810.  
  811.     LDA $0F31|!addr
  812.     STA !freeram
  813.     LDA $0F32|!addr
  814.     STA !freeram+1
  815.     LDA $0F33|!addr
  816.     STA !freeram+2
  817.     BRA ++
  818. +
  819.     LDA !freeram+5
  820.     BNE ++
  821.  
  822.     ; normal transition (door/pipe/etc)
  823.     LDA.l $05DAA3|!bank
  824.     CMP #$5C
  825.     BEQ .normal     ; skip if mmp (no transition midpt)
  826.  
  827.     PHX
  828.     REP #$10
  829.     LDX $010B|!addr
  830.     LDA.l Table_checkpoint,x
  831.     SEP #$10
  832.     PLX
  833.     CMP #$02
  834.     BCC .normal
  835.  
  836. ++
  837.     ; first entrance from ow or respawn entrance
  838.     ; reset mode 7 values for the boss
  839.     REP #$20
  840.     STZ $36
  841.     STZ $38
  842.     STZ $3A
  843.     STZ $3C
  844.     SEP #$20
  845.     ; midway number (of mmp) whos music is backed up
  846.     LDA.l $05DAA3|!bank
  847.     CMP #$5C
  848.     BNE .not_mmp
  849.     JSR CalcMMPNum
  850.     STA !freeram+11
  851. .not_mmp
  852.     ; music backup (initial entrance or after death or transition midpt)
  853.     LDA.l $008075|!bank
  854.     CMP #$5C
  855.     BEQ +
  856.     ; nonamk
  857.     LDA $0DDA|!addr
  858.     AND #$3F
  859.     STA !freeram+6
  860.     BRA .normal
  861. +
  862.     ; amk
  863.     LDA $0DDA|!addr
  864.     STA !freeram+6
  865. .normal
  866.  
  867.     ; common (orig)
  868.     LDA #$00
  869.     STA !freeram+5  ; this flag is completely used -> reset
  870.     LDA $141A|!addr
  871.     BNE +
  872.     JML $0091AB|!bank
  873. +
  874.     JML $0091B0|!bank
  875.  
  876.  
  877. YoshiInit:
  878.     LDA $1B9B|!addr
  879.     ORA !freeram+5
  880.     BNE +
  881.     JML $02A76D|!bank
  882. +
  883.     JML $02A771|!bank
  884.  
  885.  
  886. EntranceInit0:
  887.     JSR ScreenIndexAdjust
  888.     LDA $19B8|!addr,x
  889.     STA $17BB|!addr
  890.     JML $05D7C3|!bank
  891.  
  892.  
  893. EntranceInit:       ; activated by all kind of transitions (normal things like door/pipe, or the retry)
  894.     LDA !freeram+5
  895.     BNE .orig
  896.     LDX $95
  897.     LDA $5B
  898.     AND #$01
  899.     BEQ +
  900.     LDX $97
  901. +
  902.     JSR ScreenIndexAdjust
  903.     LDA $19B8|!addr,x
  904.     STA !freeram+8
  905.     LDA $19D8|!addr,x
  906.     STA !freeram+9
  907. .orig
  908.     LDA $1B93|!addr
  909.     BEQ +
  910.     JML $05D7D9|!bank
  911. +
  912.     JML $05D83B|!bank
  913.  
  914.  
  915. ScreenIndexAdjust:
  916.     CPX #$00
  917.     BPL .positive
  918.     LDX #$00
  919.     BRA .ok
  920. .positive
  921.     CPX #$20
  922.     BMI .ok
  923.     LDX #$1F
  924. .ok
  925.     RTS
  926.  
  927.  
  928. MidbarHijack:
  929.     LDA.l $05DAA3|!bank
  930.     CMP #$5C
  931.     BEQ .skip_mmp
  932.  
  933.     JSR CalcEntrance
  934.     JSR HardSave
  935.  
  936.     ; music backup
  937.     LDA.l $008075|!bank
  938.     CMP #$5C
  939.     BEQ +
  940.     ; nonamk
  941.     LDA $0DDA|!addr
  942.     AND #$3F
  943.     STA !freeram+6
  944.     BRA ++
  945. +
  946.     ; amk
  947.     LDA $0DDA|!addr
  948.     STA !freeram+6
  949. ++
  950.  
  951. .skip_mmp
  952.     LDA #$05
  953.     STA $1DF9|!addr
  954.     JML $00F2ED|!bank
  955.  
  956.  
  957. ; always spawn the midway bar if another checkpoint is being activated (i.e. every checkpoint has the same priority)
  958. MidbarSpawn:
  959.     LDA.l $05DAA3|!bank
  960.     CMP #$5C
  961.     BNE +
  962.     ; mmp -> orig
  963.     LDA $1EA2|!addr,x
  964.     JML $0DA695|!bank
  965. +
  966.  
  967.     LDA $1EA2|!addr,x
  968.     AND #$40
  969.     BNE +
  970.     LDA $13CE|!addr
  971.     BNE +
  972. .true
  973.     JML $0DA69E|!bank
  974. +
  975.     LDA $13BF|!addr
  976.     REP #$20
  977.     AND #$00FF
  978.     CMP #$0025
  979.     BCC +
  980.     CLC
  981.     ADC #$00DC
  982. +
  983.     ORA #$0C00
  984.     CMP !freeram+3
  985.     SEP #$20
  986.     BNE .true
  987.     JML $0DA6B0|!bank
  988.  
  989.  
  990. CheckMidwayEntrance:
  991.     LDA.l $05DAA3|!bank
  992.     CMP #$5C
  993.     BNE +
  994.     ; mmp -> orig
  995.     LDA $1EA2|!addr,x
  996.     AND #$40
  997.     JML $05D9DC|!bank
  998. +
  999.     ; not mmp
  1000.     LDA $1EA2|!addr,x
  1001.     AND #$40
  1002.     STA $13CF|!addr ; for no yoshi intro
  1003.     BEQ .normal ; also if no checkpoint is obtained, midway entrances can never be the case (vanilla)
  1004.     TXA
  1005.     ASL
  1006.     TAX
  1007.     LDA.l !freeram_checkpoint+1,x
  1008.     AND #$0A
  1009.     CMP #$08        ; check the midway exit bit
  1010.     BEQ +
  1011. .normal
  1012.     ; normal target
  1013.     JML $05D9EC|!bank
  1014. +
  1015.     ; midway target
  1016.     LDA $1EA2|!addr,x
  1017.     AND #$40
  1018.     JML $05D9DE|!bank   ; go to the routine called "secondary_exits"
  1019.  
  1020.  
  1021.  
  1022. InitCheckpointRam:
  1023.     LDA.l $05DAA3|!bank
  1024.     CMP #$5C
  1025.     BEQ .skip_mmp
  1026.  
  1027.     LDX #$BE
  1028.     LDY #$5F
  1029. -
  1030.     TYA
  1031.     CMP #$25
  1032.     BCC +
  1033.     CLC
  1034.     ADC #$DC
  1035. +
  1036.     STA !freeram_checkpoint,x
  1037.     LDA #$00
  1038.     ADC #$00
  1039.     ORA #$0C    ; midpoint (default)
  1040.     STA !freeram_checkpoint+1,x
  1041.     DEX
  1042.     DEX
  1043.     DEY
  1044.     BPL -
  1045. .skip_mmp
  1046.     ; orig
  1047.     LDA #$EB
  1048.     LDY #$00
  1049.     JML $0096CF|!bank
  1050.  
  1051.  
  1052.  
  1053. VanillaMidwayDestFix:
  1054.     LDA $141A|!addr     ; first entrance -> vanilla ok
  1055.     BEQ .orig
  1056.     LDA.l $05D9E3|!bank     ; check if lm hack is applied
  1057.     CMP #$22
  1058.     BNE .orig
  1059.     LDA.l !freeram+5    ; only for respawning (when !freeram+3 is the target dest) ; todo? -> no (because doors in wing levels work differently)
  1060.     BEQ .orig
  1061.     LDA.l !freeram+4
  1062.     AND #$0A
  1063.     CMP #$08        ; check the midway exit bit
  1064.     BNE .orig
  1065.     LDA $03
  1066.     PHA
  1067.     LDA $04
  1068.     PHA
  1069.     LDA $05
  1070.     PHA
  1071.  
  1072.     LDA.l $05D9E6|!bank
  1073.     STA $05
  1074.     REP #$30
  1075.     LDA.l $05D9E4|!bank
  1076.     CLC
  1077.     ADC #$000A
  1078.     STA $03
  1079.     LDA [$03]
  1080.     PHA
  1081.     INC $03
  1082.     LDA [$03]
  1083.     STA $04
  1084.     PLA
  1085.     STA $03
  1086.     LDA !freeram+3
  1087.     AND #$01FF
  1088.     TAY
  1089.     SEP #$20
  1090.  
  1091.     LDA [$03],y
  1092.     AND #$10
  1093.     STA $01
  1094.  
  1095.     LDA $F400,y
  1096.     LSR #4
  1097.     ORA $01
  1098.     STA $01
  1099.  
  1100.     PLA
  1101.     STA $05
  1102.     PLA
  1103.     STA $04
  1104.     PLA
  1105.     STA $03
  1106. .orig
  1107.     REP #$10
  1108.     LDA $01
  1109.     JML $05D9F0|!bank
  1110.  
  1111.  
  1112. ; subroutine: returns 0 or [!RAM_Midway],lv+1
  1113. CalcMMPNum:
  1114.     PHY
  1115.     LDY $13BF|!addr
  1116.     LDA $1EA2|!addr,y
  1117.     AND #$40
  1118.     BNE +
  1119.     LDA $13CE|!addr
  1120.     BNE +
  1121.     ; no midpt yet
  1122.     LDA #$00
  1123.     PLY
  1124.     RTS
  1125. +
  1126.     REP #$20
  1127.     LDA $03
  1128.     PHA
  1129.     LDA $05
  1130.     PHA
  1131.     SEP #$20
  1132.  
  1133.     ; getting the address of !RAM_Midway
  1134.     LDA.l $05D845|!bank
  1135.     STA $05
  1136.     REP #$20
  1137.     LDA.l $05D843|!bank
  1138.     CLC
  1139.     ADC #$0025
  1140.     STA $03
  1141.     LDA [$03]
  1142.     PHA
  1143.     INC $08
  1144.     INC $08
  1145.     LDA [$03]
  1146.     STA $05
  1147.     PLA
  1148.     STA $03
  1149.  
  1150.     ; midway status of the current level
  1151.     SEP #$20
  1152.     LDY $13BF|!addr
  1153.     LDA [$03],y
  1154.     TAY
  1155.  
  1156.     REP #$20
  1157.     PLA
  1158.     STA $05
  1159.     PLA
  1160.     STA $03
  1161.     SEP #$20
  1162.     TYA
  1163.     PLY
  1164.     INC
  1165.     RTS
  1166.  
  1167.  
  1168. CalcMMP:
  1169.     PHY
  1170.     LDY $13BF|!addr
  1171.     LDA $1EA2|!addr,y
  1172.     AND #$40
  1173.     BNE +
  1174.     LDA $13CE|!addr
  1175.     BNE +
  1176.     ; no midpt yet
  1177.     JSR CalcEntrance
  1178.     PLY
  1179.     RTS
  1180. +
  1181.     REP #$20
  1182.     LDA $03
  1183.     PHA
  1184.     LDA $05
  1185.     PHA
  1186.     LDA $07
  1187.     PHA
  1188.     LDA $09
  1189.     PHA
  1190.     SEP #$20
  1191.  
  1192.     ; getting the address of !RAM_Midway
  1193.     LDA.l $05D845|!bank
  1194.     STA $0A
  1195.     REP #$20
  1196.     LDA.l $05D843|!bank
  1197.     CLC
  1198.     ADC #$0025
  1199.     STA $08
  1200.     LDA [$08]
  1201.     STA $03
  1202.     INC $08
  1203.     INC $08
  1204.     SEP #$20
  1205.     LDA [$08]
  1206.     STA $05
  1207.  
  1208.     ; getting the value of !total_midpoints
  1209.     REP #$20
  1210.     LDA $08
  1211.     CLC
  1212.     ADC #$000D
  1213.     STA $08
  1214.     LDA [$08]
  1215.     STA $06
  1216.  
  1217.     ; getting the address of level_mid_tables
  1218.     LDA $08
  1219.     CLC
  1220.     ADC #$0006
  1221.     STA $08
  1222.     LDA [$08]
  1223.     STA $08
  1224.  
  1225.     ; midway status of the current level
  1226.     SEP #$20
  1227.     LDY $13BF|!addr
  1228.     LDA [$03],y
  1229.     STA $03
  1230.     STZ $04
  1231.  
  1232.     ; index for the table
  1233.     ; assuming !total_midpoints < 256
  1234.     ; multiplication
  1235.     STY $4202
  1236.     LDA $06
  1237.     STA $4203
  1238.     NOP #4      ; 8 cycles for multiplication
  1239.     REP #$30
  1240.     LDA $4216
  1241.     CLC
  1242.     ADC $03
  1243.     ASL
  1244.     TAY
  1245.  
  1246.     ; get the table val
  1247.     LDA [$08],y
  1248.     SEP #$10
  1249.     STA $08
  1250.  
  1251.     CMP #$1000
  1252.     BCS .sec
  1253. ; midway entrance
  1254.     AND #$01FF
  1255.     ORA #$0C00
  1256.     BRA +
  1257. .sec
  1258. ; secondary entrance
  1259.     AND #$01FF
  1260.     ORA #$0600
  1261. +
  1262.     STA !freeram+3
  1263.  
  1264.     PLA
  1265.     STA $09
  1266.     PLA
  1267.     STA $07
  1268.     PLA
  1269.     STA $05
  1270.     PLA
  1271.     STA $03
  1272.     SEP #$20
  1273.     PLY
  1274.     RTS
  1275.  
  1276.  
  1277.  
  1278. org $00D0D8
  1279. if !loose_lives
  1280.     DEC $0DBE|!addr
  1281. else
  1282.     NOP #3
  1283. endif
  1284.  
  1285.  
  1286.  
  1287. if read1($008075) == $5C
  1288.     print "Detected AddmusicK"
  1289. endif
  1290.  
  1291.  
  1292.  
  1293. ; handling compatibility (sprite init facing fix)
  1294. if read1($05D971) == $22
  1295.     print "Detected the 'Sprite Initial Facing Fix' patch"
  1296. else
  1297.     org $05D971
  1298.     autoclean JML InitFace1
  1299.  
  1300.     org $05D9FC
  1301.     autoclean JML InitFace2
  1302.  
  1303.     org $05DA03
  1304.     autoclean JML InitFace3
  1305.  
  1306.     freecode
  1307.     InitFace1:
  1308.         LDA !freeram+5
  1309.         BEQ +
  1310.         LDA $94
  1311.         STA $D1     ; new
  1312.         LDA $96     ; new
  1313.         STA $D3     ; new
  1314.         LDA $97     ; new
  1315.         STA $D4     ; new
  1316.         LDA.l $05D758|!bank,x
  1317.         STA $D2     ; new
  1318.         JML $05D975|!bank
  1319.     +
  1320.         LDA.l $05D758|!bank,x
  1321.         JML $05D975|!bank
  1322.  
  1323.     InitFace2:
  1324.         STA $95
  1325.         LDA !freeram+5
  1326.         BEQ +
  1327.         LDA $95
  1328.         STA $D2     ;new
  1329.     +
  1330.         JML $05DA17|!bank
  1331.  
  1332.     InitFace3:
  1333.         STA $97
  1334.         STA $1D
  1335.         LDA !freeram+5
  1336.         BEQ +
  1337.         STA $D4     ;new
  1338.     +
  1339.         LDA $97
  1340.         JML $05DA07|!bank
  1341. endif
  1342.  
  1343.  
  1344.  
  1345. ; handling compatibility (multiple midway)
  1346. if read1($05DAA3) == $5C
  1347.     print "Detected the 'Multiple Midway Points 1.6' patch"
  1348. else
  1349.     org $05D842
  1350.         autoclean JML mmp_main
  1351.  
  1352.     ORG $05D9DE
  1353.         autoclean JML secondary_exits   ; additional code for secondary exits
  1354.  
  1355.     org $048F74
  1356.         autoclean JML reset_midpoint    ; hijack the code that resets the midway point
  1357.  
  1358.     org $05DAA3
  1359.         autoclean JSL no_yoshi      ; make secondary exits compatible with no yoshi intros
  1360.  
  1361.     freecode
  1362.  
  1363.     mmp_main:
  1364.         LDA $141A|!addr     ; skip if not the opening level
  1365.         BNE .return
  1366.         LDA $1B93|!addr     ; prevent infinite loop if using a secondary exit
  1367.         BNE .return
  1368.         LDA $0109|!addr
  1369.         BNE .code_05D8A2
  1370.         JSR get_translevel
  1371.         TAY
  1372.         ASL
  1373.         TAX
  1374.         LDA $1EA2|!addr,y
  1375.         AND #$40
  1376.         BEQ .return     ; check if any midway is activated previously
  1377.         LDA.l !freeram_checkpoint+1,x
  1378.         AND #$02        ; check the 2ndary exit bit
  1379.         BNE .secondary_exit
  1380.         REP #$20
  1381.         LDA.l !freeram_checkpoint,x
  1382.         AND #$01FF
  1383.         STA $0E         ; store level number
  1384.         JML $05D8B7|!bank       ; no need to restore the processr mode
  1385.     .return
  1386.         JML $05D847|!bank
  1387.     .code_05D8A2
  1388.         JML $05D8A2|!bank
  1389.     .secondary_exit
  1390.         LDA.l !freeram_checkpoint,x
  1391.         STA $19B8|!addr     ; store secondary exit number (low)
  1392.         LDA.l !freeram_checkpoint+1,x
  1393.         STA $19D8|!addr     ; store secondary exit number (high and properties)
  1394.         STZ $95         ; set these to 0
  1395.         STZ $97
  1396.         JML $05D7B3|!bank       ; return and load level at a secondary exit position
  1397.  
  1398.     secondary_exits:
  1399.         LDX $1B93|!addr     ; check if using a secondary exit for this
  1400.         BNE .return     ; if so, skip the code that sets mario's x position to the midway entrance
  1401.         STA $13CF|!addr     ; restore old code
  1402.         LDA $02         ; restore old code
  1403.         JML $05D9E3|!bank       ; return
  1404.     .return
  1405.         JML $05D9EC|!bank       ; return without setting mario's x to the midway entrance
  1406.  
  1407.     reset_midpoint:
  1408.         STA $1EA2|!addr,x       ; restore old code
  1409.         INC $13D9|!addr
  1410.         TXA
  1411.         ASL
  1412.         TAX
  1413.         LSR
  1414.         CMP #$0025
  1415.         BCC +
  1416.         CLC
  1417.         ADC #$00DC
  1418.     +
  1419.         ORA #$0C00
  1420.         STA !freeram_checkpoint,x
  1421.         JML $048F7A|!bank       ; return
  1422.  
  1423.     no_yoshi:
  1424.         STZ $1B93|!addr     ; reset this (prevents glitch with no yoshi intros and secondary entrances)
  1425.         LDA $05D78A|!bank,x     ; restore old code
  1426.         RTL
  1427.  
  1428.     get_translevel:
  1429.         LDY $0DD6|!addr     ;get current player*4
  1430.         LDA $1F17|!addr,y       ;ow player X position low
  1431.         LSR #4
  1432.         STA $00
  1433.         LDA $1F19|!addr,y       ;ow player y position low
  1434.         AND #$F0
  1435.         ORA $00
  1436.         STA $00
  1437.         LDA $1F1A|!addr,y       ;ow player y position high
  1438.         ASL
  1439.         ORA $1F18|!addr,y       ;ow player x position high
  1440.         LDY $0DB3|!addr     ;get current player
  1441.         LDX $1F11|!addr,y       ;get current map
  1442.         BEQ +
  1443.         CLC : ADC #$04      ;if on submap, add $0400
  1444.     +   STA $01
  1445.         REP #$10
  1446.         LDX $00
  1447.         LDA !7ED000,x       ;load layer 1 tilemap, and thus current translevel number
  1448.         STA $13BF|!addr
  1449.         SEP #$10
  1450.         RTS
  1451. endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Pastebin PRO 'SUMMER SPECIAL'!
Get 40% OFF Pastebin PRO accounts!
 
Top