Examples of Fortran/Basic Chaining				Page 1

C	SAMPLE FORTRAN PROGRAM USING CHAIN SUBROUTINE.
C
C	THE ONLY TRICKY PART IS THE FILE NAME.  REQUIRE ASCIZ
C	FORMAT, WHICH MEANS THE LAST BYTE OF THE STRING IS A 0.
C	THIS IS HOW LITERALS ARE STORED.  IF INPUT IS FROM A TERMINAL
C	THIS 0 BYTE MUST BE ADDED.  NOTE THAT IF FILNAM BEGINS WITH
C	A 0 BYTE (HIT CR IN THIS PROGRAM), CHAIN SUBROUTINE WILL
C	PROMPT FOR NAME WITH AN *
C
	BYTE FILNAM(30),CORCOM(128)
C
C	IFLAG RETURNED AS ZERO IF RUN ENTRY, <>0 IF CHAIN/CCL
C
	TYPE 999
999	FORMAT(' FORTRAN/BASIC CHAINING DEMONSTRATION PROGRAM'/)
	CALL CCLRUN(IFLAG)
	IF(IFLAG.EQ.0) TYPE 900
900	FORMAT(' PROGRAM TO CHAIN TO? ',$)
	ACCEPT 800, NF,FILNAM
800	FORMAT(Q,30A1)
	FILNAM(MIN0(NF,29)+1)=0		!ASCIZ FORMAT.
	IF(IFLAG.EQ.0) TYPE 905
905	FORMAT(' PROGRAM SIZE IN K WORDS (-1 IF NOT RT11, 0 IF SAME',
	1	' SIZE & RT11)? ',$)
	ACCEPT 810, KORSIZ
	IF(IFLAG.EQ.0) TYPE 910
910	FORMAT(' LINE NUMBER TO ENTER? ',$)
	ACCEPT 810, LINE
810	FORMAT(I10)
	IF(IFLAG.EQ.0) TYPE 920
920	FORMAT(' ENTER CORE COMMON STRING'/' >',$)
	ACCEPT 820, NCHAR,CORCOM
820	FORMAT(Q,128A1)
C
C	READY TO GO
	TYPE 930
