; PROGRAM:	FLASH22O.ASM
; VERSION:	1.0 MAY 12 1985
; PROGRAMMER:	MARGARET LOUISE PRETTY
; PURPOSE:	MODIFICATIONS TO FLASHPRINT FOR
;		OSBORNE 01 
;
; NOTES:
;	(1) STOPS CREATION OF WS .BAK FILE
;   	(2) CLEARS SCREEN FASTER WITH OSBORNE
;		ROUTINE
;	(3) GIVES BUSY FLAG FOR FASTER EDIT WHILE
;		PRINTING
;	(4) DOES DIRECT SCREEN MEMORY FOR FASTER
;		DISPLAY
;	(5) HAS AUTO SCROLLING ROUTINE FOR 
;		52-COLUMN SCREEN
;	(6) GIVES SQUARE BLINKING CURSOR ON
;		OSBORNE 01
;
; THIS PATCH FOR FLASHPRINT IS IN THE PUBLIC DOMAIN.
; FLASHPRINT WITH FLASHKEY IS COPYRIGHT 1984 JAMES 
; TUCKER AND IS AVAILABLE FROM:  FLASHLITE SOFTWARE,
; PO BOX 2179, DALY CITY, CA 94017 (415) 994-8282.
; YOU MUST INSTALL THIS PATCH IN FLASH22.COM.  NOT 
; TO BE INSTALLED IN WORDSTAR.
;
; NOTE THIS PATCH IS ONLY COMPATIBLE WITH 
; FLASH22.COM RELEASE H USING WORDSTAR VERSION 2.26.
; TESTED OK ON OSBORNE 1.44 ROM
;
; FLASHPRINT IS RELOCATED IN MEMORY AND AN OFFSET
; MUST BE ADDED TO ALL CALLS AND JUMPS -- THIS IS 
; THE OFFSET FOR FLASH22 RELEASE H.
;
OFFSET	EQU	7538H	; RELOCATION OFFSET RELEASE H

BIOS	EQU	0E100H	; ROM 1.44 BIOS ADDRESS. CHANGE TO 0E500H IF
			; YOU HAVE DIFFERENT ROM

; MODS FOR FLASH22.COM

	ORG	337H	; PATCH FLASH22 TO CALL OUR ROUTINES
	CALL	NEWPAT	; WHICH PATCH WS

	ORG	557H	; FLASH22 RELEASE H PATCH TO CALL OUR
	CALL	BLINK	; BLINKING CURSOR ROUTINE

; MAKE EXTRA PATCH SPACE FOR THESE MODS -- NOTE THAT TO MAKE SPACE
; FOR THIS PATCH THE MAXIMUM LENGTH OF YOUR FLASH.OVR FILE IS REDUCED
; BY 100H BYTES (256 DECIMAL). I DOUBT THIS WILL BE A PROBLEM.
; HOWEVER, FINSTALL DOES NOT KNOW ABOUT THIS PATCH AND WILL NOT REPORT
; AN ERROR IF THE MAX LENGTH IS EXCEEDED.

	ORG	230H
	DW	791H

	ORG	4E4H
	DW	791H+OFFSET

	ORG	50DH
	DW	791H+OFFSET

	ORG	46AH
	DW	791H+OFFSET



	ORG	58BH		; PATCH SPACE AT END OF RELEASE H

; THE FOLLOWING PATCHES WS SO NO .BAK FILE IS CREATED -- YOU MAY DELETE
; THIS IF YOU REQUIRE A BACKUP FILE. IF YOU DELETE THIS YOU MAY ALSO
; DELETE CODE AT NOBAK

NEWPAT:	EQU	$+OFFSET
	LXI	H,NOBAK		; PATCH WS FOR NO BACKUP FILE
	SHLD	17FEH		; WS CALL TO OUR ROUTINE (WAS CALL BDOS)

; WORDSTAR INTERNAL FLAGS

	MVI	A,0FFH		; SET BYTES NON-ZERO
	STA	718H		; CAN TELL IF PRINTER IS BUSY
	STA	2B0H		; USE MEMORY MAPPED SCREEN
	STA	2AAH		; DISPLAY IN LAST COLUMN IS OK
	STA	2B4H		; HI BIT IS THE CURSOR

	XRA	A		; A=ZERO
	STA	2B3H		; NO BIT FOR HIGHLIGHTING
				; SET 0FFH IF YOU WANT UNDERLINING
				; ON WORDSTAR MESSAGES

	LXI	H,0F000H	; START OF SCREEN IN OSBORNE RAM
	SHLD	2B1H		; TELL WORDSTAR

