Mini-tutorials Thread

Discussion in 'Tutorials' started by DeltaWooloo, Feb 16, 2021.

  1. DeltaWooloo

    DeltaWooloo Up up up down down down left right left right Member

    Aug 7, 2019
    I've been playing around with code recently, and after testing what I've made and loving it, I decided to show all of you my code with a tutorial. But wait, isn't it minor code changes? There's no point to make a tutorial for one simple code. Which is why, after confirming with a staff, I decided to make this thread where you can share minor code changes that can make a difference technically or during gameplay. It can be from any game if it has a disassembly and you explain what changes it brings to the game. It's a neat way to save thread space and more into collaborating with your ideas. Let's see how this thread goes then:

    I'll start with a simple guide:

    Be invulnerable after losing your invincibility status

    In Sonic games, when the invincibility time is over and you hit a badnik by accident, it can make the game really annoying for you since you have to go back and get rings. If you want to have a few seconds of invulnerability after you lose your invincibility, here is what you can do:

    In the code where it removes your invincibility, insert this below:
            subq.b    #2,$24(a0)
            move.w    #$78,$30(a0)
    I will list you the labels from different Sonic 1 disassemblies:
    Sonic 1 Hivebrain: Obj01_RmvInvin
    Sonic 1 GitHub: @removeinvincible (under the file "Sonic Display.asm" in the _incObj folder)

    What it does is the first line will set the invulnerability frames and the second line will run 70 frames of invulnerability before you go back to normal. A pretty neat upgrade if you fancy not getting accidental hits.

    Now it's your turn! What small piece of code would you want to share that you believe isn't thread-worthy? Good luck!
    Last edited: Feb 17, 2021
  2. Nat The Porcupine

    Nat The Porcupine Point & Click Funny Man Staff

    Jun 23, 2017
    Went ahead and pinned the thread, as I can see this gaining some traction & being popular with newcomers.
  3. Selbi

    Selbi The Euphonic Mess Retired Staff

    Jul 20, 2008
    Northern Germany
    (This is technically a repost, but since the old thread has been moved to the archives, it felt fitting to have that one-liner in here as well.)

    Basically, when you roll really, really fast into a Caterkiller from Marble Zone and Scrap Brain Zone, you will still get damaged despite having destroyed it. In the original game this wasn't really much of a noticable issue, since the locations where you can even gain enough speed to roll this fast are scarce, if they exist at all. But nowadays, the spin dash is everywhere and it's very easy to bash head-on right into a Caterkiller at mach speed at any time.

    The issue is that the spiked body segments don't get deleted immediately when destroying the head, but rather 1 frame later. So if you happen to roll fast enough to travel the distance to the body in that single frame, you still get damaged.

    Fixing it literally takes a single line. Go to loc_16C7C and add this below the label:

           clr.b    $20(a1)
    Now, when the head gets destroyed, all touch response values (which are responsible for objects being solid, breakable, damaging, etc.) from the body spikes are getting set to 0, which essentially means harmless and without collision. This is more straight forward than deleting all the body segments immediately, though that would obviously work as well.
  4. Inferno

    Inferno Rom Hacker Member

    Oct 27, 2015
    Hidden Palace Zone, Westside Island
    If you have added the Spindash, heed this warning if you intend for any of your levels to be longer than 64 256x256 chunks, or 128 128x128 chunks.

    (I'll be using GitHub here, as it's where I had to face this issue).

    If you just added horizontal scroll delay, MoveScreenHoriz, at the top, should look like this:
            move.w    (Horiz_scroll_delay).w,d1
            beq.s    @cont1
            subi.w    #$100,d1
            move.w    d1,(Horiz_scroll_delay).w
            moveq    #0,d1
            move.b    (Horiz_scroll_delay).w,d1
            lsl.b    #2,d1
            addq.b    #4,d1
            move.w    (v_trackpos).w,d0
            sub.b    d1,d0
            lea    (v_tracksonic).w,a1
            move.w    (a1,d0.w),d0
            and.w    #$3FFF,d0
            bra.s    @cont2
    See that and? S3K increased it to 7FFF. Why? Because otherwise, the scroll delay completely breaks past 64 256x256 chunks, or 128 128x128 chunks. So, if your levels are going to be bigger than 64 256x256 chunks, or 128 128x128 chunks, then change that and.

    (Note that this would only be possible if you modified the level layout format.)
    Giovanni, Angel X, ProjectFM and 2 others like this.
  5. DeltaWooloo

    DeltaWooloo Up up up down down down left right left right Member

    Aug 7, 2019
    Changing the layout of the results card..

    This is more of a personal preference, but if you don't like the layout of the result cards in Sonic 1, seen here:

    And you want a customized version similar to this:


    Here is how you modify the end result layout then, shall we? If we jump over to Obj3A_Config, which is where you will see this:

    Obj3A_Config:    dc.w 4,    $124, $BC    ; x-start, x-main, y-main
            dc.b 2,    0        ; routine number, frame    number (changes)
            dc.w $FEE0, $120, $D0 ;  SONIC HAS
            dc.b 2,    1
            dc.w $40C, $14C, $D6 ; PASSED
            dc.b 2,    6
            dc.w $520, $120, $EC ; act number
            dc.b 2,    2
            dc.w $540, $120, $FC ; score
            dc.b 2,    3
            dc.w $560, $120, $10C ; time bonus
            dc.b 2,    4
            dc.w $20C, $14C, $CC
            dc.b 2,    5
    This is the layout code, and this is where the results layout lies in place. You may notice that the code shown looks different. This is because I labelled the code to make it easier for you to modify the positioning of the results screen. To any of you that are struggling with adjecting that layout, let me run down with what you need to know. If you are considering changing the X axis of the layout, increase the x-main and it will move to the right (decreasing is to the left), but doing so will cause stuttering when loading the results screen so the amount of times you increased the X axis will be the amount of times you need to increase (decrease if you're moving it to the left) the x-start code. For the Y axis, you can increase it to risen the layout (decrase to lower it) however you do not need to modify the starting position as the results screen flies horizontally, not vertically. You know the example I provided above? If you would like to use it, replace Obj3A_Config with this:

    Obj3A_Config:    ; routine number, frame    number (changes)
               ; x-start, x-main, y-main
            dc.w 4,    $124, $BC ; SONIC HAS
            dc.b 2,    0
            dc.w $FEE0, $120, $D0 ; PASSED
            dc.b 2,    1
            dc.w $40C, $14C, $D6 ; act number
            dc.b 2,    6
            dc.w $520,    $120,    $122 ; score
            dc.b 2,    2
            dc.w $540,    $120,    $F2 ; time bonus
            dc.b 2,    3
            dc.w $560,    $120,    $102 ; ring bonus
            dc.b 2,    4
            dc.w $20C, $14C, $CC ; The blue bit of the card
            dc.b 2,    5
    This version has been modified to make the layout similar to Sonic 2 by moving the "score" text below and moving the "time bonus" and "ring bonus" slightly up.

    And there you go! You should understand how the end results layout works. It is easy once you understand how the X and Y axis works in the screen and possibly help you for other bits of code. Enjoy having a custom results screen!
    Last edited: Feb 19, 2021
    Angel X and Speems like this.
  6. Speems

    Speems Active Member Member

    Mar 14, 2017
    Rochester Hills, MI
    S3K-Esque Act Clear Timing
    If for some reason you want the Act Clear music to play when the results tallies are fully positioned on screen, like with Sonic 3 and Knuckles, here's how this can be done. It can go alongside DeltaWooloo's switched around results layout thingy. This is meant for the 2005 Hivebrain disassembly, but I'm sure a similar concoction can be made in the GitHub disassembly.

    Head to loc_ECD0 in sonic1.asm and you'll notice a command for 8E to be played when the signpost stops spinning. Change the 8E to E0, which is the fade out command.
    Next, go to Obj3A_ChkPos and underneath the neg.w d1 line, insert this:
    That way when the act result screen tallies are all in place (has passed text, time/ring bonus tally, etc.), the act clear song will play. For the special stage results, the same applies. Delete the lines of code calling for #$8E to be played in loc_47D4. And when you get to Obj7E_ChkPos, you'd add those two lines that call for the song to play when all the tallies are displayed, right underneath the same neg.w d1 line.

    Not sure if this has been conducted before or properly well constructed, but if anyone's got feedback for how this can be better, lemme know. Thanks in advance!
    Angel X, KCEXE, RandomName and 2 others like this.
  7. TomTalker

    TomTalker Newcomer Trialist

    Feb 20, 2021
    Emerald Hill
    This is a nice short and easy thing actually but I guess it's more of a personal preference (as you mentioned in it as well).