perm filename APT11.DEC[KL,SYS] blob sn#209161 filedate 1976-04-03 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00014 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00003 00002	.SBTTL	APT10 PDP-11 PROCESS, 13-AUG-75
C00005 00003	DAHLPD=.
C00007 00004	ACTBCK:	PMSG	<?CKSUM>
C00008 00005	.SBTTL	COMMUNICATIONS ROUTINES
C00010 00006	7$:	TTICHR			GET CONTROL SEQUENCE CHARACTER
C00011 00007	CMERTB:	CMER1
C00012 00008	$COMSND:MOV	#COUTBF,R5
C00014 00009	$CMRTRY:MOV	#COUTBF-4,R0	SETUP MESSAGE POINTER
C00016 00010	$COMLIN:MOV	#CINBF-4,R1	START BUFFER ADDRESS
C00018 00011	3$:	INC	R1		NULL TO END BUFFER
C00020 00012	44$:	TST	R0		DID CHECKSUM COMPUTE TO 0 ?
C00021 00013	$COMENQ:COMCLR			CLEAR COMMUNICATIONS
C00023 00014	$COMCLR:CLR	ENQFLG
C00025 ENDMK
C⊗;
.SBTTL	APT10 PDP-11 PROCESS, 13-AUG-75

ACTFIL:	CMP	#5,LDCNTL	;LOADING ".BIN" ?
	BNE	1$
	MOV	#1,LDCNTL	;YES, ACT10 CONVERTS TO ".A11"
1$:	COMENQ			;REQUEST APT10 SERVICE
	MOV	#$INBUF,R0
	COMCMD			;SEND COMMAND TO REMOTE
	BCS	2$		;C-BIT SET, FILE NOT FOUND
	CLR	ARETRY		;CLEAR RETRY COUNTER
	BR	ACTLD1		;GO TO LOAD PROCESS
2$:	JMP	$NONXF

ACTLD2:	TST	DEVTYP
	BMI	1$		;ACT10
	JMP	LLD2		;DECTAPE/RP04
1$:	COMACK			;ACK PREVIOUS LINE
	BCS	ACTEOF		;C-BIT SET, EOF
	CLR	ARETRY		;CLEAR RETRY COUNTER

ACTLD1:	INC	DEVLC		;COUNT LINE
	MOV	DEVLC,SWR	;DISPLAY
	TST	LDCNTL		;DOING A "HELP" ?
	BPL	1$		;NO
DAHLP=.
	TST	DIAFLG		;DOING DIAMON
	BEQ	30$		;NO
	TST	DEVLC		;YES, FIRST LINE ?
	BNE	31$		;NO
	JMP	DIAFND		;YES, DIAMON FILE FOUND
31$:	JMP	DIARNL		;DIAMON READ NEW LINE
30$:	TST	IFILEF		;DOING AN INDIRECT FILE ?
	BEQ	4$
	JMP	IFILEP		;YES, STORE INPUT
4$:	SETFLG
	HLPPNT			;NORMAL BACKSLASHES
	MOV	#$INBUF,R0	;YES, PRINT INPUT LINE
	TST	DEVTYP
	BPL	41$
	MOV	#CINBF,R0
41$:	PNTAL
	CLR	HLPPNT
	BR	ACTLD2		;REPEAT TILL "EOT"

1$:	JMP	LDPROC		;GO TO LOAD PROCESS

ACTEOF:	COMCLR
DAHLPD=.
	TST	DIAFLG		;DOING DIAMON ?
	BEQ	10$		;NO
	JMP	DIAEOF		;YES, SEND DIAMON END OF FILE
10$:	TST	IFILEF		;INDIRECT/DOUBLE INDIRECT ?
	BNE	21$		;YES
	PCRLF			;NO, JUST HELP
	BR	23$		;BACK TO CONSOLE

