From dfb8fb16fcdae8bd0235949a78aa6948af817b5e Mon Sep 17 00:00:00 2001 From: Sijmen Schoon Date: Fri, 11 Dec 2020 20:52:57 +0100 Subject: [PATCH] Implement PrintFormat which scrolls the screen when overflowing --- src/Screen.cpp | 10 ++++++++++ src/Screen.h | 1 + src/main.cpp | 15 +++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/Screen.cpp b/src/Screen.cpp index 6118b5d..a4aeb28 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -188,6 +188,16 @@ void Screen::ScrollArea(u32 x1, u32 y1, u32 x2, u32 y2) } } +void Screen::ScrollUp(u32 pixels) +{ + memcpy( + framebuffer, + framebuffer + pixels * 2 * pitch, + (height - pixels * 2) * pitch + ); + DrawRectangle(0, height - pixels, width, height, RGBA(0, 0, 0, 0xFF)); +} + void Screen::Clear(RGBA colour) { DrawRectangle(0, 0, width, height, colour); diff --git a/src/Screen.h b/src/Screen.h index 1e4a8aa..5e7116c 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -36,6 +36,7 @@ public: void Clear(RGBA colour); void ScrollArea(u32 x1, u32 y1, u32 x2, u32 y2); + void ScrollUp(u32 pixels); void WriteChar(bool petscii, u32 x, u32 y, unsigned char c, RGBA colour); u32 PrintText(bool petscii, u32 xPos, u32 yPos, char *ptr, RGBA TxtColour = RGBA(0xff, 0xff, 0xff, 0xff), RGBA BkColour = RGBA(0, 0, 0, 0xFF), bool measureOnly = false, u32* width = 0, u32* height = 0); diff --git a/src/main.cpp b/src/main.cpp index 0a1b4cf..e1ac290 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1867,6 +1867,21 @@ void DisplayMessage(int x, int y, bool LCD, const char* message, u32 textColour, #endif } +int y_pos = 184; +void PrintFormat(const char* format, ...) +{ + va_list args; + va_start(args, format); + vsnprintf(tempBuffer, tempBufferSize, format, args); + va_end(args); + + if (y_pos + 96 >= screenHeight) { + screen.ScrollUp(8); + y_pos -= 16; + } + screen.PrintText(false, 0, y_pos+=16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); +} + extern "C" { void kernel_main(unsigned int r0, unsigned int r1, unsigned int atags)