
	/*
		sudAuCul ]|[ a sudoku game..
						.(c) 2k6 by ferof/dph
												*/

/**  licence ***************

	sudAuCul binarie and source code cannot be used for any commercial purpose
	you are not allowed to copy grind genered

  ******************/


// declare screen buffer var
int WIDTH=256, HEIGHT=256, *pixel ;
int fSIZE=(WIDTH*HEIGHT) ;

// include some usefull lib
#include "./Gdl/Gdl.h"			// my own graphic lib
#include "./myMix'r/myMixr.h"	// my poor&small sound mixer, for playing samples onto minifmod output..
#include "./s3lib/s3m.h"		// my own s3m parser, to load sample who'll be read by myMixer..
//#include "./xml.ib/xml.h"		// my own xml parser
//#include "./xml.ib/xml.cpp"
//#include "./gfx/s1font.h"		// a font ...
#include "./gfx/s1font.h"		// a font ...
#include "./gfx/s3font.h"		// a font ...
//#include "./gfx/flashfont.h"	// a turtle on a tree
#include "./gfx/greenfont.h"	// another turtle, without tree
#include "./gfx/refresh.h"
#include "./gfx/cursor20.h"

int **mfont[] = { s3font,s1font,greenfont }; // an array for fonts

#include "./xm/saveMyDick.xm.h"//DLZ-HSAW.XM.h"

u32 setRealNewGame(void);

#include "tinyptc.h"			// the framebuffer TinyPTC, by Gaffer
#include "../lib/minifmod.h"	// the xm replayer minifmod, by Firelight Technologies
#include "minifmodio.cpp"		// xm lib, i/o callback code
#include <windows.h>

#include "./Gdl/Gdl.h"

//#include "../object.h"

void onClick(int button)
{  if(button == -1) // left click
	if(mousex > 5 && mousex < 20) // click on 'refresh' ?
		if(mousey > 5 && mousey < 18)
			setRealNewGame();
}

#include "./picore.h"

void fillScreen(void)
{	int * s = pixel;
	u32 size = WIDTH*HEIGHT ;
	for(u32 n=0;n<size;n++)
		*s++ = n;
}

void decompSprites(void) // will uncompress game gfx from 4b to 32b
{	for(u32 n=0;n<91;n++)
		{	s1font[n]		=	data2Gfm((u8*)s1font[n]);
			s3font[n]		=	data2Gfm((u8*)s3font[n]);
			greenfont[n]	=	data2Gfm((u8*)greenfont[n]);
		};
	for(n=0;n<9;n++)
			cursor20[n]	=	data2Gfm((u8*)cursor20[n]);
	*refresh = data2Gfm((u8*)*refresh);
	setGdlfont(*mfont);
}

//#include "./Gdl/map.h"

u8*grille ;
u8*currentValue ;

u32 difficult = 0 ;

void logGrille(void)
{	char text[256];
	for(u32 l=0;l<9;l++)
	{	for(u32 c=0;c<9;c++)
		 text[c] = grille[l*9+c]+'0' ;
		text[9] = 0 ;
		printlr(text);
	};
}

char * loadString = "-\\|/-";
u32    loadStrPos = 0;

u8 getGrille(u32 c, u32 l)
{	return grille[c+9*l];
}

#define getLegalValue do{value=1+(rand()%9);}while(setValue[value]);
#define getLegalValueSecure trynb=0;do{value=1+(rand()%9);trynb++;}while(setValue[value]&&trynb<24);

