Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

ciolib.h 23.7 KB
Newer Older
1
/* $Id: ciolib.h,v 1.125 2020/06/27 00:04:44 deuce Exp $ */
2

deuce's avatar
deuce committed
3 4 5 6
/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
deuce's avatar
deuce committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 *																			*
 * This library is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU Lesser General Public License		*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU Lesser General Public License for more details: lgpl.txt or	*
 * http://www.fsf.org/copyleft/lesser.html									*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

34 35 36
#ifndef _CIOLIB_H_
#define _CIOLIB_H_

deuce's avatar
deuce committed
37
#include <string.h>	/* size_t */
deuce's avatar
deuce committed
38 39 40
#if defined(__DARWIN__)
#include <semwrap.h>
#endif
41
#include "gen_defs.h"
deuce's avatar
deuce committed
42
#include "utf8_codepages.h"
deuce's avatar
deuce committed
43

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#ifdef CIOLIBEXPORT
        #undef CIOLIBEXPORT
#endif

#ifdef _WIN32
        #if defined(CIOLIB_IMPORTS) || defined(CIOLIB_EXPORTS)
                #if defined(CIOLIB_IMPORTS)
                        #define CIOLIBEXPORT __declspec( dllimport )
                        #define CIOLIBEXPORTVAR __declspec( dllimport )
                #else
                        #define CIOLIBEXPORT __declspec( dllexport )
                        #define CIOLIBEXPORTVAR __declspec( dllexport )
                #endif
        #else   /* self-contained executable */
                #define CIOLIBEXPORT
                #define CIOLIBEXPORTVAR	extern
        #endif
#elif defined __unix__
        #define CIOLIBEXPORT
63
        #define CIOLIBEXPORTVAR	extern
64 65
#else
        #define CIOLIBEXPORT
66
        #define CIOLIBEXPORTVAR	extern
67 68
#endif

69
enum {
70 71 72
	 CIOLIB_MODE_AUTO
	,CIOLIB_MODE_CURSES
	,CIOLIB_MODE_CURSES_IBM
73
	,CIOLIB_MODE_CURSES_ASCII
74 75 76
	,CIOLIB_MODE_ANSI
	,CIOLIB_MODE_X
	,CIOLIB_MODE_CONIO
77
	,CIOLIB_MODE_CONIO_FULLSCREEN
78
	,CIOLIB_MODE_SDL
79
	,CIOLIB_MODE_SDL_FULLSCREEN
80 81
};

82 83 84 85 86
enum ciolib_mouse_ptr {
	 CIOLIB_MOUSEPTR_ARROW
	,CIOLIB_MOUSEPTR_BAR
};

deuce's avatar
deuce committed
87
#if defined(_WIN32)	/* presumably, Win32 */
88 89 90

	#include <io.h>			/* isatty */

deuce's avatar
deuce committed
91
#endif
92

93 94 95
#ifndef __COLORS
#define __COLORS

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
enum {
	 BLACK
	,BLUE
	,GREEN
	,CYAN
	,RED
	,MAGENTA
	,BROWN	
	,LIGHTGRAY	
	,DARKGRAY
	,LIGHTBLUE	
	,LIGHTGREEN	
	,LIGHTCYAN
	,LIGHTRED
	,LIGHTMAGENTA
	,YELLOW
	,WHITE
};
114 115 116 117

#endif	/* __COLORS */

#ifndef BLINK
118
#define BLINK 128
119
#endif
120

Deucе's avatar
Deucе committed
121 122 123 124 125 126 127
#define CIOLIB_VIDEO_ALTCHARS             (1<<0)	// Attribute bit 3 selects alternate char set
#define CIOLIB_VIDEO_NOBRIGHT             (1<<1)	// Attribute bit 3 does not increase intensity
#define CIOLIB_VIDEO_BGBRIGHT             (1<<2)	// Attribute bit 7 selects high intensity background, not blink
#define CIOLIB_VIDEO_BLINKALTCHARS        (1<<3)	// Attribute bit 7 selects alternate char set
#define CIOLIB_VIDEO_NOBLINK              (1<<4)	// Attribute bit 7 has no effect
#define CIOLIB_VIDEO_EXPAND               (1<<5)	// Use an extra blank column between characters from the font
#define CIOLIB_VIDEO_LINE_GRAPHICS_EXPAND (1<<6)	// Per VGA, when using CIOLIB_VIDEO_EXPAND, repeat the last column for chars 0xC0 - 0xDF inclusive
128

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
enum text_modes
{
    /* DOS-compatible modes */

    LASTMODE = -1,
    BW40     = 0,
    C40,
    BW80,
    C80,
    MONO     = 7,

    /* New Color modes */

