       NAM  STRUBIO
WARMS  EQU  $AD03
FMSCLS EQU  $B403
FMS    EQU  $B406
RPTERR EQU  $AD3F
PSTRNG EQU  $AD1E
GETFIL EQU  $AD2D
SETEXT EQU  $AD33
BUFPTR EQU  $AC14
FCBIN  EQU  $A840
LSTTRM EQU  $AC11
EOL    EQU  $AC02
GETCHR EQU  $AD15
PUTCHR EQU  $AD18
CR     EQU  $0D
       ENT  TABLES
       ENT  GETB
       ENT  OUTB
       ENT  INITIO
       ENT  REWIND
       ENT  OPENI
       ENT  OPENO
       ENT  CLOSI
       ENT  CLOSO
       ENT  MONTOR
       ENT  INEEE
       ENT  OUTEEE
       ENT  OUTLPT
*
*
OPENSW FCB  0
*
INEEE  JMP  GETCHR
OUTEEE EQU  *
OUTLPT JMP  PUTCHR
*
INIT   LDX  BUFPTR
       STX  SVPTR
       LDX  #FCBIN
       JSR  GETFIL
       BCS  ERROR1
       LDAA #1
       STAA 0,X
       JSR  SETEXT
       LDX  #FCBIN
       JSR  FMS
       BNE  ERROR2
       LDAA LSTTRM
       CMPA #CR
       BEQ  INIT2
       CMPA EOL
       BEQ  INIT2
       LDX  #FCBOUT
       JSR  GETFIL
       BCS  ERROR1
       BRA  INIT3
INIT2  LDX  SVPTR
       STX  BUFPTR
       LDX  #FCBOUT
       JSR  GETFIL
       CLR  12,X
INIT3  TST  12,X
       BNE  INIT4
       LDAA #'R
       STAA 12,X
       LDAA #'E
       STAA 13,X
       LDAA #'L
       STAA 14,X
INIT4  LDAA #$FF
       STAA OPENSW
       RTS
*
SVPTR  RMB  2
*
ERROR1 LDX  #ILST
ERR1A  JSR  PSTRNG
       BRA  EXIT
ERROR2 LDAA 1,X
       CMPA #3
       BEQ  ERROR3
       CMPA #4
       BEQ  ERROR4
       JSR  RPTERR
       BRA  EXIT
ERROR3 LDX  #FEST
       BRA  ERR1A
ERROR4 LDX  #NSST
       BRA  ERR1A
CLOSO  JMP  FMSCLS
EXIT   JSR  FMSCLS
MONTOR EQU *
       JMP  WARMS
*
NSST   FCC  'NO SUCH FILE'
       FCB  4
ILST   FCC  'ILLEGAL FILE NAME'
       FCB  4
FEST   FCC  'FILE EXISTS'
       FCB  4
FCBOUT RMB  320
*
GETB   EQU  *
       PSHB
       STX  SVX
       TST  OPENSW
       BNE  *+5
       JSR  INIT
       LDX  #FCBIN
       JSR  FMS
       BEQ  GETB2
       LDAA 1,X
       CMPA #8
       BEQ  GETEOF
       JSR  RPTERR
       JMP  WARMS
GETEOF SEC
       BRA  *+3
GETB2  CLC
       LDX  SVX
       PULB
       RTS
*
OUTB   STX  SVX
       PSHB
       LDX  #FCBOUT
       LDAB 2,X
       CMPB #2
       BEQ  OUTOP
       PSHA
       LDAB #2
       STAB 0,X
       JSR  FMS
       BEQ  OUTB2
       JMP  ERROR2
OUTB2  LDAA #$FF
       STAA 59,X
       PULA
OUTOP  JSR  FMS
       BEQ  OUTB9
       JMP  ERROR2
OUTB9  PULB
       LDX  SVX
       RTS
*
SVX    RMB  2
*
REWIND  EQU  *
       LDX  #FCBIN
       LDAA #5
       STAA 0,X
       JSR  FMS
       BEQ  *+5
       JMP  ERROR2
OPENI  EQU  *
OPENO  EQU  *
CLOSI  EQU  *
       RTS
INITIO JMP  INIT
*
*
TABLES FDB  *+2
*
       END  ASM
