! Mouse system include file

%option "-low-nons"

%recordformat queue fm {Common header for all kernel objects} -
  (%byte lock,*,%short tag, %record(*)%name queue, forward, backward, owner)

%recordformat semaphore fm -
  (%record(queue fm)header, %integer counter)

%recordformat mailbox fm -
  (%record(queue fm)header, %record(semaphore fm)%name semaphore)

%recordformat run queue fm -
  (%record(queue fm)header, %bytename tickler)

%constinteger max message size = 2020   {these two add
%constinteger message header size = 28  {up to 2048

%recordformat message fm -
  (%record(queue fm)header, %record(mailbox fm)%name reply, %integer size,
   %bytearray data(1:max message size))

%recordformat process fm -
  (%bytearray supervisor stack(-1024:-1) %or-
   %record(queue fm)header,
   %record(run queue fm)%name run queue,
   %integer vbr, ssp, cputime, starttime,
            priority, time slice size, time slice left,
   (%byte asn %or %record(*)%name pti {address space number/page table index}),
   %integer ownbase,ownlimit,stackbase,stacklimit,
   %string(63)name)

%recordformat interrupt handler fm -
  (%record(queue fm)header %or-
   %integer pc,*,%record(*)%name forward, backward)

%recordformat object fm {mailbox or sempahore - dynamically allocated} -
  ((%record(queue fm)header,%integer param) %or-
   %record(run queue fm)run queue %or-
   %record(semaphore fm)semaphore %or-
   %record(mailbox fm)mailbox,
   %string(31)name)

%constinteger object pool  size =   64
%constinteger message pool size =   32

@16_11c0 -
%record(process fm)%name current process,
%record(object fm)%arrayname object pool(0:object pool size-1),
%record(message fm)%arrayname message pool(0:message pool size-1),
%integer global code limit, system elapsed time, idle time,
%integer interrupted priority, next object, next message,
%record(semaphore fm)%name message semaphore,
%record(run queue fm)%namearray run queue(0 {lowest prio} : 7 {highest prio}),
%record(processfm)%name rivalprocess,
%record(interrupt handler fm)%array int chain(1:7)

@16_3ff0 %integer freebot,freetop,membot,memtop

! Loader/Imp specific stuff

%recordformat fe02 object fm -
  (%short flags,extra,%integer type,offset,%string(255)name)
%recordformat fe02 header fm -
  (%half tyver,flags,export,import,%integer codesize,%half reset,main,
   %integer ownsize,stack,%half dlim,chlim,spare1,spare2)
%recordformat fe02 indir fm -
  (%integer address %or -
   %half op1, %integer opd1, %half op2, %integer opd2)
%recordformat mar fm {combined file connection and module activation record} -
  (%record(mar fm)%name next,
   (%integer start %or %record(fe02 header fm)%name header),
   %integer size,gla,
   %string(255)name)

%recordformatspec fcb fm
%recordformat poa fm(%bytearray b(1:1024) %or-
  %integer evlink,%integerarray display(1:7),
  %byte event,sub,%short line,%integer extra,%string(255-32)message,
  %integer eventpc,%integerarray eventdisplay(1:7),eventregs(0:15),
  %integer scratch1,scratch2,*{excepth},%record(marfm)%name filelist,
  %integer heapbase,stacklimit,
  %record(fcb fm)%name curin,curout,
  %integer instream,outstream,
  %%record(fcb fm)%namearray in,out(0:7),
  %string(255)cliparam)
  
%register(a5)%record(poa fm)%name poa

! Procedures provided in EPROM

@16_408 %integerfn romreadfile(%string(255)file,%integer where) {booting only}
@16_40c %routine romphex(%integer x)
@16_410 %routine romphex4(%integer x)
@16_414 %routine romphex2(%integer x)
@16_418 %routine romphex1(%integer x)
@16_41c %routine rompsym(%integer x)
@16_420 %routine rompstr(%string(255)s)

! Procedures defined in SUPER

%systemroutinespec return from interrupt
%systemroutinespec wait for interrupt
%systemroutinespec add interrupt handler(%integer level)
%systemroutinespec int signal semaphore(%record(semaphore fm)%name s)
%externalroutinespec become process(%integer space)        {booting only}

%systemroutinespec move to sr(%integer x)
%systemintegerfnspec or to sr(%integer x)

%systemintegerfnspec cpu time
%systemintegerfnspec elapsed time

%systemintegerfnspec priority
%systemintegerfnspec privilege
%systemintegerfnspec time slice size

%systemroutinespec set priority(%integer prio)
%systemroutinespec set privilege(%integer onoff)
%systemroutinespec set time slice size(%integer ticks)

%externalrecord(process fm)%mapspec create subprocess(%integer size,pc)

%systemroutinespec signal semaphore(%record(semaphore fm)%name s)
%systemroutinespec semaphore wait(%record(semaphore fm)%name s)

%systemrecord(semaphore fm)%mapspec create semaphore(%string(255)id,%integer c)
%systemrecord(semaphore fm)%mapspec lookup semaphore(%string(255)id)
%systemroutinespec delete semaphore(%record(semaphorefm)%name s)
%systempredicatespec valid semaphore(%record(semaphorefm)%name s)
%systemrecord(mailbox fm)%mapspec create mailbox(%string(255)id,%record(semaphore fm)%name s)
%systemrecord(mailbox fm)%mapspec lookup mailbox(%string(255)id)
%systemroutinespec delete mailbox(%record(mailboxfm)%name m)
%systempredicatespec valid mailbox(%record(mailboxfm)%name m)

%systemrecord(message fm)%mapspec get message buffer
%systemroutinespec put message buffer(%record(message fm)%name m)
%systemroutinespec put message(%record(message fm)%name m,%record(mailbox fm)%name b)
%systemrecord(message fm)%mapspec get message (%record(mailbox fm)%name mailbox)
%systemroutinespec send message(%record(message fm)%name m,%record(mailbox fm)%name b)
%systemrecord(message fm)%mapspec receive message (%record(mailbox fm)%name mailbox)

%systemroutinespec setup queue (%record(queue fm)%name queue)
%systempredicatespec queue empty(%record(queue fm)%name queue)
%systemroutinespec enqueue(%record(queue fm)%name cell,queue)
%systemroutinespec requeue(%record(queue fm)%name cell,queue)
%systemrecord(*)%mapspec dequeue(%record(queue fm)%name queue)
%systemrecord(*)%mapspec unqueue(%record(queue fm)%name queue)
%systemroutinespec exqueue(%record(queue fm)%name cell)
%systemroutinespec inqueue(%record(queue fm)%name c,l,r)

%systemintegerfnspec freestore
@(16_3f00-6*20)%integerfn heapget(%integer x)
%systemroutinespec heapput(%integer pos)
%systemstring(*)%mapspec newstring(%string(*)%name s)
%systemrecord(fcb fm)%mapspec new fcb(%string(*)%name f)

%systemroutinespec move(%integer bytes,%name from,to)

! clock

%externalroutinespec submit timer request -
  (%record(semaphorefm)%name s,%integer id,when)
%externalroutinespec submit regular timer request -
  (%record(semaphorefm)%name s,%integer id,interval)
%externalroutinespec cancel timer request(%integer id)
%externalroutinespec cancel all timer requests
%externalroutinespec wait(%integer ms)

! hex

%systemroutinespec phex1(%integer x)
%systemroutinespec phex2(%integer x)
%systemroutinespec phex4(%integer x)
%systemroutinespec phex(%integer x)
%systemintegerfnspec rhex

! names

%externalroutinespec define local logical name(%string(255)key,info)
%externalroutinespec define global logical name(%string(255)key,info)
%externalroutinespec define logical name(%string(255)key,info)
%externalroutinespec next local logical name(%string(*)%name key,info)
%externalroutinespec next global logical name(%string(*)%name key,info)
%externalpredicatespec translated local logical name(%string(*)%name s)
%externalpredicatespec translated global logical name(%string(*)%name s)
%externalpredicatespec translated logical name(%string(*)%name s)
%externalstring(255)%fnspec translate logical name(%string(255)name)

%externalroutinespec define local command symbol(%string(255)key,info)
%externalroutinespec define global command symbol(%string(255)key,info)
%externalroutinespec define command symbol(%string(255)key,info)
%externalroutinespec next local command symbol(%string(*)%name key,info)
%externalroutinespec next global command symbol(%string(*)%name key,info)
%externalpredicatespec translated local command symbol(%string(*)%name s)
%externalpredicatespec translated global command symbol(%string(*)%name s)
%externalpredicatespec translated command symbol(%string(*)%name s)
%externalstring(255)%fnspec translate command symbol(%string(255)name)

%externalroutinespec standardise filename(%string(*)%name s)

! io

%recordformat fcb fm -
  (%integer p,l,bs,bl,fs,fl,fastpc,gla,pc,mode,
   %record(fcb fm)%name next,%string(255)%name prompt,
   %integer a,b,c,d,%string(255)filename)

%constinteger -
  cbop close   = 0,
  cbop abort   = 1,
  cbop flush   = 2,
  cbop refresh = 3,
  cbop write   = 4,
  cbop read    = 5

%constinteger -
  fop logout  = 0,
  fop login   = 1,
  fop quote   = 2,
  fop pass    = 3,
  fop openi   = 4,
  fop openo   = 5,
  fop openm   = 6,
  fop opena   = 7,
  fop credir  = 8,
  fop delete  = 9,
  fop info    = 10,
  fop rename  = 11,
  fop copy    = 12,
  fop permit  = 13,
  fop stamp   = 14,
  fop time    = 15

