	title	CP/M 2 emulator for CP/M 3
	name	('CPM2')

; A CP/M+ downgrade tool

; This program installs an RSX for emulation BDOS ans BIOS
; functions running CP/M Plus (CP/M 3.x)

; Type 'CPM2' to install the RSX

; Type 'CPM2DEL' to install the RSX

; Program based upon an idea from the Public Domain tool
; written by Jim Lopushinsky, March 22, 1984

; Adapted by	Werner Cirsovius
;		Hohe Weide 44
;		D-2000 Hamburg 20
;		Tel.: 040/4223247

;		Version 1.0, March 1987

BDOS	equ	0005h

.string	equ	 9
.scb	equ	49
.rsx	equ	60

_COMmem	equ	05dh		; SCB offset for COMMON memory

lf	equ	0ah
cr	equ	0dh
eot	equ	'$'

	ld	c,.scb
	ld	de,COMADR
	call	BDOS		; Get COMMON base address
	ld	a,h		; Test banked
	or	l
	jr	z,InstallRSX	; Nope
	ex	de,hl
	ld	hl,(BDOS+1)
	sbc	hl,de		; Test space for RSX
	jr	nc,InstallRSX	; Yeap
	ld	de,$INVCOMM
	ld	c,.string
	call	BDOS		; Tell no room
	xor	a
	ld	(INSTALL),a	; Set remove RSX
InstallRSX:
	ld	c,.rsx
	ld	de,INSTALL
	jp	BDOS		; Install RSX
;
COMADR:
	db	_COMmem
	db	0
	db	0,0
INSTALL:
	db	1		; 1 installs
				; 0 removes (see CPM2DEL)
$INVCOMM:
	db	cr,lf
	db	'Common base is above CPM2 RSX.  Not loaded.'
	db	eot

	end

