%option "-low"

%string (255) %function get MSF time
  !DAK 22/05/85
  !** MSF clock decoder board interface, copy the the various
  !** time formats and information into a string which can be
  !** returned to where ever.
  !** the first 17 characters of the string are non printable
  !** map another string on top for following
  !** compact time = string(addr(charno(result,19)))
  !** full time = string(addr(charno(result,41)))
  !** see CS4 project report for full details
  !!%option "-low-nocheck-nodiag-noline"

  %record %format time fm (%byte control1, control2, turn, null,
     hundred, second, minute, hour, day of week, day of month,
     month, year, century, BST)
  %record %format compact time fm (%byte control1, control2, turn,
     null, %string(21) time)
  %record %format full time fm (%byte control1, control2, turn,
     null, %string(55) time)
  %record %format last update fm (%byte control1, control2, turn,
     null, year, month, day of month, day of week, hour, minute)

  @16_00F80800 %record (time fm) A
  @16_00F8080E %record (compact time fm) B
  @16_00F80828 %record (full time fm) C
  @16_00F80864 %record (last update fm) D

  %byte %integer %array buffer(-1:100)
  %integer i

  %on %event 0,13 %start
    buffer(-1) = 1
    buffer(0) = 254 %if event_event = 0
    buffer(0) = 255 %if event_event = 13
    %result = string(addr(buffer(-1)))
  %finish

  %routine grab (%record (*) %name R)
    %recordformat s fm (%byte control1, control2, turn)
    %record(s fm) %name S
    %integer tout
    S==R
    S_control2 = 0
    S_turn = 255
    tout = 0
    %while S_control1=0 %and S_turn#0 %cycle
      tout = tout + 1
      %if tout > 50 %start
        S_control2 = 255
        %signal 13
      %finish
    %repeat
  %end

  %routine release (%record (*) %name R)
    %recordformat s fm (%byte control1, control2, turn)
    %record(s fm) %name S
    S==R
    S_control2 = 255
  %end

  grab (A)
  buffer(1) = A_hundred
  buffer(2) = A_second
  buffer(3) = A_minute
  buffer(4) = A_hour
  buffer(5) = A_day of week
  buffer(6) = A_day of month
  buffer(7) = A_month
  buffer(8) = A_year
  buffer(9) = A_century
  buffer(10) = A_BST
  release (A)

  grab (D)
  buffer(11) = D_year
  buffer(12) = D_month
  buffer(13) = D_day of month
  buffer(14) = D_day of week
  buffer(15) = D_hour
  buffer(16) = D_minute
  release (D)

  grab (B)
  buffer(18) = length(B_time)
  buffer(i+18) = charno(B_time,i) %for i = 1,1,buffer(18)
  release (B)

  grab (C)
  buffer(40) = length(C_time)
  buffer(i+40) = charno(C_time,i) %for i = 1,1,buffer(40)
  release (C)

  buffer(-1) = buffer(40)+40
  buffer(0) = 0
  %result = string(addr(buffer(-1)))
%end

%end %of %file
