// **************************************************************************
// **************************************************************************
// **************************************************************************
// **                                                                      **
// ** SHELLGFX.C                                                    MODULE **
// **                                                                      **
// ** Shell graphics code.                                                 **
// **                                                                      **
// ** Last modified : 03 Mar 1998 by John Brandwood                        **
// **                                                                      **
// **************************************************************************
// **************************************************************************
// **************************************************************************

// Game's N64 header files.

#include "generic.h"
#include "gameinc.h"

// John's N64 header files.

#include "teamdata.h"

#include "shell.h"
#include "shellgfx.h"

//
// DEFINITIONS
//

#define	G_CC_DECALRGB_PRIMA 0,0,0,TEXEL0,TEXEL0,0,PRIMITIVE,0

//
// GLOBAL VARIABLES
//

extern	SI                  asi__gFontBtn [16][2];

global	int                 si___gWindowX;
global	int                 si___gWindowY;
global	int                 si___gWindowW;
global	int                 si___gWindowH;

global	Vtx *               pcl__gVtx;
static	Vtx                 acl__sVtx[448*2];
static	SI                  si___sVtx;

static	SI                  fl___sMsgBoxTtl;

global	UI                  ui___gCurPipeSync;
global	UI                  ui___gCurBlendAlpha;
global	UI                  ui___gCurAlphaCompare;
global	UI                  ui___gCurRenderMode1;
global	UI                  ui___gCurRenderMode2;
global	UI                  ui___gCurCombineMode1;
global	UI                  ui___gCurCombineMode2;
global	UI                  ui___gCurTextureEnable;
global	UI                  ui___gCurTexturePersp;
global	UI                  ui___gCurTextureFilter;

global	UI                  ui___gCurPalette;
global	UB *                pub__gCurTexture;



//
// STATIC VARIABLES
//
int RCColorR, RCColorG, RCColorB, RCColorA;

//
// STATIC FUNCTION PROTOTYPES
//


void SetRCColors(int r, int g, int b, int a)
{

	RCColorR = r;
	RCColorG = g;
	RCColorB = b;
	RCColorA = a;

}


// **************************************************************************
// **************************************************************************
// **************************************************************************
//	GLOBAL FUNCTIONS
// **************************************************************************
// **************************************************************************
// **************************************************************************



// **************************************************************************
// * NextVtxList ()                                                         *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  -                                                              *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

global	void                NextVtxList             (void)

	{
	// Reset vertex list pointer.

	si___sVtx = (si___sVtx ^ 1) & 1;
	pcl__gVtx = &acl__sVtx[448*si___sVtx];

	// All Done.

	return;
	}



// **************************************************************************
// * ResetRenderStatus ()                                                   *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  Gfx *   ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

global	Gfx *               ResetRenderStatus       (
								Gfx *               gp)

	{
	// Initialize status variables.

	ui___gCurPalette = -1;
	pub__gCurTexture = NULL;

	// Initialize drawing mode.

	gDPPipeSync(gp++);

	gDPSetTextureLUT(gp++, G_TT_NONE);

	gDPSetBlendColor(gp++,
		0x00,	// r
		0x00,	// g
		0x00,	// b
		0x10u);	// a

	gDPSetTexturePersp(gp++,
		G_TP_NONE);

	gDPSetTextureFilter(gp++,
		G_TF_POINT);

	gSPTexture(gp++,
		0x8000,						// s scale 0.16
		0x8000,						// t scale 0.16
		0,							// mipmap levels
		G_TX_RENDERTILE,			// tile number
		G_ON);						// enable

	// All Done.

	return (gp);
	}



// **************************************************************************
// * SetXXXXXXXX ()                                                         *
// **************************************************************************
// * Wrappers for N64 library functions                                     *
// **************************************************************************
// * Inputs  Gfx *   ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

global	Gfx *               SetPalette              (
								Gfx *               gp,
								UI                  ui___Palette)
{
	
//	if (ui___gCurPalette != ui___Palette) commenting this fixes problems with shadow fonts/photos in substitute screen
	{
		ui___gCurPalette = ui___Palette;

		if (ui___gCurPalette == NULL)
		{
			gDPSetTextureLUT(gp++, G_TT_NONE);
		}
		else
		{
			gDPSetTextureLUT(gp++, G_TT_RGBA16);
			gDPLoadTLUT_pal256(gp++, ui___gCurPalette);
		}
	}
	return (gp);
}

/*
global	Gfx *               SetPipeSync             (
								Gfx *               gp)
	{
	if (ui___gCurPipeSync == 0)
		{
		ui___gCurPipeSync = 1;

		gDPPipeSync(gp++);
		}
	return (gp);
	}

global	Gfx *               SetBlendAlpha           (
								Gfx *               gp,
								UI                  ui___Alpha)
	{
	if (ui___gCurBlendAlpha != ui___Alpha)
		{
		ui___gCurBlendAlpha = ui___Alpha;

		gp = SetPipeSync(gp);

		gDPSetBlendColor(gp++,
			0x00,					// r
			0x00,					// g
			0x00,					// b
			ui___gCurBlendAlpha);	// a
		}
	return (gp);
	}

global	Gfx *               SetAlphaCompare         (
								Gfx *               gp,
								UI                  ui___Compare)
	{
	if (ui___gCurAlphaCompare != ui___Compare)
		{
		ui___gCurAlphaCompare = ui___Compare;

		gp = SetPipeSync(gp);

		gDPSetAlphaCompare(gp++,
			ui___gCurAlphaCompare);
		}
	return (gp);
	}

global	Gfx *               SetRenderMode           (
								Gfx *               gp,
								UI                  ui___Mode1,
								UI                  ui___Mode2)
	{
	if ((ui___gCurRenderMode1 != ui___Mode1) ||
		(ui___gCurRenderMode2 != ui___Mode2))
		{
		ui___gCurRenderMode1 = ui___Mode1;
		ui___gCurRenderMode2 = ui___Mode2;

		gp = SetPipeSync(gp);

		gDPSetRenderMode(gp++,
			ui___gCurRenderMode1,
			ui___gCurRenderMode2);
		}
	return (gp);
	}

global	Gfx *               SetCombineMode          (
								Gfx *               gp,
								UI                  ui___Mode1,
								UI                  ui___Mode2)
	{
	if (ui___gCurCombineMode1 != ui___Mode1)
		{
		ui___gCurCombineMode1 = ui___Mode1;
		ui___gCurCombineMode2 = ui___Mode2;

		gp = SetPipeSync(gp);

//		gDPSetCombineMode(gp++,
//			ui___CurCombineMode1,
//			ui___CurCombineMode2);
		}
	return (gp);
	}

global	Gfx *               SetTextureEnable        (
								Gfx *               gp,
								UI                  ui___Flag)
	{
	if (ui___gCurTextureEnable != ui___Flag)
		{
		ui___gCurTextureEnable = ui___Flag;

		gp = SetPipeSync(gp);

		gSPTexture(gp++,
			0x8000,						// s scale 0.16
			0x8000,						// t scale 0.16
			0,							// mipmap levels
			G_TX_RENDERTILE,			// tile number
			ui___gCurTextureEnable);	// enable
		}
	return (gp);
	}

global	Gfx *               SetTexturePersp         (
								Gfx *               gp,
								UI                  ui___Flag)
	{
	if (ui___gCurTexturePersp != ui___Flag)
		{
		ui___gCurTexturePersp = ui___Flag;

		gp = SetPipeSync(gp);

		gDPSetTexturePersp(gp++,
			ui___gCurTexturePersp);
		}
	return (gp);
	}

global	Gfx *               SetTextureFilter        (
								Gfx *               gp,
								UI                  ui___Flag)
	{
	if (ui___gCurTextureFilter != ui___Flag)
		{
		ui___gCurTextureFilter = ui___Flag;

		gp = SetPipeSync(gp);

		gDPSetTextureFilter(gp++,
			ui___gCurTextureFilter);
		}
	return (gp);
	}
*/



// **************************************************************************
// **************************************************************************
// **************************************************************************
// **************************************************************************



// **************************************************************************
// * RenderPhoto ()                                                         *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  Gfx *   ?                                                      *
// *         UB *    ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************


global	Gfx *               RenderPhoto             (
								Gfx *               gp,
								UW *                puw__Img,
								int                 x,
								int                 y)

	{
	// Local Variables.

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Initialize textured drawing.

	gDPPipeSync(gp++);

	gDPSetAlphaCompare( gp++, G_AC_THRESHOLD );
	gDPSetBlendColor( gp++, 0, 0, 0, 128 );

	gp = SetPalette(gp, NULL);
// above didn't always work - NULL usually does folowing line  3/30/99 mjk
//	gDPSetTextureLUT(gp++, G_TT_NONE);	fixed one thing, broke another

	gDPSetRenderMode(gp++,
			G_RM_OPA_SURF,
			G_RM_OPA_SURF2);

	gDPSetCombineMode(gp++,
			G_CC_DECALRGBA,
			G_CC_DECALRGBA);

	// Render 64x56 photo.

	pub__gCurTexture = NULL;

	gDPLoadTextureBlock(gp++,
		&puw__Img[64*0],
		G_IM_FMT_RGBA,
		G_IM_SIZ_16b,
		64,
		32,
		0,
		G_TX_CLAMP,
		G_TX_CLAMP,
		6,
		5,
		G_TX_NOLOD,
		G_TX_NOLOD);

	gSPTextureRectangle(gp++,
		(x     ) << 2,
		(y +  0) << 2,
		(x + 64) << 2,
		(y + 32) << 2,
		G_TX_RENDERTILE,
		0,
		0,
		1 << 10,
		1 << 10);

	gDPLoadTextureBlock(gp++,
		&puw__Img[64*32],
		G_IM_FMT_RGBA,
		G_IM_SIZ_16b,
		64,
		PHOTO_H-32,
		0,
		G_TX_CLAMP,
		G_TX_CLAMP,
		6,
		5,
		G_TX_NOLOD,
		G_TX_NOLOD);

	gSPTextureRectangle(gp++,
		(x     ) << 2,
		(y + 32) << 2,
		(x + PHOTO_W) << 2,
		(y + PHOTO_H) << 2,
		G_TX_RENDERTILE,
		0,
		0,
		1 << 10,
		1 << 10);

	gDPPipeSync( gp++ );
	gDPSetAlphaCompare( gp++, G_AC_NONE );

	// All Done.

	return (gp);
	}



// **************************************************************************
// * RenderSprite ()                                                        *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  Gfx *   ?                                                      *
// *         UB *    ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

#if 1

global	Gfx *               RenderSprite            (
								Gfx *               gp,
								SprTexture_T *      pcl__Spr,
								UI                  ui___Pal,
								int                 x,
								int                 y)

	{
	// Local Variables.

int                 i,j;
int                 v,w,h;

int                 tw,th;


UB *                pub__Src = (UB *) (pcl__Spr + 1);

	// Don't draw a non-existent sprite.

	if (pcl__Spr == NULL)
	{
		return (gp);
	}

	// Add window offset.

	x = x + si___gWindowX + pcl__Spr->sprX;
	y = y + si___gWindowY + pcl__Spr->sprY;

	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_THRESHOLD);

	if (ui___Pal == (UI) NULL)
	{
		ui___Pal  = (UI) (*pcl__Spr->sprPal);
	}

	gp = SetPalette(gp, ui___Pal);

	gDPSetRenderMode(gp++,
			G_RM_XLU_SURF,
			G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
			G_CC_DECALRGBA,
			G_CC_DECALRGBA);

	// Render the sprite in columns.

	w = pcl__Spr->sprW;

	while (w > 0)
	{
		if ((tw = w) > 64) tw = 64;

		v = y;

		h = pcl__Spr->sprH;

		while (h > 0)
		{
			if ((th = h) > 32) th = 32;

			if ((x+tw) > 0 && (x < 512))
			{
				pub__gCurTexture = NULL;

				gDPLoadTextureBlock(gp++,
					pub__Src,			// ptr (8-byte aligned)
					G_IM_FMT_CI,		// texel fmt
					G_IM_SIZ_8b,		// texel siz
					64,					// w
					32,					// h
					0,					// palette
					G_TX_CLAMP,			// clamp/wrap/mirror s
					G_TX_CLAMP,			// clamp/wrap/mirror t
					6,					// mask s
					5,					// mask t
					G_TX_NOLOD,			// shift s
					G_TX_NOLOD);		// shift t

				if (x < 0)
				{	// clip off-screen to left
					gSPTextureRectangle(gp++,
						(0) << 2,			// ulx  (10.2)
						(v) << 2,			// uly  (10.2)
						(x + tw) << 2,		// lrx  (10.2)
						(v + th) << 2,		// lry  (10.2)
						G_TX_RENDERTILE,	// tile
						-x << 5,			// s    (s10.5)
						0,					// t    (s10.5)
						1 << 10,			// dsdx (s5.10)
						1 << 10);			// dtdy (s5.10)
				}
				else
				{
					gSPTextureRectangle(gp++,
						(x) << 2,			// ulx  (10.2)
						(v) << 2,			// uly  (10.2)
						(x + tw) << 2,		// lrx  (10.2)
						(v + th) << 2,		// lry  (10.2)
						G_TX_RENDERTILE,	// tile
						0,					// s    (s10.5)
						0,					// t    (s10.5)
						1 << 10,			// dsdx (s5.10)
						1 << 10);			// dtdy (s5.10)
				}
			}

			pub__Src += 64*32;

			v += 32;
			h -= 32;
		}

		x += 64;
		w -= 64;
	}

	// All Done.

	return (gp);
}

