How do I fix MZ's(and now SYZ's as well) Background in Sonic 2?

Discussion in 'Discussion & Q&A' started by Blue Gamer, Feb 11, 2025.

  1. Blue Gamer

    Blue Gamer Autistic Member Member

    Joined:
    Aug 16, 2024
    Messages:
    191
    Location:
    Mysterious Marble Zone, Bird Hill Island
    I got this bug when porting Marble's Background Scrolling in the newest github disasm ( the lava is fine since I havent Ported it yet)

    SONIC THE HEDGEHOG 2 2_10_2025 6_44_52 PM.png

    Heres the Code in case anyone is asking
    Code:
    Bg_Scroll_X:
            lea    ($FFFFE000).w,a1
            move.w    #$E,d1
            move.w    (Camera_X_pos).w,d0
            neg.w    d0
            swap    d0
            andi.w    #$F,d2
            add.w    d2,d2
            move.w    (a2)+,d0
            jmp    .pixelJump(pc,d2.w)        ; skip pixels for first row
        .blockLoop:
            move.w    (a2)+,d0
        .pixelJump:   
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            move.l    d0,(a1)+
            dbf    d1,.blockLoop
            rts
    
    SwScrl_ARZ:
        ; block 1 - dungeon interior
            move.w    ($FFFFEEB0).w,d4
            ext.l    d4
            asl.l    #6,d4
            move.l    d4,d1
            asl.l    #1,d4
            add.l    d1,d4
            moveq    #2,d6
            bsr.w    SetHorizScrollFlagsBG
        ; block 3 - mountains
            move.w    ($FFFFEEB0).w,d4
            ext.l    d4
            asl.l    #6,d4
            moveq    #6,d6
            bsr.w    ScrollBlock6
        ; block 2 - bushes & antique buildings
            move.w    ($FFFFEEB0).w,d4
            ext.l    d4
            asl.l    #7,d4
            moveq    #4,d6
            bsr.w    SetHorizScrollFlagsBG2
        ; calculate y-position of background
            move.w    #$200,d0    ; start with 512px, ignoring 2 chunks
            move.w    (Camera_Y_pos).w,d1
            subi.w    #$1C8,d1    ; 0% scrolling when y <= 56px
            bcs.s    .noYscroll
            move.w    d1,d2
            add.w    d1,d1
            add.w    d2,d1
            asr.w    #2,d1
            add.w    d1,d0
        .noYscroll:
            move.w    d0,(Camera_BG2_Y_pos).w
            move.w    d0,($FFFFEE1C).w
            bsr.w    ScrollBlock3
            move.w    (Camera_BG_Y_pos).w,(Vscroll_Factor_BG).w
        ; do something with redraw flags
            move.b    (Scroll_flags_BG).w,d0
            or.b    (Scroll_flags_BG2).w,d0
            or.b    d0,(Scroll_flags_BG3).w
            clr.b    (Scroll_flags_BG).w
            clr.b    (Scroll_flags_BG2).w
        ; calculate background scroll buffer
            lea    ($FFFFA800).w,a1
            move.w    (Camera_X_pos).w,d2
            neg.w    d2
            move.w    d2,d0
            asr.w    #2,d0
            sub.w    d2,d0
            ext.l    d0
            asl.l    #3,d0
            divs.w    #5,d0
            ext.l    d0
            asl.l    #4,d0
            asl.l    #8,d0
            moveq    #0,d3
            move.w    d2,d3
            asr.w    #1,d3
            move.w    #4,d1
        .cloudLoop:   
            move.w    d3,(a1)+
            swap    d3
            add.l    d0,d3
            swap    d3
            dbf    d1,.cloudLoop
    
            move.w    (Camera_BG3_X_pos).w,d0
            neg.w    d0
            move.w    #1,d1
        .mountainLoop:   
            move.w    d0,(a1)+
            dbf    d1,.mountainLoop
    
            move.w    (Camera_BG2_X_pos).w,d0
            neg.w    d0
            move.w    #8,d1
        .bushLoop:   
            move.w    d0,(a1)+
            dbf    d1,.bushLoop
    
            move.w    (Camera_BG_X_pos).w,d0
            neg.w    d0
            move.w    #$F,d1
        .interiorLoop:   
            move.w    d0,(a1)+
            dbf    d1,.interiorLoop
    
            lea    ($FFFFA800).w,a2
            move.w    (Camera_BG_Y_pos).w,d0
            subi.w    #$200,d0    ; subtract 512px (unused 2 chunks)
            move.w    d0,d2
            cmpi.w    #$100,d0
            blo.s    .limitY
            move.w    #$100,d0
        .limitY:
            andi.w    #$1F0,d0
            lsr.w    #3,d0
            lea    (a2,d0.w),a2
            bra.w    Bg_Scroll_X
    ; End of function Deform_MZ
     
    Last edited: Feb 12, 2025
  2. Clownacy

    Clownacy Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,116
    Marble Zone has custom code in the 'Draw_BG3' function. Sonic 2 removed it, but it can be found in Sonic 1's equivalent, 'DrawBGScrollBlock3'.
     
    PeanutNoceda and Blue Gamer like this.
  3. Blue Gamer

    Blue Gamer Autistic Member Member

    Joined:
    Aug 16, 2024
    Messages:
    191
    Location:
    Mysterious Marble Zone, Bird Hill Island
    Thanks! I’m using OOZs Bg code as a placeholder now because I don’t want to port the code yet.
     
  4. Blue Gamer

    Blue Gamer Autistic Member Member

    Joined:
    Aug 16, 2024
    Messages:
    191
    Location:
    Mysterious Marble Zone, Bird Hill Island
    So I fixed that bug, but now I have a new bug:
    SONIC THE HEDGEHOG 2 4_14_2025 7_40_46 PM.png
    and this as well (dont look at the glitched tiles, look at the background position):
    SONIC THE HEDGEHOG 2 4_15_2025 7_22_58 AM.png
    How do I fix these?
     
    Last edited: Apr 15, 2025
  5. Blue Gamer

    Blue Gamer Autistic Member Member

    Joined:
    Aug 16, 2024
    Messages:
    191
    Location:
    Mysterious Marble Zone, Bird Hill Island
    nvm, found out it was slightly different code in s2 and s1.