u32 setRealNewGame(void) // will compute a new grind..
{	u32 c,l,value,ntry=0,trynb;
	u8*g ;
//	log(); 
	reset:

	++ntry;
	memset(grille,0,256);

	u32 setValue[10];

	//log();
	//log("fill center line");
	memset(setValue,0,40);
	g = grille+9*4;
	// first, set middle line
	for(c=0;c<9;c++)
	{	getLegalValue
		setValue[value] = 1;
		g[c] = value;
	};
	
	// in second, set middle colon
		// start in middle, to not get bad value
	memset(setValue,0,40);
	setValue[g[3]] = 1;
	setValue[g[4]] = 1;
	setValue[g[5]] = 1;
	
	//log("now compute center colon");
	for(l=3;l<6;l++)
	{	if(l==4)l++; // only made 3 and 5
		getLegalValue
		//printlr("find value of #%i : %i",l,value);
		setValue[value] = 1;
		grille[4+l*9] = value;
	};

	setValue[g[3]] = 0;
	setValue[g[5]] = 0;

	for(l=0;l<9;l++)
	{	if(l==3)l=6; // only made border
		getLegalValue
		//printlr("find value of #%i : %i",l,value);
		setValue[value] = 1;
		grille[4+l*9] = value;
	};

	//log("now compute center square...");

	// now finish to fill center square
	memset(setValue,0,40);
	setValue[g[3]] = 1; // set already filled value as already filled =)
	setValue[g[4]] = 1;
	setValue[g[5]] = 1;
	setValue[grille[4+3*9]] = 1;
	setValue[grille[4+5*9]] = 1;

	// fill up left corner
	getLegalValue
	setValue[value] = 1;
	grille[3+3*9] = value;

	// up right
	getLegalValue
	setValue[value] = 1;
	grille[5+3*9] = value;

	// down left
	getLegalValue
	setValue[value] = 1;
	grille[3+5*9] = value;

	// and down right corner..
	getLegalValue
	setValue[value] = 1;
	grille[5+5*9] = value;

	// ok, here we have center square and center line & colon filled
	// now fill center up down left & right square

	// start with up square
		// set right colon
		// define value already set in this square and in right colon..
	memset(setValue,0,40);
	g = grille;
	// set already square set value
	setValue[g[4]] = 1;
	setValue[g[4+9]] = 1;
	setValue[g[4+18]] = 1;
	// and colon set value
	for(l=3;l<6;l++)
		setValue[grille[5+l*9]] = 1;
	
	// now fill square right..
	for(l=0;l<3;l++)
	{	getLegalValue
		setValue[value] = 1;
		grille[5+l*9] = value;
	};
	
	// do the same for left square colon
	memset(setValue,0,40);
	setValue[g[4]] = 1;
	setValue[g[4+9]] = 1;
	setValue[g[4+18]] = 1;
	setValue[g[5]] = 1;
	setValue[g[5+9]] = 1;
	setValue[g[5+18]] = 1;

	for(l=3;l<6;l++)
		setValue[grille[3+l*9]] = 1;

	// now fill square left..
	for(l=0;l<3;l++)
	{	getLegalValueSecure // from here we can got an impossible grind!
		if(trynb>=24) goto reset;
		setValue[value] = 1;
		grille[3+l*9] = value;
	};

	// ok, square center up is fill, now fill square down!
		// start with square right colon..
	
	memset(setValue,0,40);
	g = grille + 6*9;
	for(l=0;l<3;l++)
		setValue[g[4+9*l]] = 1;
	g = grille;
	for(l=0;l<6;l++)
		setValue[g[5+l*9]] = 1;
	for(l=6;l<9;l++)
	{	getLegalValueSecure
		if(trynb>=24) goto reset;
		setValue[value] = 1;
		grille[5+l*9] = value;
	};
		// now do square left colon..

	memset(setValue,0,40);
	g = grille + 6*9;
	for(l=0;l<3;l++)
		setValue[g[4+9*l]] = 1;
	g = grille;
	for(l=0;l<6;l++)
		setValue[g[3+l*9]] = 1;
	for(l=6;l<9;l++)
	{	getLegalValueSecure
		if(trynb>=24) goto reset;
		setValue[value] = 1;
		grille[3+l*9] = value;
	};

	// ok, if here, square down full filled, now proceed left square..

	// start fill with up square line

	memset(setValue,0,40);
	g = grille + 4*9;
	for(c=0;c<3;c++)
		setValue[g[c]] = 1; // square middle value
	g = grille + 3*9 + 3;
	for(c=0;c<3;c++)
		setValue[g[c]] = 1;	// up line

	for(c=0;c<3;c++)
	{	getLegalValueSecure
		if(trynb>=24) goto reset;
		setValue[value] = 1;
		grille[3*9 + c] = value;
	};

	// now fill down square line

	memset(setValue,0,40);
	g = grille + 4*9;
	for(c=0;c<3;c++)
		setValue[g[c]] = 1; // square middle value
	g = grille + 3*9;
	for(c=0;c<3;c++)
		setValue[g[c]] = 1;	// square up line
	g = grille + 5*9 + 3;
	for(c=0;c<3;c++)
		setValue[g[c]] = 1;	// down line

	for(c=0;c<3;c++)
	{	getLegalValueSecure
		if(trynb>=24) goto reset;
		setValue[value] = 1;
		grille[5*9 + c] = value;
	};

	// ok square left is fill now proceed with right square

		// fill up line of right square
	memset(setValue,0,40);
	g = grille + 4*9 + 6;
	for(c=0;c<3;c++)
		setValue[g[c]] = 1; // square middle value
	g = grille + 3*9;
	for(c=0;c<6;c++)
		setValue[g[c]] = 1;	// up line

	for(c=6;c<9;c++)
	{	getLegalValueSecure
		if(trynb>=24) goto reset;
		setValue[value] = 1;
		grille[3*9 + c] = value;
	};
		// now fill down line of right square

	memset(setValue,0,40);
	g = grille + 4*9 + 6;
	for(c=0;c<3;c++)
		setValue[g[c]] = 1; // square middle value
	g = grille + 3*9;
	for(c=6;c<9;c++)
		setValue[g[c]] = 1;	// up line
	g = grille + 5*9;
	for(c=0;c<6;c++)
		setValue[g[c]] = 1;	// up line

	for(c=6;c<9;c++)
	{	getLegalValueSecure
		if(trynb>=24) goto reset;
		setValue[value] = 1;
		grille[5*9 + c] = value;
	};

	// ok we have a cross :)
	// now need to fill all corner square

		// start with up left square corner

	// set up line...

	for(c=0;c<3;c++)
	{	memset(setValue,0,40);
		for(l=0;l<c;l++)
			setValue[grille[l]] = 1;
		g = grille + 3;
		for(l=0;l<3;l++)
			setValue[g[l]] = 1; // up line value
		g = grille + 3*9 + c;
		for(l=0;l<3;l++) // middle square colon value
			setValue[g[l*9]] = 1 ;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[c] = value;
	}

	// set middle line

	for(c=0;c<3;c++)
	{	memset(setValue,0,40);
		for(l=0;l<c;l++)
			setValue[grille[l+9]] = 1;
		g = grille + 3 + 9;
		for(l=0;l<3;l++)
			setValue[g[l]] = 1; // middle line value
		g = grille + 3*9 + c;
		for(l=0;l<3;l++) // middle square colon value
			setValue[g[l*9]] = 1 ;
		for(l=0;l<3;l++) // up square line value
			setValue[grille[l]] = 1 ;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[c+9] = value;
	}

	// set down line

	for(c=0;c<3;c++)
	{	memset(setValue,0,40);
		for(l=0;l<c;l++)
			setValue[grille[l+18]] = 1;
		g = grille + 3 + 18;
		for(l=0;l<3;l++)
			setValue[g[l]] = 1; // down line value
		g = grille + 3*9 + c;
		for(l=0;l<3;l++) // middle square colon value
			setValue[g[l*9]] = 1 ;
		for(l=0;l<3;l++) // up square line value
			setValue[grille[l]] = 1 ;
		for(l=9;l<12;l++) // middle square line value
			setValue[grille[l]] = 1 ;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[c+18] = value;
	}

		// ok, up left square corner is fill, now made up right square corner

	// set up line...

	for(c=6;c<9;c++)
	{	memset(setValue,0,40);
		for(l=6;l<c;l++)
			setValue[grille[l]] = 1;
		g = grille;
		for(l=0;l<6;l++)
			setValue[g[l]] = 1; // up line value
		g = grille + 3*9 + c;
		for(l=0;l<3;l++) // middle square colon value
			setValue[g[l*9]] = 1 ;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[c] = value;
	}

	// set middle line

	for(c=6;c<9;c++)
	{	memset(setValue,0,40);
		for(l=6;l<c;l++)
			setValue[grille[l+9]] = 1;
		g = grille + 9;
		for(l=0;l<6;l++)
			setValue[g[l]] = 1; // middle line value
		g = grille + 3*9 + c;
		for(l=0;l<3;l++) // middle square colon value
			setValue[g[l*9]] = 1 ;
		for(l=6;l<9;l++) // up square line value
			setValue[grille[l]] = 1 ;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[c+9] = value;
	}

	// set down line

	for(c=6;c<9;c++)
	{	memset(setValue,0,40);
		for(l=6;l<c;l++)
			setValue[grille[l+18]] = 1;
		g = grille + 18;
		for(l=0;l<6;l++)
			setValue[g[l]] = 1; // down line value
		g = grille + 3*9 + c;
		for(l=0;l<3;l++) // middle square colon value
			setValue[g[l*9]] = 1 ;
		for(l=6;l<9;l++) // up square line value
			setValue[grille[l]] = 1 ;
		for(l=15;l<18;l++) // middle square line value
			setValue[grille[l]] = 1 ;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[c+18] = value;
	}

	// hehe up right corner filled, now still the 2 down corner..

	// line up of the twice corner
	// for left corner
	for(c=0;c<3;c++) // for eatch colon of up line
	{	memset(setValue,0,40);
		// ok, now retreve current colon values filled for now
		for(l=0;l<6;l++) setValue[grille[l*9+c]] = 1;
		// get values filled in this up line
		g = grille + 6*9;
		for(l=0;l<6;l++) setValue[g[l]] = 1;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[6*9+c] = value;
	};
	// and right
	for(c=6;c<9;c++) // for eatch colon of up line
	{	memset(setValue,0,40);
		// retreve value set for now in this up line
		g = grille + 6*9;
		for(l=0;l<9;l++) setValue[g[l]] = 1;
		// ok, now retreve current colon values filled for now
		for(l=0;l<6;l++) setValue[grille[l*9+c]] = 1;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[6*9+c] = value;
	};

	// middle line
	// for left
	for(c=0;c<3;c++) // for eatch colon
	{	memset(setValue,0,40);
		// ok, now retreve current colon values filled for now
		for(l=0;l<7;l++) setValue[grille[l*9+c]] = 1;
		// get values filled in this middle line
		g = grille + 7*9;
		for(l=0;l<6;l++) setValue[g[l]] = 1;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[7*9+c] = value;
	};
	// and right
	for(c=6;c<9;c++) // for eatch colon of up line
	{	memset(setValue,0,40);
		// retreve value set for now in this up line
		g = grille + 7*9;
		for(l=0;l<9;l++) setValue[g[l]] = 1;
		// ok, now retreve current colon values filled for now
		for(l=0;l<7;l++) setValue[grille[l*9+c]] = 1;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[7*9+c] = value;
	};

	// it only still down line..
	// left
	for(c=0;c<3;c++) // for eatch colon
	{	memset(setValue,0,40);
		// ok, now retreve current colon values filled for now
		for(l=0;l<8;l++) setValue[grille[l*9+c]] = 1;
		// get values filled in this middle line
		g = grille + 8*9;
		for(l=0;l<6;l++) setValue[g[l]] = 1;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[8*9+c] = value;
	};
	// right
	for(c=6;c<9;c++) // for eatch colon of up line
	{	memset(setValue,0,40);
		// retreve value set for now in this up line
		g = grille + 8*9;
		for(l=0;l<9;l++) setValue[g[l]] = 1;
		// ok, now retreve current colon values filled for now
		for(l=0;l<8;l++) setValue[grille[l*9+c]] = 1;
		getLegalValueSecure	if(trynb>=24) goto reset;
		grille[8*9+c] = value;
	};

	// now all grind is fill, time to unmask some value...

	// we unmask from 0 to 5 block per square (try to not unmask a value who already is unmask and is in the same colon/line)
	memset(currentValue,0,128);
	u32 nless=0, nmany=0, nnot=0, ok;
	for(c=0;c<3;c++) // for eatch square
	{	for(l=0;l<3;l++)
		{	// set pointer on current square up left
			g = currentValue + c*3 + l*3*9;
			
			do {	value = rand()%6; // how many block to unmask ?
					ok=1; // don't fill with some less or many block
					if( !value && ++nnot>2) ok=0;
					if(value>3 && ++nmany>2)ok=0;
					if(value<3 && ++nless>2)ok=0;
			} while(!ok);

			while(value--)
			{	u32 x,y,v,m,n=0 ;
				do	{	memset(setValue,0,40);
						do {	x = rand()%3;	y = rand()%3;
								v = g[(x+y*9)-128] ;
								m = g[x+y*9];
						} while(m);

						for(u32 cc=0;cc<9;cc++)
							setValue[g[(cc+y*9)-128]] = (g[(cc+y*9)] == 1);
						
						for(u32 ll=0;ll<9;ll++)
							setValue[g[(x+ll*9)-128]] = (g[(x+ll*9)] == 1);

					} while(setValue[v] || ++n == 3) ;

				g[x+y*9] = 1;
			};
		}
	};

//printlr("try#%i",ntry);
	return ntry ; // return try number need to create this level.. will be ~3000
	// ok we have our level!
}

