From ee89426d6ebd25792937149113c77380ec37f2c6 Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Fri, 21 Jan 2022 19:11:05 -0500 Subject: [PATCH] fix constant abstractions --- sdl/sdl-display.cpp | 38 ++++++++++---------------------------- sdl/sdl-display.h | 5 ++++- teensy/teensy-display.cpp | 9 ++------- 3 files changed, 16 insertions(+), 36 deletions(-) diff --git a/sdl/sdl-display.cpp b/sdl/sdl-display.cpp index 68c0aee..0e48e54 100644 --- a/sdl/sdl-display.cpp +++ b/sdl/sdl-display.cpp @@ -53,7 +53,7 @@ SDLDisplay::SDLDisplay() screen = SDL_CreateWindow("Aiie!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - 800, 480, + SDL_WIDTH, SDL_HEIGHT, SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE); // SDL_RENDERER_SOFTWARE because, at least on my Mac, this has some @@ -63,12 +63,11 @@ SDLDisplay::SDLDisplay() SDL_RenderClear(renderer); // clear it to the selected color SDL_RenderPresent(renderer); // perform the render - // *** buffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, - 800, - 480); + SDL_WIDTH, + SDL_HEIGHT); } SDLDisplay::~SDLDisplay() @@ -146,8 +145,7 @@ 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) { - // *** - if (x >= 800 || y >= 480) return; // make sure it's onscreen + if (x >= SDL_WIDTH || y >= SDL_HEIGHT) return; // make sure it's onscreen videoBuffer[y][x] = color16To32(color); } @@ -159,11 +157,6 @@ void SDLDisplay::drawPixel(uint16_t x, uint16_t y, uint16_t color) g = (color & 0x7E0) >> 3, b = (color & 0x1F) << 3; - // Pixel-doubling vertically and horizontally, based on scale - // for (int xoff=0; xoff 800.0/480.0) { - h = ((1.f * 480.0) / 800.0) * w; + if (aspectRatio != ((float)SDL_WIDTH)/((float)SDL_HEIGHT)) { + if (aspectRatio > ((float)SDL_WIDTH)/((float)SDL_HEIGHT)) { + h = ((1.f * ((float)SDL_HEIGHT)) / ((float)SDL_WIDTH)) * w; } else { - w = (800.0/480.0) * h; + w = (((float)SDL_WIDTH)/((float)SDL_HEIGHT)) * h; } } diff --git a/sdl/sdl-display.h b/sdl/sdl-display.h index 1184d17..ac2aae0 100644 --- a/sdl/sdl-display.h +++ b/sdl/sdl-display.h @@ -8,6 +8,9 @@ #include "physicaldisplay.h" +#define SDL_WIDTH 800 +#define SDL_HEIGHT 480 + class SDLDisplay : public PhysicalDisplay { public: SDLDisplay(); @@ -38,7 +41,7 @@ class SDLDisplay : public PhysicalDisplay { void windowResized(uint32_t w, uint32_t h); private: - uint32_t videoBuffer[480][800];// *** + uint32_t videoBuffer[SDL_HEIGHT][SDL_WIDTH]; SDL_Window *screen; SDL_Renderer *renderer; diff --git a/teensy/teensy-display.cpp b/teensy/teensy-display.cpp index 83440b5..5faa336 100644 --- a/teensy/teensy-display.cpp +++ b/teensy/teensy-display.cpp @@ -71,14 +71,9 @@ TeensyDisplay::TeensyDisplay() driveIndicator[0] = driveIndicator[1] = false; driveIndicatorDirty = true; - // tft.begin(Adafruit_800x480); - Serial.println("begin"); tft.begin(_clock); - Serial.println("set framebuffer"); tft.setFrameBuffer((uint8_t *)dmaBuffer); - Serial.println("clear window"); tft.fillWindow(); - Serial.println("ok"); } TeensyDisplay::~TeensyDisplay() @@ -223,8 +218,8 @@ void TeensyDisplay::drawString(uint8_t mode, uint16_t x, uint16_t y, const char void TeensyDisplay::clrScr(uint8_t coloridx) { uint8_t c = _565To332(loresPixelColors[coloridx]); - for (uint16_t y=0; y<480; y++) { - for (uint16_t x=0; x<800; x++) { + for (uint16_t y=0; y