From eac07459463966b866c1a594222a5e9fe8e6c66f Mon Sep 17 00:00:00 2001 From: Matthias Brukner Date: Sat, 24 Aug 2024 17:35:04 +0200 Subject: [PATCH] Fix screen code naming (#59) * Fix naming for screen code usage. Old names are still available but marked deprecated. * In the functions that plot actual character to the screen the naming suggested it would handle PETSCII codes, where in fact is was dealing with screen codes. These changes make that more clear. * Fix build instructions when using llvm * Re-adds the asciiToPetsciicode function and adds a deprecation warning when using LLVM * Fix deprecation warnings, update doxygen comment, remove deprecation for non-exported function --- README.md | 1 + include/mega65/fcio.h | 19 ++++++++++++++++++- src/fcio.c | 19 ++++++++++++------- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f8f64a8..3252b99 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Simple C library for the MEGA65 ~~~sh cd mega65-libc cmake -DCMAKE_PREFIX_PATH=$HOME/llvm-mos -B build + cd build make make test # if `xmega65` (Xemu) was in your path when running cmake ~~~ diff --git a/include/mega65/fcio.h b/include/mega65/fcio.h index e9251ba..2c76bad 100644 --- a/include/mega65/fcio.h +++ b/include/mega65/fcio.h @@ -516,7 +516,7 @@ fciInfo* fc_displayFCIFile(char* filename, byte x0, byte y0); void fc_plotExtChar(byte x, byte y, byte c); /** - * @brief plot petscii character + * @brief plot screencode character * * @param x screen column * @param y screen row @@ -524,6 +524,23 @@ void fc_plotExtChar(byte x, byte y, byte c); * @param color character colour * @param exAttr extended attributes */ +void fc_plotScreenChar(byte x, byte y, byte c, byte color, byte exAttr); + +/** + * @deprecated The function name is misleading as the supplied character code + * is expected to be a screen character code, not a PETSCII code. + * Use @ref fc_plotScreenChar(byte, byte, byte, byte, byte) instead. + * @brief plot screencode character + * + * @param x screen column + * @param y screen row + * @param c character code + * @param color character colour + * @param exAttr extended attributes + */ +#ifdef __clang__ +[[deprecated("Use fc_plotScreenChar() instead.")]] +#endif void fc_plotPetsciiChar(byte x, byte y, byte c, byte color, byte exAttr); #endif // __MEGA65_FCIO_H diff --git a/src/fcio.c b/src/fcio.c index 6cd9efb..45b7dc4 100644 --- a/src/fcio.c +++ b/src/fcio.c @@ -340,7 +340,7 @@ himemPtr fc_allocPalMem(word size) return 0; } -char asciiToPetscii(byte c) +char asciiToScreencode(byte c) { // TODO: could be made much faster with translation table if (c == '_') { @@ -355,7 +355,7 @@ char asciiToPetscii(byte c) if (c >= 192) { return c - 128; } - return c; + return (char)c; } #ifdef __clang__ @@ -740,7 +740,7 @@ void cr(void) } } -void fc_plotPetsciiChar(byte x, byte y, byte c, byte color, byte exAttr) +void fc_plotScreenChar(byte x, byte y, byte c, byte color, byte exAttr) { word adrOffset; adrOffset = (x * 2) + (y * 2 * gScreenColumns); @@ -750,6 +750,11 @@ void fc_plotPetsciiChar(byte x, byte y, byte c, byte color, byte exAttr) lpoke(gFcioConfig->colourBase + adrOffset, 0); } +void fc_plotPetsciiChar(byte x, byte y, byte c, byte color, byte exAttr) +{ + fc_plotScreenChar(x, y, c, color, exAttr); +} + byte fc_wherex(void) { return gCurrentWin->xc; @@ -780,9 +785,9 @@ void fc_putc(char c) return; } - out = asciiToPetscii(c); + out = asciiToScreencode((byte)c); - fc_plotPetsciiChar(gCurrentWin->xc + gCurrentWin->x0, + fc_plotScreenChar(gCurrentWin->xc + gCurrentWin->x0, gCurrentWin->yc + gCurrentWin->y0, out, gCurrentWin->textcolor, gCurrentWin->extAttributes); gCurrentWin->xc++; @@ -799,7 +804,7 @@ void fc_putc(char c) } if (csrflag) { - fc_plotPetsciiChar(gCurrentWin->xc + gCurrentWin->x0, + fc_plotScreenChar(gCurrentWin->xc + gCurrentWin->x0, gCurrentWin->yc + gCurrentWin->y0, CURSOR_CHARACTER, gCurrentWin->textcolor, 16); } @@ -848,7 +853,7 @@ void fc_cursor(byte onoff) { csrflag = onoff; - fc_plotPetsciiChar(gCurrentWin->xc + gCurrentWin->x0, + fc_plotScreenChar(gCurrentWin->xc + gCurrentWin->x0, gCurrentWin->yc + gCurrentWin->y0, (csrflag ? CURSOR_CHARACTER : 32), gCurrentWin->textcolor, (csrflag ? 16 : 0)); }