void showGrille(void)
{	u32 z, value;
	for(u32 l=0;l<9;l++)
		for(u32 c=0;c<9;c++)
		{	z = c+l*9;
			switch((currentValue[z])&0xf)
			{	case 0 : // empty
				break;
				case 1 : // unmasked
					value = grille[c+l*9];
					if(value) zdrawGfm((*mfont)[value+('0'-' ')],xy2scr(42+20*c,42+20*l));
				break;
				case 2 : // filled by player
					value = (currentValue[z])>>4 ;
					if(value && value<10) zdrawGfm((mfont[1])[value+('0'-' ')],xy2scr(42+20*c,42+20*l));
				break;
				case 3 : // filled by player, not sure
					value = (currentValue[z])>>4 ;
					if(value && value<10) zdrawGfm((mfont[2])[value+('0'-' ')],xy2scr(42+20*c,42+20*l));
				break;
				default :
					//zdrawGfm((*mfont)[grille[c+l*9]+('0'-' ')],xy2scr(42+20*c,42+20*l));
				break;
			};
		};
}

static int*wave=0;

#include "./xm/PRI.S3M.h"

struct s3m *s3m, *curents3m = 0 ;

void onS3mDrop(const char*path)
{	log();
	u32 fileSize ;	static u8*s3m = 0 ;
	if(s3m) free(s3m);	s3m = loadFile(path,&fileSize);
	struct s3m * mys3m = loadS3m(s3m,fileSize);
	if(curents3m) free(curents3m) ;	curents3m = mys3m ;

}

	int * whiteLine ;
	int * blackLine ;

