       .TITLE BINIO
/COPYRIGHT 1970, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/EDIT 4   10-14-70
/BINARY I/O OBJECT-TIME PACKAGE.
/   INTERNAL GLOBALS--
       .GLOBL .FS            /BINARY READ
       .GLOBL .FX            /BINARY WRITE
       .GLOBL .FB            /BINARY ARRAY I/O
       .GLOBL .FI            /BINARY ELEMENT I/O -- INTEGER DATA
       .GLOBL .FJ            /BINARY ELEMENT I/O -- REAL DATA
       .GLOBL .FK            /BINARY ELEMENT I/O -- DOUBLE DATA
       .GLOBL .FL            /BINARY ELEMENT I/O -- LOGICAL DATA
       .GLOBL .FG            /BINARY I/O CLEANUP
	.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.
/   CONSTANTS AND WORKING STORAGE--
C00001 .DSA   1
C00003 .DSA   3
C00004 .DSA   4
S17777 .DSA   017777
W00000 .DSA   400000
S00017 .DSA   000017
SLOT   .DSA   0
ID     .DSA   0
WD1    .DSA   0
WD4    .DSA   0
CNT    .DSA   0
WCNT   .DSA   0
DADD   .DSA   0
LBADD  .DSA   0
LBCNT  .DSA   0
IDLOC  .DSA   0
HDR2   .DSA   0
       .EJECT
/BINARY READ
/  CALLING SEQUENCE -- JMS   .FS
/                      .DSA  ADDRESS OF SLOT NUMBER
.FS    CAL    0
       DZM*   .FH            /SET READ/WRITE FLAG TO READ.
       LAC*   .FS            /INITALIZE INPUT DEVICE.
       JMS*   .FC
       DAC    SLOT           /SAVE SLOT NUMBER.
       ISZ    .FS            /BUMP RETURN ADDRESS.
       JMS    READ           /READ FIRST RECORD.
       JMP*   .FS            /EXIT.
       .EJECT
/BINARY WRITE
/  CALLING SEQUENCE -- JMS   .FX
/                      .DSA  ADDRESS OF SLOT NUMBER.
.FX    CAL    0
       LAC    C00001         /SET READ/WRITE FLAG TO WRITE.
       DAC*   .FH
       LAC*   .FX            /INITIALIZE OUTPUT DEVICE.
       JMS*   .FC
       DAC    SLOT           /SAVE SLOT NUMBER.
       ISZ    .FX            /BUMP RETURN ADDRESS.
       DZM    ID             /SET FIRST RECORD ID TO ZERO.
       JMS    IBLB           /INITIALIZE LINE BUFFER PARAMETERS.
       JMP*   .FX            /EXIT.
       .EJECT
/BINARY ARRAY I/O
/  CALLING SEQUENCE -- JMS   .FB
/                      .DSA  ADDRESS OF DIMENSION INFORMATION.
.FB    CAL    0
       LAC*   .FB
       DAC    WD4             /ADDRESS OF WORD 4 OF DIMENSION INFO.
	SPA		/1 MORE LEVEL?
	LAC* WD4		/YES
	DAC WD4		/RESTORE
       TAD    K00003
       DAC  WD1
       LAC*   WD1            /SET WORD COUNTER (CNT) = TWOS COMPLEMENT
       AND    S17777         /   OF THE ARRAY SIZE.
	CMA
       TAD    C00001
       DAC    CNT
       LAC*   WD4            /SET-UP BINARY ELEMENT I/O CALL WITH ARGU-
       DAC    FB2            /   MENT = ARRAY ADDRESS.
FB1    JMS    .FI            /TRANSFER ONE BINARY WORD TO LINE BUFFER.
FB2    .DSA   0
       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
       .EJECT
/BINARY ELEMENT I/O
/  CALLING SEQUENCE -- JMS   .FI, .FJ, .FK, OR .FL
/                      .DSA  ELEMENT ADDRESS (BIT0=1 IF T.V.)
/
.FI    CAL    0              /ENTRY FOR INTEGER DATA.
       LAW    -1
       JMP    FI01
.FJ    CAL    0              /ENTRY FOR REAL DATA.
       LAC    .FJ            /PLACE RETURN ADDRESS IN (.FI).
       DAC    .FI
       LAW    -2
       JMP    FI01
.FK    CAL    0              /ENTRY FOR DOUBLE DATA.
       LAC    .FK            /PLACE RETURN ADDRESS IN (.FI)
       DAC    .FI
K00003 LAW    -3
       JMP    FI01
.FL    CAL    0              /ENTRY FOR LOGICAL DATA.
       LAC    .FL            /PLACE RETURN ADDRESS IN (.FI)
       DAC    .FI
       LAW    -1
FI01   DAC    WCNT           /WORD COUNT=NO. WORDS PER DATA ITEM.
       LAC*   .FI            /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    .FI            /BUMP RETURN ADDRESS
       LAC*   .FH            /BRANCH PER READ OR WRITE.
	SZA
       JMP    FI03
FI02   LAC*   LBADD          /READ--STORE LINE BUFFER WORD IN DATA
       DAC*   DADD           /   LOCATION.
       ISZ    LBADD          /BUMP L.B. ADDRESS AND L.B. WORD COUNT.
       ISZ    LBCNT
       SKP
       JMS    READ           /IF L.B. EMPTY, READ NEXT RECORD.
       ISZ    DADD           /BUMP DATA LOCATION AND DATA WORD COUNT.
       ISZ    WCNT
       JMP    FI02           /MORE WORD(S) TO GO.
       JMP*   .FI            /FINISHED--EXIT.
FI03   LAC*   DADD           /WRITE--STORE DATA WORD IN LINE BUFFER.
       DAC*   LBADD
       ISZ    LBADD          /BUMP L.B. ADDRESS AND L.B. WORD COUNT.
       ISZ    LBCNT
	SKP
       JMS    WRITE          /IF L.B. FULL, WRITE THIS RECORD.
       ISZ    DADD           /BUMP DATA LOCATION AND DATA WORD COUNT.
       ISZ    WCNT
       JMP    FI03           /MORE WORD(S) TO GO.
       JMP*   .FI            /FINISHED--EXIT
       .EJECT
/BINARY I/O CLEANUP
/CALLING SEQUENCE -- JMS    .FG
.FG    CAL    0
       LAC*   .FH            /BRANCH PER READ OR WRITE.
	SNA
       JMP    FZ02
FZ01   DZM*   LBADD          /WRITE--FILL REMAINING UNFILLED WORDS IN
       ISZ    LBADD          /   LINE BUFFER WITH ZEROES.
       ISZ    LBCNT
	SKP
	JMP	.+4
	LAC	LBCNT
	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*   .FG
FZ02   LAC*   IDLOC          /READ--CONTINUE READING PHYSICAL RECORDS
       SPA                   /   UNTIL THE LAST ONE IN THE LOGICAL
       JMP*   .FG            /   RECORD HAS BEEN READ -- THEN EXIT.
       JMS    READ
       JMP    FZ02
       .EJECT
/INITIALIZE BINARY LINE BUFFER PARAMETERS.
/  CALLING SEQUENCE -- JMS   IBLB
IBLB   CAL    0
       LAC    .FN            /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    C00004         /   IN THE LINE BUFFER (.FM-3).
       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 S00017
	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
       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
