Sonic 1 Github - Adding a new level/ Adding water to zones

Discussion in 'Discussion & Q&A' started by Scrap Sorra, Oct 2, 2020.

  1. Scrap Sorra

    Scrap Sorra Well-Known Member Member

    Joined:
    Sep 18, 2020
    Messages:
    112
    Location:
    Development Hell
    I wanted to add a new level to Sonic 1 (Github disassembly), but the only tutorial I could find is for the Hivebrain disassembly, and when I tried to do that and convert it to Github it didn't work at all. Can someone help me add a new level? I also wanted to add water to GHZ, SBZ, and the new level I want to add. Is there a way to add water to existing zones?
     
  2. TheInvisibleSun

    TheInvisibleSun Visible Member

    Joined:
    Jul 2, 2013
    Messages:
    424
    Location:
    Western New York, USA
    For Sonic 1, adding water is quite simple: enabling water in zones simply involves modifying the several checks for Labyrinth Zone throughout the disassembly, since that is the only zone containing water in Sonic 1. The next task would be to then modify LZ Water Features to suit each zone as needed, since by default every level will use Labyrinth's dynamic water levels, wind tunnels, water slides, etc.

    This might be a question better suited for the Basic Question and Answer Thread, for future reference.
     
  3. nineko

    nineko I am the Holy Cat Member

    Joined:
    Mar 24, 2008
    Messages:
    1,902
    Location:
    italy
    I disagree, this is probably a popular enough question so it's good if it's easily retrievable for future reference, other people might be working with the github disassemly and they can share their doubts and their thoughts here. Not that I'm in favour of the github disassembly, though, Hivebrain ftw.
     
  4. TheInvisibleSun

    TheInvisibleSun Visible Member

    Joined:
    Jul 2, 2013
    Messages:
    424
    Location:
    Western New York, USA
    That's a good point, but could it not still be searched for in the thread? But given how extensive adding a new zone is in terms of info, it could be worth having it neatly packaged in a new thread.
     
    nineko likes this.
  5. Scrap Sorra

    Scrap Sorra Well-Known Member Member

    Joined:
    Sep 18, 2020
    Messages:
    112
    Location:
    Development Hell
    So I went ahead and added checks for GHZ and SBZ and added entries for them in the LZ water features subroutine, but the levels won't load in game. Is there a more direct method of doing this rather than having to aimlessly comb through my files?
     
  6. TheInvisibleSun

    TheInvisibleSun Visible Member

    Joined:
    Jul 2, 2013
    Messages:
    424
    Location:
    Western New York, USA
    Can you be more specific about what you did and/or what's going wrong? You should run a search for every instance of that Labyrinth Zone check in the entire disassembly (once you find one, just use that to search). Either add additional checks for the zones you want, or comment them out to enable water everywhere.
     
  7. Scrap Sorra

    Scrap Sorra Well-Known Member Member

    Joined:
    Sep 18, 2020
    Messages:
    112
    Location:
    Development Hell
    I searched "LZ" in my disassembly folder and added entries for GHZ and SBZ when applicable. I know I added checks for them in sonic.asm and LZWaterFeatures.asm and tried to get the game to load the bubble/water surface art in Pattern Load Cues.asm. I removed all of those changes because they didn't work and the zones wouldn't load in game at all.
     
  8. TheInvisibleSun

    TheInvisibleSun Visible Member

    Joined:
    Jul 2, 2013
    Messages:
    424
    Location:
    Western New York, USA
    Ok, now that I have time, I'll go into detail:

    First, open sonic.asm and go to 'VBla_00':


    Code:
    VBla_00:
            cmpi.b    #$80+id_Level,(v_gamemode).w
            beq.s    @islevel
            cmpi.b    #id_Level,(v_gamemode).w ; is game on a level?
            bne.w    VBla_Music    ; if not, branch
        @islevel:
            ;cmpi.b    #id_LZ,(v_zone).w ; is level LZ ? -->TIS Add to/Modify/Remove this Check
            ;bne.w    VBla_Music    ; if not, branch -->TIS Add to/Modify/Remove this Check
    ...
    Then, proceed to 'FadeIn_FromBlack':

    Code:
    FadeIn_FromBlack:
            moveq    #0,d0
            lea    (v_pal_dry).w,a0
            lea    (v_pal_dry_dup).w,a1
            move.b    (v_pfade_start).w,d0
            adda.w    d0,a0
            adda.w    d0,a1
            move.b    (v_pfade_size).w,d0
        @addcolour:
            bsr.s    FadeIn_AddColour ; increase colour
            dbf    d0,@addcolour    ; repeat for size of palette
            ;cmpi.b    #id_LZ,(v_zone).w    ; is level Labyrinth? -->TIS Add to/Modify/Remove this Check
            ;bne.s    @exit        ; if not, branch -->TIS Add to/Modify/Remove this Check
    ...
    Then do the same here:

    Code:
    WhiteIn_FromWhite:
            moveq    #0,d0
            lea    (v_pal_dry).w,a0
            lea    (v_pal_dry_dup).w,a1
            move.b    (v_pfade_start).w,d0
            adda.w    d0,a0
            adda.w    d0,a1
            move.b    (v_pfade_size).w,d0
        @decolour:
            bsr.s    WhiteIn_DecColour ; decrease colour
            dbf    d0,@decolour    ; repeat for size of palette
            ;cmpi.b    #id_LZ,(v_zone).w    ; is level Labyrinth? -->TIS Add to/Modify/Remove this Check
            ;bne.s    @exit        ; if not, branch -->TIS Add to/Modify/Remove this Check
    
    Then here:
    Code:
    Level_ClrVars3:
            move.l    d0,(a1)+
            dbf    d1,Level_ClrVars3 ; clear object variables
            disable_ints
            bsr.w    ClearScreen
            lea    (vdp_control_port).l,a6
            move.w    #$8B03,(a6)    ; line scroll mode
            move.w    #$8200+(vram_fg>>10),(a6) ; set foreground nametable address
            move.w    #$8400+(vram_bg>>13),(a6) ; set background nametable address
            move.w    #$8500+(vram_sprites>>9),(a6) ; set sprite table address
            move.w    #$9001,(a6)        ; 64-cell hscroll size
            move.w    #$8004,(a6)        ; 8-colour mode
            move.w    #$8720,(a6)        ; set background colour (line 3; colour 0)
            move.w    #$8A00+223,(v_hbla_hreg).w ; set palette change position (for water)
            move.w    (v_hbla_hreg).w,(a6)
            ;cmpi.b    #id_LZ,(v_zone).w ; is level LZ? -->TIS Add to/Modify/Remove this Check
            ;bne.s    Level_LoadPal    ; if not, branch -->TIS Add to/Modify/Remove this Check
    ...
    Then here...

    Code:
    Level_LoadPal:
            move.w    #30,(v_air).w
            enable_ints
            moveq    #palid_Sonic,d0
            bsr.w    PalLoad2    ; load Sonic's palette
            ;cmpi.b    #id_LZ,(v_zone).w ; is level LZ? -->TIS Add to/Modify/Remove this Check
            ;bne.s    Level_GetBgm    ; if not, branch -->TIS Add to/Modify/Remove this Check
    ...
    
    Then here...

    Code:
    Level_ChkWater:
            move.w    #0,(v_jpadhold2).w
            move.w    #0,(v_jpadhold1).w
            ;cmpi.b    #id_LZ,(v_zone).w ; is level LZ? -->TIS Add to/Modify/Remove this Check
            ;bne.s    Level_LoadObj    ; if not, branch -->TIS Add to/Modify/Remove this Check
    ...
    
    Then here...

    Code:
    Level_ChkWaterPal:
            ;cmpi.b    #id_LZ,(v_zone).w ; is level LZ/SBZ3? -->TIS Add to/Modify/Remove this Check
            ;bne.s    Level_Delay    ; if not, branch -->TIS Add to/Modify/Remove this Check
            moveq    #palid_LZWater,d0 ; palette $B (LZ underwater)
    ...
    
    Next, open 'Sonic Water.asm', and add to/modify this check:

    Code:
    Sonic_Water:
            cmpi.b    #1,(v_zone).w    ; is level LZ? -->TIS Add to/Modify/Remove this Check
            bra.s    @islabyrinth    ; branch anyway -->TIS Add to/Modify/Remove this Check
    ...
    
    Next, open 'LZWaterFeatures.asm':

    Go here:
    Code:
    LZWaterFeatures:
            ;cmpi.b    #id_LZ,(v_zone).w ; check if level is LZ -->TIS Add to/Modify/Remove this Check
            ;bne.s    @notlabyrinth    ; if not, branch -->TIS Add to/Modify/Remove this Check
    
    Then here, you may want to add checks for your new zones so that Sonic doesn't get zipped around the level according to LZ's positioning:

    Code:
    
    LZWindTunnels:
            cmpi.b    #id_LZ,(v_zone).w ; check if level is LZ -->TIS Add to/Modify/Remove this Check
            beq.w    IsLabyrinth    ; if so, branch -->TIS Add to/Modify/Remove this Check
            rts ;-->TIS Add to/Modify/Remove this Check
        IsLabyrinth: ;-->TIS Add to/Modify/Remove this Check
            tst.w    (v_debuguse).w    ; is debug mode    being used?
            bne.w    @quit    ; if yes, branch
            lea    (LZWind_Data+8).l,a2
    ...
    and then here:

    Code:
    LZWaterSlides:
            cmpi.b    #id_LZ,(v_zone).w ; check if level is LZ -->TIS Add to/Modify/Remove this Check
            beq.s    Islabyrinth2    ; if so, branch -->TIS Add to/Modify/Remove this Check
            rts ;-->TIS Add to/Modify/Remove this Check
        Islabyrinth2: ;-->TIS Add to/Modify/Remove this Check
            lea    (v_player).w,a1
            btst    #1,obStatus(a1)    ; is Sonic jumping?
            bne.s    loc_3F6A    ; if not, branch
    ...
    If so desired, you may also need to modify the DynamicWater subroutine as well to suit your different levels, but this is not needed for water to function in said levels.

    Do note that I avoided any of the checks for SBZ3, since those checks typically have to do with that act specifically.

    Also note, you will need to add new water palettes to your new zones as well (and properly code them with their respective checks, etc.) if desired, otherwise they will load LZ's underwater palette.

    I have also omitted any changes to the ResumeMusic subroutine, which if unmodified, will always play Labyrinth's lovely background music when you've recovered from the drowning theme.

    Regarding art, the bubbles and countdown numbers in Sonic 1 take up a ton of space in VRAM, and are naturally difficult to fit in most zones as-is. I've been able to maneuver around the PLC's and fit it in for a zone or two (namely, Marble Zone), but even then, I think I sacrificed a couple of objects to do so. Perhaps there is a more efficient way of loading this art or handling/shifting the PLC's (Sonic 3 is interesting in that it loads the countdown numbers separately as uncompressed art, into the same space as the spindash dust, so that it not only uses fewer tiles, but it just swaps places with already occupied VRAM space, making it ultra efficient). PLC's are a different, much larger discussion/explanation, and not only am I not the best person to explain it, but attempting to do so here would result in an even longer overly long post.

    So yeah, the above is the bare minimum needed for adding water to every zone; the code I have provided will thus only do so indiscriminately; it's up to you to sort out what zones you want to include/exclude, and further customize things as you please, so I'll leave that to you (I assume you understand how this is done, based on your previous reply). Attached is a ROM with the above code changes completed, from a clean Git disassembly.
     

    Attached Files:

    Last edited: Jan 19, 2022
    DeltaWooloo and Scrap Sorra like this.
  9. Grosy

    Grosy Romhacker + owns a mega drive 2 Member

    Joined:
    Dec 30, 2021
    Messages:
    36
    Hey, I kind of want to help with the new zone (id 07). If you still need the tutorial I am willing to help.