

{IncludeFrom=sysglobals <p2c/sysglobals.h>}


{*VarStrings=1} {*ExportSymbol=}


module sysglobals;  

export 

type fsidctype = packed array[1..20] of char; 
const 
  fsidc = fsidctype['Rev.  3.1  18-Jul-85'];   
                             (*20 CHARS: VERSION,DATE,TIME OF FILE SYS*)
  mminint = -32768;          (*MINIMUM SHORT INTEGER VALUE*)
  mmaxint =  32767;          (*MAXIMUM SHORT INTEGER VALUE*)
  maxunit = 50;              (*MAXIMUM PHYSICAL UNIT NUMBER*)
  passleng = 16;             (*NUMBER OF CHARS IN A PASSWORD*)
  vidleng = 16;              (*NUMBER OF CHARS IN A VOLUME NAME*)
  tidleng = 16;              (*NUMBER OF CHARS IN A FILE TITLE*)
  fidleng = 120;             (*NUMBER OF CHARS IN FILE NAME*)
  fblksize = 512;            (*STANDARD FILE BUFFER LENGTH*)
  maxsc=63;                  (*LARGEST SELECT CODE *)
  minlevel=1;                (*LOWEST INTERRUPT LEVEL*)
  maxlevel=6;                (*LARGEST MASKABLE INTERRUPT LEVEL*)
      
  
type  

  byte = 0..255; 
  shortint = mminint..mmaxint;  
  ipointer = ^integer;
  charptr = ^char;
  textpntr = ^text; 
  string80 = string[80];
  string255 = string[255];
  suffixtype = string[5];
  string255ptr = ^string255; 

                                                              
  unitnum = 0..maxunit; 
  vid = string[vidleng]; 
  tid = string[tidleng];
  fid = string[fidleng];
  passtype = string[passleng];

  filekind = (untypedfile,      {directory entry} 
              badfile,          {bad blocks}
              codefile,         {executable or linkable}
              textfile,         {UCSD format text with editor environment}
              asciifile,        {L.I.F. ASCII format text strings}
              datafile,         {file of  <data type, e.g. char, integer,etc.>}
              sysfile,          {system (BOOT) file}
     fkind7,  fkind8,  fkind9,  
     fkind10, fkind11, fkind12, 
     fkind13, fkind14, lastfkind);      {reserved for future expansion}

  
                                                           (*FILE INFORMATION*)

window = packed array [0..maxint] of char;
windowp = ^window;


fibp = ^fib;

amrequesttype = (readbytes, writebytes, flush, writeeol, readtoeol, clearunit, 
          setcursor, getcursor, startread, startwrite, unitstatus, seekeof); 
amtype = procedure (fp: fibp; request: amrequesttype; 
                           anyvar buffer: window; bufsize, position: integer); 
eotproc = procedure(fp: fibp); 

