! Transfer file to or from DMAK RS232 port A

%begin
%include "inc:util.imp-nolist"
%option"-nolist"
! 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})
%option "-list"
%option "-low"
@16_0007F440 %record(duartf) DUART

%string(255)in="",out=""
%integer zero=0
%integer baudset=0,baudcode=11

%integerfn get
  %cycle
    %signal 9 %if testsymbol>=0
  %repeatuntil duart_sra&1#0
  %result = duart_rhra
%end

%routine put(%integer k)
  %cycle
  %repeatuntil duart_sra&4#0
  duart_thra = k
%end

%onevent 9 %start
  %stop
%finish

defineparam("In",in,0)
defineparam("Out",out,pamnewgroup)
defineintparam("Baudset",baudset,0)
defineintparam("Baudcode",baudcode,0)
processparameters(cliparam)
baudcode = baudcode&15; baudset = baudset&1

printstring("Watch for 1307:")
duart_cra   = 16_10
duart_mr12a = 16_13
duart_cra   = 16_10; phex2(duart_mr12a)
duart_mr12a = 16_07; phex2(duart_mr12a); newline
duart_imr   = zero
duart_acr   = 16_60+baudset<<7
duart_opcr  = 16_01
duart_csra  = baudcode*17
duart_cra   = 16_05

%if (in="" %and out="") %or (in#"" %and out#"") %start
  printstring("Please supply input or output file")
  printstring(", not both") %unless in=""
  printsymbol('.'); newline; %stop
%finish
openinput(1,in)
openoutput(1,out)
%if in="" %start
  %cycle
    printsymbol(get)
  %repeat
%else
  %cycle
    put(readsymbol)
  %repeat
%finish

%endofprogram
