Puzzle Bobble / Bust-A-Move

Page 2 of 2 Previous  1, 2

Go down

 Puzzle Bobble / Bust-A-Move - Page 2 Empty Re: Puzzle Bobble / Bust-A-Move

Post by Cubear Sun 28 Aug 2022 - 1:52

zdrmonstera
Code:

lorom

macro CheckNoMSU(labelToJump)
 LDA $2002   ; Stolen from the MSU-1 port of Super Mario World (Plus), sue me.
 CMP #$53
 BNE <labelToJump>
endmacro

org $05B938
autoclean JSL spc_mute
nop
nop

org $80be01
autoclean JSL pause

;org $108000 Might work, might not work.
freedata
spc_mute:
    LDA $0512,X
    CMP #$00
    BEQ stop_music
    cmp #$29
    bcs not_music
    SEC ; Set Carry Flag
    SBC #$20
    BCC not_music ; If sound value is less than 20, branch to a duplicate of the original code.
    %CheckNoMSU(not_music) ; Same thing for if there is no MSU1 "chip".
    LDA #$00
    STA $2143 ; Otherwise...
    lda $0512,X
    SEC ; Set Carry Flag
    SBC #$1F
msuunpause:
    PHA
 Sta $2004 ;store incoming track to MSU1
    STA $0430 ; Not sure if this is good, but should work.
    Stz $2005 ;zero to msu1 high byte. looks like 00XX for track number
    STZ $2006 ;zero to 2006.stops static/noise from msu during track loading on console.

loop:
    Bit $2000 ;checking MSU1 state
    BVS loop

    LDA $2000;
    AND #$08 ; is the track found?
    BEQ $02 ;if yes, don't play spc.
    bra not_music2
    PLA
;noloop tracks here
    cmp #$02 ;noloop 1
    beq noloop
    cmp #$03 ;noloop2
    beq noloop
    cmp #$04 ;noloop2
    beq noloop
    cmp #$06 ;noloop2
    beq noloop
    LDA #$03 ;everything else loops
    bra $02
noloop:
    LDA #$01
    STA $2007 ; sets MSU play
    LDA #$FF ;\raises volume
    STA $2006;/
RTL

not_music2:
    pla
not_music:
    LDA $0512,X
    STA $2143
RTL

stop_music:
    STZ $2143
    %CheckNoMSU(stop_music2)
    STZ $2007
stop_music2:
    nop
RTL

pause:
    eor $0840;native code
    sta $0840;native code

    PHP;saves the processor bits
    SEP #$20 ;puts A into 8-bit mode
    %CheckNoMSU(pauseB)
    lda $0841
    cmp #$10
    beq dopause
    cmp #$00
    beq dounpause
pauseB:
    PLP
RTL

dopause:
    %CheckNoMSU(dopause2)
    LDA #$04
    STA $2007 ; sets MSU play
    nop
    STZ $2007 ; sets MSU play
dopause2:
    nop
    nop
    nop
    PLP
RTL

dounpause:
    lda $0430
    jsl msuunpause
    PLP
RTL


well, the code we are replacing to hook at pause is once again 6 bytes in length. so you need two more NOP commands at the hook to avoid wrong execution of code

you don't need the macro msu detection at all for dopause, since to get to dopause you have already passed the check.


other than those issues this looks good.
Cubear
Cubear

 Puzzle Bobble / Bust-A-Move - Page 2 Image211

Since : 2021-11-17

https://www.patreon.com/Cubear

Back to top Go down

 Puzzle Bobble / Bust-A-Move - Page 2 Empty Re: Puzzle Bobble / Bust-A-Move

Post by Conn Sun 28 Aug 2022 - 7:33

Just a few common notes to avoid troubles when hijacking code:

1. always nop out the correct number of bytes where you hijack, you need to count, for example
Stz $0101
Stz $02
Are 5 bytes, a jsl takes 4 bytes, so 1 nop
Stz $0101
Stz $0202
Are 6 bytes so 2 nops after your jsl

2.
Execute the code you overwrote for hijacking in the new code area. This is almost always necessary, for example:
.Freespace:
Stz $0101
Stz $02
...then write your new code

3. Whenever you change something in a, x, y, or processor status, push the values on stack first to restore them later, e.g.
.freespace:
Pha
PHX
Phy
PHP
Sep #$20
....your code
Plp
Ply
Plx
Pla
RTL
(Pull stack in reversed order)

With these Tipps you may avoid some frustrations Very Happy
Conn
Conn

 Puzzle Bobble / Bust-A-Move - Page 2 Image212

Since : 2013-06-30

Back to top Go down

 Puzzle Bobble / Bust-A-Move - Page 2 Empty Re: Puzzle Bobble / Bust-A-Move

Post by zdrmonstera Sun 28 Aug 2022 - 10:36

