.Title	STT Screen Stuff(v4)
.Library	/sys$library:lib/

	$SMGDEF

;	This module exists to contain the SMG routines, thereby isolating them
;	and making a VMS 3.x version easier to build/code/modify.

.Psect	stt$code,rd,page,exe
.Sbttl	+ Initial screen setup

;	called once by STT to blank screen, set up inputs, etc. A RET is
;	executed on any failure, so control is passed back to VMS.

stt$screen_setup::

;			Create Virtual Keyboard & Table

	pushaq	stt$D_null
	pushaq	stt$D_null
	pushaq	stt$D_input_device
	pushal	stt$L_keyboard_id
	calls	#4,G^smg$create_virtual_keyboard
	blbc	r0,50$
	pushal	stt$L_keytable_id
	calls	#1,G^smg$create_key_table
	blbc	r0,50$

;			Create a Pasteboard

	clrl	stt$AL_callparm			;clear screen flag
	movl	#stt$K_screen_width,stt$AL_callparm+4	;column
	movl	#stt$K_screen_length,stt$AL_callparm+8	;row
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_callparm+8
	pushaq	stt$D_output_device
	pushal	stt$L_pasteboard_id
	calls	#5,G^smg$create_pasteboard
50$:
	blbc	r0,90$
	movl	#SMG$M_BUF_ENABLED!SMG$M_MINUPD,stt$AL_callparm+4
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$L_pasteboard_id
	calls	#3,G^smg$control_mode
	blbc	r0,90$

;			Create Banner Virtual Display

	movl	#SMG$C_ASCII,stt$AL_callparm
	clrl	stt$AL_callparm+4		;screen rendition
	clrl	stt$AL_callparm+8		;don't border the display
	movl	#stt$K_banner_width,stt$AL_callparm+12	;Number of columns
	movl	#stt$K_banner_length,stt$AL_callparm+16 ;number of rows
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_callparm+8
	pushal	stt$AL_display_ids+stt$K_banner
	pushal	stt$AL_callparm+12
	pushal	stt$AL_callparm+16
	calls	#6,G^smg$create_virtual_display
	blbs	r0,100$
90$:
		ret
100$:
	movl	#SMG$C_ASCII,stt$AL_callparm
	clrl	stt$AL_callparm+4		;screen rendition
	movl	#SMG$M_BORDER,stt$AL_callparm+8	;border the display
	movl	#stt$K_main_width,stt$AL_callparm+12 ;Number of columns
	movl	#stt$K_main_length,stt$AL_callparm+16 ;number of rows
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_callparm+8
	pushal	stt$AL_display_ids+stt$K_maindisplay
	pushal	stt$AL_callparm+12
	pushal	stt$AL_callparm+16
	calls	#6,G^smg$create_virtual_display
	blbs	r0,190$
180$:
		ret
190$:
	movl	#SMG$C_ASCII,stt$AL_callparm
	clrl	stt$AL_callparm+4		;screen rendition
	movl	#SMG$M_BORDER,stt$AL_callparm+8	;border the display
	movl	#stt$K_trace_width,stt$AL_callparm+12  ;Number of columns
	movl	#stt$K_trace_length,stt$AL_callparm+16 ;number of rows
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_callparm+8
	pushal	stt$AL_display_ids+stt$K_tracedisplay
	pushal	stt$AL_callparm+12
	pushal	stt$AL_callparm+16
	calls	#6,G^smg$create_virtual_display
192$:
	blbc	r0,180$

;	>>>	Following code won't assemble in FT2 MACRO32, since 
;	>>>	SMG$SET_DISPLAY_SCROLLING_REGION is 32 characters (1 too many)
;	>>>	long.  This seems to be no problem, since scrolling is still
;	>>>	effected. I leave it in just to see if VMS4.0 fixes the 
;	>>>	problem.