#else		// -------------------- 1998 version ---------------------------

global	Gfx *               RenderSprite            (
								Gfx *               gp,
								SprTexture_T *      pcl__Spr,
								UI                  ui___Pal,
								int                 x,
								int                 y)

	{
	// Local Variables.

	int                 i;
	int                 j;

	int                 v;
	int                 w;
	int                 h;

	int                 tw;
	int                 th;

	UB *                pub__Src = (UB *) (pcl__Spr + 1);

	// Don't draw a non-existent sprite.

	if (pcl__Spr == NULL)
		{
		return (gp);
		}

	// Add window offset.

	x = x + si___gWindowX + pcl__Spr->sprX;
	y = y + si___gWindowY + pcl__Spr->sprY;

	//

/*
	gp = SetBlendAlpha(gp,
			0x80u);
	gp = SetAlphaCompare(gp,
			G_AC_THRESHOLD);
	gp = SetTextureEnable(gp,
			G_ON);
	gp = SetTexturePersp(gp,
			G_TP_NONE);
	gp = SetTextureFilter(gp,
			G_TF_POINT);
	gp = SetPalette(gp,
			(UI) ui___Pal);
	gp = SetRenderMode(gp,
			G_RM_XLU_SURF,
			G_RM_XLU_SURF2);
	gp = SetCombineMode(gp,
			G_CC_DECALRGBA,
			G_CC_DECALRGBA);
*/

	gDPPipeSync(gp++);

	gDPSetBlendColor(gp++,
		0x00,	// r
		0x00,	// g
		0x00,	// b
		0x80u);	// a

	gDPSetAlphaCompare(gp++,
		G_AC_THRESHOLD);

	gSPTexture(gp++,
		0x8000,						// s scale 0.16
		0x8000,						// t scale 0.16
		0,							// mipmap levels
		G_TX_RENDERTILE,			// tile number
		G_ON);						// enable

	gDPSetTexturePersp(gp++,
			G_TP_NONE);

	gDPSetTextureFilter(gp++,
			G_TF_POINT);

	if (ui___Pal == (UI) NULL)
		{
		ui___Pal  = (UI) (*pcl__Spr->sprPal);
		}

	gDPSetTextureLUT(gp++, G_TT_RGBA16);

	gDPLoadTLUT_pal256(gp++, ui___Pal);

	gDPSetRenderMode(gp++,
			G_RM_XLU_SURF,
			G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
			G_CC_DECALRGBA,
			G_CC_DECALRGBA);

	// Render 512x256 screen in 7 rows.

	w = pcl__Spr->sprW;

	while (w > 0)
		{
		if ((tw = w) > 64) tw = 64;

		v = y;

		h = pcl__Spr->sprH;

		while (h > 0)
			{
			if ((th = h) > 32) th = 32;

			gDPLoadTextureBlock(gp++,
				pub__Src,			// ptr (8-byte aligned)
				G_IM_FMT_CI,		// texel fmt
				G_IM_SIZ_8b,		// texel siz
				64,					// w
				32,					// h
				0,					// palette
				G_TX_CLAMP,			// clamp/wrap/mirror s
				G_TX_CLAMP,			// clamp/wrap/mirror t
				6,					// mask s
				5,					// mask t
				G_TX_NOLOD,			// shift s
				G_TX_NOLOD);		// shift t

			gSPTextureRectangle(gp++,
				(x) << 2,			// ulx  (10.2)
				(v) << 2,			// uly  (10.2)
				(x + tw) << 2,		// lrx  (10.2)
				(v + th) << 2,		// lry  (10.2)
				G_TX_RENDERTILE,	// tile
				0,					// s    (s10.5)
				0,					// t    (s10.5)
				1 << 10,			// dsdx (s5.10)
				1 << 10);			// dtdy (s5.10)

			pub__Src += 64*32;

			v += 32;
			h -= 32;
			}

		x += 64;
		w -= 64;
		}

	// All Done.

	return (gp);
	}


#endif


// **************************************************************************
// * RenderSpriteVarWidth ()   used for options - audio levels              *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  Gfx *   ?                                                      *
// *         UB *    ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

global	Gfx *               RenderSpriteVarWidth   (
								Gfx *               gp,
								SprTexture_T *      pcl__Spr,
								UI                  ui___Pal,
								int                 x,
								int                 y,
								int                 factor,
								int					max
								)

{	// sprite scaled in X to  factor/max	(factor should always be <= max)

	// Local Variables.

	int                 i;
	int                 j;

	int                 v;
	int                 w;
	int                 h;

	int                 tw;
	int                 th;

	UB *                pub__Src = (UB *) (pcl__Spr + 1);

	// Don't draw a non-existent sprite.

	if (pcl__Spr == NULL)
	{
		return (gp);
	}

	// Add window offset.

	x = x + si___gWindowX + pcl__Spr->sprX;
	y = y + si___gWindowY + pcl__Spr->sprY;

	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_THRESHOLD);

	if (ui___Pal == (UI) NULL)
	{
		ui___Pal  = (UI) (*pcl__Spr->sprPal);
	}

	gp = SetPalette(gp, ui___Pal);

	gDPSetRenderMode(gp++,
			G_RM_XLU_SURF,
			G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
			G_CC_DECALRGBA,
			G_CC_DECALRGBA);

	// Render the sprite in columns.

	if (max < 1)
	{
		max = 1;
	}
	
	w = (pcl__Spr->sprW*factor)/max;

	if(w > pcl__Spr->sprW)
	{	// error check & correct
		w = pcl__Spr->sprW;
	}

	while (w > 0)
	{
		if ((tw = w) > 64)
		{
			tw = 64;
		}

		v = y;

		h = pcl__Spr->sprH;

		while (h > 0)
		{
			if ((th = h) > 32) th = 32;

			if ((x > -64) && (x < 512))
			{
				pub__gCurTexture = NULL;

				gDPLoadTextureBlock(gp++,
					pub__Src,			// ptr (8-byte aligned)
					G_IM_FMT_CI,		// texel fmt
					G_IM_SIZ_8b,		// texel siz
					64,					// w
					32,					// h
					0,					// palette
					G_TX_CLAMP,			// clamp/wrap/mirror s
					G_TX_CLAMP,			// clamp/wrap/mirror t
					6,					// mask s
					5,					// mask t
					G_TX_NOLOD,			// shift s
					G_TX_NOLOD);		// shift t

				gSPTextureRectangle(gp++,
					(x) << 2,			// ulx  (10.2)
					(v) << 2,			// uly  (10.2)
					(x + tw) << 2,		// lrx  (10.2)
					(v + th) << 2,		// lry  (10.2)
					G_TX_RENDERTILE,	// tile
					0,					// s    (s10.5)
					0,					// t    (s10.5)
					1 << 10,			// dsdx (s5.10)
					1 << 10);			// dtdy (s5.10)
			}

			pub__Src += 64*32;

			v += 32;
			h -= 32;
		}

		x += 64;
		w -= 64;
	}

	// All Done.

	return (gp);

}




global	Gfx *               RenderSpriteVarHeight   (	// locks bottom Y
								Gfx *               gp,
								SprTexture_T *      pcl__Spr,
								UI                  ui___Pal,
								int                 x,
								int                 y,
								int                 factor,
								int					max
								)

{	// sprite scaled in Y to  factor/max	(factor should always be <= max)

	// Local Variables.

int                 i,j;
int                 v,w,h;
int                 tw,th;
int			scaledh,diffh;
UB *                pub__Src = (UB *) (pcl__Spr + 1);

	// Don't draw a non-existent sprite.

	if (pcl__Spr == NULL)
	{
		return (gp);
	}


	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_THRESHOLD);

	if (ui___Pal == (UI) NULL)
	{
		ui___Pal  = (UI) (*pcl__Spr->sprPal);
	}

	gp = SetPalette(gp, ui___Pal);

	gDPSetRenderMode(gp++,
			G_RM_XLU_SURF,
			G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
			G_CC_DECALRGBA,
			G_CC_DECALRGBA);

	// Render the sprite in columns.

	if (max < 1)
	{
		max = 1;
	}
	
	scaledh = (pcl__Spr->sprH*factor)/max;

	if(scaledh > pcl__Spr->sprH)
	{	// error check & correct
		scaledh = pcl__Spr->sprH;
	}
	
	diffh = pcl__Spr->sprH-scaledh;
//	scaledh = pcl__Spr->sprH-h;

	// Add window offset.

	x = x + si___gWindowX + pcl__Spr->sprX;
	y = y + si___gWindowY + pcl__Spr->sprY;

	w = pcl__Spr->sprW;

	while (w > 0)
	{
		if ((tw = w) > 64)
		{
			tw = 64;
		}

		v = y+diffh;

		pub__Src += 64* (diffh);

		h = scaledh;

		while (h > 0)
		{
			if ((th = h) > 32) th = 32;

			if ((x > -64) && (x < 512))
			{
				pub__gCurTexture = NULL;

				gDPLoadTextureBlock(gp++,
					pub__Src,			// ptr (8-byte aligned)
					G_IM_FMT_CI,		// texel fmt
					G_IM_SIZ_8b,		// texel siz
					64,					// w
					32,					// h
					0,					// palette
					G_TX_CLAMP,			// clamp/wrap/mirror s
					G_TX_CLAMP,			// clamp/wrap/mirror t
					6,					// mask s
					5,					// mask t
					G_TX_NOLOD,			// shift s
					G_TX_NOLOD);		// shift t

				gSPTextureRectangle(gp++,
					(x) << 2,			// ulx  (10.2)
					(v) << 2,			// uly  (10.2)
					(x + tw) << 2,		// lrx  (10.2)
					(v + th) << 2,		// lry  (10.2)
					G_TX_RENDERTILE,	// tile
					0,					// s    (s10.5)
					0,					// t    (s10.5)
					1 << 10,			// dsdx (s5.10)
					1 << 10);			// dtdy (s5.10)
			}

			pub__Src += 64*32;

			v += 32;
			h -= 32;
		}

		x += 64;
		w -= 64;
	}

	// All Done.

	return (gp);

}



// **************************************************************************
// * RenderCorner ()                                                        *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  Gfx *   ?                                                      *
// *         UB *    ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

global	Gfx *               RenderCorner            (
								Gfx *               gp,
								SprTexture_T *      pcl__Spr,
//								UI                  ui___Pal,
								int                 x,
								int                 y)

	{
	// Local Variables.

	int                 i;
	int                 j;

	int                 v;
	int                 w;
	int                 h;

	int                 tw;
	int                 th;

	UB *                pub__Src = (UB *) (pcl__Spr + 1);

	// Don't draw a non-existent sprite.

	if (pcl__Spr == NULL)
	{
		return (gp);
	}

	// Add window offset.

	x = x + si___gWindowX + pcl__Spr->sprX;
	y = y + si___gWindowY + pcl__Spr->sprY;

	//

	gDPPipeSync(gp++);

//	gDPSetPrimColor( gp++, 0, 0, RCColorR, RCColorG, RCColorB, 0 );
	gDPSetPrimColor( gp++, 0, 0, RCColorR, RCColorG, RCColorB, RCColorA );

	gDPSetRenderMode( gp++, G_RM_XLU_SURF, G_RM_XLU_SURF2 );
//	gDPSetRenderMode( gp++, G_RM_OPA_SURF, G_RM_OPA_SURF2 );

	gSPTexture( gp++, 0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON );
	gDPSetTextureLUT( gp++, G_TT_NONE );
	gDPSetAlphaCompare( gp++, G_AC_NONE );


//#define MY_COMBINE    0, 0, 0, 0,  0, 0, 0, TEXEL0
//#define MY_COMBINE TEXEL0, 0, 1, 0,  0, 0, 0, 0
#define MY_COMBINE 0, 0, 0, TEXEL0,  0, 0, 0, 0
//	gDPSetCombineMode( gp++, MY_COMBINE, MY_COMBINE);
	gDPSetCombineMode( gp++, G_CC_MODULATEIDECALA_PRIM, G_CC_MODULATEIDECALA_PRIM);
//	gDPSetCombineMode( gp++, G_CC_DECALRGB, G_CC_DECALRGB);
#undef MY_COMBINE



/**********
	gDPSetAlphaCompare(gp++,
		G_AC_THRESHOLD);

	gDPSetRenderMode(gp++,
			G_RM_XLU_SURF,
			G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
			G_CC_DECALRGBA,
			G_CC_DECALRGBA);
*******/
	// Render the sprite in columns.

	w = pcl__Spr->sprW;

	while (w > 0)
	{
		if ((tw = w) > 64) tw = 64;

		v = y;

		h = pcl__Spr->sprH;

		while (h > 0)
		{
			if ((th = h) > 32) th = 32;

			if ((x > -64) && (x < 512))
			{
				pub__gCurTexture = NULL;

				gDPLoadTextureBlock(gp++,
					pub__Src,			// ptr (8-byte aligned)
//					G_IM_FMT_CI,		// texel fmt
					G_IM_FMT_IA,		// texel fmt
					G_IM_SIZ_8b,		// texel siz
					64,					// w
					32,					// h
					0,					// palette
					G_TX_CLAMP,			// clamp/wrap/mirror s
					G_TX_CLAMP,			// clamp/wrap/mirror t
					6,					// mask s
					5,					// mask t
					G_TX_NOLOD,			// shift s
					G_TX_NOLOD);		// shift t

				gSPTextureRectangle(gp++,
					(x) << 2,			// ulx  (10.2)
					(v) << 2,			// uly  (10.2)
					(x + tw) << 2,		// lrx  (10.2)
					(v + th) << 2,		// lry  (10.2)
					0, //G_TX_RENDERTILE,	// tile
					0,					// s    (s10.5)
					0,					// t    (s10.5)
					1 << 10,			// dsdx (s5.10)
					1 << 10);			// dtdy (s5.10)
				}

			pub__Src += 64*32;

			v += 32;
			h -= 32;
		}

		x += 64;
		w -= 64;
	}

	// All Done.

	gDPPipeSync(gp++);

	gDPSetTextureLUT( gp++, G_TT_RGBA16);

	return (gp);
}




