/*
**	termData.c
**
**	Global data structures.
**
**	Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
**		All Rights Reserved
*/

#include "termGlobal.h"

	/* Libraries. */

struct ExecBase		*SysBase;
struct DosLibrary	*DOSBase;

struct IntuitionBase	*IntuitionBase;
struct GfxBase		*GfxBase;
struct RxsLib		*RexxSysBase;
struct LocaleBase	*LocaleBase;
struct Library		*GadToolsBase,
			*TimerBase,
			*ConsoleDevice,
			*DiskfontBase,
			*UtilityBase,
			*AslBase,
			*IFFParseBase,
			*CxBase,
			*IconBase,
			*LayersBase,
			*TranslatorBase,
			*WorkbenchBase,
			*AmigaGuideBase,
			*XEmulatorBase,
			*XProtocolBase,
			*OwnDevUnitBase;

BYTE			 Kick30;

	/* Timer device. */

struct timerequest	*TimeRequest;
struct MsgPort		*TimePort;

	/* Console device. */

struct IOStdReq		*ConsoleRequest;
struct KeyMap		*KeyMap;
BPTR			 KeySegment;

	/* Screen & Windows. */

struct Screen		*Screen,
			*DefaultPubScreen;
struct Window		*Window;
LONG			 WindowWidth,
			 WindowHeight,
			 WindowLeft,
			 WindowTop;
struct Window		*StatusWindow;
struct Gadget		*StatusGadget;
UWORD			 StatusOffset;
APTR			 OldWindowPtr;
struct BitMap		*InterleavedBitMap;
struct Requester	*RequesterList;
UBYTE			 ScreenTitle[80];
UBYTE			 DepthMask;
LONG			 RenderPens[4],
			 MappedPens[2][16],
			 SafeTextPen;
struct DrawInfo		*DrawInfo;
LONG			 ScreenWidth,
			 ScreenHeight;
BYTE			 UseMasking;

struct BlockMarker	*WindowMarker;
ULONG			 ClickSecs,ClickMicros;
BYTE			 FirstClick = TRUE,HoldClick = FALSE;
LONG			 ClickX,ClickY;

	/* Workbench AppWindow support. */

struct AppWindow	*WorkbenchWindow;
struct MsgPort		*WorkbenchPort;

	/* Graphics rendering. */

struct ViewPort		*VPort;
struct RastPort		*RPort;
struct Region		*ClipRegion,
			*OldRegion;
struct TextFont		*GFX,
			*CurrentFont,
			*UserTextFont;
WORD			 UserFontHeight,
			 UserFontWidth,
			 UserFontBase;
UBYTE			 UserFontName[40];
struct TextFont		*TextFont;
WORD			 TextFontHeight,
			 TextFontWidth,
			 TextFontBase;
struct TTextAttr	 TextAttr;
UBYTE			 TextFontName[40];
struct TTextAttr	 UserFont;
struct TagItem		 TagDPI[2];
APTR			 VisualInfo;
UWORD			 FontRightExtend;

ULONG			(* __regargs ReadAPen)(struct RastPort *RPort);
ULONG			(* __regargs ReadBPen)(struct RastPort *RPort);
ULONG			(* __regargs ReadDrMd)(struct RastPort *RPort);
ULONG			(* __regargs SetWrMsk)(struct RastPort *RPort,ULONG Mask);

UWORD StandardPens[] =
{
	(UWORD)~0
};

UWORD ANSIPens[] =
{
	0,4,7,7,4,6,7,0,6,	0,7,0,(UWORD)~0
};

UWORD EGAPens[] =
{
	0,15,15,15,8,7,15,0,7,	0,15,0,(UWORD)~0
};

UWORD AtomicColours[16] =
{
	0x000,
	0xDDD,
	0x000,
	0x000,
	0x000,
	0x000,
	0x000,
	0x000,
	0x000,
	0x000,
	0x000,
	0x000,
	0x000,
	0x000,
	0x000,
	0x000
};