;	movl	#stt$K_trace_length,stt$AL_callparm	;last row
;	movl	#1,stt$AL_callparm+4			;star at 1st row
;	pushal	stt$AL_callparm
;	pushal	stt$AL_callparm+4
;	pushal	stt$AL_display_ids+stt$K_tracedisplay
;	calls	#3,G^smg$set_display_scrolling_region
195$:
	blbc	r0,192$

;			Paste Virtuals to Pasteboard

	movl	#1,stt$AL_callparm		;column
	movl	#1,stt$AL_callparm+4		;row
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$L_pasteboard_id
	pushal	stt$AL_display_ids+stt$K_banner
	calls	#4,G^smg$paste_virtual_display
	blbc	r0,195$

	movl	#1,stt$AL_callparm
	movl	#6,stt$AL_callparm+4		;start MAINDISPLAY at row 6
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$L_pasteboard_id
	pushal	stt$AL_display_ids+stt$K_maindisplay
	calls	#4,G^smg$paste_virtual_display
200$:
	blbc	r0,195$

;			Initial Banner

	movl	#SMG$C_ASCII,stt$AL_callparm
	clrl	stt$AL_callparm+4		;no complement
	movl	#SMG$M_BOLD!SMG$M_REVERSE,stt$AL_callparm+8
	movl	#1,stt$AL_callparm+12
	movl	#1,stt$AL_callparm+16
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_callparm+8
	pushal	stt$AL_callparm+12
	pushal	stt$AL_callparm+16
	pushaq	stt$D_banner
	pushal	stt$AL_display_ids+stt$K_banner
	calls	#7,G^smg$put_chars_highwide
300$:
	blbc	r0,200$
	pushal	stt$L_pasteboard_id
	calls	#1,G^smg$flush_buffer
	blbc	r0,200$
	rsb

.Sbttl	+ See if user wants to continue w/ faulty TRACE table

stt$check_continue_trace::

;		see if user want's to continue...

	movl	#1,stt$AL_callparm	;column
	movl	#3,stt$AL_callparm+4	;row
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_display_ids+stt$K_banner
	calls	#3,G^smg$set_cursor_abs
	movl	#512,stt$D_input_buf	;maximum input length
	pushal	stt$AL_display_ids+stt$K_banner
	pushaq	stt$D_input_buf
	pushaq	stt$D_trace_continue
	pushaw	stt$D_input_buf		;input length (result)
	pushal	stt$L_keytable_id
	pushal	stt$L_keyboard_id
	calls	#6,G^smg$read_composed_line
	tstw	stt$D_input_buf		;defualt answer?
	beql	25$
		cmpb	stt$AB_input_buf,#^A/Y/ ;yes?
		beql	100$
			cmpb	stt$AB_input_buf,#^A/y/ ;yes?
			beql	100$
25$:
				ret
100$:
	rsb

.Sbttl	+ show ON/OFF for flag
;+
;	routine to output ON/OFF for indicated flag
;
;	inputs	r3	=	address of FAO descriptor
;		r4	=	flag number
;-
stt$show_flag_on_off::

	pushl	r4
	movl	#512,stt$D_fao_outbuf	;reinit descriptor
	pushaq	stt$D_fao_outbuf
	pushaw	stt$D_fao_outbuf
	pushl	r3
	calls	#4,G^lib$sys_fao
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_callparm+8
	pushal	stt$AL_callparm+12
	pushal	stt$AL_callparm+16
	pushal	stt$AL_callparm+20
	pushaq	stt$D_fao_outbuf
	pushal	stt$AL_display_ids+stt$K_maindisplay
	calls	#8,G^smg$put_chars
	incl	stt$AL_callparm+20	;bump row
	cmpl	#stt$K_main_length,stt$AL_callparm+20	;row at limits?
	bgeq	2000$
		addl	#8,stt$AL_callparm+16 ;move column
		movl	#11,stt$AL_callparm+20 ;reset row
2000$:
	rsb

.Sbttl	+++		Examine location & bump pointer
stt$exam_and_bump::

	$CMKRNL_S	stt$get_exam_value
	blbs	r0,5$
		rsb
5$:
	bbc	#stt$V_hex,stt$L_control,100$
		movaq	stt$D_examvalue_hl,r3
		movl	#4,r4
		bbs	#stt$V_long,stt$L_control,200$
			movaq	stt$D_examvalue_hw,r3
			movl	#2,r4
			bbs	#stt$V_word,stt$L_control,200$
				movaq	stt$D_examvalue_hb,r3
				movl	#1,r4
				brb	200$
100$:
	movaq	stt$D_examvalue_dl,r3
	movl	#4,r4
	bbs	#stt$V_long,stt$L_control,200$
		movaq	stt$D_examvalue_dw,r3
		movl	#2,r4
		bbs	#stt$V_word,stt$L_control,200$
			movaq	stt$D_examvalue_db,r3
			movl	#1,r4
200$:
	pushl	stt$L_examvalue
	pushl	stt$L_start_addr
	movl	#512,stt$D_fao_outbuf	;reinit descriptor
	pushaq	stt$D_fao_outbuf
	pushaw	stt$D_fao_outbuf
	pushl	r3
	calls	#5,G^lib$sys_fao
	addl	r4,stt$L_start_addr	;bump address

	movq	#0,-(sp)		;blank this line
	pushal	stt$AL_display_ids+stt$K_maindisplay
	calls	#3,G^smg$erase_line
	movl	#SMG$C_ASCII,stt$AL_callparm
	clrq	stt$AL_callparm+4
	clrl	stt$AL_callparm+12
	movl	#1,stt$AL_callparm+16	;line advance
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_callparm+8
	pushal	stt$AL_callparm+12
	pushal	stt$AL_callparm+16
	pushaq	stt$D_fao_outbuf
	pushal	stt$AL_display_ids+stt$K_maindisplay
	calls	#7,G^smg$put_line
	pushal	stt$L_pasteboard_id
	calls	#1,G^smg$flush_buffer
	rsb

.Sbttl	+ Examine memory in full line mode
;+
;	Inputs:
;		r5	=	current index into local buffer
;;-
stt$exam_line::

	pushl	stt$L_start_addr	;last FAO arg is start addres
	pushab	stt$AL_tracetable[r5]	;where we are
	pushl	#16			;16 characters
	movaq	stt$D_examline_hl,r3
	movl	#4,r4
	bbs	#stt$V_long,stt$L_control,200$
		movaq	stt$D_examline_hw,r3
		movl	#8,r4
		bbs	#stt$V_word,stt$L_control,200$
			movaq	stt$D_examline_hb,r3
			movl	#16,r4
200$:
	movab	stt$AL_tracetable[r5],r1
	movl	r4,r2			;copy # args
300$:
	bbc	#stt$V_long,stt$L_control,400$
		pushl	(r1)+
		brb	600$
400$:
	bbc	#stt$V_word,stt$L_control,500$
		movzwl	(r1)+,-(sp)
		brb	600$
500$:
	movzbl	(r1)+,-(sp)
600$:
	sobgtr	r2,300$
	movl	#512,stt$D_fao_outbuf	;reinit descriptor
	pushaq	stt$D_fao_outbuf
	pushaw	stt$D_fao_outbuf
	pushl	r3
	addl	#6,r4			;adjust arg count
	calls	r4,G^lib$sys_fao
	addl	#16,stt$L_start_addr	;bump address
	addl	#16,r5			;and index into buffer
	movl	#SMG$C_ASCII,stt$AL_callparm
	clrq	stt$AL_callparm+4
	clrl	stt$AL_callparm+12
	movl	#1,stt$AL_callparm+16	;line advance
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_callparm+8
	pushal	stt$AL_callparm+12
	pushal	stt$AL_callparm+16
	pushaq	stt$D_fao_outbuf
	pushal	stt$AL_display_ids+stt$K_maindisplay
	calls	#7,G^smg$put_line
	rsb

.Sbttl	+ Get a command line
stt$get_command_line::

;			Position Cursor

	movl	#1,stt$AL_callparm		;column
	movl	#3,stt$AL_callparm+4		;row (command field)
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_display_ids+stt$K_banner
	calls	#3,G^smg$erase_line

	movl	#1,stt$AL_callparm		;column
	movl	#3,stt$AL_callparm+4		;row
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_display_ids+stt$K_banner
	calls	#3,G^smg$set_cursor_abs
	pushal	stt$L_pasteboard_id
	calls	#1,G^smg$flush_buffer

;			Get Keyboard Input

	movl	#512,stt$D_input_buf		;maximum input length
	pushal	stt$AL_display_ids+stt$K_banner
	pushaq	stt$D_input_buf
	pushaq	stt$D_prompt
	pushaw	stt$D_input_buf			;input length (result)
	pushal	stt$L_keytable_id
	pushal	stt$L_keyboard_id
	calls	#6,G^smg$read_composed_line
	rsb

.Sbttl	+ Erase main display
stt$erase_maindisplay::

	movl	#stt$K_main_width,stt$AL_callparm ;last column
	movl	#stt$K_main_length,stt$AL_callparm+4 ;last row 
	movl	#1,stt$AL_callparm+8		;first column
	movl	#1,stt$AL_callparm+12		;first row
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_callparm+8
	pushal	stt$AL_callparm+12
	pushal	stt$AL_display_ids+stt$K_maindisplay
	calls	#5,G^smg$erase_display
	rsb

.Sbttl	+ Clear the error field
;+
;	This routine clears the error field. it is called AFTER input has been
;	processed by TPARSE.

stt$clear_error_field::

	movl	#stt$K_err_col,stt$AL_callparm		 ;column
	movl	#stt$K_err_row,stt$AL_callparm+4 ;row (error message field)
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_display_ids+stt$K_banner
	calls	#3,G^smg$erase_line
	pushal	stt$L_pasteboard_id
	calls	#1,G^smg$flush_buffer
	rsb


.Sbttl	+ Output error message
stt$error_message::

	movl	#1,stt$AL_callparm+4	;get message text
	movl	r0,stt$AL_callparm+8	;the error code
	pushal	stt$AL_callparm		;some kind of sts array
	pushal	stt$AL_callparm+4
	movl	#512,stt$D_input_buf
	pushaq	stt$D_input_buf
	pushaw	stt$D_input_buf		;result string length
	pushal	stt$AL_callparm+8
	calls	#5,G^lib$sys_getmsg
	blbc	r0,1000$

	movl	#1,stt$AL_callparm		;column
	movl	#4,stt$AL_callparm+4		;row
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_display_ids+stt$K_banner
	calls	#3,G^smg$set_cursor_abs
	movl	#SMG$C_ASCII,stt$AL_callparm
	clrq	stt$AL_callparm+4		;nowrap,comp
	movl	#SMG$M_BOLD!SMG$M_BLINK,stt$AL_callparm+12
	clrl	stt$AL_callparm+16
	pushal	stt$AL_callparm
	pushal	stt$AL_callparm+4
	pushal	stt$AL_callparm+8
	pushal	stt$AL_callparm+12
	pushal	stt$AL_callparm+16
	pushaq	stt$D_input_buf
	pushal	stt$AL_display_ids+stt$K_banner
	calls	#7,G^smg$put_line
1000$:
	blbc	r0,2000$
		pushal	stt$L_pasteboard_id
		calls	#1,G^smg$flush_buffer
		rsb
2000$:
	$EXIT_S	r0


.Sbttl	+ Flush output buffer

stt$flush_buffer::

	pushal	stt$L_pasteboard_id
	calls	#1,G^smg$flush_buffer
	rsb

.Sbttl	+ Show trace entry
;+
;	inputs:
;			r8	=	start index of trace buffer
;			r9	=	ending index
;-
stt$show_trace_table::

	bsbb	stt$show_trace_entry
	aobleq	r9,r8,stt$show_trace_table
	bsbb	stt$flush_buffer
	rsb

stt$show_trace_entry:

	tstl	stt$AL_tracetable[r8]			;null entry?
	bneq	40$
		addl3	#5,r8,r1			;check next 5
		addl3	#1,r8,r2
10$:
		cmpl	r2,r9				;past end of trace?
		bgeq	40$
			tstl	stt$AL_tracetable[r2]	;null entry?
			bneq	40$
			aobleq	r1,r2,10$
				movl	#5,r1
				addl	#5,r8
20$:
				tstl	stt$AL_tracetable[r8] ;null entry?
				bneq	30$
				incl	r1		;keep count
				aobleq	r9,r8,20$
30$:
				pushl	r1
				movl	#512,stt$D_fao_outbuf	;reinit descriptor
				pushaq	stt$D_fao_outbuf
				pushaw	stt$D_fao_outbuf
				pushaq	stt$D_null_trace
				calls	#4,G^lib$sys_fao
				clrl	stt$AL_callparm+8
				pushab	40$
				brw	75$
40$:
	cmpl	#^XFFFFFFFF,stt$AL_tracetable[r8]	;end of trace marker?
	bneq	100$
		movl	#SMG$M_BOLD!SMG$M_REVERSE!SMG$M_BLINK!SMG$M_UNDERLINE,-
			stt$AL_callparm+8
		movab	stt$D_end_of_trace,r3
		movl	#4,r4
50$:
		pushl	r8
		movl	#512,stt$D_fao_outbuf	;reinit descriptor
		pushaq	stt$D_fao_outbuf
		pushaw	stt$D_fao_outbuf
		pushl	r3
		calls	r4,G^lib$sys_fao
75$:
		movl	#SMG$C_ASCII,stt$AL_callparm
		clrl	stt$AL_callparm+4
		clrl	stt$AL_callparm+12
		movl	#1,stt$AL_callparm+16	;line advance
		pushal	stt$AL_callparm
		pushal	stt$AL_callparm+4
		pushal	stt$AL_callparm+8
		pushal	stt$AL_callparm+12
		pushal	stt$AL_callparm+16
		pushaq	stt$D_fao_outbuf
		pushal	stt$AL_display_ids+stt$K_tracedisplay
		calls	#7,G^smg$put_line
		rsb
100$:
	ashl	#2,r8,r1		;convert to byte index
	addl3	#3,r1,r2
	cmpb	#3,stt$AL_tracetable[r1]	;possibly a ASCIC?
	bneq	200$
		incl	r1
		bbcs	#stt$V_ascic,stt$L_control,200$
200$:
	cmpb	stt$AL_tracetable[r1],#^A/z/	;between "a" & "z"?
	bgtru	500$
	cmpb	stt$AL_tracetable[r1],#^A/a/
	bgequ	400$

	cmpb	stt$AL_tracetable[r1],#^A/0/	;between "0" & "9"?
	blssu	500$
	cmpb	stt$AL_tracetable[r1],#^A/9/
	blequ	400$

	cmpb	stt$AL_tracetable[r1],#^A/A/	;between "A" & "Z"?
	blssu	500$
	cmpb	stt$AL_tracetable[r1],#^A/Z/
	blequ	400$

	cmpb	#^A/_/,stt$AL_tracetable[r1]
	bneq	500$
400$:
	aobleq	r2,r1,200$
	
;		Ascii Trace...?

		bbsc	#stt$V_ascic,stt$L_control,600$
			movab	stt$D_ascii_trace,r3
			movl	#SMG$M_UNDERLINE,stt$AL_callparm+8
			pushal	stt$AL_tracetable[r8]
			pushl	#4
			movl	#6,r4
			brw	50$
500$:
	movab	stt$D_not_ascii_trace,r3
	clrl	stt$AL_callparm+8
	pushl	stt$AL_tracetable[r8]
	movl	#5,r4
	brw	50$
600$:
		movab	stt$D_ascic_trace,r3
		clrl	stt$AL_callparm+8
		pushal	stt$AL_tracetable+1[r8]
		pushl	#3
		movl	#6,r4
		brw	50$
.End