// **************************************************************************
// * RenderSprBit ()                                                        *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  Gfx *   ?                                                      *
// *         UB *    ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

#if 0	//--------------- not needed in Kobe 2  ---------------------


global	Gfx *               RenderSprBit            (
								Gfx *               gp,
								SprTexture_T *      pcl__Spr,
								UI                  ui___Pal,
								int                 x,
								int                 y,
								int                 tx,
								int                 ty,
								int                 tw,
								int                 th)

	{
	// Local Variables.

	int                 i;
	int                 j;

	int                 w;
	int                 h;

	UB *                pub__Src = (UB *) (pcl__Spr + 1);

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_THRESHOLD);

	if (ui___Pal == (UI) NULL)
	{
		ui___Pal  = (UI) (*pcl__Spr->sprPal);
	}

	gp = SetPalette(gp, ui___Pal);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_DECALRGBA,
		G_CC_DECALRGBA);

	// Render a sub-section of the texture.

	if ((x > -64) && (x < 512))
		{
		if (pub__gCurTexture != pub__Src)
			{
			pub__gCurTexture = pub__Src;

			gDPLoadTextureBlock(gp++,
				pub__Src,			// ptr (8-byte aligned)
				G_IM_FMT_CI,		// texel fmt
				G_IM_SIZ_8b,		// texel siz
				64,					// w
				32,					// h
				0,					// palette
				G_TX_CLAMP,			// clamp/wrap/mirror s
				G_TX_CLAMP,			// clamp/wrap/mirror t
				6,					// mask s
				5,					// mask t
				G_TX_NOLOD,			// shift s
				G_TX_NOLOD);		// shift t
			}

		gSPTextureRectangle(gp++,
			(x) << 2,			// ulx  (10.2)
			(y) << 2,			// uly  (10.2)
			(x + tw) << 2,		// lrx  (10.2)
			(y + th) << 2,		// lry  (10.2)
			G_TX_RENDERTILE,	// tile
			(tx) << 5,			// s    (s10.5)
			(ty) << 5,			// t    (s10.5)
			1 << 10,			// dsdx (s5.10)
			1 << 10);			// dtdy (s5.10)
		}

	// All Done.

	return (gp);
	}

#endif 	//--------------- not needed in Kobe 2  ---------------------


// **************************************************************************
// * RenderTSprBit ()                                                       *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  Gfx *   ?                                                      *
// *         UB *    ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

#if 0	//--------------- not needed in Kobe 2  ---------------------

global	Gfx *               RenderTSprBit           (
								Gfx *               gp,
								SprTexture_T *      pcl__Spr,
								UI                  ui___Pal,
								int                 x,
								int                 y,
								int                 a,
								int                 tx,
								int                 ty,
								int                 tw,
								int                 th)

	{
	// Local Variables.

	int                 i;
	int                 j;

	int                 w;
	int                 h;

	UB *                pub__Src = (UB *) (pcl__Spr + 1);

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_THRESHOLD);

	if (ui___Pal == (UI) NULL)
		{
		ui___Pal  = (UI) (*pcl__Spr->sprPal);
		}

	gp = SetPalette(gp, ui___Pal);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_DECALRGB_PRIMA,
		G_CC_DECALRGB_PRIMA);

	gDPSetPrimColor(gp++,
		0,		// m
		0,		// l
		0,		// r
		0,		// g
		0,		// b
		a);		// a

	// Render a sub-section of the texture.

	if ((x > -64) && (x < 512))
		{
		if (pub__gCurTexture != pub__Src)
			{
			pub__gCurTexture = pub__Src;

			gDPLoadTextureBlock(gp++,
				pub__Src,			// ptr (8-byte aligned)
				G_IM_FMT_CI,		// texel fmt
				G_IM_SIZ_8b,		// texel siz
				64,					// w
				32,					// h
				0,					// palette
				G_TX_CLAMP,			// clamp/wrap/mirror s
				G_TX_CLAMP,			// clamp/wrap/mirror t
				6,					// mask s
				5,					// mask t
				G_TX_NOLOD,			// shift s
				G_TX_NOLOD);		// shift t
			}

		gSPTextureRectangle(gp++,
			(x) << 2,			// ulx  (10.2)
			(y) << 2,			// uly  (10.2)
			(x + tw) << 2,		// lrx  (10.2)
			(y + th) << 2,		// lry  (10.2)
			G_TX_RENDERTILE,	// tile
			(tx) << 5,			// s    (s10.5)
			(ty) << 5,			// t    (s10.5)
			1 << 10,			// dsdx (s5.10)
			1 << 10);			// dtdy (s5.10)
		}

	// All Done.

	return (gp);
	}

#endif 	//--------------- not needed in Kobe 2  ---------------------


// **************************************************************************
// * RenderTSPR ()                                                          *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  Gfx *   ?                                                      *
// *         UB *    ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

#if 1	//--------------- not needed in Kobe 2  ---------------------

global	Gfx *               RenderTSPR              (
								Gfx *               gp,
								SprTexture_T *      pcl__Spr,
								UI                  ui___Pal,
								int                 x,
								int                 y,
								int                 a)

	{
	// Local Variables.

	int                 i;
	int                 j;

	int                 v;
	int                 w;
	int                 h;

	int                 tw;
	int                 th;

	UB *                pub__Src = (UB *) (pcl__Spr + 1);

	// Don't draw a non-existent sprite.

	if (pcl__Spr == NULL)
		{
		return (gp);
		}

	// Add window offset.

	x = x + si___gWindowX + pcl__Spr->sprX;
	y = y + si___gWindowY + pcl__Spr->sprY;

	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_THRESHOLD);

	if (ui___Pal == (UI) NULL)
	{
		ui___Pal  = (UI) (*pcl__Spr->sprPal);
	}

	gp = SetPalette(gp, ui___Pal);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_DECALRGB_PRIMA,
		G_CC_DECALRGB_PRIMA);

	gDPSetPrimColor(gp++,
		0,		// m
		0,		// l
		0,		// r
		0,		// g
		0,		// b
		a);		// a

	// Render 512x256 screen in 7 rows.

	w = pcl__Spr->sprW;

	while (w > 0)
		{
		if ((tw = w) > 64) tw = 64;

		v = y;

		h = pcl__Spr->sprH;

		while (h > 0)
			{
			if ((th = h) > 32) th = 32;

			pub__gCurTexture = NULL;

			gDPLoadTextureBlock(gp++,
				pub__Src,			// ptr (8-byte aligned)
				G_IM_FMT_CI,		// texel fmt
				G_IM_SIZ_8b,		// texel siz
				64,					// w
				32,					// h
				0,					// palette
				G_TX_CLAMP,			// clamp/wrap/mirror s
				G_TX_CLAMP,			// clamp/wrap/mirror t
				6,					// mask s
				5,					// mask t
				G_TX_NOLOD,			// shift s
				G_TX_NOLOD);		// shift t

			gSPTextureRectangle(gp++,
				(x) << 2,			// ulx  (10.2)
				(v) << 2,			// uly  (10.2)
				(x + tw) << 2,		// lrx  (10.2)
				(v + th) << 2,		// lry  (10.2)
				G_TX_RENDERTILE,	// tile
				0,					// s    (s10.5)
				0,					// t    (s10.5)
				1 << 10,			// dsdx (s5.10)
				1 << 10);			// dtdy (s5.10)

			pub__Src += 64*32;

			v += 32;
			h -= 32;
			}

		x += 64;
		w -= 64;
		}

	// All Done.

	return (gp);
	}

#endif 	//--------------- not needed in Kobe 2  ---------------------


// **************************************************************************
// * RenderTBOX ()                                                          *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  dyn *   ?                                                      *
// *         int     ?                                                      *
// *         Gfx **  ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

global	Gfx *               RenderTBOX              (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h,
								int                 r,
								int                 g,
								int                 b,
								int                 a)

	{
	// Local Variables.

	int                 z;

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Reset projection and modelview matrices for 2D drawing.

	/*
	gDPPipeSync(gp++);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->ballMat)),
		G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->identity)),
		G_MTX_MODELVIEW  | G_MTX_LOAD | G_MTX_NOPUSH);
	*/

	// Draw box.

	z = 20;

	x = x - 512/2;
	y = 240/2 - y;

	pcl__gVtx[0].v.ob[0] = x;		// x
	pcl__gVtx[0].v.ob[1] = y;		// y
	pcl__gVtx[0].v.ob[2] = z;		// z
	pcl__gVtx[0].v.flag  = 0;		// flags
	pcl__gVtx[0].v.tc[0] = 0;		// tx
	pcl__gVtx[0].v.tc[1] = 0;		// ty
	pcl__gVtx[0].v.cn[0] = r;		// r
	pcl__gVtx[0].v.cn[1] = g;		// g
	pcl__gVtx[0].v.cn[2] = b;		// b
	pcl__gVtx[0].v.cn[3] = a;		// a

	pcl__gVtx[1].v.ob[0] = x+w;		// x
	pcl__gVtx[1].v.ob[1] = y;		// y
	pcl__gVtx[1].v.ob[2] = z;		// z
	pcl__gVtx[1].v.flag  = 0;		// flags
	pcl__gVtx[1].v.tc[0] = 0;		// tx
	pcl__gVtx[1].v.tc[1] = 0;		// ty
	pcl__gVtx[1].v.cn[0] = r;		// r
	pcl__gVtx[1].v.cn[1] = g;		// g
	pcl__gVtx[1].v.cn[2] = b;		// b
	pcl__gVtx[1].v.cn[3] = a;		// a

	pcl__gVtx[2].v.ob[0] = x+w;		// x
	pcl__gVtx[2].v.ob[1] = y-h;		// y
	pcl__gVtx[2].v.ob[2] = z;		// z
	pcl__gVtx[2].v.flag  = 0;		// flags
	pcl__gVtx[2].v.tc[0] = 0;		// tx
	pcl__gVtx[2].v.tc[1] = 0;		// ty
	pcl__gVtx[2].v.cn[0] = r;		// r
	pcl__gVtx[2].v.cn[1] = g;		// g
	pcl__gVtx[2].v.cn[2] = b;		// b
	pcl__gVtx[2].v.cn[3] = a;		// a

	pcl__gVtx[3].v.ob[0] = x;		// x
	pcl__gVtx[3].v.ob[1] = y-h;		// y
	pcl__gVtx[3].v.ob[2] = z;		// z
	pcl__gVtx[3].v.flag  = 0;		// flags
	pcl__gVtx[3].v.tc[0] = 0;		// tx
	pcl__gVtx[3].v.tc[1] = 0;		// ty
	pcl__gVtx[3].v.cn[0] = r;		// r
	pcl__gVtx[3].v.cn[1] = g;		// g
	pcl__gVtx[3].v.cn[2] = b;		// b
	pcl__gVtx[3].v.cn[3] = a;		// a

	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetPrimColor(gp++,
		0, 0, r, g, b, a);

	if (a != 0xFF)
		{
		gDPSetRenderMode(gp++,
			G_RM_XLU_SURF,
			G_RM_XLU_SURF2);
		}
	else
		{
		gDPSetRenderMode(gp++,
			G_RM_OPA_SURF,
			G_RM_OPA_SURF2);
		}

	gDPSetCombineMode(gp++,
			G_CC_PRIMITIVE,
			G_CC_PRIMITIVE);

//	gSPSetGeometryMode(gp++,
//		G_SHADE | G_SHADING_SMOOTH);

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 4, 0);

	gSP2Triangles(gp++,
		0, 3, 2, 0, 2, 1, 0, 0);

