#include "ownincs/VT340console.h"

       /* dies wird einmal ein GUTER (=schneller..??) Parser..(-: */

struct VT52_Parm {
	VOID (*Routine)(struct VT340Console *con, UBYTE *args, ULONG argc);
	UBYTE MatchChar;
	UBYTE Pad;
};

struct VT52_Parm VT52_cmds[] = {
	{ VT340_simplecursorup,			'A' },
	{ VT340_simplecursordown,		'B' },
	{ VT340_simplecursorright,		'C' },
	{ VT340_simplecursorleft,		'D' },
	{ VT52_EnterGM,					'F' },
	{ VT52_ExitGM,						'G' },
	{ VT340_cursorposition,			'H' },
	{ VT340_cursorup,					'I' },
	{ VT340_eraseindisplay,			'J' },
	{ VT340_eraseinline,				'K' },
/* direct cursor address is handled specially..<-: */
	{ VT52_Identify,					'Z' },
	{ VT52_EnterAKM,					'=' },
	{ VT52_ExitAKM,					'>' },
	{ VT52_EnterANSI,					'<' },
	{ VT52_EnterAutoPrint,			'^' },
	{ VT52_ExitAutoPrint,			'_' },
	{ VT52_EnterControlPrint,		'W' },
	{ VT52_ExitControlPrint,		'X' },
	{ VT52_PrintScreen,				']' },
	{ VT52_PrintRow,					'V' },

	{ NULL, NUL },
};



STATIC VOID VT340_enq(struct VT340Console *con);
STATIC VOID VT340_bel(struct VT340Console *con);
STATIC VOID VT340_bs(struct VT340Console *con);
STATIC VOID VT340_ht(struct VT340Console *con);
STATIC VOID VT340_lf(struct VT340Console *con);
STATIC VOID VT340_ff(struct VT340Console *con);
STATIC VOID VT340_cr(struct VT340Console *con);
STATIC VOID VT340_so(struct VT340Console *con);
STATIC VOID VT340_si(struct VT340Console *con);
STATIC VOID VT340_esc(struct VT340Console *con);
STATIC VOID VT340_gs(struct VT340Console *con);
STATIC VOID VT340_del(struct VT340Console *con);
STATIC VOID VT340_csi(struct VT340Console *con);
STATIC VOID VT340_ind(struct VT340Console *con);
STATIC VOID VT340_nel(struct VT340Console *con);
STATIC VOID VT340_hts(struct VT340Console *con);
STATIC VOID VT340_ri(struct VT340Console *con);
STATIC VOID VT340_ss2(struct VT340Console *con);
STATIC VOID VT340_ss3(struct VT340Console *con);
STATIC VOID VT340_dcs(struct VT340Console *con);
STATIC VOID VT340_priv(struct VT340Console *con);


UBYTE PrintableTab[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,
	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,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,
	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
};
#define IsPrintable(c)	(PrintableTab[(c)])

struct SpecialKey SpecialKeys[24] = {	/* nicht vergessen, in funcs. das */
	ENQ,	VT340_enq,							/* IMPORT nachzuführen */
	BEL,	VT340_bel,
	BS,	VT340_bs,
	HT,	VT340_ht,	
	LF,	VT340_lf,
	VT,	VT340_lf,	/* `VT' is handled the same way as `LF' */
	FF,	VT340_ff,
	CR,	VT340_cr,
	SO,	VT340_so,
	SI,	VT340_si,
	ESC,	VT340_esc,
	GS,	VT340_gs,
	DEL,	VT340_del,

	CSI,	VT340_csi,
	IND,	VT340_ind,
	NEL,	VT340_nel,
	HTS,	VT340_hts,
	RI,	VT340_ri,
	SS2,	VT340_ss2,
	SS3,	VT340_ss3,
	DCS,	VT340_dcs,
	OSC,	VT340_priv,
	PM,	VT340_priv,
	APC,	VT340_priv,
};


