From c4954b9ec59911079e9086e229dce4f1aface36b Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Tue, 19 Jan 2021 09:35:25 -0500 Subject: [PATCH] normalize with a 32-bit backing video store, matching the way we use dmaMem in the teensy build --- sdl/sdl-display.cpp | 58 ++++++++++++++++++++++++++++++++------------- sdl/sdl-display.h | 3 ++- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/sdl/sdl-display.cpp b/sdl/sdl-display.cpp index 96b0f03..0fc43a0 100644 --- a/sdl/sdl-display.cpp +++ b/sdl/sdl-display.cpp @@ -7,7 +7,7 @@ #include "applevm.h" #include "apple/appleui.h" -// FIXME should be able to omit this include and relay on the xterns, which +// FIXME should be able to omit this include and rely on the xterns, which // would prove it's linking properly #include "apple/font.h" extern const unsigned char ucase_glyphs[512]; @@ -37,6 +37,13 @@ const uint8_t loresPixelColors[16][3] = { { 0, 0, 0 }, // black { 0xFF, 0xFF, 0xFF } // white }; +#define color16To32(x) ( (((x) & 0xF800) << 8) | (((x) & 0x07E0) << 5) | (((x) & 0x001F)<<3) ) +#define packColor32(x) ( (x[0] << 16) | (x[1] << 8) | (x[2]) ) +// FIXME this blend could be optimized - and it's a dumb blend that +// just averages RGB values individually, rather than trying to find a +// sane blend of 2 pixels. Needs thought. +#define blendPackedColor(x,y) ( (((x) & 0xFF0000) + ((y) & 0xFF0000) / 2) + (((x) & 0x00FF00) + ((y) & 0x00FF00)) / 2 + (((x) & 0x0000FF) + ((y) & 0x0000FF)) / 2 ) + SDLDisplay::SDLDisplay() { memset(videoBuffer, 0, sizeof(videoBuffer)); @@ -63,6 +70,7 @@ SDLDisplay::~SDLDisplay() void SDLDisplay::flush() { + blit(); SDL_RenderPresent(renderer); } @@ -70,7 +78,6 @@ void SDLDisplay::redraw() { // primarily for the device, where it's in and out of the // bios. Draws the background image. - printf("redraw background\n"); g_ui->drawStaticUIElement(UIeOverlay); if (g_vm && g_ui) { @@ -99,7 +106,9 @@ void SDLDisplay::drawImageOfSizeAt(const uint8_t *img, void SDLDisplay::blit() { - // Whole-screen blit - unimplemented here + // Whole-screen blit + AiieRect r = { 0,0,191,279 }; + blit(r); } // Blit the videoBuffer to the display device, in the rect given @@ -111,12 +120,12 @@ void SDLDisplay::blit(AiieRect r) for (uint16_t y=r.top*SDLDISPLAY_SCALE; y> 16; + g = (colorIdx & 0x00FF00) >> 8; + b = (colorIdx & 0x0000FF); if (g_displayType == m_monochrome) { float fv = 0.2125 * r + 0.7154 * g + 0.0721 * b; @@ -149,7 +158,11 @@ inline void putpixel(SDL_Renderer *renderer, int x, int y, uint8_t r, uint8_t g, void SDLDisplay::drawUIPixel(uint16_t x, uint16_t y, uint16_t color) { - drawPixel(x*SDLDISPLAY_SCALE, y, color); + for (int yoff=0; yoff>1)*SDLDISPLAY_SCALE]; - - uint8_t newColor = (uint16_t) (origColor + color) / 2; - + uint32_t origColor = videoBuffer[y][(x>>1)*SDLDISPLAY_SCALE]; + uint32_t newColor = blendPackedColor(origColor, packColor32(loresPixelColors[color])); cacheDoubleWidePixel(x>>1,y,newColor); // Else if it's black, we leave whatever was in the other pixel. } else { @@ -274,7 +291,7 @@ void SDLDisplay::cachePixel(uint16_t x, uint16_t y, uint8_t color) x = (x * SDLDISPLAY_SCALE)/2; for (int yoff=0; yoff