       .TITLE BINIO
/ 
/ 
/                   FIRST PRINTING, FEBRUARY 1974
/ 
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO 
/ CHANGE WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED
/ AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/ 
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED TO THE PURCHASER UNDER A LICENSE FOR USE ON
/ A SINGLE COMPUTER SYSTEM AND CAN BE COPIED (WITH
/ INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR 
/ USE IN SUCH SYSTEM, EXCEPT AS MAY OTHERWISE BE PRO-
/ VIDED IN WRITING BY DIGITAL.
/ 
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/ 
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/ 
/ 
        .EJECT
/COPYRIGHT 1972,1973, DIGITAL EQUIPMENT CORP., MAYNARD, MASS. 01754
/EDIT #020  9 AUG 73  TAM(19,18)*REF(006)*WAD(009*REF*
/DEFINE %V5A FOR V5A SYSTEM
/DEFINE RSX FOR RSX PLUS III (PRODUCES SAME VERSION AS V5A)
	.IFDEF	RSX
%V5A=0
	.ENDC
	.IFUND %V5A
%DOS15=0
	.ENDC
/BINARY I/O OBJECT-TIME PACKAGE.
/   INTERNAL GLOBALS--
       .GLOBL .FS            /BINARY READ
       .GLOBL .FX            /BINARY WRITE
       .GLOBL .FB            /BINARY ARRAY I/O
	.GLOBL	.RB	/* RANDOM BINARY ARRAY I/O
       .GLOBL .FJ            /BINARY ELEMENT I/O 
	.GLOBL	.RJ	/* RANDOM BINARY ELEMENT I/O
       .GLOBL .FG            /BINARY I/O CLEANUP
	.GLOBL	.BUFLC	/* LOC. OF BUFF. PTR.
	.GLOBL	.RDTV	/* READ TRANS. VEC.
	.GLOBL	.WRTV	/* WRITE TRANS. VEC.
	.GLOBL	.IBLB	/* INIT. BIN. L.B.
	.GLOBL	.ID	/* I.D. NUMBER
	.GLOBL	.IDLOC	/* PTR. TO I.D. WORD
	.GLOBL BINIO	/FOR EXPLICIT USE
BINIO=.			/WITH CHAIN
/   VIRTUAL GLOBALS--
       .GLOBL .FH            /READ/WRITE FLAG.
       .GLOBL .FC            /I/O DEVICE INITIALIZER.
       .GLOBL .FQ            /LINE BUFFER TRANSFER ROUTINE.
       .GLOBL .FM            /LINE BUFFER SIZE.
       .GLOBL .FN            /LINE BUFFER.
       .GLOBL .ER            /ERROR ROUTINE.
	.GLOBL	.ER4		/REINIT. LOCATION (OTSER)
	.IFDEF %DOS15
	.GLOBL .DSK,.FLRA,.FLTB1,.STADD,.FLZW0
	.ENDC
/   CONSTANTS AND WORKING STORAGE--
C00001 .DSA   1
C00003 .DSA   3
S17777 .DSA   017777
V00000	300000
W00000 .DSA   400000
S00077	.DSA	77
SLOT   .DSA   0
.ID     .DSA   0
WD2    .DSA   0
WD5    .DSA   0
CNT    .DSA   0
WCNT   .DSA   0
DADD   .DSA   0
LBADD  .DSA   0
LBCNT  .DSA   0
.IDLOC  .DSA   0
HDR2   .DSA   0
LDRTV	.DSA	READ	/* LOAD READ T.V.
LDWTV	.DSA	WRITE	/* LOAD WRITE T.V.
.BUFLC	XX		/*
.RDTV	XX		/*
.WRTV	XX		/*
	.TITLE	.FS  - -  BINARY READ
/BINARY READ
/  CALLING SEQUENCE -- JMS   .FS
/                      .DSA  ADDRESS OF SLOT NUMBER
.FS    CAL    0
/*
/INIT. BINIO FOR SEQ. ACC.
	LAC	LDRTV	/*
	DAC	.RDTV	/* JN .FI
	LAC	.FN	/*
	DAC	.BUFLC	/* IN .IBLB
/
       DZM*   .FH            /SET READ/WRITE FLAG TO READ.
       LAC*   .FS            /INITALIZE INPUT DEVICE.
       JMS*   .FC
       DAC    SLOT           /SAVE SLOT NUMBER.
	.IFDEF %DOS15
	DAC FS3	/SET UP .SEEK
	JMS* .DSK	/A DISK?
	SNA
	JMP FS2	/NO
	LAC SLOT	/FILE OPEN FOR RAND. ACC.?
	JMS* .FLRA
	JMP FS2	/YES
FS7A	LAC SLOT	/NO-OPEN DEFAULT FILE IF NO FILE ACTIVE
	JMS* .FLTB1
	JMP FS6	/RETURNS HERE IF A FILE ACTIVE-CHECK I/O DIR.
	DAC FS4	/NO FILE ACTIVE--DIR ENTRY BUFF. INTO
	LAC* .STADD	/ZERO SO .INIT WILL GO THRO IN .FC
	DAC FS5
	DZM* FS5
	LAC* .FS	/SLOT
	JMS* .FC	/INIT FOR INPUT
FS3	0	/FS4---.SEEK
	3
FS4	0	/BUFF ADDR.
	.ENDC
FS2       ISZ    .FS            /BUMP RETURN ADDRESS.
       JMS    READ           /READ FIRST RECORD.
       JMP*   .FS            /EXIT.
	.IFDEF %DOS15
FS5	0	/TEMP.
FS6	SPA	/IF AC POS.,FILE ACTIVE FOR OUTPUT
/CLOSE OUTPUT FILE AND REOPEN IT THRO FS7A
	JMP FS2	/FILE ACTIVE FOR INPUT.  O.K.(JUST CONT.)
	LAC SLOT	/.DAT SLOT INTO AC
	DAC FS7		/SET .CLOSE CAL
	JMS* .FLZW0	/ZERO FILE ACTIVE WORD
FS7	0		/.CLOSE
	6
	JMP FS7A	/REOPEN FILE FOR INPUT 
	.ENDC
	.TITLE	.FX  - -  BINARY WRITE
/BINARY WRITE
/  CALLING SEQUENCE -- JMS   .FX
/                      .DSA  ADDRESS OF SLOT NUMBER.
.FX    CAL    0
/*
/INIT. BINIO FOR SEQ. ACC.
	LAC	LDWTV	/*
	DAC	.WRTV	/* IN .FJ
	LAC	.FN	/*
	DAC	.BUFLC	/* IN .IBLB
/
       LAC    C00001         /SET READ/WRITE FLAG TO WRITE.
       DAC*   .FH
       LAC*   .FX            /INITIALIZE OUTPUT DEVICE.
       JMS*   .FC
       DAC    SLOT           /SAVE SLOT NUMBER.
	.IFDEF %DOS15
	DAC FX3	/SET UP .ENTER
	JMS* .DSK	/A DISK?
	SNA
	JMP FX2	/NO
	LAC SLOT	/FILE OPEN FOR RAND. ACC.?
	JMS* .FLRA
	JMP FX2	/YES
	LAC SLOT	/NO-OPEN DEFAULT FILE IF NO FILE ACTIVE
	JMS* .FLTB1
	JMP FX6	/FILE ACTIVE-CHECK I/O DIRECTION
	DAC FX4	/FILE NOT ACTIVE-DIR. ENTRY BUFF ADDRR.
	LAC* .STADD
	DAC FS5
	DZM* FS5
	LAC* .FX	/SLOT
	JMS* .FC	/INIT FOR OUTPUT
FX3	0		/.ENTER
	4
FX4	0
	.ENDC
FX2       ISZ    .FX            /BUMP RETURN ADDRESS.
       DZM    .ID             /SET FIRST RECORD ID TO ZERO.
       JMS    .IBLB           /INITIALIZE LINE BUFFER PARAMETERS.
       JMP*   .FX            /EXIT.
	.IFDEF %DOS15
FX6	SMA		/IF AC NEG,FILE ACT. FOR INPUT-ERROR
	JMP FX2
	JMS* .ER	/.OTS 51
	000051
	.ENDC
	.TITLE	.FB (.RB)  - -  BINARY ARRAY I/O, .RB IF RANDOM ACCESS
/BINARY ARRAY I/O
/  CALLING SEQUENCE -- JMS   .FB (.RB - FOR RAN. ACC.)
/                      .DSA  ADDRESS OF DIMENSION INFORMATION.
.RB=.			/* R.A. ENTRY
.FB    CAL    0
       LAC*   .FB
       DAC    WD5             /ADDRESS OF WORD 5 OF DIMENSION INFO.
	SPA		/1 MORE LEVEL?
	LAC*	WD5	/YES
	DAC	WD5	/RESTORE
	TAD	(-3)
	DAC	WD2
	LAC*	WD2	/GET ARRAY SIZE
	CMA		/SET CNT = 2'S COMPLEMENT OF ARRAY SIZE
	TAD	C00001
	DAC	CNT
	LAC*	WD5	/SET UP BINARY ELEMENT I/O CALL WITH ARGU-
	DAC	FB2	/MENT = ARRAY ADDRESS.
	LAW	-1	/MODE 0 ALWAYS INDICATED BECAUSE
FB1    JMS    .FJ            /TRANSFER ONE BINARY WORD TO LINE BUFFER.
FB2	.DSA	0	/LAW -MODE ALSO PASSED ON RETURN FROM ELEMENT I/O
       ISZ    FB2            /INCREMENT DATA ADDRESS.
       ISZ    CNT            /INCREMENT WORD COUNTER AND TEST FOR EXIT.
       JMP    FB1            /   CNT.NE.0, TRANSFER ANOTHER WORD.
       ISZ    .FB            /   CNT.EQ.0, BUMP RETURN ADDRES AND EXIT.
       JMP*   .FB
	.TITLE	.FJ(.RJ)  - -  ELEMENT I/O (.RJ IF RANDOM ACCESS)
/BINARY ELEMENT I/O
/  CALLING SEQUENCE--
/		1'S COMPLEMENT OF MODE PASSED IN AC
/		JMS*	.FJ  (.RJ FOR R.A.)
/		.DSA ELEMENT ADDRESS (BIT0=1 IF TRANSFER VECTOR)
/		1'S COMPLEMENT OF MODE RETURNED IN AC
/
.RJ=.			/* R.A. ENTRY
.FJ	CAL
	DAC	ACSAVE	/SAVE PASSED MODE FOR RETURN
	SAD	(777774)  /IF IT IS 1'S COMPLEMENT OF 3, ADJUST FOR
	TAD	(2)	/TWO WORDS PER ELEMENT. ELSE 1'S COMP OF MODE = 2'S
	DAC	WCNT	/COMP. OF NO. WDS. PER DATA ITEM
       LAC*   .FJ            /STORE ADDRESS OF FIRST DATA WORD IN LOCA-
       DAC    DADD           /   TION DADD.  IF ARGUMENT IS A TRANSFER
       SPA                   /   VECTOR, GO ONE MORE LEVEL OF INDIRECT.
       LAC*   DADD
       DAC    DADD
       ISZ    .FJ            /BUMP RETURN ADDRESS
       LAC*   .FH            /BRANCH PER READ OR WRITE.
	SZA
       JMP    FI03
FI02	ISZ	LBCNT
	JMP	.+3
	JMS*	.RDTV		/* IF LB EMPTY, READ NEW RCD
	ISZ	LBCNT
	LAC*   LBADD          /READ--STORE LINE BUFFER WORD IN DATA
       DAC*   DADD           /   LOCATION.
       ISZ    LBADD          /BUMP L.B. ADDRESS AND L.B. WORD COUNT.
       ISZ    DADD           /BUMP DATA LOCATION AND DATA WORD COUNT.
       ISZ    WCNT
       JMP    FI02           /MORE WORD(S) TO GO.
       JMP     ACSAVE           /FINISHED, EXIT
FI03	ISZ	LBCNT
	JMP	.+3
	JMS*	.WRTV		/* IF L.B. FULL, WRITE THIS RCD.
	ISZ	LBCNT
	LAC*   DADD           /WRITE--STORE DATA WORD IN LINE BUFFER.
       DAC*   LBADD
       ISZ    LBADD          /BUMP L.B. ADDRESS AND L.B. WORD COUNT.
       ISZ    DADD           /BUMP DATA LOCATION AND DATA WORD COUNT.
       ISZ    WCNT
       JMP    FI03           /MORE WORD(S) TO GO.
ACSAVE	LAW			/LAW 1'S COMPLEMENT OF MODE EXECUTED BEFORE RETURN
       JMP*   .FJ            /FINISHED--EXIT
	.TITLE	.FG  - -   I/O CLEANUP
/BINARY I/O CLEANUP
/CALLING SEQUENCE -- JMS    .FG
.FG    CAL    0
       LAC*   .FH            /BRANCH PER READ OR WRITE.
	SNA
       JMP    FZ02
	DZM*   LBADD          /WRITE--FILL REMAINING UNFILLED WORDS IN
       ISZ    LBADD          /   LINE BUFFER WITH ZEROES.
	LAC	LBCNT
	TAD	(2
	TAD*	.FM
	DAC*	.FM
       LAC    .ID             /SET BIT 0 OF RECORD ID AS AN INDICATOR
       XOR    W00000         /   THAT THIS IS THE LAST PHYSICAL RECORD
       DAC    .ID             /   IN THIS LOGICAL RECORD.
       JMS    WRITE          /WRITE LAST RECORD AND EXIT.
	JMP	FZ03
FZ02   LAC*   .IDLOC          /READ--CONTINUE READING PHYSICAL RECORDS
       SPA                   /   UNTIL THE LAST ONE IN THE LOGICAL
	JMP	FZ03		/   RECORD HAS BEEN READ -- THEN EXIT
       JMS    READ
       JMP    FZ02
FZ03	LAC	(NOP	/REINIT. .ER
	DAC*	.ER4
	JMP*	.FG
	.TITLE	BINIO
/INITIALIZE BINARY LINE BUFFER PARAMETERS.
/  CALLING SEQUENCE -- JMS   .IBLB
.IBLB   CAL    0
       LAC    .BUFLC            /* ADDRESS OF 1ST L.B. WORD (HEADER WD 1)
       TAD    C00001
       DAC    HDR2           /ADDRESS OF 2ND L.B. WORD (HEADER WD 2)
       TAD    C00001
       DAC    .IDLOC          /ADDRESS OF 3RD L.B. WORD (RECORD ID)
       TAD    C00001
       DAC    LBADD          /ADDRESS OF 4TH L.B. WORD (1ST DATA WD)
       LAC*   .FM            /SET DATA WORD COUNTER (LBCNT) = TWOS
       CMA                   /   COMPLEMENT OF THE NO. OF DATA WORDS
       TAD    C00003         /   IN THE LINE BUFFER (.FM-3) MINUS ONE
       DAC    LBCNT
       JMP*   .IBLB           /EXIT.
       .EJECT
/READ BINARY RECORD
/  CALLING SEQUENCE -- JMS   READ
READ   CAL    0
       LAC    SLOT           /READ IN NEW LINE BUFFER IN IOPS-BINARY.
       JMS*   .FQ
       LAC*   .FN            /VERIFY MODE IN HEADER WORD.
	AND S00077
	SNA
       JMP    READ1          /IF IOPS-BINARY, O.K.
       JMS*   .ER            /IF NOT, GO TO ERROR EXIT.
       .DSA   11
READ1  JMS    .IBLB           /INITIALIZE L.B. PARAMETERS.
       JMP*   READ           /EXIT
       .EJECT
/WRITE BINARY RECORD
/  CALLING SEQUENCE -- JMS   WRITE
WRITE  CAL    0
       JMS    .IBLB           /INITIALIZE L.B. PARAMETERS.
       LAC*   .FM            /PREPARE IOPS HEADER WORD.
	CLL;	RTL;	RTL;	RTL;	RTL
	AND	(777000		/SAVE ONLY BITS #0-8
       DAC*   .FN
       DZM*   HDR2
       LAC    .ID             /STORE CURRENT RECORD ID IN THIRD BUFFER
       DAC*   .IDLOC          /   WORD.
       LAC    SLOT           /OUTPUT LINE BUFFER IN IOPS-BINARY.
       JMS*   .FQ
       ISZ    .ID             /BUMP RECORD ID.
       JMP*   WRITE          /EXIT.
       .END
