*
*  USER CONFIGURATION MODULE FOR VECTOR GRAPHIC
*  DISK SYSTEMS AND CP/M 2.20
*  COPYRIGHT (C) 1979, 1980 VECTOR GRAPHIC INC.
*
*  This module contains the source code for the user configuration
*  area of the system.	The module can be broken up into two
*  sections.
*
*     (1)	Defining the user option and printer configuration
*		byte.
*     (2)	Source code for the different printer drivers.
*
*  For complete descriptions of the these areas, refer to the
*  Vector Graphic CP/M 2 users documentation.
*
***********************************************************************
*
		TITLE	USER CONFIGURATION AREA
*
*  DEFINE WHERE THE USER AREA BEGINS BY REQUESTING THE SYSTEM SIZE
*  AND THE BIOS VERSION.
*
MEMSIZE 	REQ	'SYSTEM SIZE (IN K BYTES): '
*
USERAREA	EQU	MEMSIZE*1024-300H
*
BS.BASE 	EQU	2		;BITSTREAMER 2 BASE ADDRESS
COM.DATA	EQU	BS.BASE+2	;COMMUNICATIONS DATA
COM.STAT	EQU	BS.BASE+3	;COMMUNICATIONS STATUS
SER.DATA	EQU	BS.BASE+4	;SERIAL DATA PORT
SER.STAT	EQU	BS.BASE+5	;SERIAL STATUS/COMMAND PORT
PAR.PORT	EQU	BS.BASE+6	;PARALLEL STATUS/DATA PORT (I/O)
PAR.CNTL	EQU	BS.BASE+6	;PARALLEL CONTROL PORT (ZCB)
PAR.DATA	EQU	BS.BASE+7	;PARALLEL DATA PORT (ZCB)
PAR.STAT	EQU	BS.BASE+8	;PARALLEL STATUS PORT (ZCB)
PAR.INIT	EQU	BS.BASE+9	;PARALLEL INITIALIZATION PORT (ZCB)
EXT.PRT 	EQU	0EC00H		;EXTERNAL PRINTER INIT ENTRY
*					;- DATA AT EXT.PRT+3
*					;- STATUS AT EXT.PRT+6
*
		ORG	USERAREA	;BEGIN EXECUTABLE CODE
*
***********************************************************************
*
*  DEFINE THE SYSTEM OPTION AND PRINTER CONFIGURATION BYTE
*  (DEFAULT AT NO PRINTER)
*
*  DEFINITION OPTIONS
*
*  PRINTER CONFIGURATIONS (ONE ONLY)
*
C.PINH		EQU	0		;INHIBIT PRINTER, SEND LIST TO CONSOLE
C.PTTY		EQU	1		;USE TTY DRIVER
C.PQUM		EQU	2		;USE QUME DRIVER
C.PCEN		EQU	4		;USE CENTRONICS DRIVER
C.PSYS		EQU	7		;USE SYSTEM PRINTER DRIVER (EXT.PRT)
*
C.APGE		EQU	80H		;AUTOMATIC PAGING OF LIST OUTPUT
*
*  SPECIFY CONFIGURATION BYTE BY SELECTING (ADDING) OPTIONS AS REQUIRED
*
USRCONF 	DB	C.PINH		;DEFAULT AT NO PRINTER
*
* A DESCRIPTION OF USRCONF:
*
*		BITS 0 - 2		PRINTER CONFIGURATION BYTE
*		BIT  3			COLD BOOT PROMPT INHIBIT
*					1 = INHIBIT, 0 = PERFORM
*		BIT  4			CONSOLE TO PRINTER INHIBIT
*					1 = INHIBIT, 0 = PERFORM
*		BIT  5			COLD BOOT AUTO COMMAND FLAG
*					1 = ON, 0 = OFF
*		BIT  6			WARM BOOT AUTO COMMAND FLAG
*					1 = ON, 0 = OFF
*		BIT  7			AUTOMATIC PAGING FLAG
*					1 = ON, 0 = OFF
*
*  TEMPORARY	STORAGE
*  - PLACED AT BEGINNING TO KEEP POSITION CONSTANT, RELATIVE
*    TO BEGINNING OF USER AREA
*
LINECOUNT	DB	56		;LINE COUNT - SECOND BYTE
PAGEPOS 	DB	00		;PAGE POSITION - THIRD BYTE
PAGESIZE	DB	0,0,0,0 	;FORM SIZE DECLARATION
USRCONF2	DB	0
*
* A DESCRIPTION OF USRCONF2:
*
*		BITS 0 - 6		RESERVED
*		BIT  7			I/O BOARD FLAG
*					1 = ZCB, 0 = I/O1 OR I/O2
*
***********************************************************************
*
*  BEGIN ENTRY JUMP TABLE
*
		JMP	COLDBOOT	;USER BOOT BOOT INITIALIZE
		JMP	WARMBOOT	;USER WARM BOOT INITIALIZE
		JMP	LISTSTATUS	;LIST STATUS REQUEST
		JMP	LISTOUT 	;USER LIST OUTPUT
		JMP	PUNCH		;USER PHYSICAL PUNCH
		JMP	READER		;USER PHYSICAL READER
