for(end=0;end<666;) {
	int fps_ret = fps_emu(1);
	if(fps_ret != 0) {
	        draw_engine(buffer,player.mx,player.my);
        	for(i=0;i<10;i++) {
                	if(valox[i].varattu==1)fblend_add(transsu[valox[i].intensity],buffer,valox[i].x-(transsu[valox[i].intensity]->w/2),valox[i].y-(transsu[valox[i].intensity]->h/2),128);
	                valox[i].x=0;
        	        valox[i].y=0;
                	valox[i].varattu=0;
	                valox[i].intensity=0;

	                if(kabuum[i].mode==1) {
        	                kabuum[i].frame++;
                	        if(kabuum[i].frame==50)kabuum[i].mode=0;
                        	}
	                }
	
        	draw_compiled_sprite(buffer,baaris,0,0);
	        blit(conbuf,buffer,0,console_y,20,10,600,100);
		}

        update_time();

        //statsit
	if(fps_ret != 0) {
	        textprintf(buffer,filu[console_font].dat,466,130,-1,"%d:%d",give_time(2),give_time(1));
        	textprintf(buffer,filu[console_font].dat,20,380,-1,"Hp:%d/%d",player.hp,player.hp_max);
	        textprintf(buffer,filu[console_font].dat,20,390,-1,"Mn:%d/%d",player.mana,player.mana_max);
        	textprintf(buffer,filu[console_font].dat,20,400,-1,"Dex:%d",player.dexterity);
	        textprintf(buffer,filu[console_font].dat,20,410,-1,"Ac:%d",player.defense);
        	textprintf(buffer,filu[console_font].dat,20,420,-1,"Str:%d",player.damage); //Damage rating
	        textprintf(buffer,filu[console_font].dat,20,430,-1,"Lvl:%d",player.level);
        	textprintf(buffer,filu[console_font].dat,20,440,-1,"Exp:%d/%d",player.exp,player.exp_needet);
	        textprintf(buffer,filu[console_font].dat,20,450,-1,"Gold:%d",player.money);
        	textprintf(buffer,filu[console_font].dat,20,460,-1,"FPS:%.f1/60 Emu:%d/30",fps,fe);
		}

        if((give_time(1)==0)&&(give_time(0)==1)&&(wupdate_done==0)) {
                set_world_color();
                load_fwcbmp("gfx/knight.pcx",character[0]);
                load_fwcbmp("gfx/trees.lbm",trees);
                load_tilet("gfx/tilet.pcx");
                wupdate_done=1;
                }
        if(give_time(1)==50)wupdate_done=0;

        //CONSOLE SYSTEMS
        if((onkopaalla(9,101,18,110)==1)&&(mouse_b & 1)&&(console_y<=199))console_y++;
        if((onkopaalla(9,9,18,18)==1)&&(mouse_b & 1)&&(console_y>=1))console_y--;
        if((onkopaalla(621,9,631,23)==1)&&(mouse_b & 1)&&(console_y>=1))console_y=console_y-10;
        if((onkopaalla(621,97,631,111)==1)&&(mouse_b & 1)&&(console_y<=199))console_y=console_y+10;
        if(console_y<0)console_y=0;
        if(console_y>200)console_y=200;
	if(fps_ret != 0) {
	        if(onkopaalla(260,120,280,140)==1) {
        	        if(mouse_b & 1)setup();
                	textprintf_centre(buffer,filu[REDFONT].dat,mouse_x+30,mouse_y+30,-1,"Setup");
	                }

	        if(onkopaalla(280,120,300,140)==1) {
        	        if(mouse_b & 1)end=666;
                	textprintf_centre(buffer,filu[REDFONT].dat,mouse_x+30,mouse_y+30,-1,"Main menu");
	                }

	        if(onkopaalla(300,120,320,140)==1)
        	        {
                	textprintf_centre(buffer,filu[REDFONT].dat,mouse_x+30,mouse_y+30,-1,"Save game");
	                }

	        if(onkopaalla(320,120,340,140)==1) {
        	        textprintf_centre(buffer,filu[REDFONT].dat,mouse_x+30,mouse_y+30,-1,"Load game");
                	}

	        if(onkopaalla(340,120,360,140)==1) {
        	        textprintf_centre(buffer,filu[REDFONT].dat,mouse_x+30,mouse_y+30,-1,"Map");
                	}
		}

        if(key[KEY_ESC])end=666;
        if((keypressed()) && (talkwith == -1)) {
                if(key[KEY_T])super_console(filu[console_font].dat,"Time:%d:%d",give_time(2),give_time(1));
                if(key[KEY_SPACE])explode_at(player.mx+10+rand ()%20,player.my+10+rand ()%20);

		if(fps_ret != 0) {
	                if(key[KEY_F10]) {
        	                read_line(CFG_FILE,0,puffi);
                	        super_console(filu[statu_font].dat,puffi);
                        	}

	                if(key[KEY_F11]) {
        	                read_line("manuska/fortunes.dat",rand ()%20,puffi);
                	        super_console(filu[gfont1].dat,puffi);
                        	}

	
        	        if((key[KEY_DOWN])&&(key[KEY_LEFT])&&(player.hanimo==0)&&(player.walk_mode==0))player.walk_mode=3;
                	if((key[KEY_DOWN])&&(key[KEY_RIGHT])&&(player.hanimo==0)&&(player.walk_mode==0))player.walk_mode=1;
	                if((key[KEY_UP])&&(key[KEY_RIGHT])&&(player.hanimo==0)&&(player.walk_mode==0))player.walk_mode=4;
        	        if((key[KEY_UP])&&(key[KEY_LEFT])&&(player.hanimo==0)&&(player.walk_mode==0))player.walk_mode=2;
                	if(player.walk_mode!=0)vimex=player.walk_mode;
	                if((key[KEY_RIGHT])&&(player.hanimo==0)&&(player.walk_mode==0))player.walk_mode=5;
        	        if((key[KEY_UP])&&(player.hanimo==0)&&(player.walk_mode==0))player.walk_mode=6;
                	if((key[KEY_LEFT])&&(player.hanimo==0)&&(player.walk_mode==0))player.walk_mode=7;
	                if((key[KEY_DOWN])&&(player.hanimo==0)&&(player.walk_mode==0))player.walk_mode=8;

	                if((key[KEY_LSHIFT])&&(player.hanimo==0))player.walk_mode=0;
			}
	        if((key[KEY_ALT])&&(ready_wait==0)) {
        	        switch(vimex) {
                	        case 1:
                        	operate(player.mx+20,player.my+21,0);
                                break;
                                case 2:
                                operate(player.mx+20,player.my+19,0);
                                break;
                                case 3:
                                operate(player.mx+19,player.my+20,0);
                                break;
                                case 4:
                                operate(player.mx+21,player.my+20,0);
                                break;
                                case 5:
                                operate(player.mx+21,player.my+21,0);
                                break;
                                case 6:
                                operate(player.mx+19,player.my+21,0);
                                break;
                                case 7:
                                operate(player.mx+19,player.my+19,0);
                                break;
                                case 8:
                                operate(player.mx+19,player.my+21,0);
                                break;
                                }
                        ready_wait=40;
                        }
                }
        if(talkwith >= 0) {
            open_chat_terminal(talkwith);
            }

	if(fps_ret != 0) {
		blit(mpointer,pointeris,0,0,0,0,30,30);

	        if(player.hanimo==0) {
        	        if((player.walk_mode==1)&&(voidaanko_astua(player.mx+20,player.my+20,SOUTH)==1))player.walk_mode=0;
                	if((player.walk_mode==2)&&(voidaanko_astua(player.mx+20,player.my+20,NORTH)==1))player.walk_mode=0;
	                if((player.walk_mode==3)&&(voidaanko_astua(player.mx+20,player.my+20,WEST)==1))player.walk_mode=0;
        	        if((player.walk_mode==4)&&(voidaanko_astua(player.mx+20,player.my+20,EAST)==1))player.walk_mode=0;
                	if((player.walk_mode==5)&&(voidaanko_astua(player.mx+20,player.my+20,SOUTHEAST)==1))player.walk_mode=0;
	                if((player.walk_mode==6)&&(voidaanko_astua(player.mx+20,player.my+20,NORTHEAST)==1))player.walk_mode=0;
        	        if((player.walk_mode==7)&&(voidaanko_astua(player.mx+20,player.my+20,NORTHWEST)==1))player.walk_mode=0;
                	if((player.walk_mode==8)&&(voidaanko_astua(player.mx+20,player.my+20,SOUTHWEST)==1))player.walk_mode=0;
	                }

	        if(player.walk_mode!=0) {
        	        player.hanimo++;
                	blit(character[0],phil,(player.hanimo/2)<<5,(player.walk_mode-1)*60,0,0,32,60);
	                }
        	else blit(character[0],phil,288,(vimex-1)*60,0,0,32,60);

	        //Movement controll
        	if(((player.hanimo==1) ||
	            (player.hanimo==3) ||
        	        (player.hanimo==5) ||
                	    (player.hanimo==7) ||
                        	(player.hanimo==9) ||
	                            (player.hanimo==11) ||
        	                        (player.hanimo==12) ||
                	                    (player.hanimo==14))&&((player.walk_mode>0)&&(player.walk_mode<5))) {
	                if(player.walk_mode==1)move_to(SOUTH);
        	        if(player.walk_mode==2)move_to(NORTH);
                	if(player.walk_mode==3)move_to(WEST);
	                if(player.walk_mode==4)move_to(EAST);
        	        }
	        if(player.walk_mode==5)move_to(SOUTHEAST);
        	if(player.walk_mode==6)move_to(NORTHEAST);
	        if(player.walk_mode==7)move_to(NORTHWEST);
        	if(player.walk_mode==8)move_to(SOUTHWEST);

	        if((player.hanimo==16) && (player.walk_mode<=4)) {
        	        vimex=player.walk_mode;
                	player.walk_mode=0,player.hanimo=0;
	                if(sounds==0) sample(tile[get_tile(player.mx+20,player.my+20)].step_sound,200);
        	        }

	        if((player.hanimo==16) && (player.walk_mode>=5)) {
        	        vimex=player.walk_mode;
                	player.walk_mode=0,player.hanimo=0;
	                if(sounds==0) sample(tile[get_tile(player.mx+20,player.my+20)].step_sound,200);
        	        }
		}

	//TRAPS!
	if(get_sprite(player.mx+20,player.my+20)==TRAP) trap_at(player.mx+20,player.my+20,YES);

	
        if(fps_ret != 0) {
		draw_sprite(buffer,pointeris,mouse_x,mouse_y);
		_motoko_all_logic();
		}
        evolute_player();

        if(key[KEY_F12])save_pcx("shot.pcx",buffer,pal);
        if(fps_ret != 0) {
	        if(animo==25)animo=0,fr++;
        	if(ready_wait>=1)ready_wait--;
	        if(fr==3)fr=0;
        	animo++;
	        do_ai();
		}
        release_draw_for_NPCs();



        if(fps_ret != 0) blit(buffer,screen,0,0,0,0,640,480);
	}