; 6-16-86 GSD   added ID string for TRPATCH
; 5-21-86 GSD	fixed bug in '83 patches
; 4-3-86 Gary Dickinson Advent Products, Inc.
;
; Patches to Phil Becker's FASTBACK and FASTREST programs
; to enable them to operate with '83 and '84 model Kaypro computers
;
; These patches have been tested on FASTBACK 1.1, FASTREST 1.1A, and
; FASTREST 1.1B.
;
; The patches assemble with DRI MAC assembler and are intended to be
; patched into either FASTBACK.COM or FASTREST.COM using DDT.
;
; This code selects the first floppy disk drive which must be a
; standard double sided 48 TPI disk drive.
;
; This code takes into account the differences between the following
; types of 8 bit Kaypro Computers:
;
;	1.  '83 Kaypros (single serial port, no graphics)
;	2.  '84 Kaypros (two serial ports, graphics)
;       3.  Kaypro 10s (two serial ports, graphics, hard disk controller
;           reset logic tied to floppy disk select logic.
;
;
; The following table relates the bit port definitions for the 3 types
; of Kaypro Computers:
;
; +--------+------+-------+-------+-------+-------+-------+------+------+
; |  BIT   |  D7  |  D6   |  D5   |  D4   |  D3   |  D2   |  D1  |  D0  |
; +--------+------+-------+-------+-------+-------+-------+------+------+
; | '84/10 | BANK |  (1)  | DDEN* | MTRON | STRB* | SIDE* |  B*  |  A*  |
; +--------+------+-------+-------+-------+-------+-------+------+------+
; |  '84   | BANK | MTRON*| DDEN* | STRB* |  (2)  | SIDE  |  B   |  A   |
; +--------+------+-------+-------+-------+-------+-------+------+------+
;
; Notes:	
;      (1)  This bit when read is the BUSY* status for the parallel port.
;           This bit as an output controlls the alternate character gen-
;	    erator logic that has probably never been used.
;      (2)  This bit when read is the BUSY* status for the parallel port.	
;       *   These bits are active LOW
;
;
TRUE	EQU	0ffffh
FALSE	EQU	NOT TRUE

K10	EQU	FALSE   ; set true if Kaypro 10
K84	EQU	TRUE 	; set true if '84 Kaypro that is not K10
K83	EQU	FALSE	; set true if '83 Kaypro
FBACK	EQU	FALSE   ; set true if FASTBACK, FALSE if FASTREST
FRVERS	EQU	11BH	; FASTREST version 1.1B (11AH for version 1.1A)

	if	FBACK	; FASTBACK.COM Version 1.1
VMSG	EQU	02C0H
	org	02d2H	; ID string
	db	'1.1'
SELDRV	EQU	0E4EH
TGLSID	EQU	0E89H
	else	
	if	FRVERS EQ 11AH	; FASTREST.COM Version 1.1A
VMSG	EQU	02C0H
	org	02d2H	; ID string
	db	'1.1a'
SELDRV	EQU	1405H
TGLSID	EQU	1435H
	endif
	if	FRVERS EQ 11BH	; FASTREST.COM Version 1.1B
VMSG	EQU	02C0H
	org	02d2H	; ID string
	db	'1.1b'
SELDRV	EQU	1405H
TGLSID	EQU	1438H
	endif
	endif

	if	K84 OR K10	; '84 and K10 port and bit addresses

BITPORT	EQU	014H	; bit port address
BANK	EQU	080H	; Bank select bit pattern
DDEN	EQU	020H	; Double density bit pattern
MTRON	EQU	010H	; Motor on bit
STROBE	EQU	008H	; Parallel port strobe
SIDSEL	EQU	004H	; side select bit
BSEL	EQU	002H	; B: drive select
ASEL	EQU	001H	; A: drive select
STATE	EQU	DDEN OR SIDSEL OR BSEL OR ASEL	; negative true bits

	else		; '83 port and bit addresses

BITPORT	EQU	01CH	; bit port address
BANK	EQU	080H	; Bank select bit pattern
MTRON	EQU	040H	; Motor on bit
DDEN	EQU	020H	; Double density bit pattern
STROBE	EQU	010H	; Parallel port strobe
SIDSEL	EQU	004H	; side select bit
BSEL	EQU	002H	; B: drive select
ASEL	EQU	001H	; A: drive select
STATE	EQU	MTRON OR DDEN	; negative true bits
	endif

	if	K10	
BITMSK	EQU	002H	; mask for hard disk reset
	else
BITMSK	EQU	000H	; no hard disk reset
	endif

	org	VMSG	; version message

	if	K10
	db	'Kaypro 10 Version'
	endif
	if	K84
	db	'Kaypro 84 Version'
	endif
	if	K83
	db	'Kaypro 83 Version'
	endif

	org	SELDRV	; code to select floppy disk drive

	in	BITPORT	
	ani	BANK OR STROBE OR BITMSK
	ori	((MTRON OR ASEL OR DDEN) XOR STATE) AND NOT BITMSK
	out	BITPORT


	org	TGLSID		; code to switch sides on the diskette

	ani	SIDSEL		; isolate side select bit		
	xri	STATE		; correct side select polarity
	mov	b,a
	in	BITPORT
	ani	BANK OR STROBE OR BITMSK	; preserve these bits
	ori	((MTRON OR ASEL OR DDEN) XOR STATE) AND NOT (BITMSK OR SIDSEL)
	ora	b		; add back side select bit
	out	BITPORT

	end