21$:	TST	JFILEF		;DOUBLE INDIRECT ?
	BPL	22$		;NO
	TSTB	JFILEF		;PRESENT JUST INDIRECT ?
	BEQ	22$		;YES
	CLRB	 JFILEF		;SET DONE WITH READING "J"
	MOV	#TOUTBF+5000,JFINP	;SET "J" POINTER TO BEGINNING
	JMP	CONSL		;START RUNNING

22$:	MOV	#TOUTBF,IFINP	;SET POINTER TO BEGINNING
	CLRB	IFILEF
23$:	JMP	$CONSL		;GO PROCESS INDIRECT FILE

ACTDON:	COMACK			;ACK TRANSFER BLOCK
	BCC	3$
DADONE=.
	TST	SRTFLG		;SELF START ?
	BEQ	1$
	JMP	$$GO		;YES
1$:	JMP	$CONSL		;NO

3$:	PMSG	<?EOF,ERR>
$$C2:	JMP	$CNTLC

ACTLDC:	PMSG	<?LOAD CHR>
	BR	ACTERR
ACTBCK:	PMSG	<?CKSUM>
	BR	ACTERR

ACTLDF:	PMSG	<?FORMAT>

ACTERR:	PMSG	< ERR: LOAD LINE >
	MOV	DEVLC,R0
	PNTDEC			;PRINT LOAD LINE NUMBER
	PCRLF
	TST	DEVTYP
	BPL	2$		;DECTAPE/RP04
	INC	ARETRY
	CMP	#4,ARETRY	;REACHED RETRY LIMIT ?
	BEQ	1$		;YES
	COMNAK			;NO, NAK MESSAGE & TRY AGAIN
	DEC	DEVLC		;DECREMENT LINE COUNT
	JMP	ACTLD1

1$:	PMSG	<CAN'T LOAD>
2$:	BR	$$C2
.SBTTL	COMMUNICATIONS ROUTINES

$COMACK:INC	MSGNBR		;COUNT MESSAGE
$$CMACK:MOV	#ACKMSG,R5	;MESSAGE ACKNOWLEDGE
	BR	$COMCX

$COMNAK:MOV	#NAKMSG,R5	;MESSAGE NEGATIVE ACKNOWLEDGE
	BR	$COMCX

$COMCMD:CLR	R5		;MESSAGE COMMAND

$COMCX:	MOV	#3,R4		;RETRY 3 TIMES

1$:	TST	R5
	BNE	2$

	COMSND			;COMMAND SEND
	BR	3$

2$:	MOV	R5,R0
	COMCTL			;CONTROL SEQUENCE SEND

3$:	COMLIN			;GET REPLY
	BCS	5$		;ERROR
	BPL	7$		;CONTROL SEQUENCE

	MOV	#136,R3		;NORMAL MESSAGE
	BIT	#1,MSGNBR	;ODD OR EVEN MESSAGE NUMBER
	BEQ	4$
	MOV	#041,R3
4$:	CMP	R3,COMNBR	;CORRECT MESSAGE NUMBER ?
	BNE	$$CMACK		;NO, MUST BE REPEAT
	CLR	R0
41$:	EXIT			;NEW MESSAGE READY FOR PROCESS

5$:	DEC	R4		;EXCEEDED RETRY LIMIT ?
	BNE	6$		;NO, TRY AGAIN
	JMP	$COMERR		;YES, REPORT ERROR & ABORT

6$:	TST	R5
	BNE	61$		;CONTROL REPEAT
	CMP	#-5,R0		;RECIEVED CHECKSUM ERROR ?
	BEQ	61$		;YES, SEND NAK
	COMRTRY			;COMMAND RETRY
	BR	3$

61$:	MOV	#NAKMSG,R5
	BR	2$
7$:	TTICHR			;GET CONTROL SEQUENCE CHARACTER
	CMPB	#'A,R0
	BEQ	41$		;A, ACKNOWLEDGE
	CMPB	#'Z,R0
	BEQ	8$		;Z, END OF TRANSMISSION
	CMPB	#'N,R0
	BNE	71$
	MOV	#-7,R0		;N, NEGATIVE ACKNOWLEDGE
	BR	5$

71$:	MOV	#-10,R0		;UNKNOWN RESPONSE
	BR	5$

8$:	EXITERR			;END OF FILE

$COMERR:PUSH	R0
	PMSG	<?COMM ERR >
	POP	R0
	NEG	R0
	MOV	R0,R1
	PNTOCS
	PNTCI
	", 
	DEC	R1
	SL	R1,1
	MOV	CMERTB(R1),R0
	PNTAL
	JMP	$CNTLC
CMERTB:	CMER1
	CMER2
	CMER3
	CMER4
	CMER5
	CMER6
	CMER7
	CMER10

CMER1:	.ASCIZ	%NO RESPONSE%
CMER2:	.ASCIZ	%LONG LINE%
CMER3:	.ASCIZ	%MSG NBR%
CMER4:	.ASCIZ	%NO CR%
CMER5:	.ASCIZ	%MSG CKSUM%
CMER6:	.ASCIZ	%FORMAT%
CMER7:	.ASCIZ	%NAK%
CMER10:	.ASCIZ	%UNKNOWN%
.EVEN
$COMSND:MOV	#COUTBF,R5
	CLR	R3

1$:	CMPB	(R0),#CR	;REACHED CR YET ?
	BEQ	2$		;YES
	CMPB	(R0),#ALTMOD	;OR ALTMODE ?
	BEQ	12$		;YES, SUBSTITUTE CR

	TSTB	(R0)		;REACHED NULL BYTE ?
	BNE	11$
	MOV	#-6,R0		;YES, INCORRECT MESSAGE FORMAT
	BR	$COMERR

11$:	MOVB	(R0),R2
	ADD	R2,R3		;ACCUMULATE CHECKSUM
	MOVB	(R0)+,(R5)+	;TRANSFER MSG TO OUTPUT BUFFER
	BR	1$

12$:	MOV	#ALTMOD,(R5)+
	BR	22$
2$:	MOVB	(R0)+,(R5)+	;PUT CR IN OUTPUT
22$:	CLRB	(R5)		;FOLLOW WITH NULL

	MOV	#COUTBF-4,R5	;SETUP MESSAGE START
	MOVB	#136,(R5)
	BIT	#1,MSGNBR	;SET UP MESSAGE NUMBER CHAR
	BEQ	21$
	MOVB	#041,(R5)
21$:	INC	R5

	NEG	R3		;NEGATE CHECKSUM

	MOV	R3,R0
	SWAB	R0
	BIC	#177400,R0
	SHIFTR
	  4
	JSR	PC,COMASC
	MOVB	R0,(R5)+	;INSERT 1ST CHECK CHAR

	MOV	R3,R0
	SHIFTR
	  6
	JSR	PC,COMASC
	MOVB	R0,(R5)+	;INSERT 2ND CHECK CHAR

	MOV	R3,R0
	JSR	PC,COMASC
	MOVB	R0,(R5)+	;INSERT 3RD CHECK CHAR
$CMRTRY:MOV	#COUTBF-4,R0	;SETUP MESSAGE POINTER

$COMCTL:TSTB	@$CMTKS		;ANY OLD CHARS ?
	BPL	1$
	MOVB	@$CMTKB,$TTYIN	;YES, GET GET OF IT
	BR	$COMCTL

1$:	TSTB	@$CMTPS		;WAIT TILL OUTPUT IS READY
	BPL	$COMCTL

	MOV	#2,R1		;SEND 2 SYNC CHARACTERS
2$:	MOVB	#SYN,@$CMTPB
3$:	TSTB	@$CMTPS
	BPL	3$
	DEC	R1
	BNE	2$

4$:	MOVB	(R0)+,R1	;GET MESSAGE CHAR
	BEQ	6$		;IF NULL, DONE

	MOVB	R1,@$CMTPB	;SEND CHAR
5$:	TSTB	@$CMTPS		;WAIT TILL OUTPUT READY
	BPL	5$
	BR	4$		;SEND TILL NULL

