1 /*****************************************************************************/
5 /* Direct console I/O */
9 /* (C) 1998-2007 Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
37 ** This is the direct console interface for cc65. I do not like the function
38 ** names very much, but the first version started as a rewrite of Borland's
39 ** conio, and, even if the interface has changed, the names did not.
41 ** The interface does direct screen I/O, so it is fast enough for most
42 ** programs. I did not implement text windows, since many applications do
43 ** not need them and should not pay for the additional overhead. It should
44 ** be easy to add text windows on a higher level if needed,
46 ** Most routines do not check the parameters. This may be unfortunate but is
47 ** also related to speed. The coordinates are always 0/0 based.
57 #if !defined(_STDARG_H)
61 /* Include the correct machine-specific file */
62 #if defined(__APPLE2ENH__)
63 # include <apple2enh.h>
64 #elif defined(__APPLE2__)
66 #elif defined(__ATARI5200__)
67 # include <atari5200.h>
68 #elif defined(__ATARI__)
70 #elif defined(__ATMOS__)
72 #elif defined(__CBM__)
74 #elif defined(__CREATIVISION__)
75 # include <creativision.h>
76 #elif defined(__GAMATE__)
78 #elif defined(__GEOS__)
80 #elif defined(__LUNIX__)
82 #elif defined(__LYNX__)
84 #elif defined(__NES__)
86 #elif defined(__OSIC1P__)
88 #elif defined(__PCE__)
94 /*****************************************************************************/
96 /*****************************************************************************/
101 /* Clear the whole screen and put the cursor into the top left corner */
103 unsigned char kbhit (void);
104 /* Return true if there's a key waiting, return false if not */
106 void __fastcall__ gotox (unsigned char x);
107 /* Set the cursor to the specified X position, leave the Y position untouched */
109 void __fastcall__ gotoy (unsigned char y);
110 /* Set the cursor to the specified Y position, leave the X position untouched */
112 void __fastcall__ gotoxy (unsigned char x, unsigned char y);
113 /* Set the cursor to the specified position */
115 unsigned char wherex (void);
116 /* Return the X position of the cursor */
118 unsigned char wherey (void);
119 /* Return the Y position of the cursor */
121 void __fastcall__ cputc (char c);
122 /* Output one character at the current cursor position */
124 void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c);
125 /* Same as "gotoxy (x, y); cputc (c);" */
127 void __fastcall__ cputs (const char* s);
128 /* Output a NUL-terminated string at the current cursor position */
130 void __fastcall__ cputsxy (unsigned char x, unsigned char y, const char* s);
131 /* Same as "gotoxy (x, y); puts (s);" */
133 int cprintf (const char* format, ...);
134 /* Like printf(), but uses direct screen output */
136 int __fastcall__ vcprintf (const char* format, va_list ap);
137 /* Like vprintf(), but uses direct screen output */
140 /* Return a character from the keyboard. If there is no character available,
141 ** the function waits until the user does press a key. If cursor is set to
142 ** 1 (see below), a blinking cursor is displayed while waiting.
145 int cscanf (const char* format, ...);
146 /* Like scanf(), but uses direct keyboard input */
148 int __fastcall__ vcscanf (const char* format, va_list ap);
149 /* Like vscanf(), but uses direct keyboard input */
152 /* Return the character from the current cursor position */
154 unsigned char cpeekcolor (void);
155 /* Return the color from the current cursor position */
157 unsigned char cpeekrevers (void);
158 /* Return the reverse attribute from the current cursor position.
159 ** If the character is reversed, then return 1; return 0 otherwise.
162 void __fastcall__ cpeeks (char* s, unsigned int length);
163 /* Return a string of the characters that start at the current cursor position.
164 ** Put the string into the buffer to which "s" points. The string will have
165 ** "length" characters, then will be '\0'-terminated.
168 unsigned char __fastcall__ cursor (unsigned char onoff);
169 /* If onoff is 1, a cursor is displayed when waiting for keyboard input. If
170 ** onoff is 0, the cursor is hidden when waiting for keyboard input. The
171 ** function returns the old cursor setting.
174 unsigned char __fastcall__ revers (unsigned char onoff);
175 /* Enable/disable reverse character display. This may not be supported by
176 ** the output device. Return the old setting.
179 unsigned char __fastcall__ textcolor (unsigned char color);
180 /* Set the color for text output. The old color setting is returned. */
182 unsigned char __fastcall__ bgcolor (unsigned char color);
183 /* Set the color for the background. The old color setting is returned. */
185 unsigned char __fastcall__ bordercolor (unsigned char color);
186 /* Set the color for the border. The old color setting is returned. */
188 void __fastcall__ chline (unsigned char length);
189 /* Output a horizontal line with the given length starting at the current
193 void __fastcall__ chlinexy (unsigned char x, unsigned char y, unsigned char length);
194 /* Same as "gotoxy (x, y); chline (length);" */
196 void __fastcall__ cvline (unsigned char length);
197 /* Output a vertical line with the given length at the current cursor
201 void __fastcall__ cvlinexy (unsigned char x, unsigned char y, unsigned char length);
202 /* Same as "gotoxy (x, y); cvline (length);" */
204 void __fastcall__ cclear (unsigned char length);
205 /* Clear part of a line (write length spaces). */
207 void __fastcall__ cclearxy (unsigned char x, unsigned char y, unsigned char length);
208 /* Same as "gotoxy (x, y); cclear (length);" */
210 void __fastcall__ screensize (unsigned char* x, unsigned char* y);
211 /* Return the current screen size. */
213 void __fastcall__ cputhex8 (unsigned char val);
214 void __fastcall__ cputhex16 (unsigned val);
215 /* These shouldn't be here... */
219 /*****************************************************************************/
221 /*****************************************************************************/
225 /* On some platforms, functions are not available or are dummys. To suppress
226 ** the call to these functions completely, the platform header files may
227 ** define macros for these functions that start with an underline. If such a
228 ** macro exists, a new macro is defined here, that expands to the one with the
229 ** underline. The reason for this two stepped approach is that it is sometimes
230 ** necessary to take the address of the function, which is not possible when
231 ** using a macro. Since the function prototype is still present, #undefining
232 ** the macro will give access to the actual function.
235 #if defined(_textcolor)
236 # define textcolor(x) _textcolor(x)
238 #if defined(_bgcolor)
239 # define bgcolor(x) _bgcolor(x)
241 #if defined(_bordercolor)
242 # define bordercolor(x) _bordercolor(x)
244 #if defined(_cpeekcolor)
245 # define cpeekcolor(x) _cpeekcolor(x)