/* Tektronix 4695 special printer functions */

/******* printer.device/printers/Tektronix_4695_special_functions **********
 *
 *	Name
 *	Tektronix 4695 special functions implemented:
 *
 *	aRIN, aSLRM, aSFC
 *************************************************************************/

#include	"exec/types.h"
#include	"devices/printer.h"
#include	"devices/prtbase.h"

extern struct PrinterData *PD;

long
DoSpecial(command,outputBuffer,vline,currentVMI,crlfFlag,Parms)
register char outputBuffer[];
register UWORD *command;

register BYTE *vline;
register UBYTE *currentVMI;	/* used for color on this printer */
BYTE *crlfFlag;
UBYTE Parms[];
{
	register int x = 0;
	register int y = 0;
	static BYTE ISOcolorTable[10] = 
		{'1','3','5','4','7','2','6','0','1','1'};
	static unsigned char initMarg[] = "\033H001090";

	if(*command==aRIN) {
		*currentVMI = 0x70;	/* white background, black text */
		outputBuffer[x++] = '\015';
		outputBuffer[x++] = '\012';

		Parms[0] = (PD->pd_Preferences.PrintLeftMargin);
		Parms[1] = (PD->pd_Preferences.PrintRightMargin);
		*command = aSLRM;
	}

	if(*command==aSLRM) {
		*Parms += 4;
		if (Parms[0]<5) 
			Parms[0] = 5;

		Parms[1] += 5;
		if (Parms[1]>90) 
			Parms[1] = 90;

		initMarg[4] = (char)((Parms[0]/10)+'0');
		initMarg[5] = (char)((Parms[0]-(UBYTE)(Parms[0]/10)*10)+'0');
		initMarg[6] = (char)((Parms[1]/10)+'0');
		initMarg[7] = (char)((Parms[1]-(UBYTE)(Parms[1]/10)*10)+'0');
		while (y<10) 
			outputBuffer[x++] = initMarg[y++];
		return(x);
	}

	if(*command==aSFC) {
		if (Parms[0]==39) 
			Parms[0] = 30;	/* set defaults */
		if (Parms[0]==49) 
			Parms[0] = 47;

		if (Parms[0]<40) 
			*currentVMI = ((*currentVMI)&240)+(Parms[0]-30);
		else 
			*currentVMI = ((*currentVMI)&15)+((Parms[0]-40)*16);

		outputBuffer[x++] = '\033';
		outputBuffer[x++] = 'C';
		outputBuffer[x++] = ISOcolorTable[(*currentVMI)&15];
		outputBuffer[x++] = ISOcolorTable[(((*currentVMI)&240)/16)];
		return(x);
	}

	if(*command==aRIS) 
		PD->pd_PWaitEnabled = 253;

	return(0);
}
