Google
 

Trailing-Edge - PDP-10 Archives - BB-K818A-BM_1981 - sources/gigi.mac
There are 2 other files named gigi.mac in the archive. Click here to see a list.
	Title	GIGI - Macro support routines for GIGI software
	Subttl	Assembly switches

	Tops20=4		; Version of monitor that we are using
	Eos=0			; End of string symbol

; Check for correct settings

Define Chklow (Switch,low) <	;
	Ifl <Switch-low>,<Badsw Switch,\Switch>>

Define Badsw (Switch,Value) <
	..ERR=1
	Printx ?Can not support version Value of Switch
 >

	..ERR=0

	Chklow	Tops20,3

Ifn <..err>,<
	Pass2			; Abort
	End>
	Subttl	Introduction -- Directives


	Search	MONSYM,MACSYM	; Standard 20 universals
	.Requi	SYS:MACREL	; Support code
	Sall			; Nice and neat listing
	.Direc	.Xtabm		; Give macro a break

Comment \

   GIGI is  a  collection  of  routines  written  to  support  FORTRAN
programs.  Its  main purpose  is to  provide a  easy method  for  said
programs to pass commands to the GIGI terminal.

   These routines make some assumptions as to the arguments passed and
FORTRAN conventions. They are:

	o All strings end with the null byte.

	o All strings are in ASCII, one char per word.

	o All function calls are integer in type, and return
	  their value in register zero.

The following is a list of all subroutines/function defined:  

	INTEGER FUNCTION getln (inbuf, maxlen, ecflag)
	SUBROUTINE putln (outbuf, len)
	SUBROUTINE escseq (str)
	SUBROUTINE ttnorm
	INTEGER FUNCTION prmtgt (outbuf, len, inbuf, maxlen)
	INTEGER FUNCTION ttin (ecflag)
	FUNCTION ttinnw (ecflag)
	SUBROUTINE escseq (str)

\
	Subttl	Introduction -- Table of contents