struct VT340_Parm {
	VOID (*Routine)(struct VT340Console *con, UBYTE *args, ULONG argc);
	UBYTE ServiceClass;
	UBYTE Intermediate;	/* FIRST intermediate..!! */
	UBYTE MatchChar;
	UBYTE Pad;
};

enum { BOTH=1, VT340, VT102 };

struct VT340_Parm ESC_cmds[] = {								/* Mnemonic */
	{ VT340_invokeCSI				, BOTH,	NUL,	'[' },	/* CSI */
	{ VT340_cursordown			, BOTH,	NUL,	'D' },	/* IND */
	{ VT340_cursornextline		, BOTH,	NUL,	'E' },	/* NEL */
	{ VT340_cursorup				, BOTH,	NUL,	'M' },	/* IND */
	{ VT340_settabulator			, BOTH,	NUL,	'H' },	/* HTS */
	{ VT340_setconvert			, VT340,	' ',	'F' },	/* C1 7bit */
	{ VT340_setconvert			, VT340,	' ',	'G' },	/* C1 8bit */
	{ VT340_requestterminal		, BOTH,	NUL,	'Z' },	/* DECID */
	{ VT340_hardreset				, BOTH,	NUL,	'c' },	/* RIS */
	{ VT340_savecursor			, BOTH,	NUL,	'7' },	/* DECSC */
	{ VT340_restorecursor		, BOTH,	NUL,	'8' },	/* DECRC */
	{ VT340_setnumpad				, BOTH,	NUL,	'=' },	/* DECKPNM */
	{ VT340_setnumpad				, BOTH,	NUL,	'>' },	/* DECKPAM */
/* */		
	{ VT340_textscale				, BOTH,	'#',	'3' },	/* DECDHL     top half */
	{ VT340_textscale				, BOTH,	'#',	'4' },	/* DECDHL  bottom half */
	{ VT340_textscale				, BOTH,	'#',	'5' },	/* DECSWL */
	{ VT340_textscale				, BOTH,	'#',	'6' },	/* DECDWL */
	{ VT340_textscale				, BOTH,	'#',	'8' },	/* DECALN */
/* */
	{ VT340_setG0					, BOTH,	'(',	'B' },	/* SCS G0 ASCII			*/
	{ VT340_setG0					, BOTH,	'(',	'0' },	/* SCS G0 GRAPHICS		*/
	{ VT340_setG0					, VT340,	'(',	'A' },	/* SCS G0 ISO SUPPL.		*/
	{ VT340_setG0					, VT340,	'(',	'5' },	/* SCS G0 DEC SUPPL.		*/
	{ VT340_setG0					, VT340,	'(',	'<' },	/* SCS G0 PREF. SUPPL.	*/
	{ VT340_setG0					, VT340,	'(',	'>' },	/* SCS G0 TECHNICAL.		*/
/* */
	{ VT340_setG1					, BOTH,	')',	'B' },	/* SCS G1 ASCII			*/
	{ VT340_setG1					, BOTH,	')',	'0' },	/* SCS G1 GRAPHICS		*/
	{ VT340_setG1					, VT340,	')',	'A' },	/* SCS G1 ISO SUPPL.		*/
	{ VT340_setG1					, VT340,	')',	'5' },	/* SCS G1 DEC SUPPL.		*/
	{ VT340_setG1					, VT340,	')',	'<' },	/* SCS G1 PREF. SUPPL.	*/
	{ VT340_setG1					, VT340,	')',	'>' },	/* SCS G1 TECHNICAL.		*/
/* */
	{ VT340_setG2					, VT340,	'*',	'A' },	/* SCS G2 ISO SUPPL.		*/
	{ VT340_setG2					, VT340,	'*',	'B' },	/* SCS G2 ASCII			*/
	{ VT340_setG2					, VT340,	'*',	'0' },	/* SCS G2 GRAPHICS		*/
	{ VT340_setG2					, VT340,	'*',	'5' },	/* SCS G2 DEC SUPPL.		*/
	{ VT340_setG2					, VT340,	'*',	'<' },	/* SCS G2 PREF. SUPPL.	*/
	{ VT340_setG2					, VT340,	'*',	'>' },	/* SCS G2 TECHNICAL.		*/
/* */
	{ VT340_setG3					, VT340,	'+',	'A' },	/* SCS G3 ISO SUPPL.		*/
	{ VT340_setG3					, VT340,	'+',	'B' },	/* SCS G3 ASCII			*/
	{ VT340_setG3					, VT340,	'+',	'0' },	/* SCS G3 GRAPHICS		*/
	{ VT340_setG3					, VT340,	'+',	'5' },	/* SCS G3 DEC SUPPL.		*/
	{ VT340_setG3					, VT340,	'+',	'<' },	/* SCS G3 PREF. SUPPL.	*/
	{ VT340_setG3					, VT340,	'+',	'>' },	/* SCS G3 TECHNICAL.		*/
/* */
	{ VT340_setG1_GR				, VT340,	NUL,	'~' },	/* LS1R */
/* */
	{ VT340_setG2_GL				, VT340,	NUL,	'n' },	/* LS2  */
	{ VT340_setG2_GR				, VT340,	NUL,	'}' },	/* LS2R */
/* */
	{ VT340_setG3_GL				, VT340,	NUL,	'o' },	/* LS3  */
	{ VT340_setG3_GR				, VT340,	NUL,	'|' },	/* LS3R */
/* */
	{ VT340_setG2_GL_s			, VT340,	NUL,	'N' },	/* SS2  */
	{ VT340_setG3_GL_s			, VT340,	NUL,	'O' },	/* SS3  */
/* */
	{ VT340_invokeDCS				, BOTH,	NUL,	'P' },	/* DCS  */
/* */
	{ VT340_invokePrivate		, BOTH,	NUL,	']' },	/* OSC  */
	{ VT340_invokePrivate		, BOTH,	NUL,	'^' },	/* PM   */
	{ VT340_invokePrivate		, BOTH,	NUL,	'_' },	/* APC  */

