
/********************************************************************
 *                                                                  *
 * Program      : AMIGA-BIORYTMI                                    *
 *                                                                  *
 * Version      : 1.03      (19.03.1992)    (09.04.1995)            *
 *                                                                  *
 * Description  : Ohjelma näyttää biorytmin syntymä- ja kohde-      *
 *                päivän perusteella                                *
 *                                                                  *
 * CLI-usage    : AmigaBiorytmi             (batch)                 *
 *                [run] Biorytmi [dd.mm.yy]                         *
 *                                                                  *
 * WB-usage     : AmigaBiorytmi             (batch)                 *
 *                                                                  *
 * Distribution	: PD-ohjelma                                        *
 *                                                                  *
 * Bugs         : Ei huomioi täydellisesti karkausvuosia            *
 *                                                                  *
 * Author       : Janne Kantola                                     *
 *                Fellmanninpuistokatu 20 B 26                      *
 *                92100  RAAHE ,  FINLAND                           *
 *                                                                  *
 *  E-mail      : janta@ratol.fi                                    *
 *                                                                  *
 ********************************************************************/

/*

Change history:

1.03    02.04.95    Lisätty FEA_ENGLISH_LANGUAGE

*/

#define  XX  588
#define  XXX 615
#define  YY    1
#define  TITLE "AMIGA-BIORYTMI v1.03 by Janne Kantola"

#include <proto/graphics.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/diskfont.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <graphics/gfxmacros.h>
#include <math.h>

extern UBYTE  JonoPuskuri[];
extern UBYTE  *error[];
extern struct NewScreen screen;
extern struct NewWindow window;
extern struct NewWindow aboutWindow;
extern struct Gadget Gadget6;
extern struct Gadget aboutGadget;
extern struct StringInfo JonoInfo;


/**************************** MÄÄRITTELYT ******************************/

VOID  CleanExit (int);
VOID  OpenAll(VOID);
VOID  TarkistaARG(UBYTE *);
UBYTE HandleIDCMP ( struct Window *);
VOID  HandleDGad(struct IntuiMessage *);
SHORT HandleUGad(struct IntuiMessage *);
VOID  DrawBox(SHORT, SHORT, SHORT, SHORT, SHORT, SHORT);
VOID  Texti(SHORT, SHORT, UBYTE *, struct TextFont *, SHORT);
VOID  Box(SHORT, SHORT, SHORT, SHORT, SHORT);
VOID  UusiDigit(SHORT, SHORT);
VOID  ElinTulostus(UBYTE *);
VOID  KeskiTulostus(struct Window *, SHORT,
		struct TextFont *, UBYTE *, SHORT);
VOID  Alusta(VOID);
VOID  AlustaRistikko(VOID); 
VOID  AlustaDigitit(VOID);	
VOID  About(VOID);
VOID  Biorytmi(VOID);

struct IntuitionBase *IntuitionBase = NULL;
struct Library		 *DiskfontBase  = NULL;
struct GfxBase *GfxBase = NULL;
struct Screen *screen1 = NULL;
struct Window *window1 = NULL;
struct RastPort *RP    = NULL;
struct TextAttr textAttr;
struct TextFont *textFont = NULL, *textFont2 = NULL, *oldTextFont = NULL;

#ifdef FEA_ENGLISH_LANGUAGE
UBYTE *kk[] = { " ", "january", "february", "march", "april", "may", "june",
      "july", "august", "september", "october", "november", "december" };
#else
UBYTE *kk[] = { " ", "tammi", "helmi", "maalis", "huhti", "touko", "kesä",
                     "heinä", "elo", "syys", "loka", "marras", "joulu" };
#endif

UWORD	colors[] = {
					0xFFF,
					0x000,
					0x922,
					0x999,
					0x666,
					0x1A1,
					0xB21,
					0xDD6 
				   };

SHORT numerox[12];

UBYTE string[255];
SHORT pa[12];
BYTE  p[6] = {55,55,55,55,55,55};
const BYTE VERSIO[] = 
      "$VER: Amiga-Biorytmi 1.03 (02.04.1995) Janne 'JanTa' Kantola";

