From e5798f4b71be996d599f487262040e236c74e248 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Mon, 13 Dec 2021 15:09:30 +0100 Subject: [PATCH] [CHANGE] Print jumps to next line if needed --- ascii.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ascii.cpp b/ascii.cpp index af3b75d..7824abb 100644 --- a/ascii.cpp +++ b/ascii.cpp @@ -322,15 +322,17 @@ void print(const char *str, int x, int y) { if (x >= 0) cursor_x = min(x, screen_width-1); if (y >= 0) cursor_y = min(y, screen_height-1); int len = SDL_strlen(str); - if ((cursor_x+len) > screen_width) len -= ((cursor_x+len) - screen_width); + const int pos = cursor_x+cursor_y*screen_width; + if (pos+len > screen_width*screen_height) len -= ((pos+len) - screen_width*screen_height); //int offset = x+y*screen_width; for (int i=0; i < len; ++i) { - CHRSCR(cursor_x+i, cursor_y) = str[i]; - if (current_mode != 0) COLSCR(cursor_x+i, cursor_y) = current_color; + char_screen[pos+i] = str[i]; + if (current_mode != 0) color_screen[pos+i] = current_color; //char_screen[offset+i] = str[i]; //if (current_mode != 0) color_screen[offset+i] = current_color; } - cursor_x += len; + cursor_x = (pos+len)%screen_width; + cursor_y = (pos+len)/screen_width; } bool btn(uint8_t i) {