	{ NULL, NUL, NUL },	/* der krönende Abschluss..(-: */
};

struct VT340_Parm CSI_cmds[] = {								/* Mnemonic */
	{ VT340_simplecursorup		, BOTH,	NUL,	'A' },	/* CUU */
	{ VT340_simplecursordown	, BOTH,	NUL,	'B' },	/* CUD */
	{ VT340_simplecursorright	, BOTH,	NUL,	'C' },	/* CUF */
	{ VT340_simplecursorleft	, BOTH,	NUL,	'D' },	/* CUB */
	{ VT340_cursorposition		, BOTH,	NUL,	'H' },	/* CUP */
	{ VT340_textmodes				, BOTH,	NUL,	'm' },	/* SGR */
	{ VT340_ANSIsetmodes			, BOTH,	NUL,	'h' },	/* SM ANSI */
	{ VT340_ANSIresetmodes		, BOTH,	NUL,	'l' },	/* RM ANSI */
	{ VT340_DECsetmodes			, BOTH,  '?',	'h' },	/* SM DEC */
	{ VT340_DECresetmodes		, BOTH,  '?',	'l' },	/* RM DEC */

	{ VT340_insertchars			, VT340,	NUL,	'@' },	/* ICH */
	{ VT340_cursornextline		, BOTH,	NUL,	'E' },	/* CNL */
	{ VT340_cursoraboveline		, BOTH,	NUL,	'F' },	/* CPL */
	{ VT340_eraseindisplay		, BOTH,	NUL,	'J' },	/* ED  */
	{ VT340_eraseinline			, BOTH,	NUL,	'K' },	/* EL  */
	{ VT340_sel_eraseindisplay	, VT340,	'?',	'J' },	/* DECSED */
	{ VT340_sel_eraseinline		, VT340,	'?',	'K' },	/* DECSEL */
	{ VT340_insertlines			, BOTH,	NUL,	'L' },	/* IL  */
	{ VT340_deletelines			, BOTH,	NUL,	'M' },	/* DL  */
	{ VT340_deletechars			, BOTH,	NUL,	'P' },	/* DCH */
	{ VT340_ignore					, BOTH,	NUL,	'R' },	/* CPR */
	{ VT340_erasechars			, VT340,	NUL,	'X' },	/* ECH */

