#include<time.h>
#include <allegro.h>
#include "aldumb.h"

void read_line(char *file_name,int line, char *output);

int main ()
{
char puffi[1024];
DUH *duh;
AL_DUH_PLAYER *dp;

    allegro_init ();
    install_timer();            // must call this!!
    install_keyboard();
set_color_depth(16);


read_line("play.cfg",1,puffi);
if(strcmp(puffi,"GFX_ON")==0)
        {
        set_gfx_mode(GFX_AUTODETECT_WINDOWED,320,200,0,0);
        text_mode(-1);
        clear_to_color(screen,makecol16(200,200,200));
        textprintf_centre(screen,font,160,10,makecol(0,0,0),"Owet softwares TLOJ music player.");
        textprintf_centre(screen,font,160,20,makecol(0,0,0),"Rik u r the best!");
        read_line("play.cfg",3,puffi);
        textprintf_centre(screen,font,160,30,makecol(0,0,0),"Playing:%s with DUMB",puffi);
        textprintf_centre(screen,font,160,150,makecol(0,0,0),"PRESS ANY KEY TO QUIT!");
        }

set_volume_per_voice(0);
install_sound (DIGI_AUTODETECT, MIDI_NONE, NULL);
atexit(&dumb_exit);
dumb_register_stdfiles();
read_line("play.cfg",3,puffi);
duh = dumb_load_s3m(puffi);
dp = al_start_duh(duh, 2, 0, 1.0, 4096, get_config_int("sound", "sound_freq", 44100));
while(!keypressed())
        {
        al_poll_duh(dp);
        yield_timeslice();
        }
al_stop_duh(dp);
unload_duh(duh);
allegro_exit();
return (0);
}
END_OF_MAIN();

void read_line(char *file_name,int line, char *output)
{
FILE *f;
char buf[1024];
int num=0;
f=fopen(file_name,"r");
while((fgets(buf,1024,f))!=0)
	{
	if(num==line)
		{
                buf[strlen(buf)-1]=0;
                strcpy(output,buf);
                //memcpy(output,buf,strlen(buf)-1);
		break;
		}
	num++;
	}
fclose(f);
free(buf);
}

