Sega Palette Encoding?

Discussion in 'Technical Discussion' started by Dandaman, Dec 13, 2015.

  1. Dandaman

    Dandaman

    Also known as Dandaman955 Tech Member
    86
    1
    8
    UK
    So a while back, I posted some notes for Streets of Rage. In that thread, I noted how the game uses an palette encryption/encoding which positions it in the palette buffer appropriately:

    Now, I thought this was specific to the game and I just ignored it. However, when I was looking at Flicky, I noticed that it was also used in the game (offset $1196), albeit with different data registers used and only used for the main palette. If this post is to be believed, then there may be another game that uses this format (although may just be Flicky), which leads me to believe that this might be an official format, similar to how Nemesis and Kosinski are?

    Here's the commented routine from Flicky:

    Code (ASM):
    1. DecodePalettes:                                  ; $1196
    2.                 movem.l d0-d2/a0,-(sp)           ; Store register values.
    3.                 lea     ($FFFFF7E0).w,a0         ; Load the start of the palette buffer into a0.
    4. loc_119E:
    5.                 move.w  (a5),d0                  ; Load first palette into d0.
    6.                 andi.w  #$10,d0                  ; Get the tenth; strip the rest of the bits except for the lower N bit.
    7.                 move.w  (a5),d1                  ; Reload the palette value.
    8.                 rol.w   #4,d1                    ; Get palette entry value.
    9.                 andi.w  #$F,d1                   ; Strip the rest of the bits.
    10.                 or.w    d1,d0                    ; Add onto the tenth.
    11.                 move.w  (a5),d1                  ; Reload the palette value.
    12.                 andi.w  #$100,d1                 ; Get the hundredth; strip the rest of the bits except for the higher N bit.
    13.                 lsr.w   #3,d1                    ; Divide to get into the byte range.
    14.                 or.w    d1,d0                    ; Add onto the rest of the bits.
    15.                 add.w   d0,d0                    ; Multiply by 2 to account for the word size.
    16.                 move.w  (a5)+,d2                 ; Reload the palette value.
    17.                 move.w  d2,d1                    ; Copy into d1.
    18.                 andi.w  #$0EEE,d1                ; Ensure that white is the highest value attainable.
    19.                 move.w  d1,(a0,d0.w)             ; Load to the appropriate position in the palette buffer.
    20.                 lsr.w   #1,d2                    ; Shift right to check for the presence of the T bit.
    21.                 bcc.s   loc_119e                 ; If it's not there, continue decoding palettes.
    22.                 movem.l (sp)+,d0-d2/a0           ; Restore register values.
    23.                 rts                              ; Return.