/* By Trouble₯MakerΜi.i */

#include    <egb.h>
#include    <string.h>
#include    "XFONT.H"
#include	"GRAPHIC.H"

char sysfont[21][19]={
	{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00 },	/* Ά°ΏΩ±έΐή° */
	{ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00 },	/* Ά°ΏΩBOX */
	{ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF },	/* ‘ */
	{ 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0xFF,
	  0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08 },	/* © */
	{ 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0xFF,
	  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },	/* ¨ */
	{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	  0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08 },	/* ¦ */
	{ 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0xF8,
	  0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08 },	/* § */
	{ 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x0F,
	  0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08 },	/* ₯ */
	{ 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },	/*  γ */
	{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },	/*  */
	{ 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
	  0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08 },	/*   */
	{ 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
	  0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 },	/*   E */
	{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,
	  0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08 },	/* ‘ */
	{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,
	  0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08 },	/* ’ */
	{ 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x0F,
	  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },	/* € */
	{ 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0xF8,
	  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },	/* £ */
	{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
	  0x02,0x04,0x04,0x08,0x08,0x08,0x08,0x08,0x08,0x08 },	/* ‘ Ϋ */
	{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,
	  0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x08 },	/* ’ Ϋ */
	{ 0x08,0x08,0x08,0x08,0x08,0x04,0x04,0x02,0x01,
	  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },	/* € Ϋ */
	{ 0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0xC0,
	  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }	/* £ Ϋ */
	};

extern char work[];

void cur_pos(int x, int y)	/* x=0-79 y=0-24 */
{
char para[10];

    WORD(para+0)=x*8;
    WORD(para+2)=y*19+18;
    WORD(para+4)=0;
    WORD(para+6)=0x00;
    EGB_sjisString(work,para);
}

void put_ank(int x, int y, int ch)
{
	cur_pos(x, y);
	EGB_textZoom(work, 1,  8, 19 );
	EGB_anyChar( work, 8, 19, sysfont[ch] );
	EGB_textZoom(work, 1, 16, 16 );
}

void text_box( int x1, int y1, int x2, int y2, int fc, int bc, int type)
{
/*
		x1,y1
		‘’		fc=ΜΪ°ΡF	type 0 = Ύ’ό
		            		bc=ΜF	type 1 = p
		€£      (type=0)    type 2 = Ϋ
				   x2,y2
*/

	int i;

	if ( type == 0 ) {
		DSP_linebf((x1+1)*8,(y1+1)*19,(x2+2)*8-1,(y2+2)*19-1,8,4);	/* e */
		DSP_linebf((x1+1)*8,(y1+1)*19,x2*8,y2*19,bc,0);
		EGB_color( work, 0, fc);
		cur_pos(x1,y1);
		EGB_textZoom(work, 1, 8, 19 );
		for (i=0; i<=x2-x1; i++ ) EGB_anyChar( work, 8, 19, sysfont[2] );
		for (i=1; i<y2-y1; i++ ) {
			put_ank(x1 ,y1+i, 2 );
			put_ank(x2, y1+i, 2 );
		}
		EGB_textZoom(work, 1, 8, 19 );
		cur_pos(x1,y2);
		for (i=0; i<=x2-x1; i++ ) EGB_anyChar( work, 8, 19, sysfont[2] );
	}
	if ( type == 1 ) {
		EGB_color( work, 0, fc);
		put_ank(x1 ,y1, 12 );
		EGB_textZoom(work, 1, 8, 19 );
		for (i=1; i<x2-x1; i++ ) EGB_anyChar( work, 8, 19, sysfont[9] );
		put_ank(x2 ,y1, 13 );
		for (i=1; i<y2-y1; i++ ) {
			put_ank(x1 ,y1+i, 10 );
			put_ank(x2, y1+i, 10 );
		}
		put_ank(x1 ,y2, 14 );
		EGB_textZoom(work, 1, 8, 19 );
		for (i=1; i<x2-x1; i++ ) EGB_anyChar( work, 8, 19, sysfont[9] );
		put_ank(x2 ,y2, 15 );
	}
	if ( type == 2 ) {
		EGB_color( work, 0, fc);
		put_ank(x1 ,y1, 16 );
		EGB_textZoom(work, 1, 8, 19 );
		for (i=1; i<x2-x1; i++ ) EGB_anyChar( work, 8, 19, sysfont[9] );
		put_ank(x2 ,y1, 17 );
		for (i=1; i<y2-y1; i++ ) {
			put_ank(x1 ,y1+i, 10 );
			put_ank(x2, y1+i, 10 );
		}
		put_ank(x1 ,y2, 18 );
		EGB_textZoom(work, 1, 8, 19 );
		for (i=1; i<x2-x1; i++ ) EGB_anyChar( work, 8, 19, sysfont[9] );
		put_ank(x2 ,y2, 19 );
	}
	EGB_textZoom(work, 1, 16, 16 );
}