//	gSPSetGeometryMode(gp++,
//		G_CULL_BACK);

	// Update the vertex pointer.

	pcl__gVtx += 4;

	// All Done.

	return (gp);
	}



// **************************************************************************
// * RenderFDWN ()                                                          *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  dyn *   ?                                                      *
// *         int     ?                                                      *
// *         Gfx **  ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************


#if 0	//--------------- not needed in Kobe 2  ---------------------


global	Gfx *               RenderFDWN              (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h,
								int                 r,
								int                 g,
								int                 b,
								int                 a)

	{
	// Local Variables.

	int                 z;

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Reset projection and modelview matrices for 2D drawing.

	/*
	gDPPipeSync(gp++);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->ballMat)),
		G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->identity)),
		G_MTX_MODELVIEW  | G_MTX_LOAD | G_MTX_NOPUSH);
	*/

	// Draw box.

	z = 20;

	x = x - 512/2;
	y = 240/2 - y;

	pcl__gVtx[0].v.ob[0] = x;		// x
	pcl__gVtx[0].v.ob[1] = y;		// y
	pcl__gVtx[0].v.ob[2] = z;		// z
	pcl__gVtx[0].v.flag  = 0;		// flags
	pcl__gVtx[0].v.tc[0] = 0;		// tx
	pcl__gVtx[0].v.tc[1] = 0;		// ty
	pcl__gVtx[0].v.cn[0] = r;		// r
	pcl__gVtx[0].v.cn[1] = g;		// g
	pcl__gVtx[0].v.cn[2] = b;		// b
	pcl__gVtx[0].v.cn[3] = a;		// a

	pcl__gVtx[1].v.ob[0] = x+w;		// x
	pcl__gVtx[1].v.ob[1] = y;		// y
	pcl__gVtx[1].v.ob[2] = z;		// z
	pcl__gVtx[1].v.flag  = 0;		// flags
	pcl__gVtx[1].v.tc[0] = 0;		// tx
	pcl__gVtx[1].v.tc[1] = 0;		// ty
	pcl__gVtx[1].v.cn[0] = r;		// r
	pcl__gVtx[1].v.cn[1] = g;		// g
	pcl__gVtx[1].v.cn[2] = b;		// b
	pcl__gVtx[1].v.cn[3] = a;		// a

	pcl__gVtx[2].v.ob[0] = x+w;		// x
	pcl__gVtx[2].v.ob[1] = y-h;		// y
	pcl__gVtx[2].v.ob[2] = z;		// z
	pcl__gVtx[2].v.flag  = 0;		// flags
	pcl__gVtx[2].v.tc[0] = 0;		// tx
	pcl__gVtx[2].v.tc[1] = 0;		// ty
	pcl__gVtx[2].v.cn[0] = r;		// r
	pcl__gVtx[2].v.cn[1] = g;		// g
	pcl__gVtx[2].v.cn[2] = b;		// b
	pcl__gVtx[2].v.cn[3] = a/4;		// a

	pcl__gVtx[3].v.ob[0] = x;		// x
	pcl__gVtx[3].v.ob[1] = y-h;		// y
	pcl__gVtx[3].v.ob[2] = z;		// z
	pcl__gVtx[3].v.flag  = 0;		// flags
	pcl__gVtx[3].v.tc[0] = 0;		// tx
	pcl__gVtx[3].v.tc[1] = 0;		// ty
	pcl__gVtx[3].v.cn[0] = r;		// r
	pcl__gVtx[3].v.cn[1] = g;		// g
	pcl__gVtx[3].v.cn[2] = b;		// b
	pcl__gVtx[3].v.cn[3] = a/4;		// a

	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 4, 0);

	gSP2Triangles(gp++,
		0, 3, 2, 0, 2, 1, 0, 0);

//	gSPSetGeometryMode(gp++,
//		G_CULL_BACK);

	// Update the vertex pointer.

	pcl__gVtx += 4;

	// All Done.

	return (gp);
	}

#endif 	//--------------- not needed in Kobe 2  ---------------------


// **************************************************************************
// * RenderFRGT ()                                                          *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  dyn *   ?                                                      *
// *         int     ?                                                      *
// *         Gfx **  ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

#if 0	//--------------- not needed in Kobe 2  ---------------------

global	Gfx *               RenderFRGT              (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h,
								int                 r,
								int                 g,
								int                 b,
								int                 a)

	{
	// Local Variables.

	int                 z;

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Reset projection and modelview matrices for 2D drawing.

	/*
	gDPPipeSync(gp++);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->ballMat)),
		G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->identity)),
		G_MTX_MODELVIEW  | G_MTX_LOAD | G_MTX_NOPUSH);
	*/

	// Draw box.

	z = 20;

	x = x - 512/2;
	y = 240/2 - y;

	pcl__gVtx[0].v.ob[0] = x;		// x
	pcl__gVtx[0].v.ob[1] = y;		// y
	pcl__gVtx[0].v.ob[2] = z;		// z
	pcl__gVtx[0].v.flag  = 0;		// flags
	pcl__gVtx[0].v.tc[0] = 0;		// tx
	pcl__gVtx[0].v.tc[1] = 0;		// ty
	pcl__gVtx[0].v.cn[0] = r;		// r
	pcl__gVtx[0].v.cn[1] = g;		// g
	pcl__gVtx[0].v.cn[2] = b;		// b
	pcl__gVtx[0].v.cn[3] = a;		// a

	pcl__gVtx[1].v.ob[0] = x+w;		// x
	pcl__gVtx[1].v.ob[1] = y;		// y
	pcl__gVtx[1].v.ob[2] = z;		// z
	pcl__gVtx[1].v.flag  = 0;		// flags
	pcl__gVtx[1].v.tc[0] = 0;		// tx
	pcl__gVtx[1].v.tc[1] = 0;		// ty
	pcl__gVtx[1].v.cn[0] = r;		// r
	pcl__gVtx[1].v.cn[1] = g;		// g
	pcl__gVtx[1].v.cn[2] = b;		// b
	pcl__gVtx[1].v.cn[3] = a/4;		// a

	pcl__gVtx[2].v.ob[0] = x+w;		// x
	pcl__gVtx[2].v.ob[1] = y-h;		// y
	pcl__gVtx[2].v.ob[2] = z;		// z
	pcl__gVtx[2].v.flag  = 0;		// flags
	pcl__gVtx[2].v.tc[0] = 0;		// tx
	pcl__gVtx[2].v.tc[1] = 0;		// ty
	pcl__gVtx[2].v.cn[0] = r;		// r
	pcl__gVtx[2].v.cn[1] = g;		// g
	pcl__gVtx[2].v.cn[2] = b;		// b
	pcl__gVtx[2].v.cn[3] = a/4;		// a

	pcl__gVtx[3].v.ob[0] = x;		// x
	pcl__gVtx[3].v.ob[1] = y-h;		// y
	pcl__gVtx[3].v.ob[2] = z;		// z
	pcl__gVtx[3].v.flag  = 0;		// flags
	pcl__gVtx[3].v.tc[0] = 0;		// tx
	pcl__gVtx[3].v.tc[1] = 0;		// ty
	pcl__gVtx[3].v.cn[0] = r;		// r
	pcl__gVtx[3].v.cn[1] = g;		// g
	pcl__gVtx[3].v.cn[2] = b;		// b
	pcl__gVtx[3].v.cn[3] = a;		// a

	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 4, 0);

	gSP2Triangles(gp++,
		0, 3, 2, 0, 2, 1, 0, 0);

//	gSPSetGeometryMode(gp++,
//		G_CULL_BACK);

	// Update the vertex pointer.

	pcl__gVtx += 4;

	// All Done.

	return (gp);
	}
#endif 	//--------------- not needed in Kobe 2  ---------------------



// **************************************************************************
// * RenderFLFT ()                                                          *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  dyn *   ?                                                      *
// *         int     ?                                                      *
// *         Gfx **  ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

#if 0	//--------------- not needed in Kobe 2  ---------------------

global	Gfx *               RenderFLFT              (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h,
								int                 r,
								int                 g,
								int                 b,
								int                 a)

	{
	// Local Variables.

	int                 z;

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Reset projection and modelview matrices for 2D drawing.

	/*
	gDPPipeSync(gp++);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->ballMat)),
		G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->identity)),
		G_MTX_MODELVIEW  | G_MTX_LOAD | G_MTX_NOPUSH);
	*/

	// Draw box.

	z = 20;

	x = x - 512/2;
	y = 240/2 - y;

	pcl__gVtx[0].v.ob[0] = x;		// x
	pcl__gVtx[0].v.ob[1] = y;		// y
	pcl__gVtx[0].v.ob[2] = z;		// z
	pcl__gVtx[0].v.flag  = 0;		// flags
	pcl__gVtx[0].v.tc[0] = 0;		// tx
	pcl__gVtx[0].v.tc[1] = 0;		// ty
	pcl__gVtx[0].v.cn[0] = r;		// r
	pcl__gVtx[0].v.cn[1] = g;		// g
	pcl__gVtx[0].v.cn[2] = b;		// b
	pcl__gVtx[0].v.cn[3] = a/4;		// a

	pcl__gVtx[1].v.ob[0] = x+w;		// x
	pcl__gVtx[1].v.ob[1] = y;		// y
	pcl__gVtx[1].v.ob[2] = z;		// z
	pcl__gVtx[1].v.flag  = 0;		// flags
	pcl__gVtx[1].v.tc[0] = 0;		// tx
	pcl__gVtx[1].v.tc[1] = 0;		// ty
	pcl__gVtx[1].v.cn[0] = r;		// r
	pcl__gVtx[1].v.cn[1] = g;		// g
	pcl__gVtx[1].v.cn[2] = b;		// b
	pcl__gVtx[1].v.cn[3] = a;		// a

	pcl__gVtx[2].v.ob[0] = x+w;		// x
	pcl__gVtx[2].v.ob[1] = y-h;		// y
	pcl__gVtx[2].v.ob[2] = z;		// z
	pcl__gVtx[2].v.flag  = 0;		// flags
	pcl__gVtx[2].v.tc[0] = 0;		// tx
	pcl__gVtx[2].v.tc[1] = 0;		// ty
	pcl__gVtx[2].v.cn[0] = r;		// r
	pcl__gVtx[2].v.cn[1] = g;		// g
	pcl__gVtx[2].v.cn[2] = b;		// b
	pcl__gVtx[2].v.cn[3] = a;		// a

	pcl__gVtx[3].v.ob[0] = x;		// x
	pcl__gVtx[3].v.ob[1] = y-h;		// y
	pcl__gVtx[3].v.ob[2] = z;		// z
	pcl__gVtx[3].v.flag  = 0;		// flags
	pcl__gVtx[3].v.tc[0] = 0;		// tx
	pcl__gVtx[3].v.tc[1] = 0;		// ty
	pcl__gVtx[3].v.cn[0] = r;		// r
	pcl__gVtx[3].v.cn[1] = g;		// g
	pcl__gVtx[3].v.cn[2] = b;		// b
	pcl__gVtx[3].v.cn[3] = a/4;		// a

	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 4, 0);

	gSP2Triangles(gp++,
		0, 3, 2, 0, 2, 1, 0, 0);

//	gSPSetGeometryMode(gp++,
//		G_CULL_BACK);

	// Update the vertex pointer.

	pcl__gVtx += 4;

	// All Done.

	return (gp);
	}


#endif 	//--------------- not needed in Kobe 2  ---------------------


global int shada = 0x000000c0u;	// darker than normal

// **************************************************************************
// * RenderLSHD ()                                                          *
// **************************************************************************
// * Draw left shadow                                                       *
// **************************************************************************
// * Inputs  Gfx *                                                          *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

global	Gfx *               RenderLSHD              (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h)

	{
	// Local Variables.

	int                 z;

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Initialize vertices.

	z = 20;

	x = x - 512/2;
	y = 240/2 - y;

	pcl__gVtx[0].v.ob[0] = x;						// x
	pcl__gVtx[0].v.ob[1] = y;						// y
	pcl__gVtx[0].v.ob[2] = z;						// z
	pcl__gVtx[0].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[0].v.tc[0]) = 0x00000000u;	// txty
