From d3557f6b9b775ef7cae27d461c0309e2dd22bbd3 Mon Sep 17 00:00:00 2001 From: Linus Henze Date: Fri, 7 Feb 2020 22:23:14 +0100 Subject: [PATCH] Fix iStrap for devices with a white boot screen --- iStrap/iStrap/framebuffer.c | 51 +++++++++++++------------------------ iStrap/iStrap/framebuffer.h | 2 +- iStrap/iStrap/main.c | 4 +-- 3 files changed, 19 insertions(+), 38 deletions(-) diff --git a/iStrap/iStrap/framebuffer.c b/iStrap/iStrap/framebuffer.c index c9d3319..b307fca 100644 --- a/iStrap/iStrap/framebuffer.c +++ b/iStrap/iStrap/framebuffer.c @@ -12,7 +12,6 @@ #include -bool bwInversion = false; uint32_t bgColor = 0; int printfCurrentX = 0; @@ -26,14 +25,9 @@ void initFramebuffer(boot_args *args) { uint32_t *address = (uint32_t*) video->v_baseAddr; bgColor = address[0]; - - if (bgColor != 0) { - // This is a white device - bwInversion = true; - } } -// Pixel functions automatically draw 4x +// Pixel functions automatically draw 2x/4x void drawPixelXY(int x, int y, uint32_t color) { #if SCALE_FACTOR == 2 if (x >= video->v_width/2 || y >= video->v_height/2) { @@ -127,7 +121,7 @@ void rewriteColor(uint8_t or, uint8_t og, uint8_t ob, uint8_t r, uint8_t g, uint for (int y = 0; y < video->v_height; y++) { for (int x = 0; x < video->v_width; x++) { - if ((videoAddress[(y * ((int) video->v_rowBytes / 4)) + x] >> 8) == bgColor) { + if (videoAddress[(y * ((int) video->v_rowBytes / 4)) + x] == bgColor) { videoAddress[(y * ((int) video->v_rowBytes / 4)) + x] = color; } } @@ -246,38 +240,28 @@ int puts(const char *str) { } #pragma clang optimize on +// On devices with a white boot screen, this is effectively rowHasBlack bool rowHasWhite(int y) { uint32_t rowSize = (uint32_t) video->v_rowBytes/4; uint32_t *address = (uint32_t*) video->v_baseAddr; for (int x = 0; x < video->v_width; x++) { - if (bwInversion) { - if (address[y * rowSize + x] >> 8 == 0) { - return true; - } - } else { - if (address[y * rowSize + x] >> 8 != 0) { - return true; - } + if (address[y * rowSize + x] != bgColor) { + return true; } } return false; } +// On devices with a white boot screen, this is effectively columnHasBlack bool columnHasWhite(int x) { uint32_t rowSize = (uint32_t) video->v_rowBytes/4; uint32_t *address = (uint32_t*) video->v_baseAddr; for (int y = 0; y < video->v_width; y++) { - if (bwInversion) { - if (address[y * rowSize + x] >> 8 == 0) { - return true; - } - } else { - if (address[y * rowSize + x] >> 8 != 0) { - return true; - } + if (address[y * rowSize + x] != bgColor) { + return true; } } @@ -314,8 +298,6 @@ void findAppleLogo(int *xStart, int *yStart, int *xEnd, int *yEnd) { *xEnd = x; } -//#define CHECKERBOARD_SIZE 9 - const uint32_t colorStriping[] = { 0x000FFC00, 0x000FFC00, @@ -328,9 +310,10 @@ const uint32_t colorStriping[] = { 0x000003FF }; -void checkerboardInterleaved(int startX, int startY, int endX, int endY, uint32_t bgColor) { +void checkerboardInterleaved(int startX, int startY, int endX, int endY) { bool startWithBlack = false; - int outerCounter = 0; + int outerCtr = 0; + uint32_t *address = (uint32_t*) video->v_baseAddr; uint32_t rowSize = (uint32_t) video->v_rowBytes/4; @@ -339,11 +322,11 @@ void checkerboardInterleaved(int startX, int startY, int endX, int endY, uint32_ int stripeY = (endY - startY)/(sizeof(colorStriping)/sizeof(colorStriping[0])); int yCounter = 0; - int CHECKERBOARD_SIZE = stripeY/4; + int checkerboard_size = stripeY/4; for (int y = startY; y <= endY; y++) { - if (++outerCounter == CHECKERBOARD_SIZE) { - outerCounter = 0; + if (++outerCtr == checkerboard_size) { + outerCtr = 0; startWithBlack = !startWithBlack; if (yCounter >= stripeY) { @@ -359,14 +342,14 @@ void checkerboardInterleaved(int startX, int startY, int endX, int endY, uint32_ int innerCtr = 0; for (int x = startX; x <= endX; x++) { - if (++innerCtr == CHECKERBOARD_SIZE) { + if (++innerCtr == checkerboard_size) { innerCtr = 0; isBlack = !isBlack; } - if (address[y * rowSize + x] >> 8 != bgColor) { + if (address[y * rowSize + x] != bgColor) { if (isBlack) { - address[y * rowSize + x] = 0; + address[y * rowSize + x] = bgColor; } else { address[y * rowSize + x] = currentStripeColor; } diff --git a/iStrap/iStrap/framebuffer.h b/iStrap/iStrap/framebuffer.h index 68fa686..bfebe25 100644 --- a/iStrap/iStrap/framebuffer.h +++ b/iStrap/iStrap/framebuffer.h @@ -23,6 +23,6 @@ void drawChar(int x, int y, char ch); int printf(const char * restrict format, ...) __printflike(1, 2); int puts(const char *str); void findAppleLogo(int *xStart, int *yStart, int *xEnd, int *yEnd); -void checkerboardInterleaved(int startX, int startY, int endX, int endY, uint32_t bgColor); +void checkerboardInterleaved(int startX, int startY, int endX, int endY); #endif /* framebuffer_h */ diff --git a/iStrap/iStrap/main.c b/iStrap/iStrap/main.c index 6c2b419..ac221fb 100644 --- a/iStrap/iStrap/main.c +++ b/iStrap/iStrap/main.c @@ -30,13 +30,11 @@ void simple_sleep() { } void __attribute__((section(".text.boot"))) main_iStrap(void *image, boot_args *args, void *iBoot_base, void *iBoot_end) { - uint32_t *fb = (uint32_t*) args->video.v_baseAddr; - initFramebuffer(args); int lgStartX, lgStartY, lgEndX, lgEndY = 0; findAppleLogo(&lgStartX, &lgStartY, &lgEndX, &lgEndY); - checkerboardInterleaved(lgStartX, lgStartY, lgEndX, lgEndY, fb[0]); + checkerboardInterleaved(lgStartX, lgStartY, lgEndX, lgEndY); puts("===================================="); puts(" Welcome to iStrap! ");