/* Sample of "button.o", linked with button.o vircon.o symbol.o
                                                     SAKU    */

#include <stdio.h>
#include <egb.h>
#include "button.h"
#include "vircon.h"

typedef struct
{
	char	name[16];	/* name */
	int		inp;		/* Intelligence Point */
	int		stp;		/* Strength Point */
	int		lup;		/* Luck Point */
	int		spp;		/* Speed Point */
	int		rep;		/* Reputation Point */
	int		money;		/* money */
} THIEF;

typedef struct
{
	char	stor[16];
	char	master[16];
	int		sort;
	int		money;
	int		scale;
	int		person;
	int		key;
} STORE;

char	egbwork[1536];
char	moswork[4096];

void	egbInit();
void	egbTerm();
void	mouseInit();
void	mouseTerm();
void	graphicInit();
void	menuLoop( int, int, int );

char	rootcom[4][8] = { "外出", "情報", "盗め", "機能\0" };
char	*mes[] = { "外出", "情報", "盗め", "機能\0", "ボタン外" };

void	main()
{
	int		sw,mx,my;
	int		b[4];
	int		i;

	egbInit();
	mouseInit();

	BT_init( egbwork );
	VC_init( egbwork, 0, 64, 40, 4, 15, 1 );
	for( i=0; i<4; i++ )
		b[i] = BT_create( 1, i*48, 0, 48, 20, rootcom[i] );
	sw = 0;
	while( sw != 2 )
	{
		MOS_rdpos( &sw, &mx, &my );
		for( i=0; i<4; i++ )
			menuLoop( b[i], mx, my );
		if( sw == 1 )
		{
			int		com = 4;
			for( i=0; i<4; i++ )
				if( BT_check( b[i], mx, my ) == BTC_ON )
					com = i;
			VC_printf( "(%d,%d):%s\n", L_INT, mx, L_INT, my, POINTER, mes[com] );
		}
	}
	for( i=0; i<4; i++ )
		BT_disappear( b[i] );

	mouseTerm();
	egbTerm();
	return;
}

void	egbInit()
{
	EGB_init( egbwork, 1536 );
	EGB_resolution( egbwork, 0, 3 );
	EGB_resolution( egbwork, 1, 3 );
	EGB_displayPage( egbwork, 0, 3 );
	EGB_writePage( egbwork, 1 );
	return;
}

void	egbTerm()
{
	MOS_screenterm( egbwork );
	return;
}

void	mouseInit()
{
	MOS_start( moswork, 4096 );
	MOS_sysIcon( 81, 0, 0, 0 );
	MOS_writePage( 0 );
	MOS_color( 0, 15 );
	MOS_disp( 1 );
	return;
}

void	mouseTerm()
{
	MOS_disp( 0 );
	MOS_end();
	return;
}

void	menuLoop( int b1, int cx, int cy )
{
	if( BT_check( b1, cx, cy ) == BTC_ON )
		BT_reverse( b1, 1 );
	else
		BT_reverse( b1, 0 );
	return;
}
