2 ; Copyright (C) 2004, 2005 Kent Hansen.
4 ; This file is part of Neotoxin.
6 ; Neotoxin is free software; you can redistribute it and/or modify
7 ; it under the terms of the GNU General Public License as published by
8 ; the Free Software Foundation; either version 2 of the License, or
9 ; (at your option) any later version.
11 ; Neotoxin is distributed in the hope that it will be useful,
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ; GNU General Public License for more details.
16 ; You should have received a copy of the GNU General Public License
17 ; along with this program; if not, write to the Free Software
18 ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 ; Routines for fading in/out the palette, from/to black/white.
24 ; 1. Load the palette: see load_palette in palette.asm.
25 ; 2. Set the range of palette entries to fade (set_fade_range),
26 ; set the delay (set_fade_delay).
27 ; 3. call one of the start_fade_* functions.
29 .
include "tablecall.h"
34 temp_palette .
byte[32]
44 .
public set_fade_range
45 .
public set_fade_delay
46 .
public start_fade_from_black
47 .
public start_fade_from_white
48 .
public start_fade_to_black
49 .
public start_fade_to_white
52 .
public palette_to_temp_palette
53 .
public palette_fade_in_progress
57 .extrn
ppu_buffer:byte
58 .extrn
start_palette_ppu_string:proc
59 .extrn
end_ppu_string:proc
60 .extrn
table_call:proc
61 .extrn
start_timer:proc
62 .extrn
set_timer_callback:proc
64 .
proc palette_fade_in_progress
69 ; Sets the range of palette entries affected by fade routines.
70 ; Params: A, Y = range
77 ; Sets the # of frames per step during fading.
78 ; Params: A = # of frames per step
85 jsr fade_to_black_step
86 jsr temp_palette_to_ppu_buffer
91 jsr fade_from_black_step
92 jsr temp_palette_to_ppu_buffer
96 ;-----------------------------------------------------------------------------
98 ; Does custom initialization for the selected fade type.
101 jsr palette_to_temp_palette
104 TC_SLOT fade_from_black_init
105 TC_SLOT fade_from_white_init
106 TC_SLOT fade_to_black_init
107 TC_SLOT fade_to_white_init
109 fade_from_black_init:
112 and #
$0F ; color intensity = 0
120 fade_from_white_init:
123 ora #
$30 ; color intensity = full
148 ;-----------------------------------------------------------------------------
150 ; Executes one step of fading for the selected fade type.
155 jsr temp_palette_to_ppu_buffer
162 TC_SLOT fade_from_black_step
163 TC_SLOT fade_from_white_step
164 TC_SLOT fade_to_black_step
165 TC_SLOT fade_to_white_step
167 fade_from_black_step:
170 cmp palette
,y
; has color reached full intensity?
171 bcs
+ ; if yes, don't modify it
172 adc #
$10 ; increase color intensity by 1
180 fade_from_white_step:
183 cmp palette
,y
; has color reached full intensity?
184 beq
++ ; if yes, don't modify it
190 sbc #
$10 ; decrease color intensity by 1
201 sbc #
$10 ; decrease color intensity by 1
202 bcs
+ ; if result is < 0...
203 lda #
$0F ; ... color = black
214 adc #
$10 ; increase color intensity by 1
216 bcc
+ ; if result is >= 64...
217 lda #
$30 ; ... color = white
224 ;-----------------------------------------------------------------------------
236 lda #
<fade_timer_callback
237 ldy #
>fade_timer_callback
238 jmp set_timer_callback
240 ;-----------------------------------------------------------------------------
242 start_fade_from_black:
246 start_fade_from_white:
260 jsr temp_palette_to_ppu_buffer
265 ;-----------------------------------------------------------------------------
267 ; Writes the intermediate palette to PPU buffer.
268 temp_palette_to_ppu_buffer:
275 jsr start_palette_ppu_string
286 ; Copies palette to temp palette.
287 palette_to_temp_palette: