	title	'ESP.ASM'
;
;
;
;   Executive Screen Print        Version   1.0
;                                 December 1984
;     
;   by  George Walker
;       Columbia, Md.
;       FOG member 13945
;	
;
; ESP provides a method to dump the screen image to the printer
; at any time from within any program.  This ESP.ASM TPA module
; initializes an attached RSX and sets up a BIOS CONIN intercept
; patch in shared memory.
;
;	
; Note:
;
; The attached RSX (ESPDUMP.ASM) contains the screen dump
; subroutine.  The RSX is used only as a method of gaining
; the dedicated system space needed for the subroutine.
; See SCRNDUMP.ASM for more information.
;
;
;****************************************************************
; system equates
;
BDOS	equ	5		;BDOS entry address
BIOS3	equ	0F909H		;BIOS ConIn jmp table address
ConIn	equ	0FAAFH		;BIOS ConIn subroutine
ShMem	equ	0FD00H		;BIOS User patch area (64 bytes)
;
;
;----------------------------------------------------------------
; Initialize the ESPDUMP RSX.
;    returns with HL containing the entry address to the RSX
;    and sets ESP status (0=activated, 0FFH=terminated).
;
begin	db	0EDH,073H	;Z80 SSPD instruction
	dw	StkSav		;  save system stack pointer.	
	lxi	sp,userStk	;set user stack pointer.
	mvi	c,60		;get BDOS RSX function number
	lxi	d,ESPname	;  address of ESPname then
	call	BDOS		;  setup the ESPDUMP RSX.

	lda	Status		;retrieve ESP status.
        ora	a   		;was ESP terminated (A = 0FFH)?
	jnz	Cleanup		;  yes, jump.
;
;
	page
;----------------------------------------------------------------
; RSX activated.
;
	shld	SDadr		;move screen dump adr into Patch.

 	lxi	h,Patch		;move Patch to user patch area
 	lxi	d,ShMem		;  in shared memory
 	lxi	b,UserSP-Patch	;  (Patch byte count)
 	db	0EDH,0B0H	;  Z80 LDIR block move inst.

	lxi	h,ShMem		;change BIOS3 address vector to
	shld	BIOS3+1		;  point to Patch.

	lxi	d,On		;point to turnon message then
	jmp	StrOut		;  display it.
;
;
;----------------------------------------------------------------
; RSX terminated
;
Cleanup	lxi	h,ConIn		;restore BIOS3
	shld	BIOS3+1		;  address vector then
	lxi	d,Off		;  point to turnoff message
;
;
;----------------------------------------------------------------
; Display ESP status message
;
StrOut	mvi	c,9
	call	BDOS		;send string to console
	lhld	StkSav		;  retrieve and
 	sphl			;  restore system stack pointer
	ret			;  return to CP/M.
;
;
;****************************************************************
;	Data storage
;----------------------------------------------------------------
; Status messages
;
On	db	11,12,12,12,12,12,12,12,12,12,12,' version 1.0'
	db	' - by George Walker - Columbia, Md. - Dec 1984'
	db	13,10,'           '
	db	'Type: "^0" to dump screen to printer. $'
Off	db	11,12,12,12,12,12,12,12,12,12,12,' terminated.$'
;
;
;----------------------------------------------------------------
; RSX parameter block
;
RSXpb	db	1		;user RSX function number
  	db	1		;number of parameters
	dw	ESPname		;address of ESPname
ESPname	db	'ESPDUMP '
;
;
;----------------------------------------------------------------
;	ESP data storage
;
Status	db	0		;ESP status (0 = active)	
StkSav	dw	0		;system stack pointer saved here	
	ds	16
UserStk				;user stack
;
;
;----------------------------------------------------------------
;		Shared memory patch image
;
; The following code is a patch which is moved into the BIOS user
; patch area of shared memory.
; All BIOS CONIN calls are intercepted and processed as follows:
;
; read a keyboard character
; if kbd_char = 080H  {SFK 0 must output an 80H for this to work}
;    then do begin
;		screen dump to printer
;		move null char in A reg
;	     end
; return to calling program
;
;
Patch	call	ConIn			;read keyboard character
	cpi	80H			;is it a "^0" (80H)?
	rnz				;  no, return to caller.

	db	0EDH,073H		;yes, save sys Stack Ptr
	dw	SPsave-Patch+ShMem	;  Z80 SSPD instruction.	
	lxi	sp,UserSP-Patch+ShMem	;setup user Stack Ptr.
	in	0			;read and
	push	psw			;  save Bank byte.
	mvi	a,1
	out	0			;enable Bank 1
	db	call			;call...
SDadr	dw	0			;    ...ScrDump.
	pop	psw			;retrieve Bank byte.
	lhld	SPsave-Patch+ShMem	;restore
	sphl				;  system stack ptr
	out	0			;  and Bank byte.
	xra	a			;return a null character
	ret				;  to caller.
;
SPsave	ds	2			;system stack pointer
	ds	18			;9 level  user stack
UserSP	ds	0			;  top of user stack
;
	end
o caller.
;
SPsave	ds	2			;system stack pointer
	ds	18			;9 level  use