* Background Selectric Driver - Interrupt Driven
* Programmer Ronald G. Parsons
* Execute this program after loading program
*    to be run concurrently.  The concurrent
*    program must NOT access the disk while
*    this program is still running!
* This program exits to SOLOS for
*    initiation of the other task.
* ESCAPE exits while getting file name.
 COPY NPTDEFS
 XEQ START
SOUT EQU 0C019H
PERSE EQU 0C0D5H
 ORG 0C900H
START DI .  disable interrupts
 CALL PERSE  clear screen
 MVI A,0C3H  JMP op code
 STA 38H  Store JUMP for RST 7
 LXI H,INTEN
 SHLD 39H
 LXI H,MES1
 CALL OUTM  print message
PMESG LXI H,MES2
 CALL OUTM
 CALL GETFN  get filename
 JC PMESG  error
 LXI D,FNAME  point to filename
 LXI H,0  static buffer
 CALL SYS  open file
 DB OPEOP
 JMP ERROR  error
 STA FLNBR  save file number
 LHLD SYSGLO
 LXI D,GLIF1
 DAD D  point to interrupt flag
 MVI M,1  turn it on
 MVI C,13  CR to Selectric
 CALL SELEC
 EI .  Enable interrupts
 JMP 0C004H  jump to SOLOS
*   
INTEN EQU $  interrupt entry point -----
 PUSH PSW
 PUSH B
 PUSH D
 PUSH H
 LDA NREPS  Any repeating chars?
 ORA A
 JNZ REPN  yes
 LDA FLNBR  get file number
 CALL RB  get byte
 JMP CKEOF  eof?
 MOV C,A
REPN CALL SELEC  print byte
 EI .  enable interrupts
GOBACK POP H
 POP D
 POP B
 POP PSW
 RET
*   
CKEOF CPI EREOF  eof?
 JNZ ERROR  no
 CALL CLEAN
 LDA FLNBR  get file number
 CALL SYS  close file
 DB CLOOP
 JMP ERROR
 JMP GOBACK
*   
CLEAN DI .  disable interrupts
 LHLD SYSGLO
 LXI D,GLIF1
 DAD D  point to flag
 MVI M,0  turn it off
 RET
*   
OUTM MOV A,M  message printer
 INX H
 ORA A
 RZ .  zero byte at end
 MOV B,A
 CALL SOUT
 JMP OUTM
*   
GETFN MVI C,11  Get file name
 LXI H,FNAME  point to filename
FNLOP CALL CONIN  get character
 CPI 1BH  escape?
 JZ LEAVE
 MOV B,A
 CALL SOUT  echo it
 MOV A,B
 CPI 13  CR?
 JZ FNEND  end of name
 MOV M,A  save character
 INX H
 DCR C
 JNZ FNLOP  more
 LXI H,MES3  name too long
 CALL OUTM
 STC .  set CY
 RET
*   
FNEND XRA A  zero A
 MOV M,A  mark end of filename
 RET
*   
ERROR STA ERCODE  store error code
 CALL CLEAN
 MVI A,82H
 LXI H,MES1
 CALL UTIL
 DB UXOP
 JMP LEAVE
 DB -1
ERCODE DB -1
LEAVE CALL SYS
 DB SREOP
*   
MES1 DB 13
 ASC 'Background Selectric Driver'
 DB 0
*   
MES2 DDB 0A0DH
 ASC 'Enter File Name: '
 DB 0
*   
MES3 DDB 0A0DH
 ASC 'Name too long.'
 DB 0
*   
FLNBR DB 0
FNAME DS 11
*   
* Selectric (R) interface to Sol (TM)
* Version 1.7  11/23/77
* Version for interrupt driven program
* Programmer Ronald G. Parsons
* Call SELEC with character in C
*   
OCASE DB 0  Temp store for old case
REPCHR DB 0  Temp store for repeat char
NREPS DB 0  Temp store for # repetitions
PSP   EQU 0FAH   Parallel status port
PDP   EQU 0FDH   Parallel data port
* Entry point
SELEC EQU $
     LDA NREPS  Any chars to be repeated?
     ORA A
     JZ SEL1  no
     DCR A
     STA NREPS
     LDA REPCHR  get char to be repeated
     MOV C,A
     JMP SEND
