/* Include file for con.library */

/* Created from the original assembly source ('con2.i') by Bjørn Reese.
** C translation by Michael Berg.
** Note: Target compiler must support 32 bit integers
** Place this file in <libraries/conlib.h>.
*/

#ifndef LIBRARIES_CONLIB_H
#define LIBRARIES_CONLIB_H

#include <exec/types.h>
#include <exec/libraries.h>
#include <libraries/dos.h>
#include <intuition/intuition.h>

#define CONNAME	"con.library"

#define CHARDEFSIZE	((256+7)/8)
#define IGNOREVALUE	(-1)

/* Returned by OpenLibrary() */
struct ConBase
{
	struct Node con_LibNode;              /* Library Node */
	BPTR con_SegList;                     /* Segment List [from LoadSeg()] */
	struct IntuitionBase *IntuitionBase;  /* Intuition Base */
	CPTR con_MathBase;                    /* MathFFP Base */
};

struct ConHandle
{
	CPTR cnh_CDBase;                /* Base of Console Device */
	struct Window cnh_Window;       /* Our Intuition Window */
	struct MsgPort *cnh_UserPort;   /* UserPort for Window */
	struct Unit *cnh_Unit;          /* ConUnit */
	struct IOStdReq *cnh_WriteIO;   /* Our Write IO Port */
	ULONG cnh_Signal;               /* SignalSet [for Wait()] */
	UWORD cnh_ExLength;             /* Extra space for string formatting */
	UWORD cnh_CursorStatus;         /* Current Cursor Status [on/off] */
	UBYTE cnh_PadSpace;             /* Char for Leading Spaces in Numbers */
	UBYTE cnh_PadZero;              /* Char for Leading Zeros in Numbers */
	UBYTE cnh_PadGroup;             /* Char for Group Classifying */
	UBYTE cnh_PadString;            /* Char for Unused String Positions */
	UBYTE cnh_DecimalPoint;         /* Char for Decimal Point */
	UBYTE cnh_FloatE;               /* Char for Floating Point Exponent */
	UBYTE cnh_EchoTable[CHARDEFSIZE]; /* BitTable of Echo Chars */
	ULONG cnh_UserNote[8];            /* List of Pointers to UserNotes */
	int (*cnh_MsgHandler)();          /* Pointer to a User Message Handler */
	ULONG cnh_Reserved[4];            /* Reserved for future use */
};

struct ConInfo
{
	UWORD cin_XPos;			/* Cursor X Position       */
	UWORD cin_YPos;			/* Cursor Y Position       */
	UWORD cin_XSize;		/* Chars per Line          */
	UWORD cin_YSize;		/* Lines in Window         */
	UWORD cin_Styles;		/* Text Styles             */
	UWORD cin_FgCol;		/* Foreground Color        */
	UWORD cin_BgCol;		/* Background Color        */
	ULONG cin_Reserved[4];		/* Reserved for future use */
};

struct AcceptStructure
{
	UWORD acc_XStart;		/* Start X Position     */
	UWORD acc_YStart;		/* Start Y Position     */
	UWORD acc_Styles;		/* Text Styles          */
	UWORD acc_FgCol;		/* Foreground Color     */
	UWORD acc_BgCol;		/* Background Color     */
	ULONG acc_ExitFlags;		/* IDCMP Exit Flags     */
	ULONG acc_Class;		/* Copy of im_Class     */
	UWORD acc_Code;			/* Copy of im_Code      */
	UWORD acc_Qualifier;		/* Copy of im_Qualifier */

	CPTR  acc_IAddress;		/* Copy of im_IAddress    */
	WORD  acc_MouseX;		/* Copy of im_MouseX      */
	WORD  acc_MouseY;		/* Copy of im_MouseY      */
	ULONG acc_Seconds;		/* Copy of im_Seconds     */
	ULONG acc_Micros;		/* Copy of im_Micros      */
	CPTR  acc_IDCMPWindow;		/* Copy of im_IDCMPWindow */

	UBYTE acc_Char;			/* ASCII char      */
	UBYTE acc_Pad001		/* Nothing serious */

	UBYTE acc_ValidTable[CHARDEFSIZE];	/* BitTable of Valid Chars */
	UBYTE acc_ExitTable[CHARDEFSIZE];	/* BitTable of Exit Chars  */
	ULONG acc_Reserved[4];			/* Reserved for future use */
};