/******************************* MAIN *********************************/

VOID main ( argc,argv)
int argc;
char *argv[];

{
ULONG signalmask, signals;
UBYTE done = 0;

	TarkistaARG(argv[1]);
	OpenAll();
	Alusta();
	SetFont(RP, textFont);

	signalmask = 1L << window1 -> UserPort -> mp_SigBit;

	while ( !done)
		{
		signals = Wait(signalmask);
		if (signals & signalmask)
			done = HandleIDCMP(window1);
		};
	CleanExit(RETURN_OK);

}


/********* TÄMÄ FUNKTIO KÄSITTELEE INTUITION-TAPAUKSET *************/

UBYTE HandleIDCMP(win)
struct Window *win;
{
	UBYTE flag = 0;
	struct IntuiMessage *msg;
	ULONG class;

	while ( msg = (struct IntuiMessage *) GetMsg(win->UserPort) )
		{
		class = msg->Class;
		ReplyMsg ( ( struct Message *) msg);
		switch ( class )
			{
			case CLOSEWINDOW:
				flag = 1;
				break;
			case GADGETUP:
				flag = HandleUGad(msg);
				break;
			case GADGETDOWN:
				HandleDGad(msg);
				break;
			default:
				break;
			}
		}
	return (flag);
}


/********** TÄMÄ FUNKTIO KÄSITTELEE GADGET-ALAS-TAPAUKSET **************/

VOID HandleDGad(m)
struct IntuiMessage *m;
{
struct Gadget *g;			/* TÄHÄN SAADAAN SELVILLE GADGETIN TIEDOT */
USHORT id;					/* VARSINAINEN ID-MUUTTUJA */
SHORT  digit;

	g  = (struct Gadget *)m->IAddress;		/* GADGETIN TIEDOT */
	id = g->GadgetID;						/* GADGETIN ID */

	if ( id==11 || id==17 )					/* kymmenet päivät + */
		{
		if (id==11)		digit=0;
		else			digit=6;

		pa[digit]++;
		if (pa[digit]==4)	pa[digit]=0;
		UusiDigit(numerox[digit], pa[digit]);
		}

	if ( id==31 || id==37 )					/* kymmenet päivät - */
		{
		if (id==31)		digit=0;
		else			digit=6;

		pa[digit]--;
		if (pa[digit]==-1)	pa[digit]=3;
		UusiDigit(numerox[digit], pa[digit]);
		}

	if ( id==13 || id==19 )					/* kymmenet kuukaudet + */
		{
		if (id==13)		digit=2;
		else			digit=8;

		pa[digit]++;
		if (pa[digit]==2)	pa[digit]=0;
		UusiDigit(numerox[digit], pa[digit]);
		}

	if ( id==33 || id==39 )					/* kymmenet kuukaudet - */
		{
		if (id==33)		digit=2;
		else			digit=8;

		pa[digit]--;
		if (pa[digit]==-1)	pa[digit]=1;
		UusiDigit(numerox[digit], pa[digit]);
		}

	if ( id==12 || id==18 || id==14 || id==20 || id==15 || id==21 || id==16 || id==22 )
		{
		if (id==12)		digit=1;			/* päivät + */
		if (id==18)		digit=7;

		if (id==14)		digit=3;			/* kuukaudet + */
		if (id==20)		digit=9;

		if (id==15)		digit=4;			/* 10 vuodet + */
		if (id==21)		digit=10;

		if (id==16)		digit=5;			/* vuodet + */
		if (id==22)		digit=11;

		pa[digit]++;
		if (pa[digit]==10)	pa[digit]=0;
		UusiDigit(numerox[digit], pa[digit]);
		}

	if ( id==32 || id==38 || id==34 || id==40 || id==35 || id==41 || id==36 || id==42 )
		{
		if (id==32)		digit=1;			/* päivät - */
		if (id==38)		digit=7;

		if (id==34)		digit=3;			/* kuukaudet - */
		if (id==40)		digit=9;

		if (id==35)		digit=4;			/* 10 vuodet - */
		if (id==41)		digit=10;

		if (id==36)		digit=5;			/* vuodet - */
		if (id==42)		digit=11;

		pa[digit]--;
		if (pa[digit]==-1)	pa[digit]=9;
		UusiDigit(numerox[digit], pa[digit]);
		}

