/*
 * Header file for Windows H19 terminal emulator
 * 
 * Written by William S. Hall
 *	      3665 Benton Street, #66
 *	      Santa Clara, CA 95051
 */

#if !defined(EXTERN)
#define EXTERN extern
#endif

/* special messages */
#define WH19_STRINGINPUT	WM_USER
#define WH19_COMMAND		WM_USER+1
#define WH19_CARETFUNCTION	WM_USER+2
#define WH19_SAVECURSORPOSITION	WM_USER+3
#define WH19_CURSORPOSITION  	WM_USER+4
#define WH19_SLAPSCREEN		WM_USER+5

/* commands */
#define H19_MOVECURSORRIGHT	0
#define H19_MOVECURSORLEFT	1
#define H19_MOVECURSORUP	2
#define H19_MOVECURSORDOWN	3
#define H19_ADJUSTWINDOW	4
#define H19_POSITIONCURSORROW	5
#define H19_POSITIONCURSORCOL	6
#define H19_CURSORHOME		7
#define H19_CLRSCREEN		8
#define H19_CLRTOENDOFSCREEN	9
#define H19_CLRTOENDOFLINE	10
#define H19_ERASELINE		11
#define H19_CLRTOTOPOFSCREEN	12
#define H19_CLRTOSTARTOFLINE	13
#define H19_INSERTLINE		14
#define H19_DELETELINE		15
#define H19_DELETECHAR		16
#define H19_REVERSELINEFEED	17
#define H19_SAVECURSOR		18
#define H19_GETCURSOR		19

/* caret commands */
#define H19_CREATECARET		0
#define H19_DESTROYCARET	1
#define H19_SHOWCARET		2
#define H19_HIDECARET		3

/* command states */
#define NO_COMMAND	0
#define ESC_COMMAND	1
#define YPOS_COMMAND	2
#define XPOS_COMMAND	3
#define SET_COMMAND	4
#define RESET_COMMAND	5
#define SETBAUD_COMMAND 6

/* screen attribute */
#define NORMAL 0
#define REVERSE 1

/* dialog boxes */
#define DT_ABOUT	1
#define DT_COMM		2
#define DT_TERM		3
#define DT_STRING	4

/* controls  from comm box */
#define IDD_BAUDRATE	100
#define IDD_110		101
#define IDD_150		102
#define IDD_300		103
#define IDD_600		104
#define IDD_1200	105
#define IDD_1800	106
#define IDD_2000	107
#define IDD_2400	108
#define IDD_3600	109
#define IDD_4800	110
#define IDD_7200	111
#define IDD_9600	112
#define IDD_19200	113
#define IDD_OTHER	114
#define IDD_NONE	115
#define IDD_ODD		116
#define IDD_EVEN	117
#define IDD_MARK	118
#define IDD_SPACE	119
#define IDD_7BIT	120
#define IDD_8BIT	121
#define IDD_COM1	122
#define IDD_COM2	123
#define IDD_DEFPORT	124
#define IDD_SAVE	125

/* controls from term box */
#define IDD_HALF	100
#define IDD_FULL	101
#define IDD_HEATH	102
#define IDD_ANSI	103
#define IDD_NORMAL	104
#define IDD_SHIFTED	105
#define IDD_LINE	106
#define IDD_BLOCK	107
#define IDD_WRAP	108
#define IDD_LFCR	109
#define IDD_CRLF	110

/* controls from key edit box */
#define IDD_STRINGEDIT	100
#define IDD_F1		101
#define IDD_F2		102
#define IDD_F3		103
#define IDD_F4		104
#define IDD_F5		105
#define IDD_F6		106
#define IDD_F7		107
#define IDD_F8		108
#define IDD_F9		109
#define IDD_F10		110
#define IDD_F11		111
#define IDD_F12		112
#define IDD_NOSHIFT	120
#define IDD_SHIFT	121
#define IDD_CONTROL	122
#define IDD_CTRLSHIFT	123
#define IDD_READSTRING	124
#define IDD_SAVESTRING	125

/* strings */
#define IDS_APPNAME	100
#define IDS_ABOUT	101
#define IDS_WINTITLE	102
#define IDS_OFFLINE	103
#define IDS_ONLINE	104
#define IDS_DISPLAYNAME	105
#define IDS_NOCOMOPEN	106
#define IDS_NOCOMSET	107
#define IDS_ADDDEFAULTS	108
#define IDS_FIRSTPORT	109
#define IDS_SECONDPORT	110
#define IDS_COM1	111
#define IDS_COM2	112
#define IDS_CONTINUEPROG 113

