-
Notifications
You must be signed in to change notification settings - Fork 20
Palettes
Palette (or CGRAM) data is stored in ROM at $3FA000-$3FFFFF. The CGRAM mirror table is in SRAM at $702000-$7021FF.
The routine at $00BA7A handles copying from ROM to CGRAM mirror table. The scene palette tables starting at $00B78A (one per scene) contain information about which parts of ROM, sizes, and destinations in CGRAM. Each entry in these tables is 2 words:
RRRRRRRR RRRRRRRR dddddddd LLLLssss
R = ROM (source) offset from $3FA000: if R is negative, lop off sign bit and use as index into $7E0010 (dynamic loading)
d = starting destination offset into CGRAM mirror table (word address, so * 2)
L = # of loops separated by $20 destination, source just keeps counting upward
s = size, # of words to copy per loop
These 2 words represent a single chunk of palette data in ROM.
Loading is separated into loops (L is the number of these loops). Each loop copies a single piece of ROM to CGRAM; s is the size of this piece (up to 15 as it's only 4 bits). d will start out the destination, and each loop will add $20 to the destination. The source (ROM) starts off at R, and simply counts upward each loop, making it all contiguous. It's worth noting that this chunk is contiguous in ROM but not necessarily in CGRAM; destination, as already pointed out, adds $20 each loop regardless of s.
As a scenario, let's say we have $34 $20 $35 $46
. This would give us the following variables: R = $2034, d = $35, L = $4, s = $6. Our destination starts at $35, which is really $6A (word addressing) and source starts at $2034, we begin looping. First loop, we copy 6 words from $3FC034 (that's $3FA000+$2034) into $70206A-$702075. Our source becomes $2041, and it stays here for the next loop. However, on the next loop, destination increments to $8A. Next loop: 6 words from $3FC041 -> $70208A-$702095. Source becomes $204D. Next loop, 6 words from $3FC04D -> $7020AA-$7020B5. Final loop, 6 words from $3FC059 -> $7020CA-$7020D5.
Dynamic palette loading is done via R; if R is negative, we lop off the sign bit and index into $7E0010. These give us "slots" to load with whatever values we wish. As an example, $8002 indicates slot $12, because we take off sign bit to get $0002, then add $10 as the index -> $7E0012. Whatever is at this RAM location shall be used as the ROM offset into $3FA000.
R (ROM offset/RAM slot) | CGRAM destination (word) | # of pieces | Size of pieces (words) |
---|---|---|---|
$027C | $11 | $3 | $B |
$01C8 | $81 | $5 | $F |
Slot $10 | $00 | $1 | $1 |
Slot $16 | $01 | $1 | $F |
Slot $12 | $41 | $2 | $F |
Slot $1A | $1C | $3 | $4 |
Slot $14 | $61 | $2 | $F |
Slot $18 | $E1 | $2 | $F |
Slot $1C | $D1 | $1 | $F |
R (ROM offset/RAM slot) | CGRAM destination (word) | # of pieces | Size of pieces (words) |
---|---|---|---|
$2860 | $31 | $4 | $F |
$28D8 | $21 | $1 | $F |
$2860 | $B1 | $4 | $F |
Slot $10 | $00 | $1 | $1 |
Slot $12 | $01 | $2 | $F |
Slot $14 | $F1 | $1 | $F |
R (ROM offset/RAM slot) | CGRAM destination (word) | # of pieces | Size of pieces (words) |
---|---|---|---|
0130 | $00 | $1 | $1 |
01C8 | $81 | $1 | $F |
R (ROM offset/RAM slot) | CGRAM destination (word) | # of pieces | Size of pieces (words) |
---|---|---|---|
$28F6 | $E1 | $2 | $F |
R (ROM offset/RAM slot) | CGRAM destination (word) | # of pieces | Size of pieces (words) |
---|---|---|---|
$2DDC | $00 | $1 | $1 |
$30AC | $21 | $1 | $F |
$2E18 | $41 | $3 | $F |
$2ECC | $91 | $7 | $F |
$2DDC | $01 | $2 | $F |
$328C | $31 | $1 | $F |
$346C | $81 | $1 | $F |
R (ROM offset/RAM slot) | CGRAM destination (word) | # of pieces | Size of pieces (words) |
---|---|---|---|
Slot $10 | $00 | $1 | $1 |
Slot $14 | $11 | $1 | $F |
Slot $18 | $71 | $1 | $F |
$2860 | $81 | $4 | $F |
$3DC6 | $E1 | $2 | $F |
Slot $12 | $01 | $1 | $F |
Slot $16 | $21 | $1 | $F |
$2860 | $31 | $4 | $F |
$3F4C | $C1 | $2 | $F |
R (ROM offset/RAM slot) | CGRAM destination (word) | # of pieces | Size of pieces (words) |
---|---|---|---|
$401A | $00 | $1 | $1 |
Slot $10 | $01 | $3 | $F |
Slot $12 | $71 | $1 | $F |
$01C8 | $E1 | $2 | $F |
Slot $14 | $31 | $4 | $F |
Slot $16 | $91 | $4 | $F |
$3FFC | $51 | $1 | $F |
$3FFC | $B1 | $1 | $F |
Slot $18 | $D1 | $1 | $F |
$01C8 | $81 | $6 | $F |
$0222 | $E1 | $1 | $F |
R (ROM offset/RAM slot) | CGRAM destination (word) | # of pieces | Size of pieces (words) |
---|---|---|---|
$2148 | $01 | $1 | $F |
$027C | $11 | $3 | $B |
$4354 | $41 | $4 | $F |
$01C8 | $81 | $6 | $F |
Slot $10 | $D1 | $1 | $F |
R (ROM offset/RAM slot) | CGRAM destination (word) | # of pieces | Size of pieces (words) |
---|---|---|---|
$586E | $01 | $8 | $F |
$01C8 | $81 | $5 | $F |
Slot $10 | $D1 | $1 | $F |
Slot $12 | $E1 | $2 | $F |