	if ( id==7 )
		{
		}

}	/* END OF HandleDGad() */


/*********** TÄMÄ FUNKTIO KÄSITTELEE GADGET-YLÖS-TAPAUKSET ***************/

SHORT HandleUGad(m)
struct IntuiMessage *m;
{
struct Gadget *g;			/* TÄHÄN SAADAAN SELVILLE GADGETIN TIEDOT */
USHORT id;					/* VARSINAINEN ID-MUUTTUJA */
SHORT  retval = 0;

g  = (struct Gadget *)m->IAddress;		/* GADGETIN TIEDOT */
id = g->GadgetID;						/* GADGETIN ID */

if ( id == 1 )							/* LOPETUS !!! */
	{
	retval = 1;
	}

if ( id == 2 )							/* RESET !!! */
	{
	Box(0, 20, 639, 30, 0);				/* nimi pois */
	strcpy(JonoPuskuri, "");			/* myös gadgetin puskurista */
	JonoInfo.NumChars  = 0;				/* merkkejä gadgetissa 0 */
	JonoInfo.BufferPos = 0;
	JonoInfo.DispPos   = 0;
	JonoInfo.DispCount = 0;
	RefreshGList(&Gadget6, window1, NULL, 1);
	ActivateGadget(&Gadget6, window1, NULL);
	AlustaRistikko();
	AlustaDigitit();	
	}

if ( id == 5 )							/* BIORYTMI !!! */
	{
	AlustaRistikko();
	Biorytmi();
	}

if ( id == 6 )							/* NIMI */
	{
	Box(0, 20, 639, 40, 0);
	strcpy(string, JonoPuskuri);
	KeskiTulostus(window1, 40, textFont, string, 2);
	}

if ( id == 4 )							/* ABOUT !!! */
	{
	About();
	}

return (retval);
}


/******************************* DrawBox *********************************/

/*  x ja y = laatikon vasemman yläkulman koordinaatit
	width  = laatikon leveys    
	height = laatikon korkeus
	vari1  = laatikon valopuolen väri
	vari2  = laatikon varjopuolen väri */

VOID DrawBox(x, y, width, height, vari1, vari2)
SHORT x, y, width, height, vari1, vari2;
{
	SetAPen (RP, vari1);			/* VASEN- JA YLÄREUNA VAALEALLA */
	Move    (RP, x+width, y);
	Draw    (RP, x, y);
	Draw    (RP, x, y+height);
	Draw    (RP, x+1, y+height);
	Draw    (RP, x+1, y);
    
	SetAPen (RP, vari2);			/* OIKEA- JA ALAREUNA TUMMALLA */
	Move    (RP, x+1, y+height);
	Draw    (RP, x+width, y+height);
	Draw    (RP, x+width, y);
	Draw    (RP, x+width-1, y+1);
	Draw    (RP, x+width-1, y+height);
}


/******************************* Texti ********************************/

/*  x ja y = textin alun koordinaatit
	string = tulostettava texti
	fontti = tulostusfontti
	vari   = tulostusväri				*/

VOID Texti(x, y, string, fontti, vari)
SHORT x, y, vari;
UBYTE *string;
struct TextFont *fontti;
{
	SetAPen (RP, vari);						/* textin väri */
	Move    (RP, x, y);
	SetFont (RP, fontti);
	Text    (RP, string, strlen(string));
}


/******************************** Box ***********************************/

/*  x ja y = laatikon vasen ylänurkka
	w ja h = leveys ja korkeus     
	vari   = laatikon väri				*/

VOID Box(x, y, w, h, vari)
SHORT x, y, w, h, vari;
{
	SetAPen(RP, vari);
	RectFill(RP, x, y, x+w, y+h);
}


/**************************** UUSIDIGIT *******************************/

