
 TITLE	'WSEXPAT4.ASM Wordstar 3.3 Patches	Aug. 24 1985'
;
;
; VERSION 1.0 INITIAL RELEASE 5/29/84	- Dave Campbell
; logging B: drive added  10/15/84  - Dave Walters
; memory mapped video routines added 8/20/85 - R. Prisco
;
; Overlay to patch WordStar Version 3.3 for an OSBOURNE EXEC
; This patch provides the following functions
;
;	1. Does not display the "Script" WORDSTAR initial Name
;	2. Does not display the MicroSoft Software Message
;	3. Add a BIOS call for the Printer Busy function
;	4. On entry set up the function and cursor keys to be
;	   WordStar compatible.
;	5. On exit restore the function keys to their state
;	   before WordStar was entered.
;	6. Add a Version Number Display (Over-writes the Port
;	   Driver Message )
;       7. Logs B: drive
;	8. Converts to memory map video (Eric Meyer)

; This file is MAC compatible

; **** DEFINE ALL ASCII EQUATES ****

CQ	EQU	11H	;ASCII CONTROL Q
CK	EQU	0BH	;ASCII CONTROL K
CA	EQU	01H	;ASCII CONTROL A [ WORD LEFT ]
CT	EQU	14H	;ASCII CONTROL T [ DELETE WORD ]
CS	EQU	13H	;ASCII CONTROL S [ CHAR LEFT ]
CD	EQU	04H	;ASCII CONTROL D [ CHAR RIGHT ]
CE	EQU	05H	;ASCII CONTROL E [ LINE UP ]
CX	EQU	18H	;ASCII CONTROL X [ LINE DOWN ]

ESC	EQU	1BH	;ASCII ESCAPE
CR	EQU	0DH	;ASCII CARRAGE RETRUN
LF	EQU	0AH	;ASCII LINE FEED
DEL	EQU	7FH	;ASCII DELETE

;;
;;************* MACRO DEF FOR Z80 INST *********************
;;
;;	@CHK MACRO USED FOR CHECKING 8 BIT DISPLACMENTS
;;

@CHECK	MACRO	?N	;; USED FOR CHECKING RANGE OF DISP.S
	?DD	SET ?N-$-2
	IF (?DD GT 07FH) AND (?DD LT 0FF80H)
'RANGE ERROR - Z80 LIB'
	?DD	SET	0FEH
	ENDIF 
	ENDM

LDED	MACRO	?NNNN		;;LOAD DE FROM MEMORY 
	DB	0EDH,5BH	;;  (E)=((NN)(NN))
	DW	?NNNN		;;  (D)=((NN)(NN+1))
	ENDM
LDIR	MACRO			;;MOVE (HL) <- (DE) TIL BC=0
	DB	0EDH,0B0H
	ENDM
DJNZ	MACRO	?N		;;DEC B JUMP RELATIVE NOT ZERO
	@CHECK	?N
	DB	10H,?DD
	ENDM
;
;************* DEFINE WORDSTAR ADDRESSES ******************
;
PDRVTX	EQU	01F6H	;WS PORT TEXT - OVERWRITE WITH VERS
INISUB	EQU	0287H	;TERMINAL INIT SUBROUTINE JUMP
MEMAPV	EQU	0290H	;MEMORY MAPPED VIDEO PATCHES
SWIN	EQU	02A3H	;OVERLAY BANK 7
SWOUT	EQU	02A9H	;REMOVE BANK 7
MORPAT	EQU	02CBH	;TERMINAL PATCH AREA ( 128 BYTES MAX )
HAVBSY	EQU	0718H	;PRINTER BUSY FLAG
PBGMEM	EQU	034BH	;WHERE WS SAVES END OF WS ADDR
;
;************* DEFINE OSBOURNE EXEC PARAMETERS ***********
;
BANKON	EQU	80H	;BIT TO TURN ON BANK 8
BANKOF	EQU	7FH	;MASK TO RESET BANK 8 BIT
FUNT	EQU	2155H	;START OF KEY RAM IN BANK 8

; **** OVER-WRITE THE PORT DRIVER MESSAGE ****
;      DON'T CHANGE LENGTH WHEN MODIFYING

	ORG	PDRVTX

	DB ' Patch 1.0           May 29 1984  '
	DB	0FH,0

	ORG	INISUB

