home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
- NIST ACTS Access Routine -- Dials NIST & sets DOS date/time accordingly.
- Copyright (c) Franklin Antonio, 1988, All Rights Reserved.
-
- This program (source and object) may be freely distributed and used for non-
- commercial purposes only. If you redistribute this package, you must
- distribute all the files (source, object, doc, ini), in their original,
- unmodified, form. You may, additionally, distribute modified versions, with
- the unmodified versions, but they must be clearly identified as modified,
- with the original copyright statements intact, and the name and address of
- the modifier must be clearly shown.
-
- Compile with Microsoft C 5.1 or C 6.0a ... cl /Ox /DMAIN nbscom.c
-
- Edit History...
- 12/19/88 -fa- change abs to dabs in printf of time_change
- added .ini file
- put in direct i/o (to ignore modem control signals)
- started hardware RTC stuff
- 12/20/88 -fa- replace sscanf() with atoi() in parse_a_time (AT:3.3ms-->0.3ms)
- replace putc( ,stdio) with putc_screen() (AT:1.5ms-->0.5ms)
- check ftime() {1.5ms} and kbhit() {0.5ms} only every 10th char
- now polled i/o won't drop chars on even the slowest machine
- 01/07/89 -fa- Timeout was too short for some people using pulse dialing or
- using long access codes. Changed default from 30 to 90 sec,
- and made it a param settable from ini file.
- 01/12/89 -fa- made maxtime=0 imply no timeout. made main loop much faster
- so some machines SLOWER than 4.77MHz PCs can work! if laptops
- have garbled character problems, should try maxtime=0
- 04/04/89 -fa- fix the daylight savings time bug! darn. Now vers 1.4.
- 06/05/89 -pw- fix up trivial compiler warnings.
- 06/26/89 -fa- add COM3,COM4 addresses. changed from \r\n to \r at end of
- modem commands. A few modems couldn't eat the \n so quickly
- after the \r.
- 07/30/89 -fa- chg fopen() to it_fopen() when part of InstantTrack.
- 09/29/89 -fa- add simple interrupt driven com i/o. this makes us compat.
- with TSRs that use significant time, very very slow machines,
- multitasking things, etc.
- 10/29/89 -fa- Damn. When i fixed the daylight savings time bug in april,
- i got the 2am conditional backwards for the two transition
- days! Worked right except during these 2 days. Now ver 1.6.
- 12/02/89 -fa- Change onscreen text from "NBS" to "NIST", because the
- National Bureau of Standards changed it's name!
- 01/07/90 -fa- allow computer-to-modem serial link to run at any standard
- speed, even tho we can only call NIST at 300 or 1200. Some
- brands of modem demand to talk to computer at a fixed speed.
- Has caused complaints from owners of Everex modems.
- Changed nbscom.ini to it.ini when part of IT.
- Now is version 1.7
- 02/08/90 -fa- Put delay after hangup command, and prior to dropping DTR &
- shutting down com port! May make a difference on some modems.
- 01/05/91 -fa- set baud rate by writing to port directly rather than using
- the BIOS. Works better because some BIOS's don't know how to
- set COM3 & COM4. Allow user to specify port addr & irq.
- 01/12/91 -fa- oops. wrote divisor to wrong port!
- ----------------------------------------------------------------------------*/
- #include <stdio.h>
- #include <bios.h> /*needed by _bios_serialcom() */
- #include <dos.h> /*needed by _dos_setxxxx() */
- #include <conio.h> /*needed by kbhit() */
- #include <sys\timeb.h> /*needed by ftime() */
- #include <time.h> /*needed by tzset() */
- #include <ctype.h> /*needed by isspace() */
- #include <graph.h> /*needed by _clearscreen() */
- #include <math.h> /*needed by fabs() */
- #include <stdlib.h> /*needed by atoi() */
-
- /*function prototypes*/
- double floatime(struct timeb);
- double floatimenow(void);
- void delay(double);
- int parse_a_time(char *, int *, int *, int *, int *, int *, int *, int *);
- void Datek2(long,long *,long *,long *);
- long KDAY2(long,long,long);
- void nbs_init_and_acts(void);
- void nbs_init(void);
- void call_nbs_acts(void);
- void dial_the_modem(void);
- int nbgetc_modem(void);
- void putc_screen(int c);
- int read_hw_rtc(int *yr,int *mo,int *da,int *hr,int *mi,int *se);
- void hangup_the_modem(void);
- void control_modem(int c);
- void puts_modem(char *s);
- void putc_modem(int c);
- FILE *it_fopen(char *,char *);
- void set_mcr(int valu,int mask);
- void enable_com_port(void);
- void disable_com_port(void);
- static void _cdecl interrupt far com_interrupt_handler();
-
-
- #define dabs(x) fabs(x) /*double abs*/
- #define xbcd(bcd) ( 10*((bcd)>>4) + ((bcd)&0x0f) ) /*packed bcd to integer*/
- #define bcdx(x) ( ((x)/10)<<4) + (x)%10 ) /*integer to packed bcd*/
-
-
- /*parameters initialized here, but set from NBSCOM.INI file if available*/
- int nbs_port = 0; /*port # for serial comm*/
- unsigned nbs_port_address = 0; /*port i/o address*/
- unsigned nbs_port_irq = 0; /*port irq number*/
- int nbs_speed = 1200; /*baud rate for serial comm*/
- int maxtime = 90; /*max online time (seconds*/
- char dial_sequence[50] = "ATDT1-303-494-4774"; /*dial command buffer*/
- char hangup_sequence[50] = "ATH"; /*hangup command buffer*/
-
-
- /*items specific to standard 8250-based com ports*/
- unsigned port[4] ={0x3f8,0x2f8,0x3e8,0x2e8}; /*standard IBM port addresses*/
- unsigned interrup[4] ={4,3,4,3}; /*standard IBM port interrupts*/
- #define UART_DATA 0 /*data register */
- #define UART_DLL 0 /*divisor latch least-sig*/
- #define UART_INT 1 /*interrupt enable register*/
- #define UART_DLM 1 /*divisor latch most-sig*/
- #define UART_LCR 3 /*line control register*/
- #define UART_MCR 4 /*modem control register*/
- #define UART_LSR 5 /*line status register */
- #define UART_MSR 6 /*modem status register*/
-
- static void (_cdecl interrupt far * old_com_handler)(void); /*old interrupt routine*/
- int com_port_live=0; /*flag that we have interrupts*/
- unsigned com_wp,com_rp; /*fifo write & read ptrs*/
- char com_buf[32]; /*com input fifo*/
-
-
- /*-----------------------------------------------------------------------------
- main (stand alone program)
- ----------------------------------------------------------------------------*/
- #ifdef MAIN
- main() { /*compile main optionally*/
- nbs_init_and_acts();
- }
- #endif
-
- void nbs_init_and_acts(void) {
- nbs_init();
- printf("NBSCOM 1.9a -- Copyright (c) 1990, 1991, Franklin Antonio\n");
- delay(1.0);
- call_nbs_acts();
- }
-
- /*-----------------------------------------------------------------------------
- call_nbs_acts -- Places a call to National Bureau of Standards Advanced
- Computer Time Service, reads date/time, & sets dos time accordingly.
- ----------------------------------------------------------------------------*/
- void call_nbs_acts(void) {
- struct timeb start,now,time_before,time_after;
- struct dosdate_t dosdate;
- struct dostime_t dostime;
- double time_change;
- long lda,lmo,lyr,time;
- int tick,j,j1,j2,yr1,yr2,mo1,mo2,da1,da2,hr1,hr2,mi1,mi2,se1,se2,dst1,dst2;
- int rtc,yr,mo,da,hr,mi,se;
- int c;
- char *p,buf[80];
-
- switch(nbs_speed) { /*choose divisor*/
- case 300: j=384; break;
- case 1200: j=96; break;
- case 2400: j=48; break;
- case 4800: j=24; break;
- case 9600: j=12; break;
- case 19200: j=6; break;
- } /*initialize modem port*/
- outp(nbs_port_address+UART_LCR, 0x80); /*divisor latch access*/
- outp(nbs_port_address+UART_DLM, j>>8); /*divisor latch*/
- outp(nbs_port_address+UART_DLL, j&0xff);/*divisor latch*/
- outp(nbs_port_address+UART_LCR, 0x03); /*8bits, no parity, no latch access*/
-
- _clearscreen(_GCLEARSCREEN); /*clear screen, so no scroll during*/
- /*session. Elims scn scroll time*/
-
- printf("Accessing National Institute of Standards & Technology\n"
- " Automated Computer Time Service...\n\n");
-
- printf("--- Modem dialog follows --- Type any key to abort. ---\n");
-
- enable_com_port(); /*interrupt i/o goes live here*/
- dial_the_modem(); /*initiate phonecall*/
-
-
- /*now sit in a loop for up to maxtime copying characters to screen, and a
- buffer. when lf seen, attempt to parse. two correct parses in a row which
- differ by exactly 1 second causes successful termination. Timeout or a hit
- from the keyboard causes unsuccessful termination. The most time-consuming
- item in the loop (by far) is the ftime() call. ftime() takes 6ms on a
- 4.77 MHz PC, which is 2/3 of a character time @ 1200 baud. ftime() is a
- good example of a library routine that could have been 20 times faster
- if it had been written carefully. */
-
- fflush(stdin); /*flush kb, so kbhit works*/
- ftime(&start); /*begin timeout*/
- p=buf; /*init ptr to line buffer*/
-
- for(tick=0; 1; tick = (tick>=10) ? 0 : ++tick) { /*serial port poll loop*/
-
- c = nbgetc_modem(); /*get a char from modem*/
- if(c != 0) putc_screen(c); /*echo to screen*/
-
- if(isprint(c) || isspace(c)) { /*elim trash*/
- *p++ = (char) c; /*good char to buffer*/
- if(c == '\n' || p == buf+80-1) { /*eol?*/
- *p=0; p=buf; /*tie off & reset ptr*/
- j = parse_a_time(buf,&yr1,&mo1,&da1,&hr1,&mi1,&se1,&dst1);
- if(j==1) { /*a valid time line?*/
- if(yr1==yr2 && mo1==mo2 && da1==da2 && hr1==hr2 &&
- mi1==mi2 && se1==se2+1 && dst1==dst2) { /*and it's 2nd one?*/
- goto goodtime; /*zounds*/
- }
- else {
- yr2=yr1; mo2=mo1; da2=da1; /*then it's 1st one*/
- hr2=hr1; mi2=mi1; se2=se1; /*remember values*/
- dst2=dst1;
- }
- } /*end if j==1 */
- } /*end if c == */
- } /*end if isprint( */
-
- if(tick == 0 && maxtime != 0) { /*occasionally check*/
- ftime(&now); /*for timeout*/
- if(now.time > start.time + maxtime) break;
- }
- if(tick == 5) { /*occasionally check*/
- if(kbhit()) break; /*for manual abort*/
- }
- } /*end for(tick */
-
-
- if(kbhit()) printf("--- aborted by user ---\n");
- else printf("--- %d seconds elapsed. aborted. ---\n",maxtime);
- time_change = 0.; /*there was no change*/
-
- goto hangup; /*attempt to hang up phone*/
-
-
-
- /* ------- Here when we have read a good time. Tell DOS. ---------*/
-
- /*we have to adjust the UTC time we've just received by our local timezone
- so we can set DOS date/time local. Adjustment may be negative, and the lib.
- routine mktime() can't handle negative arguments, so we convert using local
- routines to a single time variable, adjust, then convert back. messy.*/
-
- goodtime: /*got a valid time*/
- tzset(); /*make timezone valid*/
- time = 24L*KDAY2((long)da1,(long)mo1,(long)1900+yr1) + hr1;
- time -= timezone/(60L*60L); /*adjust for timezone*/
- Datek2(time/24L,&lda,&lmo,&lyr); /*get new d/m/y*/
- hr1 = (int) (time%24L); /*fractional day*/
-
- /*Now we have local *STANDARD* time. We may need to add one hour for
- daylight savings time. Rules are complicated. NBS gives us a day code.
- Day codes 02 thru 50 are DST for sure. Day 51 is DST if LOCAL hour >=2.
- Day 01 is DST if LOCAL hour < 2. We now have computed the local hour,
- so finally can make this adjustment. */
-
- if(daylight) { /*did user want us to consider DST?*/
- if( (dst1>=2 && dst1<=50) /*steady state DST case*/
- || (dst1==01 && hr1<2) /*leaving DST day case*/
- || (dst1==51 && hr1>=2) ) { /*entering DST day case*/
- time += 1; /*move us into DST*/
- Datek2(time/24L,&lda,&lmo,&lyr); /*get new d/m/y*/
- hr1 = (int) (time%24L); /*and fractional day*/
- }
- }
-
- /*Now we have local time. Do all the time-setting operations before printing
- any of the results, or doing any of the calls that use floating-point
- operations, so that we get everything set before much time passes. */
-
- ftime(&time_before); /*time before setting*/
-
- dostime.hour = (unsigned char) hr1;
- dostime.minute = (unsigned char) mi1;
- dostime.second = (unsigned char) se1;
- dostime.hsecond = (unsigned char) 0;
- j2 = _dos_settime(&dostime); /*set dos time*/
-
- dosdate.year = (unsigned int) lyr;
- dosdate.month = (unsigned char) lmo;
- dosdate.day = (unsigned char) lda;
- dosdate.dayofweek = (unsigned char) 0;
- j1 = _dos_setdate(&dosdate); /*set dos date*/
-
- ftime(&time_after); /*time after setting*/
-
- rtc = read_hw_rtc(&yr,&mo,&da,&hr,&mi,&se); /*hardware realtime clock*/
-
-
- printf("--- Setting DOS Date & Time to local: %02d/%02d/%d %02d:%02d:%02d ---\n",
- dosdate.month,dosdate.day,dosdate.year,
- dostime.hour,dostime.minute,dostime.second);
-
- if(j1 != 0) printf("--- DOS set Date failed ---\n");
- if(j2 != 0) printf("--- DOS set Time failed ---\n");
- if(j1 == 0 && j2 == 0) {
- time_change = floatime(time_after) - floatime(time_before); /*change*/
- printf("--- Your DOS time was %s NIST by %.2f seconds ---\n",
- time_change>0. ? "behind" : "ahead of",
- dabs(time_change) );
- }
- if(rtc) printf("--- Info only: Your hardware realtime clock reads: "
- "%02d/%02d/%d %02d:%02d:%02d ---\n",
- mo,da,yr,hr,mi,se);
-
- goto hangup; /*attempt to hang up phone*/
-
-
- hangup:
- hangup_the_modem(); /*terminate phone call*/
- disable_com_port(); /*live interrupt i/o ends*/
-
-
- printf("--- Done --- Phone call duration was %.1f seconds. ---\n",
- floatimenow() - floatime(start) - time_change );
-
- }
-
-
- /*-----------------------------------------------------------------------------
- dial_the_modem -- does just that. initiates phone call.
- ----------------------------------------------------------------------------*/
- void dial_the_modem(void) {
-
- control_modem(0x3); /*turn on DTR & RTS*/
-
- puts_modem("+++"); /*enter hayes command mode*/
- delay(1.25); /* +++ guardtime*/
-
- puts_modem(dial_sequence); /*dial!*/
-
- puts_modem("\r"); /*dial command terminator*/
- delay(0.1); /*avoid echo last char of dial*/
- }
-
-
-
- /*-----------------------------------------------------------------------------
- hangup_the_modem -- does just that. terminates phone call.
- ----------------------------------------------------------------------------*/
- void hangup_the_modem(void) {
-
- printf ("+++");
- puts_modem("+++"); /*enter hayes command mode*/
- delay(1.25); /* +++ guardtime*/
-
- printf( hangup_sequence); /*hangup command*/
- puts_modem(hangup_sequence);
-
- printf("\n");
- puts_modem("\r");
- delay(0.1); /*be sure command gets out!*/
-
- control_modem(0x00); /*drop DTR (hangs up some modems) */
- }
-
-
-
- /*-----------------------------------------------------------------------------
- parse_a_time -- attempt to parse a "time" line from NBS
- MJD YR MO DA H M S ST S UT1 msADV OTM
- nbs format--> 47511 88-12-16 06:03:44 00 0 -.1 045.0 UTC(NBS) *
- @ 1200 baud 47511 88-12-16 06:03:45 00 0 -.1 045.0 UTC(NBS) *
- H M S msADV OTM
- nbs format--> 06:03:44 045.0 * <--but how do i get the date?
- @ 300 baud 06:03:45 045.0 *
- ----------------------------------------------------------------------------*/
-
- parse_a_time(char *p, int *yr, int *mo, int *da,
- int *hr, int *mi, int *se, int *dstflg) {
-
- /*This scanf takes 3.3ms on my AT, but the following code that replaces it
- takes 0.3ms, so is a clear winner.
- int mjd;
- j = sscanf(line,"%d %d-%d-%d %d:%d:%d %d",&mjd,yr,mo,da,hr,mi,se,dstflg);
- */
- while(isspace(*p)) p++;
- while(isdigit(*p)) p++; /*past mjd*/
- while(isspace(*p)) p++;
- *yr = atoi(p); p+=3; /*date*/
- *mo = atoi(p); p+=3;
- *da = atoi(p); p+=3;
- while(isspace(*p)) p++;
- *hr = atoi(p); p+=3; /*time*/
- *mi = atoi(p); p+=3;
- *se = atoi(p); p+=3;
- while(isspace(*p)) p++;
- *dstflg = atoi(p); /*dst flag*/
-
-
- if(*yr<88 || *yr>99 || *mo<=0 || *mo>12 || *da<=0 || *da>31 ||
- *hr<0 || *hr>23 || *mi<0 || *mi>59 || *se<0 || *se>59 ) return 0;
- /*and legal values everywhere?*/
-
- return 1; /*good, then we got it*/
- }
-
-
-
- /*-----------------------------------------------------------------------------
- delay -- spinloop delay for wait seconds.
- ----------------------------------------------------------------------------*/
- void delay(double wait) {
- struct timeb start;
- ftime(&start);
- while(floatimenow() < floatime(start) + wait);
- }
-
-
- /*-----------------------------------------------------------------------------
- floatime -- converts a timeb structure to floating point seconds. Used
- outside critical time sections.
- ----------------------------------------------------------------------------*/
- double floatime(struct timeb t) {
- return t.time + .001*t.millitm;
- }
-
- double floatimenow() {
- struct timeb t;
- ftime(&t);
- return floatime(t);
- }
-
-
- #ifndef NOINTERRUPTS
- /*-----------------------------------------------------------------------------
- Enable COM port interrupts
- ----------------------------------------------------------------------------*/
- void enable_com_port() {
- com_wp = com_rp = 0; /*init buffer*/
- old_com_handler = _dos_getvect(8+nbs_port_irq); /*save old vect*/
- _dos_setvect(8+nbs_port_irq, com_interrupt_handler); /*set new vect*/
- outp(0x21,inp(0x21) & ~(1<<nbs_port_irq)); /*enable PIC*/
- set_mcr(0xff,0x08); /*enable board*/
- outp(nbs_port_address+UART_INT,0x01); /*enable UART*/
- inp(nbs_port_address+UART_LSR); /*dummy read*/
- inp(nbs_port_address+UART_DATA); /*dummy read*/
- com_port_live = 1; /*remember*/
- }
-
-
- /*-----------------------------------------------------------------------------
- Disable COM port interrupts
- We only disable if we had previously enabled. This allows this routine to
- be called from ^C interrupt handler, or other places that don't know
- whether we actually need to disable.
- ----------------------------------------------------------------------------*/
- void disable_com_port() {
- if(com_port_live) {
- outp(nbs_port_address+UART_INT,0x00); /*disable UART*/
- set_mcr(0x00,0x08); /*disable board*/
- outp(0x21,inp(0x21) | (1<<nbs_port_address)); /*disable PIC*/
- _dos_setvect(8+nbs_port_address, old_com_handler); /*restore old vect*/
- com_port_live = 0; /*remember*/
- }
- }
-
-
- /*-----------------------------------------------------------------------------
- COM input interrupt handler...
- ----------------------------------------------------------------------------*/
- static void _cdecl interrupt far com_interrupt_handler() {
- int c;
- unsigned next_wp;
-
- if((inp(nbs_port_address+UART_LSR) & 0x01) == 1) { /*character ready?*/
- c = inp(nbs_port_address+UART_DATA); /*yes. get it.*/
- next_wp = (com_wp+1) & 0x1f;
- if(next_wp != com_rp) { /*space available?*/
- com_buf[com_wp] = (char) c; /*store char*/
- com_wp = next_wp; /*advance write ptr*/
- }
- }
- outp(0x20,0x20); /*EOI the PIC*/
- }
-
-
- /*-----------------------------------------------------------------------------
- nonblocking read character from serial port using interrupt i/o
- ----------------------------------------------------------------------------*/
- int nbgetc_modem(void) {
- int c;
- if(com_wp != com_rp) { /*if char available*/
- c = com_buf[com_rp]; /*get character*/
- com_rp = (com_rp+1) & 0x1f; /*advance read ptr*/
- return c;
- }
- else { /*no char available*/
- return 0; /*return nothing*/
- }
- }
- #endif
-
-
- #ifdef NOINTERRUPTS
- /*-----------------------------------------------------------------------------
- nonblocking read character from serial port using direct i/o
- ----------------------------------------------------------------------------*/
- int nbgetc_modem(void) {
- if((inp(nbs_port_address+UART_LSR) & 0x01) == 0) /*character ready?*/
- return 0; /*no*/
- return inp(nbs_port_address+UART_DATA); /*yes*/
- }
- #endif
-
-
- /*-----------------------------------------------------------------------------
- write character to serial port using direct i/o
- ----------------------------------------------------------------------------*/
- void putc_modem(int c) {
- while((inp(nbs_port_address+UART_LSR) & 0x20) == 0); /*wait for holding reg*/
- outp(nbs_port_address+UART_DATA, c);
- }
-
-
- /*-----------------------------------------------------------------------------
- write string to serial port using direct i/o
- ----------------------------------------------------------------------------*/
- void puts_modem(char *s) {
- while(*s != 0)
- putc_modem(*s++);
- }
-
-
- /*-----------------------------------------------------------------------------
- set modem-control signals on serial port using direct i/o
- ----------------------------------------------------------------------------*/
- void control_modem(int c) {
- set_mcr(c,0x03);
- }
-
- void set_mcr(int valu,int mask) {
- outp(nbs_port_address+UART_MCR, valu&mask | inp(nbs_port_address+UART_MCR)&~mask);
- }
-
-
-
- /*-----------------------------------------------------------------------------
- put character to screen using bios. putc(c,stdio) took 1.4 mS, this takes
- 0.5 mS on my AT.
- ----------------------------------------------------------------------------*/
- void putc_screen(int c) {
- static union REGS reg;
-
- reg.h.ah = 0xE; /*write tty style*/
- reg.h.al = (char) c; /*this char*/
- reg.h.bh = 0; /*scn page 0*/
- int86(0x10,®,®); /*do it*/
- }
-
-
-
- /*----------------------------------------------------------------------------
- ACM Algorithm 199
- convert calendar date to day number
- K=1 at March 1, 1900.
- --------------------------------------------------------------------------*/
- long KDAY2(long Iday,long Month,long Iyear) {
- long M,IY,Kday;
- if(Iday < 1 || Iday > 31 || Month < 1 || Month > 12
- || Iyear < 1900 || Iyear > 1999) printf("?kday: ilg param\n");
-
- M=Month-3 ; IY=Iyear-1900;
- if(Month <= 2) {
- M=Month+9;
- IY=IY-1;
- }
- Kday=(1461*IY)/4+(153*M+2)/5+Iday;
- return Kday;
- }
-
-
- /*----------------------------------------------------------------------------
- ACM algorithm 199
- day number to calendar date
- Valid from 3/1/1900 thru 2/28/2000.
- --------------------------------------------------------------------------*/
- void Datek2(long K,long *Iday,long *Month,long *Iyear) {
- long day,month,year;
-
- if(K < 0 || K > 36500) printf("?datek: ilg param\n");
- year=(4*K-1)/1461;
- day=4*K-1-1461*year;
- day=(day+4)/4;
- month=(5*day-3)/153;
- day=5*day-3-153*month;
- day=(day+5)/5;
- month=month+3;
- year=year+1900;
- if(month >= 13) {
- month=month-12;
- year=year+1;
- }
- *Iday=day; *Month=month; *Iyear=year;
- }
-
-
-
- /*----------------------------------------------------------------------------
- Parameter initialization (reads .INI file)
- --------------------------------------------------------------------------*/
-
- void nbs_init(void) {
- FILE *init;
- char buf[80];
-
- #ifdef PARTOFIT /*when used in InstantTrack*/
- init = it_fopen("it.ini","r"); /*different way to open files*/
- if(init == NULL) return; /*if no file, use defaults*/
- while(NULL != fgets(buf,80,init)) { /*until end-of-file*/
- sscanf(buf," nist_dial = %50s", dial_sequence);
- sscanf(buf," nist_hangup = %50s", hangup_sequence);
- sscanf(buf," nist_port = %d", &nbs_port);
- if(1==sscanf(buf," nist_port = COM%d", &nbs_port)) nbs_port--;
- sscanf(buf," nist_port_address = %x", &nbs_port_address);
- sscanf(buf," nist_port_irq = %x", &nbs_port_irq);
- sscanf(buf," nist_speed = %d", &nbs_speed);
- sscanf(buf," nist_maxtime = %d", &maxtime);
- }
- #else
- init = fopen("nbscom.ini","r"); /*open .ini file*/
- if(init == NULL) return; /*if no file, use defaults*/
- while(NULL != fgets(buf,80,init)) { /*until end-of-file*/
- sscanf(buf," dial = %50s", dial_sequence);
- sscanf(buf," hangup = %50s", hangup_sequence);
- sscanf(buf," port = %d", &nbs_port);
- if(1==sscanf(buf," port = COM%d", &nbs_port)) nbs_port--;
- sscanf(buf," port_address = %x", &nbs_port_address);
- sscanf(buf," port_irq = %x", &nbs_port_irq);
- sscanf(buf," speed = %d", &nbs_speed);
- sscanf(buf," maxtime = %d", &maxtime);
- }
- #endif
-
- if(nbs_port_address == 0) nbs_port_address = port[nbs_port];
- if(nbs_port_irq == 0) nbs_port_irq = interrup[nbs_port];
-
- fclose(init); /*close .ini file*/
- }
-
-
- /*-----------------------------------------------------------------------------
- Routines to diddle the hardware realtime-clock (via BIOS)
- It's difficult to set the RTC accurately, because its least digit is seconds.
- Furthermore, the RTC can refuse to be read (if it's propagating a carry at
- the time). I plan to write some code that overcomes these difficulties, so
- that i can then set the RTC accurately.
- This only works on an IBMAT or later BIOS. It would also work if aftermarket
- RTCs came with TSRs that implemented the AT BIOS RTC functions, but none do.
- **NOTFINISHED**
- ----------------------------------------------------------------------------*/
- int read_hw_rtc(int *yr,int *mo,int *da,int *hr,int *mi,int *se) {
- union REGS reg;
-
- reg.h.ah = 4; /*read date from RTC*/
- reg.h.cl = reg.h.ch = 0xff; /*marker*/
- int86(0x1A,®,®); /*BIOS call*/
- if(reg.h.cl==0xff || reg.h.ch==0xff) return 0; /*if no RTC BIOS, fail return*/
- *yr = 100*xbcd(reg.h.ch) + xbcd(reg.h.cl);
- *mo = xbcd(reg.h.dh);
- *da = xbcd(reg.h.dl);
-
- reg.h.ah = 2; /*read time from RTC*/
- int86(0x1A,®,®); /*BIOS call*/
- *hr = xbcd(reg.h.ch);
- *mi = xbcd(reg.h.cl);
- *se = xbcd(reg.h.dh);
-
- return 1;
- }
-
-