/** date.c - print any portion of the "Time" message in any      **/
/**          specified format (see PRM for key)                  **/
/** Example: date "%WE, %MO the %DY%ST" would print              **/
/**              "Tuesday, December the 25th"                    **/
/** Made in England by D McSweeney, programmer to the gentry     **/
#include <stdio.h>
#include <stdlib.h>
#include <kernel.h>
#include <swis.h>
int main(int argc, char *argv[])
{
char pblock[5];
char outstring[50];
int n;
_kernel_swi_regs r;

/** First a call to OS_Word 14, 3 - read clock as 5-byte value  **/
/** r0 = 14, r1 = address of parameter block (to hold result)   **/
/** on entry, 1st byte of r1 is set to 3 (the "reason code")    **/ 

r.r[0]=14;
r.r[1]=(int)pblock;
pblock[0] = 3;
_kernel_swi(OS_Word, &r, &r);

/** on exit, pblock holds the 5-byte time - compare with a BASIC **/
/** command "SYS 07, 14, pblock TO , pblock"                     **/
/** first we show the contents of pblock....                     **/

for(n=0; n < 5; n++)
	printf("%02X ", pblock[n]);
printf("\n");

/** Now, we call SWI &C1 to convert. argv[1] is the char array   **/
/** holding the format string. For this call the 5-byte block is **/
/** addressed via r0, the output string via r1, the format       **/
/** string via r3. The length of output array is in r2.          **/

r.r[0]=r.r[1];
r.r[1]=(int)outstring;
r.r[2]=50;
r.r[3]=(int)argv[1];
_kernel_swi(OS_ConvertDateAndTime, &r, &r);
printf("%s\n", outstring);
exit(0);
}

