Forked para SNOCC
Fork of RA8875 by
Diff: GraphicsDisplay.cpp
- Revision:
- 101:e0aad446094a
- Parent:
- 100:0b084475d5a9
- Child:
- 104:8d1d3832a215
--- a/GraphicsDisplay.cpp Sat Dec 19 15:55:09 2015 +0000 +++ b/GraphicsDisplay.cpp Sun Jan 17 22:16:37 2016 +0000 @@ -93,7 +93,7 @@ int GraphicsDisplay::character(int x, int y, int c) { - return fontblit(x, y, font, c); + return fontblit(x, y, c); } RetCode_t GraphicsDisplay::window(loc_t x, loc_t y, dim_t w, dim_t h) @@ -165,7 +165,9 @@ //0x00,... // ' ' data stream. //0x00,0x06,0x00,0x07,0x80,0x07,0xC0,0x07,0xC0,0x07,0xC0 // '!' //... -int GraphicsDisplay::fontblit(int x, int y, const unsigned char * fontTable, const unsigned char c) + + +const uint8_t * GraphicsDisplay::getCharMetrics(const unsigned char c, uint8_t * width, uint8_t * height) { uint16_t offsetToCharLookup; uint16_t firstChar = font[3] * 256 + font[2]; @@ -175,42 +177,74 @@ INFO("first:%d, last:%d, c:%d", firstChar, lastChar, c); if (c < firstChar || c > lastChar) + return NULL; // advance zero pixels since it was unprintable... + + // 8 bytes of preamble to the first level lookup table + offsetToCharLookup = 8 + 4 * (c - firstChar); // 4-bytes: width(pixels), 16-bit offset from table start, 0 + uint8_t charWidth = font[offsetToCharLookup]; + charRecord = font + font[offsetToCharLookup + 2] * 256 + font[offsetToCharLookup + 1]; + //INFO("hgt:%d, wdt:%d", charHeight, charWidth); + if (width) + *width = charWidth; + if (height) + *height = charHeight; + return charRecord; +} + +int GraphicsDisplay::fontblit(int x, int y, const unsigned char c) +{ + #if 0 + uint16_t offsetToCharLookup; + uint16_t firstChar = font[3] * 256 + font[2]; + uint16_t lastChar = font[5] * 256 + font[4]; + uint8_t charHeight = font[6]; + const unsigned char * charRecord; // width, data, data, data, ... + + INFO("first:%d, last:%d, c:%d", firstChar, lastChar, c); + if (c < firstChar || c > lastChar) return 0; // advance zero pixels since it was unprintable... // 8 bytes of preamble to the first level lookup table offsetToCharLookup = 8 + 4 * (c - firstChar); // 4-bytes: width(pixels), 16-bit offset from table start, 0 uint8_t charWidth = font[offsetToCharLookup]; charRecord = font + font[offsetToCharLookup + 2] * 256 + font[offsetToCharLookup + 1]; - - INFO("hgt:%d, wdt:%d", charHeight, charWidth); - // clip to the edge of the screen - //if (x + charWidth >= width()) - // charWidth = width() - x; - //if (y + charHeight >= height()) - // charHeight = height() - y; - window(x, y, charWidth, charHeight); - _StartGraphicsStream(); - while (charHeight--) { - uint8_t pixels = charWidth; - uint8_t bitmask = 0x01; - - while (pixels) { - uint8_t byte = *charRecord; - INFO("byte, mask: %02X, %02X", byte, bitmask); - color_t c = (byte & bitmask) ? _foreground : _background; - _putp(c); - bitmask <<= 1; - if (pixels > 1 && bitmask == 0) { - bitmask = 0x01; - charRecord++; +#endif + const unsigned char * charRecord; // width, data, data, data, ... + uint8_t charWidth, charHeight; + charRecord = getCharMetrics(c, &charWidth, &charHeight); + if (charRecord) { + INFO("hgt:%d, wdt:%d", charHeight, charWidth); + // clip to the edge of the screen + //if (x + charWidth >= width()) + // charWidth = width() - x; + //if (y + charHeight >= height()) + // charHeight = height() - y; + window(x, y, charWidth, charHeight); + _StartGraphicsStream(); + while (charHeight--) { + uint8_t pixels = charWidth; + uint8_t bitmask = 0x01; + + while (pixels) { + uint8_t byte = *charRecord; + INFO("byte, mask: %02X, %02X", byte, bitmask); + color_t c = (byte & bitmask) ? _foreground : _background; + _putp(c); + bitmask <<= 1; + if (pixels > 1 && bitmask == 0) { + bitmask = 0x01; + charRecord++; + } + pixels--; } - pixels--; + charRecord++; } - charRecord++; + _EndGraphicsStream(); + WindowMax(); + return charWidth; + } else { + return 0; } - _EndGraphicsStream(); - WindowMax(); - return charWidth; } // BMP Color Palette is BGRx