Put Ristar/S3K tempo algorithm to Sonic 1

Discussion in 'Tutorials' started by AURORA☆FIELDS, Mar 27, 2017.

  1. AURORA☆FIELDS

    AURORA☆FIELDS so uh yes Exiled

    Joined:
    Oct 7, 2011
    Messages:
    759
    So, in this short tutorial, we will be placing the tempo algorithm used in S3K and Ristar into Sonic the Hedgehog 1. I will also instruct how to edit the tempos of each song so that they work properly. The tempo algorithm in Ristar differs from Sonic 1 as such, that rather than using a time out, instead it uses an accumulator to find when another delay needs to be added. The end result is, that you have way more wiggle-room with your tempo values, and are not limited to to the awkward way the default system does it.

    So, we begin with opening up sonic1.asm in hivebrain 2005, or s1.sounddriver.asm in Git disassembly. We want to remove the old routine for handling tempos. Go to sub_7260C or TempoWait, and delete it. Next, go to loc_71B82 or @driverinput, and replace these 3 lines;

    Code:
    Hivebrain:
            subq.b    #1,1(a6)
            bne.s    loc_71B9E
            jsr    sub_7260C(pc)
    
    Github:
            subq.b    #1,v_main_tempo_timeout(a6)    ; Has main tempo timer expired?
            bne.s    @skipdelay
            jsr    TempoWait(pc)
    with this:

    Code:
    Hivebrain:
            move.b    2(a6),d0        ; get tempo to d0
            add.b    d0,1(a6)        ; add to accumulator
            bcc.s    loc_71B9E        ; if carry clear, branch
    
    .ch =    $40+$E
        rept 10
            addq.b    #1,.ch(a6)        ; add 1 to duration
    .ch =        .ch+$30
        endr
    
    Github:
            move.b    v_main_tempo(a6),d0    ; get tempo to d0
            add.b    d0,v_main_tempo_timeout(a6); add to accumulator
            bcc.s    @skipdelay        ; if carry clear, branch
    
    .ch =    v_music_track_ram+zTrackDurationTimeout
        rept (v_music_track_ram_end-v_music_track_ram)/zTrackSz
            addq.b    #1,.ch(a6)        ; add 1 to duration
    .ch =        .ch+zTrackSz
        endr
    Go to loc_72068 or @nospeedshoes, and change the second line to:
    Code:
    Hivebrain:
            clr.b    1(a6)
    
    
    Github:
            clr.b    v_main_tempo_timeout(a6)
    You may now build if you are curious. Most music should play faster than usual, with the exception of 91, the credits jingle.

    Next step is to fix this. You can use this tool to convert tempos from Sonic 1 to the new method. You need to then convert the speed-up tempos, at byte_71A94 or SpeedUpIndex to have correct speed shoes tempo. Next, you need to convert tempos in the actual SMPS tracks. You can do this by hand or use my automated tool (bin only). Drag and drop each file into the executable to convert. If you are using ASM, simply find each reference to tempo (such as smpsHeaderTempo (second arg) and smpsSetTempoMod). With binary music, you can change byte 5 to the converted one, and find each EA byte inside a music track, and change the next byte to the converted one.

    Now, if you are using bin music, just find each music track include, and change the extension from "bin" to "smp", and you're set! Hopefully everything works as intended.

    Credits;
    Flamewing for the code to convert S1 tempo to S3K tempo.
    ValleyBell for Ristar sound driver disassembly.
    MarkeyJester for help with C and luv.
     
    Last edited: Mar 27, 2017
    EMK-20218, RouRouRou, KCEXE and 5 others like this.
  2. EMK-20218

    EMK-20218 The Fuss Maker Exiled

    Joined:
    Aug 8, 2008
    Messages:
    1,067
    Location:
    Jardim Capelinha, São Paulo
    It's one of the things I waited most during all these days working with SMPS and it's finally true. And even a tool for convert the tempos... seriously... thank you very much, Nats!
     
    AURORA☆FIELDS likes this.
  3. noobguy

    noobguy Newcomer Trialist

    Joined:
    Oct 31, 2021
    Messages:
    2
    I apologize for responding to a very old thread, but do you have any idea how to fix these build errors?

    E:\DEVELOPMENT\S1DISASM-MASTER\S1DISASM-MASTER\S1.SOUNDDRIVER.ASM(137) : Error : Expression must evaluate
    .ch = v_music_track_ram+zTrackDurationTimeout
    E:\DEVELOPMENT\S1DISASM-MASTER\S1DISASM-MASTER\S1.SOUNDDRIVER.ASM(138) : Error : Expression must evaluate
    rept (v_music_track_ram_end-v_music_track_ram)/zTrackSz
    E:\DEVELOPMENT\S1DISASM-MASTER\S1DISASM-MASTER\S1.SOUNDDRIVER.ASM(139) : Error : Illegal value (570014)
    addq.b #1,.ch(a6)
    E:\DEVELOPMENT\S1DISASM-MASTER\S1DISASM-MASTER\S1.SOUNDDRIVER.ASM(140) : Error : Expression must evaluate
    .ch = .ch+zTrackSz
    E:\DEVELOPMENT\S1DISASM-MASTER\S1DISASM-MASTER\S1.SOUNDDRIVER.ASM(141) : Error : No corresponding rept
    endr

    I'm using asm68k, github disassembly that I downloaded on October 30th of 2021.

    Thanks!
     
    DanielHall likes this.
  4. noobguy

    noobguy Newcomer Trialist

    Joined:
    Oct 31, 2021
    Messages:
    2
    Ok, so for anyone wondering, the GitHub disassembly constantly changes variable names/subroutines, so for the code modification in DriverInput, just use the HiveBrain example because in new versions of the GitHub fork zTrackDurationTimeout and zTrackSz were changed/named something else.