!!! Program to drive printer directly for doing special printing jobs
!  especially sticky labels

%begin
%include "sysinc:parmfm.inc"

%constinteger  bufflen = 1024
%constinteger  lp demon = 111
%integer  outbuff, obp
%record(parmfm) p
%integer  k,sym,n

%routine  abort(%string(63)  message)
   print string("Failed - ".message); newline
   %signal 15,15
%end

%routine  claim system buffer
%record(Parmfm)  p
   svc(110,p)
   %if p_p1 < 0 %start
      abort("can't get printer buffer")
   %finish
   outbuff = p_p1<<16
%end

%routine  release system buffer
%record(parmfm)  p
   p_p1 = outbuff>>16;  svc(9,p)
%end

%routine  put block
%record(parmfm)  p
   p_p1 = outbuff;  p_p2 = obp - outbuff
   p_sact = 13; svc(lp demon,p)
   p_sact = 13;  svc(16,p);   ! poff
   obp = outbuff
%end

%routine put(%integer  sym)
   byte integer(obp) = sym;  obp = obp+1
   put block %if obp = outbuff + bufflen
%end

%routine  skip
   skip symbol %while next symbol # nl
   skip symbol
%end

   %on %event 9 %start
      put block
      release system buffer
      print string("*SPECIALP complete - restart spooler!!!!".SNL)
      %stop
   %finish

   select input(0);  select output(0)
   claim system buffer
   print symbol(7) %for k = 1,1,100
   print string("
      *** Have you 'STOP' ed  the printer spooler ???????

")
   prompt("Test lines=");  read(n)
   skip
   prompt("O.K. ? ")
   select input(1)
   k = 0;  obp = outbuff
   %cycle
      %cycle
         read symbol(sym)
         put(sym)
         %exit %if sym&127 = nl
      %repeat
      k = k+1
      %if k = n %start
         put block
         select input(0)
         read symbol(sym); skip
         select input(1)
         %if 'Y' # sym&127 # 'y' %start
            reset input;  k = 0
         %finish
      %finish
   %repeat
%endofprogram
