Skip to content

Commit

Permalink
ingame change palettte rgb222 <> rgb333
Browse files Browse the repository at this point in the history
  • Loading branch information
xrip committed Oct 12, 2023
1 parent eac8466 commit edd34b6
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 89 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.3.2

ingame change palettte rgb222 <> rgb333

# v1.3.0

New videodriver added. Now you can select some video options in menu.
Expand Down
207 changes: 118 additions & 89 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ uint8_t SCREEN[NES_DISP_HEIGHT][NES_DISP_WIDTH];
uint16_t linebuffer[256];
extern uint8_t fnt8x16[];


enum PALETTES {
RGB333,
RBG222,
};
// SETTINGS
bool show_fps = false;
bool flash_line = true;
bool flash_frame = true;
PALETTES palette = RGB333;
uint8_t snd_vol = 8;
uint8_t player_1_input = 1;
uint8_t player_2_input = 0;
Expand All @@ -60,96 +66,118 @@ char fps_text[3] = {"0"};
int start_time;
int frames;

uint8_t PALETTE(uint8_t r, uint8_t g, uint8_t b) {
static uint8_t pal_index = 0;
pal_index++;
setVGA_color_palette(pal_index - 1, (r << 16) | (g << 8) | b);
return (pal_index - 1);
}
#define RGB888(r,g,b) ((r<<16) | (g << 8 ) | b )
const BYTE NesPalette[64] = {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f
};

const BYTE __not_in_flash_func(NesPalette)
const int __not_in_flash_func(NesPalette888)
[64] = {
PALETTE(0x7c, 0x7c, 0x7c),
PALETTE(0x00, 0x00, 0xfc),
PALETTE(0x00, 0x00, 0xbc),
PALETTE(0x44, 0x28, 0xbc),

PALETTE(0x94, 0x00, 0x84),
PALETTE(0xa8, 0x00, 0x20),
PALETTE(0xa8, 0x10, 0x00),
PALETTE(0x88, 0x14, 0x00),

PALETTE(0x50, 0x30, 0x00),
PALETTE(0x00, 0x78, 0x00),
PALETTE(0x00, 0x68, 0x00),
PALETTE(0x00, 0x58, 0x00),

PALETTE(0x00, 0x40, 0x58),
PALETTE(0x00, 0x00, 0x00),
PALETTE(0x00, 0x00, 0x00),
PALETTE(0x00, 0x00, 0x00),

PALETTE(0xbc, 0xbc, 0xbc),
PALETTE(0x00, 0x78, 0xf8),
PALETTE(0x00, 0x58, 0xf8),
PALETTE(0x68, 0x44, 0xfc),

PALETTE(0xd8, 0x00, 0xcc),
PALETTE(0xe4, 0x00, 0x58),
PALETTE(0xf8, 0x38, 0x00),
PALETTE(0xe4, 0x5c, 0x10),

PALETTE(0xac, 0x7c, 0x00),
PALETTE(0x00, 0xb8, 0x00),
PALETTE(0x00, 0xa8, 0x00),
PALETTE(0x00, 0xa8, 0x44),

PALETTE(0x00, 0x88, 0x88),
PALETTE(0x00, 0x00, 0x00),
PALETTE(0x00, 0x00, 0x00),
PALETTE(0x00, 0x00, 0x00),

PALETTE(0xf8, 0xf8, 0xf8),
PALETTE(0x3c, 0xbc, 0xfc),
PALETTE(0x68, 0x88, 0xfc),
PALETTE(0x98, 0x78, 0xf8),

PALETTE(0xf8, 0x78, 0xf8),
PALETTE(0xf8, 0x58, 0x98),
PALETTE(0xf8, 0x78, 0x58),
PALETTE(0xfc, 0xa0, 0x44),

PALETTE(0xf8, 0xb8, 0x00),
PALETTE(0xb8, 0xf8, 0x18),
PALETTE(0x58, 0xd8, 0x54),
PALETTE(0x58, 0xf8, 0x98),

PALETTE(0x00, 0xe8, 0xd8),
PALETTE(0x78, 0x78, 0x78),
PALETTE(0x00, 0x00, 0x00),
PALETTE(0x00, 0x00, 0x00),

PALETTE(0xfc, 0xfc, 0xfc),
PALETTE(0xa4, 0xe4, 0xfc),
PALETTE(0xb8, 0xb8, 0xf8),
PALETTE(0xd8, 0xb8, 0xf8),

PALETTE(0xf8, 0xb8, 0xf8),
PALETTE(0xf8, 0xa4, 0xc0),
PALETTE(0xf0, 0xd0, 0xb0),
PALETTE(0xfc, 0xe0, 0xa8),

PALETTE(0xf8, 0xd8, 0x78),
PALETTE(0xd8, 0xf8, 0x78),
PALETTE(0xb8, 0xf8, 0xb8),
PALETTE(0xb8, 0xf8, 0xd8),

PALETTE(0x00, 0xfc, 0xfc),
PALETTE(0xf8, 0xd8, 0xf8),
PALETTE(0x00, 0x00, 0x00),
PALETTE(0x00, 0x00, 0x00),
RGB888(0x7c, 0x7c, 0x7c),
RGB888(0x00, 0x00, 0xfc),
RGB888(0x00, 0x00, 0xbc),
RGB888(0x44, 0x28, 0xbc),

RGB888(0x94, 0x00, 0x84),
RGB888(0xa8, 0x00, 0x20),
RGB888(0xa8, 0x10, 0x00),
RGB888(0x88, 0x14, 0x00),

RGB888(0x50, 0x30, 0x00),
RGB888(0x00, 0x78, 0x00),
RGB888(0x00, 0x68, 0x00),
RGB888(0x00, 0x58, 0x00),

RGB888(0x00, 0x40, 0x58),
RGB888(0x00, 0x00, 0x00),
RGB888(0x00, 0x00, 0x00),
RGB888(0x00, 0x00, 0x00),

RGB888(0xbc, 0xbc, 0xbc),
RGB888(0x00, 0x78, 0xf8),
RGB888(0x00, 0x58, 0xf8),
RGB888(0x68, 0x44, 0xfc),

RGB888(0xd8, 0x00, 0xcc),
RGB888(0xe4, 0x00, 0x58),
RGB888(0xf8, 0x38, 0x00),
RGB888(0xe4, 0x5c, 0x10),

RGB888(0xac, 0x7c, 0x00),
RGB888(0x00, 0xb8, 0x00),
RGB888(0x00, 0xa8, 0x00),
RGB888(0x00, 0xa8, 0x44),

RGB888(0x00, 0x88, 0x88),
RGB888(0x00, 0x00, 0x00),
RGB888(0x00, 0x00, 0x00),
RGB888(0x00, 0x00, 0x00),

RGB888(0xf8, 0xf8, 0xf8),
RGB888(0x3c, 0xbc, 0xfc),
RGB888(0x68, 0x88, 0xfc),
RGB888(0x98, 0x78, 0xf8),

RGB888(0xf8, 0x78, 0xf8),
RGB888(0xf8, 0x58, 0x98),
RGB888(0xf8, 0x78, 0x58),
RGB888(0xfc, 0xa0, 0x44),

RGB888(0xf8, 0xb8, 0x00),
RGB888(0xb8, 0xf8, 0x18),
RGB888(0x58, 0xd8, 0x54),
RGB888(0x58, 0xf8, 0x98),

RGB888(0x00, 0xe8, 0xd8),
RGB888(0x78, 0x78, 0x78),
RGB888(0x00, 0x00, 0x00),
RGB888(0x00, 0x00, 0x00),

RGB888(0xfc, 0xfc, 0xfc),
RGB888(0xa4, 0xe4, 0xfc),
RGB888(0xb8, 0xb8, 0xf8),
RGB888(0xd8, 0xb8, 0xf8),

RGB888(0xf8, 0xb8, 0xf8),
RGB888(0xf8, 0xa4, 0xc0),
RGB888(0xf0, 0xd0, 0xb0),
RGB888(0xfc, 0xe0, 0xa8),

RGB888(0xf8, 0xd8, 0x78),
RGB888(0xd8, 0xf8, 0x78),
RGB888(0xb8, 0xf8, 0xb8),
RGB888(0xb8, 0xf8, 0xd8),

RGB888(0x00, 0xfc, 0xfc),
RGB888(0xf8, 0xd8, 0xf8),
RGB888(0x00, 0x00, 0x00),
RGB888(0x00, 0x00, 0x00),
};

