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.8 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
	/* New modes we've added because DigitalMan bitched for DAYS! */
	LCD80X25,

193 194 195
	/* Cruft... */

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

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

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

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

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

#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
244
CIOLIBEXPORTVAR struct text_info cio_textinfo;
245 246
CIOLIBEXPORTVAR uint32_t ciolib_fg;
CIOLIBEXPORTVAR uint32_t ciolib_bg;
247

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

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

deuce's avatar
deuce committed
270
CIOLIBEXPORTVAR struct conio_font_data_struct conio_fontdata[257];
deuce's avatar
deuce committed
271

deuce's avatar
deuce committed
272 273
struct ciolib_pixels {
	uint32_t	*pixels;
274
	uint32_t	*pixelsb;
deuce's avatar
deuce committed
275 276 277 278
	uint32_t	width;
	uint32_t	height;
};

279 280 281 282 283 284 285 286
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
287
struct ciolib_screen {
288 289
	uint32_t		fg_colour;
	uint32_t		bg_colour;
290 291
	int			flags;
	int			fonts[5];
deuce's avatar
deuce committed
292
	struct ciolib_pixels	*pixels;
293
	struct vmem_cell	*vmem;
deuce's avatar
deuce committed
294
	struct text_info	text_info;
295
	uint32_t		palette[16];
deuce's avatar
deuce committed
296 297
};

298
#define CONIO_FIRST_FREE_FONT	43
deuce's avatar
deuce committed
299

300 301
typedef struct {
	int		mode;
deuce's avatar
deuce committed
302
	int		mouse;
303 304 305 306 307 308 309 310 311 312 313 314 315
	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
316
#define CONIO_OPT_BLOCKY_SCALING	4096
317
	void	(*clreol)		(void);
318
	int		(*puttext)		(int,int,int,int,void *);
319
	int		(*vmem_puttext)		(int,int,int,int,struct vmem_cell *);
320
	int		(*gettext)		(int,int,int,int,void *);
321
	int		(*vmem_gettext)		(int,int,int,int,struct vmem_cell *);
322
	void	(*textattr)		(int);
323 324 325 326
	int		(*kbhit)		(void);
	void	(*delay)		(long);
	int		(*wherex)		(void);
	int		(*wherey)		(void);
327
	int		(*putch)		(int);
328 329 330 331 332 333
	void	(*gotoxy)		(int,int);
	void	(*clrscr)		(void);
	void	(*gettextinfo)	(struct text_info *);
	void	(*setcursortype)(int);
	int		(*getch)		(void);
	int		(*getche)		(void);
334
	void	(*beep)			(void);
335 336 337 338 339 340 341 342 343 344 345 346 347
	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
348
	int		(*cprintf)		(const char *,...);
Deucе's avatar
Deucе committed
349
	int		(*cputs)		(const char *);
350 351
	void	(*textbackground)	(int);
	void	(*textcolor)	(int);
deuce's avatar
deuce committed
352
	int		(*getmouse)		(struct mouse_event *mevent);
deuce's avatar
deuce committed
353
	int		(*ungetmouse)	(struct mouse_event *mevent);
deuce's avatar
deuce committed
354 355
	int		(*hidemouse)	(void);
	int		(*showmouse)	(void);
356
	int		(*mousepointer)	(enum ciolib_mouse_ptr);
357
	void	(*settitle)		(const char *);
358
	void	(*setname)		(const char *);
359
	void	(*seticon)		(const void *, unsigned long);
deuce's avatar
deuce committed
360 361
	void	(*copytext)		(const char *, size_t);
	char 	*(*getcliptext)	(void);
362 363
	void	(*suspend)		(void);
	void	(*resume)		(void);
364
	int		(*setfont)		(int font, int force, int font_num);
365
	int		(*getfont)		(int font_num);
366
	int		(*loadfont)		(char *filename);
367
	int		(*get_window_info)		(int* width, int* height, int* xpos, int* ypos);
368 369
	void	(*getcustomcursor)	(int *startline, int *endline, int *range, int *blink, int *visible);
	void	(*setcustomcursor)	(int startline, int endline, int range, int blink, int visible);
370
	void	(*setvideoflags)	(int flags);
deuce's avatar
deuce committed
371
	int		(*getvideoflags)	(void);
372 373
	void	(*setscaling)	(int new_value);
	int		(*getscaling)	(void);
374
	int		*escdelay;
375
	int		(*setpalette)	(uint32_t entry, uint16_t r, uint16_t g, uint16_t b);
376
	int		(*attr2palette)	(uint8_t attr, uint32_t *fg, uint32_t *bg);
deuce's avatar
deuce committed
377
	int		(*setpixel)	(uint32_t x, uint32_t y, uint32_t colour);
378
	struct ciolib_pixels *(*getpixels)(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, int force);
deuce's avatar
deuce committed
379
	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);
380
	int 	(*get_modepalette)(uint32_t[16]);
deuce's avatar
deuce committed
381
	int	(*set_modepalette)(uint32_t[16]);
382
	uint32_t	(*map_rgb)(uint16_t r, uint16_t g, uint16_t b);
383
	void	(*replace_font)(uint8_t id, char *name, void *data, size_t size);
384
	int	(*checkfont)(int font_num);
deuce's avatar
deuce committed
385 386
	void	(*setwinsize)	(int width, int height);
	void	(*setwinposition)	(int x, int y);
387 388
} cioapi_t;

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

#define _conio_kbhit()		kbhit()

#ifdef __cplusplus
extern "C" {
#endif
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
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
421
CIOLIBEXPORT int ciolib_cputs(const char *str);
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 478 479 480
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);
481 482