; PATCH WS TO JUMP TO OUR ROUTINES IN FLASHPRINT

	MVI	A,JMP		; PATCH JUMPS INTO WS
	STA	71AH		; PRINTER BUSY ROUTINE
	STA	2A4H		; CLEAR SCREEN ROUTINE
	STA	2A7H		; CLEAR SCREEN ROUTINE

	LXI	H,GETBUS	; OUR PRINTER BUSY ROUTINE
	SHLD	71BH		; JUMP ADDRESS

	LXI	H,CLRSCN	; OUR CLEAR SCREEN ROUTINE
	SHLD	2A5H		; WORDSTAR INISUB
	SHLD	2A8H		; WORDSTAR UNISUB

; THE FOLLOWING ARE SPECIAL PATCHES WHICH ALLOWS US TO USE DIRECT
; SCREEN MEMORY YET ANY WIDTH IN WORDSTAR WID (249H). IF YOUR SCREEN IS 128
; CHARACTERS WIDE (AS IS OSBORNE) YOU NORMALLY SET WID TO 128 -- WHICH MEANS
; THE LINE ENDINGS WILL OFF TO THE RIGHT IN NEVER NEVER LAND. THESE PATCHES
; FOOL WORDSTAR INTO THINKING THE SCREEN WID IS 128 WHEN PUTTING CHARS TO THE
; SCREEN BUT LESS (THE VALUE OF WID) WHEN ACTUALLY EDITING A FILE.

	MVI	A,3EH		; MVI A INSTRUCTION
	STA	202BH
	STA	234CH

	MVI	A,2EH		; MVI L INSTRUCTION
	STA	204FH

	MVI	A,128		; VALUE TO MOVE (WIDTH OF RAM SCREEN)
	STA	202CH
	STA	2050H
	STA	234DH

	XRA	A		; NOP INSTRUCTION
	STA	202DH
	STA	2051H
	STA	234EH

	MVI	A,21H		; LXI H INSTRUCTION
	STA	2E74H
	LXI	H,8018H		; VALUE TO LXI
	SHLD	2E75H

; PATCHES TO CALL AND JUMP TO OUR SCROLLING ROUTINES FOR DIRECT SCREEN

	LXI	H,PRSCRN	; PROMPT INPUT FROM WORDSTAR	
	SHLD	1BB5H

	LXI	H,EDSCRN	; EDITING INPUT FROM WORDSTAR	
	SHLD	30D3H
	
	LXI	H,7889H		; FLASH CODE WE PATCHED
	RET			; BACK TO FLASHPRINT



; WE HAVE FINISHED PATCHING WS - THE FOLLOWING ARE ROUTINES ADDED
; TO FLASH22.COM AND CALLED BY PATCHES TO WORDSTAR ABOVE


; PATCH FOR NO .BAK FILE - YOU MAY DELETE THIS CODE AND THE MOD
; ABOVE IF YOU REQUIRE .BAK FILES. NOTE WE ENTER WITH E POINTING
; TO 5CH IF RENAMING A .BAK FILE ELSE E POINTS TO A WORDSTAR
; INTERNAL ADDRESS.

NOBAK:	EQU	$+OFFSET
	MOV	A,C		; GET BDOS FUNCTION
	CPI	23		; IS IT RENAME?
	JNZ	NOBAKX		; NO SO FORGET IT

	MOV	A,E		; IS IT A .BAK FILE?
	CPI	5CH		; E = 5CH IF RENAMING .BAK
	JNZ	NOBAKX		; NO - MUST BE A .$$$ TEMPORARY FILE
	MVI	C,19		; YES - SO CHANGE IT TO CP/M DELETE

NOBAKX:	EQU	$+OFFSET
	CALL	5		; LET CP/M DO IT
	RET			; AND END OF PATCH


; GETBUS ROUTINE IS USED TO SPEED EDITING WHILE PRINTING
; THIS TELLS WORDTAR WE CAN TELL IF PRINTER IS BUSY WHICH SPEEDS UP
; EDITING WHILE PRINTING.

