ciolib.h 24.5 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
#ifdef CIOLIBEXPORT
        #undef CIOLIBEXPORT
#endif

#ifdef _WIN32
        #ifdef __BORLANDC__
50
                #define CIOLIBCALL
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        #else
                #define CIOLIBCALL
        #endif
        #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 CIOLIBCALL
        #define CIOLIBEXPORT
69
        #define CIOLIBEXPORTVAR	extern
70
71
72
#else
        #define CIOLIBCALL
        #define CIOLIBEXPORT
73
        #define CIOLIBEXPORTVAR	extern
74
75
#endif

76
enum {
77
78
79
	 CIOLIB_MODE_AUTO
	,CIOLIB_MODE_CURSES
	,CIOLIB_MODE_CURSES_IBM
80
	,CIOLIB_MODE_CURSES_ASCII
81
82
83
	,CIOLIB_MODE_ANSI
	,CIOLIB_MODE_X
	,CIOLIB_MODE_CONIO
84
	,CIOLIB_MODE_CONIO_FULLSCREEN
85
	,CIOLIB_MODE_SDL
86
	,CIOLIB_MODE_SDL_FULLSCREEN
87
88
};

89
90
91
92
93
enum ciolib_mouse_ptr {
	 CIOLIB_MOUSEPTR_ARROW
	,CIOLIB_MOUSEPTR_BAR
};

deuce's avatar
deuce committed
94
#if defined(_WIN32)	/* presumably, Win32 */
95
96
97

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

deuce's avatar
deuce committed
98
#endif
99

100
101
102
#ifndef __COLORS
#define __COLORS

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
enum {
	 BLACK
	,BLUE
	,GREEN
	,CYAN
	,RED
	,MAGENTA
	,BROWN	
	,LIGHTGRAY	
	,DARKGRAY
	,LIGHTBLUE	
	,LIGHTGREEN	
	,LIGHTCYAN
	,LIGHTRED
	,LIGHTMAGENTA
	,YELLOW
	,WHITE
};
121
122
123
124

#endif	/* __COLORS */

#ifndef BLINK
125
#define BLINK 128
126
#endif
127

128
129
130
131
132
#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
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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,
157
    C80X30,
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
    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,
185
    MONO60,		// 38
186

187
188
189
190
191
192
193
194
	/* New modes we've added 'cause they're cool */

	ST132X37_16_9,
	ST132X52_5_4,

	/* Cruft... */

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

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

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

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

	/* Custom Mode */
216
	CIOLIB_MODE_CUSTOM = 255,	// Last mode... if it's over 255, text_info can't hold it.
217
};
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

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

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

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

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

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

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

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

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

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

#define _conio_kbhit()		kbhit()

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

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

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

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

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

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

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

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

enum {
593
	 CIOLIB_MOUSE_MOVE			/* 0 */
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
619
	,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
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
	,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 */
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
};

#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
660
CIOLIBEXPORT void CIOLIBCALL ciomouse_gotevent(int event, int x, int y, int x_res, int y_res);
deuce's avatar
deuce committed
661
662
663
664
665
CIOLIBEXPORT int CIOLIBCALL mouse_trywait(void);
CIOLIBEXPORT int CIOLIBCALL mouse_wait(void);
CIOLIBEXPORT int CIOLIBCALL mouse_pending(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_getmouse(struct mouse_event *mevent);
CIOLIBEXPORT int CIOLIBCALL ciolib_ungetmouse(struct mouse_event *mevent);
666
CIOLIBEXPORT void ciolib_mouse_thread(void *data);
667
668
669
670
671
CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_setevents(uint64_t events);
CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_addevents(uint64_t events);
CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_delevents(uint64_t events);
CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_addevent(uint64_t event);
CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_delevent(uint64_t event);
672
CIOLIBEXPORT uint32_t CIOLIBCALL ciolib_mousepointer(enum ciolib_mouse_ptr type);
673
674
CIOLIBEXPORT void CIOLIBCALL mousestate(int *x, int *y, uint8_t *buttons);
CIOLIBEXPORT void CIOLIBCALL mousestate_res(int *x_res, int *y_res, uint8_t *buttons);
675
676
677
678
#ifdef __cplusplus
}
#endif

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

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

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