include  "inc:util.imp"
option  "-low-nons-nocheck-nodiag"
begin ; !TRY: Load Software front panel and trial (CS3) operating system

externalroutinespec  connectfile(string (255)f,integer  m,integername  s,l)
string (255)panel="fmac:sfp",file=""
integer  sfps,sfpl,syss,sysl,p
recordformat  hf(half  magic,flags,export,import,integer  code,
                 half  reset,main,integer  static,stack,spare2,spare3)
recordformat  ef(short  flags,ptype,integer  type,disp,string (255)s)
record (hf)name  h
record (ef)name  e

  routine  copy(integer  from,to,size)
    *move.l d0,a0
    *move.l d1,a1
    *subq.l #1,d2
    *swap d2
a:  *swap d2
b:  *move.b (a0)+,(a1)+
    *dbra d2,b
    *swap d2
    *dbra d2,a
!   %cycle
!     integer(to) = integer(from)
!     to = to+4; from = from+4; size = size-4
!   %repeatuntil size<=0
  end 

  routine  catcher
    *move.w #16_700,(sp)
    *addq.l #4,2(sp)
    *rte
  end 

  defineparam("Program",file,pamnodefault)
  defineparam("SFP",panel,0)
  processparameters(cliparam)
  connectfile(file.".mob",0,syss,sysl)
  h == record(syss)
  if  h_magic#16_fe02 start 
    printstring(file.".mob is not a V2 object file"); newline; stop 
  finish 
  if  h_import#0 start 
    p = syss+sizeof(h)+h_export
    if  short(p)#0 start 
      printstring(file." has external references:"); newline
      cycle 
        e == record(p); p = p+sizeof(e)-256
        exitif  e_flags=0
        printstring(e_s); newline
        p = (p+length(e_s)+2)&¬1
      repeat 
      stop 
    finish 
  finish 
  connectfile(panel.".mob",0,sfps,sfpl)
!write(sysl,0); space; write(sfpl,0); newline

!* Interrupts off etc

@16_400100 byte  ptm1
@16_400102 byte  ptm2
  ptm2 = 1; ptm1 = 1;        !Clock off

@16_4000c1 byte  vdus
  vdus = 3;                  !Acia ints off

@16_7fffc byte  eths
integer  zero=0
  eths = zero;               !Ether ints off

  *lea catcher,a0;           !Acquire privilege
  *move.l a0,16_1020
  *mtsr #16_700;             !and raise IPL to 7.

  copy(sfps,16_1000,sfpl)
  copy(syss,16_800000,sysl)

  *stop #0;                  !Invoke loaded SFP
endofprogram