	{ VT340_requestterminal		, BOTH,	NUL,	'c' },	/* DA primary   */
	{ VT340_requestterminal		, BOTH,	'>',	'c' },	/* DA secondary */
	{ VT340_cursorposition		, BOTH,	NUL,	'f' },	/* HVP */
	{ VT340_tabclear				, BOTH,	NUL,	'g' },	/* TBC */
	{ VT340_printcontrolmode	, BOTH,  NUL,	'i' },	/* ANSI MC */
	{ VT340_autoprintmode		, BOTH,  '?',	'i' },	/* DEC MC */
	{ VT340_devicestatreport	, BOTH,	NUL,	'n' },	/* DSR */
	{ VT340_devicestatreport	, BOTH,	'?',	'n' },	/* DSR */
	{ VT340_softreset				, VT340,	'!',	'p' },	/* DECSTR */
	{ VT340_setserviceclass		, VT340,	'"',	'p' },	/* DECSCL */
	{ VT340_reportANSIsettings	, VT340,	'$',	'p' },	/* DECRQM ANSI */
	{ VT340_reportDECsettings	, VT340,	'?',	'p' },	/* DECRQM DEC  */
	{ VT340_setselective			, VT340,	'"',	'q' },	/* DECSCA */
	{ VT340_loadleds				, VT102,	NUL,	'q' },	/* DECLL */
	{ VT340_setregion				, BOTH,	NUL,	'r' },	/* DECSTBM */
	{ VT340_reportUPSS			, VT340,	'&',	'u' },	/* DECRQUPSS */
	{ VT340_reportcursorstate	, VT340,	'$',	'u' },	/* DECCIR */
	{ VT340_reportprestate		, VT340,	'$',	'w' },	/* DECRQPSR */
	{ VT340_ignore					, VT340,	NUL,	'y' },	/* DECRPM ANSI */
	{ VT340_ignore					, VT340,	'?',	'y' },	/* DECRPM DEC */
	{ VT340_selectactivedisplay, VT340,	'$',	'}' },	/* DECSASD */
	{ VT340_setstatusline		, VT340,	'$',	'~' },	/* DECSSDT */

	{ NULL, NUL, NUL },		/* der krönende Abschluss..(-: */
};


IMPORT struct	ExecBase			*SysBase;
IMPORT struct	DosLibrary		*DOSBase;
IMPORT struct	GfxBase			*GfxBase;
IMPORT struct	IntuitionBase	*IntuitionBase;
IMPORT struct	Library	*DiskfontBase;
IMPORT struct	Library	*KeymapBase;


