/************************************************************************/
/* TITLE	: LINE.C						*/
/* Function	: Process LINE GRAPHICS PACK				*/
/*									*/
/* Project #	: JAGUAR CD+G						*/
/* Programmer	: Pradip K Fatehpuria	11/10/93			*/
/*									*/
/* COPYRIGHT(c) 1992,1993 Atari Computer Corporation			*/
/* UNATHORIZED REPRODUCTION, ADAPTATION, DISTRIBUTION, PERFORMANCE OR	*/
/* DISPLAY OF THIS COMPUTER PROGRAM OR THE ASSOCIATED AUDIOVISUAL WORK	*/
/* IS STRICTLY PROHIBITED.						*/
/* ALL RIGHTS RESERVED.							*/
/************************************************************************/

#include	"defs.h"
#include	"packbind.h"

/* -------------------------------------------------------------------- */

#define	INST_LINE_FONT		0x0004
#define	INST_LINE_SCROLL	0x000C

/* -------------------------------------------------------------------- */

extern	unsigned short	*fntdata;

extern	unsigned short	LnColTbl[];

extern	short	BldObFlag;

extern	unsigned short	*CurPack;

extern	short	CDGType;

extern	unsigned short	ScrlColr;

extern	short	lnPH;
extern	short	lnPV;

extern	short	lnCOPH;
extern	short	lnCOPV;

/* -------------------------------------------------------------------- */

extern	unsigned char	mess[];

/* -------------------------------------------------------------------- */

static	void	opnlngrf( void );
static	void	clslngrf( void );

static	void	linefont( void );
static	void	linescrl( void );

/************************************************************************/
/************************************************************************/

/* -----------------------------------------------------------------------
 */

void	procline()
{
static	unsigned short	func_items[] =
	{
	INST_LINE_FONT,
	INST_LINE_SCROLL,
	-1
	};
static	void	(*func_table[])( void ) =
	{
	linefont,
	linescrl,
	};

	procfunc(CurPack[1], func_items, func_table);
	return;
}

/* -----------------------------------------------------------------------
 */

static	void	opnlngrf()
{
	if (CDGType & TYPE_LINE_GRAPHICS)
		return;

	clrlndsp(LINECOL_BG);
	clrlngrf(LINECOL_BG);
	setlngrf(TRUE);
	CDGType |= TYPE_LINE_GRAPHICS;
	BldObFlag = TRUE;
	return;
}

/* -----------------------------------------------------------------------
 * The LINE-GRAPHICS mode WRITE-FONT instruction (4)
 */

static	void	linefont()
{
register unsigned short	*pack = CurPack;
register unsigned short	*dp = fntdata;
register unsigned short	bg_col;
register unsigned short	fg_col;
register unsigned short	d;
register short	x, y;
register short	i;

	opnlngrf();

	bg_col = LnColTbl[ (pack[4] & 0x0007) ];
	fg_col = LnColTbl[ (pack[5] & 0x0007) ];

	x = (pack[7] & 0x003F);
	y = (pack[6] & 0x0003);

	for (i = 8 ; i < 20 ; i++)
	{
		d = pack[i];

		*dp++ = ((d & 0x20) ? fg_col : bg_col);
		*dp++ = ((d & 0x10) ? fg_col : bg_col);
		*dp++ = ((d & 0x08) ? fg_col : bg_col);
		*dp++ = ((d & 0x04) ? fg_col : bg_col);
		*dp++ = ((d & 0x02) ? fg_col : bg_col);
		*dp++ = ((d & 0x01) ? fg_col : bg_col);
	}
	bltfnt16(x,y,0);
	cp2lndsp();
	return;
}

/* -----------------------------------------------------------------------
 * The LINE-GRAPHICS mode WRITE-SCROLL instruction (12)
 */

static	void	linescrl()
{
register unsigned short	*pack = CurPack;
register short	coph, copv;

	opnlngrf();

	ScrlColr = LnColTbl[ (pack[4] & 0x0007) ];

	lnPH = (pack[5] & 0x0007);
	lnPV = (pack[6] & 0x000F);

	coph = (pack[5] & 0x0030);
	copv = (pack[6] & 0x0030);

	lnCOPH = ((coph == COPH_RIGHT) ? 6 : ((coph == COPH_LEFT) ? -6 : 0));
	lnCOPV = ((copv == COPV_DOWN) ? 12 : ((copv == COPV_UP) ? -12 : 0));

	cp2lndsp();

	lnCOPH = 0;
	lnCOPV = 0;
	return;
}

/************************************************************************/
/*	END OF FILE							*/
/************************************************************************/

