[Sonic 1 GitHub] How to restore Splats

Discussion in 'Tutorials' started by Techokami, Jun 26, 2021.

  1. Techokami

    Techokami For use only on NTSC Genesis Systems. Member

    Joined:
    Oct 29, 2007
    Messages:
    20
    Location:
    LINUX
    I WANT SPLATS THE RABBIT IN MY SONIC THE HEDGEHAUG HAACK

    [​IMG] okay

    ============================================

    WHAT YOU NEED
    - Your Sonic 1 disassembly project. This guide was written using the ASM68K branch of Sonic 1 GitHub, but will work in the AS branch and Project 1: Two Eight branch as well. You might have to tweak some things for working with Hivebrain's disassembly.
    - BetaFilter's Sonic 1 Prototype Disassembly. We will be pulling in data from this.

    ============================================

    STEP 1: Importing the mappings
    From the proto disassembly, copy "Map/Splats.asm" to "_maps/Splats.asm" in your disassembly project.
    Now open the file in your editor of choice. Comparing the structure with another mapping file (Jaws has a simple one to follow), clean it up to make it more consistent with the rest of the project. So, we will change the mapping index label from "Splats_Map" to "Map_Splats_internal" and use local labels for the two frames, and split the mappings so that there is only one mapping per line. You technically don't have to do this, but it makes things a bit more consistent and might help with loading the mappings in Flex2.

    STEP 2: Adding the mappings to the game
    Open up "sonic.asm" and search for the line:
    Code:
    include	"_incObj\4F.asm"
    Object 4F was Splats' original object ID. You might have repurposed this ID already; this guide will assume that you have not yet done so for the time being, but there will be a section later explaining the simple steps to add new objects to the object list. Right now, though, we want to include the mappings file we imported, so below this line add an include statement to this file with a label "Map_Splats".

    STEP 3: Importing the object code
    Open up "_incObj/4F.asm" and you will be greeted to an empty object. Well, time to fix that! In the proto disassembly, open up "sonic1proto.asm" and search for the label "ObjSplats". At the time of writing this, it's around line 17547. Select from here all the way down to the header for a subroutine, copy that block of code, and paste it over the contents of "_incObj/4F.asm".
    Now we need to change some subroutine labels to work with our target disassembly. "ObjectMoveAndFall" should become "ObjectFall", "ObjSplatsandYadrin_ChkWall" should become "Yad_ChkWall", "MarkObjectGone" should become "RememberState", and "ObjectHitFloor" should become "ObjFloorDist" (but you may need to change this from a bsr.w to a jsr with the label cast as a long, if you get compiler errors.)

    OPTIONAL: Updating the object pointer
    If you kept the original label for the object (when it was "Obj4F") you don't need to do any of this, but if you did change the label, or you are adding this as a new object, then this is what you need to do.
    In the file "_inc/Object Pointers.asm" you will find a list of pointers to objects, and a list of object IDs. If you are re-using the ID of 4F, scroll down to line 82 to find the label "ptr_Obj4F". Swap out the "Obj4F" parts of this line for the label you gave the object. Then down at line 226, do the same thing here. If you want to add this as a new object ID, add a new pointer at the end of the object pointer list (after the object for the Chaos Emeralds in the bad ending), and then add a new ID at the end of the file in the same manner. This would make the object ID be 8D. You should also make sure to include your new object ASM file in "sonic.asm", ideally around the same place you added the mappings.

    STEP 4: Adding the sprites to the Pattern Load Cues
    Open up "_inc/Pattern Load Cues.asm" to start editing the PLCs, or Pattern Load Cues. These dictate what graphic tiles are to be decompressed, and where they are decompressed to. As the object is right now, it will use the second palette line and look for its artwork at $9C80 in VRAM. However, finding spare VRAM can be tricky for most zones... we need 29 continuous tiles to fit Splats into. Thankfully, we have a gap large enough in Star Light Zone to fit him in! Go down to the cues for Star Light Zone, and at the end of the second list (underneath the cue for the spikeball) add a new cue to load Splats' artwork into $8900. It'll look like this:
    Code:
    		plcm	Nem_Splats, $8900	; Splats
    Now, in Splats' object code, go to his init function and look for "move.w #$24E4,2(a0)". Change the value to #$2448. (The upper nybble controls various aspects of the sprite, including the palette line to use. The rest is the VRAM address divided by $20.) It should be noted that the magic value "2" here is the same as constant "obGfx", if you wanted to make things more consistent and readable.

    STEP 5: Putting Splats into a level with SonLVL
    The object has been implemented! Now we just have to put it into a level to see it in action. Go into "SonLVL INI Files/objSLZ.ini" and at the end of the file, add a new entry for Splats. It'll look something like this:
    Code:
    [4F]
    name=Splats
    art=../artnem/Enemy Splats.bin
    mapasm=../_maps/Splats.asm
    frame=0
    pal=1
    rememberstate=true
    Save this, then open up SonLVL and edit a stage in Star Light Zone. Splats should show up in the object list now, so place one down somewhere! Save the level, build your ROM (watch out for assembly errors, since we added in more code we may have to make subroutine branch instructions become long subroutine jumps instead!) and test it out!

    YOU'RE DONE!
    [​IMG]
    Splats will behave just like he does in the prototype; he bounces forwards until he hits a wall, then turns around. If you want to adjust where to put Splats in VRAM, adjust the changes made in Step 4 as needed.
     
    Stdh, ProjectFM, Scrap Sorra and 2 others like this.