; B5AS-1.INS for the Apple & Super Serial Card for BYE5 - 9/05/85
;
;	   6551 I/O with internal baudrate generator
;
;
; This version is for Apple ][ computers, using the Microsoft CP/M card
; and the Apple Super Serial Card.
;
;
; Note:  This is an insert, not an overlay.
;
;
;	MODEM=DCE			Super Serial Card
;
;	TXD	2  -------->	2	RXD	received data
;	RXD	3  <--------	3	TXD	tranmitted data
;	SG	7  ---------	7	SG	signal ground
;	DCD	8  -------->	6	DSR	data set ready (carrier)
;	DTR	20 <-------	20	DTR	data terminal ready
;
;
; This cable configuration uses DSR signal at the SSC to check carrier
; and Serial card DCD wired to DTR (Jumper pin 20-8) so that modem
; result codes are received when carrier is off.
;
; Set modem switches as defined in B5IM-1.DQC.
;
; THIS WORKS PROPERLY WITH BYE5 AND IS COMPATIBLE WITH IMP WITHOUT ANY
; CHANGES, ANY OTHER CONFIGURATION MIGHT REQUIRE RESETTING SOME MODEM
; SWITCHES WHEN GOING FROM BYE5 TO IMP, MDM7, MEX, ETC.
;
;-----------------------------------------------------------------------
;
; For the Apple //e, a user entered Control Q can trash the local dis-
; play by reverting back to 40 column mode.  This is a patch to turn
; that Control Q into a backspace.
;
; In BYE5 find the label MINP2A:  Just prior to MINP2A should be the
; lines:
;		JNZ	MINP2A
;		MVI	A,08H
;
; Add the following code just before JNZ MINP2A
;
;		JZ	CHNGIT
;		CPI	'Q'-'@'
;		JNZ	MINP2A
;	;
;	CHNGIT: MVI	A,08H	<< note the added label
;
;
; When using a Softcard CP/M system and the SSC, a warmboot causes the
; serial baud rate port to reset to its default setting.  (Whatever the
; switches are set to on the card.)  The problem is fixed by zeroing out
; the CALL in the warmboot routine that resets the baud rate.
;
; Find the following code in BYE5:
;
;			JMP	VWARMBT
;
; Just before this instruction, add the following code:
;			PUSH	PSW	 ;Save AF
;			XRA	A	 ;Make it zero
;			STA	0DAD8H	 ;Patch out the opcode
;			STA	0DAD9H	 ;Patch out the operand byte 1
;			STA	0DADAH	 ;Patch out the operand byte 2
;			POP	PSW	 ;Make it like it was
; Here's the end -->
; For reference -->	JMP	VWARMBT
;
; NOTE:  I suspect that this hack will work only with the 60k version
;	 version of Microsoft CP/M -- v2.2.3
;=================================
; 2/8/85 MADE CORRECTION FOR MICROSOFT OFFSET
; I COULD NOT GET THE HACK FOR NO RESET ON WARM BOOT TO WORK
; SO I JUST RUN ZCPR
;	REGARDS, 
;	ALLAN LEVY
;
;=  =  =  =  =	=  =  =  =  =  =  =  =	=  =  =  =  =  =  =  =	=  =
;
; 09/08/85  Created overlay for BYE5.  MBSSC-2 by Chris Heuser and
;	    Ryan Katri used as basis.		- Norman Beeler
;
;=  =  =  =  =	=  =  =  =  =  =  =  =	=  =  =  =  =  =  =  =	=  =
;
SLOT	EQU	2		; Slot 2 is normal
OFFS	EQU	16*SLOT		; This is the slot offset
MAPPM	EQU	2000H		; THIS IS THE MICROSOFT OFFSET
;
PORT	EQU	0C088H+OFFS+MAPPM	; Dataport	
STPORT	EQU	PORT+1		; Status port
CPORT	EQU	PORT+2		; Command port
BRPORT	EQU	PORT+3		; Baud rate port
;......
;
;
;-----------------------------------------------------------------------
;
; Routine to check carrier .. if not return with zero flag set
;
MDCARCK:LDA	STPORT		; Get status
	ANI	40H		; Check DSR pin for DCD (see above)
	XRI	40H		; Reverse the zero flag (the 6551
	RET			; Has status 0 for DCD/DSR true)
;.....
;
;
; This routine will turn off the serial card and hang up the phone.
;
MDINIT:	XRA	A		; Turn off DTR
	STA	STPORT
	PUSH	B		; Save register
	MVI	B,20		; Delay 2 sec to drop carrier
;
OFFTI:	CALL	DELAY		; 1 sec per loop
	DCR	B
	JNZ	OFFTI		; Keep going until finished
	POP	B		; Restore register
	MVI	A,4BH
	STA	CPORT
	MVI	A,18H		; Set 1200,8 bits, 1 stop
	STA	BRPORT
;
	 IF	IMODEM
	CALL	IMINIT
	 ENDIF
;
	RET
;.....
;
;
; Check the status to see if a character is available.  Return with zero
; flag set, if not.  If yes, use 0FFH to clear the flag.
;
MDINST:	LDA	STPORT		; Get modem status
	ANI	8		; Is data available?
	RZ			; If no, return
	ORI	0FFH		; Otherwise return true
	RET
;.....
;
;
; See if the output is ready for another character.
;
MDOUTST:LDA	STPORT		; Get modem status
	ANI	10H		; Mask out junk
	RZ
	ORI	0FFH
	RET
;.....
;
;
; Input a character from the modem port.
;
MDINP:	LDA	PORT		; Get character
	RET
;.....
;
;
; This routine will output a character to the data port.
;
MDOUTP:	STA	PORT		; Send character
	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,41H		; Drop DTR
	STA	CPORT
	XRA	A
	STA	STPORT
	RET
;.....
;
;
; If you do not support a particular baud rate, put it here before
; SETINV:
;
SETINV:	ORI	0FFH
	RET
;.....
;
;
SET300:	MVI	A,16H
	JMP	SETBAUD
;
SET1200:MVI	A,18H
	JMP	SETBAUD
;
SET2400:MVI	A,1AH
	JMP	SETBAUD
;
SET4800:MVI	A,1CH
	JMP	SETBAUD
;
SET9600:MVI	A,1EH
;
SETBAUD:STA	BRPORT
	XRA	A		; Shows the baud rate was changed ok
	RET
;
;			    end
;---------------------------------------------------------------------

.
