        title	'ESPDUMP.ASM'		;Version   1.0
;	                                 December 1984
;          by    George Walker
;                Columbia, Md.
;                FOG member 13945
;
; An RSX for Executive Screen Print.
; This module is assembled under RMAC and linked as an RSX.
; The RSX provides the dedicated system space needed for the
; screen dump subroutine.
;
;
; Implementation details:
; (for the Osborne Executive computer)
;
; With RMAC, LINK, and GENCOM on drive A:
;    ESP.ASM and ESPDUMP.ASM on drive B:
; The following steps will create ESP.COM on drive B:
;
;	RMAC B:ESP $PPSZ
;	LINK B:ESP 
;	RMAC B:ESPDUMP $PPSZ
;	LINK B:ESPDUMP.RSX=B:ESPDUMP[OP]
;	GENCOM B:ESP B:ESPDUMP
;
; For more information on RSXs see the PEEK.xxx files
;     by Ron Fowler on -FOG/EX1.017.
;
; 
;
;
; To invoke (or terminate if active) type: ESP<RET>.
;    ESP will intercept all keyboard input characters.
;    If the input character is a "^0"
;       then ESP will dump the screen image to the printer.
;
;
; NOTE:  SFK "0" must be setup to output an "80H" when pressed.
; ----           (Use ESP-SFK0.COM to accomplish this.)
;
;
;****************************************************************
;	system equates
;
LIST	equ	0F90FH		;BIOS LIST out
Screen	equ	0C000H		;screen memory start address
Columns	equ	80		;characters per line
Bank1	equ	1		;bank  1
Bank7	equ	41H		;banks 7 & 1
;
;
	page
;----------------------------------------------------------------
; RSX prefix (27 bytes)
;
	db	0,0,0,0,0,0	;serial number
	jmp	begin		;entry point
next	db	jmp		;opcode
	dw	0		;next RSX or loader
	dw	0		;previous RSX or 0
RmFlag	db	0		;removes RSX when not 0
	db	0		;nonbanked flag
RSXname db	'ESPDUMP '	;name of RSX
	db	0		;loader flag
	db	0,0		;reserved
;
;
;----------------------------------------------------------------
; process BDOS calls 
;
begin
	mov	a,c
	cpi	60		;is this an RSX call?
	jnz	next		;   no, exit to next RSX
;
;
;----------------------------------------------------------------
; Process RSX calls
;
; Process only calls from the ESP TPA program.  We must verify
; that the name in the RSX parameter block of the calling program
; (ESP.ASM) matches the name in the RSX prefix.  On entry, C
; contains the RSX function number (60) and DE points to ESPname.
;
	push	d		;save adr of ESPname
	lxi	h,RSXname	;point to RSXname	
	mvi	b,8		;index 8 char names
NxtChr
	ldax	d		;get next char of ESPname 
	cmp	m		;does ESPname match RSXname?
	inx	d
	inx	h
	jnz	pass		;  no, exit
	dcr	b		;    maybe,
	jnz	NxtChr		;      compare next character
				;  yes, fall through
;
; Check for duplicate RSX.  
; If found
;    then delete all copies of the ESPDUMP RSX.
;    
	xchg			;move adr of ESP status to HL.
	mov	a,m		;copy ESP status
	sta	RmFlag		;  to Remove Flag.
	pop	d		;retrieve address of ESPname
	push	d		;  and resave it.
	push	h		;save address of ESP status.
	call	next		;check for clone.
	pop	h		;retrieve address of ESP status.
	xri	0FFH		;is this RSX a clone (A = 0FFH)?
	jnz	Clone		;  yes, jump.

	pop	d		;  no, adjust stack
	lxi	h,ScrDump	;  get address of ScrDump and
	rz			;  return to ESP.COM.
Clone	
	sta	RmFlag		;kill this copy
	mov	m,a		;set ESP status = terminate
	mvi	c,60		;get BDOS RSX function
pass
	pop	d		;retrieve address of ESPname
	jmp	next		;  and exit to next RSX.
;
;
;****************************************************************
;	Screen Dump Subroutine 
;
ScrDump
	lxi	h,Screen	;move Screen start adr
	shld	ScrAdr		;  into screen adr ptr.
NxtRow
	mvi	a,Bank7		;point to banks 1 & 7 then
	out	0		;  set bank switch.
	lhld	ScrAdr		;block move a screen line
	lxi	d,LnBuf		;  into line buffer.
	lxi	b,Columns 
	db	0EDH,0B0H 	;  Z80 LDIR block move inst.
	mvi	a,Bank1		;point to bank 1
	out	0		;  set bank switch.

	lxi	h,LnBuf		;output line buffer
	mvi	c,Columns 	;  to LST: device.
NxtCol
	mov	a,m		;get next character
	cpi	' '		;is it a control character?
	jnc	ChrOut		;  no, print it.
	cpi	13		;is it a C/R?
	jz	ChrOut		;  yes, print it.
	cpi	10		;is it a LF?
	jz	ChrOut		;  yes, print it.
	mvi	a,'^'		;  no, print a "^"
ChrOut
	call	Cout		;output character in A.
	inx	h		;point to next character.
	dcr	c		;80 columns printed?
	jnz	NxtCol		;  no, do next character.
	mvi	a,13		;  yes,print a carriage return
	call	Cout
	mvi	a,10		;    and a linefeed.
	call	Cout
	lhld	ScrAdr		;point ScrAdr to next screen line
	lxi	b,80H
	dad	b		;     ScrAdr = ScrAdr + 80
	shld	ScrAdr
	mov	a,h
	cpi	0CCH		;24 lines done?
	jc	NxtRow		;  no,  do next line.
	ret			;  yes, ret to shared mem patch.
;
; Character out subroutine
;
Cout
	push	b
	push	h
	mov	c,a
	call	LIST		;output char via BIOS LST:
	pop	h
	pop	b
	ret
;
;
;----------------------------------------------------------------
;	Data
;
ScrAdr	dw	0		;screen memory line start address
LnBuf	ds	80		;Screen line buffer
;
	end
-----------------------
;	Data
;
ScrAdr	dw	0		;screen memory line start address
LnBuf	ds	80		;Screen line buffer
;
