! 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 sub mode = utilisation %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 sub mode = packet matrix %or sub mode = data matrix
         set colour(black)
         fill(Ox-50,Oy-50,Ox-6,Oy-40)
         set colour(yellow)
         at(Ox-50,Oy-50)
         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 sub mode = utilisation %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 sub mode = utilisation %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 sub mode = utilisation %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 sub mode = utilisation %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 monitor display
   %constinteger esc=27

      %if sub mode = utilisation %start
         set colour(white)
         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-120,Oy+yaxis+5)
         showstring("Sample Interval(minutes) = ")
         showstring(itos(interval,0))
         showstring("  Sample Period(Milliseconds) = ")
         showstring(itos(period,0))
         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

   %routine traffic matrix
   %integer add on,station,dot
   
      %routine show traffic key
      %integer f,t

         t = Ox+xaxis+120
         f = Oy+yaxis-20
         set colour(blue)
         at(t-50,f);showstring(" 0 < ")
         fill(t,f+2,t+6,f+8);at(t+10,f);showstring(" <= 1")
         f = Oy+yaxis-32
         set colour(magenta)
         at(t-50,f);showstring(" 1 < ")
         fill(t,f+2,t+6,f+8);at(t+10,f);showstring(" <= 5")
         f = Oy+yaxis-44
         set colour(red)
         at(t-50,f);showstring(" 5 < ")
         fill(t,f+2,t+6,f+8);at(t+10,f);showstring(" <= 15")
         f = Oy+yaxis-56
         set colour(green)
         at(t-50,f);showstring("15 < ")
         fill(t,f+2,t+6,f+8);at(t+10,f);showstring(" <= 25")
         f = Oy+yaxis-68
         set colour(yellow)
         at(t-50,f);showstring("25 < ")
         fill(t,f+2,t+6,f+8);at(t+10,f);showstring(" <= 50")
         f = Oy+yaxis-80
         set colour(cyan)
         at(t-50,f);showstring("50 < ")
         fill(t,f+2,t+6,f+8);at(t+10,f);showstring(" <= 75")
         f = Oy+yaxis-92
         set colour(white)
         at(t-50,f);showstring("75 < ")
         fill(t,f+2,t+6,f+8);at(t+10,f);showstring(" <= 100")
      %end

      set colour(white)
      clear
      Ox = 70; Oy = 60
      xaxis = 378; yaxis = 378
      xscale = 7; yscale = 7
      maxdisplay = 23
      hline(Ox,Ox+xaxis,Oy)
      line(Ox+1+xaxis,Oy,Ox+1+xaxis,Oy+yaxis)
      hline(Ox,Ox+xaxis,Oy+1+yaxis)
      line(Ox,Oy,Ox,Oy+yaxis)
      i=0
      station = 10
      add on = 8
      ! Draw Traffic Matrix
      %cycle
         %if rem(i,56) = 0 %start
            %if 10 < station < 48 %start
               at(Ox-25,Oy+i-10);showstring(itos(station,0))
               at(Ox+xaxis+10,Oy+i-10);showstring(itos(station,0))
               at(Ox+i-6,Oy-19);showstring(itos(station//10,0))
               at(Ox+i-6,Oy-30);showstring(itos(rem(station,10),0))
               at(Ox+i-6,Oy+yaxis+19);showstring(itos(station//10,0))
               at(Ox+i-6,Oy+yaxis+8);showstring(itos(rem(station,10),0))
            %finish
            station = station + add on
            add on = 10 - add on
         %finish
         %if i = xaxis %start
            at(Ox-35,Oy+i-7);showstring("Vax")
            at(Ox-35,Oy+i-19);showstring("FS")
            at(Ox+xaxis+10,Oy+i-7);showstring("Vax")
            at(Ox+xaxis+10,Oy+i-19);showstring("FS")
            at(Ox+i-15,Oy-19);showstring("FV")
            at(Ox+i-15,Oy-30);showstring("Sa")
            at(Ox+i-6,Oy-41);showstring("x")
            at(Ox+i-6,Oy+yaxis+30);showstring("V")
            at(Ox+i-15,Oy+yaxis+19);showstring("Fa")
            at(Ox+i-15,Oy+yaxis+8);showstring("SX")
         %finish
         line(Ox+i,Oy+1+yaxis,Ox+i,Oy+1+yaxis+5)
         hline(Ox-5,Ox,Oy+i)
         line(Ox+i,Oy-5,Ox+i,Oy)
         hline(Ox+1+xaxis,Ox+1+xaxis+5,Oy+i)
         %if i > 0 %start
            frame(((Oy+i-3)&1023)<<5+((Ox+dot)&1023)>>5) = %C
                     1<<(31-(Ox+dot)&31) %for dot = 4,xscale,xaxis-xscale+4
         %finish
         i= i + xscale
      %repeat %until i > xaxis
      at(Ox+50,Oy+yaxis+40);showstring("Destination Station")
      at(Ox-40,Oy+260);showsymbol('S');at(Ox-40,Oy+250);showsymbol('o')
      at(Ox-40,Oy+240);showsymbol('u');at(Ox-40,Oy+230);showsymbol('r')
      at(Ox-40,Oy+220);showsymbol('c');at(Ox-40,Oy+210);showsymbol('e')
      at(Ox-40,Oy+190);showsymbol('S');at(Ox-40,Oy+180);showsymbol('t')
      at(Ox-40,Oy+170);showsymbol('a');at(Ox-40,Oy+160);showsymbol('t')
      at(Ox-40,Oy+150);showsymbol('i');at(Ox-40,Oy+140);showsymbol('o')
      at(Ox-40,Oy+130);showsymbol('n')
      at(Ox+20,Oy-42)
      %if sub mode = packet matrix %start
         showstring("Traffic Matrix by no. of Packets")
         at(Ox+xaxis+50,Oy+yaxis+11)
         showstring("KEY:")
         at(Ox+xaxis+50,Oy+yaxis)
         showstring("% of Total Packets")
         show traffic key
         at(Ox+xaxis+50,Oy+yaxis-104)
         showstring("100% =")
      %else %if sub mode = data matrix
         showstring("Traffic Matrix by Amount of Data")
         at(Ox+xaxis+50,Oy+yaxis+11)
         showstring("KEY:")
         at(Ox+xaxis+50,Oy+yaxis)
         showstring(" % of Total Data")
         show traffic key
         at(Ox+xaxis+50,Oy+yaxis-104)
         showstring("100% =")
      %finish
   %end

   %routine show station(%byte colour,%integer from,to)
   %integer f,t

      f = Oy+1 + ((from-firstcli) * yscale)
      t = Ox+1 + ((to-firstcli) * xscale)
      f = f + (5*yscale) %if from > maxclis
      t = t + (5*yscale) %if to > maxclis
      set colour(colour)
      fill(t,f,t+6,f+6)
   %end

   %routine show traffic(%record(matrix fill)%array%name %C
                            traffic(firstcli:maxclis+2,firstcli:maxclis+2))
   %integer packets,i,j,jump
   %integer temp           { so remove a compiler bug   im  25/2/85  }
   %byte data colour,packet colour
   %switch sdc(0:100),spc(0:100)

   packets = pak + acks
   set colour(black)
   temp=ox+xaxis+115
   fill(temp,Oy+yaxis-104,Ox+xaxis+200,Oy+yaxis-93)
   set colour(white)
   at(Ox+xaxis+115,Oy+yaxis-104)
   showstring(itos(total data,0)) %if sub mode = data matrix
   showstring(itos(packets,0)) %if sub mode = packet matrix
   %for i = firstcli,1,maxclis+2 %cycle
      %for j = firstcli,1,maxclis+2 %cycle
         %if sub mode = data matrix %start
            %if traffic(i,j)_data= 0 %or total data= 0 %start
               data colour = 0
            %else 
               jump = int((traffic(i,j)_data / total data)*100)
               jump = 100 %if jump > 100
               -> sdc(jump)
               sdc(0):
                  data colour = blue
                  -> SHOW DATA
               sdc(1):sdc(2):sdc(3):sdc(4):sdc(5):
               sdc(6):sdc(7):sdc(8):sdc(9):sdc(10):
                  data colour = magenta
                  -> SHOW DATA
               sdc(11):sdc(12):sdc(13):sdc(14):sdc(15):
                  data colour = red
                  -> SHOW DATA
               sdc(16):sdc(17):sdc(18):sdc(19):sdc(20):
               sdc(21):sdc(22):sdc(23):sdc(24):sdc(25):
                  data colour = green
                  -> SHOW DATA
               sdc(26):sdc(27):sdc(28):sdc(29):sdc(30):
               sdc(31):sdc(32):sdc(33):sdc(34):sdc(35):
               sdc(36):sdc(37):sdc(38):sdc(39):sdc(40):
               sdc(41):sdc(42):sdc(43):sdc(44):sdc(45):
               sdc(46):sdc(47):sdc(48):sdc(49):sdc(50):
                  data colour = yellow
                  -> SHOW DATA
               sdc(51):sdc(52):sdc(53):sdc(54):sdc(55):
               sdc(56):sdc(57):sdc(58):sdc(59):sdc(60):
               sdc(61):sdc(62):sdc(63):sdc(64):sdc(65):
               sdc(66):sdc(67):sdc(68):sdc(69):sdc(70):
               sdc(71):sdc(72):sdc(73):sdc(74):sdc(75):
                  data colour = cyan
                  -> SHOW DATA
               sdc(76):sdc(77):sdc(78):sdc(79):sdc(80):
               sdc(81):sdc(82):sdc(83):sdc(84):sdc(85):
               sdc(86):sdc(87):sdc(88):sdc(89):sdc(90):
               sdc(91):sdc(92):sdc(93):sdc(94):sdc(95):
               sdc(96):sdc(97):sdc(98):sdc(99):sdc(100):
                  data colour = white
               SHOW DATA:
            %finish
            %if data colour # traffic(i,j)_dcol %start
               traffic(i,j)_dcol = data colour
               show station(data colour,i,j) %if data colour # black
            %finish
         %else
            %if traffic(i,j)_packets= 0 %or packets= 0 %start
               packet colour = 0 
            %else 
               jump = int((traffic(i,j)_packets / packets) * 100)
               jump = 100 %if jump > 100
               -> spc(jump)
               spc(0):
                  packet colour = blue
                  -> SHOW PACKET
               spc(1):spc(2):spc(3):spc(4):spc(5):
               spc(6):spc(7):spc(8):spc(9):spc(10):
                  packet colour = magenta
                  -> SHOW PACKET
               spc(11):spc(12):spc(13):spc(14):spc(15):
                  packet colour = red
                  -> SHOW PACKET
               spc(16):spc(17):spc(18):spc(19):spc(20):
               spc(21):spc(22):spc(23):spc(24):spc(25):
                  packet colour = green
                  -> SHOW PACKET
               spc(26):spc(27):spc(28):spc(29):spc(30):
               spc(31):spc(32):spc(33):spc(34):spc(35):
               spc(36):spc(37):spc(38):spc(39):spc(40):
               spc(41):spc(42):spc(43):spc(44):spc(45):
               spc(46):spc(47):spc(48):spc(49):spc(50):
                  packet colour = yellow
                  -> SHOW PACKET
               spc(51):spc(52):spc(53):spc(54):spc(55):
               spc(56):spc(57):spc(58):spc(59):spc(60):
               spc(61):spc(62):spc(63):spc(64):spc(65):
               spc(66):spc(67):spc(68):spc(69):spc(70):
               spc(71):spc(72):spc(73):spc(74):spc(75):
                  packet colour = cyan
                  -> SHOW PACKET
               spc(76):spc(77):spc(78):spc(79):spc(80):
               spc(81):spc(82):spc(83):spc(84):spc(85):
               spc(86):spc(87):spc(88):spc(89):spc(90):
               spc(91):spc(92):spc(93):spc(94):spc(95):
               spc(96):spc(97):spc(98):spc(99):spc(100):
                  packet colour = white
               SHOW PACKET:
            %finish
            %if packet colour # traffic(i,j)_pcol %start
               traffic(i,j)_pcol = packet colour
               show station(packet colour,i,j) %if packet colour # black
            %finish
         %finish
      %repeat
   %repeat
%end
