Skip to content

Commit

Permalink
R/B swap for picovision
Browse files Browse the repository at this point in the history
  • Loading branch information
Daft-Freak committed Oct 8, 2023
1 parent 0513371 commit 3fec9c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions 32blit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 18 additions & 6 deletions core/DMGDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t *>(bgPaletteRaw)[bcps & 0x3F] = data;
bgPaletteDirty = true;
#else
Expand All @@ -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<uint8_t *>(objPaletteRaw)[ocps & 0x3F] = data;
objPaletteDirty = true;
#else
Expand Down Expand Up @@ -639,21 +639,33 @@ 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;
}

if(objPaletteDirty)
{
auto outCol = objPalette;
for(auto &col : objPaletteRaw)
*outCol++ = (col & 0x1F) | (col & 0x7FE0) << 1;
for(auto col : objPaletteRaw)
*outCol++ = convert(col);

objPaletteDirty = false;
}
Expand Down
2 changes: 1 addition & 1 deletion core/DMGDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3fec9c7

Please sign in to comment.