!  File  MOUSE:CRESP

%option "-low-nons-nocheck-nodiag"
%include "mouse.inc"
%include "poa.inc"

%integerfn heapget(%integer n)
@16_3f00-6*20 %integerfn heapget(%integer n)
  n = heapget(n); byte(n-4) = 1; %result = n
%end

%systemroutine delete subprocess(%record(pcbfm)%name victim)
%record(*)%name q
%record(semaphorefm)%name s
%record(poafm)%name itspoa
%integer sr
  sr = or to sr(16_700)
  victim == currentprocess %if victim==nil
  q == victim_queue; exqueue(victim); s == q
  s_counter = s_counter+1 %unless q==victim_target
  itspoa == record(victim_process own area)
  dispose(record(itspoa_heapbase))
  dispose(itspoa)
  dispose(victim)
  semaphorewait(nil) %if currentprocess==victim
  sr = movetosr(sr)
%end

%systemrecord(pcbfm)%map create subprocess(%integer size,pc,%string(63)name)
%record(pcbfm)%name me,it
%record(poafm)%name mypoa,itspoa
%recordformat wspfm(%integer h1,h2,h3,h4)
%record(wspfm)%name wsphdr
%integer wsp,i
  %routine pushh(%integer n)
    it_supervisor stack pointer = it_supervisor stack pointer-2
    half(it_supervisor stack pointer) = n&65535
  %end
  %routine push(%integer n)
    pushh(n;n>>16)
  %end
  me == currentprocess
  mypoa == poa
  it == new(it)
  itspoa == new(itspoa)
  size = (size+1023)>>10<<10
  wsp = heapget(size); wsphdr == record(wsp)
  it = me; it_program name = name; it_owner == me
  it_process own area = addr(itspoa)
  it_supervisor stack pointer = addr(it)+sizeof(it)
  itspoa = mypoa
  itspoa_evlink = 0
  wsphdr_h1 = 1<<24+16
  wsphdr_h2 = 0
  wsphdr_h3 = wsp+16
  wsphdr_h4 = 0
  itspoa_heapbase = wsp
  itspoa_stacklimit = wsp+16+256
  it_current message buffer == nil
  it_attention mailbox == nil
  it_cputime = 0
  pushh(0); push(pc); pushh(0)
  push(a4;a1;a0;d1;d0)
  push(a6;it_processownarea;wsp+size;a3;a2;d7;d6;d5;d4;d3;d2)
  i = ortosr(16_700)
  enqueue(it,it_target)
  i = movetosr(i)
  %result == it
%end

%endoffile
