Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-06 - 43,50362/io.mac
There are 60 other files named io.mac in the archive. Click here to see a list.
	SUBTTL	IOLIB PARAMETERS AND MACROS

	IFNDEF	%.C,<XLIST>

VCODE==2		;HOMEGROWN
VMAJOR==5		;MAJOR VERSION
VMINOR==0		;MINOR VERSION
VEDIT==153		;EDIT NUMBER

;DEFINE %.C TO LIST FILE
;DEFINE %.C==-1 TO ASSEMBLE IO IN BOTH PASSES
;DEFINE %.C==-2 TO ALSO INCLUDE END STATEMENT
;DEFINE %.C==-3 TO MAKE IO A UNIVERSAL FILE
;DETERMINE IF SPECIAL ASSEMBLY NEEDED

IF1,<%..C==1	;ALWAYS ASSEMBLE PASS1
IFDEF %.C,<IFE %.C+2,<TITLE IO -- LISTING OF IO.MAC (IOLIB PARAMETER FILE)>
		IFE %.C+3,<UNIVERSAL IO -- IOLIB PARAMETER UNIVERSAL SYMBOL TABLE
		IFNDEF %%C,<SEARCH C>
				PASS2>>>
IF2,<IFNDEF %.C,<%.C==0
	IFDEF $$IOL,<%.C==-1>>	;SUPPLY VALUE IF USER DIDN'T
     %..C==%.C	;USE USER'S VALUE FOR PASS2>


	LIST
	SALL		;CLEAN EXPANSION LISTINGS
IFE %..C,<TAPE>	;SKIP REST IF NO ASSEMBLY NEEDED


$$IOMJ==VMAJOR
$$IO==<BYTE (3)VCODE (9)VMAJOR (6)VMINOR (18)VEDIT>

	PURGE	VCODE,VMAJOR,VMINOR,VEDIT
	SUBTTL	REVISION HISTORY

COMMENT !
 
REVISIONS MAKING UP VERSION 5 OF IO:
 
134	ADD SYMBOLS $BFSTS, $BFHDR AND $BFCNT EQUAL TO THE '.' SYMBOLS
	OF THE SAME NAME IN C.MAC V:6. THE PROBLEM IS THAT THE DEFINITION
	CHANGED BETWEEN V:6 AND V:7 THEREBY FOULING IOLIB (AND ANYONE
	ELSE USING THEM).
 
135	CORRECT DEFINITION OF THE XTUUO$, XTCAL$ AND XTDCL$ MACROS

136	add new macros WBwrd$, wcwrd$, wwwrd$

137	CHANGE FW$$S TO REMOVE A 'V' ERROR INTRODUCED BY MACRO V:50
	AND MY USAGE OF THE MOVX MACRO FROM C.MAC.

140	CHANGE MAKFD$ TO REMOVE A 'V' ERROR INTRODUCED BY MACRO V:50.
	THE SPEC. IS CHANGED SLIGHTLY SO THAT IF THE ACTUAL PARAMETER
	FOR THE ADR FIELD IS IN THE AC RANGE (0-17) IT IS
	NOW TREATED AS A NORMAL ADDRESS

141	ADD APEND$ AND APDWT$ MACROS

142	CORRECT UPDWT$ DEFINITION SO THAT IT MAY TAKE A T1 ARGUMENT

143	ADD NEW FIELDS TO THE FDB: ADD A PATH SPECIFICATION BLOCK
	AND A PATH MASK BLOCK, REMOVING THE OLD DIRECTORY MASK WORD:
	ADD AN EXTRA WORD TO THE BUFFER HEADERS: RESTRUCTURE BLOCK
	TO USE WASTED WORDS FOR 2 FUNCTIONS: ADD WORDS FOR /ABEFORE
	AND /ASINCE (SEE SCAN)

144	CHANGE DEFINITIONS OF MAKFD$ AND FDESC$ TO USE PATH SPEC.
	IN FDB

145	RESTRUCTURE IDB DEFINITIONS AND INCLUDE 2 NEW FIELDS:
		$IDJPT		JOB'S PATH SPEC.
		$IDCPU		CPU TYPE (CP$KAX=0
					  CP$KIX=1)

146	ADD A PRINTX TO THE VERSN$ MACRO TO TELL USER WHAT VERSIONS
	OF C.MAC AND IO.MAC ARE BEING USED IN THIS ASSEMBLY

147	GET RID OF FT$KIX