void showCursor(u32 x, u32 y,u32 x1, u32 y1, u32 size, u32 size1, int color, int color1,u32 time)
{	u32 sx = abs(x1-x);
	u32 sy = abs(y1-y);

	
	static u32 counter = 0;	// <127 for colored, >127 for transparent
	u32 way = 0 ;		// 0 line, 1 colon
	static u32 lastTime=0;
	u32 pixelValue = 0; // 1 for transparent
	u32 tsize = size+size1;

	if(tick-lastTime > time)
	{	if(++counter >= tsize)
		{	pixelValue = 0;
			counter=0;
		} else if(counter >= size) pixelValue = 1;
		lastTime = tick;
	}

	u32 c = counter ;

	int * startScreen = pixel + x+y*WIDTH ;
	int * screen = startScreen ;
	do { 	u32 w = way;
			c++;
			if(c >= size) pixelValue=1 ;
			if(c >= tsize) { c=0; pixelValue=0; }
			
			if(pixelValue)	*screen = color1;
			else			*screen = color;
		
			switch(w) // and jump into screen
			{	case 0 : // right
					if(++screen > startScreen+sx)
					{	screen--;
						screen+=WIDTH;
						way=1;
					}
					break;
				case 1 : // down
					screen += WIDTH;
					if(screen > startScreen+sy*WIDTH)
					{	screen-=WIDTH;
						screen--;
						way=2;
					}
					break;
				case 2 : // left
					if(--screen < startScreen+(sy*WIDTH)-WIDTH)
					{	screen++;
						screen-=WIDTH;
						way=3;
					}
					break;
				case 3 : // up
					screen-=WIDTH;
					if(screen < startScreen)
						return ;
						way=3;
					break;
			};
	} while(screen > startScreen);
}