6$:	EXIT			;COMPLETED

COMASC:	BIC	#177700,R0	;KEEP 6 BITS
	CMP	R0,#74		;LEAVE 75,76,77 ALONE
	BGT	1$
	BIS	#100,R0		;SET BIT 7 FOR ASCIIZE
1$:	RTS	PC
$COMLIN:MOV	#CINBF-4,R1	;START BUFFER ADDRESS
	CLR	$TTYTIM		;CLEAR TIMEOUT
	CLR	R5		;CLEAR IN SYNC FLAG

1$:	JSR	PC,C10COP	;PERFORM CLOCK OPERATIONS
	CMP	$TTYTIM,#<20.*60.>	;20 SECS
	BGT	90$		;TIMED OUT

	TSTB	@$CMTKS		;COMM IN FLAG SET ?
	BMI	2$		;YES

	JSR	PC,$PTTYC	;ANY OPERATOR INTERRUPT ?
	BR	1$		;NO

2$:	MOVB	@$CMTKB,(R1)	;MOVE CHAR TO BUFFER
	BICB	#200,(R1)
	TSTB	(R1)
	BEQ	1$		;IGNORE NULLS

	CMPB	(R1),#SYN	;SYNC CHAR ?
	BEQ	21$		;YES

	TST	R5		;RECIEVED SYNC YET ?
	BEQ	1$		;NO, DUMP GARBAGE CHARS

	CMPB	(R1),#ALTMOD
	BEQ	3$		;ALTMODE, CONTROL SEQUENCE

	CMPB	(R1),#'$	;DOLLAR, PDP-10 SENDS THIS FOR ALTMODE
	BNE	22$
	CMP	R1,#CINBF	;LEGAL ONLY IF IN CONTROL SEQUENCE
	BLT	3$

22$:	CMPB	(R1),#LF
	BEQ	4$		;LF, MESSAGE SEGMENT

	INC	R1
	CMP	R1,#CINBF+140.
	BLE	1$		;STILL ROOM
	BR	91$		;NO, LINE TOO LONG

21$:	MOV	#-1,R5		;SYNC, SET IN SYNC FLAG
	BR	1$
3$:	INC	R1		;NULL TO END BUFFER
	CLRB	(R1)
	MOV	R1,$INPTR	;SETUP INPUT POINTERS
	MOV	#CINBF-4,$INPTC
	EXIT			;CONTROL SEQUENCE RETURN

4$:	INC	R1
	CLRB	(R1)
	MOV	R1,$INPTR	;SETUP INPUT POINTERS
	MOV	#CINBF-4,R1
	CMPB	#041,(R1)
	BEQ	41$
	CMPB	#136,(R1)
	BEQ	41$
	BR	92$		;MESSAGE NUMBER INCORRECT

41$:	MOVB	(R1)+,COMNBR	;SAVE MESSAGE NUMBER
	CLR	R0		;SETUP FOR MESSAGE CHECKSUM
	MOV	#3,R5		;CHARS 2,3,4 ARE CHECKSUM

42$:	SL	R0,6
	MOVB	(R1)+,R4	;GET 1ST CHECK CHAR
	BIC	#100,R4		;CLEAR ASCIIZE BIT
	BIS	R4,R0		;INSERT IN 16 BIT CHECKSUM
	DEC	R5
	BGT	42$		;DO 3 CHARS

43$:	CMPB	(R1),#CR	;REACHED EOL ?
	BEQ	44$		;YES
	TSTB	(R1)		;PAST EOL WITHOUT CR ?
	BEQ	93$		;YES, NO CR ERROR

	MOVB	(R1)+,R3
	ADD	R3,R0		;ACCUMULATE CHECKSUM
	BR	43$
44$:	TST	R0		;DID CHECKSUM COMPUTE TO 0 ?
	BNE	94$		;NO, CHECKSUM ERROR

	MOV	#CINBF,$INPTC	;MESSAGE SEGMENT OK
	BIS	#NBIT,14(SP)	;SET NORMAL MESSAGE INDICATOR
	EXIT