UWORD EGAColours[16] =
{
	0x000,	/* Black. */
	0xA00,	/* Dark red. */
	0x0A0,	/* Dark green. */
	0xA60,	/* Dark yellow (orange). */
	0x00A,	/* Dark blue. */
	0xA0A,	/* Dark magenta.*/
	0x0AA,	/* Dark cyan. */
	0xBBB,	/* Light grey. */
	0x666,	/* Dark grey. */
	0xF00,	/* Red. */
	0x0F0,	/* Green. */
	0xFF0,	/* Yellow. */
	0x00F,	/* Blue. */
	0xF0F,	/* Magenta. */
	0x0FF,	/* Cyan. */
	0xFFF	/* White. */
};

UWORD ANSIColours[16] =
{
	0x000,	/* Black. */
	0xF00,	/* Red. */
	0x0F0,	/* Green. */
	0xFF0,	/* Yellow. */
	0x00F,	/* Blue. */
	0xF0F,	/* Magenta. */
	0x0FF,	/* Cyan. */
	0xFFF,	/* White. */

	0x000,	/* Black. */
	0xF00,	/* Red. */
	0x0F0,	/* Green. */
	0xFF0,	/* Yellow. */
	0x00F,	/* Blue. */
	0xF0F,	/* Magenta. */
	0x0FF,	/* Cyan. */
	0xFFF	/* White. */
};

UWORD			 DefaultColours[16],
			 BlinkColours[16],
			 StandardColours[16];

	/* Line/Column offset tables. */

LONG			*OffsetXTable,
			*OffsetYTable;

	/* DOS data. */

struct Process		*ThisProcess;
struct Process		*StatusProcess;
struct Process		*BufferProcess;
struct Process		*RexxProcess,
			*RexxBackgroundProcess;
struct MsgPort		*TermRexxPort;
struct WBStartup	*WBenchMsg;
BPTR			 WBenchLock;
struct TermPort		*TermPort;
BYTE			 ClipBit	= -1,
			 CheckBit	= -1;
BYTE			 InRexx;
WORD			 LimitCount	= -1;
UBYTE			 LimitMacro[MAX_FILENAME_LENGTH];

	/* Character conversion. */

struct InputEvent	*FakeInputEvent;

	/* Serial I/O. */

struct IOExtSer		*ReadRequest;
struct IOExtSer		*WriteRequest;
struct MsgPort		*ReadPort;
APTR			 ReadBuffer,
			 HostReadBuffer;
UBYTE			*SerialMessage;
ULONG			 DTERate;

UBYTE			 NewDevice[MAX_FILENAME_LENGTH];
LONG			 NewUnit;
BYTE			 UseNewDevice,
			 UseNewUnit;

LONG BaudRates[] =
{
	110,300,600,1200,2400,4800,7200,9600,12000,14400,19200,31250,38400,57600,64000,76800,115200
};

LONG			 NumBaudRates = sizeof(BaudRates) / sizeof(LONG);

	/* Localization support. */

struct Catalog		*Catalog;
struct Locale		*Locale;

	/* Hotkeys. */

struct Hotkeys		 Hotkeys;

struct NewBroker NewTermBroker =
{
	NB_VERSION,
	"term",
	"term © 1990-1993 by MXM",
	"Terminal program",
	0,0,0,NULL,0
};

	/* Static default fonts. */

struct TextAttr DefaultFont =
{
	(UBYTE *)"topaz.font",
	8,
	FS_NORMAL,
	FPF_ROMFONT | FPF_DESIGNED
};

struct TextAttr GFXFont =
{
	(UBYTE *)"GFX.font",
	8,
	FS_NORMAL,
	FPF_DISKFONT
};

	/* Character lookup tables. */

BYTE IsPrintable[256] =
{
	0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,
	0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
};

