	.title	scdef
	.ident	/8.0.21/


;	Copyright (C) 1978 1979 1980 1981 1982 1983   Change Software, Inc.
;	
;	
;	This software is furnished under a license and may
;	be  used  and  copied  only in accordance with the
;	terms of such license and with  the  inclusion  of
;	the  above copyright notice.  This software or any
;	other copies thereof may not be provided or other-
;	wise made available to any other person.  No title
;	to and ownership of the software is hereby  trans-
;	ferred.
;	
;	The information in this  software  is  subject  to
;	change  without notice and should not be construed
;	as a commitment by the author.
;


	.sbttl	define terminal screen control commands

;	re-written    Brian Nelson   15-Sep-83  11:44:48
;
;	Define terminal commands based on type. Rewritten to make
;	new types easier to insert in the future.
;
;	Must be in the root segment of the task

	.psect	ttydef
	.psect	ttydsp
	.psect	$pdata			; required PLEASE



;	Get the terminal type names and values from include file
;	we need to do this since both SCDEF and SCDSP need these
;	values  at assembly time for macro  expansions.  We will
;	also declare those  symbols to be global from here.  You
;	must have  the logical name  IN: assigned to the  source
;	device.

	.include	/IN:SCTERM.MAC/


	.iif	ndf, maxvt, .error ; the .include for SCTERM is FUBAR

	global	<tty	,ansi	,mbee	,vt100>
	global	<vt52	,tel912	,maxvt>


	.iif ndf,esc, esc = 233
	semi	=	^d59



	.sbttl	terminal dispatch macroes


	$$base	=	0		; init

	.psect	ttydef
nultxt:	.byte	0			; default control string (nothing)
	.even
no$op:	return
	.psect	$pdata
	.psect	$pdata


	.macro	define	disp		; define dispatch vector for function
	.save
	.psect	ttydsp	,con,rel,d,ro,gbl
	disp::				; define the dispatch base address
	.rept	<maxvt/2>+1		; fill in with address(null_string)
	.word	nultxt			; for # terminal types + 1
	.endr				; end of that
	.word	nultxt			; extra
	$$base	=	disp		; save the base address
	.restore
	.endm				; all done


	.macro vtdef termty,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15
	.save
	.psect	ttydef	,con,rel,d,ro,gbl
	$$def	=	.		; save current address
	.iif nb,c1	,.byte	c1	; and start putting in control chars
	.iif nb,c2	,.byte	c2	;  ditto
	.iif nb,c3	,.byte	c3	;   ditto
	.iif nb,c4	,.byte	c4	;    and so on
	.iif nb,c5	,.byte	c5	;
	.iif nb,c6	,.byte	c6	;
	.iif nb,c7	,.byte	c7	;
	.iif nb,c8	,.byte	c8	;
	.iif nb,c9	,.byte	c9	;
	.iif nb,c10	,.byte	c10	;
	.iif nb,c11	,.byte	c11	;
	.iif nb,c12	,.byte	c12	;
	.iif nb,c13	,.byte	c13	;
	.iif nb,c14	,.byte	c14	;
	.iif nb,c15	,.byte	c15	;
	.byte	0			; always make the string .asciz
	.psect	ttydsp			; back to the dispatch vector
	. = $$base + termty		; stuff string address in for tt type
	.word	$$def			; simple
	. = $$base + maxvt + 4		; insure we are after the end of it
	.restore
					;
	.endm	vtdef			; all done

	.dsabl	lc			; please




	.macro	vector	disp,default	; define dispatch vector for function
	.save
	.psect	ttydsp	,con,rel,d,ro,gbl
	disp::				; define the dispatch base address
	.rept	<maxvt/2>+1		; fill in with address(null_string)
	.if nb, default			; user specifed default ?
	.ift				; yes, use it
	.word	default			; usual for non-addresses
	.iff				; no, default to no=op subroutine
	.word	no$op			; for # terminal types + 1
	.endc				; for default
	.endr				;

	.if nb	,default		; one extra guard word in case
	.ift				; someone fubar's the table up.
	.word	default			; use passed default?
	.iff				; no
	.word	no$op			; extra
	.endc				;
	$$vect	=	disp		; save the base address
	.restore
	.endm				; all done



	.macro	dispatch termty,where
	.save
	.psect	ttydsp
	. = $$vect + termty
	.word	where
	. = $$vect + maxvt + 4
	.restore
	.endm	dispatch


	.sbttl	define the escape commands now


	define	s$up			; move up in display one line

	vtdef	ansi	,esc,'[,'A	; heath (zenith) h19 and z19
	vtdef	mbee	,esc,'A		; microbee (behive)
	vtdef	vt100	,esc,'[,'A	; dec vt100 and lookalikes
	vtdef	vt52	,esc,'A		; the old vt52 and such
	vtdef	tel912	,'k&37		; televideo 912 ala Mike Horton
	

	define	s$down			; move down in display one line

	vtdef	ansi	,esc,'[,'B
	vtdef	mbee	,esc,'B
	vtdef	vt100	,esc,'[,'B
	vtdef	vt52	,esc,'B
	vtdef	tel912	,'j&37


	define	s$home			; goto virtual location [1,1]

	vtdef	ansi	,esc,'[,'H
	vtdef	mbee	,esc,'H
	vtdef	vt100	,esc,'[,'0,'2,semi,'H
	vtdef	vt52	,esc,'H
	vtdef	tel912	,esc,'=,40,40


	define	s$clr			; clear entire screen please

	vtdef	ansi	,esc,'[,'0,'J
	vtdef	mbee	,esc,'J
	vtdef	vt100	,esc,'[,'0,'J,15
	vtdef	vt52	,esc,'J
	vtdef	tel912	,esc,'Y

	.sbttl	more screen definitions


	define	s$l24			; goto last line column one

	vtdef	ansi	,esc,'[,'2,'4,semi,'0,'1,'H
	vtdef	mbee	,esc,'Y,67,40
	vtdef	vt100	,esc,'[,'2,'4,semi,'0,'1,'H
	vtdef	vt52	,esc,'Y,67,40
	vtdef	tel912	,esc,'=,67,40


	define	s$ins			; move back and scroll if needed

	vtdef	ansi	,esc,'M
	vtdef	mbee	,esc,'I
	vtdef	vt100	,esc,'M
	vtdef	vt52	,esc,'I
	vtdef	tel912	,esc,'R


	define	s$mid			; move to center of last line

	vtdef	ansi	,esc,'[,'2,'4,semi,'4,'0,'H
	vtdef	mbee	,esc,'Y,67,110
	vtdef	vt100	,esc,'[,'2,'4,semi,'4,'0,'H
	vtdef	vt52	,esc,'Y,67,110
	vtdef	tel912	,esc,'=,67,110


	define	s$c60			; corner of last line

	vtdef	ansi	,esc,'[,'2,'4,semi,'6,'0,'H
	vtdef	mbee	,esc,'Y,67,130
	vtdef	vt100	,esc,'[,'2,'4,semi,'6,'0,'H
	vtdef	vt52	,esc,'Y,67,130
	vtdef	tel912	,esc,'=,67,130


	.sbttl	yet more of them


	define	s$kill			; delete to end of the line

	vtdef	ansi	,esc,'[,'K
	vtdef	mbee	,esc,'K
	vtdef	vt100	,esc,'[,'K
	vtdef	vt52	,esc,'K
	vtdef	tel912	,esc,'T


	define	s$left			; left in line one position

	vtdef	ansi	,esc,'[,'D
	vtdef	mbee	,esc,'D
	vtdef	vt100	,esc,'[,'D
	vtdef	vt52	,esc,'D
	vtdef	tel912	,'H&37


	define	s$right			; the other way

	vtdef	ansi	,esc,'[,'C
	vtdef	mbee	,esc,'C
	vtdef	vt100	,esc,'[,'C
	vtdef	vt52	,esc,'C
	vtdef	tel912	,'L&37


	define	s$next			; next line

	vtdef	ansi	,15,12
	vtdef	mbee	,15,12
	vtdef	vt100	,esc,'E
	vtdef	vt52	,15,12
	vtdef	tel912	,15,12


	.sbttl	more


