;
; Program: SETFILE
; Author: Richard Conn
; Version: 1.0
; Date: 5 Mar 84
;
version equ     10

;
;       SETFILE defines the name of a ZCPR3 File Name or displays it.
;

;
; Equates for Key Values
;
z3env   SET     0f400h  ;address of ZCPR3 environment
fnum    equ     5ch+1   ;file number in 1st FCB
fcb     equ     6ch     ;2nd FCB
cr      equ     0dh
lf      equ     0ah

;
; External Z3LIB and SYSLIB Routines
;
       ext     z3init,getfn1,print,pfn1,moveb,qprint,cout

;
; Environment Definition
;
       if      z3env ne 0
;
; External ZCPR3 Environment Descriptor
;
       jmp     start
       db      'Z3ENV' ;This is a ZCPR3 Utility
       db      1       ;External Environment Descriptor
z3eadr:
       dw      z3env
start:
       lhld    z3eadr  ;pt to ZCPR3 environment
;
       else
;
; Internal ZCPR3 Environment Descriptor
;
       MACLIB  Z3BASE.LIB
       MACLIB  SYSENV.LIB
z3eadr:
       jmp     start
       SYSENV
start:
       lxi     h,z3eadr        ;pt to ZCPR3 environment
       endif

;
; Start of Program -- Initialize ZCPR3 Environment and Print Banner
;
       call    z3init  ;initialize the ZCPR3 Environment
       call    qprint
       db      'SETFILE, Version '
       db      (version/10)+'0','.',(version mod 10)+'0',cr,lf,0
;
; Check Number of File
;
       lxi     h,0             ;init count
       lxi     d,11            ;size of each file name
       lda     fnum            ;get number
       sui     '0'             ;convert to binary
       jc      error
       jz      error
       cpi     5               ;range?
       jc      selfile
;
; Print Error Message
;
error:
       call    print
       db      ' Invalid File Name Number (not 1-4)',0
       ret
;
; Set Name of File
;
selfile:
       dad     d               ;compute offset from file name 1
       dcr     a               ;count down
       jnz     selfile
       xchg                    ;DE contains offset
       call    getfn1          ;get ptr to shell file name
       dad     d               ;get ptr to file name selected
       lxi     d,fcb+1         ;pt to name in FCB
       xchg                    ;copy from FCB
       mvi     b,11            ;11 bytes
       mov     a,m             ;get first char
       cpi     ' '             ;don't define if no name
       cnz     moveb           ;define name if name given
;
; Print Name of Shell Variable File
;
       call    print
       db      ' File Name ',0
       lda     fnum            ;get number
       call    cout            ;print it
       call    print
       db      ' is ',0
       jmp     pfn1

       end