Palette rotation: Difference between revisions

From NeoGeo Development Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Palette rotation is a video effect made by shifting and wrapping a range of color entries inside a [[palettes|palette]].
Palette rotation is a non-NeoGeo-specific video effect produced by rotating (shifting in a loop) a range of color entries inside a [[palettes|palette]].


This effect was frequently used in older games for cyclic, scrolling animations (waterfalls...) without having to use multiple tiles, saving up graphics memory and CPU time.
Like the [[auto animation]] feature, this effect was frequently used for cyclic animations (waterfalls, neon signs...) without having to use multiple tiles, saving up graphics memory and [[VRAM]] access time.


<gallery>
<gallery>
Line 9: Line 9:


==Example code==
==Example code==
The easiest way is to simply cycle through a table of pre-baked palettes. It can also be done procedurally, for example:


<syntaxhighlight>
<syntaxhighlight>
To do.
; Untested ! Doesn't care about transparent index.
; Executes in about 720 cycles
 
  lea    COLOR_LIST,a0  ; Pointer to list of 32 colors
  lea    PALETTE,a1      ; Pointer to destination palette in palette RAM
  lea    64(a0),a2      ; End of list (32 words)
  clr.l  d0
  move.b  ROT_INDEX,d0    ; Offset variable
  andi.b  #31,d0          ; Warp on 32
  add.w  d0,d0          ; Colors are words
  adda.l  d0,a0
  move.b  #16,d7          ; Number of entries in a palette
-:
  move.w  (a0)+,(a1)+    ; Copy
  subq.b  #1,d7
  beq    +              ; Are we done ?
  cmp.l  a0,a2
  bne    -              ; Warp ?
  lea    COLOR_LIST,a0  ; Warp !
  bra    -
+:
 
  addq.b  #1,ROT_INDEX    ; Animate
</syntaxhighlight>
</syntaxhighlight>


[[Category:Video system]]
[[Category:Video system]]
[[Category:Code]]
[[Category:Code]]

Latest revision as of 00:55, 8 March 2019

Palette rotation is a non-NeoGeo-specific video effect produced by rotating (shifting in a loop) a range of color entries inside a palette.

Like the auto animation feature, this effect was frequently used for cyclic animations (waterfalls, neon signs...) without having to use multiple tiles, saving up graphics memory and VRAM access time.

Example code

The easiest way is to simply cycle through a table of pre-baked palettes. It can also be done procedurally, for example:

; Untested ! Doesn't care about transparent index.
; Executes in about 720 cycles

  lea     COLOR_LIST,a0   ; Pointer to list of 32 colors
  lea     PALETTE,a1      ; Pointer to destination palette in palette RAM
  lea     64(a0),a2       ; End of list (32 words)
  clr.l   d0
  move.b  ROT_INDEX,d0    ; Offset variable
  andi.b  #31,d0          ; Warp on 32
  add.w   d0,d0           ; Colors are words
  adda.l  d0,a0
  move.b  #16,d7          ; Number of entries in a palette
-:
  move.w  (a0)+,(a1)+     ; Copy
  subq.b  #1,d7
  beq     +               ; Are we done ?
  cmp.l   a0,a2
  bne     -               ; Warp ?
  lea     COLOR_LIST,a0   ; Warp !
  bra     -
+:

  addq.b  #1,ROT_INDEX    ; Animate