;
;   PFK.LIT	06/17/87 NEW	ED SCHRAYER
;
;		Modified from RDONLY by Irv Bromberg
;
;		Donated to AMUS from NY-AMUS 06/17/87
;		   
; PURPOSE : PFK will determine the correct function key translation file
;		for the desired terminal and, if not already in user
;		memory, will load the module.
;
; USAGE : 1>	The translation file (Driver-name.PFK) file must permanently
;		reside on DSK0:1,4 (SYS:)
;
;	  2>    a) From the terminal type 'PFK'
;
;			OR
;
;		b) During the force commands in the .INI file just add
;		   the line  'PFK'
;
;			for example :   FORCE JOB3
;					MEMORY 64K
;					LOG 2,2
;					SET DSKERR
;		>> ADD HERE >>>>>	PFK
;					LOG DSK3:60,0
;					RUN MENU
;
;					WAIT JOB3
;
	OBJNAM PFK.LIT

	RADIX 10
	VMAJOR=1
	VMINOR=0
	VEDIT=0

	SEARCH SYS
	SEARCH SYSSYM
	SEARCH TRM


	JCB=A0
	TDV=A2
	DDB=A3
	Module=A4
	TCB=A5
	Atemp=A6

	TDVNAM=D0
	Size=D1

        PHDR    -1,0,PH$REE!PH$REU

        MOV     JOBCUR,JCB
        MOV     JOBTRM(JCB),TCB         ; get user's TCB
        MOV     T.TDV(TCB),TDV          ; get user's TDV
        MOV     -4(TDV),TDVNAM          ; get user's TDVNAM
        LEA     DDB,JOBRBK(JCB)         ; use JOBRBK as temp DDB
        MOV     TDVNAM,D.FIL(DDB)       ; look for MEM:TDVNAM.PFK first
        MOVW    #[PFK],D.EXT(DDB)       ;
        SRCH    D.FIL(DDB),Module,F.USR ; search MEM: only
        BNE     Disk                    ; not found, get from disk
	TYPESP	<? module>		; found, notify user and exit
	PFILE	@DDB
	TYPECR	< already exists in memory.>
        EXIT                            ; all done
;
;TDVNAM.PFK must be loaded from disk so fetch SYS:TDVNAM.PFK
;
Disk:   MOVW    #[DSK],D.DEV(DDB)       ; [DSK]
        CLRW    D.DRV(DDB)              ; drive #0
        CLR     D.DVR(DDB)              ; make monitor get the driver
        MOVW    #1_8!4,D.PPN(DDB)       ; [1,4]
        MOV     TDVNAM,D.FIL(DDB)	; use tdvnam as file name
        FETCH   @DDB,Module,F.USR       ; fetch but search MEM: only
        BEQ     OK			; was fetch successful? yes.
        TYPE    <? >                    ; .PFK file was not found
        PFILE   @DDB			; on DSK0:[1,4]
        TYPECR  < not found>		; notify user and exit
        EXIT				; 

OK:     ORW     #FIL,-8(Module)         ; prevent EXIT from deleting it
	TYPESP	< module>		; notify user and exit
	PFILE	@DDB
	TYPECR	< loaded into memory.>
        EXIT

        END