; ****	INITIALIZATION SUBROUTINE ****

	JMP	LOGBDR	;LOG THE B DRIVE 

; **** 	DE-INITIALIZATION SUBROUTINE ****

	JMP	EXIT

; **** MEMORY MAPPED VIDEO AREA

	ORG	MEMAPV

	DB	01H	;YES, USE MEMORY MAPPED VIDEO
	DW	0C000H	;VIDEO RAM ADDRESS
	DB	00H	;BIT FOR REVERSE VIDEO (00 NO, 80 YES)
	DB	80H	;BIT TO SET FOR CURSOR
	DB	0FFH	;BLINK CURSOR IN REVERSE VIDEO AREA? (00 NO, FF YES)

; **** BANK SWITCHING AREA

	ORG	SWIN

	MVI	A,41H
	OUT	00H
	RET

	ORG	SWOUT

	MVI	A,01H
	OUT	00H
	RET
	
; **** TERMINAL PATCH AREA ****

	ORG	MORPAT

; **** TEST FOR PRINTER BUSY ****

BUSCEK	EQU	$+1	;DEFINE ADDRESS
PBUSY:	CALL	0	;SEE IF PRINTER BUSY
	ADI	1	;SET CARRY = 1 IF NOT BUSY
	CMC		;CARRY = 0 IF NOT BUSY
	RET		;BACK TO WORDSTAR

; **** CURSOR ESCAPE CODES

EM1:	DB	1BH,2EH,30H,'$'	;CURSOR OFF
EM2:	DB	1BH,2EH,31H,'$'	;BLINKING BLOCK CURSOR

; **** LOG TO B: DRIVE
 
LOGBDR:	
	MVI	C,0EH
	MVI	E,01H
	CALL	0005H

; **** TURN OFF CURSOR

	MVI	C,09H
	LXI	D, EM1
	CALL	05H

	JMP	INIT

;
; 		RELOC
;
; THIS ROUTINE RELOCATES ITSELF TO THE END OF WORDSTAR
; THEN BRANCHES TO ITSELF, SWAPS THE FUNCTION KEYS AND
; RETURNS TO WORDSTAR. THIS ROUTINE MUST BE RELOCATED
; PAST LOCATION 4000H BECAUSE THE BANK SELECT OPERATION
; LOCKS OUT ALL MEMORY IN BANK 1 BELOW 4000H
;
EXIT:	MVI	C,09H	;TURN ON BLINKING BLOCK CURSOR
	LXI	D,EM2
	CALL	05H

RELOC:	LDED	PBGMEM	;POINTER TO THE END OF WS
	LXI	H,SWAP	;POINTER TO START OF ROUTINE
	LXI	B,SLEN	;LENGTH OF ROUTINE
	PUSH	D	;SAVE START ADDR
	LDIR		;MOVE IN PLACE
	RET		;SWAP KEYS AND RETURN

SWAP:	IN	0	;GET BANK BITS
	ORI	BANKON	;ENABLE BANK 8
	DI		;INTERRUPTS OFF
	OUT	0	;SELECT BANK 8

	LXI	D,FUNT	;POINT TO FUNCTION TABLE
	LXI	H,RAMT	;WHERE STORED IN BANK 8 RAM
	MVI	B,TABL	;LENGTH OF KEY DEF'S

SWAPL:	MOV	C,M	
	LDAX	D
	MOV	M,A
	MOV	A,C
	STAX	D
	INX	H
	INX	D
	DJNZ	SWAPL	;POSITION INDEPENDANT LOOP

	IN	0
	ANI	BANKOF
	OUT	0	;TURN OFF BANK 8
	EI
	RET
 
SLEN	EQU	$-SWAP

	ORG	HAVBSY

; BUSY TEST FLAG

	DB 0FFH		; 0 = NO BUSY TEST

LIBSY:	JMP	PBUSY	;TEST FOR PRINTER BUSY

; SEND CHAR IN A REG TO PRINTER

LISEND:	MOV	C,A	;SET UP FOR BIOS CALL
POUT	EQU	$+1	;DEFINE ADDRESS
	JMP	0	;SEND TO PRINTER
	NOP
	NOP
	NOP
	NOP

; GET CHAR FROM PRINTER

LISINP:	NOP
	STC		;NO CHAR
	RET		;BACK TO WORDSTAR

