
{  7/11/85  11:03   smlaser}

!!%include "sm:consts.inc"
!!%include "sm:utils.inc"

!LASER: Send to laser printer with new controller.

%externalroutine smlaser(%string(255) in)

%constinteger RT=13,XON=17, XOFF=19, ESC=27
%integer XOFFED=0, CURIN=0, K,KK, SENT

! Signetics Duart:-
%recordformat DUARTF (-
%byte pad0,   %byte MR12A {mode register             A  W&R},
(%byte pad2,  %byte SRA   {status register           A  R}-
%or%byte pd2, %byte CSRA) {clock select register     A  W},
%byte pad4,   %byte CRA   {command register          A  W},
(%byte pad6,  %byte RHRA  {RX holding register       A  R}-
%or%byte pd6, %byte THRA) {TX holding register       A  W},
(%byte pad8,  %byte IPCR  {input port change register   R}-
%or%byte pd8, %byte ACR)  {auxiliary control register   W},
(%byte padA,  %byte ISR   {interrupt status register    R}-
%or%byte pdA, %byte IMR)  {interrupt mask register      W},
(%byte padC,  %byte CTU   {counter/timer upper          R}-
%or%byte pdC, %byte CTUR) {counter/timer upper register W},
(%byte padE,  %byte CTL   {counter/timer lower          R}-
%or%byte pdE, %byte CTLR) {counter/timer lower register W},
%byte pad10,  %byte MR12B {                          B  W&R},
(%byte pad12, %byte SRB   {                          B  R}-
%or%byte pd12,%byte CSRB) {                          B  W},
%byte pad14,  %byte CRB   {                          B  W},
(%byte pad16, %byte RHRB  {                          B  R}-
%or%byte pd16,%byte THRB) {                          B  W},
%byte pad18,pad19,
(%byte pad1A, %byte INP   {input port                   R}-
%or%byte pd1A,%byte OPCR) {output port config reg       W},
(%byte pad1C, %byte STRCC {start counter command        R}-
%or%byte pd1C,%byte SOPBC){set output port bits command W},
(%byte pad1E, %byte STPCC {stop counter command         R}-
%or%byte pd1E,%byte ROPBC){reset output port bits command W})

@16_0007F440 %record(duartf) DUART

%constinteger RXRDY=1, TXRDY=4

%integerfn LASTPOS(%string(*)%name s,%integer k)
%integer i
  i=length(s)
  i=i-1 %while i > 0 %and charno(s,i)#k
  %result=i
%end

%routine OPEN(%string(255) name)
  %on %event 3,9 %start
    printstring(event_message);  newline
    select input(curin)
    %return
  %finish
  printstring("Opening ".name);  newline
  open input(curin+1,name)
  curin=curin+1;  select input(curin)
%end

%routine HANDLE INPUT
%integer insym
%cycle
  insym=duart_rhra&127
  %if insym=xon %start
    xoffed=0
    printstring("XON");  newline
  %else %if insym=xoff
    xoffed=1
    printstring("XOFF");  newline
  %else
    printsymbol(insym) %if insym >= ' ' %and insym#nl
  %finish
  %exit %if xoffed=0
  %cycle; %repeat %until duart_sra&rxrdy#0
%repeat
%end

%routine SEND SYM(%integer sym)
  handle input %while duart_sra&rxrdy#0;  !incoming char
  %cycle; %repeat %until duart_sra&txrdy#0
  duart_thrb=sym
%end

%routine SEND STRING(%string(255) s)
%integer sym,insym,i=0
  %while i < length(s) %cycle
    i=i+1
    handle input %while duart_sra&rxrdy#0;  !incoming char
    %cycle; %repeat %until duart_sra&txrdy#0
    duart_thrb=charno(s,i)
  %repeat
%end

%routine SEND FILE
%integer hold,sym,insym,last
%string(31) s

  %on %event 9 %start
    close input
    curin=curin-1
    select input(curin)
    %return %if curin=0
  %finish

  hold=0;  last=nl
  %cycle
    handle input %while duart_sra&rxrdy#0
    %if hold#0 %then sym=hold %and hold=0 -
    %else read symbol(sym)
    %if last=nl %and sym='$' %start
      handle input %while duart_sra&rxrdy#0
      %if nextsymbol='g' %start
        prompt("$G found: ")
        skip symbol
        %if nextsymbol=' ' %start
          prompt("'$G ' found: ")
          read symbol(sym) %until sym > ' '
          s=""
          prompt("Filename: ")
          %cycle
            s=s.tostring(sym)
            read symbol(sym)
          %repeat %until sym <= ' '
          open(s)
          %continue    ;!  This takes control to %cycle above.
        %finishelse hold='g'
      %finish
    %finish
    handle input %while duart_sra&rxrdy#0;  !incoming char
    %cycle; %repeat %until duart_sra&txrdy#0
    duart_thra=sym
    last=sym
  %repeat
%end

{Main sequence.}

%on %event 3,9,10 %start
  print string("Trap in Main Routine.".snl)
  newline %and %return %if event_event=9
  -> next
%finish

{reset MR pointer to address MR1}
  DUART_cra=16_10       
  DUART_MR12a=16_13     {no-parity, 8-bits}

{second access is to MR2}
  DUART_MR12a=16_07     {1.0 stop bits

  duart_acr=16_80       {clock}
  duart_csra=16_BB      {9600 baud RX & TX
  duart_cra=16_20;          !reset receiver
  duart_cra=16_40;          !reset error status
  duart_cra=16_05;          !enable TX & RX

next:
  curin=0
  open(in)
  %if curin > 0 %start
    send sym(1)
    send file
  %finish
  send sym(esc);  send sym('e')
  send sym('*');  send sym(nl)
%end

%endoffile