Cubear wrote:zdrmonstera
Code:

lorom

macro CheckNoMSU(labelToJump)
 LDA $2002   ; Stolen from the MSU-1 port of Super Mario World (Plus), sue me.
 CMP #$53
 BNE <labelToJump>
endmacro

org $05B938
autoclean JSL spc_mute
nop
nop

org $80be01
autoclean JSL pause

;org $108000 Might work, might not work.
freedata
spc_mute:
    LDA $0512,X
    CMP #$00
    BEQ stop_music
    cmp #$29
    bcs not_music
    SEC ; Set Carry Flag
    SBC #$20
    BCC not_music ; If sound value is less than 20, branch to a duplicate of the original code.
    %CheckNoMSU(not_music) ; Same thing for if there is no MSU1 "chip".
    LDA #$00
    STA $2143 ; Otherwise...
    lda $0512,X
    SEC ; Set Carry Flag
    SBC #$1F
msuunpause:
    PHA
 Sta $2004 ;store incoming track to MSU1
    STA $0430 ; Not sure if this is good, but should work.
    Stz $2005 ;zero to msu1 high byte. looks like 00XX for track number
    STZ $2006 ;zero to 2006.stops static/noise from msu during track loading on console.

loop:
    Bit $2000 ;checking MSU1 state
    BVS loop

    LDA $2000;
    AND #$08 ; is the track found?
    BEQ $02 ;if yes, don't play spc.
    bra not_music2
    PLA
;noloop tracks here
    cmp #$02 ;noloop 1
    beq noloop
    cmp #$03 ;noloop2
    beq noloop
    cmp #$04 ;noloop2
    beq noloop
    cmp #$06 ;noloop2
    beq noloop
    LDA #$03 ;everything else loops
    bra $02
noloop:
    LDA #$01
    STA $2007 ; sets MSU play
    LDA #$FF ;\raises volume
    STA $2006;/
RTL

not_music2:
    pla
not_music:
    LDA $0512,X
    STA $2143
RTL

stop_music:
    STZ $2143
    %CheckNoMSU(stop_music2)
    STZ $2007
stop_music2:
    nop
RTL

pause:
    eor $0840;native code
    sta $0840;native code

    PHP;saves the processor bits
    SEP #$20 ;puts A into 8-bit mode
    %CheckNoMSU(pauseB)
    lda $0841
    cmp #$10
    beq dopause
    cmp #$00
    beq dounpause
pauseB:
    PLP
RTL

dopause:
    %CheckNoMSU(dopause2)
    LDA #$04
    STA $2007 ; sets MSU play
    nop
    STZ $2007 ; sets MSU play
dopause2:
    nop
    nop
    nop
    PLP
RTL

dounpause:
    lda $0430
    jsl msuunpause
    PLP
RTL


well, the code we are replacing to hook at pause is once again 6 bytes in length. so you need two more NOP commands at the hook to avoid wrong execution of code

you don't need the macro msu detection at all for dopause, since to get to dopause you have already passed the check.


other than those issues this looks good.
I didn't see this before I realized there was a number 2 at the bottom of the page (haha), so I brought out Mesen-S's debugger and figured out to put in the two nops myself. Now that the patch is complete for the PAL version, how would I go about porting it to Bust-A-Move (US version)?