    C40X14   = 8,
    C40X21,
    C40X28,
    C40X43,
    C40X50,
    C40X60,

    C80X14,
    C80X21,
    C80X28,
152
    C80X30,
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    C80X43,
    C80X50,
    C80X60,

    /* New Black & White modes */

    BW40X14,
    BW40X21,
    BW40X28,
    BW40X43,
    BW40X50,
    BW40X60,

    BW80X14,
    BW80X21,
    BW80X28,
    BW80X43,
    BW80X50,
    BW80X60,

    /* New Monochrome modes */

    MONO14,             /* Invalid VGA mode */
    MONO21,
    MONO28,
    MONO43,
    MONO50,
180
    MONO60,		// 38
181

182 183 184 185 186
	/* New modes we've added 'cause they're cool */

	ST132X37_16_9,
	ST132X52_5_4,

Deucе's avatar
Deucе committed
187 188 189
	/* New modes we've added 'cause they're stupid */
	VGA80X25,

190 191 192
	/* Cruft... */

	C4350    = C80X50,	/* this is actually "64" in the "real" conio */
193

deuce's avatar
deuce committed
194
    _ORIGMODE = 65,      /* original mode at program startup */
195

196
	EGA80X25,	/* 80x25 in 640x350 screen */
197 198 199
    C64_40X25 = 147,	/* Commodore 64 40x25 colour mode */
    C128_40X25,		/* Commodore 128 40x25 colour mode */
    C128_80X25,		/* Commodore 128 40x25 colour mode */
200
	ATARI_40X24,	/* Atari 800 40x24 colour text mode */
201
	ATARI_80X25,	/* Atari 800 XEP80 80x25 mono text mode */
deuce's avatar
deuce committed
202 203

	/* VESA Modes */
deuce's avatar
deuce committed
204 205 206 207 208 209 210 211
	VESA_132X21	= 235,
	VESA_132X25	= 231,
	VESA_132X28	= 228,
	VESA_132X30	= 226,
	VESA_132X34	= 222,
	VESA_132X43	= 213,
	VESA_132X50	= 206,
	VESA_132X60	= 196,
212 213

	/* Custom Mode */
214
	CIOLIB_MODE_CUSTOM = 255,	// Last mode... if it's over 255, text_info can't hold it.
215
};
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240

#define COLOR_MODE	C80

enum
{
	_NOCURSOR,
	_SOLIDCURSOR,
	_NORMALCURSOR
};

struct text_info {
	unsigned char winleft;        /* left window coordinate */
	unsigned char wintop;         /* top window coordinate */
	unsigned char winright;       /* right window coordinate */
	unsigned char winbottom;      /* bottom window coordinate */
	unsigned char attribute;      /* text attribute */
	unsigned char normattr;       /* normal attribute */
	unsigned char currmode;       /* current video mode:
                                	 BW40, BW80, C40, C80, or C4350 */
	unsigned char screenheight;   /* text screen's height */
	unsigned char screenwidth;    /* text screen's width */
	unsigned char curx;           /* x-coordinate in current window */
	unsigned char cury;           /* y-coordinate in current window */
};

deuce's avatar
deuce committed
241
CIOLIBEXPORTVAR struct text_info cio_textinfo;
242 243
CIOLIBEXPORTVAR uint32_t ciolib_fg;
CIOLIBEXPORTVAR uint32_t ciolib_bg;
244

245 246 247 248 249 250 251 252
struct mouse_event {
	int event;
	int bstate;
	int kbsm;
	int startx;
	int starty;
	int endx;
	int endy;
253 254 255 256
	int startx_res;
	int starty_res;
	int endx_res;
	int endy_res;
257 258
};

deuce's avatar
deuce committed
259
struct conio_font_data_struct {
260 261 262 263
        char 	*eight_by_sixteen;
        char 	*eight_by_fourteen;
        char 	*eight_by_eight;
        char 	*desc;
deuce's avatar
deuce committed
264
        enum ciolib_codepage cp;
deuce's avatar
deuce committed
265 266
};

deuce's avatar
deuce committed
267
CIOLIBEXPORTVAR struct conio_font_data_struct conio_fontdata[257];
deuce's avatar
deuce committed
268

deuce's avatar
deuce committed
269 270
struct ciolib_pixels {
	uint32_t	*pixels;
271
	uint32_t	*pixelsb;
deuce's avatar
deuce committed
272 273 274 275
	uint32_t	width;
	uint32_t	height;
};

276 277 278 279 280 281 282 283
struct vmem_cell {
	uint8_t legacy_attr;
	uint8_t ch;
	uint8_t font;
	uint32_t fg;	// RGB 00RRGGBB High bit indicates palette colour
	uint32_t bg;	// RGB 00RRGGBB High bit indicates palette colour
};