*
*  ROUTINES IN ORDER OF JUMP TABLE
*
COLDBOOT	CALL	USRSETUP	;SET POINTER, GET PRINTER CODE
		PUSH	PSW		;SAVE PRINTER CODE
		BIT	7,M		;ZCB OR I/O BOARD ?
		JRZ	COLDBOOT10
		MVI	A,89H		;INIT BYTE FOR 8255
		OUT	PAR.INIT	;INIT FOR ZCB PARALLEL
COLDBOOT10	POP	PSW		;GET PRINTER CODE
		RZ			;NO PRINTER - SKIP INIT
		CPI	C.PSYS		;CHECK FOR EXTERNAL PRINTER
		JNC	EXT.PRT 	;INITIALIZE EXTERNAL PRINTER
		CPI	C.PCEN		;CHECK FOR CENTRONICS
		JRZ	COLDBOOT20	;SPECIAL IF CENTRONICS
					;OTHERWISE - ASSUME SERIAL
*
*  INITIALIZE BITSTREAMER USART - ONLY NECESSARY ON COLD START
*
		LXI	H,SERINIT	;POINT TO SERIAL INITIALIZATION DATA
		LXI	B,0600H+SER.STAT;GET READY TO SEND 6 BYTES TO SERSTAT
COLDBOOT15	OUTI
		JRNZ	COLDBOOT15
		RET
*
COLDBOOT20	MVI	A,80H		;STROBE IS BIT 7 (I/O)
		BIT	7,M		;TEST BOARD TO FIND STROBE LINE
		JRZ	COLDBOOT30
		MVI	A,01H		;STROBE IS BIT 0 (ZCB)
COLDBOOT30	OUT	PAR.CNTL
		RET
*
SERINIT 	DB	0,0,0		;RESET USART
		DB	40H,0CEH,27H	;MODE AND COMMAND
*
* WARM BOOT ROUTINE
*
WARMBOOT	RET			;OPEN FOR NOW
*
*  STATUS OF LIST DEVICE
*
*  RETURNS STATUS OF LIST DEVICE IN (A)
*    00 - PRINTER IS NOT READY FOR CHARACTER
*    FF - CHARACTER CAN BE SENT TO THE PRINTER
*
LISTSTATUS	CALL	USRSETUP	;SET POINTER,GET PRINTER CODE
		CPI	C.PSYS		;CHECK FOR SYSTEM OR NONE
		JNC	EXT.PRT+6	;CHECK EXTERNAL PRINTER
		CPI	C.PCEN		;CHECK FOR CENTRONICS
		JRNZ	LISTSTATUS10	;ASSUME SERIAL
		IN	PAR.STAT	;GET STATUS (ZCB)
		BIT	7,M		;ZCB OR I/O BOARD ?
		JRZ	LISTSTATUS05	;INPUT IS VALID
		IN	PAR.PORT	;GET STATUS (I/O)
LISTSTATUS05	ANI	1		;CHECK FOR READY
		RES	0,A		;ASSUME NOT READY
		RNZ			;RET IF NOT READY
		JMPR	LISTSTATUS20	;MAKE READY
LISTSTATUS10	IN	SER.STAT	;GET SERIAL STATUS
		ANI	1
		RZ			;PRINTER NOT READY
LISTSTATUS20	MVI	A,-1		;PRINTER IS READY
		RET
*
*  LIST OUTPUT SECTION
*
LISTOUT 	PUSH	B		;SAVE CHARACTER
		CALL	LISTDATA	;SEND OUT CHARACTER
		POP	B		;RESTORE CHARACTER
		MOV	A,C
		LXI	H,PAGEPOS	;POSITION ON PAGE
		CPI	0CH		;FORMFEED ?
		JRNZ	LISTOUT10
		MVI	M,0		;CLEAR PAGEPOS
		RET