9:XX AM code (In case you didn't see it in the edit):
Code:

lorom

macro CheckNoMSU(labelToJump)
   LDA $2002  ; Stolen from the MSU-1 port of Super Mario World (Plus), sue me.
   CMP #$53
   BNE <labelToJump>
endmacro

org $05B938
autoclean JSL spc_mute
nop
nop

org $80be01
autoclean JSL pause
nop
nop

;org $108000 Might work, might not work.
freedata
spc_mute:
    LDA $0512,X
    CMP #$00
    BEQ stop_music
    cmp #$29
    bcs not_music
    SEC ; Set Carry Flag
    SBC #$20
    BCC not_music ; If sound value is less than 20, branch to a duplicate of the original code.
    %CheckNoMSU(not_music) ; Same thing for if there is no MSU1 "chip".
    LDA #$00
    STA $2143 ; Otherwise...
    lda $0512,X
    SEC ; Set Carry Flag
    SBC #$1F
msuunpause:
    PHA
   Sta $2004 ;store incoming track to MSU1
    STA $0430 ; Not sure if this is good, but should work.
    Stz $2005 ;zero to msu1 high byte. looks like 00XX for track number
    STZ $2006 ;zero to 2006.stops static/noise from msu during track loading on console.

loop:
    Bit $2000 ;checking MSU1 state
    BVS loop

    LDA $2000;
    AND #$08 ; is the track found?
    BEQ $02 ;if yes, don't play spc.
    bra not_music2
    PLA
;noloop tracks here
    cmp #$02 ;noloop 1
    beq noloop
    cmp #$03 ;noloop2
    beq noloop
    cmp #$04 ;noloop2
    beq noloop
    cmp #$06 ;noloop2
    beq noloop
    LDA #$03 ;everything else loops
    bra $02
noloop:
    LDA #$01
    STA $2007 ; sets MSU play
    LDA #$FF ;\raises volume
    STA $2006;/
RTL

not_music2:
    pla
not_music:
    LDA $0512,X
    STA $2143
RTL

stop_music:
    STZ $2143
    %CheckNoMSU(stop_music2)
    STZ $2007
stop_music2:
    nop
RTL

pause:
    eor $0840;native code
    sta $0840;native code

    PHP;saves the processor bits
    SEP #$20 ;puts A into 8-bit mode
    %CheckNoMSU(pauseB)
    lda $0841
    cmp #$10
    beq dopause
    cmp #$00
    beq dounpause
pauseB:
    PLP
RTL

dopause:
    LDA #$04
    STA $2007 ; sets MSU play
dopause2:
    nop
    nop
    nop
    PLP
RTL

dounpause:
    lda $0430
    jsl msuunpause
    PLP
RTL

zdrmonstera

 Puzzle Bobble / Bust-A-Move - Page 2 Image111

Since : 2022-08-26

Back to top Go down

 Puzzle Bobble / Bust-A-Move - Page 2 Empty Re: Puzzle Bobble / Bust-A-Move

Post by Cubear Sun 28 Aug 2022 - 10:45

most of the time, a different version of the game will have very similar code, maybe with a few things moved at the time the rom was assembled/compiled

porting your code to a different version means finding where in that new rom all your hooks are supposed to be.

there's a few ways to do this, you can breakpoint the same ways and find the same things, or you can search the rom with a hex editor (using the hex for the original code) to find the new addresses.
Cubear
Cubear

 Puzzle Bobble / Bust-A-Move - Page 2 Image211

Since : 2021-11-17

https://www.patreon.com/Cubear

Back to top Go down

 Puzzle Bobble / Bust-A-Move - Page 2 Empty Re: Puzzle Bobble / Bust-A-Move

Post by Cubear Sun 28 Aug 2022 - 10:58

i use bsnes plus for its debugger, so you may have a different experience through this, but i open up the "memory manager" and go to the address of my hook.

 Puzzle Bobble / Bust-A-Move - Page 2 2wTlKUm.
that's your "pause" hook in the PAL rom (unmodified)

i copy it out and put it into the "search hex" function in a hex editor
 Puzzle Bobble / Bust-A-Move - Page 2 Vjw0J2O
i usually try two or three searches just to make sure i didn't make a mistake. you can tell if you get the right one because the hex code before your instructions is the same ($3D)

 Puzzle Bobble / Bust-A-Move - Page 2 PLXHWi1
here's the file in HxD, a free hex editor. you can see it found the hook's native code, and the preceding value is also $3D so this is likely the spot.

then you need to convert the PC address back to a SNES address
 Puzzle Bobble / Bust-A-Move - Page 2 7K9Q6s8

so $00be01 should be where you can hook in the USA rom for pausing.
Cubear
Cubear

 Puzzle Bobble / Bust-A-Move - Page 2 Image211

Since : 2021-11-17

https://www.patreon.com/Cubear

Back to top Go down

 Puzzle Bobble / Bust-A-Move - Page 2 Empty Re: Puzzle Bobble / Bust-A-Move

Post by Cubear Sun 28 Aug 2022 - 11:00

looking at this from here though, this is a lot of work to show you that your hooks are probably fine and don't need to be changed, but it is good for you to learn to do this >:)
Cubear
Cubear

 Puzzle Bobble / Bust-A-Move - Page 2 Image211

Since : 2021-11-17

https://www.patreon.com/Cubear

Back to top Go down

 Puzzle Bobble / Bust-A-Move - Page 2 Empty Re: Puzzle Bobble / Bust-A-Move

Post by zdrmonstera Sun 28 Aug 2022 - 12:48

I think my patch is pretty much now complete, where can I submit it and what are the requirements for a MSU-1 hack to get onto the database?

zdrmonstera

 Puzzle Bobble / Bust-A-Move - Page 2 Image111

Since : 2022-08-26

Back to top Go down

 Puzzle Bobble / Bust-A-Move - Page 2 Empty Re: Puzzle Bobble / Bust-A-Move

Post by Cubear Sun 28 Aug 2022 - 13:00

well, it's not "complete" until you have a PCM pack to go with it, once that is done you can post it yourself in the database section Smile
Cubear
Cubear

 Puzzle Bobble / Bust-A-Move - Page 2 Image211

Since : 2021-11-17

https://www.patreon.com/Cubear

Back to top Go down

Page 2 of 2 Previous  1, 2

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum