;================================================================
;CP/M 2.2 f}r vortex-Speichererweiterung - VT52 Terminal-Emulation
;Datei OSC4TERM.MAC Version 18-Dez-88
;Include f}r OSC4BANK.MAC

;die wichtigsten Steurzeichen eines Heath/Zenith/VT52-Terminals:
; ESC 'Y' (Zeile+32) (Spalte+32)	;Cursorpositionieren
; ESC 'L'	;Zeile einf}gen und Rest nach unten rollen
; ESC 'M'	;Zeile l|schen und Rest nach oben rollen
; ESC 'q'	;Inverse Darstellung auschalten
; ESC 'p'	;Inverse Darstellung einschalten
; ESC 'K'	;bis zum Zeilenende l|schen
; ESC 'E'	;Bildschirm l|schen (+ 24 Zeilen + Uhrzeit einblenden)

; EM (Video-Attribut)	;Zeichendarstellung ausw{hlen

; + synchronisation der Interruptgesteurten Uhrzeitanzeige mit
;   Bildschirmrollen

	.COMMENT @	;(in OSC4BANK.MAC)
	public	esctst,clrelp,lfp,newlf,paper,pen,turn,setvid
locbuf:	db 0
vidatt:	db 0
	@

esctst:	inc hl
	ld b,0
	ld a,(hl)		;ESC-Parameter holen
	cp 'Y'	;locate		;?ESC 'Y'
	jp z,curloc		;!dann Cursor positionieren
	cp 'L'	;insline	;ESC 'L'
	jr z,xinsdel		;dann Zeile einf}gen/l|schen B=0 -> einfuegen
	cp 'q'	;ivoff		;ESC 'q'?
	jr z,ivset		;dann Invers ein/aus B=0 -> ein
	dec b
	cp 'M'	;delline	;ESC 'M'
xinsdel:jp z,insdel		;dann Zeile einf}gen/l|schen B=255 -> loeschen
	cp 'p'	;ivon		;ESC 'p'?
	jr z,ivset		;dann Invers ein/aus B=255 -> aus
	cp 'K'	;eraeol		;ESC 'K'?
clrelp:	jp z,$-$
	cp 'E'	;clrscr		;ESC 'E'
	jr z,clearall
	ret

setvid:	inc hl
	ld a,(hl)
	jr pap4

turn:	ld a,(vidatt)
	xor 02
	jr pap4

ivset:	ld a,b
	jr pap3

pen:	inc hl
	ld a,(hl)
	xor 01
	jr pap2

paper:	inc hl
	ld a,(hl)
pap2:	add a,a
pap3:	and 02
	ld b,a
	ld a,(vidatt)
	and 0FDh
	or b
pap4:	ld (vidatt),a
	ret

clearall:
	call scr_get_mode
	cp 2
	ld a,2
	call nz,scr_set_mode
	ld hl,0		;h:links, l:oben
	ld de,4F17h	;d:rechts, e:unten
	call txt_win_enable
	call TXT_CLEAR_WINDO
	jp shtime

raoverfl:
	ld a,c
	dec a
	add a,l
	ret nc
	ld a,h
	and 07
	xor 07
	ret nz
	scf
	ret

curloc:	ld hl,(TXT_OUT_ACTION+1)
	ld (txtoup+1),hl
	ld hl,parcnt
	ld (TXT_OUT_ACTION+1),hl
	ret

insdel:	call txt_undraw_curs	;Register B gibt scroll-Richtung an
	call txt_get_cursor
	dec l
	ld c,l
	call txt_get_window	;Register BC bleibt unver{ndert
	ld l,c
	xor a			;call txt_get_paper!call scr_ink_encode
	call scr_software_ro
	call txt_draw_cursor
	ld a,1
	jp txt_set_column

parcnt:	ld hl,locbuf
	inc (hl)
	dec (hl)
	jr nz,exec
	ld (hl),a
	ret
exec:	sub 1Fh
	ld d,a
	ld a,(hl)
	ld (hl),0
	sub 1Fh
	ld e,a
txtoup:	ld hl,$-$	;alte Adresse wird eingepatched
	ld (TXT_OUT_ACTION+1),hl
	ex de,hl
	jp TXT_SET_CURSOR

newlf:	call stclck
	call txt_get_window	;H:links L:oben D:rechts E:unten
	ld a,h
	or l
	jr nz,lfp		;originale LF-Routine, falls Teilfenster
	ld hl,4F17h
	sbc hl,de
	jr nz,lfp		;originale LF-Routine, falls Teilfenster
	call txt_get_cursor	;H:Spalte+1 L:Zeile+1
	ld a,l
	cp 18h			;Cursor nicht in letzter Zeile
lfp:	jp nz,$-$		;originale LF-Routine
	call txt_undraw_curs
	call MC_WAIT_FLYBACK	;24 Zeilen nach oben rollen
	call SCR_GET_LOCATIO
	ld de,0050h
	add hl,de
	call SCR_SET_OFFSET
	ld hl,0018h		;Linke Spalte/letzte Zeile+1
	call SCR_CHAR_POSITI	;Ziel Byteposition
	ex de,hl		;DE := Ziel Byteposition
	ld hl,0017h		;Linke Spalte/letzte Zeile
	call SCR_CHAR_POSITI	;HL := Quell Byteposition
	ld bc,0850h		;8 Rasterzeilen/80 Spalten
loop:	push hl			;HL := Quell Byteposition
	push de			;DE := Ziel Byteposition
	push bc
	call copyline		;eine Rasterzeile kopieren
	pop bc
	pop hl			;DE := n{chste Ziel BYteposition
	call SCR_NEXT_LINE
	ex de,hl
	pop hl			;HL := n{chste Quell Byteadresse
	call SCR_NEXT_LINE
	djnz loop
	jp txt_draw_cursor
copyline:
	ld b,0
	ex de,hl
	call RAoverfl		;bei Zielzeile Overflow?
	ex de,hl
	jr c,destov
	call RAoverfl		;bei Quellzeile Overflow?
	jr nc,RAcopy
	push bc
	xor a
	sub l
	ld c,a
rap1:	call RAcopy
	pop bc
	cpl
	inc a
	add a,c
	ld c,a
	ld a,h
	sub 08
	ld h,a
	jr RAcopy
destov:	push bc
	xor a
	sub e
	ld c,a
rap2:	call RAcopy
	pop bc
	cpl
	inc a
	add a,c
	ld c,a
	ld a,d
	sub 08
	ld d,a
;wie LDIR, dabei aber Quelle mit 0 l|schen
RAcopy:	push bc
	push hl
	ldir
	pop hl
	pop bc
	ld (hl),0
	dec c
	jr z,mvend
	push de
	ld e,l
	ld d,h
	inc de
	ldir
	pop de
mvend:	inc hl
	ret

;================================================================
                                 