struct anim * cursor;
char infotext[96];
u32 currentMousseBlock = 255;

u32 refreshNeed = 0 ;
void refreshInfo(void)
{	refreshNeed=1;
}

void showGame(void)
{		fillScreen();
		static u32 setValue[10];
		int*color;
		for(u32 l=1;l<9;l++)
		{	if(l==3||l==6)	color = whiteLine;
				else		color = blackLine;
			ligne(40,40+20*l,220,40+20*l,color);
		};
		for(u32 c=1;c<9;c++)
		{	if(c==3||c==6)	color = whiteLine;
				else		color = blackLine;
			 ligne(40+20*c,40,40+20*c,220,color);
		};

		if(curentMixBf) // show music, vertical way
		{	int*color = (int*)curentMixBf;
			if(color)
			{	static int oldWidth = 0 ; static int wratio,hratio ;
				if(WIDTH!=oldWidth)	{	hratio = (curentMixSz<<15)/(HEIGHT-40);
										wratio = (32<<16)/(127);
										oldWidth=WIDTH;
									}
			
					int * ypos = &(pixel[26+30*WIDTH]) ;
					for(int n=0;n<HEIGHT-40;n++)
						{	register int size ;
							size = (n*hratio)>>16 ;  // select good value in output wave
							size = color[size]>>24 ; // take only wanted part..
							size = (size*wratio)>>16 ;	 // stretch value to output wanted zone..
							if(size>0)
									for(int z=0;z<size;z++) ypos[z] = wave[(z<<2)+64] ;	
							else	for(int z=0;z>size&&z>-26;z--) ypos[z] = wave[((-z)<<2)+64] ;
							//else	
							//memcpy(ypos,wave,size*4);
							ypos += WIDTH;
							//ligne(n,y,n,x,wave);
						};
			}
		}
		
		//for(u32 n=9;n;n--)
		//prints(-1,8,"123456789");
		//prints(-1,16,"%i.%i",mousex,mousey);
		showGrille();


//currentMousseBlock = 255;

		static int ox=0,oy=0;
		static u32 sqx=15,sqy=0, oldx=15,oldy=15;
		if(mousex>40&&mousex<220)
			if(mousey>40&&mousey<220)
			{	static u32 x=0,y=0;
				if(ox!=mousex || oy!=mousey || refreshNeed) // mouse have moved.
				{	//printlr("mouse move to %i.%i",ox,oy
					x = (mousex-40)/20 ; // yet not a size multiple of 2...
					y = (mousey-40)/20 ;
					currentMousseBlock = x+y*9 ;
					sqx = x/3;	sqy = y/3;
					ox = mousex; oy = mousey;
					if(oldx!=x||oldy!=y || refreshNeed) // we enter in a new 3*3 square
						{	refreshNeed=0;
							oldx=x; oldy=y;
							memset(setValue,0,40);
							//sqx = nsqx;	sqy = nsqy;

							// and in line & colon
							u8*line  = currentValue + y*9;
							u8*colon = currentValue + x;
							for(l=0;l<9;l++)
							{	if(l!=x+y*3)
								{	if(line[l])
										setValue[line[l-128]]=3;
									if(colon[l*9])
										setValue[colon[(l*9)-128]]=3;
								}
							};
							u8*g = currentValue + sqx*3 + sqy*3*9;
							for(l=0;l<3;l++) // compute value used in this square
								for(c=0;c<3;c++)
									{	u32 off = c+l*9;
										u32 value = (g[off])&0xf;
										if(value < 4 && value > 0)
										{	if(value==2)
											{	if((g[off])>>4 < 10)
													setValue[(g[off])>>4] = 2;
											}
											 else  setValue[g[off-128]]= 1;
										}
									};
						}

					char *t = infotext; *t=t[10]=t[20]=0; t[30]=0;

					for(u32 cc=1;cc<10;cc++)
					{	u32 value = setValue[cc]; t[30] = ' ';
						switch(value)
							{	case 1 :	*t = cc + '0'; // unmask
											t[10] = t[20] = ' ';
											t++;
								break;
								case 2 :	*t = t[20] = ' '; // user
											t[10] = cc + '0';
											t++;
								break;
								case 3 :	*t = t[10] = ' '; // in line or colon
											t[20] = cc + '0';
											t++;
								break;
								default :
											*t = t[10] = t[20] = ' ';
											t[30] = cc + '0';
											t++;
								break;
							};
					}; 	*t = t[10] = t[20] = t[30] = 0;
					//log(zzz);
					//system("debug.log");
				}

				//prints(-1,-1,"%i.%i",sqx,sqy);

				//if(x*20 != mousex+40) x++ ;
				//if(y*20 != mousex+40) y++ ;
				playAnim(&cursor,42+x*20,42+y*20);
				//prints(-1,-1,"hello");
				//if(currentValue[x+y*9]!=1)
					{	int **fnt = getGdlfont();
						setGdlfont(mfont[2]);
						prints(-1,8,infotext+20);	setGdlfont(mfont[1]);
						prints(-1,8,infotext+10);	setGdlfont(fnt);
						prints(-1,8,infotext);
						prints(-1,24,infotext+30);
					}
				showCursor(40+60*sqx,40+60*sqy,40+60*sqx+60,40+60*sqy+61,60,60,0x8080ff,0xffff80,42);
			}
				
		//zdrawGfm((*mfont)['8'-' '],xy2scr(42,42));
		

		//showCursor(16,16,32,32,6,0xff00ff);
		
		//for(u32 n=0;n<9;n++) drawAnim(&cursor,42+n*20,62+40);
		//playAnim(&cursor,62,62);

		drawGfm(*refresh,5,5);

}