GETBUS:	EQU	$+OFFSET
	CALL	BIOS+2DH	; BIOS LIST STATUS
	ANA	A
	RNZ
	CMC
	RET


; CLEAR SCREEN ROUTINE CLEARS THE SCREEN QUICKLY AT BOOT TIME

CLRSCN:	EQU	$+OFFSET
	MVI	C,26		; OSBORNE CLEAR SCREEN CHAR
	JMP	BIOS+0CH	; SEND IT VIA BIOS



; OSBORNE HORIZONTAL SCROLLING FOR DIRECT SCREEN MEMORY ADDRESSING
; WARNING - YOU MUST TURN OFF AUTO SCROLL USING SETUP WHEN USING THIS

; THIS HANDLES SCREEN PROMPTS -- WE SCROLL AFTER 50 SO THE PROMPTS
; ARE DISPLAYED IN THEIR ENTIRETY.

PRSCRN:	EQU	$+OFFSET
	PUSH	B
	PUSH	D
	PUSH	H
	LDA	0371EH		; WS V2.26 STORES CURSOR COLUMN HERE
	SBI	50		; COLUMN-1 WE BEGIN SCROLLING
				; THIS IS NUMBER OF CHAR TO LEFT OF CURSOR
				; WHICH WILL BE DISPLAYED ON THE SCREEN
	JNC	CHAR1		; CUSOR BEYOND SO MAYBE SCROLL
	XRA	A		; NO SO HOME THE SCREEN
	JMP	CHAR1

; THIS HANDLES EDITING -- WE SCROLL AFTER 44 CHARACTER (YOU MAY CHANGE)

EDSCRN:	EQU	$+OFFSET
	PUSH	B
	PUSH	D
	PUSH	H
	LDA	0371EH		; WS V2.26 STORES CURSOR COLUMN HERE
	SBI	42		; COLUMN-1 WE BEGIN SCROLLING
				; THIS IS NUMBER OF CHAR TO LEFT OF CURSOR
				; WHICH WILL BE DISPLAYED ON THE SCREEN
	JNC	CHAR1		; CUSOR BEYOND SO MAYBE SCROLL
	XRA	A		; NO SO HOME THE SCREEN

; NO NEED TO KEEP SCROLLING IF THE END OF LINE CHARS ARE ON THE SCREEN

CHAR1:	EQU	$+OFFSET
	MOV	C,A		; SAVE POSITION
	LDA	249H		; GET WORDSTAR SCREEN WID V2.26
	SBI	52		; SUBTRACT OSBORNE SCREEN WIDTH
	CMP	C		; WID ON SCREEN?
	JC	POSIT		; YES - POSITION SCREEN HERE
	MOV	A,C		; RESTORE CURSOR POS

POSIT:	EQU	$+OFFSET
	ADI	32		; ADD REQUIRED OFFSET
	STA	STRING+3	; SAVE IN X CO-ORDINATE
	LXI	H,STRING	; GET STRING ADDRESS
	CALL	OUTSTR		; SEND IT

	POP	H		; ALL DONE
	POP	D
	POP	B
	JMP	1BBBH		; BACK TO WS

; ROUTINE TO SEND STRING POINTED BY HL

OUTSTR:	EQU	$+OFFSET
	MOV	A,M		; GET THE CHAR
	ORA	A		; SET FLAGS
	RZ			; ALL DONE?
	INX	H		; BUMP ADDRESS FOR NEXT TIME
	PUSH	H		; SAVE THE ADDRESS AS BIOS CLOBBERS
	MOV	C,A		; GET CHAR IN [C] FOR BIOS
	CALL	0E10CH		; BIOS SEND TO CONSOLE ROUTINE
	POP	H		; RESTORE ADDRESS
	JMP	OUTSTR		; AND GO AGAIN

STRING:	EQU	$+OFFSET
	DB	1BH,'S',32,0,0	; OSBONE SCROLLING STRING



; PATCH FOR BLINKING CURSOR ON OSBORNE - THIS ADDED TO FLASHMOD
; BY MLP MAY 13 1985

CURPOS	EQU	3972H	; WORDSTAR CURSOR POSITION IN V2.26
			; IF YOU HAVE NOT INSTALLED DIRECT SCREEN MEMORY
			; IN YOUR OSBORNE USE THE BIOS CURSOR POSITON WHICH
			; IS 0EF5AH

