home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug184.arc / ROS34.LBR / ROS.CZK / ROS.CLK
Text File  |  1979-12-31  |  3KB  |  93 lines

  1. { ROS.CLK - Remote Operating System Clock Routines }
  2.  
  3. { File:        QX-10.CLK
  4.   Description: This driver set is designed to support the Epson QX-10 internal
  5.                clock.  Two routines are provided to perform BCD to binary and
  6.                binary to BCD conversion.
  7.   Date:        8/3/85
  8.   Author:      Mick Gaitor
  9.   Credits:     Kevin Karns and Steve Fox
  10.  
  11.   Description: Comment update.
  12.   Date:        9/7/85
  13.   Author:      Steve Fox
  14. }
  15.  
  16. function BCD_to_Bin(BCD : Byte): byte;
  17. { Convert packed BCD value to binary }
  18.   begin
  19.      BCD_to_Bin := (10 * (BCD div 16)) + (BCD mod 16)
  20.   end; {BCD_to_Bin}
  21.  
  22. function Bin_to_BCD(Bin : byte): byte;
  23. { Convert binary value to packed BCD }
  24.   begin
  25.      Bin_to_BCD := (16 * (Bin div 10)) + (Bin mod 10)
  26.   end; {Bin_to_BCD}
  27.  
  28. procedure GetTAD(var t: tad_array);
  29. { Return a 6 element integer array of the current system time in
  30.     seconds, minutes, hours, day, month, and year.
  31.   This routine is based on a BASIC routine in THE EPSON QX-10
  32.   USER'S GUIDE by James Hansen (1984 - Scott, Foresman & Co.).  [MAG]
  33. }
  34.   const
  35.      ClkAddr = $3D;
  36.      ClkData = $3C;
  37.   var
  38.      ClkRegs : array[0..9] of byte;
  39.      ndx     : integer;
  40.   begin
  41.      repeat
  42.         { read all registers into a holding array for ease of access }
  43.         for ndx := 0 to 9 do
  44.            begin
  45.               port[ClkAddr] := ndx;         { write RAM addr to clock port }
  46.               ClkRegs[ndx]  := port[ClkData]{ read register data           }
  47.            end;
  48.         { check seconds data }
  49.         port[ClkAddr] := 0;                 { write secs addr to clock port }
  50.      until port[ClkData] = ClkRegs[0];      { make sure time hasn't changed }
  51.      { return time and date to calling routine }
  52.      t[0] := BCD_to_Bin(ClkRegs[0]);        { secs }
  53.      t[1] := BCD_to_Bin(ClkRegs[2]);        { mins }
  54.      t[2] := BCD_to_Bin(ClkRegs[4]);        { hrs  }
  55.      t[3] := BCD_to_Bin(ClkRegs[7]);        { day  }
  56.      t[4] := BCD_to_Bin(ClkRegs[8]);        { mo   }
  57.      t[5] := BCD_to_Bin(ClkRegs[9]);        { yr   }
  58.   end;
  59.  
  60. procedure SetTAD(var t: tad_array);
  61. { Set the system time using a 6 element byte array which contains
  62.     seconds, minutes, hours, day, month, and year.
  63.   (Same credit for clock access routine as GetTAD  [MAG])
  64. }
  65.   const
  66.      ClkAddr = $3D;
  67.      ClkData = $3C;
  68.   var
  69.      ClkRegs : array[0..9] of integer;
  70.      ndx     : integer;
  71.   begin
  72.      { read all registers into a holding array for ease of access }
  73.      for ndx := 0 to 9 do
  74.         begin
  75.            port[ClkAddr] := ndx;            { write RAM addr to clk port }
  76.            ClkRegs[ndx]  := port[ClkData]   { read register data         }
  77.         end;
  78.      { place new time and date in holding array slots }
  79.      ClkRegs[0] := Bin_to_BCD(t[0]);        { secs }
  80.      ClkRegs[2] := Bin_to_BCD(t[1]);        { mins }
  81.      ClkRegs[4] := Bin_to_BCD(t[2]);        { hrs  }
  82.      ClkRegs[7] := Bin_to_BCD(t[3]);        { day  }
  83.      ClkRegs[8] := Bin_to_BCD(t[4]);        { mo   }
  84.      ClkRegs[9] := Bin_to_BCD(t[5]);        { yr   }
  85.      { write holding array back to clock port }
  86.      for ndx := 0 to 9 do
  87.         begin
  88.            port[ClkAddr] := ndx;            { write RAM addr to clock port }
  89.            port[ClkData] := ClkRegs[ndx]    { write register data          }
  90.         end
  91.   end;
  92.  
  93.