#define IDS_BLOCKCURSOR 114
#define IDS_KEYCLICK	115
#define IDS_WRAPAROUND	116
#define IDS_AUTOLFONCR	117
#define IDS_AUTOCRONLF	118
#define IDS_ANSIMODE	119
#define IDS_SHIFTEDKEYPAD 120
#define IDS_FULLDUPLEX	121

#define IDS_CANNOTCLOSECOM	122
#define IDS_TERMNAME		123
#define IDS_STATNAME		124
#define IDS_TERMINAL		125
#define IDS_CANNOTCREATETERM	126
#define IDS_CANNOTCREATESTATUS	127
#define IDS_LINES		128
#define IDS_COLUMNS		129
#define IDS_COMMSTR		130
#define IDS_CANNOTCHANGEPORT	131

#define IDS_SPKEYID1		200
#define IDS_SPKEYID2		201
#define IDS_SPKEYID3		202
#define IDS_SPKEYID4		203
#define IDS_SPKEYID5		204
#define IDS_SPKEYID6		205
#define IDS_SPKEYID7		206
#define IDS_SPKEYID8		207
#define IDS_SPKEYID9		208
#define IDS_SPKEYID10		209
#define IDS_SPKEYID11		210
#define IDS_SPKEYID12		211

#define IDS_SSPKEYID1		220
#define IDS_SSPKEYID2		221
#define IDS_SSPKEYID3		222
#define IDS_SSPKEYID4		223
#define IDS_SSPKEYID5		224
#define IDS_SSPKEYID6		225
#define IDS_SSPKEYID7		226
#define IDS_SSPKEYID8		227
#define IDS_SSPKEYID9		228
#define IDS_SSPKEYID10		229
#define IDS_SSPKEYID11		230
#define IDS_SSPKEYID12		231

#define IDS_CSPKEYID1		240
#define IDS_CSPKEYID2		241
#define IDS_CSPKEYID3		242
#define IDS_CSPKEYID4		243
#define IDS_CSPKEYID5		244
#define IDS_CSPKEYID6		245
#define IDS_CSPKEYID7		246
#define IDS_CSPKEYID8		247
#define IDS_CSPKEYID9		248
#define IDS_CSPKEYID10		249
#define IDS_CSPKEYID11		250
#define IDS_CSPKEYID12		251

#define IDS_CSSPKEYID1		260
#define IDS_CSSPKEYID2		261
#define IDS_CSSPKEYID3		262
#define IDS_CSSPKEYID4		263
#define IDS_CSSPKEYID5		264
#define IDS_CSSPKEYID6		265
#define IDS_CSSPKEYID7		266
#define IDS_CSSPKEYID8		267
#define IDS_CSSPKEYID9		268
#define IDS_CSSPKEYID10		269
#define IDS_CSSPKEYID11		270
#define IDS_CSSPKEYID12		271

/* menus */
#define IDM_ABOUT	300
#define IDM_OFFLINE	301
#define IDM_ONLINE	302
#define IDM_COMM	303
#define IDM_TERM	304
#define IDM_SPECIALKEYS 305
#define IDM_COPY	306
#define IDM_PASTE	307
#define IDM_BREAK	308
#define IDM_RESET	309
#define IDM_SCROLL	310
#define IDM_SHIFTSCROLL	311
#define IDM_CLEARCOM	312

/* accelerators */
#define IDM_F1		400
#define IDM_F2		401
#define IDM_F3		402
#define IDM_F4		403
#define IDM_F5		404
#define IDM_F6		405
#define IDM_F7		406
#define IDM_F8		407
#define IDM_F9		408
#define IDM_F10		409
#define IDM_F11		410
#define IDM_F12		411

#define IDM_SF1		500
#define IDM_SF2		501
#define IDM_SF3		502
#define IDM_SF4		503
#define IDM_SF5		504
#define IDM_SF6		505
#define IDM_SF7		506
#define IDM_SF8		507
#define IDM_SF9		508
#define IDM_SF10	509
#define IDM_SF11	510
#define IDM_SF12	511

#define IDM_CF1		600
#define IDM_CF2		601
#define IDM_CF3		602
#define IDM_CF4		603
#define IDM_CF5		604
#define IDM_CF6		605
#define IDM_CF7		606
#define IDM_CF8		607
#define IDM_CF9		608
#define IDM_CF10	609
#define IDM_CF11	610
#define IDM_CF12	611

