/**************************************************************************** Set time of day command. Supports the QT Computer Systems Clock - Calendar board. ***************************************************************************** Syntax: D>TOD (DAY=ddd) (DATE=mmm d,19xx) (TIME=hh:mm:ss) where ddd= day {SUNday,MONday,TUEsday,WEDnesday,THUrsday, FRIday,SATurday} mmm= month {JANuary,FEBruary,MARch,APRil,MAY,JUNe,JULy, AUGust,SEPtember,OCTober,NOVember,DECember} d= day of month {1,2,..31} xx= year {00,01,..99} hh= hours {00,01,..23} mm= minutes {00,01,..59} ss= seconds {00,01,..59} (optional, allways set to 00) If DAY, DATE and TIME fields are ommitted then only the current time is displayed, else the clock information specified by the field is changed. All fields are optional and any unspecified fields are not altered. Spaces and delimiters are only allowed as shown in the example. ***************************************************************************** Revisions: 1.0 - 27 may 83 grh Release 1.1 - 10 jul 84 grh Fix bug in time array data processing causing 24 hour bit to be cleared. Fix bug in get_txt() which returned garbage when a negative integer was passed as the offset. 1.2 - 28 Oct 84 grh Fix bug that did a modulo 10 on the month value. This caused an error when october (0x10 & 15 = 0 [- 1 = -1]) occurred. */ #define version "1.2" /****************************************************************************/ /* #include "basedef.h" */ #define FALSE 0 /****************************************************************** Time array is used to communicate with the primitives *******************************************************************/ #define _24_hour_format 8 /* time format declarations */ #define _12_hour_format 0 #define time_format _24_hour_format struct { unsigned seconds, /* 0..59 */ minutes, /* 0..59 */ hours; /* 0..23 */ char week; /* 0..6 */ unsigned day, /* 0..31 */ month, /* 1..12 */ year; /* 0..99 */ } time_array; char *day_table[7] = {"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY", "FRIDAY","SATURDAY"}; #define ndays 7 char *month_table[12] = {"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE", "JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER", "DECEMBER"}; #define nmonths 12 int error; unsigned temp, cnt; char *tptr; main(argc, argv) int argc; char *argv[];{ bdos(0x93, &time_array); /*** fill array with current time ***/ if (argc > 1){ error = 0; for (cnt = 1; cnt < argc; cnt++){ if (strncmp("DAY=", argv[cnt], 4) == 0){ temp = get_offset(argv[cnt] + 4, day_table, ndays); if (temp > 6){ put_err(argv[cnt]); break;} else time_array.week = temp; } else if (strncmp("DATE=", argv[cnt], 5) == 0){ temp = get_offset(argv[cnt] + 5, month_table, nmonths); if (temp > 11){ put_err(argv[cnt]); break;} time_array.month = bin2bcd(temp + 1); if (cnt >= argc){ put_err(argv[cnt]); break;} temp = atoi(argv[++cnt]); /*** get date ***/ if ((temp < 1) || (temp > 31)){ put_err(argv[cnt]); break;} time_array.day = bin2bcd(temp); tptr = argv[cnt]; /* find any ',' */ while ((*tptr != 0) && (*tptr != ',')) tptr++; if ((*tptr == 0) || (*(tptr + 1) == 0)) tptr = argv[++cnt]; else tptr++; time_array.year = bin2bcd(atoi(tptr) % 100); } else if (strncmp("TIME=", argv[cnt], 5) == 0){ tptr = argv[cnt] + 5; if (*tptr == 0){ put_err(tptr); break; } time_array.hours = bin2bcd(atoi(tptr) % 24) | time_format << 8; time_array.minutes = time_array.seconds = 0; /** default **/ while ((*tptr != 0) && (*tptr != ':')) tptr++; if (*tptr == ':') ++tptr; if (*tptr != 0) { time_array.minutes = bin2bcd(atoi(tptr) % 60); while ((*tptr != 0) && (*tptr != ':')) tptr++; if (*tptr == ':') ++tptr; if (*tptr != 0) time_array.seconds = bin2bcd(atoi(tptr) % 60); } } else { put_err( " >> (24 Hour)"); break; } } if (error == FALSE){ puts("\nPress any key to set time.\n"); bdos(1,0); /*** wait for char ***/ bdos(0x91, &time_array); } } puts("\n"); puts(get_txt(time_array.week & 7, day_table, ndays)); temp = time_array.month; temp = (temp & 0xf) + (((temp & 0x100) >> 8) * 10); puts(" "); puts(get_txt(temp - 1, month_table, nmonths)); puts(" "); putd(time_array.day & 0x30f); puts(", 19"); putd(time_array.year); puts(" "); putd(time_array.hours & 0x30f); puts(":"); putd(time_array.minutes); puts(":"); putd(time_array.seconds); puts("\n\n"); exit(0); } /*********************************************** compare string to array function exit- < 300= array index 300= string not found ************************************************/ unsigned get_offset(sptr, cptr, size) char *sptr, *cptr[]; int size;{ static cnt; for (cnt = 0; cnt < size; cnt++){ if (strncmp(sptr, cptr[cnt], 3) == 0) return cnt; } return 300; } /******************************************** get text ptr from array function exit- &text "Error" if out of bounds *********************************************/ char *get_txt(offs, txtptr, size) unsigned offs, size; char *txtptr[];{ return (offs >= size) ? "Error" : txtptr[offs]; } /****************************** put error function *******************************/ put_err(txtptr) char *txtptr;{ error = -1; /*** set global error flag ***/ puts("\nCommand Error: "); puts(txtptr); } /*********************************************************** put string function overrides library function. ************************************************************/ puts(ptr) char *ptr;{ while (*ptr != 0){ if (*ptr == '\n') putchar('\r'); putchar(*ptr++); } } /****************************** put char function *******************************/ putchar(c) char c;{ bdos(2, c); } /********************************* put number function **********************************/ putd(numb) unsigned numb;{ putchar((numb >> 8) + '0'); putchar((numb & 0xf) + '0'); } /************************************* convert binary to bcd function ***************************************/ unsigned bin2bcd(val) unsigned val; { return (val % 10) | ((val / 10) << 8); }