[Tutorial] How to create a Simple Scrolling HUD in Sonic 1

Mildanner

Newcomer
Original Guide by Mildanner (ft. RetroKoH)

In game development, the developers didn't know how to make a simple scrolling HUD and decided to make the HUD pop in the screen without any doubts. In this guide, you will learn how to make a simple scrolling HUD.

Hivebrain 2005 (ASM68K)​

In the Hivebrain 2005, the object for HUD was still in sonic1.asm file. You should find the Obj21_Main label and replace this entire routine with this:
Code:
Obj21_Main:                ; XREF: Obj21_Main
        addq.b    #4,$24(a0)    ; Advance to Routine 4 (Obj21_Move) on the next frame
        move.w    #0,8(a0)    ; Start offscreen (X = 0)
        move.w    #$108,$a(a0)    ; Set Y coordinate (obScreenY)
        move.l    #Map_obj21,4(a0); Set mappings pointer (obMap)
        move.w    #$6ca,2(a0)    ; Set VRAM art tile (obGfx)
        move.b    #0,1(a0)    ; Set render settings (obRender)
        move.b    #0,$18(a0)    ; Set display priority (obPriority)
        rts

; ===========================================================================

Obj21_Move:                ; Routine 4
        move.w    8(a0),d0    ; Load current X position
        cmpi.w    #$90,d0        ; Has it reached position $90?
        bge.s    @reached    ; If greater or equal, finalize movement

        addq.w    #5,d0        ; Move 5 pixels to the right
        move.w    d0,8(a0)    ; Update X coordinate directly
        jmp    DisplaySprite

@reached:
        move.b    #2,$24(a0)    ; Set routine status to Routine 2
        jmp    DisplaySprite
If the code doesn't work, you should go above Obj21_Index and after the line. Insert this (After the Obj21_Move label)
Code:
        dc.w Obj21_Move-Obj21_Index
Done! Now your hack has a fellow HUD scrolling.

(OPTIONAL) Adding sound effect if HUD is in the position

Hivebrain 2005 has no macros, so you should modify it simply and paste this in the label you pasted below @reached
Code:
        move.b    #$C5,d0    ;    set sound to cash
        jsr    (PlaySound_Special).l ;    play it
Okay, now it will play a sound once the HUD scrolling is completed.

Hivebrain 2022​

Also, Hivebrain 2022 is a upgraded version of Hivebrain 2005 but better version and more documented by following the current version of Sonic 1 disassembly from Sonic Retro.

In your disassembly, go to the Objects/HUD.asm and find the label HUD_Main:

Replace the entire routine with this
Code:
HUD_Main:    ; Routine 0
        addq.b    #4,ost_routine(a0)        ; Advance to Routine 4 (HUD_Move)
        move.w    #screen_left-80,ost_x_pos(a0)    ; Start HUD far off-screen to the left
        move.w    #screen_top+136,ost_y_screen(a0) ; Set Y position coordinate
        move.l    #Map_HUD,ost_mappings(a0)    ; Set mappings pointer
        move.w    #tile_Nem_Hud,ost_tile(a0)    ; Set art tile pattern index
        move.b    #render_abs,ost_render(a0)    ; Use absolute rendering screen space
        move.b    #0,ost_priority(a0)        ; Set sprite layout priority
        rts

HUD_Move:    ; Routine 4
        move.w    ost_x_pos(a0),d0        ; Get current HUD X position
        cmpi.w    #screen_left+16,d0        ; Has it reached the classic target position ($10)?
        bge.s    .reached            ; If yes, branch to lock movement

        addq.w    #5,d0                ; Shift 5 pixels to the right
        move.w    d0,ost_x_pos(a0)        ; Update object X position
        jmp    (DisplaySprite).l

.reached:
        move.b    #2,ost_routine(a0)        ; Set to static state routine (Routine 2 / HUD_Flash)
        jmp    (DisplaySprite).l
If there's a issue and it is not working, you should go below the pointer of HUD_Flash and insert this below the line.
Code:
        ptr HUD_Move
Done! Now your fellow HUD scrolling is now functional, enjoy your new HUD scrolling.
(OPTIONAL) Adding sound effect if HUD is in the position
So, if you want a sound effect that simply plays when the HUD is moved at the correct position, just go to the ".reached" label and add this below the label:
Code:
        play.w    1, jsr, sfx_Register            ; play "ker-ching" sound
Done! Now your HUD has a sound every time it finishes scrolling, happy hacking! 😃

GitHub version​

For getting started, you want to go in the _incObj/21 HUD.asm and go at the routine HUD_Main and replace it entirely with this new routine:
Code:
HUD_Main:    ; Routine 0
        addq.b    #4,obRoutine(a0)  ; Advances to Routine 4 (HUD_Move) on the next frame
        move.w    #0,obX(a0)        ; Starts the HUD offscreen (X = 0)
        move.w    #$108,obScreenY(a0)
        move.l    #Map_HUD,obMap(a0)
        move.w    #ArtTile_HUD,obGfx(a0)
        move.b    #0,obRender(a0)
        move.b    #0,obPriority(a0)
        rts

HUD_Move:    ; Routine 4
        move.w    obX(a0),d0        ; Loads the current HUD X position
        cmpi.w    #$90,d0           ; Has it reached position $90?
        bge.s    .reached          ; If greater or equal, finalize the movement
 
        addq.w    #5,d0             ; Move 5 pixels to the right
        move.w    d0,obX(a0)        ; Update the object's X coordinate directly
        jmp       DisplaySprite

.reached:
        move.b    #2,obRoutine(a0)
        jmp       DisplaySprite
Optional: You can change the scrolling speed to what you want, just simply replace the 5 with the number you think it's better.

If the code mentioned in particular doesn't work, you did some mistake! Just go ahead in HUD_Index: label and insert this line below the HUD_Flash-HUD_Index
Code:
        dc.w HUD_Move-HUD_Index
Did you like it? Now your hack's HUD is scrolling like how it would be.
(OPTIONAL) Adding sound effect if HUD is in the position
So, if you want a sound effect that simply plays when the HUD is moved at the correct position, just go to the ".reached" label and add this below the label:
Code:
        move.b    #sfx_Cash,d0            ; set cash sound to be played
        jsr    QueueSound2            ; play it
I hope you enjoyed this tutorial, now your hack has a HUD scrolling once the game starts.
 
Last edited:
Back
Top