BYTE CharType[256] =
{
	0,0,0,0,0,0,0,0,0,0,6,0,0,7,0,0,
	0,5,0,4,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,
	0,0,0,0,0,3,1,1,1,1,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

	/* IBM <-> ISO font conversion. */

UBYTE IBMConversion[256] =
{
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x00,0x00,
	0x00,0x11,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x00,0x00,0x00,0x00,
	0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
	0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
	0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
	0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
	0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
	0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0xAD,0x9B,0x9C,0x00,0x9D,0x00,0x15,0x00,0x00,0xA6,0x00,0x00,0x00,0xAE,0x00,
	0xF8,0xF1,0xFD,0x00,0x00,0xE6,0x14,0xF9,0x00,0x00,0xA7,0xAF,0xAC,0xAB,0x00,0xA8,
	0x00,0x00,0x00,0x00,0x8E,0x8F,0x92,0x80,0x00,0x90,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0xA5,0x00,0x00,0x00,0x00,0x99,0x00,0x00,0x00,0x00,0x00,0x9A,0x00,0x00,0xE1,
	0x85,0xA0,0x83,0x00,0x84,0x86,0x91,0x87,0x8A,0x82,0x88,0x89,0x8D,0xA1,0x8C,0x00,
	0x00,0xA4,0x95,0xA2,0x93,0x00,0x94,0x00,0x00,0x97,0xA3,0x96,0x81,0x00,0x00,0x98
};

	/* Table of graphics characters. */

BYTE GfxTable[256] =
{
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

	/* Special character treatment. */

struct SpecialKey SpecialKeys[13] =
{
	BEL,	DoBeep,		/* Ring the bell. */
	XON,	DoxON,		/* Flow control - stop output. */
	BKS,	DoBackspace,	/* Erase a character. */
	ENT,	DoLF_FF_VT,	/* Enter key. */
	FFD,	DoFF,		/* Form feed. */
	VTB,	DoLF_FF_VT,	/* Vertical tab (huh?). */
	RET,	DoCR,		/* Return key. */
	TAB,	DoTab,		/* Move to next tab stop. */
	SI,	DoShiftIn,	/* Change to graphics mode */
	SO,	DoShiftOut,	/* Change out of graphics mode. */
	ENQ,	DoEnq,		/* Transmit answerback message. */
	ESC,	DoEsc,		/* Start new control sequence. */
	CSI,	DoCsi		/* Start new control sequence. */
};

JUMP *SpecialTable;

BYTE AbortMap[256] =
{
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,1,0,1,2,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

JUMP *AbortTable;

VOID (* __regargs ConDump)(STRPTR,LONG);
VOID (* __regargs ConOutput)(STRPTR,LONG);
VOID (* __regargs ConProcessData)(register STRPTR,register LONG);

	/* Shared global string formatting buffer. */

UBYTE SharedBuffer[512];

	/* Screen pull-down-menu. */

struct NewMenu TermMenu[] =
{
	{ NM_TITLE, NULL,		 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)0},
	{   NM_SUB, NULL,		 0 , 0,		0, (APTR)MEN_SAVE_AS_PICTURE},
	{   NM_SUB, NULL,		 0 , 0,		0, (APTR)MEN_SAVE_AS_TEXT},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)0},
	{   NM_SUB, NULL,		 0 , 0,		0, (APTR)MEN_PRINT_SCREEN},
	{   NM_SUB, NULL,		 0 , 0,		0, (APTR)MEN_PRINT_CLIP},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)0},
	{   NM_SUB, NULL,		 0 , TICK,	0, (APTR)MEN_CAPTURE_TO_FILE},
	{   NM_SUB, NULL,		 0 , TICK,	0, (APTR)MEN_CAPTURE_TO_PRINTER},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_ICONIFY},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_ABOUT},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_QUIT},

	{ NM_TITLE, NULL,		 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_COPY},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_PASTE},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_CLEAR},

	{ NM_TITLE, NULL,		 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_EXECUTE_DOS_COMMAND},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_EXECUTE_REXX_COMMAND},

	{ NM_TITLE, NULL,		 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_PHONEBOOK},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_REDIAL},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_DIAL_NUMBER},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_SEND_BREAK},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_HANG_UP},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_WAIT},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_FLUSH_BUFFER},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_RELEASE_DEVICE},

	{ NM_TITLE, NULL,		 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_UPLOAD_ASCII},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_DOWNLOAD_ASCII},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_UPLOAD_TEXT},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_DOWNLOAD_TEXT},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_EDIT_AND_UPLOAD_TEXT},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_UPLOAD_BINARY},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_DOWNLOAD_BINARY},

	{ NM_TITLE, NULL,		 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_CLEAR_BUFFER},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_DISPLAY_BUFFER},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_CLOSE_BUFFER},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , TICK,	0, (APTR)MEN_FREEZE_BUFFER},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_OPEN_BUFFER},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_SAVE_BUFFER_AS},

	{ NM_TITLE, NULL,		 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_CLEAR_SCREEN},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_RESET_FONT},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_RESET_STYLES},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_RESET_TERMINAL},

	{ NM_TITLE, NULL,		 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_SERIAL},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_MODEM},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_SCREEN},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_TERMINAL},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_SET_EMULATION},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_CLIPBOARD},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_CAPTURE},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_COMMANDS},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_MISC},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_PATH},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_TRANSFER_PROTOCOL},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_TRANSFER},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_TRANSLATION},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_MACROS},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_CURSORKEYS},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_FAST_MACROS},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_HOTKEYS},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_SPEECH},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_SOUND},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_SET_CONSOLE},
	{  NM_ITEM, NM_BARLABEL,	 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_OPEN_SETTINGS},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_SAVE_SETTINGS},
	{  NM_ITEM, NULL,		 0 , 0,		0, (APTR)MEN_SAVE_SETTINGS_AS},

	{ NM_TITLE, NULL,		 0 , 0,		0, (APTR)0},
	{  NM_ITEM, NULL,		 0 , TICK,	0, (APTR)MEN_STATUS_WINDOW},
	{  NM_ITEM, NULL,		 0 , TICK,	0, (APTR)MEN_REVIEW_WINDOW},
	{  NM_ITEM, NULL,		 0 , CHECKIT,	0, (APTR)MEN_PACKET_WINDOW},
	{  NM_ITEM, NULL,		 0 , TICK,	0, (APTR)MEN_FAST_MACROS_WINDOW},

	{ NM_TITLE, NULL,		 0 , 0,		0, (APTR)0},
	{   NM_END, 0,			 0 , 0,		0, (APTR)0}
};

