;firstly, we have the RSX header.
	db	0,0,0		;the loader puts the serial number here
	jmp	entrypoint	;beginning of the program
next:	db	0C3H
	dw	000		;jump to the next module in line. If the
;routine makes BDOS calls, then they should be:-
;jmp	next
;
previous:
	dw	000		;the address of the previous module or 0005H
;if it is the first in line.
	db	00H		;the remove flag (-1 if it should be removed)
;if this is set to 00, then it can set this flag to -1 when it has terminated
;so as to remove the RSX.
	db	00H		;nonbank
	db	'COMMS   ',0,0,0
;end of RSX header

		ds	80
our_sp:
		ds	4
his_sp:		dw	00
surpressed:	db	00
stopped:	db	00
main_::		;dummy entrypoint (never called)	
entrypoint:
	push	psw
	lda	surpressed
	ana	a
	jnz	do_next	;is there a lock on this?
	push	b
	push	d
	push	h	;save the environment
	lxi	h,0
	dad	sp	;and the stack
	shld	his_sp
	lxi	sp,our_sp
	push	b	;push the function number
	push	d	;and the parameter
	xra	a
	dcr	a
	sta	surpressed	;prevent reentrancy
	mov	a,c	;look at the function number again
	cpi	60	;is it our special one?
	jnz	not_ours
	call	rsx_entry##
	jmp	hop_over	
not_ours:
	cpi	10	;was it a read console buffer?
	jnz	hop_over
loop_again:
	call	rsx_entry##
	mvi	c,6	;direct console io
	mvi	e,0feh	;console status
	call	next	;from the bdos
	ana	a
	jz	loop_again
hop_over:
	pop	d
	pop	b
	xra	a
	sta	surpressed	;allow RSX_entry to be called
	lhld	his_sp	;restore the stack
	sphl
	pop	h
	pop	d
	pop	b
do_next:
	pop	psw
	jmp	next	;and go to the next.

end

