Skip to content

Commit

Permalink
Fix screen code naming (#59)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mbrukner authored Aug 24, 2024
1 parent c786a47 commit eac0745
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~
Expand Down
19 changes: 18 additions & 1 deletion include/mega65/fcio.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,31 @@ 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
* @param c character code
* @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
19 changes: 12 additions & 7 deletions src/fcio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '_') {
Expand All @@ -355,7 +355,7 @@ char asciiToPetscii(byte c)
if (c >= 192) {
return c - 128;
}
return c;
return (char)c;
}

#ifdef __clang__
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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++;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit eac0745

Please sign in to comment.