Skip to content

Commit 16e6fcc

Browse files
committed
Disable packed/double width palettes by default
1 parent df4c609 commit 16e6fcc

File tree

3 files changed

+53
-17
lines changed

3 files changed

+53
-17
lines changed

examples/debug/peanut-debug.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "SDL.h"
1616

17+
#define PEANUT_GB_USE_NIBBLE_FOR_PALETTE 1
1718
#define ENABLE_LCD 1
1819
#define ENABLE_SOUND 0
1920

examples/sdl2/peanut_sdl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# include "minigb_apu/minigb_apu.h"
1818
#endif
1919

20+
#define PEANUT_GB_USE_NIBBLE_FOR_PALETTE 1
21+
2022
#include "../../peanut_gb.h"
2123

2224
enum {

peanut_gb.h

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@
9494
# define PEANUT_GB_12_COLOUR 1
9595
#endif
9696

97+
/**
98+
* If PEANUT_GB_USE_DOUBLE_WIDTH_PALETTE is enabled, the pixel colour data will be
99+
* duplicated into both nibbles. This allows for faster scaling when rendering to
100+
* a 4 bit per pixel destination.
101+
*
102+
* PEANUT_GB_USE_NIBBLE_FOR_PALETTE must also be defined for this to work.
103+
*/
104+
#if PEANUT_GB_USE_DOUBLE_WIDTH_PALETTE
105+
# define PEANUT_GB_USE_DOUBLE_WIDTH_PALETTE 0
106+
#endif
107+
108+
/**
109+
* If PEANUT_GB_USE_NIBBLE_FOR_PALETTE is enabled, the pixel colour data will be
110+
* packed into the four least significant bits of a byte (or nibble). This
111+
* allows for a smaller look-up table (LUT) to be used directly, in comparison
112+
* to performing bit shifts or using a larger LUT.
113+
*/
114+
#ifndef PEANUT_GB_USE_NIBBLE_FOR_PALETTE
115+
# define PEANUT_GB_USE_NIBBLE_FOR_PALETTE PEANUT_GB_USE_DOUBLE_WIDTH_PALETTE
116+
#endif
117+
97118
/* Adds more code to improve LCD rendering accuracy. */
98119
#ifndef PEANUT_GB_HIGH_LCD_ACCURACY
99120
# define PEANUT_GB_HIGH_LCD_ACCURACY 1
@@ -464,20 +485,29 @@ struct count_s
464485
#define LCD_COLOUR 0x03
465486

466487
# if PEANUT_GB_12_COLOUR
467-
/**
468-
* Bit mask for whether a pixel is OBJ0, OBJ1, or BG. Each may have a different
469-
* palette when playing a DMG game on CGB.
470-
*/
471-
#define LCD_PALETTE_OBJ 0x04
472-
#define LCD_PALETTE_BG 0x08
473-
/**
474-
* Bit mask for the two bits listed above.
475-
* LCD_PALETTE_ALL == 0b00 --> OBJ0
476-
* LCD_PALETTE_ALL == 0b01 --> OBJ1
477-
* LCD_PALETTE_ALL == 0b10 --> BG
478-
* LCD_PALETTE_ALL == 0b11 --> NOT POSSIBLE
479-
*/
480-
#define LCD_PALETTE_ALL 0x0c
488+
# if PEANUT_GB_USE_NIBBLE_FOR_PALETTE
489+
/**
490+
* Bit mask for whether a pixel is OBJ0, OBJ1, or BG. Each may have a different
491+
* palette when playing a DMG game on CGB.
492+
*/
493+
#define LCD_PALETTE_OBJ 0x04
494+
#define LCD_PALETTE_BG 0x08
495+
/**
496+
* Bit mask for the two bits listed above.
497+
* LCD_PALETTE_ALL == 0b00 --> OBJ0
498+
* LCD_PALETTE_ALL == 0b01 --> OBJ1
499+
* LCD_PALETTE_ALL == 0b10 --> BG
500+
* LCD_PALETTE_ALL == 0b11 --> NOT POSSIBLE
501+
*/
502+
#define LCD_PALETTE_ALL 0x0c
503+
# else
504+
# if PEANUT_GB_USE_DOUBLE_WIDTH_PALETTE
505+
# error PEANUT_GB_USE_NIBBLE_FOR_PALETTE must be enabled for PEANUT_GB_USE_DOUBLE_WIDTH_PALETTE to work
506+
# endif
507+
#define LCD_PALETTE_OBJ 0x10
508+
#define LCD_PALETTE_BG 0x20
509+
#define LCD_PALETTE_ALL 0x30
510+
# endif
481511
# else
482512
#define LCD_PALETTE_OBJ 0
483513
#define LCD_PALETTE_BG 0
@@ -1140,11 +1170,12 @@ void __gb_write(struct gb_s *gb, uint_fast16_t addr, uint8_t val)
11401170
gb->display.bg_palette[1] = ((gb->hram_io[IO_BGP] >> 2) & 0x03) | LCD_PALETTE_BG;
11411171
gb->display.bg_palette[2] = ((gb->hram_io[IO_BGP] >> 4) & 0x03) | LCD_PALETTE_BG;
11421172
gb->display.bg_palette[3] = ((gb->hram_io[IO_BGP] >> 6) & 0x03) | LCD_PALETTE_BG;
1143-
1173+
#if PEANUT_GB_USE_DOUBLE_WIDTH_PALETTE
11441174
gb->display.bg_palette[0] |= gb->display.bg_palette[0] << 4;
11451175
gb->display.bg_palette[1] |= gb->display.bg_palette[1] << 4;
11461176
gb->display.bg_palette[2] |= gb->display.bg_palette[2] << 4;
11471177
gb->display.bg_palette[3] |= gb->display.bg_palette[3] << 4;
1178+
#endif
11481179
return;
11491180

11501181
case 0x48:
@@ -1153,11 +1184,12 @@ void __gb_write(struct gb_s *gb, uint_fast16_t addr, uint8_t val)
11531184
gb->display.sp_palette[1] = ((gb->hram_io[IO_OBP0] >> 2) & 0x03);
11541185
gb->display.sp_palette[2] = ((gb->hram_io[IO_OBP0] >> 4) & 0x03);
11551186
gb->display.sp_palette[3] = ((gb->hram_io[IO_OBP0] >> 6) & 0x03);
1156-
1187+
#if PEANUT_GB_USE_DOUBLE_WIDTH_PALETTE
11571188
gb->display.sp_palette[0] |= gb->display.sp_palette[0] << 4;
11581189
gb->display.sp_palette[1] |= gb->display.sp_palette[1] << 4;
11591190
gb->display.sp_palette[2] |= gb->display.sp_palette[2] << 4;
11601191
gb->display.sp_palette[3] |= gb->display.sp_palette[3] << 4;
1192+
#endif
11611193
return;
11621194

11631195
case 0x49:
@@ -1166,11 +1198,12 @@ void __gb_write(struct gb_s *gb, uint_fast16_t addr, uint8_t val)
11661198
gb->display.sp_palette[5] = ((gb->hram_io[IO_OBP1] >> 2) & 0x03) | LCD_PALETTE_OBJ;
11671199
gb->display.sp_palette[6] = ((gb->hram_io[IO_OBP1] >> 4) & 0x03) | LCD_PALETTE_OBJ;
11681200
gb->display.sp_palette[7] = ((gb->hram_io[IO_OBP1] >> 6) & 0x03) | LCD_PALETTE_OBJ;
1169-
1201+
#if PEANUT_GB_USE_DOUBLE_WIDTH_PALETTE
11701202
gb->display.sp_palette[4] |= gb->display.sp_palette[4] << 4;
11711203
gb->display.sp_palette[5] |= gb->display.sp_palette[5] << 4;
11721204
gb->display.sp_palette[6] |= gb->display.sp_palette[6] << 4;
11731205
gb->display.sp_palette[7] |= gb->display.sp_palette[7] << 4;
1206+
#endif
11741207
return;
11751208

11761209
/* Window Position Registers */

0 commit comments

Comments
 (0)