Sonic CD Quirks (Sega CD Version)

Discussion in 'Discussion & Q&A' started by ⸸ devon ⸸, Jul 11, 2022.

  1. ⸸ devon ⸸

    ⸸ devon ⸸ There's nothing left but faith Member

    Joined:
    Aug 26, 2013
    Messages:
    1,173
    Sonic CD changed the roll check routine a little. In Sonic 1, 2, and 3 (alone), you're not allowed to roll unless you're moving with a speed of at least $80 in either direction, and will only boost you at a speed of $200 to the right if you're in a roll tunnel and you stop. In Sonic (3) & Knuckles, the minimum speed is $100. There is no minimum speed in CD, and you must be moving at a speed < $200 to the right or be stopped to be boosted:

    [​IMG]

    However, this code has a side effect where if you roll at a slow enough speed to the right, you get that boost, but not when rolling left:

    [​IMG]

    Even then, not all roll tunnels use the Sonic 1 method of setting a special chunk to force Sonic to stay in a ball, nor do the roll tunnel objects that make Sonic go into a ball when touched set any special flags.
     
  2. ⸸ devon ⸸

    ⸸ devon ⸸ There's nothing left but faith Member

    Joined:
    Aug 26, 2013
    Messages:
    1,173
    In Palmtree Panic Act 2 Present, the bottom of the background has bad deformation at the bottom:
    [​IMG]

    This is due to a bug in the deformation routine. If there's an 8px section at the bottom that's only partially on screen (it will only process a maximum of 28 8px sections on screen, if the camera is not aligned at an 8px position vertically, then 29 will be visible due to the first row still being visible, while an additional pops up), then it's not processed and the water deformation code kicks in its place (which ALWAYS runs, regardless of whether the water is actually on screen or not).
    Code:
        move.w  d0,d3                           ; Get top 8px row
        lsr.w   #1,d3
        moveq   #(288/8)-1,d1                   ; Size of clouds/mountains in 8px rows (d1 used for dbf)
    
        ; BUG: Max number of 8px rows on screen should be 29
        moveq   #28,d5                          ; Max number of 8px rows on screen
        sub.w   d3,d1                           ; Get number of remaining 8px rows in clouds/mountains
        bcs.s   .ScrollWater                    ; If only the water is visible, branch
        cmpi.w  #28-1,d1                        ; Is the number of 8px rows too large to be all on screen?
        bcs.s   .ScrollCloudsMtns               ; If not, branch
        moveq   #28-1,d1                        ; If so, cap it
    
    .ScrollCloudsMtns:
        sub.w   d1,d5                           ; Get number of visible 8px rows for the water
        lea     (a2,d0.w),a2                    ; Scroll clouds/mountains
        bsr.w   ScrollRows
    
    .ScrollWater:
        ; WARNING: Runs even if the water if offscreen. Requires that the number of 8px rows left for the
        ; for the water section be at least 1, as there is no check for if it's less!
        ; This is also why they subtract the offset (by 1 for dbf) number of 8px rows for the
        ; clouds/mountains from the absolute number of visible 8px rows on screen, to ensure that at least
        ; 1 row is available for the water.
        move.w  cameraBg2X.w,d0                 ; Get water scroll accumulator
        move.w  cameraX.w,d2
        sub.w   d0,d2
        ext.l   d2
        asl.l   #8,d2
        divs.w  #$100,d2
        ext.l   d2
        asl.l   #8,d2
    
        moveq   #0,d3                           ; Get top water scanline offset
        move.w  d0,d3
    
        move.w  d5,d1                           ; Convert number of 8px rows to scroll to lines
        lsl.w   #3,d1
        subq.w  #1,d1                           ; Subtract 1 for dbf
    
    .ScrollWaterLoop:
        move.w  d3,d0                           ; Set scanline offset for water
        neg.w   d0
        move.l  d0,(a1)+
    
        swap    d3                              ; Add water scroll accumulator
        add.l   d2,d3
        swap    d3
    
        dbf     d1,.ScrollWaterLoop             ; Loop until water is scrolled
        rts

    Other deformation routines in other levels use 29 instead of 28. Act 1 uses a more complex routine, where there are multiple water sections, for the 3D loop effect.

    The 1996 PC version actually uses the same deformation routine as in the Sega CD version, just ported to C. HOWEVER, they did add a small bit of code that makes it so that the number of rows for the clouds and mountains is incremented to 29 if it's 28 (aka if the water is offscreen).
    Code:
        movsx   eax, word ptr [esp+28h+cloudMtnRows]            ; Get number of 8px rows for the clouds/mountains
        sub     ebx, ecx                                        ; Get number of visible scanlines in the first 8px row
        mov     [esp+28h+cloudMtnRows2], eax
        cmp     word ptr [esp+28h+cloudMtnRows], 28-1           ; Are there 28 8px rows to scroll for the clouds/mountains?
        jnz     short loc_10012E14                              ; If not, branch
        inc     [esp+28h+cloudMtnRows2]                         ; If so, scroll an additional row to keep the water deformation offscreen
    
    loc_10012E14:
     
  3. Neotendo

    Neotendo Newcomer Trialist

    Joined:
    Nov 16, 2022
    Messages:
    6
    hi there, thank you for disassemble sonicCD, i was able to make a new intro fmv with sonic mania music and immersive sounds. changed the title screen, sonic is waving his finger the whole time, slower.
    (idk if i am allowed to post a YT link here)

    i even want to add the sonic 2 spindash move but for that we need all levels as far as i know.
    i added the SonicCD++ Patch to my iso so i have the spindash in all levels and my modifications in titlescreen and intro fmv

    i keep following this thread, great work
     
    Last edited: Nov 25, 2022 at 8:58 PM
  4. Neotendo

    Neotendo Newcomer Trialist

    Joined:
    Nov 16, 2022
    Messages:
    6
    @⸸ devon ⸸

    Can you tell me please if we can make the intro fmv with more than 8 FPS? i tried it but the fmv played too slow, looks like the source code is caping it to 8 FPS but i can't find where in the code.

    And i need to know how to add .mmd into source code, i want to playback an fmv before the title screen but something goes wrong. i only able to playback the stock .stm files, it looks like the source code is not finding my .stm file if i add my own.

    thanks in advance
     
  5. ⸸ devon ⸸

    ⸸ devon ⸸ There's nothing left but faith Member

    Joined:
    Aug 26, 2013
    Messages:
    1,173
    You would need to redo the FMV playback engine and change the format to fit more data in a CD read packet. As it stands, the data is uncompressed, and the CD drive can only read so much at once (it uses 1M/1M mode so that it can display the frames stored in a bank of Word RAM while the CD drive reads into the other, and a bank is only $20000 bytes in size).

    To add an additional FMV playback program, you'll need to add both the Main CPU, Sub CPU, and data files to the list of files in the beginning system program, assign them IDs in _Include/System.i, and add a command (and ID) for loading it in the system program.
     
    Last edited: Nov 25, 2022 at 7:33 PM
  6. Neotendo

    Neotendo Newcomer Trialist

    Joined:
    Nov 16, 2022
    Messages:
    6
    A1: ahhh, ok, so the stm intro file can't be have more FPS cause cdrom speed is too slow. ok, fine.

    A2:
    i did copy Sub (Opening).asm to Sub (Intro).asm and Main (Opening).asm to Main (Intro.asm).
    added FID_INTROSTM, FID_OPENMAIN, FID_OPENSUB, SCMD_INTRO in System.i.
    File_IntroData, File_IntroMain, File_IntroSub in SPX.asm.

    but i do not get to work :(

    can you tell me more about that please
    " and add a command (and ID) for loading it in the system program."
    sorry, i never programmed for the segaCD, hahaha

    IPX.asm
    ...
    tst.b d0 ; Was it a succes?
    beq.s .GetSaveData ; If so, branch
    bset #0,saveDisabled ; If not, disable saving to Backup RAM

    .GetSaveData:
    bsr.w ReadSaveData ; Read save data

    <Here was my jump call to the stm player, opn.stm is playing but not my intro.stm>

    .GameLoop:
    move.w #SCMD_INITSS2,d0 ; Initialize special stage flags
    bsr.w SubCPUCmd

    ...
     
    Last edited: Nov 25, 2022 at 9:01 PM
  7. ⸸ devon ⸸

    ⸸ devon ⸸ There's nothing left but faith Member

    Joined:
    Aug 26, 2013
    Messages:
    1,173
    See "SPCmd_LoadOpening" for reference in SPX.asm. Make sure that your entry for your FMV loading routine is listed in ".SPCmds" at the appropriate offset for your ID.
     
  8. Neotendo

    Neotendo Newcomer Trialist

    Joined:
    Nov 16, 2022
    Messages:
    6
    thank you very much, i missed this code section , i will try to add my intro.
     
    Last edited: Nov 25, 2022 at 9:54 PM
  9. Neotendo

    Neotendo Newcomer Trialist

    Joined:
    Nov 16, 2022
    Messages:
    6
    i think i got it working. need some finetuning with animation and sound.
     
  10. ⸸ devon ⸸

    ⸸ devon ⸸ There's nothing left but faith Member

    Joined:
    Aug 26, 2013
    Messages:
    1,173
    There are some sprites that can be found in the 1996 PC version, but NOT the Sega CD version. These rolling sprites do exist in the v0.02 prototype, albeit unused. The shrinking sprites only exist via leftover mappings data in Tidal Tempest since 510; no tile data can be found.

    [​IMG]

    Also, made my own rips of Sonic's sprites in the final's regular stages.
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]

    v0.02 rip
    [​IMG]

    510 rips
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]

    v0.51 rips
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]

    712 rips
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]

    1996 PC version rip
    [​IMG]

    510, 0.51, 712, and the final sprite sets are almost the same as reach other, minus some missing sprites, and also flipped balancing and skidding animations. The Tidal Tempest set are very much based on v0.02's set, with the mappings for the 3D rolling sprites being left over.
     
    Last edited: Nov 27, 2022 at 4:32 AM
  11. ⸸ devon ⸸

    ⸸ devon ⸸ There's nothing left but faith Member

    Joined:
    Aug 26, 2013
    Messages:
    1,173
    So, the game features a downward speed cap of 16 when you are in the air, so that it would prevent you from clipping through floors or messing up vertical wrapping if you were to fall for an extended period of time.

    However, this only applies when Sonic is in a normal state, where he uses the standard movement+gravity routine to handle falling. However, like in the other Genesis games, in his hurt state, they use a different gravity value than the one hardcoded in the standard function, so they just use the standard non-gravity movement routine and handle apply gravity manually, and they did not put the speed cap there.

    In the 510 prototype, in the beginning section of Tidal Tempest Act 2, there used to be enemies, and it's possible to get knocked back by one and glitch the vertical wrapping and die:
    [​IMG]

    The enemies placed in that area were removed, presumably for that reason.

    In the final, if you time and position yourself right in Wacky Workbench, you can get knocked back and clip through the floor:
    [​IMG]
     
  12. Neotendo

    Neotendo Newcomer Trialist

    Joined:
    Nov 16, 2022
    Messages:
    6
    nice find