;	THIS PATCH OVERLAYS MICRO-PRO'S SIGN ON 
;	AND SOFTWARE VERBAGE WITH A PATCH TO SET
;	ADDRESSES FOR PRINTER BUSY

; SOME NONSTANDARD PATCHES FROM EM

	ORG	2074H
	MVI	A,80H	;THESE ALLOW YOU TO LEAVE SCREEN WIDTH SET AT
	DB	00H	;80 (OR WHATEVER).  OTHERWISE YOU'D HAVE TO
	ORG	2098H	;CHANGE IT TO 128, AND THEN FLAGS WOULDN'T
	MVI	L,80H	;BE VISIBLE ON THE SCREEN.
	DB	00H 
	ORG	2355H
	MVI	A,80H
	DB	00H
	ORG	3DBFH
	LXI	H,8018H

	ORG	3CF1H

;	SET TARGET ADDRESSES FOR DIRECT BIOS CALLS

	LHLD	1	;GET COLD START ADDR
	XCHG		;TO DE REG
	LXI	H,2AH	;OFFSET TO LIST STATUS
	DAD	D	;POINTER TO THAT JUMP
	SHLD	BUSCEK	;SET ADDRESS
	LXI	H,0CH	;OFFSET TO PRINTER DRIVER
	DAD	D
	SHLD	POUT	;SET ADDR

	LXI	H,2	;ORIGINAL CODE
	CALL	2198H
	LXI	H,14EH	;POINTER TO RELEASE MESSAGE
	CALL	1B2AH
	LXI	H,112H	;POINTER TO COPYRIGHT MESSAGE
	CALL	1B2AH

; THIS PATCH OVER-LAYS THE MICROPRO SOFTWARE MESSAGE

	ORG	4120H

; MOVE FUNCTION KEY DATA INTO THE LAST BYTES OF THE
; FUNCTION KEY RAM. THEN SWAP WORDSTAR AND NORMAL KEYS

INIT:	IN	0	;GET BANK BITS
	ORI	BANKON	;ENABLE BANK 8
	DI		;INTERRUPTS OFF
	OUT	0
	LXI	H,KEYT	;POINT TO KEY TABLE
	LXI	D,RAMT	;WHERE STORE IN BANK 8 RAM
	MVI	B,TABL	;LENGTH
MOVL:	MOV	A,M
	STAX	D
	INX	H
	INX	D
	DCR	B
	JNZ	MOVL

	IN	0
	ANI	BANKOF
	OUT	0	;TURN OFF BANK 8
	EI
	JMP	RELOC	;NOW GO SWAP THE KEYS

KEYT:	DB	2	;FUNC. KEY 0 -- CURSOR TO END OF FILE
	DB	CQ,'C'

	DB	2	;FUNC. KEY 1 -- CURSOR TO START OF FILE
	DB	CQ,'R'

	DB	2	;FUNC. KEY 2 -- CURSOR TO END OF SCREEN
	DB	CQ,'X'

	DB	2	;FUNC. KEY 3 -- BLOCK START
	DB	CK,'B'

	DB	2	;FUNC. KEY 4 -- CURSOR TO START OF LINE
	DB	CQ,'S'

	DB	3	;FUNC. KEY 5 -- INSERT A LINE
	DB	CQ,'D',CR

	DB	2	;FUNC. KEY 6 -- CURSOR TO END OF LINE
	DB	CQ,'D'

	DB	2	;FUNC. KEY 7 -- DELETE TO BEGIN OF LINE
	DB	CQ,DEL

	DB	2	;FUNC. KEY 8 -- CURSOR TO TOP OF SCREEN
	DB	CQ,'E'

	DB	2	;FUNC. KEY 9 -- FIND STRING
	DB	CQ,'F'

	DB	1	;CURSOR UP
	DB	CE

	DB	1	;CURSOR RIGHT
	DB	CD

	DB	1	;CURSOR DOWN
	DB	CX

	DB	1	;CURSOR LEFT
	DB	CS

TABL	EQU	$-KEYT		;LENGTH OF TABLE
RAMT	EQU	2355H-TABL	;END OF KEY RAM

	END

OWN
	DB	CX

	DB	1	;CURSOR LEFT
	DB	CS

TABL	EQU	$-KEYT		;LENGTH OF TABLE
RAMT	EQ