struct Menu *Menu;

	/* Pointer. */

UWORD __chip Stopwatch[(1 + 16 + 1) * 2] =
{
	0x0000,0x0000,

	0x0400,0x07C0,
	0x0000,0x07C0,
	0x0100,0x0380,
	0x0000,0x07E0,
	0x07C0,0x1FF8,
	0x1FF0,0x3FEC,
	0x3FF8,0x7FDE,
	0x3FF8,0x7FBE,
	0x7FFC,0xFF7F,
	0x7EFC,0xFFFF,
	0x7FFC,0xFFFF,
	0x3FF8,0x7FFE,
	0x3FF8,0x7FFE,
	0x1FF0,0x3FFC,
	0x07C0,0x1FF8,
	0x0000,0x07E0,

	0x0000,0x0000
};

	/* Cross-hatch pattern. */

ULONG __chip Crosshatch = 0x5555AAAA;

	/* Configuration. */

struct Configuration	*Config,
			*PrivateConfig,
			*BackupConfig;
struct SpeechConfig	 SpeechConfig;
BYTE			 English = TRUE;
BYTE			 Status;
BYTE			 Online,WasOnline;
ULONG			 OnlineMinutes;
UWORD			 PublicModes;

UBYTE			 LastConfig[MAX_FILENAME_LENGTH];
UBYTE			 DefaultPubScreenName[MAXPUBSCREENNAME + 1],
			 SomePubScreenName[MAXPUBSCREENNAME + 1];

	/* Capture file. */

struct Buffer		*FileCapture;
BPTR			 PrinterCapture;
UBYTE			 CaptureName[MAX_FILENAME_LENGTH];
BYTE			 StandardPrinterCapture,
			 ControllerActive;

	/* Buffer. */