//	*((UD *) &pcl__gVtx[0].v.cn[0]) = 0x00000080u;	// rgba
	*((UD *) &pcl__gVtx[0].v.cn[0]) = shada;	// rgba
 
	pcl__gVtx[1].v.ob[0] = x+w;						// x
	pcl__gVtx[1].v.ob[1] = y;						// y
	pcl__gVtx[1].v.ob[2] = z;						// z
	pcl__gVtx[1].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[1].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[1].v.cn[0]) = 0x00000000u;	// rgba

	pcl__gVtx[2].v.ob[0] = x+w;						// x
	pcl__gVtx[2].v.ob[1] = y-h;						// y
	pcl__gVtx[2].v.ob[2] = z;						// z
	pcl__gVtx[2].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[2].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[2].v.cn[0]) = 0x00000000u;	// rgba

	pcl__gVtx[3].v.ob[0] = x;						// x
	pcl__gVtx[3].v.ob[1] = y-h;						// y
	pcl__gVtx[3].v.ob[2] = z;						// z
	pcl__gVtx[3].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[3].v.tc[0]) = 0x00000000u;	// txty
//	*((UD *) &pcl__gVtx[3].v.cn[0]) = 0x00000080u;	// rgba
	*((UD *) &pcl__gVtx[3].v.cn[0]) = shada;	// rgba

	// Initialize drawing mode.

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	// Finally, draw it.

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 4, 0);

	gSP2Triangles(gp++,
		0, 3, 2, 0, 2, 1, 0, 0);

	// Update the vertex pointer.

	pcl__gVtx += 4;

	// All Done.

	return (gp);
	}





global	Gfx *               RenderTSHDa              (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h)

	{
	// Local Variables.

	int                 z;

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Initialize vertices.

	z = 20;

	x = x - 512/2;
	y = 240/2 - y;

	pcl__gVtx[0].v.ob[0] = x;						// x
	pcl__gVtx[0].v.ob[1] = y;						// y
	pcl__gVtx[0].v.ob[2] = z;						// z
	pcl__gVtx[0].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[0].v.tc[0]) = 0x00000000u;	// txty
//	*((UD *) &pcl__gVtx[0].v.cn[0]) = 0x00000080u;	// rgba
	*((UD *) &pcl__gVtx[0].v.cn[0]) = shada;	// rgba

	pcl__gVtx[1].v.ob[0] = x+w;						// x
	pcl__gVtx[1].v.ob[1] = y;						// y
	pcl__gVtx[1].v.ob[2] = z;						// z
	pcl__gVtx[1].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[1].v.tc[0]) = 0x00000000u;	// txty
//	*((UD *) &pcl__gVtx[1].v.cn[0]) = 0x00000080u;	// rgba
	*((UD *) &pcl__gVtx[1].v.cn[0]) = shada;	// rgba

	pcl__gVtx[2].v.ob[0] = x+w;						// x
	pcl__gVtx[2].v.ob[1] = y-h;						// y
	pcl__gVtx[2].v.ob[2] = z;						// z
	pcl__gVtx[2].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[2].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[2].v.cn[0]) = 0x00000000u;	// rgba

	pcl__gVtx[3].v.ob[0] = x;						// x
	pcl__gVtx[3].v.ob[1] = y-h;						// y
	pcl__gVtx[3].v.ob[2] = z;						// z
	pcl__gVtx[3].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[3].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[3].v.cn[0]) = 0x00000000u;	// rgba

	// Initialize drawing mode.

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	// Finally, draw it.

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 4, 0);

	gSP2Triangles(gp++,
		0, 3, 2, 0, 2, 1, 0, 0);

	// Update the vertex pointer.

	pcl__gVtx += 4;

	// All Done.

	return (gp);
	}




// **************************************************************************
// * RenderTSHD ()                                                          *
// **************************************************************************
// * Draw top shadow                                                        *
// **************************************************************************
// * Inputs  Gfx *                                                          *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

global	Gfx *               RenderTSHD              (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h)

	{
	// Local Variables.

	int                 z;

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Initialize vertices.

	z = 20;

	x = x - 512/2;
	y = 240/2 - y;

	pcl__gVtx[0].v.ob[0] = x;						// x
	pcl__gVtx[0].v.ob[1] = y;						// y
	pcl__gVtx[0].v.ob[2] = z;						// z
	pcl__gVtx[0].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[0].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[0].v.cn[0]) = 0x00000080u;	// rgba
//	*((UD *) &pcl__gVtx[0].v.cn[0]) = shada;	// rgba

	pcl__gVtx[1].v.ob[0] = x+w;						// x
	pcl__gVtx[1].v.ob[1] = y;						// y
	pcl__gVtx[1].v.ob[2] = z;						// z
	pcl__gVtx[1].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[1].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[1].v.cn[0]) = 0x00000080u;	// rgba
//	*((UD *) &pcl__gVtx[1].v.cn[0]) = shada;	// rgba

	pcl__gVtx[2].v.ob[0] = x+w;						// x
	pcl__gVtx[2].v.ob[1] = y-h;						// y
	pcl__gVtx[2].v.ob[2] = z;						// z
	pcl__gVtx[2].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[2].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[2].v.cn[0]) = 0x00000000u;	// rgba

	pcl__gVtx[3].v.ob[0] = x;						// x
	pcl__gVtx[3].v.ob[1] = y-h;						// y
	pcl__gVtx[3].v.ob[2] = z;						// z
	pcl__gVtx[3].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[3].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[3].v.cn[0]) = 0x00000000u;	// rgba

	// Initialize drawing mode.

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	// Finally, draw it.

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 4, 0);

	gSP2Triangles(gp++,
		0, 3, 2, 0, 2, 1, 0, 0);

	// Update the vertex pointer.

	pcl__gVtx += 4;

	// All Done.

	return (gp);
	}







// **************************************************************************
// * RenderCSHD ()                                                          *
// **************************************************************************
// * Draw top-left corner shadow                                            *
// **************************************************************************
// * Inputs  Gfx *                                                          *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

global	Gfx *               RenderCSHD              (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h)

	{
	// Local Variables.

	int                 z;
	int                 r = 0x00;
	int                 g = 0x00;
	int                 b = 0x00;

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Initialize vertices.

	z = 20;

	x = x - 512/2;
	y = 240/2 - y;

	pcl__gVtx[0].v.ob[0] = x;						// x
	pcl__gVtx[0].v.ob[1] = y;						// y
	pcl__gVtx[0].v.ob[2] = z;						// z
	pcl__gVtx[0].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[0].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[0].v.cn[0]) = 0x00000080u;	// rgba

	pcl__gVtx[1].v.ob[0] = x+w;						// x
	pcl__gVtx[1].v.ob[1] = y;						// y
	pcl__gVtx[1].v.ob[2] = z;						// z
	pcl__gVtx[1].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[1].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[1].v.cn[0]) = 0x00000080u;	// rgba

	pcl__gVtx[2].v.ob[0] = x+w;						// x
	pcl__gVtx[2].v.ob[1] = y-h;						// y
	pcl__gVtx[2].v.ob[2] = z;						// z
	pcl__gVtx[2].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[2].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[2].v.cn[0]) = 0x00000000u;	// rgba

	pcl__gVtx[3].v.ob[0] = x;						// x
	pcl__gVtx[3].v.ob[1] = y-h;						// y
	pcl__gVtx[3].v.ob[2] = z;						// z
	pcl__gVtx[3].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[3].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[3].v.cn[0]) = 0x00000080u;	// rgba

	// Initialize drawing mode.

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	// Finally, draw it.

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 4, 0);

	gSP2Triangles(gp++,
		0, 3, 2, 0, 2, 1, 0, 0);

	// Update the vertex pointer.

	pcl__gVtx += 4;

	// All Done.

	return (gp);
	}



global	Gfx *               RenderSquareShadows              (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h)
{

	gp = RenderCSHD(gp, x,		y,		12,		7);
	gp = RenderTSHD(gp, x+12,	y,		w-12,	7);
	gp = RenderLSHD(gp, x,		y+7,	12,		h-7);

	return(gp);
}

// **************************************************************************
// * RenderESHD ()                                                          *
// **************************************************************************
// * Draw bottom-right external drop shadow                                 *
// **************************************************************************
// * Inputs  Gfx *                                                          *
// *                                                                        *
// * Output  -                                                              *
// **************************************************************************

global	Gfx *               RenderESHD              (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h)

	{
	// Local Variables.

	int                 z;
	int                 r = 0x00;
	int                 g = 0x00;
	int                 b = 0x00;

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Initialize vertices.

	z = 20;

	x = x - 512/2;
	y = 240/2 - y;

	pcl__gVtx[0].v.ob[0] = x;						// x
	pcl__gVtx[0].v.ob[1] = y;						// y
	pcl__gVtx[0].v.ob[2] = z;						// z
	pcl__gVtx[0].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[0].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[0].v.cn[0]) = 0x00000080u;	// rgba

	pcl__gVtx[1].v.ob[0] = x+w;						// x
	pcl__gVtx[1].v.ob[1] = y;						// y
	pcl__gVtx[1].v.ob[2] = z;						// z
	pcl__gVtx[1].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[1].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[1].v.cn[0]) = 0x00000000u;	// rgba

	pcl__gVtx[2].v.ob[0] = x+w;						// x
	pcl__gVtx[2].v.ob[1] = y-h;						// y
	pcl__gVtx[2].v.ob[2] = z;						// z
	pcl__gVtx[2].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[2].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[2].v.cn[0]) = 0x00000000u;	// rgba

	pcl__gVtx[3].v.ob[0] = x;						// x
	pcl__gVtx[3].v.ob[1] = y-h;						// y
	pcl__gVtx[3].v.ob[2] = z;						// z
	pcl__gVtx[3].v.flag  = 0;						// flags
	*((UD *) &pcl__gVtx[3].v.tc[0]) = 0x00000000u;	// txty
	*((UD *) &pcl__gVtx[3].v.cn[0]) = 0x00000000u;	// rgba

	// Initialize drawing mode.

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	// Finally, draw it.

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 4, 0);

	gSP2Triangles(gp++,
		0, 3, 2, 0, 2, 1, 0, 0);

	// Update the vertex pointer.

	pcl__gVtx += 4;

	// All Done.

	return (gp);
	}



// **************************************************************************
// * RenderMessageBox ()                                                    *
// **************************************************************************
// * Draw complete message box                                              *
// **************************************************************************
// * Inputs  dyn *   ?                                                      *
// *         int     ?                                                      *
// *         Gfx **  ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// *                                                                        *
// * N.B.    Vertex positions are as follows ...                            *
// *                                                                        *
// *         00------------------------------------------01                 *
// *         05-04------------------------------------03-02                 *
// *         -----12                                13-----                 *
// *         -----  16-17-------------------------18  -----                 *
// *         -----  21-20-------------------------19  -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  23-22                             -----                 *
// *         -----15                                14-----                 *
// *         06-07------------------------------------08-09                 *
// *         11------------------------------------------10                 *
// *                                                                        *
// *         00-11 Box edges                                                *
// *         12-15 Box center                                               *
// *         16-23 Box shadow                                               *
// **************************************************************************

#define  BOX_EDGE_PAL	c[16],c[17],c[18],c[19]	// the edge colors of the help box
#define  MBOX_BOTLINE_H		3

