Basic Questions and Answers Thread

Discussion in 'Discussion & Q&A' started by Malevolence, Jul 7, 2009.

  1. DemonFox

    DemonFox Newcomer Member

    Joined:
    Aug 15, 2014
    Messages:
    10
    Trying to port this into Sonic 128 AS disassembly
    [S1] Considerably speeding up level loading
    However, the guide references:

    1. move.l #$70000002,($C00004) ; set mode "VRAM Write to $B000"
    2. lea Nem_TitleCard,a0 ; load title card patterns
    3. move.l #((Nem_TitleCard_End-Nem_TitleCard)/32)-1,d0; the title card art lenght, in tiles
    4. jsr LoadUncArt ; load uncompressed art

    "move.l #$70000002,($C00004)" doesn't seem to work in AS

    The following is the error:
    > > >_incObj/0D Signpost.asm(136): error: addressing mode not allowed here
    > > > move.l #$70000002,($C00004) ; set mode "VRAM Write to $B000"

    Any help with an AS equivalent?

    EDIT: Thanks to DeltaWooloo issue resolved

    "locVRAM $B000 ; set mode "VRAM Write to $B000"
     
    Last edited: Mar 9, 2022
  2. DeltaWooloo

    DeltaWooloo I barely use this account Member

    Joined:
    Aug 7, 2019
    Messages:
    359
    My recommendation is to use macros the GitHub disassembly provides you. Replace this line:
    Code:
    move.l #$70000002,($C00004) ; set mode "VRAM Write to $B000"
    with this:
    Code:
            locVRAM    $B000        ; set mode "VRAM Write to $B000"
    I've tested it in the same disassembly your using, and it works fine. However, I believe another error may lead to that popping up like a branch error or something since AS assemblers recognize that, or it could just be that.
     
    DemonFox likes this.
  3. Nik Pi

    Nik Pi Active Member Member

    Joined:
    Feb 14, 2022
    Messages:
    39
    Location:
    Kazakhstan
    Hello, peoples. I want to insert the Sonic 2 SW beta music,in final version, and for this- i port Clone Driver in S2GH disassembly, but now- music plays without FM-channels and DAC samples. Only PSG. Has anyone ever had this? Can anyone help me? If somebody want- i will upload code. MP3 file at bottom- example for music at this moment

    EDIT:
    I can't find the error :(
    Code at bottom
     

    Attached Files:

    Last edited: Mar 5, 2022
  4. DemonFox

    DemonFox Newcomer Member

    Joined:
    Aug 15, 2014
    Messages:
    10
    I had been working on an Sonic 1 hack using ProjectSonic1TwoEight-AS but there seems to be a problem with the block in Marble Zone Act 3 as it just sinks straight into the Lava (see below).

    upload_2022-3-4_8-35-20.png

    I thought this might have been something I had messed up, but it is actually present in the initial source disassembly

    Any idea how to fix this would be amazing, as I really don't want to start over again.

    EDIT: Tried to see if there was another Two Eight AS disassembly, and this same issue also exists in the 'kraminator-Special-MKII'

    EDIT2: So I couldn't find a source Project Two Eight AS disassembly that didn't have a Marble Zone issue, sooooooo I created my own, if any body else needs this you can find it here (Plus I did a quick play through and couldn't find any major problems)
     

    Attached Files:

    Last edited: Mar 5, 2022
  5. Scrap Sorra

    Scrap Sorra Well-Known Member Member

    Joined:
    Sep 18, 2020
    Messages:
    102
    Location:
    Sonic the Hedgehog for the Sega Genesis
    I wanted to implement Sonic 3D blast styled shields (normal shield with electric resistance, red shield with fire resistance, and gold shield with homing attack), so I tried copying the code for the normal shield to make a red shield and give the normal shield electricity resistance but then about halfway through I realized I had no idea what I was doing. Could someone help me out with this?
     
  6. Nik Pi

    Nik Pi Active Member Member

    Joined:
    Feb 14, 2022
    Messages:
    39
    Location:
    Kazakhstan
  7. Bluestreak

    Bluestreak Lady in red, living in dread. Member

    Joined:
    Apr 1, 2016
    Messages:
    226
    Location:
    Eastwatch Island
    Having issues with the Sonic CD Restored and SCD Restored & Knuckles mods. I'm using the Steam version, with the Steam mod loader from Main Memory too. I have the mods in the proper order as needed, but when at the mod menu in-game, it shows white blocks blanked out for many things, and when I load the game, it crashes for player 4 not being found. If I play without the & Knuckles mod, it also fucks the music up, where if you play with Purist OST, the music is in all the wrong places, and if using Purist, the loop themes will overwrite part of the songs too.

    Note: I'm using the Steam compatibility parts on the mods too.
     
  8. DemonFox

    DemonFox Newcomer Member

    Joined:
    Aug 15, 2014
    Messages:
    10
    So trying to apply "Optimizing collapsing platforms (a lot)" to SmashObject: (Subroutine to smash a block (GHZ walls and MZ blocks)) and I'm sure it should work, but cant work out where I am making an error:
    Code:
    ; ---------------------------------------------------------------------------
    ; Subroutine to    smash a    block (GHZ walls and MZ    blocks)
    ; ---------------------------------------------------------------------------
    
    ; ||||||||||||||| S U B    R O U T    I N E |||||||||||||||||||||||||||||||||||||||
    
    
    SmashObject:
            moveq    #0,d0
            move.b    obFrame(a0),d0
            add.w    d0,d0
            movea.l    obMap(a0),a3
            adda.w    (a3,d0.w),a3
            addq.w    #1,a3
            bset    #5,obRender(a0)
            _move.b    0(a0),d4
            move.b    obRender(a0),d5
            movea.l    a0,a1
            ;bra.s    .loadfrag  ; We have to remove this otherwise a1's value won't be right,
    ; but since it's what creates the first object over the source object, we also have to create it now...
    ; First object's creation begins here:
            move.b    #4,obRoutine(a1)
            _move.b    d4,0(a1)
            move.l    a3,obMap(a1)
            move.b    d5,obRender(a1)
            move.w    obX(a0),obX(a1)
            move.w    obY(a0),obY(a1)
            move.w    obGfx(a0),obGfx(a1)
            move.w obPriority(a0),obPriority(a1)
            move.b    obActWid(a0),obActWid(a1)
            move.w    (a4)+,obVelX(a1)
            move.w    (a4)+,obVelY(a1)
    ; and ends here, it's a simple copy/paste from .loadfrag:
    ; Now since we created one object already, we have to decrease the counter
            subq.w #1,d1
    ; We don't have to check whether it's the last one or not, it can't be unless there's not enough free ram to create more (and that's checked later).
    ; Here we begin what's replacing FindFreeObj, in order to avoid resetting its d0 every time an object is created.
            lea (v_lvlobjspace).w,a1
            move.w #$5F,d0
    ; ===========================================================================
    
    .loop:
            ;bsr.w    FindFreeObj ; We remove this, it's the routine we want to avoid
            ; So here goes what was originally happening in FindFreeObj, excepted now d0 won't be reset every time an object has to be created.
            ; We'll just copy/paste the content of loc_DA94 and correct the branches.
            .loop2:
            tst.b (a1)
            beq.s .cont ; Let's correct the branches. Here we can also skip the bne that was originally after bsr.w SingleObjLoad because we already know there's a free object slot in memory.
            lea $40(a1),a1
            dbf d0,.loop2 ; Branch correction again.
            bne.s    .playsnd
            .cont:
            ; And that's it, copy/paste complete
            addq.w    #5,a3
    
    .loadfrag:
            move.b    #4,obRoutine(a1)
            _move.b    d4,0(a1)
            move.l    a3,obMap(a1)
            move.b    d5,obRender(a1)
            move.w    obX(a0),obX(a1)
            move.w    obY(a0),obY(a1)
            move.w    obGfx(a0),obGfx(a1)
            move.w obPriority(a0),obPriority(a1)
            move.b    obActWid(a0),obActWid(a1)
            move.w    (a4)+,obVelX(a1)
            move.w    (a4)+,obVelY(a1)
            ;cmpa.l    a0,a1
            ;bcc.s    .loc_D268
            move.l    a0,-(sp)
            movea.l    a1,a0
            bsr.w    SpeedToPos
            add.w    d2,obVelY(a0)
            movea.l    (sp)+,a0
            bsr.w    DisplaySprite1
    
    .loc_D268:
            dbf    d1,.loop
    
    .playsnd:
            sfx    sfx_WallSmash,1,0,0 ; play smashing sound
    
    ; End of function SmashObject

    Code:
    ; ---------------------------------------------------------------------------
    ; Subroutine to    smash a    block (GHZ walls and MZ    blocks)
    ; ---------------------------------------------------------------------------
    
    ; ||||||||||||||| S U B    R O U T    I N E |||||||||||||||||||||||||||||||||||||||
    
    
    SmashObject:
            moveq    #0,d0
            move.b    obFrame(a0),d0
            add.w    d0,d0
            movea.l    obMap(a0),a3
            adda.w    (a3,d0.w),a3
            addq.w    #1,a3
            bset    #5,obRender(a0)
            _move.b    0(a0),d4
            move.b    obRender(a0),d5
            movea.l    a0,a1
            bra.s    .loadfrag
    ; ===========================================================================
    
    .loop:
            bsr.w    FindFreeObj
            bne.s    .playsnd
            addq.w    #5,a3
    
    .loadfrag:
            move.b    #4,obRoutine(a1)
            _move.b    d4,0(a1)
            move.l    a3,obMap(a1)
            move.b    d5,obRender(a1)
            move.w    obX(a0),obX(a1)
            move.w    obY(a0),obY(a1)
            move.w    obGfx(a0),obGfx(a1)
            move.w obPriority(a0),obPriority(a1)
            move.b    obActWid(a0),obActWid(a1)
            move.w    (a4)+,obVelX(a1)
            move.w    (a4)+,obVelY(a1)
            cmpa.l    a0,a1
            bcc.s    .loc_D268
            move.l    a0,-(sp)
            movea.l    a1,a0
            bsr.w    SpeedToPos
            add.w    d2,obVelY(a0)
            movea.l    (sp)+,a0
            bsr.w    DisplaySprite1
    
    .loc_D268:
            dbf    d1,.loop
    
    .playsnd:
            bsr.w    DisplaySprite1
            sfx    sfx_WallSmash,1,0,0 ; play smashing sound
    
    ; End of function SmashObject

    I'm pretty sure I have added this correctly for:
    • Collapsing Ledges
    • Spiked Balls
    • Caterkiller
    • GHZ Bridge
    • Orbinaut
    • Spinning Platforms with chain (SBZ)
    But I cant seem to get it to work here, and if anyone also knows how to implement this optimization for "Object 15 - swinging platforms (GHZ, MZ, SLZ) - spiked ball on a chain (SBZ)" that would be awesome
     
    Last edited: Mar 9, 2022
  9. DeltaWooloo

    DeltaWooloo I barely use this account Member

    Joined:
    Aug 7, 2019
    Messages:
    359
    What I did was I copied the code from the part where SmashObject was modified to create the first object over to Smash_LoadFrag. Here is what the entire subroutine should look like:

    Code:
    SmashObject:                ; XREF: Obj3C_Smash
            moveq    #0,d0
            move.b    $1A(a0),d0
            add.w    d0,d0
            movea.l    obMap(a0),a3
            adda.w    (a3,d0.w),a3
            addq.w    #1,a3
            bset    #5,1(a0)
            move.b    0(a0),d4
            move.b    1(a0),d5
            movea.l    a0,a1
            ;bra.s    Smash_LoadFrag
            move.b    #4,obroutine(a1)
            move.b    d4,0(a1)
            move.l    a3,obMap(a1)
            move.b    d5,1(a1)
            move.w    8(a0),8(a1)
            move.w    obY(a0),obY(a1)
            move.w    2(a0),2(a1)
            move.w    obpriority(a0),obpriority(a1)
            move.b    obActWid(a0),obActWid(a1)
            move.w    (a4)+,$10(a1)
            move.w    (a4)+,$12(a1)
            subq.w #1,d1
            lea ($FFFFD800).w,a1
            move.w #$5F,d0    
    ; ===========================================================================
    
    Smash_Loop:
            tst.b (a1)
            beq.s .cont
            lea $40(a1),a1
            dbf d0,Smash_Loop
            bne.s Smash_PlaySnd
        .cont:
            addq.w #5,a3
    
    Smash_LoadFrag:                ; XREF: SmashObject
            move.b    #4,obroutine(a1)
            move.b    d4,0(a1)
            move.l    a3,obMap(a1)
            move.b    d5,1(a1)
            move.w    8(a0),8(a1)
            move.w    obY(a0),obY(a1)
            move.w    2(a0),2(a1)
            move.w    obpriority(a0),obpriority(a1)
            move.b    obActWid(a0),obActWid(a1)
            move.w    (a4)+,$10(a1)
            move.w    (a4)+,$12(a1)
    
    loc_D268:
            dbf    d1,Smash_Loop
    
    Smash_PlaySnd:
           sfx    sfx_WallSmash,1,0,0 ; play smashing sound
    ; End of function SmashObject
    My assumption is since you don't need to load SingleObjLoad, it doesn't need to keep loading SpeedToPos for the tiny bits of the walls, and since that's loaded in, it overwrites them and loads the bits twice (usually 8, but now it's 16) but since you cannot load them in-game, it spawns in with 2. Sorry if this doesn't make sense, as I find it easier to present my code than explain the changes. If my wording or something sounds wrong, I'd appreciate someone correcting it. Besides that, I can confirm the code above works.

    Hopefully, you should see a difference in performance from there. If you want to see the output out of curiosity, I'll provide a YouTube link demonstrating it:

    Now do bear in mind it also depends on the optimizations you have on your side. This is being tested with Sonic 3K's priority, object and ring managers along with heavily optimized SpeedToPos and ObjectMove subroutines. I hope everything goes swimmingly with you!
     
    Last edited: Mar 9, 2022
    Samey, Crimson Neo and DemonFox like this.
  10. DemonFox

    DemonFox Newcomer Member

    Joined:
    Aug 15, 2014
    Messages:
    10
    Hey Thanks DeltaWooloo for the help, that was really bugging me.

    I plan to add the S3K object manager and Ring Manager in too, but working my way up to it.........the last two times I tried it failed, objects respawning in correctly, Loops not working.

    Not sure if its because I am using Project Two Eight (with the loops), as I might be breaking them when trying to convert
     
    Last edited: Mar 9, 2022
    DeltaWooloo likes this.
  11. Inferno

    Inferno Rom Hacker Member

    Joined:
    Oct 27, 2015
    Messages:
    121
    Location:
    Sky Base Zone, South Island
    Considering I got it working with Project 128 for S1D, no, it's not because of Project 128. I did have similar issues, but that was because I missed some lines in the object manager itself.

    If you aren't using it already, ProjectFM's own port of the Object and Ring Managers to S1 works well as a reference.
     
    DemonFox and DeltaWooloo like this.
  12. DemonFox

    DemonFox Newcomer Member

    Joined:
    Aug 15, 2014
    Messages:
    10
    I was trying to use that as a reference point, comparing to a standard Hivebrain disassembly for the changes, and I know I'm screwing something up each try:

    1. first time everything seemed mostly fine but I had removed a lot of the calls to the out_of_range macros, but I messed up something with the Ring Manager as rings respawned, and the loop didn't work.
    2. second attempt, I thought I had figured out how to use the out_of_range macro, and created a second one that did the correct code at the bottom that was different for the S3K manager, but most objects were missing, and the loop didn't work (so totally screwed that up somehow), but the Ring Manager worked perfectly
    Then I found out the Marble Zone in the AS Project 128 disassembly I was using was broken anyway, and I managed to successfully convert the AS disassembly to Project 128 (well I hope, haven't seen any issues), so hopefully I'll get it working at some point.

    Don't Worry, I am not blaming Project 128, I know I am stuffing it up somewhere each time
     
  13. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,170
    Location:
    Limbo
    Has anyone ripped Sonic 3D blasts SFX? I can't find any in the usual places, and I'd be shocked if someone hasn't already done it, it doesn't look too hard. I can probably do it myself given time (I'm not quite in the headspace for it right now, and it's been quite a while since I ripped SMPS data from a rom), but I'd rather not reinvent the wheel if someone else is happy to share their rips.
     
  14. DeltaWooloo

    DeltaWooloo I barely use this account Member

    Joined:
    Aug 7, 2019
    Messages:
    359
    I got you covered. I have 3 3D Blast SFXes that you may want inside the attachment. (got flicky, lost a flicky and lost flickes). They are all converted to flamewing's smps2asm, but you should be able to insert them, include them in your ROM, rip it by hex, and add it to any other sound driver if you aren't using that.
     

    Attached Files:

    Last edited: Mar 19, 2022
    ProjectFM and Pacca like this.
  15. badnest

    badnest Newcomer Member

    Joined:
    Dec 3, 2019
    Messages:
    20
    Location:
    Brazil Bad Future
    Does anyone know how Sonic 1 "links" the angled animations to the regular ones? I found code in Sonic\ Animate.asm to get Sonic's angle, but I can't find where it tells the game to use X animation based on that angle.
     
  16. Inferno

    Inferno Rom Hacker Member

    Joined:
    Oct 27, 2015
    Messages:
    121
    Location:
    Sky Base Zone, South Island
    There isn't seperate angled animations: it manually adds to the frame you'd be on during the normal walking animation based off angle in Sonic/Animate.asm's code, overwriting the normal walk animation. In other words, it's hardcoded.

    Mind if I ask why you wish to go into that? Just curious.
     
    badnest likes this.
  17. badnest

    badnest Newcomer Member

    Joined:
    Dec 3, 2019
    Messages:
    20
    Location:
    Brazil Bad Future
    That's actually exactly how I thought it worked, because there actually are no angled animations, yes, the angled sprite mappings are never referenced anywhere. I'm just not sure about the bit of code that actually adds to the frame to "find" the angled frame. Some commented code would be pretty nice, if you (or someone else) could.

    I'm thinking it's this part, maybe?

    Code:
    move.b      d0,d1
    lsr.b       #1,d1
    add.b       d1,d0
    
    @running:
    add.b       d0,d0
    move.b      d0,d3

    Not what I'm actually doing, but suppose I wanted to add the peelout to the game. That's easy, yeah. Except for the part of making the game display your angled sprites when sonic runs up a slope in the peelout animation. Maybe I'm overthinking and there's an easier way of doing that, but so far no luck.

    EDIT: Come to think of it, ReadySonic did add the peelout. Looking at it, I think that since the peelout has the same number of frames as the running animation, Mercury simply put the sprite mappings in the same order and reused the running code. But if the peelout had a different number of frames, suppose 10 for instance, then a branch with new math to add to the peelout sprites would be needed, correct?
     
    Last edited: Mar 24, 2022
  18. badnest

    badnest Newcomer Member

    Joined:
    Dec 3, 2019
    Messages:
    20
    Location:
    Brazil Bad Future
    Well, figured out the answer to my own question:


    Code:
    Sonic_Animate:
    
    ...
            andi.b    #6,d0        ;angle must be 0, 2, 4 or 6
    ...
            ;the following 3 lines only run when sonic is walking
    
            move.b    d0,d1 ;d0,d1=02,04,06
            lsr.b     #1,d1 ;divide d1 by 2, d1=01,02,03
            add.b     d1,d0 ;d1+d0, d0=03,06,09
         
        @running:
            add.b     d0,d0 ;d0+d0=06,12,18  ;if running, d0+d0=04,08,12
            move.b    d0,d3 ;d3=06,12,18 ;if running, d3=04,08,12
    
            ;walking animation is 6 frames long, running is 4 frames
    ...  
            add.b     d3,obFrame(a0)    ; modify frame number
    
     
    Last edited: Mar 25, 2022
    Inferno likes this.
  19. badnest

    badnest Newcomer Member

    Joined:
    Dec 3, 2019
    Messages:
    20
    Location:
    Brazil Bad Future
    Come to think of it, we could just get rid of all that math and save some cycles:

    Code:
            andi.b    #6,d0        ;angle must be 0, 2, 4 or 6
            lsr.b     #1,d0
            move.b    d0,d3
            add.b     d3,obFrame(a0)    ; modify frame number

    Then arrange the frames like so:
    Code:
    walk11
    walk21
    walk31
    walk41
    walk12
    walk22
    
    ...
    Arrange them the same way for running and whatever else. Tested and working.
     
  20. DeltaWooloo

    DeltaWooloo I barely use this account Member

    Joined:
    Aug 7, 2019
    Messages:
    359
    Quick question: I've noticed a strange bug where the camera gets delayed when going too fast in Sonic 1.
    ASIA (14).001.png ASIA (14).002.png
    Now I'm aware it's possible to fix it by setting the lower y-boundary x-axis in the resize subroutines but I've had little to no luck in getting them fixed after inserting that code. Does anyone know what occurs? If I do sound a bit blunt and you want me to provide some code, please let me know.

    EDIT: Fixed. No need to help me with this.
     
    Last edited: Mar 31, 2022