deuce's avatar
deuce committed
284
struct ciolib_screen {
285 286
	uint32_t		fg_colour;
	uint32_t		bg_colour;
287 288
	int			flags;
	int			fonts[5];
deuce's avatar
deuce committed
289
	struct ciolib_pixels	*pixels;
290
	struct vmem_cell	*vmem;
deuce's avatar
deuce committed
291
	struct text_info	text_info;
292
	uint32_t		palette[16];
deuce's avatar
deuce committed
293 294
};

295
#define CONIO_FIRST_FREE_FONT	43
deuce's avatar
deuce committed
296

297 298
typedef struct {
	int		mode;
deuce's avatar
deuce committed
299
	int		mouse;
300 301 302 303 304 305 306 307 308 309 310 311 312
	uint64_t	options;
#define	CONIO_OPT_LOADABLE_FONTS	1
#define CONIO_OPT_BLINK_ALT_FONT	2
#define CONIO_OPT_BOLD_ALT_FONT		4
#define CONIO_OPT_BRIGHT_BACKGROUND	8
#define CONIO_OPT_PALETTE_SETTING	16
#define CONIO_OPT_SET_PIXEL			32
#define CONIO_OPT_CUSTOM_CURSOR		64
#define CONIO_OPT_FONT_SELECT		128
#define CONIO_OPT_SET_TITLE			256
#define CONIO_OPT_SET_NAME			512
#define CONIO_OPT_SET_ICON			1024
#define CONIO_OPT_EXTENDED_PALETTE	2048
313
#define CONIO_OPT_BLOCKY_SCALING	4096
314
	void	(*clreol)		(void);
315
	int		(*puttext)		(int,int,int,int,void *);
316
	int		(*vmem_puttext)		(int,int,int,int,struct vmem_cell *);
317
	int		(*gettext)		(int,int,int,int,void *);
318
	int		(*vmem_gettext)		(int,int,int,int,struct vmem_cell *);
319
	void	(*textattr)		(int);
320 321 322 323
	int		(*kbhit)		(void);
	void	(*delay)		(long);
	int		(*wherex)		(void);
	int		(*wherey)		(void);
324
	int		(*putch)		(int);
325 326 327 328 329 330
	void	(*gotoxy)		(int,int);
	void	(*clrscr)		(void);
	void	(*gettextinfo)	(struct text_info *);
	void	(*setcursortype)(int);
	int		(*getch)		(void);
	int		(*getche)		(void);
331
	void	(*beep)			(void);
332 333 334 335 336 337 338 339 340 341 342 343 344
	void	(*highvideo)	(void);
	void	(*lowvideo)		(void);
	void	(*normvideo)	(void);
	void	(*textmode)		(int);
	int		(*ungetch)		(int);
	int		(*movetext)		(int,int,int,int,int,int);
	char	*(*cgets)		(char *);
	int		(*cscanf)		(char *,...);
	char	*(*getpass)		(const char *);
	void	(*wscroll)		(void);
	void	(*window)		(int,int,int,int);
	void	(*delline)		(void);
	void	(*insline)		(void);
deuce's avatar
deuce committed
345
	int		(*cprintf)		(const char *,...);
Deucе's avatar
Deucе committed
346
	int		(*cputs)		(const char *);
347 348
	void	(*textbackground)	(int);
	void	(*textcolor)	(int);
deuce's avatar
deuce committed
349
	int		(*getmouse)		(struct mouse_event *mevent);
deuce's avatar
deuce committed
350
	int		(*ungetmouse)	(struct mouse_event *mevent);
deuce's avatar
deuce committed
351 352
	int		(*hidemouse)	(void);
	int		(*showmouse)	(void);
353
	int		(*mousepointer)	(enum ciolib_mouse_ptr);
354
	void	(*settitle)		(const char *);
355
	void	(*setname)		(const char *);
356
	void	(*seticon)		(const void *, unsigned long);
deuce's avatar
deuce committed
357 358
	void	(*copytext)		(const char *, size_t);
	char 	*(*getcliptext)	(void);
359 360
	void	(*suspend)		(void);
	void	(*resume)		(void);
361
	int		(*setfont)		(int font, int force, int font_num);
362
	int		(*getfont)		(int font_num);
363
	int		(*loadfont)		(char *filename);
364
	int		(*get_window_info)		(int* width, int* height, int* xpos, int* ypos);
365 366
	void	(*getcustomcursor)	(int *startline, int *endline, int *range, int *blink, int *visible);
	void	(*setcustomcursor)	(int startline, int endline, int range, int blink, int visible);
367
	void	(*setvideoflags)	(int flags);
deuce's avatar
deuce committed
368
	int		(*getvideoflags)	(void);
369 370
	void	(*setscaling)	(int new_value);
	int		(*getscaling)	(void);
371
	int		*escdelay;
372
	int		(*setpalette)	(uint32_t entry, uint16_t r, uint16_t g, uint16_t b);
373
	int		(*attr2palette)	(uint8_t attr, uint32_t *fg, uint32_t *bg);
deuce's avatar
deuce committed
374
	int		(*setpixel)	(uint32_t x, uint32_t y, uint32_t colour);
375
	struct ciolib_pixels *(*getpixels)(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, int force);
deuce's avatar
deuce committed
376
	int		(*setpixels)(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, uint32_t x_off, uint32_t y_off, struct ciolib_pixels *pixels, void *mask);
377
	int 	(*get_modepalette)(uint32_t[16]);
deuce's avatar
deuce committed
378
	int	(*set_modepalette)(uint32_t[16]);
379
	uint32_t	(*map_rgb)(uint16_t r, uint16_t g, uint16_t b);
380
	void	(*replace_font)(uint8_t id, char *name, void *data, size_t size);
381
	int	(*checkfont)(int font_num);
deuce's avatar
deuce committed
382 383
	void	(*setwinsize)	(int width, int height);
	void	(*setwinposition)	(int x, int y);
384 385
} cioapi_t;

