nesemu/gui/dbg_palette.c

37 lines
1.1 KiB
C

//
// Created by william on 7/28/24.
//
#include <string.h>
#include "dbg_palette.h"
#include "../include/ppu.h"
#include "../ppu/colors.h"
DebugPaletteMemory palette_memory;
pixel dbg_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_update() {
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 dbg_color_list[color];
}