diff --git a/include/mega65/conio.h b/include/mega65/conio.h index 9259aa0..9e2a080 100644 --- a/include/mega65/conio.h +++ b/include/mega65/conio.h @@ -914,7 +914,8 @@ void fastcall cputs(const unsigned char* s); * @param y The Y coordinate where string will be printed * @param s An array of screen codes to print. Must have non-zero length. * @remarks This function works with screen codes only. To output ordinary - * @warning Undefined behavior if `s` has zero length. + * ASCII/PETSCII strings, use the "pcputsxy" macro. No pointer check is + * performed. If s is null or invalid, behavior is undefined. */ void cputsxy(unsigned char x, unsigned char y, const unsigned char* s); @@ -946,7 +947,6 @@ void cputcxy(unsigned char x, unsigned char y, unsigned char c); * @param y The Y coordinate where character will be printed * @param count The number of characters to output. Must be larger than zero. * @param c The screen code of the characters to print - * @warning Undefined behavior if `count` is zero. */ void cputncxy( unsigned char x, unsigned char y, unsigned char count, unsigned char c); diff --git a/src/conio.c b/src/conio.c index 84da7b6..2ed080b 100644 --- a/src/conio.c +++ b/src/conio.c @@ -571,9 +571,11 @@ void cputs(const unsigned char* s) void cputsxy(unsigned char x, unsigned char y, const unsigned char* s) { const unsigned char len = (unsigned char)strlen((const char*)s); - const unsigned int offset = (y * (unsigned int)g_curScreenW) + x; - lcopy((unsigned long)s, SCREEN_RAM_BASE + offset, len); - lfill(COLOR_RAM_BASE + offset, g_curTextColor, len); + if (len > 0) { + const unsigned int offset = (y * (unsigned int)g_curScreenW) + x; + lcopy((unsigned long)s, SCREEN_RAM_BASE + offset, len); + lfill(COLOR_RAM_BASE + offset, g_curTextColor, len); + } g_curY = y + ((x + len) / g_curScreenW); g_curX = (x + len) % g_curScreenW; } @@ -590,9 +592,11 @@ void cputcxy(unsigned char x, unsigned char y, unsigned char c) void cputncxy( unsigned char x, unsigned char y, unsigned char count, unsigned char c) { - const unsigned int offset = (y * (unsigned int)g_curScreenW) + x; - lfill(SCREEN_RAM_BASE + offset, c, count); - lfill(COLOR_RAM_BASE + offset, g_curTextColor, count); + if (count > 0) { + const unsigned int offset = (y * (unsigned int)g_curScreenW) + x; + lfill(SCREEN_RAM_BASE + offset, c, count); + lfill(COLOR_RAM_BASE + offset, g_curTextColor, count); + } g_curY = y + ((x + count) / g_curScreenW); g_curX = (x + count) % g_curScreenW; } @@ -714,8 +718,7 @@ unsigned char cinput( } while (1) { - if (strlen(buffer) != 0) - cputsxy(sx, sy, buffer); + cputsxy(sx, sy, buffer); blink(1); cputc(224); blink(0);