Environmental effects In Sonic 2

Discussion in 'Discussion and Q&A Archive' started by Mike B Berry, Jun 6, 2012.

Thread Status:
Not open for further replies.
  1. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    I've had many ideas on what types of environmental effects I would like to see in Sonic 2. Though I also have no idea on how to make them happen. The pallet swapping in mid level would be the exact environmental effect I am talking about. Sonic 1 Harder levels project was the very first hack I've played that featured such an effect and have wondered if there has ever been a post on that specific function. I know my last few posts have been questions on design choices, but I'm doing it as research. These specific effects and details applicable in a rom makes me want to learn how to do such badass things to not only my rom hacks, but help out with others in there roms.


    Once again, I thank you for applying the information if at all possible SSRG.
     
  2. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    For palette changing effects, what Sonic games tend to do is DMA transfer colour data from a RAM space called the "palette buffer", and it does this during V-blank so the transfer is every frame.


    The palette buffer RAM space in Sonic 2 is from FFFB00 to FFFB7F, every 2 bytes represents a colour; 0B GR. To change a specific colour in the palette, simply move the colour value (the two bytes) to the desired colour slot in the palette buffer, for example, the colour black used for Sonic/Tails/etc on the first line is held at FFFB02/FFFB03, if you wanted to change that to say green, then the following would allow that:


    move.w #$00E0,($FFFFFB02).w


    That is the basic principle of colour alteration, now for it to be triggered under certain conditions really depends on the condition, for example, if you wanted the colour swap to occur after passing a specific range in a level, then checking the co-ordinates of the screen is best suited, for example, if I wanted the black colour to turn green after the screen's X position passes 200 hex pixels, and wish for it to turn back to black if moving to 200 hex pixels or before, this would be suited:


    move.w #$0000,($FFFFFB02).w


    cmpi.w #$0200,($FFFFEE00).w


    ble.s UseBlackColour


    move.w #$00E0,($FFFFFB02).w


    UseBlackColour:


    It's quite a simple procedure.
     
  3. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    Let us say that I wanted, to do this to EHZ, what would the Ram address be if I wanted to do such an effect? I use Xenowhirl's dis-asm. I got Sonic to swap the palettes, yet I'm unsure if the EHZ palette is loaded as the Normal_Palette line or if it is loaded and used by its'self. Could you fill me in if you can?
     
  4. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    FFFB00 - FFFB7F is your palette buffer:

    • FFFB00 - FFFB1F = palette line 1
    • FFFB20 - FFFB3F = palette line 2
    • FFFB40 - FFFB5F = palette line 3
    • FFFB60 - FFFB7F = palette line 4


    As I already said, every two bytes is a single colour, and all colours are in order:

    • FFFB00 - FFFB01 = Colour 01
    • FFFB02 - FFFB03 = Colour 02
    • FFFB04 - FFFB05 = Colour 03
    • etc


    I strongly recommend that if you are unsure as to what you're doing, you should try sending two bytes to each RAM space, ckeck each one until the colours that you wanted changing are changed.


    I will say that the level's colours are usually held in palette line 3, and the BG's colour are usually held in palette line 4, but you have to understand that levels are not limited to this rule...
     
    Last edited by a moderator: Jun 7, 2012
  5. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    I thank you for this information. I understand how it works for Sonic and Tails, now I have to implement the code lines to make the EHZ pallet appear like the sun is beginning to set. I understand that this form is the kind that allows members to learn topics on their own, but I am such a dumb ass when it comes to the more advanced code lines. I know exactly how to dynamically load palettes in Sonic 1, but never implemented a pallet shifting effect. MarkeyJester, I thank you once again for your help with my posts.
     
    Last edited by a moderator: Jun 9, 2012
Thread Status:
Not open for further replies.