]> git.sur5r.net Git - cc65/blob - libsrc/c1p/cputc.c
Started cputc and related functions implementation.
[cc65] / libsrc / c1p / cputc.c
1 /*\r
2  * cputc.c\r
3  *\r
4  * void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c);\r
5  * void __fastcall__ cputc (char c);\r
6  */\r
7 \r
8 #include <conio.h>\r
9 \r
10 /* Implements a 25 by 25 screen in the 1024 bytes video ram (32 by 32) */\r
11 #define LINEWIDTH 0x20\r
12 #define SCREENBASE ((char *) 0xd000)\r
13 #define TOP_OFFSET 4\r
14 #define LEFT_OFFSET 3\r
15 #define SCREENVISBASE (SCREENBASE + 4 * LINEWIDTH + LEFT_OFFSET)\r
16 #define WIDTH 25\r
17 #define HEIGHT 25\r
18 \r
19 static unsigned char xpos = 0;\r
20 static unsigned char ypos = 0;\r
21 \r
22 void __fastcall__ cputc(char c)\r
23 {\r
24     char * const cp = SCREENVISBASE + ypos * LINEWIDTH + xpos;\r
25 \r
26     *cp = c;\r
27 \r
28     xpos += 1;\r
29     if (xpos > WIDTH - 1) {\r
30         xpos = 0;\r
31         ypos += 1;\r
32 \r
33         if (ypos > HEIGHT - 1) {\r
34             ypos = 0;\r
35         }\r
36     }\r
37 }\r
38 \r
39 void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c)\r
40 {\r
41     xpos = x > WIDTH - 1 ? WIDTH - 1 : x;\r
42     ypos = y > HEIGHT - 1 ? HEIGHT - 1 : y;\r
43 \r
44     cputc(c);\r
45 }\r
46 \r
47 unsigned char wherex (void)\r
48 {\r
49     return xpos;\r
50 }\r
51 \r
52 unsigned char wherey (void)\r
53 {\r
54     return ypos;\r
55 }\r
56 \r
57 void __fastcall__ gotox (unsigned char x)\r
58 {\r
59     xpos = x;\r
60 }\r
61 \r
62 void __fastcall__ gotoy (unsigned char y)\r
63 {\r
64     ypos = y;\r
65 }\r
66 \r
67 void __fastcall__ gotoxy (unsigned char x, unsigned char y)\r
68 {\r
69     xpos = x;\r
70     ypos = y;\r
71 }\r