Skip to content

Commit 0418f46

Browse files
committed
[core] Store both BGR565 and RGB565 palettes to speed up paletted modes
1 parent 9ad800d commit 0418f46

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

core/lcd.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ void emu_lcd_drawmem(void *output, void *data, void *data_end, uint32_t lcd_cont
131131
if (!dat) { goto draw_black; }
132132

133133
if (mode < 4) {
134+
const uint16_t *palette = lcd.palettes[bgr & 1];
134135
uint_fast8_t bpp = 1u << mode;
135136
uint32_t mask = (1 << bpp) - 1;
136137
uint_fast8_t bi = bebo ^ (CEMU_BYTE_ORDER == CEMU_BIG_ENDIAN) ? 0 : 24;
@@ -140,12 +141,8 @@ void emu_lcd_drawmem(void *output, void *data, void *data_end, uint32_t lcd_cont
140141
uint_fast8_t bitpos = 32;
141142
word = *dat++;
142143
do {
143-
color = lcd.palette[word >> ((bitpos -= bpp) ^ bi) & mask];
144-
color |= (uint32_t)lcd.palette[word >> ((bitpos -= bpp) ^ bi) & mask] << 16;
145-
color = lcd_bgr565swap(color, bgr);
144+
color = palette[word >> ((bitpos -= bpp) ^ bi) & mask];
146145
*out++ = lcd_rgb565out(color);
147-
if (out == out_end) break;
148-
*out++ = lcd_rgb565out(color >> 16);
149146
} while (bitpos && out != out_end);
150147
} while (dat < dat_end);
151148

@@ -309,18 +306,16 @@ static uint32_t lcd_words(uint8_t words) {
309306
}
310307

311308
default: {
309+
const uint16_t *palette = lcd.palettes[bgr & 1];
312310
uint_fast8_t bpp = 1 << lcd.LCDBPP;
313311
uint_fast8_t mask = (1 << bpp) - 1;
314312
uint_fast8_t bi = (lcd.BEBO ^ (CEMU_BYTE_ORDER == CEMU_BIG_ENDIAN) ? 0 : 24) ^ (lcd.BEPO ? 0 : 8 - bpp);
315313
do {
316314
uint_fast8_t bitpos = 32;
317315
uint32_t word = *dat++;
318316
do {
319-
uint32_t pixel = lcd.palette[word >> ((bitpos -= bpp) ^ bi) & mask];
320-
pixel |= (uint32_t)lcd.palette[word >> ((bitpos -= bpp) ^ bi) & mask] << 16;
321-
pixel = lcd_bgr565swap(pixel, bgr);
317+
uint16_t pixel = palette[word >> ((bitpos -= bpp) ^ bi) & mask];
322318
ticks = lcd_process_pixel(ticks, pixel);
323-
ticks = lcd_process_pixel(ticks, pixel >> 16);
324319
} while (bitpos);
325320
} while (--words);
326321
break;
@@ -687,7 +682,9 @@ static void lcd_write(const uint16_t pio, const uint8_t value, bool poke) {
687682
/* Convert to RGB565 in native endianness */
688683
paletteIndex >>= 1;
689684
uint16_t color = lcd.paletteBytes[paletteIndex * 2] | (lcd.paletteBytes[paletteIndex * 2 + 1] << 8);
690-
lcd.palette[paletteIndex] = color + (color & 0xFFE0) + (color >> 10 & 0x0020);
685+
uint16_t bgr565 = color + (color & 0xFFE0) + (color >> 10 & 0x0020);
686+
lcd.palettes[0][paletteIndex] = bgr565;
687+
lcd.palettes[1][paletteIndex] = lcd_bgr565swap(bgr565, 0x1F);
691688
}
692689
} else if (index < 0xC00) {
693690
if (index >= 0x800) {

core/lcd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ typedef struct lcd_state {
7171
enum lcd_comp compare;
7272
uint32_t PPL, HSW, HFP, HBP, LPP, VSW, VFP, VBP, PCD, ACB, CPL, LED, LCDBPP, BPP, PPF;
7373
bool CLKSEL, IVS, IHS, IPC, IOE, LEE, BGR, BEBO, BEPO, WTRMRK;
74-
uint16_t crsrPalette[4]; /* Palette stored as RGB565 or BGR565, and transparency/inversion masks */
75-
uint16_t palette[0x100]; /* Palette stored as RGB565 in native endianness */
74+
uint16_t crsrPalette[4]; /* Cursor palette stored as BGR565, plus transparency/inversion masks */
75+
uint16_t palettes[2][0x100]; /* Palette stored as BGR565 and RGB565 in native endianness */
7676

7777
/* Everything above here goes into the state */
7878
uint32_t *data; /* Pointer to start of data to start extracting from */

0 commit comments

Comments
 (0)