How to create dynamic palettes in Sonic 2

Discussion in 'Tutorials Archive' started by Mike B Berry, Jan 7, 2013.

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
    How to create dynamic palettes in Sonic 2:
    To make things simple, we have to take a similar step-by-step process like the Sonic 1 dynamic palette code.
    First of all, we need to backup your disassembly, and then you can duplicate your palette files. You don’t have to rename them right away, but it helps if you do.
    Next, we have to locate the routine that loads the palettes. In this case, it’s PalLoad1
    In the code, you should have something that looks like this:


    PalLoad1:
    <=
    lea (PalPointers).l,a1
    cmp.b #0,d1
    lsl.w #3,d0
    adda.w d0,a1
    movea.l (a1)+,a2
    movea.w (a1)+,a3
    adda.w #$80,a3
    move.w (a1)+,d7

    loc_2110:
    move.l (a2)+,(a3)+
    dbf d7,loc_2110
    rts
    ; End of function PalLoad1

    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||

    PalLoad2:
    <=
    lea (PalPointers).l,a1
    cmp.b #0,d1
    lsl.w #3,d0
    adda.w d0,a1
    movea.l (a1)+,a2
    movea.w (a1)+,a3
    move.w (a1)+,d7

    loc_2128:
    move.l (a2)+,(a3)+
    dbf d7,loc_2128
    rts
    ; End of function PalLoad2

    ; ---------------------------------------------------------------------------
    ; Underwater palette loading subroutine
    ; ---------------------------------------------------------------------------

    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||

    PalLoad3_Water:
    <=
    lea (PalPointers).l,a1
    cmp.b #0,d1
    lsl.w #3,d0
    adda.w d0,a1
    movea.l (a1)+,a2
    movea.w (a1)+,a3
    suba.l #$A80,a3
    move.w (a1)+,d7

    - move.l (a2)+,(a3)+
    dbf d7,-
    rts
    ; End of function PalLoad3_Water


    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||

    PalLoad4_Water:
    <=
    lea (PalPointers).l,a1
    cmp.b #0,d1
    lsl.w #3,d0
    adda.w d0,a1
    movea.l (a1)+,a2
    movea.w (a1)+,a3
    suba.l #$B00,a3
    move.w (a1)+,d7

    - move.l (a2)+,(a3)+
    dbf d7,-
    rts
    ; End of function PalLoad4_Water
    Alright, now we have to copy over some of the code from the Sonic 1 Guide… Which is practically everything excluding the extra pointers, since Sonic 2 works around a two act system only. Anyway, when you’re all done, the code should look like this:


    PalLoad1:
    move.b $FFFFFE11,d1
    lea (PalPointers).l,a1
    cmp.b #0,d1
    beq.w PalLoad1_Continue
    lea (PalPointers2).l,a1
    cmp.b #1,d1

    PalLoad1_Continue:
    lsl.w #3,d0
    adda.w d0,a1
    movea.l (a1)+,a2
    movea.w (a1)+,a3
    adda.w #$80,a3
    move.w (a1)+,d7

    loc_2110:
    move.l (a2)+,(a3)+
    dbf d7,loc_2110
    rts
    ; End of function PalLoad1

    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||

    PalLoad2:
    move.b $FFFFFE11,d1
    lea (PalPointers).l,a1
    cmp.b #0,d1
    beq.w PalLoad2_Continue
    lea (PalPointers2).l,a1
    cmp.b #1,d1

    PalLoad2_Continue:
    lsl.w #3,d0
    adda.w d0,a1
    movea.l (a1)+,a2
    movea.w (a1)+,a3
    move.w (a1)+,d7

    loc_2128:
    move.l (a2)+,(a3)+
    dbf d7,loc_2128
    rts
    ; End of function PalLoad2

    ; ---------------------------------------------------------------------------
    ; Underwater palette loading subroutine
    ; ---------------------------------------------------------------------------

    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||

    PalLoad3_Water:
    move.b $FFFFFE11,d1
    lea (PalPointers).l,a1
    cmp.b #0,d1
    beq.w PalLoad3_Water_Continue
    lea (PalPointers2).l,a1
    cmp.b #1,d1

    PalLoad3_Water_Continue:
    lsl.w #3,d0
    adda.w d0,a1
    movea.l (a1)+,a2
    movea.w (a1)+,a3
    suba.l #$A80,a3
    move.w (a1)+,d7

    - move.l (a2)+,(a3)+
    dbf d7,-
    rts
    ; End of function PalLoad3_Water


    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||

    PalLoad4_Water:
    move.b $FFFFFE11,d1
    lea (PalPointers).l,a1
    cmp.b #0,d1
    beq.w PalLoad4_Water_Continue
    lea (PalPointers2).l,a1
    cmp.b #1,d1

    PalLoad4_Water_Continue:
    lsl.w #3,d0
    adda.w d0,a1
    movea.l (a1)+,a2
    movea.w (a1)+,a3
    suba.l #$B00,a3
    move.w (a1)+,d7

    - move.l (a2)+,(a3)+
    dbf d7,-
    rts
    ; End of function PalLoad4_Water
    Alright, now we have two palette indexes loading but we only have one index programmed at the momemnt... Not to worry. Next, we have to locate the PalPointers routine, which is only 15 lines below PalLoad4. Just duplicate the code and place it directly before the binclude directory. Be sure to name the routine PalPointers2. If you have already numbered the copied palette files with a number after them (We’ll just say you renamed them with a 2 after the name,) be sure to change the name in the pointers routine, here is an example:


    PalPointers:
    palptr Pal_BGND, Normal_palette, $F
    palptr Pal_EHZ, Normal_palette_line2, $17
    palptr Pal_CPZ, Normal_palette_line2, $17
    palptr Pal_CPZ_U, Normal_palette, $1F

    PalPointers2:
    palptr Pal_BGND, Normal_palette, $F
    palptr Pal_EHZ, Normal_palette_line2, $17
    palptr Pal_CPZ, Normal_palette_line2, $17
    palptr Pal_CPZ_U, Normal_palette, $1F
    We now have two directories where the palettes can be loaded. Of course this isn't the full routine, but things should be clear at this point.

    After theses palette pointers in palpointers2 routine have been changed, this would be the point where you would want to build your rom, be sure to copy the original bincluded file(s) after doing so. If everything works without corrupted palettes, it is time to use the copied palette files. Whichever file you would like to use, change add a 2 right at the end of the file name. Like So:


    Pal_EHZ: BINCLUDE "art/palettes/EHZ.bin" ; Emerald Hill Zone palette
    Pal_EHZ2: BINCLUDE "art/palettes/EHZ2.bin"
    Now you can change the palptr names and do the same thing with the copied files. Add a 2 before the .bin tag.

    If you followed the steps correctly, build up your rom and test it out. In the end, you should be able to load separate palettes in each act.

    There is a possibility that palloads 3 and 4 will incorrectly build into the rom. This may cause the underwater palettes to fail completely, greeting the player with a black block where the palettes originally were. This is why I suggest you back up your files first.

    ----------------

    If you would like to save yourself some space in your assembly you can eliminate a loading routine without damaging the game in any way. First, Search for The  PalLoad4_Water routine and either comment or delete the code entirely.

    Then find Loc_42E4. Right under the routine tag, change the Palload4_Water branch to Palload3_Water.

    That's about it. If this works, which I'm confident it will, the water palettes should load just fine without issue.

    You can also do this with the original ASM file, so you can use it anyhow.
     
    Last edited by a moderator: Jan 12, 2013
  2. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    I'm a fuss-pot. Could you edit your post and put all your coding in an ASM tag? Example:



    PalLoad1:
    lea (PalPointers).l,a1


    lsl.w #3,d0


    adda.w d0,a1


    movea.l (a1)+,a2


    movea.w (a1)+,a3


    adda.w #$80,a3


    move.w (a1)+,d7


    - move.l (a2)+,(a3)+


    dbf d7,-


    rts


    ; End of function PalLoad1



    [asm]Your coding here[/asm]


    It's easier for people to follow then and for people to copy and paste if need to.
     
    Last edited by a moderator: Jan 7, 2013
  3. DanielHall

    DanielHall Well-Known Member Member

    Joined:
    Jan 18, 2010
    Messages:
    860
    Location:
    North Wales
    I thought you could edit his post as a staff member.
     
    Last edited by a moderator: Jan 7, 2013
  4. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    I thought you could edit his post as a staff member.

     
    I was about to finish work at the time so was in a rush. Plus it's his guide, so he can do it =P
     
    Last edited by a moderator: Jan 7, 2013
  5. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Regarding the guide, I strongly advise explaining what it is that your guide does in a more specific way, at this point, from the eyes of someone who had just popped in with little knowledge, they may very well not understand the whole point and principle of the code change, other than that, nice work.

    To be honest, it isn't easier at all, it's a complete fucking mess, using the tags causes syntax highlighting, which is fine, except it accounts for comments too, which it shouldn't, this often screws up the colour placement between words majorly, making the code more difficult to comprehend. Another annoyance is that you can no longer use "code" instead of "asm" if you want to avoid it, because somewhere along the line of updating the board, syntax highlight also got applied to the "code" stucture along with (sigh) the incorrect accounting of comments. Which is silly, as you could very well use the "code" tag for non-assembly (or even assembly that isn't in the nature of 68k), that's "why" we have a "code" and an "asm" tag as seperate items.

    Additionally, the choice of colours is questionable, there are both light and dark colours, against a possible light or dark background, for example, my background is white, and the size specifier and certain symbols such as the brackets, the plus, minus, etc, are also quite bright and clash with the background making it difficult to see, if I had a dark background the instructions which are quite a dark colour will clash. if it were up to me, I'd have away with the entire fucking thing, if it isn't going to be made to perform the task correctly then there's no point in having it.
     
    Last edited by a moderator: Jan 7, 2013
  6. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    I think it would be a lot easier if it wasn't coloured at all, except for comments, which could be green. Basically, exactly how notepad2 works.
     
  7. Spanner

    Spanner The Tool Member

    Joined:
    Aug 9, 2007
    Messages:
    2,570
    Dynamic pallets you say?

    [​IMG]
     
  8. SuperEgg

    SuperEgg I'm a guy that knows that you know that I know Member

    Joined:
    Oct 17, 2009
    Messages:
    Location:
    THE BEST GOD DAMN STATE OF TEXAS
    lol. I was thinking the same thing and wondered if anybody would catch it.
     
  9. OrdosAlpha

    OrdosAlpha RIGHT! Naebody move! Root Admin

    Joined:
    Aug 5, 2007
    Messages:
    1,793
    Location:
    Glasgow, Scotland

    What about widden dynamic pallets?
     
    Last edited by a moderator: Jan 10, 2013
  10. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    Might as well say I didn't think this through...
     
    Last edited by a moderator: Jan 12, 2013
  11. Spanner

    Spanner The Tool Member

    Joined:
    Aug 9, 2007
    Messages:
    2,570
    You can add that to the existing post.
     
  12. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    Well in that case, could you remove both this and my previous message?
     
  13. GamesArePlayed

    GamesArePlayed Newcomer Trialist

    Joined:
    Dec 23, 2012
    Messages:
    8
    Yeah... I didn't understand a single bit of that guide..
     
  14. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    This is more or less a copy paste guide...

    • Open you ASM file with Notepad or whatever program it is you use. Search for the routine you are about the change with the "FIND" tool, and replace all of the lines with the ones that need to be replaced.
    • Then copy PalPointers and past it right before Pal_SEGA and name the routine you just pasted as PalPointers2
    • If you have copied your palette files, (which you should have) add a 2 right after the Zone name you are adding the palette to. As an example I will re-post this part:
    Code:
    PalPointers:
            palptr Pal_EHZ, Normal_palette_line2, $17
    PalPointers2:
            palptr Pal_EHZ2, Normal_palette_line2, $17
    • Alright now you should have Pal_EHZ2 created, there should be a palette pointing to that pointer. Locate Pal_EHZ With the Find tool, or look maybe 20 lines below. and you should see it.
    • Just copy Pal_EHZ and paste it under it while changing it to Pal_EHZ2.
    • Now you have to change "art/palettes/EHZ.bin" to "art/palettes/EHZ2.bin" Which in all honesty, is one of the easiest parts of this guide.
     
Thread Status:
Not open for further replies.