From 691b2de8bbba054608692fea1374361eda0c2a26 Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Mon, 27 Feb 2017 08:12:18 -0500 Subject: [PATCH] convert primitive drawing routines to macros --- apple/appledisplay.cpp | 65 +++++++++++++++++++----------------------- apple/appledisplay.h | 7 +---- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/apple/appledisplay.cpp b/apple/appledisplay.cpp index 7562786..e8f2196 100644 --- a/apple/appledisplay.cpp +++ b/apple/appledisplay.cpp @@ -30,6 +30,35 @@ } \ } +#define drawPixel(c, x, y) { \ + uint16_t idx = ((y) * DISPLAYWIDTH + (x)) / 2; \ + if ((x) & 1) { \ + videoBuffer[idx] = (videoBuffer[idx] & 0xF0) | (c); \ + } else { \ + videoBuffer[idx] = (videoBuffer[idx] & 0x0F) | ((c) << 4); \ + } \ + } + +#define draw2Pixels(cAB, x, y) { \ + videoBuffer[((y) * DISPLAYWIDTH + (x)) /2] = cAB; \ + } + + +#define DrawLoresPixelAt(c, x, y) { \ + uint8_t pixel = c & 0x0F; \ + for (uint8_t y2 = 0; y2<4; y2++) { \ + for (int8_t x2 = 6; x2>=0; x2--) { \ + drawPixel(pixel, x*7+x2, y*8+y2); \ + } \ + } \ + pixel = (c >> 4); \ + for (uint8_t y2 = 4; y2<8; y2++) { \ + for (int8_t x2 = 6; x2>=0; x2--) { \ + drawPixel(pixel, x*7+x2, y*8+y2); \ + } \ + } \ +} + #include "globals.h" AppleDisplay::AppleDisplay(uint8_t *vb) : VMDisplay(vb) @@ -490,7 +519,7 @@ void AppleDisplay::modeChange() void AppleDisplay::Draw80LoresPixelAt(uint8_t c, uint8_t x, uint8_t y, uint8_t offset) { - // Just like 80-column text, this has a minor problem; we're talimg + // Just like 80-column text, this has a minor problem; we're taking // a 7-pixel-wide space and dividing it in half. Here I'm drawing // every other column 1 pixel narrower (the ">= offset" in the for // loop condition). @@ -517,40 +546,6 @@ void AppleDisplay::Draw80LoresPixelAt(uint8_t c, uint8_t x, uint8_t y, uint8_t o } } -// col, row are still character-like positions, as in DrawCharacterAt. -// Each holds two pixels (one on top of the other). -void AppleDisplay::DrawLoresPixelAt(uint8_t c, uint8_t x, uint8_t y) -{ - uint8_t pixel = c & 0x0F; - for (uint8_t y2 = 0; y2<4; y2++) { - for (int8_t x2 = 6; x2>=0; x2--) { - drawPixel(pixel, x*7+x2, y*8+y2); - } - } - - pixel = (c >> 4); - for (uint8_t y2 = 4; y2<8; y2++) { - for (int8_t x2 = 6; x2>=0; x2--) { - drawPixel(pixel, x*7+x2, y*8+y2); - } - } -} - -void AppleDisplay::draw2Pixels(uint16_t two4bitColors, uint16_t x, uint8_t y) -{ - videoBuffer[(y * DISPLAYWIDTH + x) /2] = two4bitColors; -} - -inline void AppleDisplay::drawPixel(uint8_t color4bit, uint16_t x, uint8_t y) -{ - uint16_t idx = (y * DISPLAYWIDTH + x) / 2; - if (x & 1) { - videoBuffer[idx] = (videoBuffer[idx] & 0xF0) | color4bit; - } else { - videoBuffer[idx] = (videoBuffer[idx] & 0x0F) | (color4bit << 4); - } -} - void AppleDisplay::setSwitches(uint16_t *switches) { dirty = true; diff --git a/apple/appledisplay.h b/apple/appledisplay.h index 44cd484..8a46ede 100644 --- a/apple/appledisplay.h +++ b/apple/appledisplay.h @@ -58,14 +58,9 @@ class AppleDisplay : public VMDisplay{ bool deinterlaceAddress(uint16_t address, uint8_t *row, uint8_t *col); bool deinterlaceHiresAddress(uint16_t address, uint8_t *row, uint16_t *col); - void Draw80CharacterAt(uint8_t c, uint8_t x, uint8_t y, uint8_t offset); - void DrawCharacterAt(uint8_t c, uint8_t x, uint8_t y); - void Draw14DoubleHiresPixelsAt(uint16_t address); + void Draw14DoubleHiresPixelsAt(uint16_t addr); void Draw14HiresPixelsAt(uint16_t addr); void Draw80LoresPixelAt(uint8_t c, uint8_t x, uint8_t y, uint8_t offset); - void DrawLoresPixelAt(uint8_t c, uint8_t x, uint8_t y); - void draw2Pixels(uint16_t two4bitColors, uint16_t x, uint8_t y); - void drawPixel(uint8_t cidx, uint16_t x, uint8_t y); const unsigned char *xlateChar(uint8_t c, bool *invert);