#define IDM_CSF1	700
#define IDM_CSF2	701
#define IDM_CSF3	702
#define IDM_CSF4	703
#define IDM_CSF5	704
#define IDM_CSF6	705
#define IDM_CSF7	706
#define IDM_CSF8	707
#define IDM_CSF9	708
#define IDM_CSF10	709
#define IDM_CSF11	710
#define IDM_CSF12	711

/* comm stuff */
#define RXQUESIZE	512
#define BUFSIZE		RXQUESIZE - 1
#define TXQUESIZE	128
#define DEF_TABSTOP 	8

/* term window size */
#define H19LINES 	24
#define H19COLS  	80
#define TERMMAXLINES	40
#define TERMMAXCOLS	95

/* misc */
#define VK_SCROLL 0x91

typedef struct MainWndData {
    HWND hWnd;
    short BottomTextLine;		/* in client coordinates */
    short SCTopTextLine, SCBottomTextLine;	/* in screen coordinates */
    short Width, Height;
} MWND;

typedef struct TermWndData {
    HWND hWnd;
    HDC hDC;
    HANDLE hVidBuffer;
    char *pVidBuffer;		/* pointer to buffer */
    short Xpos, Ypos;
    short oVidLastLine;		/* offset to last line in buffer */
    short oTopLine;		/* top line of screen */
    short oCurrentLine;		/* current line of screen */
    short oBottomLine;		/* bottom line of screen */
    short CurLineOffset;	/* offset into current screen */
    short MaxCols, MaxLines;	/* screen size in chars */
    short ScreenSize;
    short TabLimit;
    short Width, Height;	/* screen size */
    short CharWidth, CharHeight;
} TWND;
typedef TWND *PTWND;

/* structures */
struct tagS401 {
    WORD BaudRate;
    BYTE ByteSize;
    BYTE Parity;
    BYTE StopBits;
};

struct tagS402 {
    BOOL BlockCursor;
    BOOL KeyClick;
    BOOL WrapAround;
    BOOL LFonCR;
    BOOL CRonLF;
    BOOL ANSIMode;
    BOOL ShiftedKeypad;
    BOOL FullDuplex;
};

struct CommonData {
    BOOL BlockCursor;
    BOOL KeyClick;
    BOOL WrapAround;
    BOOL LFonCR;
    BOOL CRonLF;
    BOOL ANSIMode;
    BOOL ShiftedKeypad;
    BOOL FullDuplex;
    BOOL InverseVideo;
    BOOL GraphicsMode;
    BOOL ICToggle;
    BOOL AltKeypad;
    BOOL CursorOff;
    BOOL OwnCaret;
    BOOL KeyboardDisabled;
    BOOL HoldScreen;
    BOOL ScrollLock;
    BYTE CharAttribute;
    HFONT hScreenFont;
    int CommandState;
    BOOL StatOpen;
    BOOL StatOverlayTerm;
    short CurSaveRow, CurSaveCol;
    int LineState;
    int BreakFlag;
    int ReleaseCount;
};

typedef struct GlobalBuf {
    HANDLE hBuf;
    LONG lBufSize;
    LONG lBufHead;
    LONG lBufTail;
} GLOBALBUF;

typedef GLOBALBUF *PGLOBALBUF;

/* globals */
#define BAUDTABLESIZE 13

EXTERN WORD BaudRateTable[BAUDTABLESIZE]
#if defined(INITIALIZE)
    = {110,150,300,600,1200,1800,2000,2400,3600,4800,7200,9600,19200}
#endif
;

EXTERN MWND MW;
EXTERN TWND TW;
EXTERN TWND SW;
EXTERN struct CommonData CD;
EXTERN struct tagS401 S401;
EXTERN struct tagS402 S402;
EXTERN GLOBALBUF GB;

#define WINTITLELEN	50
EXTERN char szAppName[10];
EXTERN char szTermName[10];
EXTERN char szStatName[10];
EXTERN char szWinTitle[WINTITLELEN];
EXTERN char szOffline[20];
EXTERN char szOnline[20];
EXTERN char *szFKey[12];
EXTERN char *szSFKey[12];
EXTERN char *szCFKey[12];
EXTERN char *szCSFKey[12];

EXTERN short cid;
EXTERN DCB CommData;

EXTERN HANDLE hInst;
EXTERN HANDLE hPrevInst;
EXTERN HWND hWndActive;
EXTERN HWND hAccel;

EXTERN FARPROC fpTerminal;
EXTERN HANDLE hCommandLine;
EXTERN char *pCommandLine;
EXTERN HANDLE hWndNext;
EXTERN HANDLE hClipData;
EXTERN LPSTR pClipData;