UBYTE			**BufferLines;
LONG			 Lines;
struct SignalSemaphore	*BufferSemaphore;
LONG			 MaxLines = 100;
LONG			 BufferSpace;
BYTE			 BufferClosed;
BYTE			 BufferFrozen;

	/* Sound support.c */

struct SoundConfig	 SoundConfig;
BYTE			 SoundChanged = FALSE;

	/* Phonebook. */

struct PhoneEntry	**Phonebook;
LONG			 PhoneSize;
LONG			 NumPhoneEntries;
UBYTE			 PhonePassword[256];
BYTE			 PhonePasswordUsed,
			 RebuildMenu;
UBYTE			 Password[100];
UBYTE			 UserName[100];
UBYTE			 GlobalPassword[256];

UBYTE			 CurrentBBSName[40],
			 CurrentBBSNumber[100],
			 CurrentBBSComment[100];

UBYTE			 LastPhone[MAX_FILENAME_LENGTH];
UBYTE			 LastKeys[MAX_FILENAME_LENGTH];
UBYTE			 LastMacros[MAX_FILENAME_LENGTH];
UBYTE			 LastCursorKeys[MAX_FILENAME_LENGTH];
UBYTE			 LastTranslation[MAX_FILENAME_LENGTH];
UBYTE			 LastSpeech[MAX_FILENAME_LENGTH];
UBYTE			 LastSound[MAX_FILENAME_LENGTH];

struct MacroKeys	*MacroKeys;
struct CursorKeys	*CursorKeys;

	/* Console stuff. */

UBYTE			*StripBuffer;
UWORD			 LastLine,LastColumn,LastPixel;
BYTE			 Charset,Attributes,FgPen,BgPen;
WORD			 CursorX,CursorY,Top,Bottom;
BYTE			 UseRegion,RegionSet,InSequence,Quiet,Blocking;
BYTE			*TabStops;
UWORD			 TabStopMax;
BYTE			 CharMode[2];

BYTE			 ResetDisplay,DisplayReopened,FixPubScreenMode,FixScreenSize;

	/* Flow filter. */

STRPTR			 AttentionBuffers[SCAN_COUNT];
BYTE			 BaudPending,FullCheck,UseFlow;
UBYTE			 BaudBuffer[80],BaudCount;

struct FlowInfo		 FlowInfo;

	/* Transfer data. */

BYTE			 BinaryTransfer;
LONG			 TransferBits;

VOID			(* __regargs ConTransfer)(STRPTR,LONG);

UBYTE			*DownloadPath;
BYTE			 Uploading;
BYTE			 DidTransfer;

struct Window		*TransferWindow;
struct Menu		*TransferMenu;
struct Gadget		*TransferGadgetArray[GAD_TRANSFER_SKIP + 1];
struct List		 TransferInfoList;
struct TextBox		*TransferBoxArray[BOX_TRANSFER_RIGHT2 + 1],
			*TransferBoxList;
struct List		 TransferInfoList;

struct FileTransferInfo	*FileTransferInfo;

struct XPR_IO		*XprIO;

UBYTE			 ProtocolOptsBuffer[256];
BYTE			 NewLibrary,NewOptions;
UBYTE			 LastXprLibrary[MAX_FILENAME_LENGTH];
UBYTE			 ConvNumber[30],ConvNumber10[30];
BYTE			 UsesZModem,SendAbort,TransferAborted,TransferFailed,TransferError;

	/* The standard ZModem cancel sequence
	 * (ten CAN chars followed by ten
	 * BS chars).
	 */

UBYTE ZModemCancel[] =
{
	24,24,24,24,24,24,24,24,24,24,8,8,8,8,8,8,8,8,8,8
};

	/* Pay per minute. */

LONG			 CurrentPay;
LONG			 PayPerUnit[2];
LONG			 SecPerUnit[2];
LONG			 WhichUnit;
struct PhoneEntry	*ChosenEntry;
BYTE			 ChosenInUse;

	/* Execute a command/script. */

