!  File  NMOUSE:BUILD

%option "-nodiag-nocheck"
%include "inc:util.imp"
%begin
%string(255)in1="prefix.mob",in2="loader.mob",out="x"
%integer p1,p2,s1,s2,room
%constinteger base=16_1000,limit=16_3f00-6*64
  defineparam("Prefix",in1,0)
  defineparam("Loader",in2,0)
  defineparam("Image",out,pamnewgroup)
  processparameters(cliparam)
  connectfile(in1,0,p1,s1)
  connectfile(in2,0,p2,s2)
  room = limit-base-s1-s2
  %if half(p2)#16_fe02 %start
    printstring("Unexpected .MOB file type "); phex4(half(p2)); newline
    ->no
  %finish
  %if half(p2+6)#0 %start
    printstring("Warning: loader has external references"); newline
  %finish
  %if room<0 %start
    printstring("Image is "); phex4(-room); printstring(" bytes too long")
    newline; ->no
  %finish
  phex4(room); printstring(" spare bytes"); newline
  openoutput(1,out); selectoutput(1)
  s1 = s1-1 %and printsymbol(byte(p1)) %and p1 = p1+1 %while s1>0
  s2 = s2-1 %and printsymbol(byte(p2)) %and p2 = p2+1 %while s2>0
  %stop
no: printstring("No image file written"); newline
%end
