//	ＤＯＳＣＡＬＬ　ダイレクトコール関数
//		Copyright (C) 1996 by AIG-SOFT
//	実はＧＣＣのDOSCALLに対応させるためDOSCALL.Hを変更したもの。
//	関数の実体のアドレスを使う時はdoslib.hを使うこと。
//	（このヘッダーを使うとDOSCALLが直接展開されるため、関数に実体がないから）

#ifdef	__DOSLIB_H
/* 先にDOSLIB.Hがインクルードされている時は有効にしない */
#define	___AIG_DOSLIBM___	1
#endif

#ifndef	___AIG_DOSLIBM___
#define	___AIG_DOSLIBM___	1
#define	__DOSLIB_H		/* DOSLIB.Hもインクルードしたことにする */

#include "deftype.h"

#ifndef __GNUC__
	// XCのときはDOSLIB.Hへ
	#include "doslib.h"
#else
// GCCでのみ有効
#include	"dosclass.h"
#ifdef	__cplusplus
extern	"C" {
#endif
// プロトタイプのみ有効
// ここにある関数はライブラリを使わずに直接コールするコードが出来る
//								//**の関数はテストしていない
// #defineで定義している関数は、引数がDOSCALLと異なるものだけプロトタイプ宣言を別に行う
DOSCALL	volatile void	EXIT(void);
DOSCALL	int	GETCHAR(void);
DOSCALL	void	PUTCHAR(short);
DOSCALL	int	COMINP(void);					//**
DOSCALL	void	COMOUT(short);					//**
DOSCALL	void	PRNOUT(short);					//**
DOSCALL	int	INPOUT(short);					//**
DOSCALL	int	INKEY(void);
DOSCALL	int	GETC(void);
DOSCALL	void	PRINT(unchar *);
DOSCALL	int	GETS(_INPPTR *);
DOSCALL	int	KEYSNS(void);
DOSCALL	int	KFLUSH(short);					//**
DOSCALL	int	KFLUSH_2W(short,short);				//**
DOSCALL	int	KFLUSH_2L(short,unchar *);			//**
	int	KFLUSHGP(void);
	int	KFLUSHIO(short);
	int	KFLUSHIN(void);
	int	KFLUSHGC(void);
	int	KFLUSHGS(unchar *);
#define		KFLUSHGP()	KFLUSH(1)			/**/
#define		KFLUSHIO(c)	KFLUSH_2W(6,c)			/**/
#define		KFLUSHIN()	KFLUSH(7)			/**/
#define		KFLUSHGC()	KFLUSH(8)			/**/
#define		KFLUSHGS(c)	KFLUSH_2L(10,c)			/**/
DOSCALL	void	FFLUSH(void);					//**
DOSCALL	int	CHGDRV(short);
DOSCALL	int	DRVCTRL_M(unshort);
	int	DRVCTRL(short,short);
#define		DRVCTRL(md,drv)	DRVCTRL_M(((md)<<8)|(drv))
DOSCALL	int	CONSNS(void);					//**
DOSCALL	int	PRNSNS(void);					//**
DOSCALL	int	CINSNS(void);					//**
DOSCALL	int	COUTSNS(void);					//**
DOSCALL	int	FATCHK(unchar *, unshort *);			//**
DOSCALL	int	FATCHK_B(unchar *, unshort *, short);		//**
#define		FATCHK2(a, b, c)	\
({	void	*bb=(b);		\
	bb+=0x80000000; 		\
	(FATCHK_B(a,(unshort *)bb,c));	\
})
DOSCALL	int	HENDSP(short);					//**
DOSCALL	int	HENDSP_2(short,short);				//**
DOSCALL	int	HENDSP_3(short,short,unchar *);			//**
	int	HENDSPMO(void);
	int	HENDSPMP(short,unchar *);
	int	HENDSPMR(short,unchar *);
	void	HENDSPMC(void);
	int	HENDSPIO(void);
	int	HENDSPIP(short,unchar *);
	int	HENDSPIR(short,unchar *);
	void	HENDSPIC(short);
	int	HENDSPSO(void);
	int	HENDSPSP(short,unchar *);
	int	HENDSPSR(short,unchar *);
	void	HENDSPSC(void);
#define		HENDSPMO()	HENDSP(0)			/**/
#define		HENDSPMP(b,c)	HENDSP_3(1,b,c)			/**/
#define		HENDSPMR(b,c)	HENDSP_3(2,b,c)			/**/
#define		HENDSPMC()	HENDSP(3)			/**/
#define		HENDSPIO()	HENDSP(4)			/**/
#define		HENDSPIP(b,c)	HENDSP_3(5,b,c)			/**/
#define		HENDSPIR(b,c)	HENDSP_3(6,b,c)			/**/
#define		HENDSPIC(a)	HENDSP_2(7,a)			/**/
#define		HENDSPSO()	HENDSP(8)			/**/
#define		HENDSPSP(b,c)	HENDSP_3(9,b,c)			/**/
#define		HENDSPSR(b,c)	HENDSP_3(10,b,c)		/**/
#define		HENDSPSC()	HENDSP(11)			/**/
DOSCALL	int	CURDRV(void);
DOSCALL	int	GETSS(_INPPTR *);
DOSCALL	int	FGETC(short);
DOSCALL	int	FGETS(_INPPTR *, short);
DOSCALL	void	FPUTC(short, short);
DOSCALL	void	FPUTS(unchar *, short);
DOSCALL	void	ALLCLOSE(void);
DOSCALL	int	SUPER(int);
DOSCALL	void	FNCKEY(short,unchar *);
#define		FNCKEYGT(fno,buf)	FNCKEY((short)((unchar)(fno)),buf)
#define		FNCKEYST(fno,buf)	FNCKEY((short)((unchar)(fno)|0x100),buf)
DOSCALL	int	CONCTRL(short);					//**
DOSCALL	int	CONCTRL_2(short,short);
DOSCALL	int	CONCTRL_2L(short,unchar *);
DOSCALL	int	CONCTRL_3(short,short,short);
	int	C_PUTC(short);
	int	C_PRINT(unchar *);
	int	C_COLOR(short);
	int	C_LOCATE(short, short);
	int	C_DOWN_S(void);
	int	C_UP_S(void);
	int	C_UP(short);
	int	C_DOWN(short);
	int	C_RIGHT(short);
	int	C_LEFT(short);
	int	C_CLS_ED(void);
	int	C_CLS_ST(void);
	int	C_CLS_AL(void);
	int	C_ERA_ED(void);
	int	C_ERA_ST(void);
	int	C_ERA_AL(void);
	int	C_INS(short);
	int	C_DEL(short);
	int	C_FNKMOD(short);
	int	C_WINDOW(short, short);
	int	C_WIDTH(short);
	int	C_CURON(void);
	int	C_CUROFF(void);
#define		C_PUTC(c)	CONCTRL_2(0,c)
#define		C_PRINT(s)	CONCTRL_2L(1,s)
#define		C_COLOR(c)	CONCTRL_2(2,c)
#define		C_LOCATE(x,y)	CONCTRL_3(3,x,y)
#define		C_DOWN_S()	CONCTRL(4)			/**/
#define		C_UP_S()	CONCTRL(5)			/**/
#define		C_UP(c)		CONCTRL_2(6,c)			/**/
#define		C_DOWN(c)	CONCTRL_2(7,c)			/**/
#define		C_RIGHT(c)	CONCTRL_2(8,c)			/**/
#define		C_LEFT(c)	CONCTRL_2(9,c)			/**/
#define		C_CLS_ED()	CONCTRL_2(10,0)			/**/
#define		C_CLS_ST()	CONCTRL_2(10,1)			/**/
#define		C_CLS_AL()	CONCTRL_2(10,2)			/**/
#define		C_ERA_ED()	CONCTRL_2(11,0)			/**/
#define		C_ERA_ST()	CONCTRL_2(11,1)			/**/
#define		C_ERA_AL()	CONCTRL_2(11,2)			/**/
#define		C_INS(c)	CONCTRL_2(12,c)			/**/
#define		C_DEL(c)	CONCTRL_2(13,c)			/**/
#define		C_FNKMOD(c)	CONCTRL_2(14,c)			/**/
#define		C_WINDOW(x,y)	CONCTRL_3(15,x,y)		/**/
#define		C_WIDTH(c)	CONCTRL_2(16,c)			/**/
#define		C_CURON()	CONCTRL(0x11)			/**/
#define		C_CUROFF()	CONCTRL(0x12)			/**/
DOSCALL	int	KEYCTRL(short);
DOSCALL	int	KEYCTRL_2(short,short);
	int	K_KEYINP(void);
	int	K_KEYSNS(void);
	int	K_SFTSNS(void);
	int	K_KEYBIT(short);
	int	K_INSMOD(short);
#define		K_KEYINP()	KEYCTRL(0)
#define		K_KEYSNS()	KEYCTRL(1)
#define		K_SFTSNS()	KEYCTRL(2)
#define		K_KEYBIT(c)	KEYCTRL_2(3,c)		/*??*/
#define		K_INSMOD(c)	KEYCTRL_2(4,c)
DOSCALL	int	INTVCS(short, char *);				//**
DOSCALL	void	PSPSET(_PDBADR *);			// 非常に危険な関数。使い方が不明。
DOSCALL	int	GETTIM2(void);
DOSCALL	int	SETTIM2(int);					//**
DOSCALL	int	NAMESTS(unchar*, _NAMESTBUF *);
DOSCALL	int	GETDATE(void);
DOSCALL	int	SETDATE(short);					//**
DOSCALL	int	GETTIME(void);
DOSCALL	int	SETTIME(short);					//**
DOSCALL	void	VERIFY(short);
DOSCALL	int	DUP0(short, short);				//**
DOSCALL	int	VERNUM(void);
DOSCALL	volatile void	KEEPPR(int, short);			//**
DOSCALL	int	GETDPB(short, _DPBPTR *);
DOSCALL	int	BREAKCK(short);
DOSCALL	void	DRVXCHG(short, short);
DOSCALL	int	INTVCG(short);					//**
DOSCALL	int	DSKFRE(short, _FREEINF *);
DOSCALL	int	NAMECK(unchar*, _NAMECKBUF *);
DOSCALL	int	MKDIR(unchar *);
DOSCALL	int	RMDIR(unchar *);
DOSCALL	int	CHDIR(unchar *);
DOSCALL	int	CREATE(unchar *, int);
DOSCALL	int	OPEN(unchar *, short);
DOSCALL	int	CLOSE(short);
DOSCALL	int	READ(short, unchar *, int);
DOSCALL	int	WRITE(short, unchar *, int);
DOSCALL	int	DELETE(unchar *);
DOSCALL	int	SEEK(short, int, short);
DOSCALL	int	CHMOD(unchar *, short);
DOSCALL	int	IOCTRL(short);					//**
DOSCALL	int	IOCTRL_2(short,short);				//**
DOSCALL	int	IOCTRL_3(short,short,short);			//**
DOSCALL	int	IOCTRL_4(short,short,unchar *,long);		//**
DOSCALL	int	IOCTRL_4L(short,short,short,unchar *);		//**
	int	IOCTRLGT(short);
	int	IOCTRLST(short, short);
	int	IOCTRLRH(short, unchar *, long);
	int	IOCTRLWH(short, unchar *, long);
	int	IOCTRLRD(short, unchar *, long);
	int	IOCTRLWD(short, unchar *, long);
	int	IOCTRLIS(short);
	int	IOCTRLOS(short);
	int	IOCTRLDVGT(short);
	int	IOCTRLFDGT(short);
	int	IOCTRLRTSET(short, short);
	int	IOCTRLDVCTL(short, short, unchar *);
	int	IOCTRLFDCTL(short, short, unchar *);
#define		IOCTRLGT(a)		IOCTRL_2(0,a)		/**/
#define		IOCTRLST(a,b)		IOCTRL_3(1,a,b)		/**/
#define		IOCTRLRH(a,b,c)		IOCTRL_4(2,a,b,c)	/**/
#define		IOCTRLWH(a,b,c)		IOCTRL_4(3,a,b,c)	/**/
#define		IOCTRLRD(a,b,c)		IOCTRL_4(4,a,b,c)	/**/
#define		IOCTRLWD(a,b,c)		IOCTRL_4(5,a,b,c)	/**/
#define		IOCTRLIS(a)		IOCTRL_2(6,a)		/**/
#define		IOCTRLOS(a)		IOCTRL_2(7,a)		/**/
#define		IOCTRLDVGT(a)		IOCTRL_2(9,a)		/**/
#define		IOCTRLFDGT(a)		IOCTRL_2(10,a)		/**/
#define		IOCTRLRTSET(a,b)	IOCTRL_3(11,a,b)	/**/
#define		IOCTRLDVCTL(a,b,c)	IOCTRL_4L(12,a,b,c)	/**/
#define		IOCTRLFDCTL(a,b,c)	IOCTRL_4L(13,a,b,c)	/**/
DOSCALL	int	DUP(short);
DOSCALL	int	DUP2(short, short);				//**
DOSCALL	int	CURDIR(short ,unchar *);
DOSCALL	int	MALLOC(int);
DOSCALL	int	MFREE(int);
DOSCALL	int	SETBLOCK(int, int);				//**
DOSCALL	volatile void	EXIT2(short);
DOSCALL	int	WAIT(void);					//**
DOSCALL	int	FILES(_FILBUF *, unchar *, short);
	int	EXFILES(_EXFILBUF *,unchar *,short);
#define		EXFILES(fb,name,atrb)		\
({	void *fbb=(fb);				\
	fbb+=0x80000000;			\
	(EXFILES((_EXFILBUF *)fbb,name,atrb));	\
})
DOSCALL	int	NFILES(_FILBUF *);
	int	EXNFILES(_EXFILBUF *);
#define		EXNFILES(fb)		\
({	void *fbb=(fb);			\
	fbb+=0x80000000;		\
	(EXNFILES((_EXFILBUF *)fbb));	\
})
// EX?FILESを使う時でTwentyOneも使う時は、V1.36C12以降を使うこと
DOSCALL	int	SETPDB(_PDBADR *);				//**
DOSCALL	_PDBADR	*GETPDB(void);					//**
DOSCALL	int	SETENV(unchar *, unchar *, unchar *);
DOSCALL	int	GETENV(unchar *, unchar *, unchar *);
DOSCALL	int	VERIFYG(void);
DOSCALL	int	COMMON_2(short,unchar *);			//**
DOSCALL	int	COMMON_5(short,unchar *,long,long,long);   	//**
	int	COMMON_CK(unchar *);
	int	COMMON_RD(unchar *,long,unchar *,long);
	int	COMMON_WT(unchar *,long,unchar *,long);
	int	COMMON_LK( unchar *,long,long,long);
	int	COMMON_FRE(unchar *,long,long,long);
	int	COMMON_DEL(unchar *);
#define		COMMON_CK(a)		COMMON_2(0,a)		/**/
#define		COMMON_RD(a,b,c,d)	COMMON_5(1,a,b,c,d)	/**/
#define		COMMON_WT(a,b,c,d)	COMMON_5(2,a,b,c,d)	/**/
#define		COMMON_LK(a,b,c,d)	COMMON_5(3,a,b,c,d)	/**/
#define		COMMON_FRE(a,b,c,d)	COMMON_5(4,a,b,c,d)	/**/
#define		COMMON_DEL(a)		COMMON_2(6,a)		/**/
DOSCALL	int	MOVE(unchar *, unchar *);
//RENAME(a,b)はdoscallと大きく異なるので実現出来ない
DOSCALL	int	FILEDATE(short, int);
DOSCALL	int	MALLOC2(unshort, int);				//**
#define		MALLOC0(a,b)		MALLOC2((a)|0x8000,b)	/**/
DOSCALL	int	MAKETMP(unchar *, short);
DOSCALL	int	NEWFILE(unchar *, int);
DOSCALL	int	LOCK_4(short,short,long,long);			//**
	int	LOCK(short,long,long);
	int	UNLOCK(short,long,long);
#define		LOCK(a,b,c)		LOCK_4(0,a,b,c)
#define		UNLOCK(a,b,c)		LOCK_4(1,a,b,c)
DOSCALL	int	ASSIGN_2(short,unchar *);			//**
DOSCALL	int	ASSIGN_3(short,unchar *,unchar *);
DOSCALL	int	ASSIGN_4(short,unchar *,unchar *,short);	//**
	int	GETASSIGN(unchar *,unchar *);
	int	MAKEASSIGN(unchar *,unchar *,short);
	int	RASSIGN(unchar *);
#define		GETASSIGN(a,b)		ASSIGN_3(0,a,b)
#define		MAKEASSIGN(a,b,c)	ASSIGN_4(1,a,b,c)	/**/
#define		RASSIGN(a)		ASSIGN_2(4,a)		/**/
DOSCALL	int	FFLUSH_SET(short);				//**
DOSCALL	int	OS_PATCH(short,char *);				//**
DOSCALL	_FCBS	*GET_FCB_ADR(short);				//*
DOSCALL	int	S_MALLOC(unshort, int);				//**
#define		S_MALLOC0(a,b)		S_MALLOC((a)|0x8000,b)	/**/
DOSCALL	int	S_MFREE(int);					//**
DOSCALL	int	S_PROCESS(short, int, int, int);		//**
DOSCALL	void	DISKRED(unchar *, short, short, short);		//**
DOSCALL	void	DISKRED_L(unchar *,short,long,long);		//**
#define		DISKRED2(a,b,c,d)	\
({	void *aa=(a);			\
	aa+=0x80000000;			\
	(DISKRED_L((unchar *)a,b,c,d));	\
}
DOSCALL	void	DISKWRT(unchar *, short, short, short);		//**
DOSCALL	void	DISKWRT_L(unchar *,short,long,long);		//**
#define		DISKWRT2(a,b,c,d)	\
({	void *aa=(a);			\
	aa+=0x80000000;			\
	DISKWRT_L((unchar *)a,b,c,d);	\
})
DOSCALL	int	INDOSFLG(void);					//**
DOSCALL	int	BUS_ERR(unchar *, unchar *, short);	// この関数は本当に有効か？
/* _PR系はテストしていない */
DOSCALL	int	OPEN_PR(unchar *, short, int, int, short, int, _PRCCTRL *, long);
DOSCALL	int	KILL_PR(void);
DOSCALL	int	GET_PR(short, _PRCPTR *);
DOSCALL	int	SUSPEND_PR(short);
DOSCALL	long	SLEEP_PR(long);
DOSCALL	int	SEND_PR(short, short, short, unchar *, long);
DOSCALL	long	TIME_PR(void);
DOSCALL	void	CHANGE_PR(void);
//
// 以上にないもの（実現出来ないもの）はライブラリ関数を使う(doslib.hと同じ)
	int	KNJCTRL(long,...);
	int	LOADEXEC(UBYTE *, _COMLINE *, UBYTE *);
	int	LOAD(UBYTE *, _COMLINE *, UBYTE *);
	int	PATHCHK(UBYTE *, _COMLINE *, UBYTE *);
	int	LOADONLY(UBYTE *, UBYTE *, UBYTE *);
	int	EXECONLY(int);
	int	BINDNO(UBYTE *, UBYTE *);
	int	EXEC2(int, UBYTE *, UBYTE *, UBYTE **);
	int	RENAME(UBYTE *, UBYTE *);
	void	SUPER_JSR(void (*)(void), _DREGS *, _DREGS *);
#ifdef	__cplusplus
}
#endif

#endif		// __GNUC__

#endif		// ___AIG_DOSLIBM___
