; IVCSCROL.GEN : IVC/SVC program to scroll top 10 lines of screen

;			ZEM  Z80 Emulator and Monitor
;			 Version 1.03   22 June 1986
;
;			(C) 1986 by P. G. Kenny
;				    27 Colwyn Road
;			 	    Northampton
;
;	Permission is hereby granted for all non-commercial
;	reproduction and distribution of this material provided
;	this notice is included.


; ivc/svc addresses

progst	equ	0e400h		; program origin in ivc/svc memory
vdust	equ	0e0d6h		; pointer to start of display memory

; ivc/svc monitor restarts

putscr	equ	08h		; put A to screen at (DE)
getscr	equ	10h		; get A from screen at (DE)
getchr	equ	20h		; get next char from host into A

; program constants

linsiz	equ	80		; line length
lastln	equ	9		; number of lines to scroll - 1
blksiz	equ	linsiz*lastln	; size of memory block to move

	org	progst

	ld	bc, blksiz	; common initialization
	ld	hl, (vdust)	; address of display memory
	rst	getchr		; get next char from host
	cp	"D"		; "D" means scroll down
	jr	z, scrdown	; else scroll up

	ex	de, hl		; scroll up
	ld	hl, linsiz	; calculate address pointers
	add	hl, de		; start of first 2 lines of screen
culoop:	ex	de, hl		; copy loop (DE) <= (HL)
	rst	getscr		; starting from top
	ex	de, hl
	rst	putscr
	inc	de		; adjust pointers and count
	cpi
	jp	pe, culoop

	jr	clrlin		; DE points to bottom line

scrdown:push	hl		; scroll down, save screen start address
	ld	de, blksiz-1	; offset to bottom of screen
	add	hl, de		; calculate pointers to end of bottom 2 lines
	ex	de, hl
	ld	hl, linsiz
	add	hl, de
cdloop:	rst	getscr		; move block (HL) <= (DE)
	ex	de, hl		; starting from bottom
	rst	putscr
	ex	de, hl
	dec	de		; adjust pointers and count
	cpd
	jp	pe, cdloop

	pop	de		; DE points to start of top line

clrlin:	ld	b, linsiz	; clear line pointed to by DE
	ld	a, " "		; by filling with spaces
cloop:	rst	putscr		; loop
	inc	de
	djnz	cloop

	ret			; exit

	end			; end of IVCSCROL.GEN
"		; by filling with spaces
cloop:	rst	putscr		; loop
	inc	de
	djn