/*
	scrplt.c
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winb.h>
#include <te.h>
#include <fntb.h>
#include <gui.h>
#include <fmcfrb.h>
#include <file_dlg.h>
#include <egb.h>

#include "art.h"
#include "pic.h"

static unsigned int _15_31[] =
	{ 0,2,4,6,8,11,13,15,17,19,21,23,25,27,29,31 };

static char byTmenuPlt[][4] =
{
	{0,0,0},			// 0: 透過色
	{9,9,10},			// 1: メニュー色１
	{12,6,4}, {15,12,10}, {9,9,9},
	{0,12,7},
	{12,12,13},			// 6: メニュー色２  (ARTemis での back 色)
	{7,7,8},			// 7: メニュー色３
	{2,2,3},			// 8: メニュー色４（黒）
	{13,13,14},			// 9: メニュー色５
	{13,0,0}, {0,0,10}, {5,5,5}, {0,15,15}, {15,13,0}, {15,15,15}
};

#define CRGB(r,g,b) (((r)*32+(g)*1024+(b))+(((r)*32+(g)*1024+(b))<<16))

#define RGB16M(r,g,b)   (((uint)(g)<<16)|((uint)(r)<<8)|((uint)(b)))

void scrplt_init(void)
{
#if 1
#if 1
	unsigned int *coltbl;
	if (scrPixelSize == 16)
	{
		coltbl = MG_getColorTable(2);
		int i;
		for (i=0; i<16; i++)
			coltbl[i] = CRGB(_15_31[byTmenuPlt[i][0]],
							 _15_31[byTmenuPlt[i][1]],
							 _15_31[byTmenuPlt[i][2]]);
		coltbl[GRAY]     = CRGB(21,21,22);
		coltbl[LIGHT]    = CRGB(30,30,31);
		coltbl[SHADOW]   = CRGB(8,8,9);
		coltbl[BLACK]    = CRGB(0,0,0);
		coltbl[WHITE]    = CRGB(31,31,31);
		coltbl[DARKGRAY] = CRGB(15,15,16);
	}
	else
	{
		static uint tbl16M[] =
			{ 0x2109, 0x4e75, 0x3728, 0x67f5, 0x4e73, 0x640f, 0x56b6, 0x3df1,
			  0x0000, 0x3df0, 0x0360, 0x0015, 0x2d6b, 0x7c1f, 0x7bdf, 0x7fff };
		coltbl = MG_getColorTable(3);
		int i;
		for (i=0; i<16; i++)
		{
			static uint _31_255[] =
				{  0,8,16,25, 33,41,49,58, 66,74,82,90, 99,107,115,123,
				   132,140,148,156, 165,173,181,189, 197,206,214,222, 
				   230,239,247,255};
			int r,g,b;
			GETRGB31(tbl16M[i],r,g,b);
			coltbl[i] = (_31_255[b]<<16)|(_31_255[g]<<8)|_31_255[r];
		}
	}
#else
	// guiColTbl = MG_getColorTable(2);
	  {
		unsigned int *coltbl;
		coltbl = MG_getColorTable(2);
		#define CRGB(r,g,b) (((r)*32+(g)*1024+(b))+(((r)*32+(g)*1024+(b))<<16))
		coltbl[GRAY]     = CRGB(21,21,22);
		coltbl[LIGHT]    = CRGB(30,30,31);
		coltbl[SHADOW]   = CRGB(8,8,9);
		coltbl[BLACK]    = CRGB(0,0,0);
		coltbl[WHITE]    = CRGB(31,31,31);
		coltbl[DARKGRAY] = CRGB(15,15,16);
		#undef CRGB
	  }
#endif
#endif
}

	// guiColTbl = MG_getColorTable(2);
	//   {
	// 	unsigned int *coltbl;
	// 	coltbl = MG_getColorTable(2);
	// 	#define CRGB(r,g,b) (((r)*32+(g)*1024+(b))+(((r)*32+(g)*1024+(b))<<16))
	// 	coltbl[GRAY]     = CRGB(21,21,22);
	// 	coltbl[LIGHT]    = CRGB(30,30,31);
	// 	coltbl[SHADOW]   = CRGB(8,8,9);
	// 	coltbl[BLACK]    = CRGB(0,0,0);
	// 	coltbl[WHITE]    = CRGB(31,31,31);
	// 	coltbl[DARKGRAY] = CRGB(15,15,16);
	// 	#undef CRGB
	//   }