VOID VT340_writecon(struct VT340Console *con, UBYTE *buff, LONG buflen)
{
	UWORD i;
	UBYTE c;

	if(con->ustat & U_CURSOR)
		VT340_cursorflip(con);

	if(buflen == -1)
		buflen = strlen(buff);

	while(buflen--)
	{
		c = *buff++;

		if(con->pstat & P_ANSI_MODE)	/* VT-102 or VT-340 */
		{
/*
*			if(con->inTEK)
*			{
*				if(TEK_parse(con, c))
*					continue;
*			}
*/

			if(con->inPrivate)
			{
			/* 'OSC' 'PM' 'APC' is cancelled only by an 'ST' or 'ESC /' */

				if(c == ST  ||  (con->lastPRIVc == ESC && c == '/'))
				{
					con->lastPRIVc = '\0';
					con->inPrivate = FALSE;
					VT340_locked(con, FALSE);
				}
				else
					con->lastPRIVc = c;

				continue;
			}

			if(c == CAN  ||  c == SUB)
			{
				VT340_cancel(con);
				if(c == SUB)
				{
				/* do this tricky reverse question-mark */
					VT340_simplecursorright(con, "\001", 0);
					VT340_writecon(con, "\033""7\010\033+>\033oR\033""8", -1);
				}
				continue;
			}

			if(con->inESC  &&  (c >= 32  &&  c < 127))
			{
				if(c < '0')
				{
					if(con->icnt < MAXINTER)
					{
						con->inter[con->icnt] = c;		/* something like '#', etc. */
						con->icnt++;
						con->inter[con->icnt] = NUL;	/* clear next intermediate */
					}
					continue;
				}

				for(i=0; ESC_cmds[i].Routine; i++)
				{
					if(				c == ESC_cmds[i].MatchChar		&&
						con->inter[0] == ESC_cmds[i].Intermediate)
					{
						if(ESC_cmds[i].ServiceClass != BOTH)
						{
							if(con->pstat & P_VT340_MODE  &&  ESC_cmds[i].ServiceClass == VT102)
								break;
							else
							{
								if(!(con->pstat & P_VT340_MODE)  &&  ESC_cmds[i].ServiceClass == VT340)
									break;
							}
						}

						if(con->ordc)
							VT340_textout(con);

						con->inESC = ESC_cmds[i].MatchChar;
						ESC_cmds[i].Routine(con, con->args, con->argc);
						break;
					}
				}
				con->inESC = FALSE;
				continue;
			}

			if(con->inCSI  &&  (c >= 32  &&  c < 127))
			{
				if(c < '@')
				{
					if(c >= '0'  &&  c <= '9')	/* Parameter.. */
					{
						con->args[con->argc] = con->args[con->argc] * 10;
						con->args[con->argc] += c - '0';
						continue;
					}

					if(c == ';')					/* Parameter-TrennZeichen */
					{
						con->args[++con->argc] = 0;
						if(con->argc > MAXARGS)
							con->argc = MAXARGS;
						continue;
					}

					if(con->icnt < MAXINTER)
					{
						con->inter[con->icnt++] = c;	/* something like '?', etc. */
						con->inter[con->icnt] = NUL;	/* clear next intermediate */
					}
					continue;
				}

				for(i=0; CSI_cmds[i].Routine; i++)
				{
					if(				c == CSI_cmds[i].MatchChar		&&
						con->inter[0] == CSI_cmds[i].Intermediate)
					{
						if(CSI_cmds[i].ServiceClass != BOTH)
						{
							if(con->pstat & P_VT340_MODE  &&  CSI_cmds[i].ServiceClass == VT102)
								break;
							else
							{
								if(!(con->pstat & P_VT340_MODE)  &&  CSI_cmds[i].ServiceClass == VT340)
									break;
							}
						}

						if(con->ordc)
							VT340_textout(con);

						con->inCSI = CSI_cmds[i].MatchChar;
						CSI_cmds[i].Routine(con, con->args, con->argc);
						break;
					}
				}
				con->inCSI = FALSE;
				continue;
			}

			if(con->inDCS)	/* 'DCS' is canceled by a CAN ; SUB ; ESC ; ST */
			{
			/* CAN & SUB are trapped above */
				con->inDCS = (c != ST  &&  c != ESC);
				if(con->inDCS == FALSE)
					VT340_locked(con, FALSE);
				continue;
			}
		}

		else	/* VT-52 */
		{
			if(c == CAN  ||  c == SUB)
			{
				VT340_cancel(con);
				continue;
			}

			c &= ~(0x80);	/* kill possible hi-bit */

			if(con->inESC  &&  c >= 32)
			{
				if(c == 'Y'  ||  con->VT52_dca)	/* Direct Cursor Address */
				{
					if(con->VT52_dca == FALSE)
						con->VT52_dca = TRUE;
					else
					{
						con->args[con->argc++] = c;
						con->args[con->argc] = NUL;
						if(con->argc == 2)
						{
							con->args[0]	-= 31;
							con->args[1]	-= 31;
							con->inESC		= 'Y';	/* compatibility rules.. */
							VT340_cursorposition(con, con->args, con->argc);
							con->VT52_dca	= FALSE;
							con->inESC		= FALSE;
						}
					}
					continue;
				}

				else	/* regular command */
				{
					for(i=0; VT52_cmds[i].Routine; i++)
					{
						if(c == VT52_cmds[i].MatchChar)
						{
							if(con->ordc)
								VT340_textout(con);

							con->inESC = c;
							VT52_cmds[i].Routine(con, con->args, con->argc);
							break;
						}
					}

					con->inESC = FALSE;
				}

				continue;
			}
		}

		if(IsPrintable(c))
		{
			UWORD lim;

			lim = con->columns;

			if(*(con->rows + con->row))
				lim >>= 1;

			if(!con->ordc)
				con->ordcol = con->col;
			con->ordtext[con->ordc++] = c;
			con->col++;

			if(con->fstat & F_GXGL)
			{
				VT340_textout(con);
				VT340_setlset(con, con->slset);
				con->fstat &= ~F_GXGL;
			}

			if(con->col > lim)
			{
				if(con->ordc)
					VT340_textout(con);

				if(con->tstat & T_WRAP)
					VT340_cursornextline(con, "\001", 0);
				else
					con->col = lim;
			}
		}
		else	/* char is a control-char.. */
		{
			if(con->special_map[c] != -1)
			{
				if(con->ordc)
					VT340_textout(con);

				SpecialKeys[con->special_map[c]].Routine(con);
			}
		}
	}


	if(con->ordc)
		VT340_textout(con);

	if(con->ustat & U_CURSOR)
		VT340_cursorflip(con);
}



