! New 1976-spec filestore
! The main program which initialises everything and
! starts up all the processes, before diving into the
! scheduler, from whence it never (we hope!) returns.

%option "-nocheck-nodiag-noline"

%constinteger default encrypted password = 16_212AF09E;  ! The system password

%include "Config.Inc"

%include "System:Common"
%include "System:Utility.Inc"

%externalstring(255)%fnspec unpack VAX date(%short date)

%include "Inc:Util.Imp"

%recordformat frig fm(%record(common fm)%name common)
%externalrecord(frig fm)%spec common frig
! These are needed because %external %names don't work.
! (Maybe they do now (Imp V2)?)

%externalroutinespec init common
%externalroutinespec start processes
%externalroutinespec schedule

%externalroutinespec set VAX date(%string(255) date)
%externalstring(31)%fnspec VAX date

@16_400031 %readonly %byte switch register

%begin
%on %event 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 %start
  newline; printstring("**Event ")
  write(event_event,0); write(event_sub,1); space
  phex(event_extra); space; printstring(event_message); newline
%finish
%routine begin
   %record(common fm) common area
   %string(255) d, t
   %integer i
   %short xd, xt
      open input(1, ":T");  select input(1)
      ! We may have been started up in a command file.
      set terminal mode(no page)
      d = VAX date
      %if d = "" %start
         ! VAX not responding.  Ask for the date on the console.
try again:
         printstring("Enter date in the form DD-MMM-YYYY")
         newline
         read {string}(d)
         upper case(d)
         printstring("Enter time in the form HH.MM")
         newline
         read {string}(t)
         d = d . "  " . t
      %else
         ! Fiddle the time part's format
         length(d) = 18;  charno(d, 16) = '.'
      %finish
      -> invalid %if length(d) # 18
      charno(d, 1) = '0' %if charno(d, 1) = ' ';  ! Leading space allowed
      set VAX date(d)
      time stamp(xd, xt)
      %unless unpack VAX date(xd) . "  " . unpack time(xt) = d %start
invalid: printstring("Invalid date or time: ");  printstring(d);        newline
         printstring("Should be, for example, 01-JUN-1984 and 12.45");  newline
         -> try again
      %finish
      common area = 0;  ! zap everything
      common area_system pass = default encrypted password
      common frig_common == common area
      !! common area_diags = -1
      init common;      ! Unfortunately main programs and %externals don't mix...
      start processes;  ! Start off all the processes.
      pdate;  printstring("Booted from area ")
      %if switch register & 15 = 0 %then print symbol('0') %c
                                   %else print symbol('1')
      newline
      schedule;         ! Dive off into the scheduler (shoudn't ever come back).
      printstring("*** Returned from scheduler ***");  newline
%end;begin
%end %of %program