fib = packed record 
           fwindow: windowp;                         (*BUFFER VARIABLE...F^ *)
           flistptr: fibp;                            (* LIST OF OPEN FILES *)
       {declaration and type information}
           frecsize: integer;                 (* SIZE OF ONE LOGICAL RECORD *)
           feft: shortint;                            (* EXTERNAL FILE TYPE *)
           fkind: filekind;                                    (* FILE KIND *)
           fistextvar:  boolean;                  (* FILE IS LINE FORMATTED *)
           fbuffered:   boolean;               (* HAS 512 BYTE BLOCK BUFFER *)
           fanonymous: boolean;                         (* FILE HAS NO NAME *)
           fisnew:  boolean;                (* WAS CREATED THIS ASSOCIATION *)
           freadable, fwriteable: boolean;            (* FILE ACCESS RIGHTS *)
       {state information}
           freadmode, fbufvalid: boolean;         (*F^ AND LOOKAHEAD STATES *)
           feoln: boolean;                          (* F^ IS AN END OF LINE *) 
           feof: boolean;                 (* TRIED TO READ PAST END OF FILE *)
           fmodified: boolean;                     (* FILE HAS CHANGED SIZE *)
           fbufchanged: boolean;              (* BUFFER NEEDS TO BE WRITTEN *)
       {file size and position}
           fpos:  integer;           (* FILE POINTER, CURRENT FILE POSITION *)
           fleof: integer;         (*LOGICAL END OF FILE, CURRENT FILE SIZE *)
           fpeof: integer;        (*PHYSICAL END OF FILE, MAXIMUM FILE SIZE *)
       {buffering and low level formatting information}
           flastpos:  integer;                   (* FILE POSITION OF BUFFER *)
           freptcnt:  shortint;                  (* SPACE COMPRESSION COUNT *)
           am:  amtype;                              (*BUFFER METHOD MODULE *)
       {file association info}
           fstartaddress: integer;         (*EXECUTION ADDRESS IN BOOT FILE *)
           fvid: vid;                                        (* VOLUME NAME *)
           ffpw: passtype;                                 (* FILE PASSWORD *)
           ftid: tid;                                          (* FILE NAME *)
           pathid:  integer;     (* ADDITIONAL SYSTEM DEPENDENT INFORMATION *)
           fanonctr: shortint;                      (* TEMP FILE IDENTIFIER *)
           foptstring: string255ptr;               (* OPTIONAL STRING PARAM *)
       {byte block transfer information}
           fileid:  integer; (* START BYTE OF FILE, OR OTHER IDENTIFICATION *)
           fb0,fb1,                                 (* FOR FUTURE EXPANSION *)
           fnosrmtemp,                   (*TRUE IF NO SRM TEMP FILE CREATED *)
           fwaitonlock,                  (*TRUE IF SRM SHOULD WAIT FOR LOCK *)
           fpurgeoldlink,            (*TRUE IF OLD SRM LINK IS TO BE PURGED *)
           foverwritten,                    (*TRUE IF OPENED WITH OVERWRITE *)
           fsavepathid,               (*TRUE IF PATHID NOT UNIQUE TO FILEID *)
           flockable,                     (*TRUE IF FILE OPENED AS LOCKABLE *)
           flocked,                                (*TRUE IF FILE IS LOCKED *)
           fbusy        : boolean;               (*TRUE IF DRIVER IS ACTIVE *)
           funit        : unitnum;                   (*PHYSICAL UNIT NUMBER *)
           feot         : eotproc;         (*CALLED WHEN TRANSFER COMPLETES *)
           fxpos        : integer;                (* X POSITION FOR  GOTOXY *)
           fypos        : integer;                (* Y POSITION FOR  GOTOXY *)
           foldfileid   : integer;    (* FILEID FOR OLD SRM FILE ON REWRITE *)
       {for future expansion}
           fextra:  array[0..2] of integer;
           fextra2: shortint;
       {large miscellaneous fields sometimes present}
           case integer of 
             0: ( {minimal FIB ends here} );
             1: (ftitle:  fid);        (* FILE NAME, EXCEPT VOLUME AND SIZE *)
             2: (fbuffer: packed array [0..fblksize-1] of char); 
        end (*FIB*) ;


damrequesttype = (getvolumename, setvolumename, getvolumedate, setvolumedate,  
 changename, purgename, 
 openfile, createfile, overwritefile, closefile, purgefile,
 stretchit, makedirectory, crunch, opendirectory, closedirectory, catalog,
 stripname, setunitprefix, openvolume, duplicatelink, openparentdir,
 catpasswords,setpasswords,lockfile,unlockfile,openunit); 
  
damtype = procedure (anyvar f: fib; unum:unitnum; request: damrequesttype); 
  
unitentry =  {unitable entry definition}
    packed record
      dam: damtype;                     {directory access method}
      tm:  amtype;                      {byte block transfer method}
      sc: byte;                         {select code}
      ba: byte;                         {bus address} 
      du: byte;                         {disc unit}  
      dv: byte;                         {disc volume}
      byteoffset: integer;              {physical starting byte of volume} 
      devid: integer;                   {identifier (Amigo identify sequence)} 
      uvid: vid;                        {volume id}
      dvrtemp: integer;                 {temp for driver use only; init to 0!}
      dvrtemp2: shortint;               {temp for driver use only; init to 0!}
      letter: char;                     {device specifier letter}
      offline,                          {unit absent or down flag}
      uisinteractive,                   {user can edit input}
      umediavalid,                      {medium not changed since last access}
      uuppercase:   boolean;            {volume name must be uppercased}
      uisfixed: boolean;                {fixed/removeable media flag}
      ureportchange: boolean;           {driver mode: report/ignore media change}
      pad: 0..1;                        {   (bit not used yet)  }
      case uisblkd: boolean of          {blocked volume flag}
        true: (umaxbytes: integer)      {volume size in bytes }
    end;  {unitentry}
    
unitabletype = array [unitnum] of unitentry;                   (*0 NOT USED*)
amtabletype  = array[filekind] of amtype; 
suftabletype = array[filekind] of suffixtype; 
efttabletype = array[filekind] of shortint; 

