News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Super Mario All Stars  (Read 2817 times)

Lenophis

  • Discord Staff
  • Hero Member
  • *****
  • Posts: 971
  • The return of the sombrero!
    • View Profile
    • Slick Productions
Super Mario All Stars
« on: May 14, 2017, 01:51:16 pm »
So I'm doing a small hack for Super Mario Bros 3 for Super Mario All Stars, but I've hit a really odd snag I can't figure out.

Going through this door to Boom Boom...


Takes you back to the first room of the fortress.

Going through the spike room door in the world 2 fortress also does the same thing, takes you back to the first room of the fortress. The only thing either of these rooms have in common is both rooms scroll.

I updated the HUD code to support 3-digit coin numbers. If I don't include the updated HUD, the doors work fine. That leads me to believe my HUD code is broken in some fashion:
Code: [Select]
org $29E6ED

LDA $1D80,X  ; with indexing, it should be at $1DA2 for mario
CLC
ADC $0422
STA $1D80,X
BCC _ThirdCoin  ; first logic check, making sure a third digit is incremented!
INC $1D82,X
_ThirdCoin:
; so now we need to do display stuff, essentially just adding in support to increment the third digit
JSL $3BF400  ; update coins
STZ $0422
RTS

padbyte $00 : pad $29E72F


org $3BF400
REP #$20
PHA  ; save upper A before it gets destroyed, just in case it's needed
SEP #$20
LDA $1D82,X
XBA
LDA $1D80,X
REP #$20
CMP #$03E8  ; 1000 coins?
BCC not_maxed_out ; this branch will generally always be taken
; but if for some reason it's not, let's do max numbers
PLA  ; restore A
SEP #$20
LDA #$E8
STA $1D80,X
LDA #$03
STA $1D82,X
LDA #$99
STA $1F30
STA $1F48
STA $1F49
RTL

not_maxed_out:
STA $1F60  ; store it away for now
SEP #$20
LDA #$03  ; 3 loops
STA $1F62
PHY  ; preserve Y, we likely need it
LDY #$00
TYX
mathloop1:
REP #$20
LDA numbertable,X
INX
INX
STA $1F63  ; for math
STZ $1F65  ; and more math
mathloop3:
SEC
LDA $1F60  ; load our original value
SBC $1F63  ; and subtract our LUTs value, either 100, 10, or 1
BCC mathloop2  ; if carry is clear, we wrapped
STA $1F60
INC $1F65
BRA mathloop3
mathloop2:
CLC
ADC $1F63
STA $1F60  ; effectively restoring our original value
SEP #$20
LDA $1F65
ORA #$90
STA $1F67,Y
INY
DEC $1F62
BNE mathloop1
PLY
REP #$20
PLA
SEP #$20
; now that all of the conversions are done, we need to get them to display
LDA $1F68
STA $1F48  ; ten's digit
LDA $1F69
STA $1F49  ; one's digit
LDA $1F67
STA $1F30  ; hundred's digit
RTL

numbertable:
DW $0064
DW $000A
DW $0001

I've used different values for my math, including scratch DP and other locations in ram that don't look like they're used. I've run comparison traces from original and this hack, and no appreciable differences have been spotted. This HUD is updated every frame, but doesn't execute while Mario is in the process of going through a door. The stack is still stable, correct bank is still in play, and register sizes are what they should be.

My best guesses are either I've triggered some goofy copy-protection, or my code is just too slow. If it's too slow, it's only by a matter of cycles, since the vanilla game uses a rather sloppy method to do 2-digit coin display.

Would anyone be willing to take a look at it and see what could be wrong?


https://ff6randomizer.codeplex.com/ - Randomize your FF6 experience!

rainponcho

  • Sr. Member
  • ****
  • Posts: 275
    • View Profile
Re: Super Mario All Stars
« Reply #1 on: May 15, 2017, 09:39:59 am »
Memory conflict:
1f67 = bad! must stay B7
wrong ex. set FF = drop room, 27 = scroll room


$29/E12B BD 66 1F    LDA $1F66,x[$21:1F67]   A:E100 X:0001 Y:0000 P:envMXdiZc


edit:
for temp vars 1f67,1f68,1f69 - you can use stack as a temporary

pha
pha
sta $00,s
sta $01,s
« Last Edit: May 15, 2017, 12:17:14 pm by rainponcho »

Lenophis

  • Discord Staff
  • Hero Member
  • *****
  • Posts: 971
  • The return of the sombrero!
    • View Profile
    • Slick Productions
Re: Super Mario All Stars
« Reply #2 on: May 15, 2017, 03:31:50 pm »
Wow, that was it! I never thought to check for conflicts like that. My own fault for not doing any real assembly work in 3 years. Thanks for that.  :thumbsup:


https://ff6randomizer.codeplex.com/ - Randomize your FF6 experience!