/* DoorWay specific stuff that's only applicable to ANSI mode. */
483
CIOLIBEXPORT void ansi_ciolib_setdoorway(int enable);
484 485 486 487 488 489 490 491 492 493 494 495
#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
496
	#define getche()				ciolib_getche()
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
	#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)
512
	#define vmem_puttext(a,b,c,d,e)	ciolib_vmem_puttext(a,b,c,d,e)
513
	#define gettext(a,b,c,d,e)		ciolib_gettext(a,b,c,d,e)
514
	#define vmem_gettext(a,b,c,d,e)	ciolib_vmem_gettext(a,b,c,d,e)
515 516 517 518 519 520 521
	#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
522 523 524
	#define insline()				ciolib_insline()
	#define getpass(a)				ciolib_getpass(a)
	#define getmouse(a)				ciolib_getmouse(a)
deuce's avatar
deuce committed
525
	#define ungetmouse(a)			ciolib_ungetmouse(a)
deuce's avatar
deuce committed
526 527
	#define	hidemouse()				ciolib_hidemouse()
	#define showmouse()				ciolib_showmouse()
528
	#define mousepointer(a)				ciolib_mousepointer(a)
529
	#define setname(a)				ciolib_setname(a)
530
	#define seticon(a,b)			ciolib_seticon(a,b)
531
	#define settitle(a)				ciolib_settitle(a)
deuce's avatar
deuce committed
532
	#define copytext(a,b)			ciolib_copytext(a,b)
533
	#define getcliptext()			ciolib_getcliptext()
534
	#define setfont(a,b,c)			ciolib_setfont(a,b,c)
535
	#define getfont(a)				ciolib_getfont(a)
536
	#define loadfont(a)				ciolib_loadfont(a)
537
	#define get_window_info(a,b,c,d)	ciolib_get_window_info(a,b,c,d)
deuce's avatar
deuce committed
538
	#define beep()				ciolib_beep()
539 540
	#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)
541 542
	#define setvideoflags(a)		ciolib_setvideoflags(a)
	#define getvideoflags()			ciolib_getvideoflags()
543 544
	#define setscaling(a)			ciolib_setscaling(a)
	#define getscaling()			ciolib_getscaling()
545
	#define setpalette(e,r,g,b)		ciolib_setpalette(e,r,g,b)
546
	#define attr2palette(a,b,c)		ciolib_attr2palette(a,b,c)
deuce's avatar
deuce committed
547
	#define setpixel(a,b,c)			ciolib_setpixel(a,b,c)
548
	#define getpixels(a,b,c,d, e)		ciolib_getpixels(a,b,c,d, e)
deuce's avatar
deuce committed
549
	#define setpixels(a,b,c,d,e,f,g,h)	ciolib_setpixels(a,b,c,d,e,f,g,h)
550
	#define freepixels(a)			ciolib_freepixels(a)
deuce's avatar
deuce committed
551 552 553
	#define savescreen()			ciolib_savescreen()
	#define freescreen(a)			ciolib_freescreen(a)
	#define restorescreen(a)		ciolib_restorescreen(a)
554
	#define setcolour(a,b)			ciolib_setcolour(a,b)
deuce's avatar
deuce committed
555 556
	#define get_modepalette(a)		ciolib_get_modepalette(a)
	#define set_modepalette(a)		ciolib_set_modepalette(a)
557
	#define map_rgb(a,b,c)			ciolib_map_rgb(a,b,c)
558 559
	#define replace_font(a,b,c,d)	ciolib_replace_font(a,b,c,d)
	#define attrfont(a)				ciolib_attrfont(a)
560
	#define checkfont(a)			ciolib_checkfont(a)
561 562
	#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
563 564
	#define setwinsize(a,b)			ciolib_setwinsize(a,b)
	#define setwinposition(a,b)		ciolib_setwinposition(a,b)
565
	#define getcodepage()			ciolib_getcodepage()
566 567
#endif

deuce's avatar
deuce committed
568
#ifdef WITH_SDL
569
	#include <gen_defs.h>
deuce's avatar
deuce committed
570
	#include <SDL.h>
571

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

#if defined(__DARWIN__)
	extern sem_t main_sem;
581 582
	extern sem_t startsdl_sem;
	extern int initsdl_ret;
deuce's avatar
deuce committed
583
#endif
deuce's avatar
deuce committed
584 585
#endif

586 587 588
#define CIOLIB_BUTTON_1	1
#define CIOLIB_BUTTON_2	2
#define CIOLIB_BUTTON_3	4
589 590
#define CIOLIB_BUTTON_4	8
#define CIOLIB_BUTTON_5	16
591 592 593 594

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

enum {
595
	 CIOLIB_MOUSE_MOVE			/* 0 */
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
	,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
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
	,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 */
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
};

#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
662 663 664 665 666 667
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);
668
CIOLIBEXPORT void ciolib_mouse_thread(void *data);
669 670 671 672 673 674 675 676
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);
677 678 679 680
#ifdef __cplusplus
}
#endif

deuce's avatar
deuce committed
681
#define CIO_KEY_HOME      (0x47 << 8)
682
#define CIO_KEY_UP        (0x48 << 8)
deuce's avatar
deuce committed
683
#define CIO_KEY_END       (0x4f << 8)
684
#define CIO_KEY_DOWN      (0x50 << 8)
deuce's avatar
deuce committed
685 686 687
#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)
688 689 690 691 692 693
#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
694 695 696 697
#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
698 699 700
#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))
701
#define CIO_KEY_BACKTAB   (0x0f << 8)
deuce's avatar
deuce committed
702

703 704
#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
705 706
#define CIO_KEY_ABORTED   0x01E0	// ESC key by scancode

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