386 387 388 389
CIOLIBEXPORTVAR cioapi_t cio_api;
CIOLIBEXPORTVAR int _wscroll;
CIOLIBEXPORTVAR int directvideo;
CIOLIBEXPORTVAR int hold_update;
390
CIOLIBEXPORTVAR int puttext_can_move;
deuce's avatar
deuce committed
391
CIOLIBEXPORTVAR int ciolib_reaper;
392
CIOLIBEXPORTVAR char *ciolib_appname;
393 394
CIOLIBEXPORTVAR int ciolib_initial_window_height;
CIOLIBEXPORTVAR int ciolib_initial_window_width;
395 396 397 398 399 400

#define _conio_kbhit()		kbhit()

#ifdef __cplusplus
extern "C" {
#endif
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
CIOLIBEXPORT int initciolib(int mode);
CIOLIBEXPORT void suspendciolib(void);

CIOLIBEXPORT int ciolib_movetext(int sx, int sy, int ex, int ey, int dx, int dy);
CIOLIBEXPORT char * ciolib_cgets(char *str);
CIOLIBEXPORT int ciolib_cscanf (char *format , ...);
CIOLIBEXPORT int ciolib_kbhit(void);
CIOLIBEXPORT int ciolib_getch(void);
CIOLIBEXPORT int ciolib_getche(void);
CIOLIBEXPORT int ciolib_ungetch(int ch);
CIOLIBEXPORT void ciolib_gettextinfo(struct text_info *info);
CIOLIBEXPORT int ciolib_wherex(void);
CIOLIBEXPORT int ciolib_wherey(void);
CIOLIBEXPORT void ciolib_wscroll(void);
CIOLIBEXPORT void ciolib_gotoxy(int x, int y);
CIOLIBEXPORT void ciolib_clreol(void);
CIOLIBEXPORT void ciolib_clrscr(void);
Deucе's avatar
Deucе committed
418
CIOLIBEXPORT int ciolib_cputs(const char *str);
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
CIOLIBEXPORT int ciolib_cprintf(const char *fmat, ...);
CIOLIBEXPORT void ciolib_textbackground(int colour);
CIOLIBEXPORT void ciolib_textcolor(int colour);
CIOLIBEXPORT void ciolib_highvideo(void);
CIOLIBEXPORT void ciolib_lowvideo(void);
CIOLIBEXPORT void ciolib_normvideo(void);
CIOLIBEXPORT int ciolib_puttext(int a,int b,int c,int d,void *e);
CIOLIBEXPORT int ciolib_vmem_puttext(int a,int b,int c,int d,struct vmem_cell *e);
CIOLIBEXPORT int ciolib_gettext(int a,int b,int c,int d,void *e);
CIOLIBEXPORT int ciolib_vmem_gettext(int a,int b,int c,int d,struct vmem_cell *e);
CIOLIBEXPORT void ciolib_textattr(int a);
CIOLIBEXPORT void ciolib_delay(long a);
CIOLIBEXPORT int ciolib_putch(int a);
CIOLIBEXPORT void ciolib_setcursortype(int a);
CIOLIBEXPORT void ciolib_textmode(int mode);
CIOLIBEXPORT void ciolib_window(int sx, int sy, int ex, int ey);
CIOLIBEXPORT void ciolib_delline(void);
CIOLIBEXPORT void ciolib_insline(void);
CIOLIBEXPORT char * ciolib_getpass(const char *prompt);
CIOLIBEXPORT void ciolib_settitle(const char *title);
CIOLIBEXPORT void ciolib_setname(const char *title);
CIOLIBEXPORT void ciolib_seticon(const void *icon,unsigned long size);
CIOLIBEXPORT int ciolib_showmouse(void);
CIOLIBEXPORT int ciolib_hidemouse(void);
CIOLIBEXPORT int ciolib_mousepointeer(enum ciolib_mouse_ptr);
CIOLIBEXPORT void ciolib_copytext(const char *text, size_t buflen);
CIOLIBEXPORT char * ciolib_getcliptext(void);
CIOLIBEXPORT int ciolib_setfont(int font, int force, int font_num);
CIOLIBEXPORT int ciolib_getfont(int font_num);
CIOLIBEXPORT int ciolib_loadfont(char *filename);
CIOLIBEXPORT int ciolib_get_window_info(int *width, int *height, int *xpos, int *ypos);
CIOLIBEXPORT void ciolib_beep(void);
CIOLIBEXPORT void ciolib_getcustomcursor(int *startline, int *endline, int *range, int *blink, int *visible);
CIOLIBEXPORT void ciolib_setcustomcursor(int startline, int endline, int range, int blink, int visible);
CIOLIBEXPORT void ciolib_setvideoflags(int flags);
CIOLIBEXPORT int ciolib_getvideoflags(void);
CIOLIBEXPORT void ciolib_setscaling(int flags);
CIOLIBEXPORT int ciolib_getscaling(void);
CIOLIBEXPORT int ciolib_setpalette(uint32_t entry, uint16_t r, uint16_t g, uint16_t b);
CIOLIBEXPORT int ciolib_attr2palette(uint8_t attr, uint32_t *fg, uint32_t *bg);
CIOLIBEXPORT int ciolib_setpixel(uint32_t x, uint32_t y, uint32_t colour);
CIOLIBEXPORT struct ciolib_pixels * ciolib_getpixels(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, int force);
CIOLIBEXPORT int ciolib_setpixels(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, uint32_t x_off, uint32_t y_off, struct ciolib_pixels *pixels, void *mask);
CIOLIBEXPORT void ciolib_freepixels(struct ciolib_pixels *pixels);
CIOLIBEXPORT struct ciolib_screen * ciolib_savescreen(void);
CIOLIBEXPORT void ciolib_freescreen(struct ciolib_screen *);
CIOLIBEXPORT int ciolib_restorescreen(struct ciolib_screen *scrn);
CIOLIBEXPORT void ciolib_setcolour(uint32_t fg, uint32_t bg);
CIOLIBEXPORT int ciolib_get_modepalette(uint32_t[16]);
CIOLIBEXPORT int ciolib_set_modepalette(uint32_t[16]);
CIOLIBEXPORT uint32_t ciolib_map_rgb(uint16_t r, uint16_t g, uint16_t b);
CIOLIBEXPORT void ciolib_replace_font(uint8_t id, char *name, void *data, size_t size);
CIOLIBEXPORT int ciolib_attrfont(uint8_t attr);
CIOLIBEXPORT int ciolib_checkfont(int font_num);
CIOLIBEXPORT void ciolib_set_vmem(struct vmem_cell *cell, uint8_t ch, uint8_t attr, uint8_t font);
CIOLIBEXPORT void ciolib_set_vmem_attr(struct vmem_cell *cell, uint8_t attr);
CIOLIBEXPORT void ciolib_setwinsize(int width, int height);
CIOLIBEXPORT void ciolib_setwinposition(int x, int y);
CIOLIBEXPORT enum ciolib_codepage ciolib_getcodepage(void);
478 479

/* DoorWay specific stuff that's only applicable to ANSI mode. */
480
CIOLIBEXPORT void ansi_ciolib_setdoorway(int enable);
481 482 483 484 485 486 487 488 489 490 491 492
#ifdef __cplusplus
}
#endif