150	ADD A NEW ERROR MACRO ADVIS$ THAT TAKES THE SAME ARGUMENTS
	AS FATAL$ AND WARN$, BUT PTINTS ITS MESSAGE ENCLOSED WITHIN
	[], E.G. [DELAMB AMBIGUOUS FILESPEC.: MYPROG]
	REDEFINE EC$XXX SYMBOLS TO MAKE WAY FOR EC$FLG, A SEVEN BIT
	ASCII SEVERITY CHARACTER - ? - % - [ E.G.

151	ADD MACROS TO CALL ROUTINES TO PERFORM THE MT???. UUOS
	THAT CALL MTAPE

152	alter BEGIN$ so that it always generates 5 instructions that
	fixup CCL entry and PORTALs, and call a new routine $BEGIN.
	make a debugging label, $$BEG, on the first user instruction.

153	move $IDPPN within the IDB to help $INIID

!
COMMENT ;

THIS REVISION HISTORY BEGINS AT EDIT 120: HALFWAY THROUGH VERSION 4

120	ADD A NEW FLAG TO $FDCHN:
		FC$CSC (1B4)	CHANNEL SET BY CALLER

121	ADD ARGUMENT TO BEGIN$ MACRO  TO SPECIFY 3 CHARACTER NAME OF
	TEMPCORE FILE

122	ADD TWO WORDS TO IDB:
		$IDJNO		JOB NUMBER (RH): 3 CHARACTER JOB NUMBER (LH)
		$IDJPP		JOB PPN

123	ADD TWO NEW OPDEFS FOR LOADING AC(D):
		LDFD$	ADDRESS		:MOVE  D,ADDRESS
		LDFDI$	ADDRESS		:MOVEI D,ADDRESS

124	CORRECT MX$ MACRO AND SLEEP$ MACRO

125	ADD NEW MACROS, XTCAL$, XTDCL$, CNVUI$, CNVIU$, CNVNU$

126	FIX WCHAR$ MACRO TO HANDLE 'WCHAR$  ","' CORRECTLY

127	CHANGE NAMES OF SWITCH TABLES GENERATED BY SWTAB$ MACRO TO
	INCLUDE '$' SYMBOL

130	ADD NEW SYMBOL $ECTER FOR ERROR CODE (I.E. CODE OUT OF RANGE)
 
131	ALTER THE RSWIT$ MACRO, SO THAT IT ONLY CALLS 1 ENTRY POINT

132	ADD ARGUMENT TO RLEAS$ MACRO TO INDICATE NOT
	TO DELETE BUFFER RINGS.

133	MACROS TO CALL $SAVET AND $RESTT

;
COMMENT ;
PREFACE TO VERSION 4.
VERSION 4 IS A REWRITE TO
1.  COMPLEMENT IOL4
2.  REMOVE SERIOUS DEFICIENCIES IN VERSION 3
3.  EXTEND THE RANGE OF MACROS AND OPDEFS AVAILABLE
;

COMMENT ;
IO CONTAINS:

1.  DEFINITIONS OF SYMBOLS NEEDED BY PROGRAMMERS USING THE IOLIB
    LIBRARY OF SUBROUTINES

2.  DEFINITIONS OF OPDEFS USEFUL TO PROGRAMMERS USING IOLIB

3.  ESSENTIAL MACROS FOR IOLIB USERS (BEGIN$)

4.  USEFUL MACROS FOR IOLIB USERS
;


COMMENT ;
IO SYMBOL NAMING CONVENTIONS:

IO FOLLOWS THE PATTERN ESTABLISHED BY DEC IN THE PARAMETER FILE C.MAC

DEC USES THE SPECIAL CHARACTERS '.' AND '%' IN ALL SYMBOLS IN C.MAC
TO SHOW THAT THE SYMBOL HAS A SPECIAL SIGNIFICANCE.
DEC HAS RESERVED THE CHARACTER '$' FOR CUSTOMER USE, SO IO USES THAT
CHARACTER IN THE SAME WAY THAT DEC USES '.' AND '%'.

	PATTERN		USE

	$GGSSS		NUMBER OF GENERAL CATEGORY 'GG', SPECIFIC USE 'SSS'
	GG$SSS		BYTE OF GENERAL CATEGORY 'GG', SPECIFIC USE 'SSS'
	MMMMM$		MACRO, OPDEF, UUO OR SPECIAL ERROR SYMBOL 

E.G.
	$FDXXX		WORD IN THE FILE DESCRIPTOR BLOCK
	FC$XXX		BIT IN THE FILE DESCRIPTOR CHANNEL WORD
	FATAL$		FATAL ERROR REPORTING MACRO
	ERIMP$		IMPROPER MODE IO ERROR
;


	SUBTTL	FEATURE TEST SWITCHES

	ND	FT$DBG,0		;-1 INVOKES DEBUG FEATURES

	ND	FT$SFD,6		;NONZERO IS NUMBER OF DIRECTORY LEVELS
	 
;[147]	ND	FT$KIX,-1		;0 FOR KA10, NONZERO FOR KI10

	ND	FT$CCL,0		;NONZERO FOR CCL ENTRY POINT

	ND	FT$2SG,0		;NONZERO FOR TWO SEGMENTS

	ND	FT$ALC,-1		;NONZERO FOR DYNAMIC CORE ALLOCATION
	SUBTTL	ACCUMULATOR DEFINITIONS

;  5 TEMPORARIES

	T0=0		;UNUSED BY IOLIB. ALSO DEFINED AS F (FLAG)
	T1=1		;4 DESTROYED BY IOLIB ROUTINES
	T2=2		; EXCEPT FOR THE BASIC IO
	T3=3		; MODULE.
	T4=4		;

; 4 PRESERVED

	P1=5		;4 PRESERVED BY ALL IOLIB ROUTINES
	P2=6		; AND SHOULD BE PRESERVED BY ALL
	P3=7		; USER SUBROUTINES BEFORE USING
	P4=10		; THEM.

; 7 GLOBALS

	G1=11		;4 TOTALLY UNUSED BY THE IOLIB SYSTEM
	G2=12		; AND FREE FOR USE BY THE USER IN ANY WAY
	G3=13		; HE WISHES
	G4=14		;
	G5=15		;ALSO DEFINED AS D, AND HEAVILY USED BY IOLIB IO
	G6=16		;ALSO DEFINED AS L AND I. USED BY IOLIB
	G7=17		;ALMOST INVARIABLY THE GENERAL STACK POINTER

; REDEFINE 4 ACS FOR SPECIAL PURPOSES
  
	F=0		;FLAG AC (SINCE NON-INDEX)
	D=15		;FILE DESCRIPTOR BLOCK POINTER
	I=16		;IOLIB DATA BLOCK POINTER
	L=16		;LINK AC FOR DEC STANDARD S/R CALLING SEQUENCE
	P=17		;PUSH-DOWN STACK POINTER

COMMENT ;
THE CONFLICT BETWEEN I AND L MUST BE RESOLVED BY THE USER OF IOLIB.
IOLIB ROUTINES DO NOT USE THE L=LINK CONVENTION AND SOME EXPECT
THAT A POINT TO THE IOLIB DATA BLOCK IS IN AC(I).  USER ROUTINES
USING L AS A LINK MUST BE CAREFUL TO SETUP I BEFORE CALLING ANY IOLIB
ROUTINE.

D, I AND P ARE LOADED BY THE BEGIN$ MACRO
;


	SUBTTL	FILE DESCRIPTOR BLOCK

	LOC	0

$FDFPT:	BLOCK	1		;FORWARD POINT FOR LINKING CHAINS OF FDBS
$FDCHN:	BLOCK	1		;STATUS BITS (0-12) CHANNEL NUMBER (27-30)
	FC$OPN==1B0		;OPEN UUO DONE
	FC$LUK==1B1		;LOOKUP UUO DONE
	FC$ENT==1B2		;ENTER UUO DONE
	FC$TCI==1B3		;INPUT IS FROM TEMPCORE
	FC$CSC==1B4		;CHANNEL SET BY CALLER
	FC$CHN==17B30		;CHANNEL NUMBER
$FDTYP:	BLOCK	1		;DEVTYP UUO WORD
$FDNBK:	BLOCK	1		;LAST BLOCK NUMBER,,THIS BLOCK NUMBER
$FDBUF:	BLOCK	1		;NUMBER OF BUFFERS,,BUFFER SIZE
$FDIOW:	BLOCK	1		;POINT TO IOWD BLOCK OR NEXT BUFFER
$FDOPN:			;3 WORD OPEN BLOCK
$FDSTS:	BLOCK	1		;CHANNEL STATUS
$FDDEV:	BLOCK	1		;DEVICE NAME IN SIXBIT
$FDBHD:	BLOCK	1		;BUFFER HEADER POINTERS
$FDPTH:	BLOCK	FT$SFD+3	;PATH SPECIFICATION BLOCK
$FDOBH:	BLOCK	4		;OUTPUT BUFFER HEADER (INCL. MPX)
$FDIBH:	BLOCK	4		;INPUT BUFFER HEADER (INCL. MPX)
$FDMOD:	BLOCK	1		;MODIFIER WORD
$FDMOM:	BLOCK	1		;MODIFIER MASK
$FDBFR:	BLOCK	1		;/BEFORE
$FDSNC:	BLOCK	1		;/SINCE
$FDABF:	BLOCK	1		;/ABEFORE
$FDASN:	BLOCK	1		;/ASINCE
$FDRIB:			;RIB BLOCK (TO .RBVER)
$FDCNT:	BLOCK	1		;COUNT OF WORDS FOLLOWING
$FDPPN:	BLOCK	1		;POINT TO $FDPTH
$FDNAM:	BLOCK	1		;FILE NAME IN SIXBIT
$FDEXT:	BLOCK	1		;EXTENSION IN SIXBIT
$FDPRV:	BLOCK	1		;PRIVILEDGE WORD
$FDSIZ:	BLOCK	1		;FILE SIZE
$FDVER:	BLOCK	1		;VERSION NUMBER
$LNFDB==.-$FDFPT		;LENGTH
$ENFDB==$LNFDB-1		;END

COMMENT ;
SYMBOLS FOR ELEMENTS OF AN EXTENDED FDB TO ACCOMODATE THE REST OF
AN EXTENDED RIB ARE NOT DEFINED WITH $FDXXX SYMBOLS. THE USER
MAY DEFINE HIS OWN, OR REFER TO THE RELATIVE TO $FDRIB USING
.RBXXX SYMBOLS.

SEE OVER FOR FURTHER FDB DEFINITIONS......../
;


;  DEFINITIONS OF BYTES IN THE MODIFIER WORD

	FM$NDV==1B0		;NULL DEVICE SPEC.
	FM$NUL==1B1		;NULL EXTENSION
	FM$DIR==1B2		;DIRECTORY SPEC.
	FM$PHY==1B3		;/PHYSICAL
	FM$NOM==1B4		;/OKNONE
	FM$DFX==1B5		;WILD FIXUP UNNEC. FOR DIRECTORY
	FM$ADD==1B6		;SPEC. TERMINATED BY '+' (OBSOLETE)
	FM$TRM==7B8		;CODE FOR SPEC. TERMINATOR
		$FMTRA==1	;& - AND
		$FMTRO==2	;! - OR
		$FMTRN==3	;- - NOT
		$FMTRC==4	;+ - CONCATENATION
	FM$STR==1B9		;/STRS
	FM$PAR==1B24		;/PARITY
	FM$DEN==3B26		;/DENSITY
	FM$PRO==777B35		;/PROTECTION

;  MASKS USED IN WILD CARD DECODING.
;  THESE SYMBOLS FALL IN THE BUFFER HEADERS AND WILL BE OVRWRITTEN
;  AS SOON AS IO IS PERFORMED WITH THESE FDB'S.  USERS ARE NOT
;  RECOMMENDED TO ATTEMPT IO WITH WILD FILES!

	LOC	$FDPTH

	BLOCK	2
$FDPPP:	BLOCK	1		;PATH PPN
$FDSFD:	BLOCK	FT$SFD		;PATH SFD NAMES IN SIXBIT

	LOC	$FDOBH

$FDPTM:	BLOCK	FT$SFD		;PATH MASK (SHARED WITH $FDXBH)
$FDNMM:	BLOCK	1		;NAME MASK


;  BITS RETURNED BY $RFILE IN AC(T2) TO SHOW SOME FACTS ABOUT
;  THE INPUT FILENAME

	FF$NUL==1B0		;NO FILENAME
	FF$WLD==1B1		;SOME PART OF THE FILENAME WAS WILD
	SUBTTL	IOLIB DATA BLOCK DEFINITIONS

	LOC	0

$IDDYC:	BLOCK	1		;POINT TO CHAIN OF CORE CHUNKS ON HEAP
$IDTOP:	BLOCK	1		;USER DEFINED LIMIT TO LOW CORE USAGE

$IDLAC:	BLOCK	1		;LOOKAHEAD CHARACTER (COMMAND SCANNER)
$IDCPC:	BLOCK	1		;COMMAND COROUTINE PC
$IDLSC:	BLOCK	1		;LAST CHARACTER READ (COMMAND SCANNER)
$IDNXC:	BLOCK	1		;NEXT CHARACTER TO BE READ (COMMAND SCANNER)

$IDPNM:	BLOCK	1		;PROGRAM NAME
$IDPPN:	BLOCK	1		;program ppn
$IDPEX:	BLOCK	1		;PROGRAM LOW EXTENSION
$IDPDV:	BLOCK	1		;PROGRAM DEVICE

$IDIFD:	BLOCK	1		;COMMAND INPUT FDB POINT
$IDOFD:	BLOCK	1		;LOG OUTPUT FDB POINTER
$IDEFD:	BLOCK	1		;ERROR MESSAGE FDB

$IDCCL:	BLOCK	1		;CCL ENTRY POINT FLAG
$IDSWT:	BLOCK	1		;POINT TO TABLE OF USER SWITCH TABLES
$IDRUN:	BLOCK	1		;RUNOFFSET,,RUN FDB
$IDECD:	BLOCK	1		;ERROR CODE IN SIXBIT
$IDHNM:	BLOCK	1		;FILE NAME FOR HELP
$IDDFD:	BLOCK	1		;FDB HOLDING DEFAULTS FOR FILENAME DECODING

$IDJNO:	BLOCK	1		;[122] JOB NUMBER (SIXBIT),,JOB NUMBER
$IDJPP:	BLOCK	1		;[122] JOB PPN
$IDJPT:	BLOCK	FT$SFD+3	;[145] JOB'S PATH SPEC.
$IDCPU:	BLOCK	1		;[145] CPU WE ARE RUNNING ON

$LNIDB==.-$IDDYC		;LENGTH OF FDB
$ENIDB==$LNIDB-1		;END OF IDB
	SUBTTL	CHARACTER DEFINITIONS

COMMENT ;
C.MAC DEFINES ALL THE SYMBOLS FOR THE ASCII CHARACTERS AS .CHXXX
THESE SYMBOLS DEFINE CHARACTERS DUMMIED UP BY THE CHARACTER
READING ROUTINES TO SHOW THE VARIOUS FLAVOURS OF ENDLINE. THEY
CAN BE WRITTEN BY THE $WFCHA (WRITE A FUNNY CHARACTER) ROUTINE.
;

	$CHALX==0		;ALL FLAVOURS OF ESCAPE OR ALTMODE
	$CHEOL==-1		;ENDLINE
	$CHEOF==-2		;ENDFILE


COMMENT !

REDEFINE SYMBOLS FOR 3 WORD HEADER OF BUFFERS TO CONFORM TO THE
C V:6 STANDARD, BUT MAKE IO INDEPENDANT OF V:6 OR V:7.

!

	$BFSTS==-1		;STATUS WORD
	$BFHDR==0		;POINT TO NEXT BUFFER
	$BFCNT==1		;3RD WORD (SOMEWHAT DEVICE DEPENDANT)
	SUBTTL	ERROR CODES FOR IO ERRORS UNDEFINED BY DEC

;  CODE DEFINING WHICH UUO HAD THE IO ERROR

	UUUUO$==0		;UNDEFINED UUO
	UUOPN$==1		;OPEN
	UUENT$==2		;ENTER
	UULUK$==3		;LOOKUP
	UUREN$==4		;RENAME
	UUINP$==5		;INPUT
	UUOUT$==6		;OUTPUT
	UURUN$==7		;RUN
	UUGET$==10		;GETSEG
	UUCLO$==11		;CLOSE
	UUTMP$==12		;TMPCOR

;  ADDITIONAL IO ERROR CODES PRODUCED BY $OPEN, $INPUT, $OUTPUT

	EREOF$==-1		;ENDFILE (COULD BE AN ERROR)
	ERBKT$==-2		;BLOCK TOO LARGE
	ERDTE$==-3		;DATA ERROR
	ERDER$==-4		;DEVICE ERROR
	ERIMP$==-5		;IMPROPER MODE
	ERQTA$==-6		;NO ROOM OR QUOTA EXCEEDED
	ERRSD$==-7		;RESTRICTED DEVICE
	ERNFC$==-10		;NO FREE IO SOFTWARE CHANNEL
	ERUNK$==-11		;UNKNOWN ERROR CODE

;  FIELDS IN LH(T1) ON CALL TO $ERROR

	EC$IND==1B0		;[150] RH(T1) POINTS TO POINT
	EC$UUO==1B1		;[150] AC(T3) CONTAINS UUO NAME
				;[150] BITS 2,3,4 ARE FREE AND RESERVED
	EC$FLG==177B11		;[150] SEVERITY FLAG CHARACTER IN ASCII
	EC$TYP==77B17		;[150] VALUE TYPE CODE
		$ECTER==0	;[130] ERROR
		$ECTNO==0	;NONE
		$ECTCH==1	;CHARACTER
		$ECTDE==2	;DECIMAL
		$ECTFI==3	;FILE
		$ECTOC==4	;OCTAL
		$ECTTE==5	;TEXT
		$ECTWO==6	;WORD

	SUBTTL	SWITCH TABLE INDEX NAMES

;  THERE ARE 4 TABLES ASSOCIATED WITH SWITCHES AND A BLOCK
;  OF 4 WORDS USED TO POINT TO THESE TABLES. THESE SYMBOLS DEFINE
;  INDICES WITHIN THE 4 WORD BLOCK

	$STNAM==0		;IOWD TO TABLE OF SWITCH NAMES
	$STPNT==1		;P1,,POINT TO TABLE OF BYTE POINTERS
	$STMAX==2		;P1,,POINT TO TABLE OF MAX,,PROC
				; OR IOWDS TO KEYWORD TABLES
	$STDFT==3		;P1,,POINT TO TABLE OF FLAGS,,DEFAULTS
	SUBTTL	SOME USEFUL OPDEFS

; OK, SOME PEOPLE USE JUMPA

	OPDEF	PJUMPA	[JRST]

; SET THE CURRENT FDB POINTER TO STANDARD FDBS

	OPDEF	CMDFD$	[MOVE	D,$IDIFD(I)]
	OPDEF	MSGFD$	[MOVE	D,$IDOFD(I)]
	OPDEF	ERRFD$	[MOVE	D,$IDEFD(I)]
	OPDEF	TRMFD$	[MOVEI	D,0]
	OPDEF	LDFD$	[MOVE	D,]		;[123] ADDRESS OF FDB
	OPDEF	LDFDI$	[MOVEI	D,]		;[123] ADDRESS OF FDB IMMEDIATE
	SUBTTL	MACROS TO CALL BASIC IO ROUTINES

;MACRO TO DEFINE A CALL TO AN IOLIB ROUTINE AND TO MAKE THE
;SYMBOL INTERNAL OR EXTERNAL ACCORDING TO WHETHER IT IS DEFINED IN
;THIS MODULE OR NOT

DEFINE MM$$(SYM),<
IF2,<IFNDEF $'SYM,<EXTERN $'SYM>>
	PUSHJ	P,$'SYM>

;MACRO TO DEFINE A CALL TO ONE OF TWO IOLIB ROUTINES DEPENDING ON
;WHETHER AN ARGUMENT WAS SUPPLIED.  THE TWO ROUTINES ARE NORMALLY
;DIFFERENT ENTRY POINTS TO THE SAME ROUTINE.
;IF THE ARGUMENT IS OTHER THAN 'T1', THE ARGUMENT IS LOADED FROM
;THE GIVEN ADDRESS INTO T1.

DEFINE MR$$(ADR,SYM1,SYM2),<
IFB <ADR>,<
	MM$$	SYM1>
IFNB <ADR>,<
	IFN <<ADR>-T1>,<
	MOVE	T1,<ADR>>
	MM$$	SYM2>>
;  MACROS TO CALL THE FORMATTED WRITE ROUTINES

DEFINE WCHAR$(CHR,X),<
IFNB <X>,<
	MOVEI	T1,",">
IFB <X>,<
	IFNB <CHR>,<
	MOVEI	T1,CHR>>
	MM$$	$WCHR>

DEFINE WTEXT$(TXT),<
IFNB <TXT>,<
	MOVEI	T1,[ASCIZ `'TXT'`]>
	MM$$	WTEXT>

DEFINE WLINE$(TXT),<
IFNB <TXT>,<
	MOVEI	T1,[ASCIZ `'TXT'
`]>
	MM$$	WTEXT>

DEFINE WDECL$(NUM),<
IFNB <NUM>,<
	MOVEI	T1,^D'NUM>
	MM$$	WDECL>

DEFINE WOCTL$(NUM),<
IFNB <NUM>,<
	MOVEI	T1,NUM>
	MM$$	WOCTL>

DEFINE WREAL$(NUM),<
IFNB <NUM>,<
	MOVE	T1,[NUM]>
	MM$$	WREAL>

DEFINE WWORD$(WOR),<
IFNB <WOR>,<
	MOVX	T1,<SIXBIT `'WOR'`>>
	MM$$	WWORD>

DEFINE WPWOR$(CHR,WOR),<
IFNB <CHR>,<
	MOVEI	T1,CHR>
IFNB <WOR>,<
	MOVX	T2,<SIXBIT `'WOR'`>>
	MM$$	WPWOR>
;  BASIC IO ROUTINES

DEFINE INPUT$,<MM$$ INPUT>
DEFINE OUTPU$,<MM$$ OUTPU>
DEFINE OUTIN$,<MM$$ OUTIN>
DEFINE USETI$,<MM$$ USETI>
DEFINE USETO$,<MM$$ USETO>
DEFINE GETST$,<MM$$ GETST>
DEFINE SETST$,<MM$$ SETST>
DEFINE DELET$,<MM$$ DELET>
DEFINE RENAM$,<MM$$ RENAM>
DEFINE LUKUP$,<MM$$ LUKUP>
DEFINE ENTER$(ADR),<MR$$ ADR,ENTER,ENTE0>
DEFINE OPEN$,<MM$$ OPEN>
DEFINE MKBUF$,<MM$$ MKBUF>
DEFINE DLBUF$,<MM$$ DLBUF>
DEFINE CLOSE$(BIT),<
IFNB <BIT>,<
	MOVEI	T1,<BIT>
	MM$$	CLOS0>
IFB <BIT>,<
	MM$$	CLOSE>>
DEFINE RLEAS$(ADR),<MR$$ ADR,RLEAS,RLEA0>
DEFINE FRCHN$,<MM$$ FRCHN>
DEFINE MX$$(UUO,SYM),<		;[124,135] CORRECT ARGUMENT ORDER, AND SYMBOL NAMES
IFNB <UUO>,<
	MOVX	T1,<UUO>>
	MM$$	SYM>
DEFINE XTUUO$(UUO),<MX$$ UUO,XTUUO>
DEFINE XTDCL$(UUO),<MX$$ UUO,XTDCL>
	DEFINE XTCDV$(UUO),<XTDCL$  UUO>		;[125] OBSOLETE
DEFINE XTCAL$(UUO),<MX$$ UUO,XTCAL>
	DEFINE XTCLI$(UUO),<XTCAL$  UUO>		;[125] OBSOLETE
DEFINE APEND$,<MM$$ APEND>
DEFINE UPDAT$,<MM$$ UPDAT>
DEFINE SAVE1$,<MM$$ SAVE1>
DEFINE SAVE2$,<MM$$ SAVE2>
DEFINE SAVE3$,<MM$$ SAVE3>
DEFINE SAVE4$,<MM$$ SAVE4>
DEFINE SAVET$,<MM$$ SAVET>
DEFINE RESTT$,<MM$$ RESTT>
DEFINE ALLOC$,<MM$$ $ALLC>
DEFINE DEALC$,<MM$$ $DALC>
DEFINE CLRFD$(ADR),<MR$$ ADR,CLRFD,CLRF0>
DEFINE LOSFD$,<MM$$ LOSFD>
DEFINE FDTTY$,<MM$$ FDTTY>
DEFINE APDWT$(ADR),<MR$$ ADR,APDWT,APDW0>
DEFINE UPDWT$(ADR),<MR$$ ADR,UPDWT,UPDW0>


;  MACROS TO CALL THE MTAPE UUO

DEFINE MT$$(OP),<
	PUSHJ	P,$MT'OP'##>

DEFINE MTWAT$,<MT$$ WAT>
DEFINE MTREW$,<MT$$ REW>
DEFINE MTEOF$,<MT$$ EOF>
DEFINE MTSKR$,<MT$$ SKR>
DEFINE MTBSR$,<MT$$ BSR>
DEFINE MTEOT$,<MT$$ EOT>
DEFINE MTUNL$,<MT$$ UNL>
DEFINE MTBLK$,<MT$$ BLK>
DEFINE MTSKF$,<MT$$ SKF>
DEFINE MTBSF$,<MT$$ BSF>
DEFINE MTDEC$,<MT$$ DEC>
DEFINE MTIND$,<MT$$ IND>
;  FORMATTED WRITE MACROS

DEFINE WRITE$,<MM$$ WRITE>
DEFINE WBYTE$,<MM$$ $WBYT>
DEFINE WCRLF$,<MM$$ WCRLF>
DEFINE WRADX$,<MM$$ WRADX>
DEFINE WXWD$,<MM$$ WXWD>
DEFINE WFILE$,<MM$$ WFILE>
DEFINE WNAME$,<MM$$ WNAME>
DEFINE WDVIC$,<MM$$ WDVIC>
DEFINE WPATH$,<MM$$ WPATH>
DEFINE WFCHA$,<MM$$ WFCHA>
DEFINE W2FIL$,<MM$$ W2FIL>
DEFINE W2FL0$,<MM$$ W2FL0>
DEFINE W2FLB$,<MM$$ W2FLB>
DEFINE WCASH$,<MM$$ WCASH>
DEFINE WADDR$,<MM$$ WADDR>
DEFINE WDATE$,<MM$$ WDATE>
DEFINE WDNOW$,<MM$$ WDNOW>
DEFINE WTIME$,<MM$$ WTIME>
DEFINE WTIMS$,<MM$$ WTIMS>
DEFINE WTMTS$,<MM$$ WTMTS>
DEFINE WTNOW$,<MM$$ WTNOW>
DEFINE WTDAY$,<MM$$ WTDAY>
DEFINE WTDNW$,<MM$$ WTDNW>
DEFINE WHELP$,<MM$$ WHELP>
define wbwrd$,<mm$$ wbwrd>		;[136]
define wcwrd$,<mm$$ wcwrd>		;[136]
define wwwrd$,<mm$$ wwwrd>		;[136]
DEFINE WKWRD$,<MM$$ WKWRD>
DEFINE WPWRD$,<MM$$ WPWRD>


;  FORMATTED READ ROUTINES

DEFINE READ$,<MM$$ READ>
DEFINE RBYTE$,<MM$$ $RBYT>
DEFINE RCHAR$,<MM$$ $RCHR>
DEFINE CKEOL$,<MM$$ CKEOL>
DEFINE RCCHR$,<MM$$ RCCHR>
DEFINE RCALT$,<MM$$ RCALT>
DEFINE RUCCH$(ADR),<MR$$ ADR,RUCCH,RUCC0>
DEFINE RANCH$(ADR),<MR$$ ADR,RANCH,RANC0>
DEFINE REDCH$(ADR),<MR$$ ADR,REDCH,REDC0>
DEFINE RWORD$(ADR),<MR$$ ADR,RWORD,RWOR0>
DEFINE RNAME$(ADR),<MR$$ ADR,RNAME,RNAM0>
DEFINE RWNAM$(ADR),<MR$$ ADR,RWNAM,RWNA0>
DEFINE RWNUM$(ADR),<MR$$ ADR,RWNUM,RWNU0>
DEFINE RDECL$(ADR),<MR$$ ADR,RDECL,RDEC0>
DEFINE RDECM$(ADR),<MR$$ ADR,RDECM,RDCM0>
DEFINE ROCTL$(ADR),<MR$$ ADR,ROCTL,ROCT0>
DEFINE ROCTM$(ADR),<MR$$ ADR,ROCTM,ROCM0>
DEFINE RKWRD$(ADR),<MR$$ ADR,RKWRD,RKWR0>
DEFINE RREAL$(ADR),<MR$$ ADR,RREAL,RREA0>
DEFINE RTDAY$(ADR),<MR$$ ADR,RTDAY,RTDA0>
DEFINE RDATE$(ADR),<MR$$ ADR,RDATE,RDAT0>
DEFINE RTIME$(ADR),<MR$$ ADR,RTIME,RTIM0>
DEFINE RCASH$(ADR),<MR$$ ADR,RCASH,RCAS0>
DEFINE RFILE$(ADR),<MR$$ ADR,RFILE,RFIL0>
DEFINE RDVIC$(ADR),<MR$$ ADR,RDVIC,RDVI0>
DEFINE RPATH$(ADR),<MR$$ ADR,RPATH,RPAT0>
DEFINE RPPN$(ADR),<MR$$ ADR,RPPN,RPPN0>
DEFINE RPJPG$(ADR),<MR$$ ADR,RPJPG,RPJP0>
DEFINE RSWIT$,<MM$$ RSWIT>


;MISCELLANEOUS ROUTINES

DEFINE MONRT$,<MM$$ MONRT>
DEFINE CLLIN$,<MM$$ CLLIN>
DEFINE CLBUF$,<MM$$ CLBUF>
DEFINE SLEEP$(SEC),<
IFNB <SEC>,<
	MOVEI	T1,SEC
	MM$$	SLEE0>
IFB <SEC>,<
	MM$$	SLEEP>>
DEFINE MATCH$,<MM$$ MATCH>
DEFINE ZERO$,<MM$$ ZERO>
DEFINE BATCH$,<MM$$ BATCH>
DEFINE TMPFD$,<MM$$ TMPFD>
DEFINE TMPIN$,<MM$$ TMPIN>
DEFINE TMPOU$,<MM$$ TMPOU>
DEFINE TMPDL$,<MM$$ TMPDL>
DEFINE CNVUI$,<MM$$ CNVUI>
	DEFINE CNTDT$,<MM$$ CNTDT>		;[125] OBSOLETE
DEFINE CNVNU$,<MM$$ CNVNU>
	DEFINE CNNOW$,<MM$$ CNNOW>		;[125] OBSOLETE
DEFINE CNVIU$,<MM$$ CNVIU$>
	DEFINE CNVDT$,<MM$$ CNVDT>		;[125] OBSOLETE
	SUBTTL	ERROR REPORTING MACROS

;  THE ERROR REPORTING MACROS CAN BE USED TO CALL THE ROUTINES
;  $FATAL/$WARN OR ANY ROUTINES OF THE FORM $FTLXX/$WRNXX
;  THE CALL ALWAYS TAKES ONE INSTRUCTION OF INLINE CODE AND
;  FROM 0 TO 5 WORDS OF LITERALS.

;  CALL:(E.G.)
;	FATAL$			;CALLS $FTLIO
;	FATAL$	,FD		;CALLS $FTLFD
;	FATAL$	<TEXT>,CHAR,TXT,SYNTAX	;CALLS $FATAL

;  FIRST DEFINE A MACRO TO DEFINE THE OTHER TWO MACROS

DEFINE FW$$(NAM,ABR,TXT,TYP,EID,UUO),<
IFB <TXT'TYP>,<
	PUSHJ	P,$'ABR'IO##>
IFNB <TXT'TYP>,<
IFB <TXT>,<
	EXTERN	$'ABR'TYP
	PUSHJ	P,$'ABR'TYP>
IFNB <TXT>,<
IFB <TYP'UUO'EID>,<
	PUSHJ	P,[MOVEI T1,[ASCIZ \TXT\]
		   PJRST $'NAM'##]>
IFNB <TYP'UUO'EID>,<
IFNB <EID>,<
	FW$$S==EC$IND+[<SIXBIT `'EID'`>+[ASCIZ `'TXT'`]]>
IFB <EID>,<
	FW$$S==[ASCIZ `'TXT'`]>
IFNB <UUO>,<
	FW$$S==FW$$S+EC$UUO>
IFNB <TYP>,<
	FW$$S==FW$$S+<<$ECT'TYP>B17>>
	PUSHJ	P,[MOVE	T1,[FW$$S]
IFNB <UUO>,<
		   MOVE	T3,[SIXBIT `'UUO'`]>	;[137]
		   JRST $'NAM'##]
	PURGE	FW$$S>
>>>;DEFINE

DEFINE FATAL$(TXT,TYP,EID,UUO),<
FW$$	FATAL,FTL,TXT,TYP,EID,UUO>

DEFINE WARN$(TXT,TYP,EID,UUO),<
FW$$	WARN,WRN,TXT,TYP,EID,UUO>

DEFINE ADVIS$(TXT,TYP,EID,UUO),<
FW$$	ADVIS,ADV,TXT,TYP,EID,UUO>
	SUBTTL	BEGIN MACRO

COMMENT ;
THIS MACRO SHOULD BE CALLED AS THE FIRST EXECUTABLE
INSTRUCTION AT THE START ADDRESS. IT PERFORMS ALL PROGRAM INITIALISATION
INCLUDING

1	PORTALS FOR EX ONLY KI PROGRAMS
2	SET CCL FLAG IN $IDCCL
3	INITIALISE IDB
4	RESET
5	LOAD D I AND P
6	SETUP TEMPCORE INPUT IN $IDIFD IF CCL ENTRY
;

;  CALL:
;	BEGIN$

DEFINE BEGIN$(TCN),<		;;[121]  ARGUMENT TO BEGIN$ MACRO
IFE FT$DBG,<SALL>
IFE FT$ALC,<
	$$ALLC==$CRGET##
	$$DALC==$CRREL##>	;STATIC CORE ALLOCATION
IFN FT$DBG,<EXTERN $DEBUG>		;LOAD PATCH AREA
IFE FT$DBG,<EXTERN $UNDBG>	;LOAD NON-DEBUG CODE
	PORTAL	.+2		;XCT ONLY ENTRY
	PORTAL	.+2		;XCT ONLY CCL ENTRY
	TDZA	T1,T1		;FLAG NORMAL ENTRY
IFNB <TCN>,<
	MOVEI	T1,(SIXBIT \TCN\)	;;[124] SET TEMPCORE FILE NAME>
IFB <TCN>,<
	HLRZ	T1,.SGNAM	;;[124] USE PROGRAM NAME AS TEMPCORE FILENAME>
IFE FT$CCL,<
	JSP	T0,$BEGIN##	;initialise code>
IFN FT$CCL,<
	JSP	T0,$BEGCC##	;initialise code + CCL stuff>;FT$CCL
$$BEG::
>;BEGIN$


	SUBTTL	VERSION NUMBERING MACROS

COMMENT ;
THERE ARE 4 VERSION NUMBER MACROS.
1. VERSN$    DEFINES THE SYMBOLS FOR THE FOUR BASIC VERSION NUMBERS
2. PATCH$    DEFINES $N SYMBOLS FOR PATCHES AND UPDATES THE EDIT AND
	     RELEASE NUMBERS
3. JBVER$    SETS THE VERSION NUMBERS INTO .JBVER
4. VTEXT$    CREATES AN ASCIZ STRING OUT OF THE VERSION NUMBER
	     SUITABLE FOR PRINTING
;

;  CALL:
;	VERSN$	3,105,2		;WHERE 3 IS VMAJOR, 105 IS VEDIT AND 2 IS VWHO

DEFINE VERSN$(VMJ,VED,VCD)<
	$VMAJ==<VMJ>		;;MAJOR VERSION
	$VMIN==0		;;RELEASE
	$VEDT==<VED>		;;EDIT NUMBER
	$VCOD==<VCD>		;;WHO LAST MODIFIED

;;PRINT OUT VERSION NUMBERS OF C AND IO ON ASSEMBLY

	V1$$==<<%%C&<77700,,000000>>_-^D24>
	V2$$==<%%C&777777>
	V3$$==<<$$IO&<77700,,000000>>_-^D24>
	V4$$==<$$IO&777777>
DEFINE V$$(V1,V2,V3,V4),<
IF1,<
PRINTX %Assembled using C version V1(V2) and IO version V3(V4)
>>;DEFINE
	V$$	\V1$$,\V2$$,\V3$$,\V4$$
	PURGE	V1$$,V2$$,V3$$,V4$$
>


;  CALL:
;	PATCH$	<23,24,26>	;EDIT NUMBERS BRACKETED BY RELEASE

DEFINE PATCH$(PAT)<
IFNB <PAT><$VMIN==$VMIN+1>
IRP PAT<$VEDT==$VEDT+1
          $'PAT==-1>
>


;  CALL:
;	JBVER$

DEFINE JBVER$<
	.JBVER==137
	LOC	.JBVER
	BYTE	(3)$VCOD(9)$VMAJ(6)$VMIN(18)$VEDT
	RELOC
>


;  CALL:
;	VTEXT$

   DEFINE VTEXT$,<
   DEFINE VTEXT$(VMJ,VMI,VED,VCD),<
	DEFINE ..NUM(..N),<
IFN ..N<IRPC ..N<..T==..T_7+..N+"0"
..WRD>>>;..NUM
	DEFINE ..ABC(..A),<
IFN ..A<..T==..T_7+"A"+..A-1
..WRD>>;..ABC
	DEFINE ..CHR(..C),<
..T==..T_7+"..C"
..WRD>;..CHR
	DEFINE ..WRD,<
IFN <..T&..M>,<..DEP
..T==0>>;..WRD
	DEFINE ..DEP,<
BYTE(7) <..T&<376000,,0>>_-^D28,<..T&<1770,,0>>_-^D21,
	<..T&<7,,740000>>_-^D14,<..T&37600>_-^D7,..T&177>;..DEP
	..T==0
	..M==376000,,0
	..NUM	VMJ
	..ABC	VMI
IFN VED<..CHR	<(>
	..NUM	VED
	..CHR	<)>>
IFN VCD<..CHR	<->
	..NUM	VCD>
IFE ..T<DEFINE ..WRD,<..DEP>>
IFN ..T<
	DEFINE ..WRD,<
..T==..T_7
IFE <..T&..M>,<..WRD>
IFN ..T<..DEP
..T==0>>>;..WRD
	..WRD
	PURGE	..NUM,..ABC,..CHR,..WRD,..DEP,..T,..M>;VERSION
	VTEXT$	\$VMAJ,$VMIN,\$VEDT,\$VCOD>


	SUBTTL	MACROS TO AID ASSEMBLY

;  HISEG$

;	CHANGE RELOCATION SO THAT CODE WILL BE ASSEMBLED INTO
;	THE HIGH SEGMENT.  IF THE SEGMENT INDICATOR IS NOT YET
;	DEFINED, DEFINE IT AND ISSUE A TWOSEG PSEUDO-OP

;  CALL:
;	HISEG$

DEFINE HISEG$,<
IF1,<
	IFDEF SEG$1,<
		IFE SEG$1,<
			IFE FT$DBG,<XLIST>
			LIT
			RELOC
			IFE FT$DBG,<LIST>>>
	IFNDEF SEG$1,<
		TWOSEG
		RELOC	400000>
	SEG$1==-1>
IF2,<
	IFDEF SEG$2,<
		IFE SEG$2,<
			IFE FT$DBG,<XLIST>
			LIT
			RELOC
			IFE FT$DBG,<LIST>>>
	IFNDEF SEG$2,<
		TWOSEG
		RELOC	400000>
	SEG$2==-1>>

;  LOSEG$

;	CHANGE RELOCATION SO THAT CODE WILL BE ASSEMBLED INTO THE
;	LOW SEGMENT.  IF THE SEGMENT INDICATOR IS UNDEFINED THERE
;	IS NO HIGH SEGMENT, SO DO NOTHING.

;  CALL:
;	LOSEG$

DEFINE LOSEG$,<
IF1,<
	IFDEF SEG$1,<
		IFN SEG$1,<
			IFE FT$DBG,<XLIST>
			LIT
			RELOC
			SEG$1==0
			IFE FT$DBG,<LIST>>>>
IF2,<
	IFDEF SEG$2,<
		IFN SEG$2,<
			IFE FT$DBG,<XLIST>
			LIT
			RELOC
			SEG$2==0
			IFE FT$DBG,<LIST>>>>>


;  INSTK$

;	SET UP THE PUSH DOWN POINTER TO THE START OF THE STACK

;  CALL:
;	INSTK$

DEFINE INSTK$,<
	GLOB	<$STACK,$LNSTK,$PTSTK>
	MOVE	P,$PTSTK>


;  JBREN$

;	LOAD .JBREN WITH THE ADDRESS OF THE REENTRY ROUTINE.  USES
;	AN AC OF THE USER'S CHOICE

;  CALL:
;	JBREN$	T1,RENTER

DEFINE JBREN$(AC,ADR),<
	.JBREN==124
	MOVEI	AC,ADR
	HRRM	AC,.JBREN>


;  CHNNO$

;	LOAD THE CHANNEL NUMBER FOR THE CURRENT FILE INTO THE
;	GIVEN AC

;  CALL:
;	CHNNO$	AC

DEFINE CHNNO$(AC),<
	LDB	AC,[POINTR ($FDCHN(D),FC$CHN)]>
	SUBTTL	MACROS TO BUILD SWITCH TABLES

COMMENT ;
THE SWITCH TABLES ARE USED BY THE COMMAND SCANNING ROUTINES TO READ
AND ACT ON SWITCHES ENCOUNTERED IN THE COMMAND. THERE ARE 4 TABLES
END TO END WITH ONE ENTRY PER SWITCH IN EACH TABLE.  THE TABLES
CONTAIN:
1.  SIXBIT NAMES OF THE SWITCHES
2.  BYTE POINTER TO STORE THE VALUE OF THE SWITCH
3.  IF .LT.0, THEN IOWD TO TABLE OF ALLOWED KEYWORD VALUES FOR
    THE SWITCH
    IF .GE.0, THEN THE ADDRESS OF THE PROCESSOR ROUTINE FOR THE
    THE VALUE IS IN THE RH, AND THE MAXIMUM VALUE IS IN THE LH.
4.  DEFAULT VALUE FOR THE SWITCH IN THE RH: OTHERWISE ZERO.

6 MACROS ARE USED TO BUILD THE TABLES, AND A FURTHER MACRO TO
DEFINE THE MAXIMA AND DEFAULTS FOR THE SWITCHES.
THE SWTAB$ MACRO BUILDS THE 4 TABLES, GIVEN A LIST OF SWITCHES
DEFINED IN A USER DEFINED MACRO 'SWITCH'.
SWITCH MUST CONTAIN A LIST OF SWITCHES DEFINED IN TERMS OF THE
MACROS SP$, SL$, SS$.

SP$ DEFINES SWITCHES WITH VALUES OTHER THAN KEYWORDS. ITS
    ARGUMENTS ARE THE NAME, THE STORAGE BYTE POINTER, THE NAME
    OF THE PROCESSOR, WHICH MUST BE ONE OF
		DECL
		OCTL
		WORD
		FILE
    AND THE ABBREVIATION USED IN THE 'DM$' MACRO TO DEFINE THE
    DEFAULTS.

SL$ DEFINES SWITCHES WITH KEYWORD VALUES.  THE ARGUMENTS ARE THE
    NAME, THE STORAGE BYTE POINTEER, A NAME OF A TABLE OF KEYWORDS
    AS A TWO WORD ID, AND THE DEFAULT KEYWORD AS A TWO CHARACTER

SS$ DEFINES SWITCHES WHICH HAVE NO VALUE. THE ARGUMENTS ARE THE NAME
    THE STORAGE BYTE POINTER, AND THE VALUE TO BE STORED. OFTEN 1 FOR
    1 BIT FLAG.

THE STORAGE BYTE POINTER MAY BE AN ADDRESS ONLY, IF THE BYTE IS A FULL
WORD.

THE TABLE OF KEYWORDS ARE DEFINED BY THE KEYWD$ MACRO.

MAXIMA AND DEFAULT SYMBOLS ARE DEFINED BY THE DM$ MACRO.
IT DEFINES SYMBOLS
	MX$XXX  FOR THE MAXIMUM
	AD$XXX  FOR THE DEFAULT IF THE KEYWORD IS ABSENT
	PD$XXX  FOR THE DEFAULT IF THE KEYWORD IS PRESENT
;
DEFINE DM$(ABR,MAX,ADF,PDF),<
	ND	MX$'ABR,MAX
	ND	AD$'ABR,ADF
	ND	PD$'ABR,PDF>

DEFINE SP$(NAM,STO,PRO,ABR,FLG),<
	X	NAM,PRO,<STO>,PD$'ABR,MX$'ABR,FLG>

DEFINE SL$(NAM,STO,TAB,DEF,FLG),<
	X	NAM,TAB'$T-1,<STO>,DEF,-TAB'$L,FLG>

DEFINE SS$(NAM,STO,VAL,FLG),<
	X	NAM,0,<STO>,VAL,0,FLG>

DEFINE SWTAB$(NAM),<
	XALL

;TABLE OF POINTERS TO THE OTHER TABLES

	IOWD	NAM'$$L,NAM'$$N		;[127] IOWD TO NAME TABLE
	XWD	P1,NAM'$$P		;[127] POINT TO BYTE POINT TABLE
	XWD	P1,NAM'$$M		;[127] POINT TO MAXIMA TABLE
	XWD	P1,NAM'$$D		;[127] POINT TO DEFAULT TABLE

;;TABLE OF SIXBIT SWITCH NAMES

DEFINE X(A,B,C,D,E,F),<
	EXP	SIXBIT `A`>
NAM'$$N:	;[127] TABLE OF SIXBIT SWITCH NAMES
	SWIT$$
NAM'$$L==.-NAM'$$N

;;TABLE OF BYTE POINTERS TO STORE RESULT

IF2,<
DEFINE X(A,B,C,D,E,F),<
	TMP$$==0
IFB <C>,<
	Z			;A
	TMP$$==1>
IFN <C>_-^D24,<
	TMP$$==C
	TMP$$			;A
>
IFE TMP$$,<
	POINT	36,C,35		;A
>
>>
NAM'$$P:	;[127] TABLE OF POINTERS TO VALUE WORDS
	SWIT$$

;;TABLE OF IF LT 0, IOWD KEY-TABLE
;;      OR IF GE 0, XWD MAX,PROCESSOR

	MX$==0
DEFINE X(A,B,C,D,E,F),<
	XWD	E,B		;A
>
NAM'$$M:	;[127] TABLE OF MAXIMA OR IOWDS
	SWIT$$

;;FLAGS,,DEFAULT VALUE

	PD$==0
DEFINE X(A,B,C,D,E,F),<
	XWD	0,D		;A
>
NAM'$$D:	;[127] TABLE OF FLAGS AND DEFAULTS
	SWIT$$
	PURGE	MX$,PD$,TMP$$
	SALL>
DEFINE KEYWD$(NAM,KEY),<
NAM'$L==0
NAM'$T:
	IRP	(KEY),<EXP	SIXBIT `KEY`
		       NAM'$L==NAM'$L+1
		       TMP$$==0
		       IRPC (KEY),<IFIDN <KEY><*>,<TMP$$==1>
		                   STOPI>
		       IFE TMP$$,<NAM'KEY==NAM'$L>
		>
	PURGE TMP$$>
	SUBTTL	MACROS TO BUILD FDB'S

;  FDESC$

;	BUILD AN FDB IN SITU
;	FIELDS THAT THE USER MAY SUPPLY ARE
;		DEVICE,NAME,EXT,PPN,MODE,LENGTH

;  CALL:
;	FDESC$	DSKB,IO,MAC,<1,4,MACRO>,.IOBIN,<$FDRIB+.RBDEV>

DEFINE FDESC$(DEV,NAM,EXT,PPN,MOD,LEN),<

;  DEFINE A LENGTH SYMBOL FOR THIS FDB, WHICH MAY BE LONGER
;  THEN $LNFDB, AND REMEMBER WHERE THE START IS ($$$LEN AND
;  $$$LOC)

IFL <<LEN>-$LNFDB>,<$$$LEN==$LNFDB>	;DEFINE A LENGTH SYMBOL
IFGE <<LEN>-$LNFDB>,<$$$LEN==<LEN>>	;
	$$$LOC==.			;REMEMBER WHERE WE ARE

;  MAKE ZEROED WORDS FROM THE START DOWN TO $FDSTS

REPEAT $FDSTS,<
	EXP	0			;ZEROS TILL STATUS WORD
>

;  SET THE FILE IO MODE TO .IOASC OR THE GIVEN MODE

IFNB <MOD>,<EXP	<MOD>>			;SET MODE
IFB <MOD>,<EXP	.IOASC>		;DEFAULT
	SIXBIT	`'DEV'`		;DEVICE

;  CLEAR DOWN TO PPN IN PATH SPEC BLOCK

REPEAT <$FDPPP-$FDBHD>,<
	EXP	0			;BUFFER HEADERS AND MODE
>

;  IF NO PATH GIVEN, MAKE ZEROED PATH BLOCK
;  IF PATH SUPPLIED, SET THIS PATH INTO THE PATH BLOCK

IFB <PPN>,<		;ZERO PATH SPEC
  REPEAT <FT$SFD>,<
	EXP	0
  >;REPEAT
>;IFB


IFNB <PPN>,<				;CREATE PATH SPEC
	$$$N==0				;PPN PARTS SEEN SO FAR
  IRP <PPN>,<
    IFE <$$$N>,<$$$PPN==PPN,,0>		;PRJ
    IFE <$$$N-1>,<$$$PPN==$$$PPN+PPN	;PRG
	EXP	$$$PPN			;SET PPN
    >;IFE
    IFG <$$$N-1>,<			;THEREFORE AN SFD
      IFG <$$$N-FT$SFD>,<PRINTX TOO MANY SFDS IN FDESC$ CALL
		         STOPI>
	SIXBIT	@PPN@			;SET SFD
    >;IFG
    $$$N==$$$N+1
  >;IRP
  IFLE <$$$N-FT$SFD>,<
    REPEAT <FT$SFD+1-$$$N>,<
	EXP	0			;FILL IN PATH BLOCK
    >;REPEAT
  >;IFLE
>;IFNB
	EXP	0			;END PATH SPEC

;  CLEAR DOWN TO RIB BLOCK

REPEAT <$FDCNT-$FDOBH>,<
	EXP	0
>

;  .RBCNT  -  COUNT OF WORDS REMAINING IN FDB
;  .RBPPN  -  POINT TO PATH SPEC.
;  .RBNAM  -  GIVEN FILENAME
;  .RBEXT  -  GIVEN EXTENSION
;  .RBPRV-.RBVER  -  EMPTY

	EXP	$$$LEN-$FDCNT-1		;RIB WORD COUNT
	EXP	$$$LOC+$FDPTH		;ADDRESS OF PATH SPEC
	<SIXBIT	`'NAM'`>		;NAME
	<SIXBIT `'EXT'`>&<-1,,0>	;EXTENSION
REPEAT <$$$LEN-$FDPRV>,<
	EXP	0			;ZERO REST OF FDB
>

;  CLEAN UP TEMPORARY VARIABLES

	PURGE	$$$LEN,$$$N,$$$PPN,$$$LOC
>


;  MAKFD$

;	BUILD AN FDB BY CODE INSERTING ANY FIELDS SPECIFIED.
;	THE POSSIBILITIES ARE
;	DEVICE,NAME,EXTENSION,PPN,MODE,LENGTH,ADDRESS OF FDB

;  CALL:
;	MAKFD$	DSK,FILEA,F4,<30,652>,.IOASC,,D

DEFINE MAKFD$(DEV,NAM,EXT,PPN,MOD,LEN,ADR),<

;  DEFINE SYMBOL, $$$LEN, FOR LENGTH OF THIS FDB, WHICH MAY BE
;  LONGER THAN $LNFDB

IFL <<LEN>-$LNFDB>,<$$$LEN==$LNFDB>	;LENGTH OF FDB
IFGE <<LEN>-$LNFDB>,<$$$LEN==<LEN>>	;

;  CREATE INSTRUCTION TO MOVE $CLRFD ARGUMENT INTO AC(T1)
;  THE ARG IS  [LENGTH,,ADDRESS] WITH ADDRESS ZERO FOR A NEW
;  FDB TO BE ALLOCATED

IFNB <ADR>,<
	MOVE	T1,[$$$LEN,,<ADR>]	;ARGUMENTS FOR $CLRFD
>
IFB <ADR>,<
	MOVSI	T1,$$$LEN		;FIND SPACE
>

;  S/R CALL TO CREATE (OR CLEAR) FDB.  ERRORS ARE FATAL

	CLRFD$	T1			;
	  FATAL$			;
	MOVE	D,T1			;SETUP D

;  IF THE FILE IO MODE IS GIVEN, SET IT INTO $FDMOD

IFNB <MOD>,<
	MOVX	T1,<MOD>		;SET MODE
	MOVEM	T1,$FDSTS(D)		;
>

;  IF THE DEVICE SPEC. IS GIVEN, SET IT INTO $FDDEV

IFNB <DEV>,<
	MOVX	T1,<SIXBIT `'DEV'`>	;SET DEVICE NAME
	MOVEM	T1,$FDDEV(D)		;
>

;  IF THE PATH SPEC IS GIVEN, SET IT WORD BY WORD INTO THE
;  PATH SPEC. BLOCK

	$$$N==0				;IRP COUNT
IFNB <PPN>,<
  IRP PPN,<
    IFE <$$$N>,<$$$PPN==PPN,,0>		;PRJ
    IFE <$$$N-1>,<$$$PPN==$$$PPN+PPN	;PRG
	MOVE	T1,[$$$PPN]	;SET PPN
	MOVEM	T1,$FDPPP(D)		;IN PATH SPEC.
    >;IFE
    IFG <$$$N-1>,<
      IFG <$$$N-FT$SFD>,<PRINTX TOO MANY SFDS IN MAKFD$ CALL
			 STOPI>
	MOVX	T1,<SIXBIT `'PPN'`>	;
	MOVEM	T1,$FDPTH+1+$$$N(D)	;
    >;IFG
    $$$N==$$$N+1				;INCREMENT IRP COUNT
  >;IRP
>;IFNB

;  INSERT FILE NAME INTO FDB IF GIVEN

IFNB <NAM>,<
	MOVX	T1,<SIXBIT `'NAM'`>	;
	MOVEM	T1,$FDNAM(D)		;
>

;  INSERT FILE EXTENSION INTO FDB IF GIVEN

IFNB <EXT>,<
	MOVX	T1,<SIXBIT `'EXT'`>	;
	HLLZM	T1,$FDEXT(D)		;
>

;  CLEAN UP TEMPORARY VARIABLES

	PURGE	$$$LEN,$$$N,$$$PPN
>


	IF1,<	ASUPPRESS>
	IFDEF %.C,<IFLE %.C+2,<
			IF2,<PURGE %.C,%..C>
			END>>	;BIND OFF TO GET CLEAN LISTING