; B3MD-2.INS - BYE3 insert for Morrow Micro Decision Computers  07/30/85
;
; Pin 8 (DCD) from the modem must be connected to the USART's DSR input,
; either on the internal jumper block or in the modem connecting cable.
;
;            Note:  This is an insert, not an overlay.
;
; =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =
;
; 07/30/85  Restored to original format                 - pst
; 03/30/85  Written for Rev 1.x and Rev 2.x boards      - Jim Sinning
;
; =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =
;
;
; The following equate will be YES if using a later Micro Decision with
; Intel 8253 timer chip and Centronics Port.  Set NO for rev 1.x board.
;
REV2X   EQU     YES             ; Yes if Centronix port and 8253 chip
                               ; No if Rev 1.x board
;
; The following define the port address to use
;
DPORT   EQU     0FEH            ; Data port
SPORT   EQU     DPORT+1         ; Status/control port
;
; NOTE: The DIP switches for Serial 2 Port must be set for 1200 baud for
; this to work.
;
        IF     REV2X
BDPORT  EQU     0F2H            ; Serial 2 Port on Intel 8253 timer
CDPORT  EQU     0F3H            ; 8253 control port
MODINS1 EQU     4EH             ; 8 bits, 1 stop, 16x, no parity
        ENDIF                  ; REV2X
;
        IF     NOT REV2X
BDPORT  EQU     SPORT           ; Baud rate port=8251 control
CDPORT  EQU     SPORT           ; Control port=8251 control
MODINS1 EQU     4FH             ; 8 bits, 1 stop, 64x, no parity
        ENDIF                  ; NOT REV2X
;
; The following byte selects the proper mode for the Intel 8253 timer.
; Selects counter 2, reads least significant byte then most significant
; byte, sets the square wave generator and count is binary.
;
        IF     REV2X
CNTR2   EQU     0BEH
        ENDIF                  ; REV2X
;
DAV     EQU     00000010B       ; Data available
TBMT    EQU     00000001B       ; Transmit buffer empty
DCD     EQU     10000000B       ; Data carrier detect
;
;-----------------------------------------------------------------------
;
;
; See if we still have a carrier - if not, return with the zero flag set
;
MDCARCK:IN      SPORT           ; Get status
       ANI     80H             ; Check DSR bit for a carrier
       RET
;
; Disconnect and wait for an incoming call
;
MDINIT: MVI     A,10H           ; Clear DTR
       OUT     SPORT           ; Causing hangup
;
       PUSH    B               ; Preserve in case we need it
       MVI     B,20            ; 2 second delay
OFFTI:  CALL    DELAY           ; 0.1 second delay
       DCR     B
       JNZ     OFFTI           ; Keep looping until finnished
       POP     B               ; Restore BC
;
       MVI     A,17H           ; Assert DTR so that modem
       OUT     SPORT           ; Can answer phone
       CALL    UDELAY          ; Added to be safe
;
        IF     IMODEM
       CALL    IMINIT
        ENDIF                  ; IMODEM
;
       RET
;
; Input a character from the modem port
;
MDINP:  IN      DPORT           ; Get character
       RET
;
; Check the status to see if a character is available.  If not, return
; with the zero flag set.  If yes, use 0FFH to clear the flag.
;
MDINST: IN      SPORT           ; Get status
       ANI     DAV             ; Check the receive ready bit
       RZ                      ; Return if none
       ORI     255
       RET
;
; Send a character to the modem
;
MDOUTP: OUT     DPORT           ; Send it
       RET
;
; See if the output is ready for another character
;
MDOUTST:IN      SPORT
       ANI     TBMT            ; Check the transmit ready bit
       RZ
       ORI     255
       RET
;
; Reinitialize the modem and hang up the phone by dropping DTR and
; leaving it inactive.
;
MDQUIT:  IF     IMODEM
       CALL    IMQUIT          ; Tell smartmodem to quit
        ENDIF                  ; IMODEM
;
;
; Called by the main program after caller types BYE
;
MDSTOP: MVI     A,10H           ; Turn off DTR
       OUT     SPORT
       RET
;
;-----------------------------------------------------------------------
;                    Start of rev 1.x speeds
;
; The following routine sets the baudrate.  BYE3 asks for the maximum
; speed you have available.
;
        IF     NOT REV2X
SET2400 ORI     255             ; Rev 1 doesn't support 2400 baud
       RET
;
SET300: MVI     B,BD300
       JMP     SETBAUD
;
SET1200:MVI     B,BD1200
;
SETBAUD:MVI     A,47H           ; Reset, enable Rx, DTR, Tx
       OUT     SPORT           ; Rx,Tx enabled
       CALL    UDELAY
       MOV     A,B             ; Recover Baud Rate Word
       OUT     BDPORT
       CALL    UDELAY          ; Wait for USART
       MVI     A,17H           ; ERR reset, DTR, Rx, Tx all on
       OUT     SPORT
       CALL    UDELAY
       XRA     A               ; Say rate OK
       RET
;
; Values to switch the 8251 between x16 and x64 for rev 1.x boards
;
BD300   EQU     4FH             ; 300 baud
BD1200  EQU     4EH             ; 1200 bps
        ENDIF                  ; NOT REV2X
;
;                     End of rev 1.x speeds
;-----------------------------------------------------------------------
;                    Start of rev 2.x speeds
;
        IF     REV2X           ; 300/1200/2400 baud supported
SET300: LXI     H,BD300         ; Point Divisor word
       JMP     SETBAUD
;
SET1200:LXI     H,BD1200
       JMP     SETBAUD
;
SET2400:LXI     H,BD2400
;
SETBAUD:MVI     A,CNTR2         ; Select Serial 2 Counter
       OUT     CDPORT
       CALL    UDELAY
       MOV     A,L             ; Send Least significant byte
       OUT     BDPORT
       CALL    UDELAY
       MOV     A,H
       OUT     BDPORT
       CALL    UDELAY
       MVI     A,17H           ; ERR reset, Rx, DTR, Tx all on
       OUT     SPORT
       CALL    UDELAY
       XRA     A               ; Say baud rate is OK
       RET
;
; The following data words are the Intel 8253 divisors for BDPORT
;
BD300   EQU     416             ; 300 baud
BD1200  EQU     104             ; 1200 bps
BD2400  EQU     52              ; 2400 bps
BD9600  EQU     13              ; 9600 bps
        ENDIF                  ; REV2X
;
; IN8251 specific USART delay
;
UDELAY: NOP
       NOP
       NOP
       RET
;                              end
;------------------------------------------------------