global	Gfx *               RenderMessageBox        (
								Gfx *               gp,
								int                 t,
								int                 x,
								int                 y,
								int                 w,
								int                 h,
								int                 s,	// size scaled 0-256
								UB *                c)

	{
	// Local Variables.

	int                 z;

	UD                  rgba;

	// Show nothing ?

	if (s == 0) return (gp);

	// Do we want a titlebar ?

	fl___sMsgBoxTtl = t;

	// Calculate scaled window size.

	w = (w * s) >> (8);
	h = (h * s) >> (8);

	// Calculate centered window position (in screen coordinates).

	x = x - ((w + 0) >> 1);
	y = y - ((h + 0) >> 1);

	// Render the box.


	if ((w > 12) && (h > 7))
	{
//		gp = RenderESHD(gp, x +  w-4, y + h-3,     12,     7);	// fill hole left by rounded corner bottom right
		gp = RenderTBOX(gp, x +  w-10, y + h-6,    12,     8,2,2,2,0xff);	// fill hole left by rounded corner bottom right
	}


	gp = RenderShadedBox(gp, x, y, w, h, c);

	if ((w > 12) && (h > 7))
	{
		gp = RenderLSHD(gp, x +  w, y + 7,     12, h - 7);
		gp = RenderESHD(gp, x +  w, y + h,     12,     7);
		gp = RenderTSHD(gp, x + 12, y + h, w - 12,     7);


//		gp = RenderESHD(gp, x +  w-6, y + h-3,     12,     7);	// fill hole left by rounded corner bottom right

		gp = RenderTBOX(gp,x+15,y,w-(2*15),						13,BOX_EDGE_PAL);	// top
		gp = RenderTBOX(gp,x+15,y+h-MBOX_BOTLINE_H,w-(2*15),	 MBOX_BOTLINE_H,BOX_EDGE_PAL);	// bottom

		gp = RenderTBOX(gp,x,		y+12,4,h-(2*12),BOX_EDGE_PAL);	// left
		gp = RenderTBOX(gp,x+w-4,	y+12,4,h-(2*12),BOX_EDGE_PAL);	// right

	}

#if	1	//def DEBUG
	if ((w > 15+15) && (h > 24+12))		// w&h of the sprites
	{

	// rounded corners in help menu
		if(fl___gShowingHelp)
		{	// - green background & corners
			gp = RenderSprite(gp, SPR_PTR(SPR_HELPTL), (UI)puw__gContPal, x,		y);
			gp = RenderSprite(gp, SPR_PTR(SPR_HELPTR), (UI)puw__gContPal, x+w-15,	y);
			gp = RenderSprite(gp, SPR_PTR(SPR_HELPBL), (UI)puw__gContPal, x,		y+h-12);
			gp = RenderSprite(gp, SPR_PTR(SPR_HELPBR), (UI)puw__gContPal, x+w-15,	y+h-12);
		}
		else	// message box - blue background & corners
		{
			gp = RenderSprite(gp, SPR_PTR(SPR_HELPTL1), (UI)puw__gContPal, x,		y);
			gp = RenderSprite(gp, SPR_PTR(SPR_HELPTR1), (UI)puw__gContPal, x+w-15,	y);
			gp = RenderSprite(gp, SPR_PTR(SPR_HELPBL1), (UI)puw__gContPal, x,		y+h-12);
			gp = RenderSprite(gp, SPR_PTR(SPR_HELPBR1), (UI)puw__gContPal, x+w-15,	y+h-12);
		}
	}
#endif


	// Do we want a titlebar ?

	fl___sMsgBoxTtl = 0;

	// All Done.

	return (gp);
}



// **************************************************************************
// * RenderShadedBox ()                                                     *
// **************************************************************************
// * Draw complete shaded box                                               *
// **************************************************************************
// * Inputs  dyn *   ?                                                      *
// *         int     ?                                                      *
// *         Gfx **  ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// *                                                                        *
// * N.B.    Vertex positions are as follows ...                            *
// *                                                                        *
// *         00------------------------------------------01                 *
// *         05-04------------------------------------03-02                 *
// *         -----12                                13-----                 *
// *         -----  16-17-------------------------18  -----                 *
// *         -----  21-20-------------------------19  -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  -----                             -----                 *
// *         -----  23-22                             -----                 *
// *         -----15                                14-----                 *
// *         06-07------------------------------------08-09                 *
// *         11------------------------------------------10                 *
// *                                                                        *
// *         00-11 Box edges                                                *
// *         12-15 Box center                                               *
// *         16-23 Box shadow                                               *
// **************************************************************************

global	Gfx *               RenderShadedBox         (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h,
								UB *                c)

	{
	// Local Variables.

	int                 z;
	int                 t;

	UD                  rgba;

	// Do we want a titlebar ?

	t = 2;

	if (fl___sMsgBoxTtl)
		{
		t = 13;
		}

	// Calculate centered window position (in 3D coordinates).

	x = x - 512/2;
	y = 240/2 - y;
	z = 20;

	// Calculate normal vertex coordinates (in 3D coordinates).

	pcl__gVtx[ 0].v.ob[0] = x;		// x
	pcl__gVtx[ 0].v.ob[1] = y;		// y
	pcl__gVtx[ 0].v.ob[2] = z;		// z
	pcl__gVtx[ 0].v.flag  = 0;		// flags

	pcl__gVtx[ 1].v.ob[0] = x+w;	// x
	pcl__gVtx[ 1].v.ob[1] = y;		// y
	pcl__gVtx[ 1].v.ob[2] = z;		// z
	pcl__gVtx[ 1].v.flag  = 0;		// flags

	pcl__gVtx[ 2].v.ob[0] = x+w;	// x
	pcl__gVtx[ 2].v.ob[1] = y-t;	// y
	pcl__gVtx[ 2].v.ob[2] = z;		// z
	pcl__gVtx[ 2].v.flag  = 0;		// flags

	pcl__gVtx[ 3].v.ob[0] = x+w-4;	// x
	pcl__gVtx[ 3].v.ob[1] = y-t;	// y
	pcl__gVtx[ 3].v.ob[2] = z;		// z
	pcl__gVtx[ 3].v.flag  = 0;		// flags

	pcl__gVtx[13].v.ob[0] = x+w-4;	// x
	pcl__gVtx[13].v.ob[1] = y-t;	// y
	pcl__gVtx[13].v.ob[2] = z;		// z
	pcl__gVtx[13].v.flag  = 0;		// flags

	pcl__gVtx[ 4].v.ob[0] = x+4;	// x
	pcl__gVtx[ 4].v.ob[1] = y-t;	// y
	pcl__gVtx[ 4].v.ob[2] = z;		// z
	pcl__gVtx[ 4].v.flag  = 0;		// flags

	pcl__gVtx[12].v.ob[0] = x+4;	// x
	pcl__gVtx[12].v.ob[1] = y-t;	// y
	pcl__gVtx[12].v.ob[2] = z;		// z
	pcl__gVtx[12].v.flag  = 0;		// flags

	pcl__gVtx[ 5].v.ob[0] = x;		// x
	pcl__gVtx[ 5].v.ob[1] = y-t;	// y
	pcl__gVtx[ 5].v.ob[2] = z;		// z
	pcl__gVtx[ 5].v.flag  = 0;		// flags

	pcl__gVtx[ 6].v.ob[0] = x;		// x
	pcl__gVtx[ 6].v.ob[1] = y-h+MBOX_BOTLINE_H;	// y
	pcl__gVtx[ 6].v.ob[2] = z;		// z
	pcl__gVtx[ 6].v.flag  = 0;		// flags

	pcl__gVtx[ 7].v.ob[0] = x+4;	// x
	pcl__gVtx[ 7].v.ob[1] = y-h+MBOX_BOTLINE_H;	// y
	pcl__gVtx[ 7].v.ob[2] = z;		// z
	pcl__gVtx[ 7].v.flag  = 0;		// flags

	pcl__gVtx[15].v.ob[0] = x+4;	// x
	pcl__gVtx[15].v.ob[1] = y-h+MBOX_BOTLINE_H;	// y
	pcl__gVtx[15].v.ob[2] = z;		// z
	pcl__gVtx[15].v.flag  = 0;		// flags

	pcl__gVtx[ 8].v.ob[0] = x+w-4;	// x
	pcl__gVtx[ 8].v.ob[1] = y-h+MBOX_BOTLINE_H;	// y
	pcl__gVtx[ 8].v.ob[2] = z;		// z
	pcl__gVtx[ 8].v.flag  = 0;		// flags

	pcl__gVtx[14].v.ob[0] = x+w-4;	// x
	pcl__gVtx[14].v.ob[1] = y-h+MBOX_BOTLINE_H;	// y
	pcl__gVtx[14].v.ob[2] = z;		// z
	pcl__gVtx[14].v.flag  = 0;		// flags

	pcl__gVtx[ 9].v.ob[0] = x+w;	// x
	pcl__gVtx[ 9].v.ob[1] = y-h+MBOX_BOTLINE_H;	// y
	pcl__gVtx[ 9].v.ob[2] = z;		// z
	pcl__gVtx[ 9].v.flag  = 0;		// flags

	pcl__gVtx[10].v.ob[0] = x+w;	// x
	pcl__gVtx[10].v.ob[1] = y-h;	// y
	pcl__gVtx[10].v.ob[2] = z;		// z
	pcl__gVtx[10].v.flag  = 0;		// flags

	pcl__gVtx[11].v.ob[0] = x;		// x
	pcl__gVtx[11].v.ob[1] = y-h;	// y
	pcl__gVtx[11].v.ob[2] = z;		// z
	pcl__gVtx[11].v.flag  = 0;		// flags

	// Calculate shadow vertex coordinates (in 3D coordinates).

	pcl__gVtx[16].v.ob[0] = x+4;	// x
	pcl__gVtx[16].v.ob[1] = y-t;	// y
	pcl__gVtx[16].v.ob[2] = z;		// z
	pcl__gVtx[16].v.flag  = 0;		// flags

	pcl__gVtx[17].v.ob[0] = x+4+14;	// x
	pcl__gVtx[17].v.ob[1] = y-t;	// y
	pcl__gVtx[17].v.ob[2] = z;		// z
	pcl__gVtx[17].v.flag  = 0;		// flags

	pcl__gVtx[18].v.ob[0] = x+w-4;	// x
	pcl__gVtx[18].v.ob[1] = y-t;	// y
	pcl__gVtx[18].v.ob[2] = z;		// z
	pcl__gVtx[18].v.flag  = 0;		// flags

	pcl__gVtx[19].v.ob[0] = x+w-4;	// x
	pcl__gVtx[19].v.ob[1] = y-(t+7);// y
	pcl__gVtx[19].v.ob[2] = z;		// z
	pcl__gVtx[19].v.flag  = 0;		// flags

	pcl__gVtx[20].v.ob[0] = x+4+14;	// x
	pcl__gVtx[20].v.ob[1] = y-(t+7);// y
	pcl__gVtx[20].v.ob[2] = z;		// z
	pcl__gVtx[20].v.flag  = 0;		// flags

	pcl__gVtx[21].v.ob[0] = x+4;	// x
	pcl__gVtx[21].v.ob[1] = y-(t+7);// y
	pcl__gVtx[21].v.ob[2] = z;		// z
	pcl__gVtx[21].v.flag  = 0;		// flags

	pcl__gVtx[22].v.ob[0] = x+4+14;	// x
	pcl__gVtx[22].v.ob[1] = y-h+MBOX_BOTLINE_H;	// y
	pcl__gVtx[22].v.ob[2] = z;		// z
	pcl__gVtx[22].v.flag  = 0;		// flags

	pcl__gVtx[23].v.ob[0] = x+4;	// x
	pcl__gVtx[23].v.ob[1] = y-h+MBOX_BOTLINE_H;	// y
	pcl__gVtx[23].v.ob[2] = z;		// z
	pcl__gVtx[23].v.flag  = 0;		// flags

	// Set vertex colours.

	rgba = ((UD *) c)[RGB_BOXEDGE];

	*((UD *) pcl__gVtx[ 0].v.tc) = 0;
	*((UD *) pcl__gVtx[ 0].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 1].v.tc) = 0;
	*((UD *) pcl__gVtx[ 1].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 2].v.tc) = 0;
	*((UD *) pcl__gVtx[ 2].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 3].v.tc) = 0;
	*((UD *) pcl__gVtx[ 3].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 4].v.tc) = 0;
	*((UD *) pcl__gVtx[ 4].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 5].v.tc) = 0;
	*((UD *) pcl__gVtx[ 5].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 6].v.tc) = 0;
	*((UD *) pcl__gVtx[ 6].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 7].v.tc) = 0;
	*((UD *) pcl__gVtx[ 7].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 8].v.tc) = 0;
	*((UD *) pcl__gVtx[ 8].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 9].v.tc) = 0;
	*((UD *) pcl__gVtx[ 9].v.cn) = rgba;
	*((UD *) pcl__gVtx[10].v.tc) = 0;
	*((UD *) pcl__gVtx[10].v.cn) = rgba;
	*((UD *) pcl__gVtx[11].v.tc) = 0;
	*((UD *) pcl__gVtx[11].v.cn) = rgba;

	*((UD *) pcl__gVtx[12].v.tc) = 0;
	*((UD *) pcl__gVtx[12].v.cn) = ((UD *) c)[RGB_BOXTL];
	*((UD *) pcl__gVtx[13].v.tc) = 0;
	*((UD *) pcl__gVtx[13].v.cn) = ((UD *) c)[RGB_BOXTR];
	*((UD *) pcl__gVtx[14].v.tc) = 0;
	*((UD *) pcl__gVtx[14].v.cn) = ((UD *) c)[RGB_BOXBR];
	*((UD *) pcl__gVtx[15].v.tc) = 0;
	*((UD *) pcl__gVtx[15].v.cn) = ((UD *) c)[RGB_BOXBL];

	*((UD *) pcl__gVtx[16].v.tc) = 0;
	*((UD *) pcl__gVtx[16].v.cn) = 0x00000080u;
	*((UD *) pcl__gVtx[17].v.tc) = 0;
	*((UD *) pcl__gVtx[17].v.cn) = 0x00000080u;
	*((UD *) pcl__gVtx[18].v.tc) = 0;
	*((UD *) pcl__gVtx[18].v.cn) = 0x00000080u;
	*((UD *) pcl__gVtx[19].v.tc) = 0;
	*((UD *) pcl__gVtx[19].v.cn) = 0x00000000u;
	*((UD *) pcl__gVtx[20].v.tc) = 0;
	*((UD *) pcl__gVtx[20].v.cn) = 0x00000000u;
	*((UD *) pcl__gVtx[21].v.tc) = 0;
	*((UD *) pcl__gVtx[21].v.cn) = 0x00000080u;
	*((UD *) pcl__gVtx[22].v.tc) = 0;
	*((UD *) pcl__gVtx[22].v.cn) = 0x00000000u;
	*((UD *) pcl__gVtx[23].v.tc) = 0;
	*((UD *) pcl__gVtx[23].v.cn) = 0x00000080u;

	// Reset projection and modelview matrices for 2D drawing.

	/*
	gDPPipeSync(gp++);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->ballMat)),
		G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->identity)),
		G_MTX_MODELVIEW  | G_MTX_LOAD | G_MTX_NOPUSH);
	*/

	// Set drawing mode.

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetRenderMode(gp++,
		G_RM_OPA_SURF,
		G_RM_OPA_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 24, 0);

	// Draw edge

