Basic Questions and Answers Thread

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

  1. Greenknight9000

    Greenknight9000 Well-Known Member Member

    Joined:
    Apr 30, 2014
    Messages:
    53
    Sonic's palette doesn't seem to change - Is there something I'm doing wrong?
     
  2. Pacca

    Pacca Why succeed when you can profit off of failure? Member

    Joined:
    Jul 5, 2014
    Messages:
    1,149
    Location:
    Triton (Moon)
    It seems the guide isn't finished yet.
     
  3. Greenknight9000

    Greenknight9000 Well-Known Member Member

    Joined:
    Apr 30, 2014
    Messages:
    53
    Damn
    It's been like that for years
    So close yet so far
    One last thing, I suppose (for now)
    I want the transformation sprite to use the unused air-punch animation, what animation number do I use?
     
  4. Pacca

    Pacca Why succeed when you can profit off of failure? Member

    Joined:
    Jul 5, 2014
    Messages:
    1,149
    Location:
    Triton (Moon)
    It seems that $12 or $13 points to the two unused animations. If you ever want to check or edit the animations, you can open up Sonics' animation file (in the Hivebrain disassembly, it's in "_anim/Sonic.asm" by default).
     
  5. AsuharaMoon

    AsuharaMoon kakyoin did you lay this egg Member

    Joined:
    Aug 15, 2013
    Messages:
    65
    After a long while, I've finally properly managed to port Knuckles' stuff to Sonic 1, but there are still a pair of things that REALLY needs to be fix:

    [​IMG][​IMG]
    It seems that these problems also happens in other known old Sonic 1 hacks (such as Sonic 1 Remastered v2, Sonic Green Snake 4.0, Stealth's old KiS1, etc.), with the only exception of Sonic 1 Megamix. I've also tried to explore a bit these codes, but I haven't achieved anything yet.

    Does anyone experienced with it know the reasons of these situations?
     
  6. MainMemory

    MainMemory Well-Known Member Member

    Joined:
    Mar 29, 2011
    Messages:
    877
    Well, I've never encountered that when porting Knuckles to Sonic 2. I've never tried Sonic 1 so I can't really help you.
     
  7. D.A. Garden

    D.A. Garden & Knuckles Retired Staff

    Joined:
    Aug 6, 2009
    Messages:
    514
    Location:
    England
    AsuharaMoon, it looks like Knuckles' hitbox is a little off when he hits the floor/is sliding. The first gif shows that Knuckles is triggering the wall ejection code (zipping), and the second is Knuckles hitting the spike object in that bit of floor under the moveable green block. I don't much else about it though.
     
    MarkeyJester likes this.
  8. LuigiXHero

    LuigiXHero Well-Known Member Member

    Joined:
    Mar 22, 2014
    Messages:
    277
    Sonic 2 is actually rather similar to Sonic 1 in a lot of ways due to being built off of it. If you compare Sonic 2's source to Sonic 1 you'd be able to find where the super code is and just copy it over to Sonic 1. Sonic 2 does have different ram addresses though so I recommend looking at the constants and variables files in the github versions of the sonic 1 and 2 disasm so you can see what to change them to.

    I should mention that Sonic 1 and the Sonic 2 disasms don't have the same label names so you'll have to dig a bit to find where the same code is and where to put the Super code.
     
  9. Greenknight9000

    Greenknight9000 Well-Known Member Member

    Joined:
    Apr 30, 2014
    Messages:
    53
    The palette cycle is all that I need, though RAM addresses are going to be a pain - I'll give it a shot, got any idea where and how I should change them?
     
  10. Pacca

    Pacca Why succeed when you can profit off of failure? Member

    Joined:
    Jul 5, 2014
    Messages:
    1,149
    Location:
    Triton (Moon)
    Here's two completely unrelated questions!

    What the heck is this?
    Code:
        clr.w    anim_frame_duration-mapping_frame(a1)
    I was trying to implement RHSs' guide on freeing up universal SSTs, and I stumbled across this odd looking bit of code. As far as I can tell, this subtracts the two constants, then uses the result to get an offset to clear relative to a1. This pops up twice in Cluckers code, and I have no idea why this is setup the way it is, or how I should deal with it given the guide (which shortens anim_frame_duration to a byte, but leaves it's intial value of $1E unchanged). My best guess for what it does is that it just compiles as "clr.w 4(a1)", but then wouldn't "mappings(a1)" make more sense? Clearly, I'm missing something here.

    As for the second question, I'm trying to give Sonic a 10 frame walking cycle. Obviously, none of the games support this properly by default. I've located where it adjusts the mappings used for walking to fit the angle, but I'm not sure specifically how it works, although I have a general idea. Here's what I know:

    Code:
    ;Sonic 2
        lea    (SonAni_Run).l,a1    ; use running animation
        cmpi.w    #$600,d2        ; is Sonic at running speed?
        bhs.s    +            ; use running animation
        lea    (SonAni_Walk).l,a1    ; if yes, branch
        add.b    d0,d0
    +
        add.b    d0,d0
    
    ;Sonic 1
            lea    (SonAni_Run).l,a1 ; use    running    animation
            cmpi.w    #$600,d2    ; is Sonic at running speed?
            bcc.s    @running    ; if yes, branch
            lea    (SonAni_Walk).l,a1 ; use walking animation
            move.b    d0,d1
            lsr.b    #1,d1
            add.b    d1,d0
    @running:
            add.b    d0,d0
    
    The animation code for Sonic 1 (which uses 6 walking frames) and Sonic 2 (which uses 8) is nearly identical, except for this little bit. As far as I can tell, before d0 is modified the game could technically support a 2 frame walking/running animation with angles, and doubling d0 gets you 4 "rotatable" frames (which matches the running animation, which the code clearly shows). Sonic 2 simply doubles it again to get 8 frames, which makes sense. Sonic 1, on the other hand, does some weirdness with bit shifting and adding that goes over my head, which presumably creates a rotatable 3 frame value, which then doubles to 6 frames (matching Sonic 1s' walking frame count).

    How could I get this to work with 10 frames? Or should I just scrap this whole thing and hard code it? I'm thinking about just doing that, but I really want to work with the existing solution, too...
     
  11. LazloPsylus

    LazloPsylus A Certain Scientific Railgun The Railgun

    Joined:
    Nov 25, 2009
    Messages:
    Location:
    Academy City
    The first question is actually quite easy.
    Code:
    clr.w    anim_frame_duration-mapping_frame(a1)
    This is a clear operation of a word. The word to clear is an indirect address register access with offset, as you know. I'm assuming this bit:
    Code:
    anim_frame_duration-mapping_frame(a1)
    This is the point of confusion? Well, it's really simpler than it looks. a1 is set to an address, of course. (a1) means to access the data at the address in a1 (indirect address, treating what's in a1 as a pointer). Finally, "anim_frame_duration-mapping_frame" is a subtraction operation to get an offset value. So, you subtract mapping_frame from anim_frame_duration, and the result is then used to temporarily increase the address in a1 and modify the data there. You end up clearing a word of data at the location of a1's pointer + (anim_frame_duration-mapping_frame).

    Make sense? It's an oversimplification, to be clear, but I'm hoping it makes some sense for the time being.

    As for the second, tried doubling up on those first two add.b instructions? It's been a long time since I've done Sonic engine work, so I'm just spitballing with basic test methods to see what changes, so apologies if it's not too helpful. Hopefully someone else who has actually touched the engine far more recently than a couple of years ago can give more clear input for extending the frames.
     
  12. MainMemory

    MainMemory Well-Known Member Member

    Joined:
    Mar 29, 2011
    Messages:
    877
    If I had to guess, I'd say that a1 is pointing at mapping_frame(a0), thus that line of code is indicating that it's operating on the anim_frame_duration SST relative to the mapping_frame SST that a1 is pointing at currently.
     
    Pacca likes this.
  13. Pacca

    Pacca Why succeed when you can profit off of failure? Member

    Joined:
    Jul 5, 2014
    Messages:
    1,149
    Location:
    Triton (Moon)
    Ah, that makes sense now. Thing get confusing when address registers point to things I don't expect them to point too.

    That's actually a great idea! I'll test it later, when I'm awake and I have all the sprites imported.
     
  14. AURORA☆FIELDS

    AURORA☆FIELDS the cute one here Member

    Joined:
    Oct 7, 2011
    Messages:
    711
    Location:
    Nathan's arms <3
    Since Sonic 1 is using 6 frames as you say, it is a 4 + 2 calculation, hence the lsr. As you want a 8 + 2 calculation, you should double d0 before d1 is added into it.
     
  15. Pacca

    Pacca Why succeed when you can profit off of failure? Member

    Joined:
    Jul 5, 2014
    Messages:
    1,149
    Location:
    Triton (Moon)
    Lazlos' suggestion seems to have worked! Here's the code with comments, just in case someone else wants an arbitrary number of walking/running frames:

    Code:
        lea    (SonAni_Run).l,a1    ;load running animation
        cmpi.w    #$600,d2        ; is Sonic at running speed?
        bhs.s    +            ; use running animation
        lea    (SonAni_Walk).l,a1    ; load walking animation
        move.b    d0,d1    ;use three Sonic 1 lines to get a 3 frame cycle
        lsr.b    #1,d1    ;ditto
        add.b    d1,d0    ;ditto
        add.b    d1,d0    ;add again to get 4?
        add.b    d1,d0    ;add again to get 5?
    +
        add.b    d0,d0        ;double 5 frame value for 10 frame walk cycle (or double 2 to 4, for running animation)
    
     
  16. StephenUK

    StephenUK Working on a Quackshot disassembly Administrator

    Joined:
    Aug 5, 2007
    Messages:
    991
    Instead of that, could you not have the following:

    Code:
        lea    (SonAni_Walk).l,a1    ; load walking animation
        move.b    d0,d1    ;store d0 (2 frames)
        lsr.b    #1,d1         ;shift d1 (1 frame)
        add.d      d0,d0    ;double d0 (4 frames)
        add.b    d1,d0      ;add d1 (5 frames)
    +
        add.b    d0,d0        ;double 5 frame value for 10 frame walk cycle (or double 2 to 4, for running animation)
    
    Based on the original code, d0 contains a value for 2 frames, which is why they add half that value with the LSR to make it 3 frames, and double it to become 6 frames. With what I've just written it should work out half the original value (2 frames to 1) then double the original value once (to get 4 frames) and add the 1 frame from the LSR on (5 frames) and then finally double the result to get 10 frames. I don't imagine it's a huge saving in terms of cycles but it looks a little cleaner as well.
     
  17. LazloPsylus

    LazloPsylus A Certain Scientific Railgun The Railgun

    Joined:
    Nov 25, 2009
    Messages:
    Location:
    Academy City
    Oh yeah, definitely go with cleaner solutions. Mine was just a shot in the dark estimate to get *something* to happen to give some idea on what to adjust. As I said, I've not done Sonic engine work in *ages*, but I'm glad the guess got you somewhere.
     
    MarkeyJester likes this.
  18. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,808
    Ah don't feel bad Lazlo, we know you weren't aiming for full optimisation, any help is better than no help.

    Speaking of optimisation, if you really wanna save some time (and space), you can remove that last "add.b d0,d0" entirely, provided you change the "lsr.b #4,d0" and "andi.b #6,d0" that's before that code above to a "lsr.b #3,d0" and "andi.b #$0C,d0".

    Additionally, you could change the "add.b d3,$1A(a0)" changing the d3 to a d0 that's after that code, this'll allow you to remove the "move.b d0,d3" as well.

    I think quicker methods than this will involve look up tables and a rewrite, but these will evidently cost you space in favour of time. I guess it depends on how much speed you really want, and not only to keep in mind that this particular code will only run once per frame, you're not really looking to obtain much of a gain-back from it.
     
    Last edited: Jul 29, 2018
  19. Greenknight9000

    Greenknight9000 Well-Known Member Member

    Joined:
    Apr 30, 2014
    Messages:
    53
    Hey all!
    after messing around in SonMapEd, I finally learned how to use it!
    I eventually ended up giving Super Sonic his own custom sprites in Sonic - Open Source Project which gave me the idea - what if Sonic 2 gave Super Sonic a complete set of animations?
    I set to work, excited to finally make my mark on the hacking community....and found out the _anim folder is absent from Sonic 2
    I came here to ask: How to add custom animations to Super Sonic and where is the animation section in the asm file?
    (My goal is to at least give Super Sonic his floating-rotation, spring, look up, and breaking sprites, I want to make the more glaring issues to be sorted first).
    I plan to use Sonic Mania Plus' sprites - I really want to do this and I'm pretty eager to see how this will turn out!
     
  20. Pacca

    Pacca Why succeed when you can profit off of failure? Member

    Joined:
    Jul 5, 2014
    Messages:
    1,149
    Location:
    Triton (Moon)
    All the animations are left inside the main asm file. Just open it up and search for "sonicanidata:", that will get you to Sonics' animation pointers. Shortly after that is his super animation data as well.