home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / PROGRAMS / CLOCKK / MDCLCK13.LBR / READTIME.PZS / READTIME.PAS
Pascal/Delphi Source File  |  2000-06-30  |  3KB  |  59 lines

  1. {       program in TurboPASCAL to read real-time-clock loacted at ports
  2.         30h through 33h in Morrow MD 2/3 rev.2 main board
  3.                   Mike Allen 7/13/86                                   }
  4. program time;
  5.  
  6. const
  7.   {array of days of the week}
  8.   day: array[0..6] of string[9] = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  9.   {array of time tags}
  10.   tag: array[0..2] of string[4] = ('HRS.','AM','PM');
  11.   CLS= ^Z;           {Clear Screen}
  12.   HOME = ^^;         {Home cursor [MDT 60/70]}
  13.   CUROFF = ^['"6';   {Turn off cursor (ESC"6) [MDT60/70]}
  14.   CURON = ^['"0';    {Turn on cursor (ESC"0) [MDT60/70]}
  15.   PA = $30;          {8255 A register}
  16.   PB = $31;          {8255 B register}
  17.   PC = $32;          {8255 C register}
  18.   CNTRL = $33;       {8255 control register}
  19.  
  20. var
  21.   rtc: array[0..12] of byte;  {MSM8532 registers}
  22.   i,civil_time: byte;         {i=general loop variable,
  23.                                civil_time=24hr, AM or PM indicator}
  24.  
  25. begin
  26.   write(CUROFF);     {turn off the cursor}
  27.   write(CLS);        {clear the screen}
  28.   port[CNTRL]:=$90;  {set up the 8522}
  29.   port[PC]:=$20;     {put MSM5832 in 'read' mode}
  30.   while not KeyPressed do     {loop until a key is pressed}
  31.   begin
  32.     for i:=0 to 12 do         {read all 12 MSM5832 registers}
  33.     begin
  34.       port[PB]:=i;            {output the register address}
  35.       rtc[i]:=port[PA] and $0f     {read the register and
  36.                                     strip the top 4 bits}
  37.     end;
  38.     rtc[8]:=rtc[8] and $03;   {strip off the leap year flag}
  39.     if rtc[5]>7 then          {check for 24hr time}
  40.       civil_time:=0
  41.     else if rtc[5]>3 then     {not 24 hr, check for PM}
  42.       civil_time:=2
  43.     else
  44.       civil_time:=1;          {not 24 hr or PM, must be AM}
  45.     rtc[5]:=rtc[5] and $03;   {strip off 24hr and PM flags}
  46.     writeln(HOME,'DATE: ',day[rtc[6]],', ',10*rtc[10]+rtc[9],'/',10*rtc[8]+rtc[7],'/',rtc[12]:1,rtc[11]:1);
  47.             {home the cursor and print the day and date}
  48.     if civil_time=0 then
  49.       write('TIME: ',rtc[5]:1,rtc[4]:1) {if 24hr time, print leading 0 in hrs}
  50.     else
  51.       write('TIME: ',10*rtc[5]+rtc[4]); {otherwise suppress it.}
  52.     write(':',rtc[3]:1,rtc[2]:1,':',rtc[1]:1,rtc[0]:1,' ',tag[civil_time])
  53.            {print minutes, seconds and tag}
  54.   end;
  55.   port[PC]:=$00;  {take the MSM5832 out of read mode}
  56.   write(CURON)    {turn the cursor back on}
  57. end.              { and retire!}
  58. PC]:=$00;  {take the MSM5832 out of read mode}
  59.   write(CURON)    {turn the cursor