#ifndef CIOLIB_NO_MACROS
	#define cscanf					ciolib_cscanf
	#define cprintf					ciolib_cprintf

	#define movetext(a,b,c,d,e,f)	ciolib_movetext(a,b,c,d,e,f)
	#define cgets(a)				ciolib_cgets(a)
	#define kbhit()					ciolib_kbhit()
	#define getch()					ciolib_getch()
deuce's avatar
deuce committed
493
	#define getche()				ciolib_getche()
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
	#define ungetch(a)				ciolib_ungetch(a)
	#define gettextinfo(a)			ciolib_gettextinfo(a)
	#define wherex()				ciolib_wherex()
	#define wherey()				ciolib_wherey()
	#define	wscroll()				ciolib_wscroll()
	#define gotoxy(a,b)				ciolib_gotoxy(a,b)
	#define clreol()				ciolib_clreol()
	#define clrscr()				ciolib_clrscr()
	#define cputs(a)				ciolib_cputs(a)
	#define textbackground(a)		ciolib_textbackground(a)
	#define textcolor(a)			ciolib_textcolor(a)
	#define highvideo()				ciolib_highvideo()
	#define lowvideo()				ciolib_lowvideo()
	#define normvideo()				ciolib_normvideo()
	#define puttext(a,b,c,d,e)		ciolib_puttext(a,b,c,d,e)
