/**************************************************************************** Set time of day command. Supports the QT Computer Systems Clock - Calendar board. ***************************************************************************** Syntax: TOD (DAY=ddd) (DATE=mmm d,yy) (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} yy= 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. TOD ? Displays the help prompt. ***************************************************************************** Revision History: 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. 1.3 12-7-90 grh Revise code to call the monitor functions. Use printf() instead of local functions for ease of programming. 2.0 11-20-91 grh Modify for monitor V2.00 calls. */ #define version "2.0" /****************************************************************************/ #include "stdio.h" #include ctype.h #include io.h #include farcall.h #include m5zf200.h /****************************************************************** Time array is used to communicate with the primitives *******************************************************************/ struct { BYTE seconds, /* 0..59 */ minutes, /* 0..59 */ hours; /* 0..23 */ BYTE week; /* 0..6 */ BYTE day, /* 0..31 */ month, /* 1..12 */ year; /* 0..99 */ } time_array; #define ndays 7 char *day_table[ndays] = { "SUNDAY","MONDAY","TUESDAY","WEDNESDAY", "THURSDAY","FRIDAY","SATURDAY"}; #define nmonths 12 char *month_table[nmonths] = {"JANUARY","FEBRUARY","MARCH","APRIL","MAY", "JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER", "NOVEMBER","DECEMBER"}; /* Other variables */ BYTE this_bnk; int error; WORD get_offset(), temp, cnt; char *get_txt(), *tptr; struct regs cpui, /* CPU input register array */ cpuo; /* CPU output register array */ /**************************************************************************** MAIN Program ****************************************************************************/ main(argc, argv) int argc; char *argv[];{ /* Get bank data */ cpui.AF = MF_GBNK << 8; farcall( (WORD) MR_FUN, 0, &cpui, &cpuo); this_bnk = cpuo.AF >> 8; /* Get current time */ get_clock(); /* If args given then process changes */ if (argc > 1){ error = 0; for (cnt = 1, tptr = argv[cnt]; cnt < argc; cnt++) { /******* Process day input */ if (strncmp("DAY=", tptr, 4) == 0) { temp = get_offset( &tptr[4], day_table, ndays); if (temp > 6) { error = -1; /*** set global error flag ***/ printf("Err: %s", tptr); break; } else time_array.week = temp; } /******* Process date input */ else if (strncmp("DATE=", tptr, 5) == 0) { temp = get_offset( &tptr[5], month_table, nmonths); if (temp > 11) { error = -1; /*** set global error flag ***/ printf("Err: %s", tptr); break; } time_array.month = (temp + 1); if (cnt >= argc) { error = -1; /*** set global error flag ***/ printf("Err: %s", tptr); break; } temp = atoi( (tptr = argv[++cnt]) ); /*** get date ***/ if ( (temp < 1) || (temp > 31) ) { error = -1; /*** set global error flag ***/ printf("Err: %s", tptr); break; } time_array.day = temp; /********** find any ',' */ while ( (*tptr != 0) && (*tptr != ',') ) tptr++; if ( (*tptr == 0) || (*(tptr + 1) == 0) ) tptr = argv[++cnt]; else tptr++; time_array.year = atoi(tptr); } /******* Process time input */ else if ( strncmp("TIME=", tptr, 5) == 0){ tptr = &tptr[5]; if ( *tptr == 0) { error = -1; /*** set global error flag ***/ printf("Err: %s", tptr); break; } time_array.hours = atoi(tptr); time_array.minutes = time_array.seconds = 0; /** default **/ while ( (*tptr != 0) && (*tptr != ':') ) tptr++; if ( *tptr == ':') ++tptr; if ( *tptr != 0) { time_array.minutes = atoi(tptr); while ( (*tptr != 0) && (*tptr != ':') ) tptr++; if ( *tptr == ':') ++tptr; if ( *tptr != 0) time_array.seconds = atoi(tptr); } } /* If arg error then display format */ else { error = -1; /*** set global error flag ***/ puts("\ >> (24 Hour)"); break; } } /**** If no errors so far then set the time */ if (error == FALSE){ puts("\nPress any key to set time.\n"); bdos(1,0); /*** wait for char ***/ set_clock(); } } /* In all cases, display the time */ printf("\n%s %s %2d,19%2d %2d:%2d:%2d\n\n", get_txt(time_array.week & 7, day_table, ndays), get_txt(time_array.month - 1, month_table, nmonths), time_array.day, time_array.year, time_array.hours, time_array.minutes, time_array.seconds ); exit(0); } /**************************************************************************** compare string to array function exit- < 300= array index 300= string not found *****************************************************************************/ WORD get_offset( sptr, cptr, size) char *sptr, *cptr[]; int size; { static WORD 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]; } /**************************************************************************** Get clock data *****************************************************************************/ get_clock() { cpui.AF = MF_GTIM << 8; farcall( (WORD) MR_FUN, this_bnk, &cpui, &cpuo); time_array.seconds = cpuo.AF >> 8; time_array.minutes = cpuo.BC >> 8; time_array.hours = cpuo.BC & 0xff; cpui.AF = MF_GCAL << 8; farcall( (WORD) MR_FUN, this_bnk, &cpui, &cpuo); time_array.day = cpuo.AF >> 8; time_array.month = cpuo.BC >> 8; time_array.year = cpuo.BC & 0xff; time_array.week = cpuo.HL & 0xff; } /**************************************************************************** Set clock data *****************************************************************************/ set_clock() { cpui.AF = MF_STIM << 8; cpui.BC = time_array.seconds << 8; cpui.DE = (time_array.minutes << 8) + (time_array.hours & 0xff); farcall( (WORD) MR_FUN, this_bnk, &cpui, &cpuo); cpui.AF = MF_SCAL << 8; cpui.BC = time_array.day << 8; cpui.DE = (time_array.month << 8) + (time_array.year & 0xff); cpui.HL = time_array.week & 0xff; farcall( (WORD) MR_FUN, this_bnk, &cpui, &cpuo); }