930	FORMAT(' CHAINING...'//)
	CALL CHAIN(FILNAM,LINE,CORCOM,NCHAR,KORSIZ)
	STOP 'BLEW IT - CHAIN RETURNED'
	END

Examples of Fortran/Basic Chaining				Page 2

	.TITLE CHAIN

;	FORTRAN CALLABLE ROUTINE FOR CHAINING BETWEEN PROGRAMS IN
;	SAME OR DIFFERENT RUN-TIME SYSTEMS.
;	*** ONLY VALID WITH FOR (NOT F4P) UNDER RT11 EMULATOR ***
;
;	CALL CHAIN(PROG,LINE,CORCOM,NCHAR,CORSIZ)
;		PROG - PROGRAM TO CHAIN TO IN ASCIZ FORMAT.
;		LINE - LINE NUMBER OF CHAIN (I.E., FQNENT VALUE)
;		CORCOM - BYTE ARRAY TO PASS AS CORE COMMON
;		NCHAR - NUMBER OF CHARACTERS IN CORCOM
;		CORSIZ - INTEGER*2	<0 IF PROG NOT RT11 .SAV FILE
;					=0 IF CURRENT SIZE OK
;					>0 EXPAND TO CORSIZ BEFORE
;					   DOING RT11 CHAIN.


	.MCALL .PRINT,.CHAIN,.CSISPC

.SETFQB	=	EMT+360
.DORUN	=	EMT+363
.PRTERR	=	EMT+364
.GETCOR	=	EMT+366
FIRQB	=	402
FQPPN	=	6

PROG	=	2
LINE	=	4
CORCOM	=	6
NCHAR	=	10
CORSIZ	=	12
SPACES	=	40+<400*40>	;TWO ASCII SPACES


CHAIN::
	MOV	SP,R4		;SWITCHES IN FILESPEC PUSHED ON STACK
	TSTB	@PROG(R5)	;A ZERO MEANS LET CSISPC PROMPT
	BEQ	10$
	.CSISPC	#OUTSPC,#DEFEXT,PROG(R5)
	BR	20$
10$:	.CSISPC	#OUTSPC,#DEFEXT,#0
20$:	BCS	BADNAM
	MOV	R4,SP		;RESTORE SP IN CASE SWITCHES GIVEN

	TST	@CORSIZ(R5)	;WHAT KIND OF CHAIN?
	BLT	DORUN		;<0 MEANS WE MUST "RUN" NOT "CHAIN"
	BEQ	RCHAIN		;=0 MEANS CHAIN WITH CURRENT CORE SIZE.

			;MUST NOW EXPAND BEFORE CHAINING.
	MOV	@CORSIZ(R5),R0	;SIZE REQUESTED FOR EXPAND.
	.GETCOR			;PREPARE FOR FAILURE IF EMT BOMBS.
	BCS	TOOBIG		;CARRY BIT SET IF ERROR IN EMT

Examples of Fortran/Basic Chaining				Page 3


RCHAIN:
	MOV	#500,R1		;POINT TO PARAMETER AREA
	MOV	#FILNAM,R0	;GET ADDRESS OF NAME OF PROG
	.SETFQB			;RECOVER A PPN, IF ANY IN ORIGINAL
	MOV	@#FIRQB+FQPPN,@54	;LOAD PPN INTO ONE-SHOT AREA
	MOV	(R0)+,(R1)+	;MOVE IN NAME OF CHAINEE
	MOV	(R0)+,(R1)+
	MOV	(R0)+,(R1)+
	MOV	(R0)+,(R1)+
	CALL	PUTCC		;NOW INSERT CORCOM ARRAY
	.CHAIN
;	.EXIT		;CHAIN WILL NEVER RETURN, EVEN IF FAILURE.

DORUN:
	MOVB	@NCHAR(R5),@#460	;NUMBER OF CHAR IN CORE COMMON
	MOV	#461,R1		;BASIC'S CORE COMMON IS AT 460
	CALL	PUTCC
	MOV	#FILNAM,R0	;ADDRESS OF RT11 TYPE FILEBLOCK
	.SETFQB			;RECOVER A PPN, IF ANY IN ORIGINAL
	MOV	@#FIRQB+FQPPN,@54	;LOAD PPN INTO ONE-SHOT AREA
	MOV	@LINE(R5),4*2(R0)	;LINE NUMBER - VERSION 7.0
	.DORUN			;DO A RSTS .RUN AFTER UNDOING RT11 STUFF
BADNAM:	MOVB	@#FIRQB,R0	;GET THE RETURNED RSTS ERROR CODE.
	.PRTERR			;PRINT THE RSTS ERROR.
	CLR	R0
	.PRINT			;ADD THE CR/LF
	RETURN

PUTCC:
	MOV	CORCOM(R5),R2
	MOV	@NCHAR(R5),R3
1$:	MOVB	(R2)+,(R1)+
	SOB	R3,1$
	RETURN

TOOBIG:	.PRINT	#NOCORE
	RETURN

OUTSPC:	.BLKW	15.
FILNAM:	.BLKW	24.		;IT'S THE 1ST INPUT FILE WE WANT.
DEFEXT:	.WORD	^RSAV,0,0,0
NOCORE:	.ASCIZ	'?BAD CORE SIZE REQUEST'

	.END

Ready
Examples of Fortran/Basic Chaining				Page 4

	.title	cclrun
;
;	call cclrun(iflag)
;		iflag returned as zero if RUN, <>zero if CHAINed.
;		this routine only detects chaining from non-RT11
;		program.  RT11 .CHAINs are detected as shown in
;		RT11 Advanced Programmers Guide., i.e, entry is
;		via an RT11 .CHAIN if following is non-zero:
;			BIT	#400,@#44
;
cclrun::
	clr	@2(r5)		;set iflag to zero
	mov	@#54,r0		;start of RT11 read/write area
	tstb	242(r0)		;this byte <> 0 on ccl/chain entry
	beq	10$
	com	@2(r5)		;set to -1
10$:	return
	.end

!Now some sample runs.  First chaining to ourself, and then to Basic

run chain
FORTRAN/BASIC CHAINING DEMONSTRATION PROGRAM


PROGRAM TO CHAIN TO? chain
PROGRAM SIZE IN K WORDS (-1 IF NOT RT11, 0 IF SAME SIZE & RT11)? 0
LINE NUMBER TO ENTER? 0
ENTER CORE COMMON STRING
>ignored here
CHAINING...


FORTRAN/BASIC CHAINING DEMONSTRATION PROGRAM


PROGRAM TO CHAIN TO? x.bac
PROGRAM SIZE IN K WORDS (-1 IF NOT RT11, 0 IF SAME SIZE & RT11)? -1
LINE NUMBER TO ENTER? 0
ENTER CORE COMMON STRING
>Start at first line number
CHAINING...


Entering from the beginning...
Core common:
START AT FIRST LINE NUMBER

Ready


ty x.bas

10	print 'Entering from the beginning...'
20	goto 200
100	print 'Entered at line 100'
200	print 'Core common:'
210	print sys(chr$(7))
300	end

Ready


Examples of Fortran/Basic Chaining				Page 5


!Now chain to line 100 of x.bac
run chain
FORTRAN/BASIC CHAINING DEMONSTRATION PROGRAM


PROGRAM TO CHAIN TO? x.bac
PROGRAM SIZE IN K WORDS (-1 IF NOT RT11, 0 IF SAME SIZE & RT11)? -1
LINE NUMBER TO ENTER? 100
ENTER CORE COMMON STRING
>Line 100 please...
CHAINING...


Entered at line 100
Core common:
LINE 100 PLEASE...

Ready
!Now chaining to $PIP.SAV with core common.  By saying its not
!an RT11 program, PIP will behave as if a CCL were typed.

run chain
FORTRAN/BASIC CHAINING DEMONSTRATION PROGRAM


PROGRAM TO CHAIN TO? $PIP
PROGRAM SIZE IN K WORDS (-1 IF NOT RT11, 0 IF SAME SIZE & RT11)? -1
LINE NUMBER TO ENTER? 8192
ENTER CORE COMMON STRING
> chain/l
CHAINING...



 Name .Ext    Size    Prot    Date      SY:[9,0]
CHAIN .BAK       6   < 60> 28-Feb-80
CHAIN .MAC       6   < 60> 28-Feb-80
CHAIN .OBJ       1   < 40> 28-Feb-80
CHAIN .LST      11   < 40> 28-Feb-80
CHAIN .MAP       7   < 40> 28-Feb-80
CHAIN .SAV      15C  <104> 28-Feb-80

Total of 46 blocks in 6 files in SY:[9,0]


Ready
Examples of Fortran/Basic Chaining				Page 6



!Note that chain entries with core common to RT11 programs toss
!away stuff before the first space or "/" and then force core
!common into the terminal input buffer, followed by <CR><LF><CTRL/Z>
!CCLRUN subroutine can detect the chain entry.  For example:

old b

Ready


listnh
1	!note the leading space -- rt strips everything in core
2	!common upto the first space or /
5	q$=chr$(13)+chr$(10)
10	i$=sys(chr$(8)+' X.BAC'+q$+'-1'+q$+'100'+q$+

		'from basic to fortran to basic')
15	t$=sys(chr$(7))
16	print len(t$)
17	print t$
20	chain 'chain.sav' 8192
30	end

Ready


run
B     	12:34 PM	28-Feb-80
 47 
 X.BAC
-1
100
from basic to fortran to basic
FORTRAN/BASIC CHAINING DEMONSTRATION PROGRAM


CHAINING...


Entered at line 100
Core common:
FROM BASIC TO FORTRAN TO BASIC

Ready