SEL1 CALL TRANS  Translate ASCII to bail codes
     JNC DONE  Error in character
     LXI H,OCASE  Validate OCASE
     MOV A,M   Get old case
     ANI 7FH   Any garbage?
     JZ ISOL   No
     MVI M,0   Zero old case
ISOL MOV A,C
     ANI 80H  Isolate case bit
     CMP M  Compare to old case
     JZ SEND   Same
     CALL STAT  Wait until ready
     MOV A,C
     ORI 7FH  Retain case bit
     OUT PDP  Latch new case
     ANI 80H
     MOV M,A  Save case bit
     MVI A,1
     STA NREPS  Set for one repetition
     MOV A,C
     STA REPCHR  Store char to be printed
     JMP DONE
SEND CALL STAT  Wait until ready
     MOV A,C
     OUT PDP  Send character
     CPI 07EH  Was it return?
     JZ DELRET  yes
     CPI 06FH  Was it a tab?
     JNZ DONE  no
DELRET MVI A,10  Delay for return or tab
     STA NREPS
     MVI A,07FH  Set l.c. character
     STA REPCHR
DONE RET
*   
* Waits until Selectric is ready
*   
STAT EQU $
     IN PSP  Get PXDR
     ANI 4  Test bit 2
     JNZ STAT
     RET
*   
* Translation routine from ASCII to bail codes
* CY set if legal character
*   
TRANS MOV A,C
     ANI 7FH   Drop sign bit
     MOV C,A
     LXI H,TABL  Prepare for offset
     MVI B,0
     DAD B     Offset to table
     MOV C,M
     MOV A,C
     CPI 0FFH  Illegal character
     RET
*   
* Translation table
*   
TABL DB 0FFH
 NLST
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 077H   bksp
     DB 06FH   tab
     DB 07BH   line feed  ???? temp. space
     DB 07DH   vtab (index)
     DB 0FFH
     DB 07EH   return
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 0FFH
     DB 07BH   space
     DB 028H   !
     DB 0AAH   "
     DB 081H   #
     DB 086H   $
     DB 08AH   %
     DB 082H   &
     DB 02AH   '
     DB 08FH   (
     DB 08EH   )
     DB 083H   *
     DB 0B9H   +
     DB 033H   ,
     DB 03FH   -
     DB 029H   .
     DB 036H   /
     DB 00EH   0
     DB 016H   1
     DB 009H   2
     DB 001H   3
     DB 006H   4
     DB 00AH   5
     DB 00BH   6
     DB 002H   7
     DB 003H   8
     DB 00FH   9
     DB 0B2H   :
     DB 032H   ;
     DB 07BH
     DB 039H   =
     DB 07BH
     DB 0B6H   ?
     DB 089H   @
     DB 0A3H   A
     DB 09FH   B
     DB 093H   C
     DB 092H   D
     DB 09AH   E
     DB 0B1H   F
     DB 0B0H   G
     DB 09EH   H
     DB 0ABH   I
     DB 0B8H   J
     DB 09BH   K
     DB 096H   L
     DB 0A0H   M
     DB 099H   N
     DB 0A6H   O
     DB 0BAH   P
     DB 0BBH   Q
     DB 0A2H   R
     DB 0AEH   S
     DB 098H   T
     DB 091H   U
     DB 0A1H   V
     DB 0AFH   W
     DB 090H   X
     DB 0BEH   Y
     DB 088H   Z
     DB 080H   [
     DB 07BH
     DB 000H   ]
     DB 07BH
     DB 0BFH   _
     DB 07BH
     DB 023H   a
     DB 01FH   b
     DB 013H   c
     DB 012H   d
     DB 01AH   e
     DB 031H   f
     DB 030H   g
     DB 01EH   h
     DB 02BH   i
     DB 038H   j
     DB 01BH   k
     DB 016H   l
     DB 020H   m
     DB 019H   n
     DB 026H   o
     DB 03AH   p
     DB 03BH   q
     DB 022H   r
     DB 02EH   s
     DB 018H   t
     DB 011H   u
     DB 021H   v
     DB 02FH   w
     DB 010H   x
     DB 03EH   y
     DB 008H   z
     DB 07BH
     DB 08BH   cent sign
     DB 07BH
     DB 0A8H   degree sign
     LST
ENDT DB 077H   del
* End of table
*   