unitableptr     = ^unitabletype;
amtableptrtype  = ^amtabletype; 
suftableptrtype = ^suftabletype; 
efttableptrtype = ^efttabletype; 
  
  
iorsltwd = 
            { *note* the ioresult enumerations have been partitioned into two
              mutually-exclusive groups: those beginning with 'z' are reserved
              for the low-level drivers , and those beginning
              with 'i' are reserved for the higher-level routines.}
             
             (inoerror,zbadblock,ibadunit,zbadmode,ztimeout,
              ilostunit,ilostfile,ibadtitle,inoroom,inounit,
              inofile,idupfile,inotclosed,inotopen,ibadformat,
              znosuchblk,znodevice,zinitfail,zprotected,
              zstrangei,zbadhardware,zcatchall,zbaddma,
              inotvalidsize,inotreadable,inotwriteable,inotdirect,
              idirfull,istrovfl,ibadclose,ieof,
              zuninitialized,znoblock,znotready,znomedium,
              inodirectory,ibadfiletype,ibadvalue,icantstretch,
              ibadrequest, inotlockable, ifilelocked, ifileunlocked, 
              idirnotempty, itoomanyopen, inoaccess, ibadpass, ifilenotdir, 
              inotondir, ineedtempdir, isrmcatchall, zmediumchanged,
              {end marker} endioerrs);
  
proctype=procedure;
sctype=0..maxsc;
leveltype=minlevel..maxlevel;
pisrib = ^isrib;
isrproctype = procedure(isribptr: pisrib);
isrib = {isr information block}
   packed record
     intregaddr: charptr;       {interrupt register address}
     intregmask: byte;          {interrupt register mask}
     intregvalue: byte;         {interrupt register target value after masking}
     chainflag: boolean;        {chaining flag}
     proc: isrproctype;         {isr}
     link: pisrib;              {pointer to next isrib in linked list}
   end;
 
inttabletype = array [1..7] of pisrib;

action = procedure; 

daterec         = packed record
                    year        : 0..100;       (*100 IS TEMP DISK FLAG*)
                    day         : 0..31;        (*DAY OF MONTH*)
                    month       : 0..12;        (*0 ==> DATE NOT MEANINGFUL*)
                  end; 

timerec         = packed record
                    hour        : 0..23;
                    minute      : 0..59;
                    centisecond : 0..5999;
                  end; 
  
datetimerec     = packed record
                    date        : daterec;
                    time        : timerec;
                  end;

var
(*========= MANY OF THE FOLLOWING HAVE HARDCODED
            ADDRESSES IN COMPILER AND ELSEWHERE  =====*)
       
(*** ERROR RECOVERY  ***)
  sysescapecode:        shortint; 
  openfileptr:  anyptr; 
  recoverblock: anyptr; 
  
(*** MEMORY MANAGEMENT ***)
  heapmax:      anyptr; 
  heapbase:     anyptr; 
  
(*** I/O DRIVERS ***)
  sysioresult:          integer; 
  hardwarestatus:       integer;
  locklevel:      integer; 
  unitable: unitableptr;
  interrupttable: inttabletype;
  endisrhook:  integer;
  actionspending: integer; 
  
(*** FILE SYSTEM ***)
  gfiles: array[0..5] of textpntr;    
  {  [0] INPUT          [3] (unused)
     [1] OUTPUT         [4] LISTING 
     [2] KEYBOARD       [5] (unused)   }
  
  amtable:     amtableptrtype;                  {pointer to access methods }
  suffixtable: suftableptrtype;                 {pointer to list of suffixes}
  efttable:    efttableptrtype;                 {pointer to LIF file types}
  sysunit: integer;
  syvid,dkvid: vid;                           (*SYSUNIT VOLID & DEFAULT VOLID*)
  syslibrary: fid; 
  
  (*** DEBUGGER HOOK ***)
  debugger: procedure(p1, p2, p3: integer); 
  
  (*** CLEAR I/O HOOK ***)
  cleariohook : procedure;    
  
  perminttable: inttabletype;
  
  deferredaction: array[1..10] of action; 
  
  serialtextamhook: amtype;             {access method for serial devices}
  
  sysname[-574]: packed array[1..10] of char; 
  
  sysflag[-302]: packed record
    reserved1, reserved2, nointhpib, crtconfigreg, 
    nokeyboard, highlightsxorbiggraphics, biggraphics,
    alpha50: boolean; 
    end; 

  sysflag2[hex('FFFFFEDA')]: packed record    {extend to 8 digits SFB 4/26/85}
                             pad7to1    : 0..127;
                             prompresent: boolean;
                           end;
                           
  endsysvars : shortint;   {must be last thing
                            in SYSGLOBALS}
  

end.