90$:	MOV	#-1,R0		;NO RESPONSE ERROR
	BR	99$

91$:	MOV	#-2,R0		;LINE TOO LONG ERROR
	BR	99$

92$:	CMPB	#'?,(R1)	;IS MESSAGE NUMBER QUESTION MARK ?
	BEQ	COMQ		;YES, HOST ERROR
	MOV	#-3,R0		;MESSAGE NUMBER CHAR ERROR
	BR	99$

93$:	MOV	#-4,R0		;NO CARRIAGE RETURN ERROR
	BR	99$

94$:	MOV	#-5,R0		;MESSAGE CHECKSUM ERROR

99$:	EXITERR			;ERROR EXIT, C-BIT SET, CODE IN R0

COMQ:	$PMSG			;PRINT ERROR REPLY
	 CINBF-4
	JMP	$CNTLC
$COMENQ:COMCLR			;CLEAR COMMUNICATIONS
	SETFLG
	  ENQFLG		;SET APT10 IN PROGRESS
	MOV	#3,R4
10$:	CLR	MSGNBR		;INITIALIZE MESSAGE NUMBER
	MOV	#ENQMSG,R0
	COMCTL			;SEND "ENQ" MESSAGE

	COMLIN			;WAIT FOR REPLY
	BCS	1$		;ERROR, CODE IN R0
	BMI	3$		;NORMAL MESSAGE REPLY ?
	TTICHR
	CMPB	#'A,R0		;A, ACKNOWLEDGE
	BNE	1$
	EXIT			;ACKED, GO AHEAD

1$:	TST	R0		;IS REPLY CODE NEGATIVE ?
	BMI	4$		;YES, COMLIN ERROR

	CMPB	#'Z,R0		;IS REPLY EOT, WAIT ?
	BNE	3$		;NO

	CLR	$TTYTIM		;YES, WAIT 10 SECONDS
2$:	JSR	PC,$PTTYC
	JSR	PC,C10COP
	CMP	$TTYTIM,#<10.*60.>
	BLE	2$
	BR	$COMENQ		;THEN TRY AGAIN

3$:	PMSG	<?APT10 ENQ>
	JMP	$CNTLC

4$:	DEC	R4
	BNE	10$		;RETRY
	JMP	$COMERR		;COMMUNICATIONS ERROR

$COMEOT:MOV	#EOTMSG,R0
	COMCTL
	EXIT
$COMCLR:CLR	ENQFLG
	MOV	#CANMSG,R0
	COMCTL
	MOV	#100000,R1
1$:	TSTB	@$CMTKS		;ANY INPUT IN PROGRESS ?
	BPL	2$
	MOVB	@$CMTKB,R0	;IF SO, GET RID OF IT
	BR	1$
2$:	DEC	R1
	BNE	1$		;A LITTLE DELAY
	EXIT

ENQMSG:	.BYTE	'E,33,0
ACKMSG:	.BYTE	'A,33,0
NAKMSG:	.BYTE	'N,33,0
CANMSG:	.BYTE	'C,33,0
EOTMSG:	.BYTE	'Z,33,0

	.EVEN

IFILEP:	MOV	#$INBUF,R0	;SETUP POINTERS
	TST	DEVTYP
	BPL	10$
	MOV	#CINBF,R0
10$:	MOV	IFINP,R1
1$:	MOVB	(R0)+,(R1)+	;TRANSFER CHARS TO STORAGE
	BNE	1$		;TILL NULL
	CLRB	(R1)		;THEN STORE 2ND NULL
	MOV	R1,IFINP	;RESAVE POINTER
	CMP	R1,#TOUTBF+10000-200
	BLE	2$		;EXCEEDED BUFFER ROOM ?
	JMP	$LINERR		;YES
2$:	JMP	ACTLD2		;REPEAT TILL EOF