*
*  USER CONFIGURATION MODULE FOR THE VECTOR GRAPHIC CP/M 2.0 SYSTEMS
*  COPYRIGHT (C) 1979 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.0 USERS DOCUMENTATION.
*
***********************************************************************
*
             TITLE   USER CONFIGURATION AREA
*
*  DEFINE WHERE THE USER AREA BEGINS BY REQUESTING THE SYSTEM SIZE
*
MEMSIZE      REQ     'SYSTEM SIZE (IN K BYTES) :'
*
USERAREA     EQU     MEMSIZE*1024-300H    ;CALCULATE STARTING ADDRESS
*
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
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
*
*  TEMPORARY STORAGE
*  - PLACED AT BEGINNING TO KEEP POSITION CONSTANT, RELATIVE
*    TO BEGINNING OF USER AREA
*
PAGESIZE     DB      56                   ;PAGE SIZE - SECOND BYTE
PAGEPOS      DB      00                   ;PAGE POSITION - THIRD BYTE
*
***********************************************************************
*
             ORG     USERAREA+8
*
*  BEGIN ENTRY JUMP TABLE
*
             JMP     COLDBOOT             ;USER COLD 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     LDA     USRCONF              ;GET CONFIG BYTE
             ANI     7                    ;TEST FOR SERIAL
             RZ                           ;NO PRINTER - SKIP INIT
             CPI     7                    ;CHECK FOR EXTERNAL PRINTER
             JZ      EXT.PRT              ;VECTOR TO INIT ENTRY
             CPI     4                    ;CHECK FOR SERIAL PRINTER
             RNC                          ;OTHERWISE - SKIP INT
*
*  INITIALIZE BITSTREAMER USART - ONLY NECESSARY ON COLD START
*
             XRA     A
             OUT     SER.STAT             ;RESET USART
             OUT     SER.STAT
             OUT     SER.STAT
             MVI     A,40H
             OUT     SER.STAT
             MVI     A,0CEH
             OUT     SER.STAT             ;SEND MODE BYTE
             MVI     A,27H
             OUT     SER.STAT             ;SEND COMMAND BYTE
             RET
*
* 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   LDA     USRCONF              ;GET CONFIGURATION BYTE
             ANI     7                    ;MASK OFF PRINTER PART
             MOV     B,A                  ;SAVE
             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.PORT             ;GET PARALLEL STATUS
             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,0FFH               ;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                  ;LINEFEED ?
             RNZ                          ;NO SPECIAL ATTENTION
             INR     M
             LDA     PAGESIZE             ;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
             JMPR    LISTDATA
*
*  PHYSICAL LIST DATA OUTPUT HANDLER
*
LISTDATA     PUSH    B                    ;SAVE CHARACTER IN C
LISTDATA05   CALL    LISTSTATUS           ;GET PRINTER STATUS
             ORA     A
             JRZ     LISTDATA05           ;WAIT UNTIL READY
             POP     B
             LDA     USRCONF              ;GET CONFIGURATION BYTE
             ANI     07                   ;MASK OFF PRINTER PART
             MOV     B,A                  ;SAVE IT
             CPI     C.PSYS               ;SYSTEM PRINTER ?
             JZ      EXT.PRT+3            ;EXTERNAL ROUTINE (CHAR IN C)
             CPI     C.PCEN               ;CENTRONICS PRINTER ?
             MOV     A,C                  ;MOVE IN CHARACTER
             JRNZ    LISTDATA10           ;ASSUME SERIAL
             SET     7,A                  ;SET STROBE
             OUT     PAR.PORT             ;SEND IT OUT
             RES     7,A                  ;RESET STROBE
             OUT     PAR.PORT             ;PULSED OUTPUT
             SET     7,A                  ;SET IT AGAIN
             OUT     PAR.PORT
             RET
LISTDATA10   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
LISTDATA20   CALL    LISTSTATUS           ;WAIT FOR PRINTER READY
             ORA     A
             JRZ     LISTDATA20           ;LOOP UNTIL READY
             MVI     A,3                  ;END OF TEXT CHARACTER
             OUT     SER.DATA             ;SEND IT OUT
LISTDATA30   IN      SER.STAT             ;WAIT FOR ACKNOWLEGE
             BIT     1,A
             JRZ     LISTDATA30
             IN      SER.DATA
             RES     7,A
             CPI     6                    ;CORRECT RESPONSE ?
             JRNZ    LISTDATA30           ;CONTINUE WAITING
             RZ
*
*  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
*
             FILL    USERAREA+256-$,0     ;CLEAR REMAINING SPACE
*
