; B3AM-0.INS - AMPRO "Little Board" insert for BYE3 - 06/10/85
;
;               DART I/O and CTC timer 2.000 MHz
;
; Note:  This is an insert, not an overlay.
;
; This version is for the AMPRO "Little Board" using channel "B" of the
; Z80 DART.  The Z80-CTC is used as the baud rate generator.
;
;          The AMPRO computer does not implement DTR or DCD
;          (CTS and RTS are used instead).
;
;          Make up a RS232 cable per the instructions below:
;
;                       Modem      Ampro
;                       -----      -----
;                       pin 1   -  pin 1
;                       pin 2   -  pin 3
;                       pin 3   -  pin 2
;                       pin 6   -  pin 20
;                       pin 7   -  pin 7
;                       pin 20  -  pin 5
;
; Note: These pin assignments assume that your Little Board RS232 female
; connector is wired the same as the Ampro assembled computers.
;
;
; =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =
;
; 06/10/85  Written for use with BEE335 and later       - Irv Hoff
; 02/08/84  Initial Version                              Jerry Haigwood
;
; =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =
;
;-----------------------------------------------------------------------
;
;
PORT    EQU     88H             ; Data port
MDCTL1  EQU     PORT+4          ; Status/control port
BRPORT  EQU     50H             ; Baud rate port
;
;
BD300:  DW      47D0H           ; 62400/300  (first half is CTC command)
BD1200: DW      4734H           ; 62400/1200
BD2400: DW      471AH           ; 62400/2400
;
;
;-----------------------------------------------------------------------
;
; See if we still have a carrier - if not, return with the zero flag set
;
MDCARCK:MVI     A,10H           ; Reset status
       OUT     MDCTL1
       IN      MDCTL1          ; Get status
       ANI     20H             ; Check for data carrier
       RET
;.....
;
;
; Disconnect and wait for an incoming call
;
MDINIT: MVI     A,18H           ; Reset channel
       OUT     MDCTL1
       MVI     A,4             ; Setup to write register 4
       OUT     MDCTL1
       MVI     A,84H           ;*1 stop, 8 bits, no parity, 32x
       OUT     MDCTL1
       MVI     A,5             ; Setup to write register 5
       OUT     MDCTL1
       MVI     A,68H           ; Clear RTS causing hangup
       OUT     MDCTL1
       PUSH    B               ; Save in case it's being used elsewhere
       MVI     B,20            ; 2 seconds delay to drop any carrier
;
OFFTI:  CALL    DELAY           ; 0.1 second delay
       DCR     B
       JNZ     OFFTI           ; Keep looping until finished
       POP     B               ; Restore bc
       MVI     A,3             ; Setup to write register 3
       OUT     MDCTL1
       MVI     A,0C1H          ; Initialize receive register
       OUT     MDCTL1
       MVI     A,5             ; Setup to write register 5
       OUT     MDCTL1
       MVI     A,0EAH          ; Turn on RTS so modem can answer phone
       OUT     MDCTL1
;
        IF     IMODEM          ; If using intelligent modem
       CALL    IMINIT          ; Go initialize
        ENDIF                  ; IMODEM
;
       RET
;.....
;
;
; Input a character from the modem port
;
MDINP:  IN      PORT            ; Get character
       ANI     7FH             ; Strip parity
       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      MDCTL1          ; Get status
       ANI     01H             ; Check receive ready bit
       RZ                      ; Return if none
       ORI     0FFH            ; Otherwise, set the proper flag
       RET
;.....
;
;
; Send a character to the modem
;
MDOUTP: OUT     PORT            ; Send it
       RET
;.....
;
;
; See if the output is ready for another character
;
MDOUTST:IN      MDCTL1
       ANI     04H             ; Check transmit ready bit
       RET
;.....
;
;
; Reinitialize the modem and hang up the phone by dropping DTR and
; leaving it inactive.
;
MDQUIT:  IF     IMODEM          ; If using a smartmodem
       CALL    IMQUIT          ; Tell it to shut down
        ENDIF                  ; IMODEM
;
;
; Called by the main program after caller types BYE
;
MDSTOP: MVI     A,5             ; Setup to write register 5
       OUT     MDCTL1
       MVI     A,68H           ; Clear RTS causing shutdown
       OUT     MDCTL1
       RET
;.....
;
;
; The following routine sets the baudrate.  BYE3 asks for the maximum
; speed you have available.
;
SETINV: ORI     0FFH            ; Make sure zero flag is not set
       RET                     ; Return
;.....
;
;
SET300: LHLD    BD300           ; Get 300 bps parameters in 'HL'
       JMP     LOADBD          ; Go load them
;
SET1200:LHLD    BD1200
       JMP     LOADBD
;
SET2400:LHLD    BD2400
;
LOADBD: MOV     A,H             ; CTC command word
       STA     BRPORT
       MOV     A,L             ; Baudrate
       STA     BRPORT
       RET
;.....
;
;                              end
;-----------------------------------------------------------------------