	.TITLE	POSITION IN SCREEN
	.IDENT	/130789/
;
;+
;
; Dieses UP holt Input bzw. gibt Output in FMS-aehnlicher Weise
; Aufruf:
;        CALL POS(FKT,IZEIL,ISPALT,IVAR,IHTEXT)
;                                        mit:
;                                            FKT = IN = 0
;				$ESC+"[m"          OUT= 1  GRAPHIC NO ATTRB.
;							2  Behalte Cursorpos.
;				$ESC+"[1m"	     +"10 GRAPHIC BOLD
;				$ESC+"(0"	     +"20 GRAPHIC DRAWING SET
;				$ESC+"[1;5m"	     +"30 GRAPHIC BOLD BLINK
;				$ESC+"[4m"	     +"40 GRAPHIC UNDERSCORE
;				$ESC+"[5m"	     +"50 GRAPHIC BLINK
;				$ESC+"[5;7m"	     +"60 GRAPHIC REVERSE BLINK
;				$ESC+"[7m"	     +"70 GRAPHIC REVERSE
;				$ESC+"[1;4m"	    +"100 GRAPHIC BOLD UNDERSCOR
;				$ESC+"[1;7m"	    +"110 GRAPHIC BOLD REVERSE
;				$ESC+"[J"           +"120 CLEAR SCREEN
;				$ESC+"[K"           +"130 CLEAR LINE
;				$ESC+"[1;4;7m"	    +"140 GRAPHIC BOLD REV UND
;                                          IZEIL = 1...24
;                                          ISPALT= 1...80
;                                          IVAR  = Variable f. I/O [BYTE(ILEN)]
;                                          IHTEXT= Variable fuer Help-Text
;
;                                     SKN/BME H.-J. May
;
;-
	.MCALL	QIOW$S
;
	.PSECT	POSCOD,I
POS::
	MOV	R0,-(SP)
	MOV	R1,-(SP)
	MOV	R2,-(SP)
	MOV	R3,-(SP)
	MOV	R4,-(SP)
	TST	VT100
	BNE	2$
	JMP	EING
2$:	CLR	VT100
	QIOW$S	#SF.GMC,#5,#5,,,,<#TYPBUF,#2>
	MOV	#TRMTBL,R0
	MOV	#LTT,R1
1$:
	CMPB	(R0)+,TYPBUF+1		;VT100 od. kompatibel?
	BEQ 	EING			;nein, Ende
	SOB	R1,1$
	INC	VT100
EING:
	TST	(R5)+			;Anz. Parameter
	MOV	@(R5),FKTgrf		;Funktion holen
	BIC	#177607,FKTgrf
	CCC
	ROR	FKTGRF
	CCC
	ROR	FKTGRF
	CCC
	ROR	FKTGRF
	MOV	@(R5)+,FKT		;Funktion holen
	BIC	#177770,FKT
	MOV	@(R5)+,R1
	MOV	#TRANS,R0
	MOV	#1,R2
	MOV	R5,-(SP)
	CALL	$CBDMG
	MOV	(SP)+,R5
	MOVB	TRANS+3,ZEIL
	MOVB	TRANS+4,ZEIL+1
	MOVB	ZEIL,SCR+2
	MOVB	ZEIL+1,SCR+3
	INC	SCR+3
	MOV	@(R5)+,R1
	MOV	#TRANS,R0
	MOV	#1,R2
	MOV	R5,-(SP)
	CALL	$CBDMG
	MOV	(SP)+,R5
	MOVB	TRANS+3,SPALT
	MOVB	TRANS+4,SPALT+1
	MOV	(R5),VAR
	MOV	(R5)+,R2
	CLR	R3
	MOV	#QIOT,R4		;(Default)
2$:	TSTB	(R2)
	BEQ	22$
	MOVB	(R2)+,(R4)+		;umspeichern
	INC	R3
	BR	2$
22$:	MOV	#HELP,R4		;(Help-Text)
	MOV	#160.,R2
23$:	CLRB	(R4)+
	SOB	R2,23$
;
	MOV	R3,LAEN
	MOV	(R5)+,R2
	MOV	#HELP,R4		;(Help-Text)
1$:	TSTB	(R2)
	BEQ	11$
	MOVB	(R2)+,(R4)+		;umspeichern
	BR	1$
11$:
;
	TST	VT100	;VT100?
	BEQ 	CONT
	JMP	HCPY			;nein, weiter
CONT:	QIOW$S	#IO.WLB,#5,#5,,,,<#QIO,#QIOL,#0> ;Save Cursor und POS
	CALL	GRAFIC
	TST	FKT
	BEQ	LESEN
	JMP	OUT
LESEN:	MOV	VAR,R2
	MOV	LAEN,R1
	QIOW$S	#IO.WLB,#5,#5,,,,<R2,R1,#0> ;Output Text
CONT0:	QIOW$S	#IO.WLB,#5,#5,,,,<#QIO,#QIOL,#0> ;POS
CONT1:	QIOW$S	#IO.RLB,#5,#5,,#IOSB,,<R2,LAEN,#0> ;Read Input
	CMPB	#IE.EOF,IOSB
	BEQ	LESEN
	QIOW$S	#IO.WLB,#5,#5,,,,<#CLH,#CLHL,#0> ;Clear Help line
NOCL:	MOV	VAR,R3
	MOV	R3,R4
	ADD	LAEN,R4
	SUB	R2,R4
12$:	CMPB	(R3)+,#33
	BEQ	1$
	SOB	R4,12$
	JMP	EXIT
