; changes to definitions follow:

TVI950_SC       = ^A'='         ; Tvi950 set cursor position     FT3
TVI950_EOS      = ^A'Y'         ; Tvi950 erase to end of screen
TVI950_EOL      = ^A'T'         ; Tvi950 erase to end of line

HP_SC   = ^A'C'                 ; HP264X set cursor position    FT2
HP_DWN  = ^A'A'                 ; HP264X down scroll
HP_UP   = ^A'B'                 ; HP264X up   scroll
HP_EOS  = ^A'J'                 ; HP264X erase to end of screen
HP_EOL  = ^A'K'                 ; HP264X erase to end of line


; changes to dispatcher follow:

dispatcher:
	.word	^m<r2,r3,r4,r5,r6,r11>

	movl	28(ap),r11		; r11 = address of SCRFT args
	callg	@4(r11),b^10$		; call with SCR argument list
	ret
10$:	.word	0
	clrw	@20(r11)		; Clear output length
	subl3	#1,12(r11),r1		; r1 = Foreign terminal number - 1
	cmpl    r1,#3                   ; we only handle FT1,FT2, and FT3
	bgequ	20$			; ignore others
	case	8(r11),type=w,<-	; Case on request type
		put_screen,-            ; PUT_SCREEN
		get_screen,-            ; GET_SCREEN
		erase_page,-            ; ERASE_PAGE
		erase_line,-            ; ERASE_LINE
		set_cursor,-            ; SET_CURSOR
		down_scroll,-           ; DOWN_SCROLL
		20$,-                   ; SCREEN_INFO - always handled by SCR
		put_line,-		; PUT_LINE
		20$,-			; MOVE_CURSOR (not implemented in SCRPKG)
;		set_scroll,-		; SET_SCROLL
		dispatch_extended,-	; DISPATCH TO EXTENDED ROUTINES
		up_scroll -		; UP_SCROLL
		>
20$:	movl	#1,r0
	ret



; changes to pos_output follow:
;---
hexascvt:
	.ascic  '!UL;!UL'                ; Convert to VT100 sequences
hexaschp:
	.ascic  '!ULy!UL'                ; Convert to hp264x sequences
					 ; --screen relative addressing
pos_output:
	movl	(sp),r0			; Save optional argument
	case    12(r11),type=b,limit=#1,<- ; Case on terminal type
		20$,-                   ; vt100 requires ; in middle
		20$,-                   ; hp264x requires y in middle
		30$>                    ; tvi950 use different bias

20$:	subl	#16,sp			; Allocate FAO output buffer
	pushr	#^m<r0,r1>		; Save registers
	pushab	9(sp)			; Create descriptor of buffer
	pushl	#15
	cmpl    #2,12(r11)              ; check for FT2
	bnequ   21$
	subb2   #1,8(ap)                ; decrement row,column for hp264x
	subb2   #1,4(ap)
	movab   hexaschp,r1             ; Address of FAO control string
	brb     25$
21$:    movab   hexascvt,r1             ; Address of FAO control string
25$:    movzbl  (r1)+,r0
	movq	r0,-(sp)		; Push descriptor of string onto stack
	movl	sp,r0			; Address of stack arguments
	pushl   8(ap)                   ; Column number
	pushl   4(ap)                   ; Line number

	$fao_s	(r0),8(r0),8(r0)	; Convert to ASCII characters
	movb	16(sp),32(sp)		; Copy length into ASCIC string
	addl	#24,sp			; Leave buffer on top of stack
	popr	#^m<r0,r1>		; Restore registers
	brb	50$
30$:
; end of changes to pos_output


: other table changes follow:
cr_table:
	string	<<cr>>			;Vt100
	string  <<cr>>                  ;HP264x
	string  <<cr>>                  ;Tvi950

erase_table:				; ERASE TO END OF SCREEN
	string	<<esc><lb><vt100_eos>>			; VT100
	string  <<esc><hp_eos>>                         ; hp264x
	string  <<esc><tvi950_eos>>                     ; Tvi950
