PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
graphics/Palette/GetColors/GetColors.c
/*---------------------------------------------------------------------------------
Simple mode 1 example with some palette management
-- alekmaul
---------------------------------------------------------------------------------*/
#include <snes.h>
#include <stdarg.h>
#include <stdio.h>
extern char patterns, patterns_end;
extern char palette;
extern char map, map_end;
extern char snesfont;
u16 colpal; // unique color palette for test
u16 arraypals[3]; // array of colors for test
//---------------------------------------------------------------------------------
int main(void)
{
// Initialize SNES
// Initialize text console with our font
consoleInitText(0, 16 * 2, &snesfont, &palette);
// Read tiles to VRAM
bgInitTileSet(1, &patterns, &palette, 1, (&patterns_end - &patterns), 16 * 2, BG_16COLORS, 0x4000);
// Copy Map to VRAM
bgInitMapSet(1, &map, (&map_end - &map), SC_32x32, 0x1000);
// Now Put in 16 color mode and disable Bgs except current
setMode(BG_MODE1, 0);
// Get one color and print value (RGB=1E 1F 1F -> ((1E)|((1F)<<5)|((1F)<<10)) -> 7FFE
getPaletteColor(16 + 2, &colpal); // because palette #1 used
consoleDrawText(0, 24, "Color#2 Pal#1=%04x", (u16)colpal);
// Infinite loop
while (1)
{
}
return 0;
}
void bgSetDisable(u8 bgNumber)
Disable a BG in the actual SNES mode.
void bgInitMapSet(u8 bgNumber, u8 *mapSource, u16 mapSize, u8 sizeMode, u16 address)
Initializes a Map Set and loads it into SNES VRAM.
void bgInitTileSet(u8 bgNumber, u8 *tileSource, u8 *tilePalette, u8 paletteEntry, u16 tileSize, u16 paletteSize, u16 colorMode, u16 address)
Initializes a Tile Set and Loads the Tile GFX into VRAM.
void consoleSetTextVramAdr(u16 vramfont)
Change text graphics address (4K aligned)
void consoleInitText(u8 palnum, u8 palsize, u8 *tilfont, u8 *palfont)
Initialize the Text System.
void consoleInit(void)
Initialize console.
void consoleDrawText(u16 x, u16 y, char *fmt,...)
Output formatted string on a screen (tiles mode)
void consoleSetTextOffset(u16 offsetfont)
Change text Background map address for display (must be BG address)
void consoleSetTextVramBGAdr(u16 offsetfont)
Change text Background map address for display (must be BG address)
void WaitForVBlank(void)
Wait for vblank interrupt
the master include file for snes applications.
void setScreenOn(void)
Put screen On.
void getPaletteColor(u8 paletteEntry, u16 *paletteColor)
Get a color palette from CGRAM.
void setMode(u8 mode, u8 size)
Set the SNES hardware to operate in new display mode.