From: Stephan Mühlstrasser Date: Tue, 18 Nov 2014 22:06:28 +0000 (+0100) Subject: Started cputc and related functions implementation. X-Git-Tag: V2.15~22^2~49 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5c8cd00dd53bec4ce837991704c0a455b4908153;p=cc65 Started cputc and related functions implementation. --- diff --git a/libsrc/c1p/cputc.c b/libsrc/c1p/cputc.c new file mode 100644 index 000000000..0c001cf58 --- /dev/null +++ b/libsrc/c1p/cputc.c @@ -0,0 +1,71 @@ +/* + * cputc.c + * + * void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c); + * void __fastcall__ cputc (char c); + */ + +#include + +/* Implements a 25 by 25 screen in the 1024 bytes video ram (32 by 32) */ +#define LINEWIDTH 0x20 +#define SCREENBASE ((char *) 0xd000) +#define TOP_OFFSET 4 +#define LEFT_OFFSET 3 +#define SCREENVISBASE (SCREENBASE + 4 * LINEWIDTH + LEFT_OFFSET) +#define WIDTH 25 +#define HEIGHT 25 + +static unsigned char xpos = 0; +static unsigned char ypos = 0; + +void __fastcall__ cputc(char c) +{ + char * const cp = SCREENVISBASE + ypos * LINEWIDTH + xpos; + + *cp = c; + + xpos += 1; + if (xpos > WIDTH - 1) { + xpos = 0; + ypos += 1; + + if (ypos > HEIGHT - 1) { + ypos = 0; + } + } +} + +void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c) +{ + xpos = x > WIDTH - 1 ? WIDTH - 1 : x; + ypos = y > HEIGHT - 1 ? HEIGHT - 1 : y; + + cputc(c); +} + +unsigned char wherex (void) +{ + return xpos; +} + +unsigned char wherey (void) +{ + return ypos; +} + +void __fastcall__ gotox (unsigned char x) +{ + xpos = x; +} + +void __fastcall__ gotoy (unsigned char y) +{ + ypos = y; +} + +void __fastcall__ gotoxy (unsigned char x, unsigned char y) +{ + xpos = x; + ypos = y; +}