erase_table2:				; ERASE FROM POSITION
	STRING	<<esc><lb>"!AC"<vt100_sc>-		; vt100
		<esc><lb><vt100_eos>>
	STRING  <<esc><amp>"a!AC"<hp_sc>-                ; hp264x
		<esc><hp_eos>>
	string  <<esc><tvi950_sc>"!AC"<esc><tvi950_eos>> ; Tvi950


line_table:				; ERASE TO END OF LINE
	string	<<esc><lb><vt100_eol>>			; vt100
	string  <<esc><hp_eol>>                         ; hp264x
	string  <<esc><tvi950_eol>>                     ; Tvi950
line_table2:				; ERASE FROM POSITION
	string	<<esc><lb>"!AC"<vt100_sc>-		; vt100
		<esc><lb><vt100_eol>>
	string  <<esc><amp>"a!AC"<hp_sc>-                ; hp264x
		<esc><hp_eol>>
	string  <<esc><tvi950_sc>"!AC"<esc><tvi950_eol>>; Tvi950



cursor_table:				; SET CURSOR
	string  <<esc><lb>"!AC"<vt100_sc>>       ; vt100
	string  <<esc><amp>"a!AC"<hp_sc>>        ; hp264x
	string  <<esc><tvi950_sc>"!AC">          ; Tvi950



PUT_TABLE:				; Write with embedded cursor
	string	<<esc><lb>"!AC"<vt100_sc>"!AS">	; vt100
	string  <<esc><amp>"a!AC"<hp_sc>"!AS">   ; hp264x
	string  <<esc><tvi950_sc>"!AC!AS">       ; Tvi950

; end of table changes







; beginning of extended dispatcher changes:
 
	.sbttl	DISPATCH_EXTENDED	Dispatch to extended functions.
;---
;	DISPATCH_EXTENDED
;
;	This routine dispatches to an extended function.  The original
;	SET_SCROLL routine has been preceded by this dispatcher.  Extended
;	screen handling routines may be added to SCRFT by including the
;	routines' entry points in the displacement list of the CASE
;	instruction below.
;
;	The high level call format for executing the extended routines is:
;	
;		return_status = scr$set_scroll (P0, P1, Fn, P2, ..., Pn)
;
;	where:	P0 - Pn	 are the function dependent arguments,
;		Fn	 is the function code for the routine.
;
;	The function code of a particular routine is determined by the
;	its entry point position in the CASE statement below.  The entry
;	point for SET_SCROLL should always appear first on the list;
;	this will allow the original SET_SCROLL function to be dispatched
;	with a function code of zero (0) or simply,
;
;		return_status = scr$set_scroll (P0, P1)
;
;
;---
dispatch_extended:
	cmpl	(ap), #3		; Check for existance of a func code.
	blssu	set_scroll		; Skip to orig func if no func code.
	case	12(ap), type=w, <-	; Dispatch to user function routines.
		set_scroll,-		; Set scrolling region (orig function).
		screen_up,-		; Scroll up screen section.
		screen_down -		; Scroll down screen section.
		>			;
	movl	#1, r0			; Ignore undefined user function codes.
	ret				;

	.page
	.sbttl	SCREEN_UP	Scroll up a screen section
;---
;
;	This routine scrolls up the selected screen section.
;	All lines within the TOP_ROW and BOTTOM_ROW inclusive are 
;	scrolled up one line while the lines outside these limits
;	remain unchanged.  The cursor is in the home position after
;	the call execution.
;
;	High level call format:
;
;		return_status = scr$scroll (TOP_ROW, BOTTOM_ROW, 1)
;
;---
screen_up:
	cmpl	4(ap), 8(ap)		; Check if TOP is less than BOTTOM.
	bgequ	5$			; Ignore request if TOP .GE. BOTTOM.
	subl	#2048, sp		; Allocate space for FAO buffer.
	pushl	sp			; Create FAO output descriptor (addr).
	pushl	#2048			;
	movab	(sp), r2		; Save address of FAO output desc.
	movaq	screen_up_tbl[r1], r1	; Create FAO input descriptor (addr).
	movq	(r1), -(sp)		;
	addl	r1, 4(sp)		;
	movab	(sp), r0		; Save address of FAO input desc.
