;USER AREA for Lifeboat CP/M2
;  Customized for Martin E.'s Poly-88
;  Dec 3, 2013

; Change MSIZE to the desired CP/M memory size in K.
MSIZE	EQU	60		;Distribution size

; These equates are automatically changed by MSIZE.
BIOS	EQU (MSIZE*1024)-0C00H	;Memory location of BIOS
USER	EQU	BIOS+600H	;and of this USER AREA
OFFSET	EQU	2600H-USER	;To overlay SYSGEN image

; POLEX (Custom Poly-88 Executive) Entry points

PXCSTA	EQU	0F403h		;console input status
PXCIN	EQU	0F406h		;console input
PXCOUT	EQU	0F409h		;console output
PXSSTA	EQU	0F40Ch		;serial port input status
PXSIN	EQU	0F40Fh		;serial port input
PXSOUT	EQU	0F412h		;serial port output
PXSOST	EQU	0F415h		;serial port output status

; ASCII
DEL	equ	7Fh
BSPACE	equ	08H

	ORG	USER		;Start of USER AREA
;----------------------------------------------------------------------
; JUMP TABLE - Jumps MUST remain here in same order.
;----------------------------------------------------------------------
CINIT	JMP	CINITR		;Cold boot init
WINIT	JMP	WINITR		;Warm boot init
CONST	JMP	PXCSTA		;Console input status
CONIN	JMP	MCONIN		;Console input
CONOUT	JMP	PXCOUT		;Console output
LIST	JMP	PXSOUT		;Printer output on serial port
PUNCH	JMP	PXSOUT		;Punch output on serial port
READER	JMP	RDRIN		;Reader input on serial port
LISTST	JMP	PXSOST		;Printer output status on serial port

; This 8 byte data area is used and externally MUST remain here.

LENUA	DW	USRLEN		;Length of USER AREA
USRIOB	DB	0		;"I" Initial IOBYT
HSTYPE	DB	0		;"H" Handshaking type
NULLOC	DB	0		;"J" Printer nulls
	DB	0,0,0		;Reserved

;-----------------------------------------------------------------------
; MCONIN
;   Get console character. Translate DEL (which is produced by the
;   Poly-88 RUB OUT key) into a backspace character, so that console
;   line editing is less ugly.
;-----------------------------------------------------------------------
MCONIN:	CALL	PXCIN		;get console chr
	CPI	DEL
	RNZ
	MVI	A,BSPACE	;replace DEL with Backspace
	RET

;-----------------------------------------------------------------------
; RDRIN
;   Reader device input with modified return status convention.
;   The function returns with Z set if no character is present
;   or with Z clear and the char in A if a character is present.
;-----------------------------------------------------------------------
RDRIN	CALL	PXSSTA		;serial port data available?
	RZ			;No data, return with Z set
	JMP	PXSIN		;read the data into A, clear Z

;-----------------------------------------------------------------------
; CINITR, WINITR 
;   Cold and warm boot initialization
;-----------------------------------------------------------------------
WINITR
	;Any warm boot initialization goes here.
	RET

CINITR
	;Hardware initialization on cold boot goes
	;here if needed.  Make sure it ends with a RET.

	;Initialization string for terminal #8
	;of length "L" begins at "S" below.
STRING				;"S"
	RET	
STRLEN	EQU	$-STRING	;"L"

USRLEN	EQU	$-CINIT		;Length of USER AREA
	END
