/INKTRONIC OUTPUT
 .LOC 17000
    .SIZE
    .SIXBT 'LP'
    300002                  /OUTPUT
PRINT
    SNL; JMP* PRINT         /CLOSE ->
    SAD (40; JMP P2         /SPACE ->
    SAD .NL; SKP; JMP P1     /NOT NL ->
    LAC (12; JMS OUT        /LF
    LAC (15                 /CR
P1  TAD SC                  /ADD SPACE COUNT
    JMS OUT
    JMP P3
P2  LAW -400; TAD SC
    DAC SC; ISZ POS
P3  STL
    JMP* PRINT
OUT
    DZM SC
    DAC* A1
    SAD (15; DZM POS        /ZERO IF CR
    AND (140; SNA; JMP O1   /CONTROL ->
    LAW -120; TAD POS       /LINE FULL?
    SMA; JMP* OUT           /YES =>
    ISZ POS
O1  ISZ A1
    LAW -BUF; TAD A1        /WRAP ROUND
    SAD BS; DAC A1          /IF NECESSARY
    LAC IND                 /HANDLER ACTIVE?
    ISZ CHARS
    SMA!SZA; JMP O4         /YES ->
O2  SMA; JMP O3             /OK ->
    LAC LITLP
    GUARD; JMP .MH          /REPORT
O3  GUARD; JMP H            /ACTIVATE HANDLER
O4  GUARD
    LAW -BUF; TAD CHARS     /CHARS = LIMIT
    RAL; LAC IND            /& HANDLER ACTIVE?
    SNL!SMA!SZA; WAIT       /YES => WAIT
    ION
    SNL; JMP O2             /-> ACTIVATE
    JMP* OUT
/HANDLER
H   ACCEPT
    DZM IND; ISZ IND        /HANDLER ACTIVE
    ICEF                    /CLEAR ERROR FLAG
H1  CLC
    ISEF; SKP; JMP H9       /ERROR ->
    LAC* A2; SMA; JMP H2    /NO SPACES ->
    TAD (400; DAC* A2
    LAC (40; ICLP           /PRINT SPACE
    JMP H3
H2  ICLP
    CLC; TAD CHARS; DAC CHARS
    ISZ A2
    LAW -BUF; TAD A2        /WRAP ROUND
    SAD BS; DAC A2          /IF NECESSARY
H3  JMS .LP                 /WAIT FOR DEVICE
    ISDF; JMP .LP+3         /NOT LP ->
    LAC CHARS               /BUFF EMPTY?
    SZA; JMP H1             /NO ->
H9  DAC IND; ICDF
    JMP .LP+2
BUF=40
B0  .BLOCK BUF
LITLP .SIXBT 'LP'
BS  B0;A1 B0;A2 B0
IND;CHARS;POS;SC
GUARD=JMS 3;WAIT=JMP 2;ACCEPT=ISZ 3
.MH=16000;.LP=16010;.NL=16020
ISDF=706401;ICDF=706402;ICLP=706406
ISEF=706421;ICEF=706422
 .END