LISTOUT10	CPI	0AH		;CARRIAGE RETURN
		RNZ			;NO SPECIAL ATTENTION
		INR	M
		LDA	LINECOUNT	;GET CURRENT SIZE
		CMP	M		;ARE WE OVER ?
		RNC
		MVI	M,0		;CLEAR PAGEPOS
		LDA	USRCONF 	;GET CONFIGURATION BYTE
		ANI	C.APGE		;CHECK FOR AUTO PAGING
		RZ			;RETURN IF NOT ACTIVE
		MVI	C,0CH		;FORM FEED PRINTER
					;FALL THRU TO LISTDATA ROUTINE
*
*  PHYSICAL LIST DATA OUTPUT HANDLER
*
LISTDATA	PUSH	B		;SAVE CHARACTER IN C
LISTDATA10	CALL	LISTSTATUS	;GET PRINTER STATUS
		ORA	A
		JRZ	LISTDATA10	;WAIT UNTIL READY
		POP	B
		CALL	USRSETUP	;SET POINTER,GET PRINTER CODE
		MOV	B,A		;SAVE PRINTER CODE
		CPI	C.PSYS		;SYSTEM PRINTER ?
		JNC	EXT.PRT+3	;EXTERNAL ROUTINE (CHAR IN C)
		CPI	C.PCEN		;CENTRONICS PRINTER ?
		MOV	A,C		;MOVE IN CHARACTER
		JRNZ	LISTDATA30	;ASSUME SERIAL
		BIT	7,M		;ZCB OR I/O ?
		JRZ	LISTDATA20	;JUMP IF ZCB
		RES	7,A		;RESET STROBE
		OUT	PAR.PORT	;PULSED OUTPUT
		SET	7,A		;SET STROBE AGAIN
		OUT	PAR.PORT
		RET
LISTDATA20	OUT	PAR.DATA	;SEND IT OUT
		XRA	A
		OUT	PAR.CNTL	;STROBE SET LOW (LATCH DATA)
		INR	A
		OUT	PAR.CNTL	;SET STROBE HIGH AGAIN
		RET
LISTDATA30	OUT	SER.DATA	;SEND IT OUT
		CPI	0AH		;LINEFEED ?
		RNZ			;NO MORE ATTENTION
		MOV	A,B		;GET SAVED USERCONF
		CPI	C.PQUM
		RNZ			;ALL DONE WITH STANDARD
LISTDATA40	CALL	LISTSTATUS	;WAIT FOR PRINTER READY
		ORA	A
		JRZ	LISTDATA40	;LOOP UNTIL READY
		MVI	A,3		;END OF TEXT CHARACTER
		OUT	SER.DATA	;SEND IT OUT
LISTDATA50	IN	SER.STAT	;WAIT FOR ACKNOWLEGE
		BIT	1,A
		JRZ	LISTDATA50
		IN	SER.DATA
		RES	7,A
		CPI	6		;CORRECT RESPONSE ?
		JRNZ	LISTDATA50	;CONTINUE WAITING
		RET
*
*  LOGICAL PUNCH OUPUT
*  SETUP FOR DATA COMMUNICATIONS
*  INITIALIZATION IS RESPONSIBILITY OF SYSTEM MONITOR
*
PUNCH		IN	COM.STAT	;GET STATUS
		BIT	0,A
		JRZ	PUNCH		;WAIT UNTIL READY
		MOV	A,C
		OUT	COM.DATA
		RET
*
*  LOGICAL READER INPUT
*  SETUP FOR DATA COMMUNICATIONS
*  INITIALIZATION IS RESPONSIBILITY OF SYSTEM MONITOR
*
READER		IN	COM.STAT	;GET STATUS
		BIT	1,A
		JRZ	READER
		IN	COM.DATA	;GET DATA
		RES	7,A		;CLEAR HIGH BIT (OPTIONAL)
		RET
*
USRSETUP	LXI	H,USRCONF2	;SET MEMORY POINTER
		LDA	USRCONF 	;GET CONFIG BYTE 1
		ANI	07H		;CLEAR OUT THE PRINTER CODE
		RET
*
		FILL	USERAREA+256-$,0 ;CLEAR REMAINING SPACE
*