;
	case	12(r11), type=b, limit=#1, <-	; Determine terminal type.
		10$,-			; VT100
		20$ -			; HP2621
		>			;
5$:
	movl	#1, r0			; Ignore undefined terminal types.
	ret				;
;
;	VT100 parameters.
;
10$:
	pushl	8(ap)			; BOTTOM_LINE specification.
	pushl	8(ap)			; BOTTOM_LINE specification.
	pushl	4(ap)			; TOP_LINE specification.
	brw	90$			;
;
;	HP parameters.
;
20$:
	subl3	#1, 8(ap), -(sp)	; BOTTOM_LINE specification - 1.
	subl3	#1, 4(ap), -(sp)	; TOP_LINE specification - 1.
	brw	90$			;
;
;
;
90$:
	$fao_s	(r0), 8(r0), 8(r0)	; Format the output string
	movl	r2, sp			; Set-up output buffer pointer that
	movl	r2, r1			; is suitable for use in the original
	subl	r2, 4(r1)		; SCRFT\OUTPUT routine.
	brw	output			; Skip to OUTPUT for completion.
;
;
;
screen_up_tbl:
	string	<<esc>"[!UL;!ULr"<esc>"[!UL;H"<esc>"D"<esc>"[1;24r">
	string	<<esc>"&a!ULy0C"<esc>"M"<esc>"&a!ULy0C"<esc>"L"<esc>"&a0y0C">

	.page
	.sbttl	SCREEN_DOWN	Scroll down a screen section
;---
;
;	This routine scrolls down the selected screen section.
;	All lines within the TOP_ROW and BOTTOM_ROW inclusive are
;	scrolled down one line while the lines outside these limits
;	remain unchanged.  The cursor is in the home position after
;	the call execution.
;
;	High level call format:
;
;		return_status = scr$scroll (TOP_ROW, BOTTOM_ROW, 2)
;
;---
screen_down:
	cmpl	4(ap), 8(ap)		; Check if TOP is less than BOTTOM.
	bgequ	5$			; Ignore request if TOP .GE. BOTTOM.
	subl	#2048, sp		; Allocate space for FAO buffer.
	pushl	sp			; Create FAO output descriptor.
	pushl	#2048			;
	movab	(sp), r2		; Save address of FAO output desc.
	movaq	screen_down_tbl[r1], r1	; Create FAO input descriptor.
	movq	(r1), -(sp)		;
	addl	r1, 4(sp)		;
	movab	(sp), r0		; Save address of FAO input desc.
;
	case	12(r11), type=b, limit=#1, <-	; Determine terminal type.
		10$,-			; VT100
		20$ -			; HP2621
		>			;
5$:
	movl	#1, r0			; Ignore undefined terminal types.
	ret
;
;	VT100 parameters.
;
10$:
	pushl	4(ap)			; TOP_LINE specification.
	pushl	8(ap)			; BOTTOM_LINE specification.
	pushl	4(ap)			; TOP_LINE specification.
	brw	90$			;
;
;	HP parameters.
;
20$:
	subl3	#1, 4(ap), -(sp)	; TOP_LINE specification - 1.
	subl3	#1, 8(ap), -(sp)	; BOTTOM_LINE specification - 1.
	brw	90$			;
;
;
;
90$:
	$fao_s	(r0), 8(r0), 8(r0)	; Format the output string.
	movl	r2, sp			; Set-up output buffer pointer that
	movl	r2, r1			; is suitable for use in the original
	subl	r2, 4(r1)		; SCRFT\OUTPUT routine.
	brw	output			; Skip to OUTPUT for completion.
;
;
;
screen_down_tbl:
	string	<<esc>"[!UL;!ULr"<esc>"[!UL;H"<esc>"M"<esc>"[1;24r">
	string	<<esc>"&a!ULy0C"<esc>"M"<esc>"&a!ULy0C"<esc>"L"<esc>"&a0y0C">
;
;
;
	.end	dispatcher