;                  Table of Contents for GIGI.MAC
;
;                                 Section                   Page
;
;    1. Assembly switches . . . . . . . . . . . . . . . . .    1
;    2. Introduction 
;         2.1    Directives . . . . . . . . . . . . . . . .    2
;         2.2    Table of Contents. . . . . . . . . . . . .    3
;         2.3    Edit History . . . . . . . . . . . . . . .    4
;    3. Definitions 
;         3.1    Accumulators . . . . . . . . . . . . . . .    5
;    4. Macros 
;         4.1    Jsys (Call to monitor) . . . . . . . . . .    6
;         4.2    Sbr (Subroutine definition). . . . . . . .    7
;         4.3    Fatal (Abort message). . . . . . . . . . .    8
;    5. Storage 
;         5.1    Impure . . . . . . . . . . . . . . . . . .    9
;    6. Subroutines 
;         6.1    Initialization of, . . . . . . . . . . . .   10
;         6.2    TTNORM (Restore user environment). . . . .   11
;         6.3    Function GETLN (Read a line) . . . . . . .   12
;         6.4    Function PRMTGT (prompt then get line) . .   13
;         6.5    Function TTIN (Get a character). . . . . .   14
;         6.6    Function TTINW (get character if availabl.   15
;         6.7    PUTLN (Print a line) . . . . . . . . . . .   16
;         6.8    ESCSEQ (Send an escape sequence) . . . . .   17
;         6.9    Exit from, . . . . . . . . . . . . . . . .   18
;    7. Support 
;         7.1    Echo on and off. . . . . . . . . . . . . .   19
;    8. End of source . . . . . . . . . . . . . . . . . . .   20
	Subttl	Introduction -- Edit History

Comment \

Edit #	Date		Description
------	-------		---------------------------------------------------
   100	26 Aug 80	Creation of program

\
	Subttl	Definitions -- Accumulators

; Registers
	
	FV=0			; Return the value of the function here

	A=1
	B=2
	C=3
	D=4
	E=5

	W1=6
	W2=7
	W3=10

	T1=11			; Work register for subroutines
	T2=12

	CX=14

	.SAC=15			; Super scratch register
	
	ARG=16

	P=17
	Subttl	Macros -- Jsys (Call to monitor)

; Version 4 of the monitor appends a percent sign after the JSYS name
; thus to be compatible with older version do: JSYS (Foo) instead of
; foo


Define JSYS (foo,erradr<Jshlt0##>) <
 Ife <tops20-4>,<foo'%>
 Ife <Tops20-3>,<foo>
 Erjmp erradr
>
	Subttl	Macros -- Sbr (Subroutine definition)

Define Sbr (Nam) <
	Entry	Nam
Nam:
	Movem	P,Svp		; Save stack pointer
	Hlre	W1,-1(Arg)	; Get number of arguments passed
	Movms	W1		;   ...
	Movem	W1,Argcnt	;   ...
	Skipn	Init		; Have we inited?
	 Call	Initit		;   Nope

>
	Subttl	Macros -- Fatal (Abort message)

Define Fatal ($Str) <
	Jrst	[Tmsg (<$Str
>)
		 Haltf]
>
	Subttl	Storage -- Impure

Svp:	Block	1		; State of stack at call
Argcnt:	Block	1		; Number of arguments passed
Erradr:	Block	1		; Points to error code addr
Prompt:	Block	15		; Buffer for a prompt

IJFNP:	EXP	IJFNST-1	; Points to current input JFN
	EXP	-1		; Delimit list
IJFNST:	BLOCK	17		; Should be a good size
	EXP	01		; qed

Init:	Exp	0		; Initialized flag

; Parameters saved at init time

TTMODE:	BLOCK	1		; Terminal mode word
CCOC:	BLOCK	2		; Control Character Output Control

; TEXTI parameter block

TEXTPB:	EXP	6		;;.RDCWB;; Count of words
	BLOCK	1		;;.RDFLG;; Flag bits
	.PRIIN,,.PRIOU		;;.RDIOJ;; Input output devices
	BLOCK	1		;;.RDDBP;; Output buffer
	BLOCK	1		;;.RDDBC;; Bytes in output buffer
	BLOCK	1
	BLOCK	1		;;.RDRTY;; CNTR-R buffer
	Subttl	Subroutines -- Initialization of,

; This is a one time init. It saves modes that we change.

	ENTRY	INITIT
INITIT:	SETOM	INIT		; Tell rest of world

	MOVEI	A,.PRIIN	; Get the JFN mode word
	JSYS	(RFMOD)
	MOVEM	B,TTMODE

	JSYS 	(RFCOC)		; Get CCOC words
	DMOVEM	B,CCOC

; Now let's setup things as we wish them to be

	MOVE	B,TTMODE
	TXO	B,TT%MFF!TT%TAB!TT%LCA!TT%PGM
	TXZ	B,TT%LEN!TT%WID!TT%UOC!TT%LIC
	JSYS	(STPAR)
	JSYS	(SFMOD)

	MOVE	B,[BYTE (2)2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
	MOVE	C,B
	JSYS	(SFCOC)

	RET
	SUBTTL	Subroutines -- TTNORM (Restore user environment)

; Subroutine restore
;
;	This routine will restore everything (i.e. that we have control
; over) that we have changed. The initial state of the environment is
; saved in INITIT.

	SBR	TTNORM

	MOVEI	A,.PRIOU
	MOVE	B,TTMODE
	JSYS	(SFMOD)
	JSYS	(STPAR)

	DMOVE	B,CCOC
	JSYS	(SFCOC)
	RET
	Subttl	Subroutines -- Function GETLN (Read a line)

; INTEGER FUNCTION getln (inbuf, maxlen, ecflag, {ucflag})
;
; 	  Read a line from the terminal. If ecflag is 1 echo input.
;	Returns the number of character inputted as the function's
;	value. If there is a forth argument, then if it is non zero
;	convert all input to upper case. Otherwise pass the case the
;	user typed in.

	SBR	GETLN

	SKIPE	W1,@2(ARG)	; Get state of echo flag
	 CALL	ECHON		;   q.e.d.
	SKIPN	W1
	 CALL	ECHOFF

	MOVE	W1,0(ARG)	; Get address of buffer
	HRLI	W1,(POINT 36,)	; Make it a pointer
	MOVEM	W1,TEXTPB+.RDDBP

	MOVE	W1,@1(ARG)	; Get buffer max
	MOVEM	W1,TEXTPB+.RDDBC

	MOVX	W1,RD%BEL!RD%CRF!RD%JFN
	MOVE	T1,ARGCNT	; Get # of arguments
	CAIL	T1,4		; If four or more then we have upper case flag
	 JRST	[SKIPE @3(ARG)
		  TXO W1,RD%RAI
		 JRST GETLN1]

GETLN1:	MOVEM	W1,TEXTPB+.RDFLG ; Break on CRLF of LF only, and return
				;    just a LF

	MOVEI	A,TEXTPB
	TEXTI			; Do the input
	 JFCL
	
	MOVE	FV,@1(ARG)	; Get buffer size
	SUB	FV,TEXTPB+.RDDBC ; Subtract bytes remaining, giving
	SOS	FV,		;    number of characters read

	MOVEI	CX,EOS		; Get end of string delimiter
	DPB	CX,TEXTPB+.RDDBP

	RET
	Subttl	Subroutines -- Function PRMTGT (prompt then get line)

; Integer function prmtgt (prompt, len, inbuf, maxlen)

; This entry  takes  advantage that  some  operating systems  allow  a
; terminal input  request to  be specified  at the  same time  as  the
; appropriate prompt message. The main advantage is that certain kinds
; of line  editing,  e.g.,  line  deletetion, can  then  result  in  a
; reissuing of the prompt.

; This call is otherwise  functionally equivalent to  a call to  putln
; followed by  a call  to  to getln,  with the  obvios  correspondence
; between arguments. Input characters are always echoed.

	SBR	PRMTGT

	CALL	ECHON

	MOVE	A,0(ARG)	; Get address of prompt
	HRLI	A,(POINT 36,)
	HRROI	B,PROMPT	; Destination
	MOVEM	B,TEXTPB+.RDRTY
	MOVN	C,@1(ARG)
	JSYS	(SIN)
	SETZ	C,
	IDPB	C,B		; Put in the null byte

	HRROI	A,PROMPT	; Print the prompt
	JSYS	(PSOUT)

	MOVE	W1,2(ARG)	; Get address of buffer
	HRLI	W1,(POINT 36,)
	MOVEM	W1,TEXTPB+.RDDBP

	MOVE	W1,@3(ARG)	; Get buffer max
	MOVEM	W1,TEXTPB+.RDDBC

	MOVX	W1,RD%BEL!RD%CRF!RD%JFN
	MOVEM	W1,TEXTPB+.RDFLG ; Break on CRLF of LF only, and return
				;    just a LF

	MOVEI	A,TEXTPB
	TEXTI			; Do the input
	 JFCL
	
	MOVE	FV,@3(ARG)	; Get buffer size
	SUB	FV,TEXTPB+.RDDBC ; Subtract bytes remaining, giving
	SOS	FV,		;    number of characters read

	MOVEI	CX,EOS		; Get end of string delimiter
	DPB	CX,TEXTPB+.RDDBP

	RET
	Subttl	Subroutines -- Function TTIN (Get a character)

; Function TTIN (ecflag)
; 
; This  function  returns   the  ASCII  code for  the  next  character
; available from the terminal.  That character is returned as soon  as
; it is  typed;  this  method  of input  is  not  suitable  if  normal
; line-editing functions are  desired. If no  character is  available,
; the program will  be hung until  one is obtained.  If integer  value
; "ecflag" is zero, the character is not echoed to the user.

	SBR	TTIN

TTIN01:	SKIPE	W1,@0(ARG)	; Get state of echo flag
	 CALL	ECHON		;   q.e.d.
	SKIPN	W1
	 CALL	ECHOFF

	JSYS	(PBIN)		; Get a character
	MOVE	FV,A		; Return it to caller

	RET
	Subttl	Subroutines -- Function TTINW (get character if available)

; Integer Function TTINNW (ecflag)

; This function tests  to see  if a  character is  available from  the
; terminal. If no character is available it returns a zero.  Otherwise
; it will return the ASCII value of the character.

	SBR	TTINNW

	MOVEI	A,.PRIIN	; Test if character is waiting
	SIBE			; Empty?
	 JRST	TTIN01		;   Nope get it
	SETZ	FV,		; Return zero

	RET
	Subttl	Subroutines -- PUTLN (Print a line)

; SUBROUTINE putln (outbuf, len)
;
;	Putln will output the buffer onto the primary output device.
;  Note that there is no auto-wrap or character translation setup.
;

	SBR	PUTLN

	MOVEI	A,.PRIOU
	MOVE	B,0(ARG)	; Get address of output buffer
	HRLI	B,(POINT 36,)
	MOVN	C,@1(ARG)	; Number of bytes to output
	JSYS	(SOUT)
	RET
	Subttl	Subroutines -- ESCSEQ (Send an escape sequence)

; SUBROUTINE escseq (str)
;
; This will transmit the escape character, and tehn transmit the contents
; of string "str" (which is presumed to be an escape sequence).
;

	SBR	ESCSEQ

	MOVEI	A,.CHESC	; Output an escape character
	JSYS	(PBOUT)
	MOVEI	A,.PRIOU
	MOVE	B,0(ARG)	; Get address of output buffer
	HRLI	B,(POINT 36,)
	SETZ	C,		; Assume it ends with a null
	JSYS	(SOUT)
	RET
	Subttl	Subroutines -- FILEIN (Read an ascii record)

; Integer function FILEIN (inbuff, maxlen, eof)
;
; Read an ASCII record, returning the CRLF if maxlen not exceeded. If EOF
; is reached the argument eof becomes non-zero and the file is closed.

	SBR	FILEIN

	SKIPGE	A,@IJFNP	; Get the current input JFN
	 Fatal	<There is no input file open>

	MOVE	B,0(ARG)	; Get address of buffer
	HRLI	B,(POINT 36,)	; Make it a pointer
	MOVE	C,@1(ARG)	; Get negative max bytes to read
	MOVEI	D,.CHLFD	; Stomp on this character
	SIN
	 ERJMP	CHKEOF		; Hummm??
	JRST	ASC10

; Check for EOF, if not blow up

CHKEOF:	MOVEI	A,.FHSLF	; Get the error
	GETER
	TXZ	B,-1B17		; Just the error
	CAIE	B,IOX4		; EOF condition?
	 JSHLT			; Surrender

	MOVE	A,IJFNP
	CLOSF			; Close file
	 JFCL
	SOS	IJFNP		; Adjust pointer

	SETOM	@2(ARG)		; Tell caller 'bout EOF

; Return number of bytes read

ASC10:
	MOVE	FV,@1(ARG)	; Get buffer size
	SUB	FV,C
	RET
	Subttl	Subroutines -- FILEOP (Open an ascii file)

; Integer function FILEOP (filename)
;
; Opens a file for input. This file may then be read by FILEIN. If an error
; is encountered while trying to open the file, the monitor error code is
; returned to the caller otherwise zero is.

	SBR	FILEOP

	AOS	IJFNP		; Push current file (if any)
	SKIPGE	@IJFNP		; Too many files?
	 Fatal	<Too many files pushed>

	MOVX	A,GJ%SHT+GJ%OLD
	MOVE	B,0(ARG)	; Get address of file name
	HRLI	B,(POINT 36,)	; Make it a pointer

	GTJFN
	 ERJMP	OPERR		; Giver error to caller

	MOVEM	A,@IJFNP
	MOVX	B,OF%RD+<FLD (7,OF%BSZ)>
	OPENF			; Open file file ASCII input
	 ERJMP	OPERR

	SETZ	FV,		; Successful
	RET

; Give error back to caller

OPERR:	MOVEI	A,.FHSLF
	GETER
	HRRZ	FV,B
	RET
	Subttl	Subroutines -- Exit from,

Xit:	Move	P,Svp		; Restore stack
	Ret			; Return to caller
	Subttl	Support -- Echo on and off

ECHON:	MOVEI	A,.PRIIN	; Get current echo state
	JSYS	RFMOD
	TXOE	B,TT%ECO	; Is echo on?
	 RET			;   Yes...No need to do anything
	JSYS	SFMOD		; Turn echo back on
	RET

ECHOFF:	MOVEI	A,.PRIIN	; Get current echo state
	JSYS	RFMOD
	TXZN	B,TT%ECO	; Is echo off?
	 RET			;   Yes
	JSYS	SFMOD
	RET
	
	Subttl	End of source

	End