VOID VT340_textout(struct VT340Console *con)
{
	UWORD col, s_col;
	WORD  chars;
	UBYTE  width;

	col	= con->ordcol;
	chars	= con->ordc;
	width	= *(con->rows + con->row);

	if(width)
	{
		col <<= 1;
		col--;
		if(con->ustat & U_INSERT)
		{
			UBYTE args[1]; 

			s_col = con->col;
			con->col = col;
			args[0] = chars << 1;
			VT340_insertchars(con, args, 1);
			con->col = s_col;
		}
	}
	else
	{
		if(con->ustat & U_INSERT)
		{
			UBYTE args[1]; 

			s_col = con->col;
			con->col = col;
			args[0] = chars;
			VT340_insertchars(con, args, 1);
			con->col = s_col;
		}
	}

	Move(con->rp, (col - 1) * XSIZE,
	 con->row * con->ysize - (FONT_YSIZE - BOTLINE));

	if(con->attr & M_INVERSID)
	{
		SetDrMd(con->rp, JAM2|INVERSVID);
		Text(con->rp, con->ordtext, con->ordc);
		SetDrMd(con->rp, JAM2);
	}
	else
		Text(con->rp, con->ordtext, con->ordc);

	if(width)
	{
		if(col + (chars << 1) > (con->columns+1))
			chars = ((con->columns+1) - col) >> 1;
		if(chars > 0)
			VT220_stretch(con->rp, (col - 1) * XSIZE, (con->row - 1) * con->ysize,
                chars * XSIZE, con->ysize, width);
    }

	RasterPutString(con, con->ordtext, con->ordc, con->ordcol-1);

	con->ordc = 0;
}


VOID VT340_scrollarea(struct VT340Console *con, WORD direction, UWORD top, UWORD bot)
{
/* delta X => 0 */
/*	     x1 => 0 */
	UWORD y1, x2, y2;

	RasterScroll_V(con, direction, top-1, bot);

	y1 = (top - 1) * con->ysize;
	y2 = bot * con->ysize - 1;
	x2 = con->width - 1;

	if(con->pstat & P_SMOOTH_SCROLL)
	{
		UWORD i, cnt;

		cnt = abs(direction) * con->ysize;

		for(i=0; i<cnt; i++)
		{
			WaitTOF();
			ScrollRaster(con->rp, 0, direction, 0, y1, x2, y2);
		}
	}
	else
	{
		con->io->xem_window->Flags |= RMBTRAP;
		ScrollRaster(con->rp, 0, direction * con->ysize, 0, y1, x2, y2);
		con->io->xem_window->Flags &= ~RMBTRAP;
	}
}


