/#ED# FILE INPUT

	PAGE  /--------------------------

/ OS/8 USER SERVICE ROUTINE DEFS
USR=7700
FETCH=1
LOOKUP=2
ENTER=3
CLOSE=4

/ FIND FILE
FFILE,	0
	JMS GETFIL		/ GET FILENAME
	JMP I FFILE

	JMS CLRBUF		/ GOT ONE, CLEAR BUFFER
	JMP I FFILE		/ USER ABORTED SAVE OFFER

	JMS SETFN		/ ACTIVE FILENAME = ENTERED NAME

	TAD (FILEEN		/ LOOKUP FILE
	JMS LUFILE
	JMP FFNEW

	JMS INSFIL		/ EXISTS, INSERT
	JMP FFERR
FFILEA,	DCA CHANGD		/ SET BUFFER NOT CHANGED
	JMS GOBEG		/ BEGINNING OF FILE
	HLT
	ISZ FFILE
	JMP I FFILE

FFNEW,	JMS CLRMLT		/ FILE NOT FOUND, NEW ONE
	TAD (NEWMSG
	JMS WR6
	WRMLT
	ISZ MLHOLD
	JMP FFILEA

FFERR,	JMS CLRFN		/ ERROR (BUFFER FULL) DON'T LET
	JMP I FFILE		/ USER ACCIDENTALLY WRITE PARTIAL FILE

NEWMSG,	TEXT /NEW FILE/

/ INSERT FILE AT POINT
INFILE,	0
	JMS GETFIL		/ GET FILENAME
	JMP I INFILE
	TAD (FILEEN		/ LOOK FOR IT
	JMS LUFILE
	JMP INFLN
	JMS INSFIL		/ INSERT
	SKP
	ISZ INFILE
	JMP I INFILE

INFLN,	TAD (NFMSG		/ FILE MUST BE FOUND
	JMS WR6
	WRMLT
	ISZ MLHOLD
	JMP I INFILE
NFMSG,	TEXT / NOT FOUND/

/ CLEAR BUFFER, SKIP IF NOT QUIT
CLRBUF,	0
	JMS OFFER
	JMP I CLRBUF
	ISZ CLRBUF
	
	TAD BUF
	DCA GAP
	TAD BUF+1
	DCA GAP+1
	TAD BUFEND
	DCA POINT
	TAD BUFEND+1
	DCA POINT+1
	JMP I CLRBUF

/ SKIP IF GETFCH IS ALPHANUMERIC
SKIPAN,	0
	TAD GETFCH
	TAD (-60		/ NUMERIC?
	SPA CLA
	JMP SKNAB
	TAD GETFCH
	TAD (-72
	SPA CLA
	JMP SKANA

SKNAB,	TAD GETFCH		/ NO, ALPHA?
	TAD (-101
	SPA CLA
	JMP I SKIPAN
	TAD GETFCH
	TAD (-133
	SPA CLA

SKANA,	ISZ SKIPAN
	JMP I SKIPAN

/ INSERT ONE CHAR, SKIP IF NOT ^Z AND THE CHAR FITS. IGNORE LF
INSF1,	0
	TAD (-32		/ ^Z?
	SNA
	JMP I INSF1
	TAD (32-LF		/ LF?
	SNA
	JMP INSF1A
	TAD [LF
	JMS INSERT		/ OK TO INSERT
	JMP INSF1B
INSF1A,	ISZ INSF1
	JMP I INSF1
INSF1B,	ISZ MOREOK
	JMP I INSF1

MOREOK,	0			/ BUFFER FULL, MORE TO READ

/ CLEAR ACTIVE FILENAME
CLRFN,	0
	DCA FILENM
	DCA FILENM+3
	JMP I CLRFN

/ SKIP IF THERE IS AN ACTIVE FILENAME
HAVEFN,	0
	TAD FILENM
	SZA CLA
	ISZ HAVEFN
	JMP I HAVEFN

	PAGE  /--------------------------

/ INSERT PREVIOUSLY LOOKED UP FILE AT POINT, SKIP IF OK
INSFIL,	0
	TAD FILLOC
	DCA FILBLK
	DCA MOREOK
	
INSFA,	JMS I DEVEP		/ NEXT BLOCK
	200
FILBUF,	IOBUF
FILBLK,	0
	JMP INSFER
	ISZ FILBLK		/ UPDATE BLOCK NUMBER

	TAD (-200		/ PROCESS CHARACTERS
	DCA INSFN
	TAD FILBUF
	DCA INSFP

INSFC,	TAD I INSFP		/ CHAR 1
	AND (177
	JMS INSF1
	JMP INSFB

	TAD I INSFP		/ SAVE HIGH NIBBLE OF CHAR 3
	AND (3400
	LSR; 3
	DCA INSFT

	ISZ INSFP		/ CHAR 2
	TAD I INSFP
	AND (177
	JMS INSF1
	JMP INSFB

	TAD I INSFP		/ CHAR 3
	LSR; 7
	TAD INSFT
	JMS INSF1
	JMP INSFB

	ISZ INSFP
	ISZ INSFN
	JMP INSFC
	ISZ FILSIZ
	JMP INSFA

INSFB,	TAD [POINT		/ DISTINGUISH EOF FROM BUFFER FULL
	MQL 			/ EOF SKIPS, BUFFER FULL DOESN'T
	TAD [GAP
	JMS SNE15
	SKP
	ISZ INSFIL
	JMP I INSFIL
	
INSFER,	SMA CLA			/ I/O ERROR, SHOW MESSAGE
	TAD (INSE2-INSE1	/ SHOUDN'T GET NON-FATAL
	TAD (INSE1
	JMS WR6
	WRMLT
	ISZ MLHOLD
	JMP I INSFIL

INSE1,	TEXT /FATAL ERR/
INSE2,	TEXT /EOF?/		/ SHOULD BE IMPOSSIBLE, BUT ...

INSFP,	0
INSFN,	0
INSFT,	0

/ LOOKUP FILE, AC->NAME, SKIP IF FOUND
LUFILE,	0
	DCA FILLOC
	TAD DEVNUM
	CIF 10
	JMS I (USR
	LOOKUP
FILLOC,	0
FILSIZ,	0
	SKP
	ISZ LUFILE
	JMP I LUFILE

/ INITIALIZE FILE I/O, SKIP IF OK
IOINIT,	0
	CIF 10			/ FETCH DISK HANDLER
 	JMS I (USR
	FETCH
DEVNUM=.+1
	DEVICE DSK
DEVEP,	7201
	JMP I IOINIT
	ISZ IOINIT
	JMP I IOINIT

/ CONVERT CHAR IN AC TO UPPER CASE, A LITTLE TOO AGRESSIVELY SINCE
/ THE SYMBOLS >= 140 ARE ALSO AFFECTED
UPPER,	0
	TAD (-140
	SPA
	TAD (40
	TAD (100
	JMP I UPPER

/ CONVERT GETFCH TO UPPER CASE
CVUP,	0
	TAD GETFCH
	JMS UPPER
	DCA GETFCH
	JMP I CVUP

	PAGE  /--------------------------

/ GET FILE NAME, SKIP IF NOT QUIT
GETFIL,	0
GETFR,	JMS CLRMLT		/ PROMPT IN MODE LINE TEXT (MLT)
	TAD (GFMSG
	JMS WR6
	WRMLT
	JMS UPDATE

	DCA FILEEN		/ CLEAR NAME TO BE ENTERED
	DCA FILEEN+1
	DCA FILEEN+2
	DCA FILEEN+3
	TAD (FILEEN

	DCA FILEP		/ SEE COMMENTS BELOW
	DCA FILEX
	DCA FILEH

GETFA,	JMS RDTTY		/ READ NEXT CHAR
	DCA GETFCH
	TAD GETFCH		/ QUIT?
	TAD (-BELL
	SNA CLA
	JMP I GETFIL
	
GETFE,	TAD GETFCH
	TAD (-CR		/ END OF ENTRY?
	SNA CLA
	JMP GETFB

	TAD GETFCH		/ ERASE?
	TAD (-10
	SNA CLA
	JMP GETFR

	TAD GETFCH		/ DOT?
	TAD (-56
	SZA CLA
	JMP GETFD

	TAD FILEX		/ YES DOT, IN EXTENSION MODE?
	SZA CLA
	JMP GETFER
	TAD FILEEN		/ NO, ANY NAME CHARACTERS?
	SNA CLA
	JMP GETFER
	ISZ FILEX		/ YES, OK TO SWITCH TO EXTENSION MODE
	TAD (FILEEN+3
	DCA FILEP
	DCA FILEH
	JMP GETFC

GETFD,	TAD FILEX		/ NOT DOT, TOO MANY CHARACTERS?
	SZA CLA
	JMP .+3
	TAD FILEEN+2
	SKP
	TAD FILEEN+3	
	AND (77
	SZA CLA
	JMP GETFER

	JMS CVUP		/ CONVERT TO UPPERCASE
	JMS SKIPAN		/ ALPHANUMERIC?
	JMP GETFER
	TAD FILEH		/ CHAR OK, INSERT IN FILENAME
	SZA CLA
	JMP GETFG
	
	MQL			/ LEFT HALF
	TAD GETFCH
	SHL; 5
	DCA I FILEP
	ISZ FILEH
	JMP GETFC

GETFG,	TAD GETFCH		/ RIGHT HALF
	AND (77			
	TAD I FILEP
	DCA I FILEP
	DCA FILEH
	ISZ FILEP

GETFC,	TAD GETFCH
	JMS WRMLT
	JMS UPDATE
	JMP GETFA

GETFER,	TAD (BELL		/ ERROR, IGNORE CHARACTER
	JMS WRTTY
	JMP GETFA

GETFB,	TAD FILEEN		/ GOT CR, ANY NAME ENTERED?
	SNA CLA
	JMP GETFER

	
	ISZ GETFIL
	JMP I GETFIL

/ MAKE ENTERED FILENAME CURRENT
SETFN,	0
	TAD FILEEN
	DCA FILENM
	TAD FILEEN+1
	DCA FILENM+1
	TAD FILEEN+2
	DCA FILENM+2
	TAD FILEEN+3
	DCA FILENM+3
	JMP I SETFN

GFMSG,	TEXT /FILE: /
GETFCH,	0			/ CHARACTER BEING ENTERED
FILEP,	0			/ POINTER INTO FILEEN
FILEX,	0			/ NON-ZERO IF WORKING ON FILE EXTENSION
FILEH,	0			/ NON-ZERO IF INSERTING INTO RIGHT HALF
FILEEN,	ZBLOCK 4		/ ENTER NEW NAME HERE

FILENM,	ZBLOCK 5		/ FILE OF CURRENT BUFFER, DISPLAYED IN MODE LINE
	       			/ ONE EXTRA FOR RMODE