//	if (((UD *) c)[RGB_BOXEDGE] != 0)
	if(0)	
	{
		gSP2Triangles(gp++,
			 0,  5,  2,  0,  2,  1,  0,  0);	// top 2 tri

		gSP2Triangles(gp++,
			 5,  6,  7,  0,  7,  4,  5,  0);	// left 2 tri

		gSP2Triangles(gp++,
			 3,  8,  9,  0,  9,  2,  3,  0);	//  right 2 tri

		gSP2Triangles(gp++,
			 6, 11, 10,  0, 10,  9,  6,  0);	// bottom
	}

	// Draw center

	gDPPipeSync(gp++);

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	if (((UD *) c)[RGB_BOXTL] != 0)
		{
		if ((w >=  4) && (h >= (2 + t)))
			{
			gSP2Triangles(gp++,
				12, 15, 14,  0, 14, 13, 12,  0);
			}
		}

	// Draw shadows

	if ((w >= 22) && (h >= (9 + t)))
		{
		gSP2Triangles(gp++,
			16, 21, 20,  0, 20, 17, 16,  0);

		gSP2Triangles(gp++,
			17, 20, 19,  0, 19, 18, 17,  0);

		gSP2Triangles(gp++,
			21, 23, 22,  0, 22, 20, 21,  0);
		}

	// Update the vertex pointer.

	pcl__gVtx += 24;

	// All Done.

	return (gp);
	}



// **************************************************************************
// * RenderBevelBox ()                                                      *
// **************************************************************************
// * Draw complete beveled box                                              *
// **************************************************************************
// * Inputs  dyn *   ?                                                      *
// *         int     ?                                                      *
// *         Gfx **  ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// *                                                                        *
// * N.B.    Vertex positions are as follows ...                            *
// *                                                                        *
// *         00------------------------------------------01 (08)            *
// *         ---04------------------------------------05---                 *
// *         -----                                    -----                 *
// *         -----                                    -----                 *
// *         -----                                    -----                 *
// *         -----                                    -----                 *
// *         ---07------------------------------------06---                 *
// *    (09) 03------------------------------------------02                 *
// *                                                                        *
// *         00-09 Box edges                                                *
// **************************************************************************

#if 0	// not needed in Kobe 2

/************
global	Gfx *               RenderBevelBox          (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h,
								UB *                c)

	{
	// Local Variables.

	int                 z;
	int                 t;

	UD                  rgba;

	// Calculate centered window position (in 3D coordinates).

	x = x - 512/2;
	y = 240/2 - y;
	z = 20;

	// Calculate normal vertex coordinates (in 3D coordinates).

	pcl__gVtx[ 0].v.ob[0] = x;		// x
	pcl__gVtx[ 0].v.ob[1] = y;		// y
	pcl__gVtx[ 0].v.ob[2] = z;		// z
	pcl__gVtx[ 0].v.flag  = 0;		// flags

	pcl__gVtx[ 1].v.ob[0] = x+w;	// x
	pcl__gVtx[ 1].v.ob[1] = y;		// y
	pcl__gVtx[ 1].v.ob[2] = z;		// z
	pcl__gVtx[ 1].v.flag  = 0;		// flags

	pcl__gVtx[ 8].v.ob[0] = x+w;	// x
	pcl__gVtx[ 8].v.ob[1] = y;		// y
	pcl__gVtx[ 8].v.ob[2] = z;		// z
	pcl__gVtx[ 8].v.flag  = 0;		// flags

	pcl__gVtx[ 2].v.ob[0] = x+w;	// x
	pcl__gVtx[ 2].v.ob[1] = y-h;	// y
	pcl__gVtx[ 2].v.ob[2] = z;		// z
	pcl__gVtx[ 2].v.flag  = 0;		// flags

	pcl__gVtx[ 3].v.ob[0] = x;		// x
	pcl__gVtx[ 3].v.ob[1] = y-h;	// y
	pcl__gVtx[ 3].v.ob[2] = z;		// z
	pcl__gVtx[ 3].v.flag  = 0;		// flags

	pcl__gVtx[ 9].v.ob[0] = x;		// x
	pcl__gVtx[ 9].v.ob[1] = y-h;	// y
	pcl__gVtx[ 9].v.ob[2] = z;		// z
	pcl__gVtx[ 9].v.flag  = 0;		// flags

	pcl__gVtx[ 0].v.ob[0] = x;		// x
	pcl__gVtx[ 0].v.ob[1] = y;		// y
	pcl__gVtx[ 0].v.ob[2] = z;		// z
	pcl__gVtx[ 0].v.flag  = 0;		// flags

	pcl__gVtx[ 1].v.ob[0] = x+w;	// x
	pcl__gVtx[ 1].v.ob[1] = y;		// y
	pcl__gVtx[ 1].v.ob[2] = z;		// z
	pcl__gVtx[ 1].v.flag  = 0;		// flags

	pcl__gVtx[ 2].v.ob[0] = x+w;	// x
	pcl__gVtx[ 2].v.ob[1] = y-h;	// y
	pcl__gVtx[ 2].v.ob[2] = z;		// z
	pcl__gVtx[ 2].v.flag  = 0;		// flags

	pcl__gVtx[ 3].v.ob[0] = x;		// x
	pcl__gVtx[ 3].v.ob[1] = y-h;	// y
	pcl__gVtx[ 3].v.ob[2] = z;		// z
	pcl__gVtx[ 3].v.flag  = 0;		// flags

	pcl__gVtx[ 4].v.ob[0] = x+4;	// x
	pcl__gVtx[ 4].v.ob[1] = y-2;	// y
	pcl__gVtx[ 4].v.ob[2] = z;		// z
	pcl__gVtx[ 4].v.flag  = 0;		// flags

	pcl__gVtx[ 5].v.ob[0] = x+w-4;	// x
	pcl__gVtx[ 5].v.ob[1] = y-2;	// y
	pcl__gVtx[ 5].v.ob[2] = z;		// z
	pcl__gVtx[ 5].v.flag  = 0;		// flags

	pcl__gVtx[ 6].v.ob[0] = x+w-4;	// x
	pcl__gVtx[ 6].v.ob[1] = y+2-h;	// y
	pcl__gVtx[ 6].v.ob[2] = z;		// z
	pcl__gVtx[ 6].v.flag  = 0;		// flags

	pcl__gVtx[ 7].v.ob[0] = x+4;	// x
	pcl__gVtx[ 7].v.ob[1] = y+2-h;	// y
	pcl__gVtx[ 7].v.ob[2] = z;		// z
	pcl__gVtx[ 7].v.flag  = 0;		// flags

	// Set vertex colours.

	*((UD *) pcl__gVtx[0].v.tc) = 0;
	*((UD *) pcl__gVtx[0].v.cn) = ((UD *) c)[RGB_BOXTL];
	*((UD *) pcl__gVtx[3].v.tc) = 0;
	*((UD *) pcl__gVtx[3].v.cn) = ((UD *) c)[RGB_BOXTL];
	*((UD *) pcl__gVtx[1].v.tc) = 0;
	*((UD *) pcl__gVtx[1].v.cn) = ((UD *) c)[RGB_BOXTR];

	*((UD *) pcl__gVtx[9].v.tc) = 0;
	*((UD *) pcl__gVtx[9].v.cn) = ((UD *) c)[RGB_BOXBL];
	*((UD *) pcl__gVtx[2].v.tc) = 0;
	*((UD *) pcl__gVtx[2].v.cn) = ((UD *) c)[RGB_BOXBR];
	*((UD *) pcl__gVtx[8].v.tc) = 0;
	*((UD *) pcl__gVtx[8].v.cn) = ((UD *) c)[RGB_BOXBR];

	//

	rgba = ((UD *) c)[RGB_BOXEDGE];

	*((UD *) pcl__gVtx[4].v.tc) = 0;
	*((UD *) pcl__gVtx[4].v.cn) = rgba;
	*((UD *) pcl__gVtx[5].v.tc) = 0;
	*((UD *) pcl__gVtx[5].v.cn) = rgba;
	*((UD *) pcl__gVtx[6].v.tc) = 0;
	*((UD *) pcl__gVtx[6].v.cn) = rgba;
	*((UD *) pcl__gVtx[7].v.tc) = 0;
	*((UD *) pcl__gVtx[7].v.cn) = rgba;

	// Reset projection and modelview matrices for 2D drawing.

	
//	gDPPipeSync(gp++);

//	gSPMatrix(gp++,
//		OS_K0_TO_PHYSICAL(&(d->ballMat)),
//		G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);

//	gSPMatrix(gp++,
//		OS_K0_TO_PHYSICAL(&(d->identity)),
//		G_MTX_MODELVIEW  | G_MTX_LOAD | G_MTX_NOPUSH);
	

	// Set drawing mode.

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	if (c[3] == 0xFFu)
		{
		gDPSetRenderMode(gp++,
			G_RM_OPA_SURF,
			G_RM_OPA_SURF2);
		}
	else
		{
		gDPSetRenderMode(gp++,
			G_RM_XLU_SURF,
			G_RM_XLU_SURF2);
		}

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 10, 0);

	// Draw top and lhs edges

	gSP2Triangles(gp++,
		 0,  4,  5,  0,  5,  1,  0,  0);

	gSP2Triangles(gp++,
		 0,  3,  7,  0,  7,  4,  0,  0);

	// Draw btm and rhs edges

	gSP2Triangles(gp++,
		 7,  9,  2,  0,  2,  6,  7,  0);

	gSP2Triangles(gp++,
		 5,  6,  2,  0,  2,  8,  5,  0);

	// Draw center

	gSP2Triangles(gp++,
		 4,  7,  6,  0,  6,  5,  4,  0);

	// Update the vertex pointer.

	pcl__gVtx += 10;

	// All Done.

	return (gp);
	}
*********/
#endif

// **************************************************************************
// * RenderVolumeBar ()                                                     *
// **************************************************************************
// * Draw complete volume bar                                               *
// **************************************************************************
// * Inputs  dyn *   ?                                                      *
// *         int     ?                                                      *
// *         Gfx **  ?                                                      *
// *                                                                        *
// * Output  -                                                              *
// *                                                                        *
// * N.B.    Vertex positions are as follows ...                            *
// *                                                                        *
// *         00------------------------------------------01                 *
// *         05-04------------------------------------03-02                 *
// *         -----12                                13-----                 *
// *         -----                                    -----                 *
// *         -----15                                14-----                 *
// *         06-07------------------------------------08-09                 *
// *         11------------------------------------------10                 *
// *                                                                        *
// *         00-11 Bar edges                                                *
// *         12-15 Bar center                                               *
// **************************************************************************

#if  0		// not needed in Kobe 2