/* Extended AcceptString() Structure */
struct EAcceptStructure
{
	struct AcceptStructure accs_AS; /* Standard acceptstructure header */
	char *accs_InputBuffer;		/* Pointer to Input Buffer */
	char *accs_WorkBuffer;		/* Pointer to Work Buffer  */
	UWORD accs_MaxLength;		/* Maximum Length of Text [incl. NULL] */
	UWORD accs_FieldLen;		/* Length of Input Field [incl. NULL]  */
	UWORD accs_Length;		/* Current Length of Text [excl. NULL] */
	UWORD accs_Position;		/* Current Position in Text            */
	UWORD accs_DispPos;		/* First Displayed Position in Text    */
	ULONG accs_Reserved[4];		/* Reserved for future use             */
};

/* Codes for DefineChar() */

/* Modes */
#define DEFMODE_ALL	0
#define DEFMODE_NEW	1
#define DEFMODE_ADD	2
#define DEFMODE_REM	3
#define DEFMODE_GET	4

/* Pre-defined Tables */
#define DEFALL		(0 << 17)
#define DEFNONE		(1 << 17)
#define DEFALFANUM	(2 << 17)
#define DEFALFA		(3 << 17)
#define DEFNUMERIC	(4 << 17)
#define DEFDECIMAL	(5 << 17)
#define DEFHEX		(6 << 17)
#define DEFOCTAL	(7 << 17)
#define DEFBINARY	(8 << 17)
#define DEFFLOAT	(9 << 17)

/* Codes for Cursor() */
#define CURSOROFF	0
#define CURSORON	1

/* Codes for Accept() & AcceptString() */

/* General Flags */
#define ACCB_ERASE	31
#define ACCF_ERASE	(1 << ACCB_ERASE)

/* Accept Flags */
#define ACCB_WAIT	24
#define ACCB_ECHO	25
#define ACCB_UPKEY	26
#define ACCB_DUALKEY	27
#define ACCB_RAWKEY	28

#define ACCF_RAWKEY	(1 << ACCB_RAWKEY)
#define ACCF_DUALKEY	(1 << ACCB_DUALKEY)
#define ACCF_UPKEY	(1 << ACCB_UPKEY)
#define ACCF_ECHO	(1 << ACCB_ECHO)
#define ACCF_WAIT	(1 << ACCB_WAIT)

/* AcceptString Flags */
#define ACCB_NOSCROLL	15
#define ACCB_NOSTDAMIGA	16
#define ACCB_NOAMIGA	17
#define ACCB_FULLSTOP	18
#define ACCB_LASTEXIT	19
#define ACCB_OVERWRITE	20
#define ACCB_CONTINUE	21
#define ACCB_JUSTIFIED	22

#define ACCF_JUSTIFIED	(1 << ACCB_JUSTIFIED)
#define ACCF_CONTINUE	(1 << ACCB_CONTINUE)
#define ACCF_OVERWRITE	(1 << ACCB_OVERWRITE)
#define ACCF_LASTEXIT	(1 << ACCB_LASTEXIT)
#define ACCF_FULLSTOP	(1 << ACCB_FULLSTOP)
#define ACCF_NOAMIGA	(1 << ACCB_NOAMIGA)
#define ACCF_NOSTDAMIGA	(1 << ACCB_NOSTDAMIGA)
#define ACCF_NOSCROLL	(1 << ACCB_NOSCROLL)

/* Codes for SetGfx() */
#define SGFB_PLAIN	0
#define SGFB_BOLD	1
#define SGFB_ITALIC	2
#define SGFB_UNDERLINED	3

#define SGFF_PLAIN	(1 << SGFB_PLAIN)
#define SGFF_BOLD	(1 << SGFB_BOLD)
#define SGFF_ITALIC	(1 << SGFB_ITALIC)
#define SGFF_UNDERLINED	(1 << SGFB_UNDERLINED)

/* Codes for Convert() */

/* Modes */
#define CNV_DECIMAL	1
#define CNV_HEX		2
#define CNV_OCTAL	3
#define CNV_BINARY	4

/* Attributes */
#define CNV_SIGNED	(1 << 16)
#define CNV_LEADSPACE	(1 << 17)

/* Codes for Special Keys */
#define AKEY_NONE	0
#define AKEY_HELP	5
#define AKEY_BS		8
#define AKEY_TAB	9
#define AKEY_LF		10
#define AKEY_RETURN	13
#define AKEY_ARROWRG	17
#define AKEY_ARROWLF	18
#define AKEY_ARROWUP	19
#define AKEY_ARROWDN	20
#define AKEY_ESC	27
#define AKEY_DEL	127
#define AKEY_F1		129
#define AKEY_F2		130
#define AKEY_F3		131
#define AKEY_F4		132
#define AKEY_F5		133
#define AKEY_F6		134
#define AKEY_F7		135
#define AKEY_F8		136
#define AKEY_F9		137
#define AKEY_F10	138
#define AKEY_CSI	155

#endif
