	.TITLE	LINKAL
/
/  26 OCT 70
/
/  THIS PROGRAM WILL TRANSMIT ALL OF THE ASCII FILES ON .DAT 2
/  TO THE 360/75 VIA THE DATA LINK
/
	.IODEV	2	/DK6
/
FILPNT=10
INPNT=11
OUTPNT=12
.SCOM=100
/
	.GLOBL	TRANFR,PACK,UNPACK
/
START	JMS*	TRANFR	/INITIALIZE LINK
	JMP	.+2
	%START
	.INIT	2,0,START /INITIALIZE DK6 FOR INPUT
	.TRAN	2,0,100,DIRECT,256	/READ IN DIRECTORY BLOCK
	.INIT	-3,1,START
	.WRITE	-3,2,ENERG,0  /TELL WHEN LINK ENERGIZED
	LAW	-70
	DAC	FILCNT	/ # OF ENTRIES IN DIRECTORY BLOCK
	LAC	(DIRECT+37
	DAC*	(FILPNT
	.EJECT
SCOM3	LAC*	(.SCOM+3
	CMA
	TAD*	(.SCOM+2
	LRSS	6	/COMPLEMENT OF # OF 64 WORD
	DAC	HOWMNY	/LINES WE CAN STORE IN MEMORY
	DAC	LINCNT
	TAD*	(.SCOM+3
	DAC*	(.SCOM+3	/CHANGE .SCOM+3
	TAD	(1
	DAC	TABLE	/ADDRESS OF BEGINNING OF TABLE
	LAC*	(.SCOM+2
	DAC	PCK+2	/SET OUTPUT POINTER
	LAC	(JMP .+2
	DAC	SCOM3
	.WAIT	2
GETNAME	LAC*	FILPNT
	SNA
	JMP	NONAME	/THIS SPOT HAS NO FILE NAME IN IT
	DAC	NAME
	LAC*	FILPNT	/TRANSFER FILE NAME TO BLOCK USED
	DAC	NAME+1	/ON .SEEK
	LAC*	FILPNT
	DAC	NAME+2
	LAC*	FILPNT	/GET BLOCK ADDRESS
	AND	(1777
	DAC	TRYBLK
TRYBLK=.+2
	.TRAN	2,0,0,LINE,32  /INPUT PART OF 1ST BLOCK OF FILE
	.WAIT	2
	LAC	LINE
	AND	(7	/CHECK FOR ASCII
	SAD	(2
	SKP
	JMP	NXTFIL	/NOT ASCII.  TRY NEXT FILE
	.EJECT
/  FILE IS ASCII.  ANNOUNCE FILE NAME ON TT AND BEGIN UNPACKING
/
	LAC	(LINE-1	/SET POINTER
	DAC*	(INPNT
	LAC	(NAME	/GET ADDRESS OF FILE NAME
	DAC	NAMAD
	LAW	-2
	DAC	NAMCNT	/COUNTERS FOR NAME & EXT
	DAC	TABCNT
LOOPNA	LAW	-3	/3 CHARACTERS PER WORD IN .SIXBT
	DAC	CCNT
	LAC*	NAMAD	/GET WORD
	ISZ	NAMAD
	LMQ
	JMS	SIXTO7	/CONVERT FROM 6 TO 7 BIT ASCII
	ISZ	CCNT
	JMP	.-2
	ISZ	NAMCNT
	JMP	LOOPNA	/GO FOR NEXT WORD IF 1ST TIME
	ISZ	TABCNT
	SKP
	JMP	TELNAME	/JUMP  2ND TIME THRU
	LAW	-1
	DAC	NAMCNT	/MAKE IT RUN OUT NEXT TIME AGN
	LAW	40
	DAC*	INPNT	/INSERT SPACE BETWEEN NAME & EXT
	JMP	LOOPNA
/
TELNAME	LAW	15	/ADD CARRIAGE RETURN ON END
	DAC*	INPNT
	LAC	(LINE
	DAC	PK+1
	LAC	(TYPE+2
	DAC	PK+2
	.WAIT	-3	/WAIT UNTIL PREVIOUS NAME TYPED OUT
PK	JMS*	PACK
	0; 0
	SMA
	JMP	PK
	.WRITE	-3,2,TYPE,0  /WRITE NAME OF FILE BEING UNPACKED
/
	.SEEK	2,NAME
	JMS	FORM	/SEND FORM FEED TO 360
	JMS	FORM	/SEND TWO
READ	.READ	2,2,LINE,52
	LAW	-170
	DAC	CHRCNT	/SET CHARACTER COUNTER TO -120 (DECIMAL)
	LAW	-10
	DAC	TABCNT	/RESET TAB COUNTER FOR 8 SPACE TABS
	LAC	(IN-1
	DAC*	(INPNT	/SET INPUT AND OUTPUT POINTERS
	TAD	(1
	DAC	UNPCK+2
	LAC	(OUT-1
	DAC*	(OUTPNT
	LAC	(LINE+2
	DAC	UNPCK+1
	.WAIT	2
	LAC	LINE
	AND	(7
	SAD	(5	/CHECK FOR END OF FILE
	JMP	NXTFIL	/EOF.  GO TO NEXT FILE
/
UNPCK	JMS*	UNPACK
	0; 0
	SMA
	JMP	UNPCK
	ISZ	CHRCNT	/COUNT CARRIAGE CONTROL CHARACTER
	LAC*	INPNT
	SAD	(14	/FORM FEED?
	LAW	61	/CARRIAGE CONTROL IS "1"
	SAD	(12	/LINE FEED?
BL	LAW	40	/CARRIAGE CONTROL IS "BLANK"
	SMA
	JMP	.+3
	DAC*	OUTPNT
	JMP	LOOP
	LAW	-1
	TAD*	(INPNT	/1ST CHARACTER WAS NOT CARRIAGE CONTROL
	DAC*	(INPNT	/MUST RESET AUTO INDEX
	JMP	BL
	.EJECT
LOOP	LAC*	INPNT
	SNA
	JMP	LOOP	/IGNORE NULL CHARACTERS
	SAD	(11	/TAB?
	JMP	TAB
	SAD	(15	/CARRIAGE RETURN?
	JMP	LINEND
	SAD	(175	/ALT MODE?
	JMP	LINEND
	DAC*	OUTPNT
	ISZ	TABCNT
	SKP
TABDONE	JMS	NEWTAB	/RESET TAB COUNTER
	ISZ	CHRCNT	/IS LINE TOO LONG?
	JMP	LOOP
	JMP	LINFUL	/LINE OVERFLOW
/
TAB	LAW	40	/SPACES FOR TABS
	DAC*	OUTPNT
	ISZ	TABCNT
	SKP
	JMP	TABDONE
	ISZ	CHRCNT	/MUST INCREMENT CHARACTER COUNTER
	JMP	TAB+1
	JMP	LINFUL
/
NEWTAB	XX
	LAW	-10	/8 DECIMAL
	DAC	TABCNT
	JMP*	NEWTAB
	.EJECT
LINEND	LAW	-7
	DAC	TABCNT
	LAW	40
	DAC*	OUTPNT	/ADD 7 SPACES TO END OF LINE FOR
	ISZ	CHRCNT	/PACK & 360/75 TRUNCATION
	SKP
	JMP	LINFUL
	ISZ	TABCNT
	JMP	.-5
LINFUL	LAC	(170
	TAD	CHRCNT	/CALCULATE NUMBER OF CHARACTERS IN LINE
	CLL
	IDIV
	5
	CMA
	TAD	(1
	TAD*	(OUTPNT	/BACK AUTO-INDEX BY REMAINDER OF
	DAC*	(OUTPNT	/DIVISION BY 5
	LACQ
	CMA
	TAD	(1	/CALCULATE LOOP PARAMETER FOR PACK
	DAC	CHRCNT
	CLL
	MUL\LMQ!EAE	/PERFORM MODULO 5 TRUNCATION
	5		/MULTIPLICAND ALREADY IN MQ
	LACQ
	DAC*	TABLE
	ISZ	TABLE
	LAC	(OUT
	DAC	PCK+1
PCK	JMS*	PACK
	0; 0
	ISZ	CHRCNT
	JMP	PCK
	ISZ	LINCNT	/COUNT NUMBER OF LINES STORED IN CORE
	JMP	READ
	JMS	SEND
	JMP	READ
	.EJECT
SEND	XX
	LAC*	(.SCOM+2
	DAC	%LINE	/RESET POINTER FOR TRANSFER
	DAC	PCK+2	/AND FOR NEXT GROUP OF LINES
	LAC	HOWMNY
	DAC	LINCNT	/RESET LINE COUNTER
	TAD	TABLE
	DAC	TABLE	/AND TABLE POINTER
SEND1	LAC*	TABLE
	AND	LM4	/MAKE EVEN MULTIPLE OF 4
	DAC	NUMBER	/GET NUMBER OF CHARACTERS IN LINE
	JMS*	TRANFR	/SEND LINE TO 360
	JMP	.+6
	%SAL
	NUMBER
	%LINE
	NCOUNT
	ERROR
ANNOUNC	.INIT	-3,1,KRUNCH
	.WRITE	-3,2,BEGIN,4  /WORD COUNT MUST BE 4 FOR
LM4=.-1			/THIS LITERAL
	LAC	(JMP .+2	/ANNOUNCE WHEN TRANSFER BEGINS
	DAC	ANNOUNCE
	LAW	-2
	TAD	ERROR	/CHECK FOR SERIOUS ERRORS
	SMA
	JMP	KRUNCH	/IF(ERROR.GE.2) GO TO KRUNCH
	LAC*	TABLE
	RCL
	IDIV
	5
	LACQ
	TAD	%LINE	/CALCULATE NEXT POINTER
	DAC	%LINE	/UPDATE LINE POINTER
	ISZ	TABLE
	ISZ	LINCNT
	JMP	SEND1	/LOOP UNTIL LINES EXHAUSTED
	LAC	HOWMNY
	DAC	LINCNT	/RESET LINE COUNTER & TABLE POINTER
	TAD	TABLE
	DAC	TABLE
	JMP*	SEND
	.EJECT
FORM	XX
	LAC	FF
	DAC*	PCK+2	/PUT FORM FEED & 4 SPACES IN BUFFER
	ISZ	PCK+2
	LAC	FF+1
	DAC*	PCK+2
	ISZ	PCK+2
	LAC	(5
	DAC*	TABLE	/INDICATE 5 CHARACTERS IN LINE
	ISZ	TABLE
	ISZ	LINCNT
	JMP*	FORM
	JMS	SEND	/SEND GROUP OF LINES TO 360 IF NECESSARY
	JMP*	FORM
/
FF	.ASCII	'1    '	/"1" AND 4 SPACES - FORM FEED
/
/
SIXTO7	XX
	LLS	6	/SHIFT IN CHARACTER
	AND	(77	/CHOP OFF GARBAGE
	SNA
	LAW	40	/CONVERT BLANK TO SPACE
	LLS	14
	SMA!CLL
	STL
	LRS	14	/EXTEND TO 7 BITS
	DAC*	INPNT	/PUT IN BUFFER
	JMP*	SIXTO7
/
/
	.REPT	3
NONAME	LAC*	FILPNT	/STEP PAST EMPTY DIRECTORY ENTRY
NXTFIL	.CLOSE	2	/CLOSE 2 TO PREVENT IOPS ERROR
	ISZ	FILCNT	/INCREMENT FILE COUNTER
	JMP	GETNAME
	JMS	FORM	/END LISTING WITH FORM FEED
	LAC	LINCNT	/CALCULATE HOW MANY LINES WE HAVE
	CMA
	TAD	(1
	TAD	HOWMNY	/READY TO TRANSFER
	SNA
	JMP	KRUNCH	/MIGHT BE 0
	DAC	HOWMNY
	JMS	SEND	/SEND THEM
KRUNCH	JMS*	TRANFR	/TURN OFF LINK WHEN FILE COUNTER RUNS
	JMP	.+2	/OUT OR ON ERROR
	%QUIT
	.EJECT
	.INIT	-3,1,EXIT
WRITE	.WRITE	-3,2,FINISH,0
	.WAIT	-3
EXIT	.EXIT		/LEAVE WHEN FINISHED
/
ENERG	EN-.*400+2
NAMAD
	.ASCII	'***   LINK ENERGIZED   ***'<15>
EN=.
/
BEGIN	BE-.*400+2
NAMCNT
	.ASCII	'*** TRANSFER BEGINNING ***'<15>
BE=.
	.EJECT
FINISH	FI-.*400+2
CCNT
	.ASCII	'*** TRANSFER COMPLETE  ***'<15>
FI=.
/
/  CONSTANTS AND BUFFER AREA
/
%START	.ASCII	'START'
%QUIT	.ASCII	'QUIT '
%SAL	.ASCII	'SAL  '
NUMBER	0
	020060		/WORDS FOR PDP-9 FORTRAN
	000000
	000000
%LINE	LINE
NCOUNT;ERROR;CHRCNT;TABCNT;FILCNT;TABLE;LINCNT;HOWMNY
NAME	.BLOCK	3
LINE	.BLOCK	64
	.ASCII	<15>	/IN CASE LINE IS TOO LONG
IN	.BLOCK	200
OUT	.BLOCK	200
DIRECT	.BLOCK	400
TYPE	002002
	.BLOCK	7
	.EJECT
	.END	START