;	 What should we print instead of the form feed (octal 14)
;	some terminals (like vt100) can print a small F/F sybmbol
;	by switching to the alternate graphics character set.



	define	ff$prt

	vtdef ansi  ,esc,'[,'1,'0,'m!40,'^,esc,'[,'1,'1,'m!40
	vtdef mbee  ,'f,'/,'f
	vtdef vt100 ,esc,'[,'7,'M!40,esc,'(,'0,'c!40,esc,'(,'B,esc,'[,'0,'M!40
	vtdef vt52  ,esc,'F,'c!40,esc,'G
	vtdef tel912,'f,'/,'f


;	one shot init codes for terminal types
;	called from 'ter' command exe.


	vector	t$init

	dispatch	ansi	,i.ansi
	dispatch	mbee	,i.mbee
	dispatch	vt100	,i.vt100
	dispatch	vt52	,i.vt52
	dispatch	tel912	,i.tel


	vector	t$quit

	dispatch	ansi	,q.ansi
	dispatch	vt100	,q.vt100
	dispatch	vt52	,q.st52


	global	<i.ansi,i.mbee,i.vt100,i.vt52,i.tel>
	global	<q.ansi,q.vt100,q.st52>


	.sbttl	definitions for tertype and nonscreen edit cmds


	.macro	txtent	txt
	.asciz	#txt#
	.even
	.endm	txtent


;	This list is used to dispatch on PF keys typed during
;	line editing (not in the screen editor). Some  people
;	still seem to like using this mode of operation.


e.esc2::txtent	<ABCPRPL>		; micro bee terminals
e.esc3::txtent	<ABCPRQLBACRS>		; VT100  terminals
e.esc4 = e.esc3				; vt52
e.esc5::.asciz	/ABCPRPL/<11.><12.>	; hazeltines
e.esc6 = e.esc3 			; tel912
e.esc1=e.esc3
	.even
	.word	0


	vector	e.tbl,default=e.esc1

	dispatch	ansi	,e.esc1
	dispatch	mbee	,e.esc2
	dispatch	vt100	,e.esc3
	dispatch	vt52	,e.esc4
	dispatch	tel912	,e.esc6


e.jmp::	.word	e.nxtl			; esc cmd next line
 	.word	e.lstl			; esc cmd last line
	.word	sclear			; esc cmd screen clear
	.word	e.page			; esc cmd next page
	.word	c.ref			; esc cmd screen refresh
	.word	e.page			; esc cmd next page
	.word	e.lstp			; esc cmd last page
	.word	e.lstl			; esc cmd last line
	.word	e.nxtl			; esc cmd next line
	.word	sclear			; esc cmd screen clear
	.word	c.ref			; refresh the screen
	.word	e.lstp			; esc cmd last page

	global	<e.nxtl>
 	global	<e.lstl>
	global	<sclear>
	global	<e.page>
	global	<c.ref>
	global	<e.lstp>



	.sbttl	terminal type names and screen size


;	TTMODL is used by both the line editor TERMINAL/name command
;	and by the screen editor as in VT/ANS to match a passed type
;	and set the correct value into the variable 'SCOPE'.


	vector	$ttmodl,default=nultxt

	dispatch	ansi,tty1
	dispatch	mbee,tty2
	dispatch	vt100,tty3
	dispatch	vt52,tty4
	dispatch	tel912,tty6
	dispatch	<maxvt+2>,0
	
tty1:	txtent	<ANSI>
tty2:	txtent	<MBEE>
tty3:	txtent	<VT100>
tty4:	txtent	<VT52>
tty5:	txtent	<H1510>
tty6:	txtent  <TEL912>
	.even

	ttmodl	==	$ttmodl+2

	vector	p$siz,default=1		; size of the screen less one

	dispatch	ansi,22.
	dispatch	mbee,22.
	dispatch	vt100,20.
	dispatch	vt52,22.
	dispatch	tel912,21.


	.end