VOID UusiDigit(x, data)
SHORT x, data;
{
	sprintf(string,"%d", data);
	Texti(x, 240, string, textFont, 4);	
}


/**************************** ELINTULOSTUS *******************************/

VOID ElinTulostus(texti)
UBYTE *texti;
{
SHORT fontwidth;

	SetFont(RP, textFont);
	fontwidth = TextLength(RP, texti, strlen(texti));
	Texti(325-(fontwidth/2), 246, texti, textFont, 2);
}


/**************************** KESKITULOSTUS *******************************/

VOID KeskiTulostus(window, y, fontti, texti, vari)
struct Window *window;
SHORT  y;
struct TextFont *fontti;
UBYTE  *texti;
SHORT  vari;
{
SHORT  fontwidth;

	SetFont(window->RPort, fontti);						/* fontti */
	fontwidth = TextLength(window->RPort, texti, strlen(texti));	
	SetAPen (window->RPort, vari);						/* textin väri */
	Move    (window->RPort, 320-(fontwidth/2), y);		/* mihin */
	Text    (window->RPort, texti, strlen(texti));		/* teksti */
}


/**************************** BIORYTMI *******************************/

VOID Biorytmi()
{
SHORT p1, k1, v1;
SHORT p2, k2, v2;
SHORT x, y, k3, k4, x2, x3, x4, p3, l, x1;
LONG  l1, l2, u;
FLOAT y1;
SHORT pl[13]= { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

p1 = pa[0]*10+pa[1];
k1 = pa[2]*10+pa[3];
v1 = pa[4]*10+pa[5];
p2 = pa[6]*10+pa[7];
k2 = pa[8]*10+pa[9];
v2 = pa[10]*10+pa[11];

if (!(k1>12 || k1<1 || k2>12 || k2<1 || p1>pl[k1] || p2>pl[k2] || p1<1 || p2<1 ))
	{
	l1=v1*365+v1/4;
	l2=v2*365+v2/4;
	if ( (floor(v1/4.0)==v1/4) && (k1<3) )	l1--;
	if ( (floor(v2/4.0)==v2/4) && (k2<3) )	l2--;
	if (k1>1)
		for (x=1; x<(k1); x++)
			l1=l1+pl[x];
	if (k2>1)
		for (x=1; x<(k2); x++)
			l2=l2+pl[x];
	l1=l1+p1;
	l2=l2+p2;

	u=l2-l1;

	if (u<0L)
		{
#ifdef FEA_ENGLISH_LANGUAGE
		ElinTulostus(" MINUS!");
#else
		ElinTulostus(" MIINUS!");
#endif
		}
	else
		{
		sprintf(string, "%ld", u);
		ElinTulostus(string);
		k3=k2-1;
		if (k3==0)		k3=12;
		k4=k2+1;
		if (k4==13)		k4=1;
		pl[2]=pl[2]+(v2/4==v2/4.0);
		if (p2<21)
			{
			x=(21-p2)*16+2;
			if (p2<12)
				{
#ifdef FEA_ENGLISH_LANGUAGE
				sprintf(string,"%s", kk[k3]);
#else
				sprintf(string,"%skuu", kk[k3]);
#endif
				Texti(16, 74, string, textFont2, 4);	
				}
#ifdef FEA_ENGLISH_LANGUAGE
			sprintf(string,"%s", kk[k2]);
#else
			sprintf(string,"%skuu", kk[k2]);
#endif
			Texti(x+6, 74, string, textFont2, 4);	
			Box(x-2, 70, 1, 10, 1); 
			}
		else
			{
#ifdef FEA_ENGLISH_LANGUAGE
			sprintf(string,"%s", kk[k2]);
#else
			sprintf(string,"%skuu", kk[k2]);
#endif
			Texti(16, 74, string, textFont2, 4);	
			p3=pl[k2]-p2;
			x=337+p3*16;
#ifdef FEA_ENGLISH_LANGUAGE
			sprintf(string,"%s", kk[k4]);
#else
			sprintf(string,"%skuu", kk[k4]);
#endif
			Texti(x+6, 74, string, textFont2, 4);	
			Box(x-1, 70, 1, 10, 1); 
			}

		for (l=1; l<4; l++)
			{
			SetAPen(RP, l+4);
			x3=l*5+18;
			x4=u-20;
			x2=(x4-(x4/x3)*x3)*8;
			y1=6.28/(x3*8.0);

			for (x=16; x<621; x++)
				{
				x1=x2+x/2;
				y=132-(SHORT)(sin(x1*y1)*50);
				RectFill(RP, x, y, x+4, y+2);
				}
			}
		SetAPen(window1->RPort, 1);     
		SetDrPt(window1->RPort, 0xCCCC);
		Move(window1->RPort, 320, 77);   
		Draw(window1->RPort, 320, 185);   
		Move(window1->RPort, 321, 77);   
		Draw(window1->RPort, 321, 185);   
		SetDrPt(window1->RPort, 0xFFFF);
		}
	}
	else
#ifdef FEA_ENGLISH_LANGUAGE
		ElinTulostus(" ERROR!");
#else
		ElinTulostus(" VIRHE!");
#endif

}


/**************************** ALUSTADIGITIT *******************************/

VOID AlustaDigitit()
{
UBYTE d[8];
SHORT x;

pa[0]  = p[0];
pa[1]  = p[1];
pa[2]  = p[2];
pa[3]  = p[3];
pa[4]  = p[4];
pa[5]  = p[5];

	getclk(d);					/* luetaan kellonaika */
	d[1] += 80;					/* 80 vuotta lisää    */

pa[6]  = d[3]/10;				/* kymmenet päivät    */
pa[7]  = d[3]-10*pa[6];			/* päivät             */
pa[8]  = d[2]/10;				/* kymmenet kuukaudet */
pa[9]  = d[2]-10*pa[8];			/* kuukaudet          */
pa[10] = d[1]/10;				/* kymmenet vuodet    */
pa[11] = d[1]-10*pa[10];		/* vuodet             */

	for (x=0; x<12; x++)
		UusiDigit(numerox[x], pa[x]);		
}


/**************************** ALUSTARISTIKKO *******************************/

VOID AlustaRistikko()
{
SHORT x;

	SetAPen(RP, 0);
	WaitTOF();	
	RectFill(RP, 0, 63, 639, 76);		/* kuukausien nimien putsaus */
	RectFill(RP, 0, 82, 639, 184);		/* käyrien puhdistus */
	RectFill(RP, 262, 232, 390, 249);	/* elinpäivien puhdistus */

	SetAPen(RP, 3);
	for(x=16; x<630; x += 16)			/* ristikkoviivat */
		{
		Move(RP, x+1,  77);
		Draw(RP, x+1,  80);
		Move(RP,   x,  77);
		Draw(RP,   x, 184);
		WaitTOF();
		}
}


/****************************** Alusta ********************************/

VOID Alusta()
{
SHORT x, y;

	strcpy(string, "Amiga-Biorytmi (c) Janne Kantola 92-95");
	Texti(70, 13, string, textFont, 3);

#ifdef FEA_ENGLISH_LANGUAGE
	Texti(36, 232, "DAY OF", textFont2, 3);
	Texti(39, 246, "BIRTH", textFont2, 3);

	Texti(283, 231, "DAYS SPENT", textFont2, 3);

	Texti(558, 232, "DEST.", textFont2, 3);
	Texti(558, 246, "DAY", textFont2, 3);
#else
	Texti(25, 232, "SYNTYMÄ-", textFont2, 3);
	Texti(35, 246, "PÄIVÄ", textFont2, 3);

	Texti(287, 231, "ELINPÄIVIÄ", textFont2, 3);

	Texti(558, 232, "KOHDE-", textFont2, 3);
	Texti(558, 246, "PÄIVÄ", textFont2, 3);
#endif

	Texti(148, 240, ".", textFont, 4);
	Texti(199, 240, ".", textFont, 4);
	Texti(433, 240, ".", textFont, 4);
	Texti(484, 240, ".", textFont, 4);

	for (x=0; x<3; x++)
		for (y=0; y<2; y++)
			{
			DrawBox(110+x*51+y*19, 219, 12, 4, 3, 4);
			DrawBox(110+x*51+y*19, 243, 12, 4, 3, 4);
			numerox[x*2+y] = 110+x*51+y*19;
			}

	for (x=0; x<3; x++)
		for (y=0; y<2; y++)
			{
			DrawBox(395+x*51+y*19, 219, 12, 4, 3, 4);
			DrawBox(395+x*51+y*19, 243, 12, 4, 3, 4);
			numerox[6+x*2+y] = 395+x*51+y*19;
			}

	DrawBox(  0,  1, 23, 8, 3, 4);
	DrawBox( 27,  1, 23, 8, 3, 4);
	DrawBox( XX, YY, 23, 8, 3, 4);
	DrawBox(XXX, YY, 23, 8, 3, 4);

	SetAPen(RP, 3);
	Move(RP, 16, 81);
	Draw(RP, 625, 81);
	Move(RP, 16, 185);
	Draw(RP, 624, 185);

	Box(40, 192, 50, 3, 5);
#ifdef FEA_ENGLISH_LANGUAGE
	Texti(100, 199, "PHYSICAL", textFont2, 5);
#else
	Texti(100, 199, "KEHO", textFont2, 5);
#endif

#ifdef FEA_ENGLISH_LANGUAGE
	Box(250, 192, 50, 3, 6);
	Texti(310, 199, "EMOTION", textFont2, 6);
#else
	Box(270, 192, 50, 3, 6);
	Texti(330, 199, "TUNNE", textFont2, 6);
#endif

#ifdef FEA_ENGLISH_LANGUAGE
	Box(460, 192, 50, 3, 7);
	Texti(520, 199, "INTELLIGENCE", textFont2, 7);
#else
	Box(500, 192, 50, 3, 7);
	Texti(560, 199, "JÄRKI", textFont2, 7);
#endif

	ShowTitle(screen1, FALSE);
	ScreenToFront(screen1);

	AlustaRistikko(); 
	AlustaDigitit();

}


/******************************** ABOUT *********************************/

/* THIS FUNCTION ASKS ARE YOU SURE TO DO THAT */

VOID About()
{
struct IntuiMessage *msg;
struct Window *aboutwindow;
struct Gadget *g;
ULONG  class;
SHORT  flagi=TRUE;


	aboutWindow.Screen = screen1;

	/* OPENS WINDOW, IF ERROR THEN FLASHES DISPLAY */

	if (!(aboutwindow = (struct Window *)OpenWindow(&aboutWindow)))
		DisplayBeep(screen1);
	else
		{

		/* CHANGES GLIST TO THE ARE-YOU-SURE-WINDOW */

		RemoveGList(window1, &Gadget6, -1); 
		AddGList(aboutwindow, &aboutGadget, 0, -1, NULL);

		SetAPen (aboutwindow->RPort, 3);			/* Exit - loota */
		Move    (aboutwindow->RPort, 6+23, 3);
		Draw    (aboutwindow->RPort, 6, 3);
		Draw    (aboutwindow->RPort, 6, 3+8);
		Draw    (aboutwindow->RPort, 6+1, 3+8);
		Draw    (aboutwindow->RPort, 6+1, 3);
    
		SetAPen (aboutwindow->RPort, 4);			
		Move    (aboutwindow->RPort, 6+1, 3+8);
		Draw    (aboutwindow->RPort, 6+23, 3+8);
		Draw    (aboutwindow->RPort, 6+23, 3);
		Draw    (aboutwindow->RPort, 6+23-1, 3+1);
		Draw    (aboutwindow->RPort, 6+23-1, 3+8);

		KeskiTulostus(aboutwindow, 19, textFont, TITLE, 6);

#ifdef FEA_ENGLISH_LANGUAGE
		KeskiTulostus(aboutwindow, 87, textFont2,
		 "Janne  \"           \"  Kantola, Hiidentie 4 A 2, FIN - 90550 OULU 55, FINLAND", 6);
#else
		KeskiTulostus(aboutwindow, 87, textFont2,
		 "Janne  \"           \"  Kantola, Hiidentie 4 A 2, 90550  OULU 55", 6);
#endif

		SetFont(aboutwindow->RPort, textFont);		/* fontti */
		SetAPen(aboutwindow->RPort, 6);				/* textin väri */
#ifdef FEA_ENGLISH_LANGUAGE
		Move   (aboutwindow->RPort, 142, 90);		/* mihin */
#else
		Move   (aboutwindow->RPort, 192, 90);		/* mihin */
#endif
		Text   (aboutwindow->RPort, "³", 1);		/* teksti 'JanTa' */

#ifdef FEA_ENGLISH_LANGUAGE
		KeskiTulostus(aboutwindow, 34, textFont2,
		 "This program is a GiftWare.  That means you have to send a (little) gift to the author", 5);
		KeskiTulostus(aboutwindow, 47, textFont2,
		 "if you use this program frequently.  Instructions how to use this program can be", 5);
		KeskiTulostus(aboutwindow, 60, textFont2,
		 "found in 'Biorytmi.doc'.  I hope that you copy that document file with the program.", 5);
		KeskiTulostus(aboutwindow, 73, textFont2,
		 "You can sent gifts (or any kind of letters) to the author, address below:", 5);
		KeskiTulostus(aboutwindow, 100, textFont2,
		 "My email addresses are:  janne.kantola@nmp.nokia.com  and  janta@tolsun.oulu.fi", 3);
#else
		KeskiTulostus(aboutwindow, 34, textFont2,
		 "Tämä ohjelma on ns. GiftWare -ohjelma.  Se tarkoittaa sitä, että ohjelman jatkuva käyttä-", 5);
		KeskiTulostus(aboutwindow, 47, textFont2,
		 "minen edellyttää (pienen) lahjan lähettämistä tekijälle.  Ohjelman käyttöohjeet löytyvät", 5);
		KeskiTulostus(aboutwindow, 60, textFont2,
		 "tiedostosta 'Biorytmi_FIN.doc'.  Toivon, että kopioit dokumentin ohjelman yhteydessä.", 5);
		KeskiTulostus(aboutwindow, 73, textFont2,
		 "Lähetä lahja tai voit kirjoittaa ihan muuten vaan tekijälle, osoitteeseen:", 5);
		KeskiTulostus(aboutwindow, 100, textFont2,
		 "Email-osoitteeni ovat:  janne.kantola@nmp.nokia.com  ja  janta@tolsun.oulu.fi", 3);
#endif

		/* WAITS UNTIL "OK!" */

		while(flagi)
			{
			Wait ( 1L << aboutwindow->UserPort->mp_SigBit);
			while (msg=(struct IntuiMessage *)GetMsg(aboutwindow->UserPort))
				{
				g  = (struct Gadget *)msg->IAddress;
				class=msg->Class;
				switch(class)
					{
					case GADGETUP:
						flagi=FALSE;
						break;
					default:
						 break;
					}
				ReplyMsg((struct Message *)msg);
				}
			}
		CloseWindow(aboutwindow);		
		RemoveGList(window1, &aboutGadget, -1); 
		AddGList(window1, &Gadget6, 0, -1, NULL);
		}
}

	
/**************************** TarkistaARG *******************************/

VOID TarkistaARG(argv)
UBYTE *argv;
{
int error=0;
int x;

if ( strcmp(argv, "") )
	{
	if ( (argv[1]=='.') && (argv[3]=='.') && strlen(argv)==6 )	/* x.x.xx */
		{
		p[0] = 0;
		p[1] = argv[0]-48;
		p[2] = 0;
		p[3] = argv[2]-48;
		p[4] = argv[4]-48;
		p[5] = argv[5]-48;
		}
	if ( (argv[2]=='.') && (argv[4]=='.') && strlen(argv)==7 )	/* xx.x.xx */
		{
		p[0] = argv[0]-48;
		p[1] = argv[1]-48;
		p[2] = 0;
		p[3] = argv[3]-48;
		p[4] = argv[5]-48;
		p[5] = argv[6]-48;
		}
	if ( (argv[1]=='.') && (argv[4]=='.') && strlen(argv)==7 )	/* x.xx.xx */
		{
		p[0] = 0;
		p[1] = argv[0]-48;
		p[2] = argv[2]-48;
		p[3] = argv[3]-48;
		p[4] = argv[5]-48;
		p[5] = argv[6]-48;
		}
	if ( (argv[2]=='.') && (argv[5]=='.') && strlen(argv)==8 )	/* xx.xx.xx */
		{
		p[0] = argv[0]-48;
		p[1] = argv[1]-48;
		p[2] = argv[3]-48;
		p[3] = argv[4]-48;
		p[4] = argv[6]-48;
		p[5] = argv[7]-48;
		}

	}

	for (x=0; x<6;x++)
		if ( p[x]<0 || p[x]>9 )	error = 1;

	if (error == 1)
		{
		if ( strcmp(argv, "") )
			{
			printf("\n%s\n", TITLE);
#ifdef FEA_ENGLISH_LANGUAGE
			printf("Usage: [run] Biorytmi [dd.mm.yy]\n\n");
#else
			printf("Käyttö: [run] Biorytmi [pp.kk.vv]\n\n");
#endif
			CleanExit(RETURN_ERROR);
			}
		p[0]=2;
		p[1]=2;
		p[2]=0;
		p[3]=3;
		p[4]=9;
		p[5]=2;
 
		}
}


/****************************** OpenAll ********************************/

VOID OpenAll()
{
	IntuitionBase = (struct IntuitionBase *)
		OpenLibrary( "intuition.library", 33L);
	if (IntuitionBase == NULL)
		CleanExit(0);

	DiskfontBase = OpenLibrary("diskfont.library", 33L);
	if (DiskfontBase==NULL)
		CleanExit(1);

	GfxBase = (struct GfxBase *)
		OpenLibrary("graphics.library", 33L);
	if (GfxBase == NULL)
		CleanExit(2);

	screen1 = (struct Screen *)OpenScreen(&screen);
	if (screen1 == NULL)
		CleanExit(3);

	window.Screen = screen1;

	window1 = (struct Window *)OpenWindow(&window);
	if (window1 == NULL)
		CleanExit(4);

	RP = window1->RPort;

	LoadRGB4(&screen1->ViewPort, colors, 8);

	oldTextFont = RP->Font;

	textAttr.ta_Name  = "Biorytmi1.font";
	textAttr.ta_YSize = 16;
	textAttr.ta_Style = FS_NORMAL;
	textAttr.ta_Flags = FPF_DESIGNED | FPF_DISKFONT;

	textFont = (struct TextFont *)OpenDiskFont(&textAttr);
	if (!textFont)
		CleanExit(5);

	textAttr.ta_Name  = "Biorytmi2.font";
	textAttr.ta_YSize = 13;
	textAttr.ta_Style = FS_NORMAL;
	textAttr.ta_Flags = FPF_DESIGNED | FPF_DISKFONT;

	textFont2 = (struct TextFont *)OpenDiskFont(&textAttr);
	if (!textFont2)
		CleanExit(6);

	AddGList(window1, &Gadget6, 0, -1, NULL);
	RefreshGList(&Gadget6, window1, NULL, 1);
	ActivateGadget(&Gadget6, window1, NULL);


}


/**************************** CleanExit ******************************/

VOID CleanExit (returnValue)
int returnValue;
{
	if (window1) CloseWindow(window1);
	if (screen1) CloseScreen(screen1);
	if (DiskfontBase)  CloseLibrary( ( struct Library *) DiskfontBase);
	if (textFont)	CloseFont(textFont);
	if (textFont2)	CloseFont(textFont2);
	if (IntuitionBase) CloseLibrary( ( struct Library *) IntuitionBase);
	if (returnValue != RETURN_OK && returnValue != RETURN_ERROR)
#ifdef FEA_ENGLISH_LANGUAGE
		printf("Amiga-Biorytmi error:\n%s\n", error[returnValue]);
#else
		printf("Amiga-Biorytmi -virhe:\n%s\n", error[returnValue]);
#endif
	exit (returnValue);
}