1$:	MOV	R3,R0
	DEC	R0
	MOVB	2(R0),INPT
	MOV	#INP,R3
	ADD	LAEN,R3
	SUB	R4,R3
	MOVB	(R3)+,(R0)+
	MOVB	(R3)+,(R0)+
	MOVB	(R3)+,(R0)+
	CMPB	INPT,#'D		;CUR LINKS
	BNE	CURSR
	CMP	VAR,R2
	BNE	2$
	JMP	CONT0
2$:	DEC	R2
	DEC	R1
	QIOW$S	#IO.WLB,#5,#5,,,,<#CURL,#3,#0>
	BR	CONT1
CURSR:	CMPB	INPT,#'C		;CUR RECHTS
	BNE	HLP
	MOV	VAR,R3
	ADD	LAEN,R3
	CMP	R3,R2
	BEQ	BEG
	INC	R2
	INC	R1
	QIOW$S	#IO.WLB,#5,#5,,,,<#CURR,#3,#0>
	JMP	CONT1
BEG:	MOV	VAR,R2
	MOV	LAEN,R1
	JMP	CONT0
HLP:	CMPB	INPT,#'Q		;PF2
	BEQ	1$
	JMP	CONT0
1$:	QIOW$S	#IO.WLB,#5,#5,,,,<#QIOH,#QIOHL,#0> ;Print Help Message
	JMP	CONT0
;	
;	Outputfunktion fuer VT100-kompat. Terminal
;
OUT:
	CMP	FKT,#2
	BEQ	OUT1			;FKT=2 don't restore cursor
	QIOW$S	#IO.WLB,#5,#5,,,,<#SCR,#SCRL,#0> ;Fix scroll-region
OUT1:	QIOW$S	#IO.WLB,#5,#5,,,,<#QIO,#QIOL,#0> ;POS
CONT3:	QIOW$S	#IO.WLB,#5,#5,,,,<VAR,LAEN,#0> ;Output Line
	CMP	FKT,#2
	BEQ	EX1			;FKT=2 don't restore cursor
	BR	EX2

;
EXIT:	ADD	LAEN,R3
	CLRB	(R3)
EX2:	MOV	#15,FKTGRF
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ASCII	<15><33>/[/
ZEIL:	.ASCII	/nn;/
SPALT:	.ASCII	/mmH/
QIOL=.-QIO
SCR:	.ASCII	<33>/[nn;24r/
SCRL=.-SCR
	.EVEN
LAEN:	.WORD	0
INPT:	.WORD	0
INP:
QIOT:	.BLKB	80.
QIOE:
	.ASCII	<33>/[m/<33>/[24;01H/<15>
QIOEL=.-QIOE
DUM:
	.ASCII	/ /
DUML=.-DUM
QIOH:
	.ASCII	<15><33>/[/
	.ASCII	/24;/
	.ASCII	/01H/
HELP:	.BLKB	160.
QIOHL=.-QIOH
CLH:
	.ASCII	<33>/7/<15><33>/[24;01H/<33>/[K/<33>/8/
CLHL=.-CLH
CURR:	.ASCII	<33>/[C/
CURL:	.ASCII	<33>/[D/
	.EVEN
GRFTBL:
	.WORD	GRF0,GRF0L
	.WORD	GRF1,GRF1L
	.WORD	GRF2,GRF2L
	.WORD	GRF3,GRF3L
	.WORD	GRF4,GRF4L
	.WORD	GRF5,GRF5L
	.WORD	GRF6,GRF6L
	.WORD	GRF7,GRF7L
	.WORD	GRF10,GRF10L
	.WORD	GRF11,GRF11L
	.WORD	GRF12,GRF12L
	.WORD	GRF13,GRF13L
	.WORD	GRF14,GRF14L
	.WORD	GRF20,GRF20L
	.WORD	0,0
GRF0:	.ASCII	<33>/[m/	;GRAPHIC NO ATTRB.
	GRF0L=.-GRF0
	.even
GRF1:	.ASCII	<33>/[1m/	;GRAPHIC BOLD
	GRF1L=.-GRF1
	.even
GRF2:	.ASCII	<33>/(0/	;GRAPHIC DRAWING SET
	GRF2L=.-GRF2
	.even
GRF3:	.ASCII	<33>/[1;5m/	;GRAPHIC BOLD BLINK
	GRF3L=.-GRF3
	.even
GRF4:	.ASCII	<33>/[4m/	;GRAPHIC UNDERSCORE
	GRF4L=.-GRF4
	.even
GRF5:	.ASCII	<33>/[5m/	;GRAPHIC BLINK
	GRF5L=.-GRF5
	.even
GRF6:	.ASCII	<33>/[5;7m/	;GRAPHIC REVERSE BLINK
	GRF6L=.-GRF6
	.even
GRF7:	.ASCII	<33>/[7m/	;GRAPHIC REVERSE
	GRF7L=.-GRF7
	.even
GRF10:	.ASCII	<33>/[1;4m/	;GRAPHIC BOLD UNDERSCORE
	GRF10L=.-GRF10
	.even
GRF11:	.ASCII	<33>/[1;7m/	;GRAPHIC BOLD REVERSE
	GRF11L=.-GRF11
	.even
GRF12:	.ASCII	<33>/[J/	;CLEAR SCREEN
	GRF12L=.-GRF12
	.even
GRF13:	.ASCII	<33>/[K/	;CLEAR LINE
	GRF13L=.-GRF13
	.even
GRF14:	.ASCII	<33>/[1;4;7m/	;GRAPHIC BOLD REVERSE UNDERSCORE
	GRF14L=.-GRF14
	.even
GRF20:	.ASCII	<33>/(B/	;GRAPHIC RESET
	GRF20L=.-GRF20
	.EVEN
	.END
