! Display Handling Routines for Ether Monitor V1.3
! CDM  May 1984


   %routine gotoxy(%integer line,col)
   %constinteger esc=27

      printsymbol(esc); printsymbol('Y')
      printsymbol(line+' '); printsymbol(col+' ')
   %end

   %routine show time(%integer hours,minutes)
   %string(255) hrs,mins

      hrs = itos(hours,0); mins = itos(minutes,0)
      hrs  = ("0").hrs %if hours < 10
      mins = ("0").mins %if minutes < 10
      %if mode = colour monitor %start
         set colour(black)
         fill(Ox-50,Oy+1,Ox-6,Oy+yscale)
         set colour(yellow)
         at(Ox-50,Oy+1)
         showstring(hrs.":".mins)
      %else %if mode = v200
         gotoxy(Ox,2);printstring("     ")
         gotoxy(Ox,2);printstring(hrs.":".mins)
      %finish   
   %end

   %routine reset led bar(%integer time band)
   %constinteger esc=27
   %integer bar
      
      %if mode = colour monitor %start
         bar = Oy + (timeband * yscale)
         set colour(white)
         line(Ox,bar+1,Ox,bar+yscale)
         set colour(black)
         fill(Ox+1,bar+1,Ox+(xscale*100),bar+yscale)
         fill(0,bar+1,Ox-30,bar+yscale) %if time band # 0
      %else %if mode = v200
         bar = Ox - time band
         gotoxy(bar,0)
         printsymbol(esc);printsymbol('t')
         gotoxy(bar,Oy-4);write(-time band,3) %if time band # 0
         gotoxy(bar,Oy); printsymbol('|')
      %finish         
   %end

   %routine clear led bar(%integer maxoldpercent)
   %constinteger esc=27
   %integer percent

      %if mode = colour monitor %start
         percent = maxoldpercent//20
         percent = percent + 1 %if rem(maxoldpercent,20) >= 10
         set colour(red)
         %if percent <= peakwidth %start
            fill(Ox+1,Oy+1,Ox+ percent,Oy+yscale) %if percent > 0
         %else         
            fill(Ox+ percent - peakwidth,Oy+1,
                 Ox+ percent,Oy+yscale)
            set colour(black)
            fill(Ox+1,Oy+1,Ox+ percent - peakwidth,Oy+yscale)
         %finish
      %else %if mode = v200
         gotoxy(Ox,Oy);printsymbol(esc);printsymbol('x')
         gotoxy(Ox,Oy);printsymbol('|')
      %finish
   %end

   %routine  led bar(%integer oldpercent,newpercent,maxoldpercent)
   %integer percent,npercent,opercent

      %if mode = colour monitor %start
         clear led bar(maxoldpercent) %if oldpercent > newpercent
         npercent = newpercent//20
         npercent = npercent + 1 %if rem(newpercent,20) >= 10
         opercent = maxoldpercent//20
         opercent = opercent + 1 %if rem(maxoldpercent,20) >= 10
         %if newpercent # 0 %start
            set colour(green)
            %if npercent > peakwidth %start
               fill(Ox+1,Oy+1,Ox+ npercent - peakwidth,Oy+yscale)
               set colour(red) %if npercent >= opercent
               fill(Ox+ npercent - peakwidth,Oy+1,
                    Ox+ npercent,Oy+yscale)
            %else
               set colour(red) %if newpercent >= maxoldpercent
               fill(Ox+1,Oy+1,Ox+ npercent,Oy+yscale) %if npercent > 0
            %finish
         %finish
      %else %if mode = v200
         npercent = newpercent//200
         npercent = npercent + 1 %if rem(newpercent,200) >= 100
         opercent = maxoldpercent//200
         opercent = opercent + 1 %if rem(maxoldpercent,200) >= 100
         clear led bar(maxoldpercent)
         %if npercent >= opercent %start
            gotoxy(Ox,Oy+ npercent);printsymbol('>')
         %else 
            gotoxy(Ox,Oy+ npercent);printsymbol('+')
            gotoxy(Ox,Oy+ opercent);printsymbol('>')
         %finish
      %finish
   %end

   %routine show mean bars(%integer mean,peak,row)
   %integer bar,ppercent,mpercent,units,tenths
   %string(2) pt

      reset led bar(row)
      %if mode = colour monitor %start
         bar = Oy + (row * yscale)
         ppercent = peak//20
         ppercent = ppercent + 1 %if rem(peak,20) >= 10 
         mpercent = mean//20
         mpercent = mpercent + 1 %if rem(mean,20) >= 10 
         set colour(red)
         %if ppercent <= peakwidth %start
            fill(Ox+1,bar+1,Ox+ ppercent,bar+yscale)
         %else         
            fill(Ox+ ppercent - peakwidth,bar+1,
                 Ox+ ppercent,bar+yscale)
         %finish
         at(Ox-109,bar)
         units = peak//100; tenths = rem(peak,100)
         pt = "."; pt = pt."0" %if tenths < 10
         showstring(itos(units,0).pt.itos(tenths,0))
         set colour(blue)
         at(Ox-157,bar)
         units = mean//100; tenths = rem(mean,100)
         pt = "."; pt = pt."0" %if tenths < 10
         showstring(itos(units,0).pt.itos(tenths,0))
         fill(Ox+1,bar+1,Ox+ mpercent,bar+yscale)
      %else %if mode = v200
         bar = Ox - row
         gotoxy(bar,2)
         units = mean//100; tenths = rem(mean,100)
         pt = "."; pt = pt."0" %if tenths < 10
         write(units,3);printstring(pt);write(tenths,0)
         gotoxy(bar,9)
         units = peak//100; tenths = rem(peak,100)
         pt = "."; pt = pt."0" %if tenths < 10
         write(units,3);printstring(pt);write(tenths,0)
         ppercent = peak//200
         ppercent = ppercent + 1 %if rem(peak,200) >= 100
         mpercent = mean//200
         mpercent = mpercent + 1 %if rem(mean,200) >= 100
         gotoxy(bar,Oy + ppercent);printsymbol('>')
         gotoxy(bar,Oy + mpercent);printsymbol('*')
      %finish
   %end

   %routine set up display
   %constinteger esc=27

      %if mode = colour monitor %start
         setup
         readfont
         clear
         Ox = 170; Oy = 75
         xaxis = 500; yaxis = 375
         xscale = 5; yscale = 15
         maxdisplay = 23
         hline(Ox,Ox+xaxis,Oy)
         line(Ox,Oy,Ox,Oy+yaxis)
         at(Ox+200,Oy-35)
         showstring("% Utilisation Vs. Time")
         i=0
      ! Draw scale on X-axis
         %cycle
            %if rem(i,25) = 0 %start
               %if i//5 >= 100 %then at(Ox-10+i,Oy-20) %C
               %else %if i//5 >= 10 %then at(Ox-7+i,Oy-20) %C
               %else at(Ox-3+i,Oy-20)
               showstring(itos(i//5,0))
               line(Ox+i,Oy,Ox+i,Oy-9)
            %else
               line(Ox+i,Oy,Ox+i,Oy-5)
            %finish
            i= i + xscale
         %repeat %until i > xaxis
      ! Draw scale on Y-axis
         i=yscale
         %cycle
            %if i//15 >= 10 %then at(Ox-29,Oy+1+i) %C
            %else at(Ox-19,Oy+1+i)
            showsymbol('-')
            showstring(itos(i//15,0))
            hline(Ox-5,Ox,Oy+i)
            i = i + yscale
         %repeat %until i + yscale >  yaxis
         hline(Ox-5,Ox,Oy+i)
      %else %if mode = v200
         Ox = 20; Oy = 24
         maxdisplay = 9
         gotoxy(Ox+1,Oy)
         printstring("+----+----+----+----+----+----+----+----+----+----+")
         gotoxy(Ox+2,Oy)
         printstring("0   10   20   30   40   50   60   70   80   90   100")
         gotoxy(Ox+3,Oy)
         printstring("              % Utilisation Vs. Time")
         i=1
         gotoxy(Ox,Oy);printstring("|")
         %cycle
             gotoxy(Ox-i,Oy-4);write(-i,3);printstring("|")
             i= i + 1
          %repeat %until i > maxdisplay + 1
      %finish
   %end