UBYTE			 WindowName[256];

BYTE			 WeAreBlocking;

	/* Dial list. */

struct List		*DialList;

BYTE			 SendStartup;

	/* TermMain data. */

BYTE			 ReleaseSerial;
BYTE			 ResetSerial;
BYTE			 MainTerminated,
			 IconTerminated = TRUE,
			 DoIconify = FALSE,
			 DoDial = DIAL_IGNORE;

BYTE			 ConfigChanged,PhonebookChanged,TranslationChanged,
			 MacroChanged,CursorKeysChanged,FastMacrosChanged,
			 HotkeysChanged,SpeechChanged,BufferChanged;

	/* Upload/Download paths. */

UBYTE			 LastDownload[MAX_FILENAME_LENGTH];
UBYTE			 LastUpload[MAX_FILENAME_LENGTH];

	/* String gadget hooks. */

struct Hook		 CommandHook,
			 PasswordHook;
BYTE			 DontActivate;

struct Window		*CommandWindow;
struct Gadget		*CommandGadget;
struct Gadget		*ActiveGadget;

struct Process		*ClipProcess;
struct MsgPort		*ClipPort;
BYTE			 ClipInput,
			 ClipXerox,
			 ClipPrefix;

	/* Text sending. */

UBYTE			 SendPrompt[256];
LONG			 SendPromptLen;
BYTE			(* __regargs SendLine)(register STRPTR,register LONG);

	/* Packet window. */

struct Window		*PacketWindow;
struct Gadget		*PacketGadgetArray[2];
struct Menu		*PacketMenu;
struct Gadget		*PacketGadgetList;
struct List		 PacketHistoryList;

	/* Some more colour control flags. */

BYTE			 Initializing,LoadColours;

	/* The character raster. */

UBYTE			*Raster,*RasterAttr;
LONG			 RasterWidth,RasterHeight;
BYTE			 Marking;
struct SignalSemaphore	*RasterSemaphore;
BYTE			 RasterEnabled = TRUE;

	/* Generic lists. */

struct GenericList	*GenericListTable[GLIST_COUNT];

	/* File version test. */

ULONG VersionProps[2] =
{
	ID_TERM,
	ID_VERS
};

	/* Window stack. */

struct Window		*TopWindow;

struct Window		*WindowStack[5];
WORD			 WindowStackPtr;

	/* Global term ID. */

LONG			 TermID;
UBYTE			 TermIDString[MAXPUBSCREENNAME + 1];
UBYTE			 RexxPortName[256];

	/* Fast! macros. */

struct List		 FastMacroList;
LONG			 FastMacroCount;
UBYTE			 LastFastMacros[MAX_FILENAME_LENGTH];
struct Window		*FastWindow;
WORD			 FastWindowLeft		= -1,
			 FastWindowTop		= -1,
			 FastWindowHeight	= -1;

	/* Double-buffered file locking. */

struct List		 DoubleBufferList;
struct SignalSemaphore	 DoubleBufferSemaphore;

	/* XEM interface. */

struct XEM_IO		*XEM_IO;
ULONG			 XEM_Signal;
struct XEmulatorHostData XEM_HostData;
UBYTE			*OptionTitle;
struct List		 XEM_MacroList;
struct XEmulatorMacroKey *XEM_MacroKeys;
UBYTE			 EmulationName[40];

struct List		 EmptyList;

	/* Screen scrolling support. */

UWORD			 ScrollLineFirst,ScrollLineLast,
			 ScrollLineCount;
struct ScrollLineInfo	*ScrollLines;

	/* term review buffer. */

struct MsgPort		*ReviewPort;
struct Window		*ReviewWindow;

	/* Background information. */

ULONG			 BytesIn,
			 BytesOut;
struct DateStamp	 SessionStart;
struct Window		*InfoWindow;

	/* Gadget support routines */

LONG			 InterWidth,
			 InterHeight;

	/* Character translation. */

struct TranslationEntry	**SendTable,
			**ReceiveTable;
