38 lines
1.1 KiB
C
38 lines
1.1 KiB
C
|
//
|
||
|
// Created by william on 7/28/24.
|
||
|
//
|
||
|
|
||
|
#include <string.h>
|
||
|
#include <stdio.h>
|
||
|
#include "dbg_palette.h"
|
||
|
#include "../include/ppu.h"
|
||
|
#include "colors.h"
|
||
|
|
||
|
DebugPaletteMemory palette_memory;
|
||
|
pixel color_list[0x40] = COLOR_LIST;
|
||
|
|
||
|
#define COPY_PALETTE(memory, dest) memcpy(&(dest), &(memory), sizeof(DebugPalette))
|
||
|
#define COPY_PALETTES(memory, base_addr, dest) \
|
||
|
COPY_PALETTE((memory)[(base_addr) + 0x1], (dest)[0]); \
|
||
|
COPY_PALETTE((memory)[(base_addr) + 0x5], (dest)[1]); \
|
||
|
COPY_PALETTE((memory)[(base_addr) + 0x9], (dest)[2]); \
|
||
|
COPY_PALETTE((memory)[(base_addr) + 0xd], (dest)[3]) \
|
||
|
|
||
|
|
||
|
void dbg_palette_init() {
|
||
|
byte *memory = ppu_get_state()->memory.palette;
|
||
|
|
||
|
palette_memory.universal_background_color = memory[0];
|
||
|
|
||
|
COPY_PALETTES(memory, 0, palette_memory.background_palettes);
|
||
|
COPY_PALETTES(memory, 0x10, palette_memory.sprite_palettes);
|
||
|
}
|
||
|
|
||
|
pixel dbg_get_background_color(byte palette, byte data) {
|
||
|
if (data == 0) {
|
||
|
return palette_memory.universal_background_color;
|
||
|
}
|
||
|
|
||
|
int color = palette_memory.background_palettes[palette][data - 1];
|
||
|
return color_list[color];
|
||
|
}
|