void onWhell(int way) // way : zero for up and one for down
{	if((currentValue[currentMousseBlock]&0xf)!=1)
	{	int value = (currentValue[currentMousseBlock])>>4;
		
		if(!way)	++value;
		else		--value;

		if(value<0) value=0;
		else if(value>9) value=9;

		if(value)	currentValue[currentMousseBlock] = 2|(value<<4) ;
		else		currentValue[currentMousseBlock] = 0 ;
		
		refreshInfo();

		//if( (3&0xf)==3 ) prints(-1,-1,"***3==3***");

		//prints(-1,-1,"can change value %i %i %i",value,value,value);
	} //else prints(-1,-1,"unmasked value : %i",grille[currentMousseBlock]);


}


int main(void)
{	if(!iniSomeAndSomeThing())	// ini game,gfx,song,... blahblablb
		{ showMsg("     cannot render the framebuffer\n\nyou need directx 5 or more,\n\ta minimum of 16b color deep","that's too bad :|"); return 1 ; }

	fillScreen();
	prints(-1,-1,".. loading ..");
	ptc_update(pixel);
	log();
	if(!wave)
		{	wave = (int*)malloc(2048*4);
			for(int n=0;n<1024;n++)
			{	int red = 0x6b+n; if(red>0xff) red = 0xff;
				wave[n] = (red<<16)|(0x2b<<8)|0xc6 ;
			};
		}

	decompSprites();
	cursor = setAnim(cursor20,9,45);

	grille = (u8*)malloc(256); currentValue = grille + 128;


	whiteLine = (int*)malloc(2048);
	blackLine = whiteLine+256;
	memset(whiteLine,0xaa,1024);
	memset(blackLine,0x00,1024);

	setRealNewGame();

	u32 selected = 4;

	while(1)
	{	tick = GetTickCount();
		showGame();
		ptc_update(pixel);
	}

	return 1;
}


/*	// code to test speed of grind generator..

		// will made a grind in ~30ms
		// need ~3000 try to generate a grind

	unsigned int totalTry = 0 ;

	int btick = GetTickCount();

	#define levelNb 1024

	for(u32 n=0;n<levelNb;n++)
	{	totalTry += setRealNewGame();
	};

	int atick = GetTickCount();

	totalTry /= levelNb;

	log();

	printlr("average try for %i level : %i",levelNb,totalTry);
	printlr("total tick for %i levels : %i",levelNb,atick-btick);
	float myntick = (float)(atick-btick); myntick /= levelNb ;
	printlr("average tick for one level .. %i",(int)myntick);
	logGrille();
	system("debug.log");
*/