509
	#define vmem_puttext(a,b,c,d,e)	ciolib_vmem_puttext(a,b,c,d,e)
510
	#define gettext(a,b,c,d,e)		ciolib_gettext(a,b,c,d,e)
511
	#define vmem_gettext(a,b,c,d,e)	ciolib_vmem_gettext(a,b,c,d,e)
512 513 514 515 516 517 518
	#define textattr(a)				ciolib_textattr(a)
	#define delay(a)				ciolib_delay(a)
	#define putch(a)				ciolib_putch(a)
	#define _setcursortype(a)		ciolib_setcursortype(a)
	#define textmode(a)				ciolib_textmode(a)
	#define window(a,b,c,d)			ciolib_window(a,b,c,d)
	#define delline()				ciolib_delline()
deuce's avatar
deuce committed
519 520 521
	#define insline()				ciolib_insline()
	#define getpass(a)				ciolib_getpass(a)
	#define getmouse(a)				ciolib_getmouse(a)
deuce's avatar
deuce committed
522
	#define ungetmouse(a)			ciolib_ungetmouse(a)
deuce's avatar
deuce committed
523 524
	#define	hidemouse()				ciolib_hidemouse()
	#define showmouse()				ciolib_showmouse()
525
	#define mousepointer(a)				ciolib_mousepointer(a)
526
	#define setname(a)				ciolib_setname(a)
527
	#define seticon(a,b)			ciolib_seticon(a,b)
528
	#define settitle(a)				ciolib_settitle(a)
deuce's avatar
deuce committed
529
	#define copytext(a,b)			ciolib_copytext(a,b)
530
	#define getcliptext()			ciolib_getcliptext()
531
	#define setfont(a,b,c)			ciolib_setfont(a,b,c)
532
	#define getfont(a)				ciolib_getfont(a)
533
	#define loadfont(a)				ciolib_loadfont(a)
534
	#define get_window_info(a,b,c,d)	ciolib_get_window_info(a,b,c,d)
deuce's avatar
deuce committed
535
	#define beep()				ciolib_beep()
536 537
	#define getcustomcursor(a,b,c,d,e)	ciolib_getcustomcursor(a,b,c,d,e)
	#define setcustomcursor(a,b,c,d,e)	ciolib_setcustomcursor(a,b,c,d,e)
538 539
	#define setvideoflags(a)		ciolib_setvideoflags(a)
	#define getvideoflags()			ciolib_getvideoflags()
540 541
	#define setscaling(a)			ciolib_setscaling(a)
	#define getscaling()			ciolib_getscaling()
542
	#define setpalette(e,r,g,b)		ciolib_setpalette(e,r,g,b)
543
	#define attr2palette(a,b,c)		ciolib_attr2palette(a,b,c)
deuce's avatar
deuce committed
544
	#define setpixel(a,b,c)			ciolib_setpixel(a,b,c)
545
	#define getpixels(a,b,c,d, e)		ciolib_getpixels(a,b,c,d, e)
deuce's avatar
deuce committed
546
	#define setpixels(a,b,c,d,e,f,g,h)	ciolib_setpixels(a,b,c,d,e,f,g,h)
547
	#define freepixels(a)			ciolib_freepixels(a)
deuce's avatar
deuce committed
548 549 550
	#define savescreen()			ciolib_savescreen()
	#define freescreen(a)			ciolib_freescreen(a)
	#define restorescreen(a)		ciolib_restorescreen(a)
551
	#define setcolour(a,b)			ciolib_setcolour(a,b)
deuce's avatar
deuce committed
552 553
	#define get_modepalette(a)		ciolib_get_modepalette(a)
	#define set_modepalette(a)		ciolib_set_modepalette(a)
554
	#define map_rgb(a,b,c)			ciolib_map_rgb(a,b,c)
555 556
	#define replace_font(a,b,c,d)	ciolib_replace_font(a,b,c,d)
	#define attrfont(a)				ciolib_attrfont(a)
557
	#define checkfont(a)			ciolib_checkfont(a)
558 559
	#define set_vmem(a, b, c, d)		ciolib_set_vmem(a, b, c, d)
	#define set_vmem_attr(a, b)		ciolib_set_vmem_attr(a, b)
