//	ＡＩＧライブラリ　基本関数：マクロ関数
//		Copyright (C) 1989-1994,2001 by AIG-SOFT

#ifndef	__AIG_MACRO__
#define __AIG_MACRO__	1

#include <stdio.h>
#include <io.h>		// isatty()
#include <iocslib.h>	// B_*()
#include "doslibm.h"	// C_*()
#include "defines.h"

/* 数値出力 */
#define	fprint_dec5(num,keta,fp)	fprint_decII(num,' ',keta,fp)
#define	print_hex2(num,mode)		fprint_hex2(num,stdout,mode)
#define	print_hex4(num,mode)		fprint_hex4(num,stdout,mode)
#define	print_hex8(num,mode)		fprint_hex8(num,stdout,mode)
#define	print_dec(num)			fprint_dec(num,stdout)
#define	print_dec5(num,keta)		fprint_dec5(num,keta,stdout)
#define	print_decII(num,initc,keta)	fprint_decII(num,initc,keta,stdout)
#define	print_dec2c(num,c)		fprint_dec2c(num,c,stdout)

/* 標準出力関数 */
#define printc(c)	fputc(c,stdout)
#define prints(s)	fputs(s,stdout)
#define spc()		printc(SPC)
#define tab()		printc(TAB)
#define crlf()		printc('\n')

/* エラー出力関数 */
#define errprintc(c)	fputc(c,stderr)
#define errprints(s)	fputs(s,stderr)
#define errspc()	errprintc(' ')
#define errtab()	errprintc('\t')
#define errcrlf()	errprintc('\n')

/* 表示制御関数 */
#define curleft()	C_PUTC(0x08)
#define curright()	C_PUTC(0x0c)
#define CLS()		B_CLR_AL()
#define eline()		C_ERA_ED()
#define B_SPC()		B_PUTC(SPC)
#define curon()		curmode(1)
#define curoff()	curmode(0)
#define	syslineon()	C_PRINT("\x1b[>1l")
#define	syslineoff()	C_PRINT("\x1b[>1h")
#define	pos()		((int)B_WPEEK((unsigned short *)0x974))
#define	csrlin()	((int)B_WPEEK((unsigned short *)0x976))
#define	poslin()	B_LPEEK((unlong *)0x974)
#define	curxy(xy)	B_LPOKE((unlong *)0x974,xy)

/* データ変換 */
#define	ctol68(buff)	(*(long *)(buff))
#define	ctos68(buff)	(*(unsint *)(buff))
#define	ltoc68(n,buff)	(*(long *)(buff)=(long)(n))
#define	stoc68(n,buff)	(*(unsint *)(buff)=(unsint)(n))
#define	rgb(r,g,b)	(((g)<<11)|((r)<<6)|((b)<<1))
/* １６ビット数値の上位下位８ビットを取り出す */
#define low(no)		((unchar)(no))
#define high(no)	((unchar)((no)>>8))

/* テキスト全画面退避・復帰 */
#define text_all_get(no)	text_all_sub(no,0xe10000,0)
#define	text_all_put(no)	text_all_sub(no,0xe10000,1)
#define text_all_get0(no)	text_all_sub(no,0xe50000,0)
#define	text_all_put0(no)	text_all_sub(no,0xe50000,1)

/* 旧バージョンとの互換性のため */
#define	EX_PRINT16(str)		print16s(str,0)
#define	print16(str)		print16s(str,1)
#define	EX_PRINT24(str)		print24s(str,0)
#define	print24(str)		print24s(str,1)
#define	pcmplay(fname,f,s)	pcmplay2(fname,f,s,0,0)
#define read1line(fp,ln,t)	read1line0(fp,ln,t,DISPX)
#define	check_char_device(fp)	isatty(fileno(fp))
#if 0	/* これからは使わせない */
#define	stol(c)			toupper(c)
#define	ltos(c)			tolower(c)
#endif
#define	ctoi80(work)		ctol80(work)
#define	itoc80(num,work)	ltoc80(num,work)
#define	WrInt80(fp,num)		WrLong80(fp,num)

/* 名前置き換え */
#define	chkknj1(c)		check_kanji1(c)

#endif