STATIC VOID VT340_enq(struct VT340Console *con)
{
	if(con->answer_back[0])
		con->io->xem_swrite(con->answer_back, -1);
}

STATIC VOID VT340_bel(struct VT340Console *con)
{
	con->io->xem_tbeep(1, 0);
}

STATIC VOID VT340_bs(struct VT340Console *con)
{
	if(con->col > 1)
	{
		con->col--;
		if(con->pstat & P_DESTRUCTIVEBS)
			VT340_suppdeletechars(con, 1);
	}
}

STATIC VOID VT340_ht(struct VT340Console *con)
{
	while(con->col < con->columns)
	{
		con->col++;
		if(con->tabs[con->col])
			break;
	}
}

STATIC VOID VT340_lf(struct VT340Console *con)
{
	if(con->ustat & U_NEWLINE)
		VT340_cursornextline(con, "\001", 0);
	else
		VT340_cursordown(con, "\001", 0);
}

STATIC VOID VT340_ff(struct VT340Console *con)
{
	if(con->pstat & P_DESTRUCTIVEFF)
	{
		RasterEraseScreen(con, 2);
		VT340_eraseactivescreen(con);
		con->row = con->firstline;
		con->col = 1;
	}
	else
		VT340_lf(con);
}

STATIC VOID VT340_cr(struct VT340Console *con)
{
	con->col = 1;
}

STATIC VOID VT340_so(struct VT340Console *con)
{
	if(con->pstat & P_ANSI_MODE)
		VT340_setlset(con, 1);
}

STATIC VOID VT340_si(struct VT340Console *con)
{
	if(con->pstat & P_ANSI_MODE)
		VT340_setlset(con, 0);
}

STATIC VOID VT340_esc(struct VT340Console *con)
{
	VT340_invokeESC(con, NULL, NUL);
}

STATIC VOID VT340_gs(struct VT340Console *con)
{
	con->inTEK = TRUE;

	if(con->TEKscreen)
	{
		ScreenToFront(con->TEKscreen);
		con->TEKmainmode = MOVE;
	}
}

STATIC VOID VT340_del(struct VT340Console *con)
{
	if(con->pstat & P_DESTRUCTIVEDEL)
		VT340_suppdeletechars(con, 1);
}

STATIC VOID VT340_csi(struct VT340Console *con)
{
	VT340_invokeCSI(con, NULL, 0);
}

STATIC VOID VT340_ind(struct VT340Console *con)
{
	VT340_cursordown(con, "\001", 0);
}

STATIC VOID VT340_nel(struct VT340Console *con)
{
	VT340_cursornextline(con, "\001", 0);
}

STATIC VOID VT340_hts(struct VT340Console *con)
{
	VT340_settabulator(con, NULL, NUL);
}

STATIC VOID VT340_ri(struct VT340Console *con)
{
	VT340_cursorup(con, "\001", 0);
}

STATIC VOID VT340_ss2(struct VT340Console *con)
{
	con->slset = con->lset;
	con->fstat |= F_GXGL;
	VT340_setlset(con, 2);
}

STATIC VOID VT340_ss3(struct VT340Console *con)
{
	con->slset = con->lset;
	con->fstat |= F_GXGL;
	VT340_setlset(con, 3);
}

STATIC VOID VT340_dcs(struct VT340Console *con)
{
	VT340_invokeDCS(con, NULL, NUL);
}

STATIC VOID VT340_priv(struct VT340Console *con)
{
	VT340_invokePrivate(con, NULL, NUL);
}


/* <EOB> */