deuce's avatar
deuce committed
560 561
	#define setwinsize(a,b)			ciolib_setwinsize(a,b)
	#define setwinposition(a,b)		ciolib_setwinposition(a,b)
562
	#define getcodepage()			ciolib_getcodepage()
563 564
#endif

deuce's avatar
deuce committed
565
#ifdef WITH_SDL
566
	#include <gen_defs.h>
deuce's avatar
deuce committed
567
	#include <SDL.h>
568

deuce's avatar
deuce committed
569
#if defined(_WIN32) || defined(__DARWIN__)
570 571 572 573 574
	#ifdef main
		#undef main
	#endif
	#define main	CIOLIB_main
#endif
deuce's avatar
deuce committed
575 576 577

#if defined(__DARWIN__)
	extern sem_t main_sem;
578 579
	extern sem_t startsdl_sem;
	extern int initsdl_ret;
deuce's avatar
deuce committed
580
#endif
deuce's avatar
deuce committed
581 582
#endif

583 584 585
#define CIOLIB_BUTTON_1	1
#define CIOLIB_BUTTON_2	2
#define CIOLIB_BUTTON_3	4
586 587
#define CIOLIB_BUTTON_4	8
#define CIOLIB_BUTTON_5	16
588 589 590 591

#define CIOLIB_BUTTON(x)	(1<<(x-1))

enum {
592
	 CIOLIB_MOUSE_MOVE			/* 0 */
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
	,CIOLIB_BUTTON_1_PRESS
	,CIOLIB_BUTTON_1_RELEASE
	,CIOLIB_BUTTON_1_CLICK
	,CIOLIB_BUTTON_1_DBL_CLICK
	,CIOLIB_BUTTON_1_TRPL_CLICK
	,CIOLIB_BUTTON_1_QUAD_CLICK
	,CIOLIB_BUTTON_1_DRAG_START
	,CIOLIB_BUTTON_1_DRAG_MOVE
	,CIOLIB_BUTTON_1_DRAG_END
	,CIOLIB_BUTTON_2_PRESS			/* 10 */
	,CIOLIB_BUTTON_2_RELEASE
	,CIOLIB_BUTTON_2_CLICK
	,CIOLIB_BUTTON_2_DBL_CLICK
	,CIOLIB_BUTTON_2_TRPL_CLICK
	,CIOLIB_BUTTON_2_QUAD_CLICK
	,CIOLIB_BUTTON_2_DRAG_START
	,CIOLIB_BUTTON_2_DRAG_MOVE
	,CIOLIB_BUTTON_2_DRAG_END
	,CIOLIB_BUTTON_3_PRESS
	,CIOLIB_BUTTON_3_RELEASE		/* 20 */
	,CIOLIB_BUTTON_3_CLICK
	,CIOLIB_BUTTON_3_DBL_CLICK
	,CIOLIB_BUTTON_3_TRPL_CLICK
	,CIOLIB_BUTTON_3_QUAD_CLICK
	,CIOLIB_BUTTON_3_DRAG_START
	,CIOLIB_BUTTON_3_DRAG_MOVE
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
	,CIOLIB_BUTTON_3_DRAG_END
	,CIOLIB_BUTTON_4_PRESS
	,CIOLIB_BUTTON_4_RELEASE
	,CIOLIB_BUTTON_4_CLICK			/* 30 */
	,CIOLIB_BUTTON_4_DBL_CLICK
	,CIOLIB_BUTTON_4_TRPL_CLICK
	,CIOLIB_BUTTON_4_QUAD_CLICK
	,CIOLIB_BUTTON_4_DRAG_START
	,CIOLIB_BUTTON_4_DRAG_MOVE
	,CIOLIB_BUTTON_4_DRAG_END
	,CIOLIB_BUTTON_5_PRESS
	,CIOLIB_BUTTON_5_RELEASE
	,CIOLIB_BUTTON_5_CLICK
	,CIOLIB_BUTTON_5_DBL_CLICK		/* 40 */
	,CIOLIB_BUTTON_5_TRPL_CLICK
	,CIOLIB_BUTTON_5_QUAD_CLICK
	,CIOLIB_BUTTON_5_DRAG_START
	,CIOLIB_BUTTON_5_DRAG_MOVE
	,CIOLIB_BUTTON_5_DRAG_END		/* 45 */
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
};

#define CIOLIB_BUTTON_PRESS(x)		((x-1)*9+1)
#define CIOLIB_BUTTON_RELEASE(x)	((x-1)*9+2)
#define CIOLIB_BUTTON_CLICK(x)		((x-1)*9+3)
#define CIOLIB_BUTTON_DBL_CLICK(x)	((x-1)*9+4)
#define CIOLIB_BUTTON_TRPL_CLICK(x)	((x-1)*9+5)
#define CIOLIB_BUTTON_QUAD_CLICK(x)	((x-1)*9+6)
#define CIOLIB_BUTTON_DRAG_START(x)	((x-1)*9+7)
#define CIOLIB_BUTTON_DRAG_MOVE(x)	((x-1)*9+8)
#define CIOLIB_BUTTON_DRAG_END(x)	((x-1)*9+9)