void updatePalette(PALETTES palette)
{
for(int i=0;i<64;i++)
{
if (palette == RGB333) {
setVGA_color_palette(i, NesPalette888[i]);
} else {
uint32_t c= NesPalette888[i];
uint8_t r=(c>>(16+6))&0x3;
uint8_t g=(c>>(8+6))&0x3;
uint8_t b=(c>>(0+6))&0x3;

r*=42*2;
g*=42*2;
b*=42*2;
setVGA_color_palette(i, RGB888(r,g,b) );
}
}
}


struct input_bits_t {
bool a: true;
bool b: true;
Expand Down Expand Up @@ -507,7 +535,7 @@ void __time_critical_func(render_core)() {
setVGA_text_buf(text_buf, &text_buf[80 * 30]);
setVGA_bg_color(0);
setVGAbuf_pos(32, 0);

updatePalette(palette);
setVGA_color_flash_mode(flash_line, flash_frame);

sem_acquire_blocking(&vga_start_semaphore);
Expand Down Expand Up @@ -754,7 +782,7 @@ typedef struct __attribute__((__packed__)) {
char value_list[5][10];
} MenuItem;

#define MENU_ITEMS_NUMBER 13
#define MENU_ITEMS_NUMBER 14
const MenuItem menu_items[MENU_ITEMS_NUMBER] = {
{"Player 1: %s", ARRAY, &player_1_input, 2, {"Keyboard ", "Gamepad 1", "Gamepad 2"}},
{"Player 2: %s", ARRAY, &player_2_input, 2, {"Keyboard ", "Gamepad 1", "Gamepad 2"}},
Expand All @@ -763,6 +791,7 @@ const MenuItem menu_items[MENU_ITEMS_NUMBER] = {
{""},
{"Flash line: %s", ARRAY, &flash_line, 1, {"NO ", "YES"}},
{"Flash frame: %s", ARRAY, &flash_frame, 1, {"NO ", "YES"}},
{"Palette: %s", ARRAY, &palette, 1, {"RGB333", "RGB222"}},
{""},
{"Save state", SAVE},
{"Load state", LOAD},
Expand Down Expand Up @@ -873,7 +902,7 @@ void menu() {

memset(SCREEN, 63, sizeof SCREEN);
setVGA_color_flash_mode(flash_line, flash_frame);

updatePalette(palette);
setVGAmode(VGA640x480div2);
}

Expand Down

0 comments on commit edd34b6

Please sign in to comment.