/*
	tsrlib.H

	Copyright (C) 1993, Geoff Friesen B.Sc.
	All rights reserved.
*/

#pragma inline

#include <ctype.H>
#include <dir.H>
#include <dos.H>
#include <fcntl.H>
#include <io.H>
#include <stdio.H>
#include <stdlib.H>
#include <string.H>

#undef isalnum
#undef isalpha
#undef isdigit
#undef islower
#undef isspace
#undef isupper
#undef isxdigit

#define	NUL	0x0000
#define	BS	0x0008
#define	TAB	0x0009
#define	LF	0x000a
#define	FF	0x000c
#define	CR	0x000d
#define	RET	0x000d
#define	ESC	0x001b
#define	STAB	0x0f00
#define	ALTA	0x1e00
#define	ALTB	0x3000
#define	ALTC	0x2e00
#define	ALTD	0x2000
#define	ALTE	0x1200
#define	ALTF	0x2100
#define	ALTG	0x2200
#define	ALTH	0x2300
#define	ALTI	0x1700
#define	ALTJ	0x2400
#define	ALTK	0x2500
#define	ALTL	0x2600
#define	ALTM	0x3200
#define	ALTN	0x3100
#define	ALTO	0x1800
#define	ALTP	0x1900
#define	ALTQ	0x1000
#define	ALTR	0x1300
#define	ALTS	0x1f00
#define	ALTT	0x1400
#define	ALTU	0x1600
#define	ALTV	0x2f00
#define	ALTW	0x1100
#define	ALTX	0x2d00
#define	ALTY	0x1500
#define	ALTZ	0x2c00
#define	F1	0x3b00
#define	F2	0x3c00
#define	F3	0x3d00
#define	F4	0x3e00
#define	F5	0x3f00
#define	F6	0x4000
#define	F7	0x4100
#define	F8	0x4200
#define	F9	0x4300
#define	F10	0x4400
#define	HOME	0x4700
#define	UP	0x4800
#define	PGUP	0x4900
#define LEFT	0x4b00
#define	RIGHT	0x4d00
#define	END	0x4f00
#define	DOWN	0x5000
#define	PGDN	0x5100
#define	INS	0x5200
#define	DEL	0x5300

#define	MDA		0
#define	CGA		1
#define	EGA_BW		2
#define	EGA_COLOR	3
#define	VGA_BW		4
#define	VGA_COLOR	5

#define	BW80		2
#define	C80		3
#define	MONO		7

#define	BLACK		0
#define	BLUE		1
#define	GREEN		2
#define	CYAN		3
#define	RED		4
#define	MAGENTA		5
#define	BROWN		6
#define	LIGHTGRAY	7

#define	DARKGRAY	8
#define	LIGHTBLUE	9
#define	LIGHTGREEN	10
#define	LIGHTCYAN	11
#define	LIGHTRED	12
#define	LIGHTMAGENTA	13
#define	YELLOW		14
#define	WHITE		15

#define	BLINK		128

#define	SINGLE_LINE	0
#define	DOUBLE_LINE	1
#define	BLOCK_LINE	2
#define	NOBORDER	3

#define	SCREEN_SAVE	0
#define	SCREEN_RESTORE	1

#define	SCROLL_UP	0
#define	SCROLL_DN	1

#define	center(x, y)	((((x)-(y))>>1)+1)

#define	v_clear(a,b,c,d)	v_paint (' ', (a), (b), (c), (d))

#define	VIDEO_INT	asm { \
				push bp; \
				int 10h; \
				pop bp; \
			}

int	pascal format	(void (*func) (int), const char *fmt, void *ap);
int	getstr		(char *buffer, unsigned char maxlen);
int	isleap		(int year);
char *	_itoa		(int value, char *string);
int	k_fetch		(void);
int	k_iskey		(void);
char *	_ltoa		(long value, char *string);
void	memswap		(void *addr1, void *addr2, size_t n);
int	sprintf		(char *buffer, const char *fmt, ...);
void	update_cursor	(void);
int	v_aa		(void);
void	v_border	(int style, int x, int y, int nx, int ny);
int	v_cprintf	(const char *fmt, ...);
int	v_cputs		(const char *str);
int	v_getattr	(void);
int	v_getmode	(void);
int	v_getshape	(void);
void	v_gotoxy	(int x, int y);
void	v_paint		(int c, int x, int y, int nx, int ny);
int	v_putch		(int c, int count);
void	v_screen	(int cmd, int x, int y, int nx, int ny,
			 void *buffer);
void	v_scroll	(int x, int y, int nx, int ny, int dir,
			 int nblines, int attr);
void	v_setattr	(int attr);
void	v_setshape	(int shape);
void	v_shadow	(int x1, int y1, int nx, int ny);
int	v_wherex	(void);
int	v_wherey	(void);

/* ------------------- */
/* Resident Kernel API */
/* ------------------- */

void	beep		(void);
void	nosound		(void);
void	pause		(unsigned ticks);
void	sound		(unsigned frequency);

typedef struct
	{
	   long length;
	   unsigned srchandle;
	   long srcoffset;
	   unsigned desthandle;
	   long destoffset;
	}
	EMMS;		/* Extended Memory Move Structure */

int	XMS_Alloc	(unsigned nkilos);
int	XMS_Copy	(EMMS *x);
int	XMS_Exists	(void);
int	XMS_Free	(unsigned handle);
long	XMS_Lock	(unsigned handle);
int	XMS_Query	(unsigned *nkilos, unsigned *maxblocksize);
int	XMS_Realloc	(unsigned handle, unsigned nkilos);
int	XMS_Unlock	(unsigned handle);

/* ----------------------- */
/* Installation Kernel API */
/* ----------------------- */

int	cleanup		(void);
int	parse		(void);
void	setcseg		(void);
void	setrseg		(void);
int	setup		(void);
void	skipws		(void);
void	unparse		(void);
int	xparse		(int option);