#define CIOLIB_BUTTON_NUMBER(x)		((x+8)/9)

#define CIOLIB_BUTTON_BASE(x)		(x!=CIOLIB_MOUSE_MOVE?x-9*(CIOLIB_BUTTON_NUMBER(x)-1):CIOLIB_MOUSE_MOVE)

extern int ciolib_mouse_initialized;

#ifdef __cplusplus
extern "C" {
#endif
659 660 661 662 663 664
CIOLIBEXPORT void ciomouse_gotevent(int event, int x, int y, int x_res, int y_res);
CIOLIBEXPORT int mouse_trywait(void);
CIOLIBEXPORT int mouse_wait(void);
CIOLIBEXPORT int mouse_pending(void);
CIOLIBEXPORT int ciolib_getmouse(struct mouse_event *mevent);
CIOLIBEXPORT int ciolib_ungetmouse(struct mouse_event *mevent);
665
CIOLIBEXPORT void ciolib_mouse_thread(void *data);
666 667 668 669 670 671 672 673
CIOLIBEXPORT uint64_t ciomouse_setevents(uint64_t events);
CIOLIBEXPORT uint64_t ciomouse_addevents(uint64_t events);
CIOLIBEXPORT uint64_t ciomouse_delevents(uint64_t events);
CIOLIBEXPORT uint64_t ciomouse_addevent(uint64_t event);
CIOLIBEXPORT uint64_t ciomouse_delevent(uint64_t event);
CIOLIBEXPORT uint32_t ciolib_mousepointer(enum ciolib_mouse_ptr type);
CIOLIBEXPORT void mousestate(int *x, int *y, uint8_t *buttons);
CIOLIBEXPORT void mousestate_res(int *x_res, int *y_res, uint8_t *buttons);
674 675 676 677
#ifdef __cplusplus
}
#endif

deuce's avatar
deuce committed
678
#define CIO_KEY_HOME      (0x47 << 8)
679
#define CIO_KEY_UP        (0x48 << 8)
deuce's avatar
deuce committed
680
#define CIO_KEY_END       (0x4f << 8)
681
#define CIO_KEY_DOWN      (0x50 << 8)
deuce's avatar
deuce committed
682 683 684
#define CIO_KEY_F(x)      ((x<11)?((0x3a+x) << 8):((0x7a+x) << 8))
#define CIO_KEY_IC        (0x52 << 8)
#define CIO_KEY_DC        (0x53 << 8)
685 686 687 688 689 690
#define CIO_KEY_SHIFT_IC  (0x05 << 8)	/* Shift-Insert */
#define CIO_KEY_SHIFT_DC  (0x07 << 8)	/* Shift-Delete */
#define CIO_KEY_CTRL_IC   (0x04 << 8)	/* Ctrl-Insert */
#define CIO_KEY_CTRL_DC   (0x06 << 8)	/* Ctrl-Delete */
#define CIO_KEY_ALT_IC    (0xA2 << 8)	/* Alt-Insert */
#define CIO_KEY_ALT_DC    (0xA3 << 8)	/* Alt-Delete */
deuce's avatar
deuce committed
691 692 693 694
#define CIO_KEY_LEFT      (0x4b << 8)
#define CIO_KEY_RIGHT     (0x4d << 8)
#define CIO_KEY_PPAGE     (0x49 << 8)
#define CIO_KEY_NPAGE     (0x51 << 8)
deuce's avatar
deuce committed
695 696 697
#define CIO_KEY_SHIFT_F(x)((x<11)?((0x53 + x) << 8):((0x7c + x) << 8))
#define CIO_KEY_CTRL_F(x) ((x<11)?((0x5d + x) << 8):((0x7e + x) << 8))
#define CIO_KEY_ALT_F(x)  ((x<11)?((0x67 + x) << 8):((0x80 + x) << 8))
698
#define CIO_KEY_BACKTAB   (0x0f << 8)
deuce's avatar
deuce committed
699

700 701
#define CIO_KEY_MOUSE     0x7dE0	// This is the right mouse on Schneider/Amstrad PC1512 PC keyboards "F-14"
#define CIO_KEY_QUIT	  0x7eE0	// "F-15"
deuce's avatar
deuce committed
702 703
#define CIO_KEY_ABORTED   0x01E0	// ESC key by scancode

704
#endif	/* Do not add anything after this line */