/* program in MIX 'C' to read real-time-clock located at ports 30h through 33h in Morrow MD 2/3 rev. 2 main board. Mike Allen 7/13/86 */ #include "stdio" #include "stdlib.h" #define CLS 'Z'-0x40 /* Clear Screen (^Z) */ #define HOME '^'-0x40 /* Home Cursor (^^) [MDT 60/70] */ #define CUROFF "\033\"6" /* Turn cursor off (ESC " 6) [MDT 60/70] */ #define CURON "\033\"0" /* Turn cursor on (ESC " 0) [MDT 60/70] */ #define PA 0x30 /* 8255 A register */ #define PB 0x31 /* 8255 B register */ #define PC 0x32 /* 8255 C register */ #define CNTRL 0x33 /* 8255 Control register */ main() { int rtc[13]; /* MSM8532 registers */ int i, /* general loop variable */ civil_time; /* 24hr, AM or PM indicator */ char *day[]={"Sunday", /* pointer array of days of the week */ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; char *tag[]={"HRS.", /* pointer array of time tags */ "AM", "PM"}; puts(CUROFF); /* Turn off the cursror */ putchar(CLS); /* Clear the screen */ outp(CNTRL,'\220'); /* Set up 8255 */ outp(PC,'\040'); /* Put MSM5832 in 'read' mode */ while(!keypress()){ /* loop until any key is pressed */ for(i=0;i<13;i++) { /* read all 13 MSM5832 registers */ outp(PB,i); /* output the register address */ rtc[i]=inp(PA)&0xf; /* read the register and strip the 4 top bits */ } rtc[8]&=0x3; /* strip off the leap year flag */ if(rtc[5]>7) /* check for 24 hr time. */ civil_time=0; else if(rtc[5]>3) /* not 24 hr, check for PM */ civil_time=2; else /* not 24 hr or PM. Must be AM. */ civil_time=1; rtc[5]&=0x3; /* strip off 24hr and PM flags */ printf("%cDATE: %s, %d/%d/%d%d\n",HOME,day[rtc[6]], 10*rtc[10]+rtc[9],10*rtc[8]+rtc[7],rtc[12],rtc[11]); /* home the cursor, print the day and date */ if(!civil_time) /* if 24 hr time... */ printf("TIME: %d%d",rtc[5],rtc[4]); /* ... don't suppress leading 0 in the hours */ else /* not 24 hr time, suppress leading 0 */ printf("TIME: %d",rtc[5]*10+rtc[4]); printf(":%d%d:%d%d %s",rtc[3],rtc[2],rtc[1],rtc[0], tag[civil_time]); /* print min, sec and appropriate tag */ } /* end of the main loop */ outp(PC,'\000'); /* We're quitting, so take the MSM5832 out of the read mode */ puts(CURON); /* and turn the cursor back on */ exit(0); /* We done! We bad! */ }