From 3fec9c7ecbe279eeb7c7312321a813d871ed7168 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Sun, 8 Oct 2023 17:30:57 +0100 Subject: [PATCH] R/B swap for picovision --- 32blit/CMakeLists.txt | 2 ++ core/DMGDisplay.cpp | 24 ++++++++++++++++++------ core/DMGDisplay.h | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/32blit/CMakeLists.txt b/32blit/CMakeLists.txt index fda12bc..348674d 100644 --- a/32blit/CMakeLists.txt +++ b/32blit/CMakeLists.txt @@ -13,6 +13,8 @@ target_link_libraries(DaftBoy32 DaftBoyCore DUH) if(32BLIT_PICO) if(${PICO_BOARD} STREQUAL "pimoroni_picosystem") target_compile_definitions(DaftBoy32 PRIVATE -DDISPLAY_RGB565) + elseif(${PICO_ADDON} STREQUAL "pimoroni_picovision") + target_compile_definitions(DaftBoy32 PRIVATE -DDISPLAY_RB_SWAP) endif() else() set_target_properties(DaftBoy32 PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) diff --git a/core/DMGDisplay.cpp b/core/DMGDisplay.cpp index 1ed9451..d6c685c 100644 --- a/core/DMGDisplay.cpp +++ b/core/DMGDisplay.cpp @@ -463,7 +463,7 @@ bool DMGDisplay::writeReg(uint16_t addr, uint8_t data) auto bcps = mem.readIOReg(IO_BCPS); -#ifdef DISPLAY_RGB565 +#if defined(DISPLAY_RGB565) || defined(DISPLAY_RB_SWAP) reinterpret_cast(bgPaletteRaw)[bcps & 0x3F] = data; bgPaletteDirty = true; #else @@ -485,7 +485,7 @@ bool DMGDisplay::writeReg(uint16_t addr, uint8_t data) auto ocps = mem.readIOReg(IO_OCPS); -#ifdef DISPLAY_RGB565 +#if defined(DISPLAY_RGB565) || defined(DISPLAY_RB_SWAP) reinterpret_cast(objPaletteRaw)[ocps & 0x3F] = data; objPaletteDirty = true; #else @@ -639,12 +639,24 @@ void DMGDisplay::drawScanLine(int y) const bool isColour = cpu.getColourMode(); // sync palettes +#if defined(DISPLAY_RGB565) || defined(DISPLAY_RB_SWAP) + + const auto convert = [](uint16_t col) + { +#ifdef DISPLAY_RB_SWAP + col = col << 10 | (col & 0x3E0) | (col << 1) >> 11; +#endif #ifdef DISPLAY_RGB565 + col = (col & 0x1F) | (col & 0x7FE0) << 1; +#endif + return col; + }; + if(bgPaletteDirty) { auto outCol = bgPalette; - for(auto &col : bgPaletteRaw) - *outCol++ = (col & 0x1F) | (col & 0x7FE0) << 1; + for(auto col : bgPaletteRaw) + *outCol++ = convert(col); bgPaletteDirty = false; } @@ -652,8 +664,8 @@ void DMGDisplay::drawScanLine(int y) if(objPaletteDirty) { auto outCol = objPalette; - for(auto &col : objPaletteRaw) - *outCol++ = (col & 0x1F) | (col & 0x7FE0) << 1; + for(auto col : objPaletteRaw) + *outCol++ = convert(col); objPaletteDirty = false; } diff --git a/core/DMGDisplay.h b/core/DMGDisplay.h index a5e8537..1cfcfd2 100644 --- a/core/DMGDisplay.h +++ b/core/DMGDisplay.h @@ -59,7 +59,7 @@ class DMGDisplay // GBC uint16_t bgPalette[8 * 4], objPalette[8 * 4]; -#ifdef DISPLAY_RGB565 +#if defined(DISPLAY_RGB565) || defined(DISPLAY_RB_SWAP) uint16_t bgPaletteRaw[8 * 4], objPaletteRaw[8 * 4]; bool bgPaletteDirty = false, objPaletteDirty = false; #endif