Say hello to D-Pad Hero 2 repository
[dpadhero2.git] / common / palette.asm
blob4369ce8c162b3ae4048e75d8df351e8fb4e0e12d
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
21 ; Description:
22 ; Basic palette stuff.
23 ; A copy of the palette is kept in RAM so it can be faded and such
24 ; (see fade.asm).
25 ; The load_palette() function loads a palette into internal memory;
26 ; the write_palette() function writes the palette to VRAM.
28 .include "ptr.h"
30 .dataseg
32 ; background + sprite palette (16+16 bytes)
33 .public palette .byte[32]
35 .dataseg zeropage
37 datap .ptr
39 .codeseg
41 ; exported API
42 .public load_palette
43 .public write_palette
44 .public set_palette
45 .public set_black_palette
46 .public start_palette_ppu_string
48 .extrn ppu_buffer:byte
49 .extrn ppu_buffer_offset:byte
50 .extrn begin_ppu_string:proc
51 .extrn end_ppu_string:proc
53 ; Starts a PPU buffer string with address=$3F00 and count=32.
54 ; Params: A = index of first palette entry (0..31)
55 ; X = # of entries
56 ; Returns: X = PPU buffer index
57 .proc start_palette_ppu_string
58 ldy #$3F
59 jmp begin_ppu_string
60 .endp
62 ; Loads a 32-byte palette into RAM array.
63 ; The palette is not written to VRAM.
64 ; Once the palette is loaded, you can call write_palette()
65 ; or one of the palette loading functions (see fade.asm).
66 ; Params: A = low address of palette
67 ; Y = high address of palette
68 .proc load_palette
69 sta datap.lo
70 sty datap.hi
71 ldy #31
72 - lda [datap],y
73 sta palette,y
74 dey
75 bpl -
76 rts
77 .endp
79 ; Writes in-RAM palette to VRAM.
80 ; You should have set a palette first with load_palette()
81 ; before calling this function.
82 ; Params: None
83 .proc write_palette
84 lda #0
85 ldx #32
86 jsr start_palette_ppu_string
87 ldy #0
88 - lda palette,y
89 iny
90 sta ppu_buffer,x
91 inx
92 cpy #32
93 bne -
94 jmp end_ppu_string
95 .endp
97 ; Sets all RAM palette entries to $0F (black), and writes
98 ; the palette to VRAM.
99 .proc set_black_palette
100 ldx #31
101 lda #$0F ; color black
102 - sta palette,x
104 bpl -
105 bmi write_palette
106 .endp
108 ; Loads a palette and writes it to VRAM in one go.
109 ; Params: A = low address of palette
110 ; Y = high address of palette
111 .proc set_palette
112 jsr load_palette
113 jmp write_palette
114 .endp
116 .end