Monday, July 3, 2017

Do the boss flash

Boss palettes are generally loaded to palette line 1. Because of this, even a level with a kooky enemy palette such as Angel Island Zone gets sensible HUD colors for a while.


When the player deals damage to a boss, it rapidly flashes in bright colors. This is purely a palette effect, which means any other graphics using the flashing colors will also flash. In most cases, this only affects the HUD shadow.


Each boss object has its own palette flashing code, but they all follow the same general pattern. Here is the boss flash code for the Angel Island Zone 1 boss:
loc_68F88:
    moveq   #0,d0
    btst    #0,$20(a0)
    bne.s   loc_68F94
    addq.w  #8,d0

loc_68F94:
    lea     word_68FE6(pc),a1
    lea     word_68FEE(pc,d0.w),a2
    jsr     (CopyWordData_4).l
    subq.b  #1,$20(a0)
    ...
; ---------------------------------------------------------------------------
word_68FE6:
    dc.w  $FC2E, $FC34, $FC36, $FC3C
word_68FEE:
    dc.w   $644,  $240,   $20,  $644
    dc.w   $888,  $AAA,  $EEE,  $AAA
The CopyWordData functions are a family of helper functions which copy arbitrary word values from an array in a2 to RAM addresses from an array in a1. The number in the function's name denotes the number of words to copy.

Addresses $FC00 through $FC80 echo the state of color RAM in the VDP. Once per frame, the contents of this RAM block are DMA'd to CRAM. Therefore, writing to these addresses is equivalent to writing to CRAM.

Here's the breakdown:
  • Colors are read from word_68FEE and written to the addresses from word_68FE6. Recall that each palette line holds 16 colors, and each color is two bytes, so $FC20 maps to the start of palette line 1.
  • There are four addresses in word_68FE6, and the CopyWordData_4 function is being called, so four colors from word_68FEE are written to palette line 1.
  • word_68FEE is indexed by d0, which is set to 0 or 8 depending on the lowest bit of $20(a0). When d0 is set to 8, the code skips over the first 8 bytes of word_68FEE, and reads from the second set of colors.
  • After writing the colors to RAM, $20(a0) is decremented, so when the object is processed again next frame, it will read from the set of colors it ignored this frame.

Next time we'll see how one detail can throw the whole thing off, and why you probably never noticed anything wrong.

1 comment:

  1. Sheesh. With all the HUD palette conflicts, you'd think they would just make the shadows black and get done with it.

    Anyway, I love your blog. I rather enjoy reading about how my favorite games work. Could you please explain at some point how the water effect in the backgrounds of Hidrocity 1 and Launch Base 2 is accomplished? You know, that pseudo-3d effect reminiscent of mode 7.

    ReplyDelete