AHSCRL	EQU	0E7F6H	; 1.44 BIOS ROUTINE WHICH CAUSES OSBORNE TO DO
			; HORIZONTAL SCROLLING IF BIOS AHSENB IS
			; NON-ZERO -- I.E. YOU HAVE SCROLLING ON.
			; IF YOU HAVE A MODIFIED OR DIFFERENT BIOS
			; YOU MUST CHANGE THIS ADDRESS OR SUFFER A SMALL
			; CONSEQUENCE (SEE CALL BELOW).
			
CONST	EQU	BIOS+6	; BIOS GET STATUS OF CONSOLE (HAS THE USER
			; HIT A KEY) ROUTINE

CURSOR	EQU	22	; AN OSBORNE SOLID SQUARE -- YOU MAY CHANGE
			; TO ANOTHER CHARACTER

; BLINKING CURSOR ROUTINE

BLINK	EQU	$+OFFSET

; NORMALLY WS CALLS THE BIOS CONIN ROUTINE HERE TO GET A CHAR. THE FIRST
; THING CONIN DOES IS CHECK IF HORIZONTAL SCROLLING IS REQUIRED.
; WE DELAY CONIN WHILE WE FLASH THE CURSOR SO MUST CHECK FOR SCROLLING
; NOW ELSE CURSOR BLINKS IN COLUMN 1 BEFORE WE HAVE HOMED THE SCREEN.
;
; IF YOU DO NOT KNOW THE ADDRESS OF AHSCRL IN YOUR ROM YOU MAY DELETE
; THIS CALL BUT YOUR SCREEN WILL NOT SCROLL BACK UNTIL YOUR CURSOR IS
; ON THE SECOND CHARACTER IN THE LINE. YOU MAY DELETE THIS
; CALL IF SCROLLING IF TURNED OFF -- I.E. YOU HAVE DIRECT SCREEN
; MEMORY AND/OR YOU USE 80/104 COLUMN SCREENPAC WITH WORDSTAR.

	CALL	AHSCRL		; BIOS AUTO HORIZONTAL SCROLL ROUTINE
				; SEE NOTES ABOVE

	LHLD	CURPOS		; GET THE CURSOR POSITION
	MOV	A,M		; GET THE CHARACTER IN THIS POSITION
	XRI	80H		; REMOVE THE UNDERLINE
	MOV	C,A		; SAVE IT IN [C] FOR EASY ACCESS
	MVI	M,CURSOR	; REPLACE CHAR WITH CURSOR

TLOOP1:	EQU	$+OFFSET	; BLINK RATE
	LXI	D,4000		; YOU MAY CHANGE -- LESS MEANS FASTER

TLOOP2:	EQU	$+OFFSET
	PUSH	D		; SAVE THE COUNT
	CALL	CONST		; HE SHE HIT A KEY?
	POP	D		; RESTORE THE COUNT
	ORA	A		; SET FLAGS
	JNZ	KEYHIT		; YES - ALL DONE

	DCX	D		; COUNT DOWN
	MOV	A,E
	ORA	D		
	JNZ	TLOOP2		; MORE TO DO

; FALL THRU IF DE=ZERO SO REPLACE THE CURSOR OR CHARACTER

	LHLD	CURPOS		; GET CURSOR POSITION
	MOV	A,M		; GET CHARACTER HERE
	CPI	CURSOR		; IS IT A CURSOR?
	JZ	DOCHAR		; YES - PUT IN THE CHARACTER

	MVI	M,CURSOR	; NO - PUT IN A CURSOR
	JMP	TLOOP1		; AND START COUNTING AGAIN

DOCHAR:	EQU	$+OFFSET
	MOV	M,C		; PUT IN THE CHAR
	JMP	TLOOP1		; AND START COUNTING AGAIN

KEYHIT:	EQU	$+OFFSET
	LHLD	CURPOS		; GET CURSOR POSITION
	MOV	A,C		; GET CURRENT CHARACTER
	ADI	80H		; ADD THE UNDERLINE (WS NEEDS THIS)
	MOV	M,A		; PUT IT ON SCREEN

	LXI	H,7A9BH		; FLASH22 CODE WE PATCHED OVER
	RET			; BACK TO FLASHPRINT

	DB	'<<< MORE PATCH SPACE HERE'

END