global	Gfx *               RenderVolumeBar         (
								Gfx *               gp,
								int                 x,
								int                 y,
								int                 w,
								int                 h,
								UB *                c,
								int                 volume)

	{
	// Local Variables.

	int                 i;
	int                 j;

	int                 z;

	UD                  rgba;

	UB                  s[4];

	// Add window offset.

	x += si___gWindowX;
	y += si___gWindowY;

	// Calculate the shaded bar colour.

	i = 32 - volume;
	j = volume;

	s[0] = ((i * c[0x4]) + (j * c[0x8])) >> 5;
	s[1] = ((i * c[0x5]) + (j * c[0x9])) >> 5;
	s[2] = ((i * c[0x6]) + (j * c[0xA])) >> 5;
	s[3] = 255;

	// Calculate normal vertex coordinates (in 3D coordinates).

	z = 20;

	x = x - 512/2;
	y = 240/2 - y;

	pcl__gVtx[ 0].v.ob[0] = x;		// x
	pcl__gVtx[ 0].v.ob[1] = y;		// y
	pcl__gVtx[ 0].v.ob[2] = z;		// z
	pcl__gVtx[ 0].v.flag  = 0;		// flags

	pcl__gVtx[ 1].v.ob[0] = x+w;	// x
	pcl__gVtx[ 1].v.ob[1] = y;		// y
	pcl__gVtx[ 1].v.ob[2] = z;		// z
	pcl__gVtx[ 1].v.flag  = 0;		// flags

	pcl__gVtx[ 2].v.ob[0] = x+w;	// x
	pcl__gVtx[ 2].v.ob[1] = y-1;	// y
	pcl__gVtx[ 2].v.ob[2] = z;		// z
	pcl__gVtx[ 2].v.flag  = 0;		// flags

	pcl__gVtx[ 3].v.ob[0] = x+w-2;	// x
	pcl__gVtx[ 3].v.ob[1] = y-1;	// y
	pcl__gVtx[ 3].v.ob[2] = z;		// z
	pcl__gVtx[ 3].v.flag  = 0;		// flags

	pcl__gVtx[ 4].v.ob[0] = x+2;	// x
	pcl__gVtx[ 4].v.ob[1] = y-1;	// y
	pcl__gVtx[ 4].v.ob[2] = z;		// z
	pcl__gVtx[ 4].v.flag  = 0;		// flags

	pcl__gVtx[ 5].v.ob[0] = x;		// x
	pcl__gVtx[ 5].v.ob[1] = y-1;	// y
	pcl__gVtx[ 5].v.ob[2] = z;		// z
	pcl__gVtx[ 5].v.flag  = 0;		// flags

	pcl__gVtx[ 6].v.ob[0] = x;		// x
	pcl__gVtx[ 6].v.ob[1] = y+1-h;	// y
	pcl__gVtx[ 6].v.ob[2] = z;		// z
	pcl__gVtx[ 6].v.flag  = 0;		// flags

	pcl__gVtx[ 7].v.ob[0] = x+2;	// x
	pcl__gVtx[ 7].v.ob[1] = y+1-h;	// y
	pcl__gVtx[ 7].v.ob[2] = z;		// z
	pcl__gVtx[ 7].v.flag  = 0;		// flags

	pcl__gVtx[ 8].v.ob[0] = x+w-2;	// x
	pcl__gVtx[ 8].v.ob[1] = y+1-h;	// y
	pcl__gVtx[ 8].v.ob[2] = z;		// z
	pcl__gVtx[ 8].v.flag  = 0;		// flags

	pcl__gVtx[ 9].v.ob[0] = x+w;	// x
	pcl__gVtx[ 9].v.ob[1] = y+1-h;	// y
	pcl__gVtx[ 9].v.ob[2] = z;		// z
	pcl__gVtx[ 9].v.flag  = 0;		// flags

	pcl__gVtx[10].v.ob[0] = x+w;	// x
	pcl__gVtx[10].v.ob[1] = y-h;	// y
	pcl__gVtx[10].v.ob[2] = z;		// z
	pcl__gVtx[10].v.flag  = 0;		// flags

	pcl__gVtx[11].v.ob[0] = x;		// x
	pcl__gVtx[11].v.ob[1] = y-h;	// y
	pcl__gVtx[11].v.ob[2] = z;		// z
	pcl__gVtx[11].v.flag  = 0;		// flags

	// Calculate bar coordinates.

	x = x + 4;
	w = ((w - 8) * volume) >> 5;

	pcl__gVtx[12].v.ob[0] = x;		// x
	pcl__gVtx[12].v.ob[1] = y-2;	// y
	pcl__gVtx[12].v.ob[2] = z;		// z
	pcl__gVtx[12].v.flag  = 0;		// flags

	pcl__gVtx[13].v.ob[0] = x+w;	// x
	pcl__gVtx[13].v.ob[1] = y-2;	// y
	pcl__gVtx[13].v.ob[2] = z;		// z
	pcl__gVtx[13].v.flag  = 0;		// flags

	pcl__gVtx[14].v.ob[0] = x+w;	// x
	pcl__gVtx[14].v.ob[1] = y+2-h;	// y
	pcl__gVtx[14].v.ob[2] = z;		// z
	pcl__gVtx[14].v.flag  = 0;		// flags

	pcl__gVtx[15].v.ob[0] = x;		// x
	pcl__gVtx[15].v.ob[1] = y+2-h;	// y
	pcl__gVtx[15].v.ob[2] = z;		// z
	pcl__gVtx[15].v.flag  = 0;		// flags

	// Set vertex colours.

	rgba = ((UD *) c)[0];

	*((UD *) pcl__gVtx[ 0].v.tc) = 0;
	*((UD *) pcl__gVtx[ 0].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 1].v.tc) = 0;
	*((UD *) pcl__gVtx[ 1].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 2].v.tc) = 0;
	*((UD *) pcl__gVtx[ 2].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 3].v.tc) = 0;
	*((UD *) pcl__gVtx[ 3].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 4].v.tc) = 0;
	*((UD *) pcl__gVtx[ 4].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 5].v.tc) = 0;
	*((UD *) pcl__gVtx[ 5].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 6].v.tc) = 0;
	*((UD *) pcl__gVtx[ 6].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 7].v.tc) = 0;
	*((UD *) pcl__gVtx[ 7].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 8].v.tc) = 0;
	*((UD *) pcl__gVtx[ 8].v.cn) = rgba;
	*((UD *) pcl__gVtx[ 9].v.tc) = 0;
	*((UD *) pcl__gVtx[ 9].v.cn) = rgba;
	*((UD *) pcl__gVtx[10].v.tc) = 0;
	*((UD *) pcl__gVtx[10].v.cn) = rgba;
	*((UD *) pcl__gVtx[11].v.tc) = 0;
	*((UD *) pcl__gVtx[11].v.cn) = rgba;

	*((UD *) pcl__gVtx[12].v.tc) = 0;
	*((UD *) pcl__gVtx[12].v.cn) = ((UD *) c)[1];
	*((UD *) pcl__gVtx[13].v.tc) = 0;
	*((UD *) pcl__gVtx[13].v.cn) = ((UD *) s)[0];
	*((UD *) pcl__gVtx[14].v.tc) = 0;
	*((UD *) pcl__gVtx[14].v.cn) = ((UD *) s)[0];
	*((UD *) pcl__gVtx[15].v.tc) = 0;
	*((UD *) pcl__gVtx[15].v.cn) = ((UD *) c)[1];

	// Reset projection and modelview matrices for 2D drawing.

	/*
	gDPPipeSync(gp++);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->ballMat)),
		G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);

	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(d->identity)),
		G_MTX_MODELVIEW  | G_MTX_LOAD | G_MTX_NOPUSH);
	*/

	// Set drawing mode.

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_NONE);

	gDPSetRenderMode(gp++,
		G_RM_OPA_SURF,
		G_RM_OPA_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_SHADE,
		G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 16, 0);

	// Draw edge

	gSP2Triangles(gp++,
		 0,  5,  2,  0,  2,  1,  0,  0);

	gSP2Triangles(gp++,
		 5,  6,  7,  0,  7,  4,  5,  0);

	gSP2Triangles(gp++,
		 3,  8,  9,  0,  9,  2,  3,  0);

	gSP2Triangles(gp++,
		 6, 11, 10,  0, 10,  9,  6,  0);

	// Draw center

//	gDPPipeSync(gp++);
//
//	gDPSetRenderMode(gp++,
//		G_RM_XLU_SURF,
//		G_RM_XLU_SURF2);

	if (volume != 0)
		{
		gSP2Triangles(gp++,
			12, 15, 14,  0, 14, 13, 12,  0);
		}

	// Update the vertex pointer.

	pcl__gVtx += 16;

	// All Done.

	return (gp);
	}

#endif 

// **************************************************************************
// * InitFontBtn ()                                                         *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  Gfx **                                                         *
// *                                                                        *
// * Output  Gfx **                                                         *
// **************************************************************************

global	void                InitFontBtn             (void)

	{
	// Local Variables.

	int                 i;

	// Clear button coordinates.

	for (i = 0; i < 16; i++)
		{
		asi__gFontBtn[i][0] =
		asi__gFontBtn[i][1] = -32768;
		}

	// All done.

	return;
	}



// **************************************************************************
// * DrawFontBtn ()                                                         *
// **************************************************************************
// *                                                                        *
// **************************************************************************
// * Inputs  Gfx **                                                         *
// *                                                                        *
// * Output  Gfx **                                                         *
// **************************************************************************

static	SB                  asb__sButtons [] =
	{
	6,  0,
	FNTBTN_PU, -9,  0,  0 -  0, 18, 11,
	FNTBTN_PD, -9,  0, 11 -  0, 18, 11,
	FNTBTN_PL, -9, 18,  0 -  0, 18, 11,
	FNTBTN_PR, -9, 18, 11 -  0, 18, 11,
	FNTBTN_B,  -9, 36,  0 -  0, 18, 11,
	FNTBTN_A,  -9, 36, 11 -  0, 18, 11,

	5, 22,
	FNTBTN_S,  -9, 36, 22 - 22, 18, 11,
	FNTBTN_CU, -9,  0, 22 - 22, 18, 11,
	FNTBTN_CD, -9, 18, 22 - 22, 18, 11,
	FNTBTN_CL, -9, 46, 33 - 22, 18, 11,
	FNTBTN_TL, -9,  0, 33 - 22, 41, 11,

	3, 44,
	FNTBTN_CR, -9, 46, 44 - 44, 19, 11,
	FNTBTN_TR, -9,  0, 44 - 44, 41, 11,
	FNTBTN_Z,  -9,  0, 55 - 44, 18, 11,

	0
	};

global	Gfx *               DrawFontBtn             (
								Gfx *               gp)

	{
	// Local Variables.

	int                 i;
	int                 j;

	int                 x;
	int                 y;

	int                 tx;
	int                 ty;
	int                 tw;
	int                 th;

	SprTexture_T *      pcl__Spr;
	UB *                pub__Src;
	int                 fl___Src;

	SB *                psb__Buttons;

	// Don't continue if the sprite isn't loaded.

	pcl__Spr = SPR_PTR(SPR_SMALLBTN);

	if (pcl__Spr == NULL) return (gp);

	pub__gCurTexture = NULL;

	// Set up the render mode.

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
		G_AC_THRESHOLD);

	gp = SetPalette(gp, (UI) (*pcl__Spr->sprPal));

	gDPSetRenderMode(gp++,
		G_RM_XLU_SURF,
		G_RM_XLU_SURF2);

	gDPSetCombineMode(gp++,
		G_CC_DECALRGBA,
		G_CC_DECALRGBA);

	// Load up the first section of the buttons.

	psb__Buttons = asb__sButtons;

	while ((i = *psb__Buttons++) != 0)
		{
		// Load the texture.

		pub__Src = ((UB *) (pcl__Spr + 1)) + (*psb__Buttons++ * 64);
		fl___Src = 0;

		gDPPipeSync(gp++);

		// Then draw the buttons.

		while (i--)
			{
			j = psb__Buttons[0];

			if (asi__gFontBtn[j][0] > -32768)
				{
				if (fl___Src == 0)
					{
					fl___Src = 1;

					gDPLoadTextureBlock(gp++,
						pub__Src,			// ptr (8-byte aligned)
						G_IM_FMT_CI,		// texel fmt
						G_IM_SIZ_8b,		// texel siz
						64,					// w
						22,					// h
						0,					// palette
						G_TX_CLAMP,			// clamp/wrap/mirror s
						G_TX_CLAMP,			// clamp/wrap/mirror t
						6,					// mask s
						5,					// mask t
						G_TX_NOLOD,			// shift s
						G_TX_NOLOD);		// shift t
					}

				x = si___gWindowX + asi__gFontBtn[j][0];
				y = si___gWindowX + asi__gFontBtn[j][1];

//				y = si___gWindowY + asi__gFontBtn[j][1] - psb__Buttons[1];

				tx = psb__Buttons[2];
				ty = psb__Buttons[3];
				tw = psb__Buttons[4];
				th = psb__Buttons[5];

				if ((x > -64) && (x < 512))
					{
					gSPTextureRectangle(gp++,
						(x) << 2,			// ulx  (10.2)
						(y) << 2,			// uly  (10.2)
						(x + tw) << 2,		// lrx  (10.2)
						(y + th) << 2,		// lry  (10.2)
						G_TX_RENDERTILE,	// tile
						(tx) << 5,			// s    (s10.5)
						(ty) << 5,			// t    (s10.5)
						1 << 10,			// dsdx (s5.10)
						1 << 10);			// dtdy (s5.10)
					}
				}

			psb__Buttons += 6;
			}
		}

	// All Done.

	return (gp);
	}



// **************************************************************************
// **************************************************************************
// **************************************************************************
//	STATIC FUNCTIONS
// **************************************************************************
// **************************************************************************
// **************************************************************************



// **************************************************************************
// **************************************************************************
// **************************************************************************
//	END OF SHELLGFX.C
// **************************************************************************
// **************************************************************************
// **************************************************************************

