/*
	COSTATE2.C

   Sample program showing usage of the timing mechanism provided by 
   Costatement programming. This example also shows how one costatement
	can be used to trigger another one.

   If using Dynamic C for DOS, make sure CPLC.LIB is
   commented out with an '*' and uncomment out VDRIVER.LIB
   in LIB.DIR.
*/

#use vdriver.lib

extern CoData say_goodbye; 
main()
{
    int i, j, k;
    char on_flag;
    VdInit();    	            	// need this to drive the timer mechanism
                                	// functions DelaySec and DelayMs
    i = 0;
    while (1)                   	// do an infinite loop
    {
        runwatch();             	// monitor with the watch window

        costate say_hello always_on
        {
            printf("Hello there %d\n",i++);
           waitfor(DelaySec(5L));          // print every 5 secs
            if(i == 2)
                CoBegin(&say_goodbye);     // start other function block
            if(i == 3)
                i = 0;   
        }

        costate say_goodbye
        {
            k = 0;                  		// say 8 goodbyes
            while(k<8)
            {
                waitfor(DelayMs(500L));
                printf("Goodbye %d\n", k++);
            }
        }
    }
}
