%begin
   %include "mach:extl1.imp"
   %include "fred:trig"
   %include "inc:fs.imp"
   %include "inc:util.imp"
   %record %format pointfm(%integer x, y)
   %record %format linefm(%integer x0, x1, y)
   %const %integer cx = 344
   %integer size = 250
   %integer dr, dw, hr, mr, sr
   %integer i, x, y, h, m, s, ss, sss, t, tt, ah, am, as, al h, al m, al s,
      state, alarm, ring, setting, sym, text x
   %switch set(0:2)
   %real piov6, piov30, piov1500, xt, yt
   %record(pointfm) a, b, c, ha, hb, hc, ma, mb, mc, mma, mmb, mmc,
          hha, hhb, hhc
   %record(pointfm) %array da, db, dc(0:11)
   %string(15) time
%routine draw clock(%integer cy)
   dr = size*31//32
   dw = size//32
   hr = size*5//8
   mr = size*25//32
   sr = size*15//16
   colour(white)
   text at(8, cy-248)
   show string("Alarm time :")
   colour(blue)
   piov6 = pi
   piov30 = piov6/30
   piov1500 = piov6/1500
   piov6 = piov6/6
   disc(cx, cy, size)
   colour(red)
   %for i = 3, 1, 14 %cycle
      xt = cos(i*piov6)
      yt = sin(i*piov6)
      a_x = intpt(xt*(mr+1))
      a_y = intpt(yt*(mr+1))
      b_x = intpt(xt*dr+yt*dw)
      b_y = intpt(yt*dr-xt*dw)
      c_x = intpt(xt*dr-yt*dw)
      c_y = intpt(yt*dr+xt*dw)
      da(i-3) = a
      db(i-3) = b
      dc(i-3) = c
      a_x = a_x+cx
      a_y = a_y+cy
      b_x = b_x+cx
      b_y = b_y+cy
      c_x = c_x+cx
      c_y = c_y+cy
      triangle(a_x, a_y, b_x, b_y, c_x, c_y)
   %repeat
   a_x = cx
   a_y = cx
   ha = a
   hb = a
   hc = a
   ma = a
   mb = a
   mc = a
   hha = a
   hhb = a
   hhc = a
   mma = a
   mmb = a
   mmc = a
   ss  = 0
   sss = 0
%end
%integer cy = 256, ccy = 768
%routine show time(%integer hrs, mins, secs)
   %integer wait, temp
   temp = cy
   cy = ccy
   ccy = temp
   colour(blue)
   triangle(hha_x, hha_y, hhb_x, hhb_y, hhc_x, hhc_y)
   triangle(mma_x, mma_y, mmb_x, mmb_y, mmc_x, mmc_y)
   yt = (3750-sss)*piov1500
   line(cx, cy, cx+intpt(cos(yt)*sr), cy+intpt(sin(yt)*sr))
   sss = rem((3125-sss)//250, 12)
   colour(red)
   a = da(sss)
   b = db(sss)
   c = dc(sss)
   a_x = a_x+cx
   a_y = a_y+cy
   b_x = b_x+cx
   b_y = b_y+cy
   c_x = c_x+cx
   c_y = c_y+cy
   triangle(a_x, a_y, b_x, b_y, c_x, c_y)
   colour(yellow)
   yt = (75-hrs*5-mins/12)*piov30
   xt = cos(yt)
   yt = sin(yt)
   a_x = cx+intpt(xt*hr)
   a_y = cy+intpt(yt*hr)
   b_x = cx+intpt(yt*dw)
   b_y = cy+intpt(-xt*dw)
   c_x = cx+intpt(-yt*dw)
   c_y = cy+intpt(xt*dw)
   hha = ha
   hhb = hb
   hhc = hc
   ha=a
   hb=b
   hc=c
   triangle(a_x, a_y, b_x, b_y, c_x, c_y)
   colour(green)
   yt = (75-mins-secs/3000)*piov30
   xt = cos(yt)
   yt = sin(yt)
   a_x = cx+intpt(xt*mr)
   a_y = cy+intpt(yt*mr)
   b_x = cx+intpt(yt*dw)
   b_y = cy+intpt(-xt*dw)
   c_x = cx+intpt(-yt*dw)
   c_y = cy+intpt(xt*dw)
   mma = ma
   mmb = mb
   mmc = mc
   ma=a
   mb=b
   mc=c
   triangle(a_x, a_y, b_x, b_y, c_x, c_y)
   colour(white)
   yt = (3750-secs)*piov1500
   line(cx, cy, cx+intpt(cos(yt)*sr), cy+intpt(sin(yt)*sr))
   disc(cx, cy, dw)
   sss = ss
   ss = secs
   offset(0, cy-256)
   wait = cpu time+20
   %while cpu time<=wait %cycle
      print symbol(7) %unless ring=0
   %repeat
%end
%string(15) %function datime
   %string(255) s
   length(s) = fcommr('G0',"",charno(s,1),255)
   %result = s
%end
time = datime
h = (charno(time, 11)-'0')*10+charno(time, 12)-'0'
h = rem(h, 12)
m = (charno(time, 14)-'0')*10+charno(time, 15)-'0'
m = rem(m, 60)
!new line
!prompt("Hr:")
!read(h)
!h = rem(h, 12)
!prompt("Min:")
!read(m)
!m = rem(m, 60)
s = 0
t = cpu time
clear
offset(0, 0)
draw clock(256)
draw clock(768)
setting = 0
alarm = 0
ring = 0
ah = 0
am = 0
as = 0
text x = 56
%cycle
   sym = test symbol
   %while sym>=0 %cycle
      ring = 0
      %if sym=nl %start
         %unless setting=0 %start
            alarm = 1
            al h = rem(ah, 12)
            al m = rem(am, 60)
            al s = rem(as, 60)
         %else
            colour(black)
            fill(118, 8, 200, 20)
            fill(118, 520, 200, 532)
         %finish
         ah = 0
         am = 0
         as = 0
         setting = 0
      %else
         %if setting=0 %start
            colour(black)
            fill(118, 8, 200, 20)
            fill(118, 520, 200, 532)
            text x = 126
         %finish
         colour(white)
         text at(text x, 8)
         show symbol(sym)
         text at(text x, 520)
         show symbol(sym)
         text x = text x+8
         alarm = 0
         %if '0'<=sym<='9' %start
            state = 0 %if setting=0
            setting = 1
            ->set(state)
set(0):     ah = ah*10+sym-'0'
            sym = test symbol
            %continue
set(1):     am = am*10+sym-'0'
            sym = test symbol
            %continue
set(2):     as = as*10+sym-'0'
            sym = test symbol
            %continue
         %else %if sym=' ' %or sym=':' %or sym='.'
            state = state+1 %if state<2
         %else
            clear
            print symbol(27)
            print symbol('R')
            %stop
         %finish
      %finish
      sym = test symbol
   %repeat
   tt = t
   t = cpu time
   s = s+t-tt
   %if s>=60000 %start
      s = s-60000
      m = rem(m+1, 60)
      h = rem(h+1, 12) %if m=0
   %finish
   %unless alarm=0 %start
      ring = 1 %if al h=h %and al m=m %and al s=s//1000
   %finish
   show time(h, m, (s+50)//20)
%repeat
%end %of %program
