;
;	WSPATCH3.ASM -- VERSION 1.0 -- For F10-40 printers.
;
;====================================================================
;						                    |
; Wordstar patches combined from many other patches published, with |
; some enhancements and modifications.                              |
; Written by Mike Schwab, assistant librarian, Denver Osborne Group |
;   (303) 966-3102,  CompuServe 71555,222.		    	    |
;  Please contact me (telephone is faster) if you find any problems |
;  or have any suggestions.					    |
;								    |
; Refer to the WSPATCH2.DOC documentation file for instructions on  |
; modifying and installing this patch routine.			    |
;								    |
; Modified 1/5/84 by G. Dahl for F10-40 printer and 52-column       |
;   Osborne.							    |
; - For Wordstar version 2.26.					    |
; - Hor. scroll column is 52 (DWIDTH) if right margin <=52 (DWIDTH),|
;   42 (DWIDTH-10) if right margin >52 (DWIDTH).		    |
; - Highlight is optionally toggled with ^OD (set HTGLE to TRUE).   |
;   ^OD initially set OFF.  When turned ON, print control characters|
;   like ^S and ^B will immediately be displayed, but soft          |
;   hyphen highlighting will appear only when the line is re-       |
;   displayed, and blocks will be highlighted only when created or  |
;   unhidden (with ^KH ^KH).					    |
; - Use INSTALL program and select Qume Sprint 5 printer type       |
;   BEFORE running this patch.                      		    |
; - Output to printer slowed to 45 cps, for F10-40 (set SLOWPR to   |
;   TRUE).							    |
; - The print spooling modification from FOGHORN, November 1983,    |
;   p. 7 is implemented by setting SPOOL to TRUE.  NOTE change to   |
;   line labelled JSPOOL for SINGLE DENSITY Osbornes.		    |
;								    |
;___________________________________________________________________|
;
;
;	DEFINITIONS
;
TRUE	EQU	1
FALSE	EQU	NOT TRUE	
CURSOR	EQU	0EF5Ah	;location of cursor position in BMRAM
SCREEN	EQU	0F000h	;this was left out of Thom Hogan's listing
;					
;
;  	ADJUSTABLE OPTIONS (See documentation):
;
FAST	EQU	TRUE 	;if TRUE, memory mapped video being used.
HILITE	EQU	TRUE 	;if TRUE, underlined video selected for hilite.
HTGLE	EQU	TRUE	;toggle underlined highlight with ^OD.
SMOOTH	EQU	TRUE AND FAST 	;SMOOTH not allowed if not FAST.
SPECL	EQU	TRUE 	;special adjustable scroll mode keyed on right margin.
SLOWPR	EQU	TRUE	;For F10-40 printer, slow output to printer.  
WIDTH	EQU	80 	;width of screen to use (i.e: 80, 104, or 128).
DWIDTH	EQU	52	;width of actual display (52, 80, or 104).
COLSCR	EQU	52	;column to begin horizontal scroll after (if enabled).
SPOOL	EQU	TRUE	;turn on print spooling feature
;                   
;	(Note: setting SMOOTH=FALSE disables smooth scrolling without
;	 disabling the memory mapped video.) 
;
;
; 	ASCII control code equates - to be used in defining patches.
;
NUL	EQU	00H	;Null 
SOH	EQU	01H	;Start of Heading
STX	EQU	02H	;Start of Text
ETX	EQU	03H	;End of Text
EOT	EQU	04H	;End of Transmission
ENQ	EQU	05H	;Enquiry
ACK	EQU	06H	;Acknowledge
BEL	EQU	07H	;Bell
BS	EQU	08H	;Backspace
HT	EQU	09H	;Horizontal Tab
LF	EQU	0AH	;Line Feed
VT	EQU	0BH	;Vertical Tab
FF	EQU	0CH	;Form Feed
CR	EQU	0DH	;Carriage Return
SO	EQU	0EH	;Shift Out
SI	EQU	0FH	;Shift In
DLE	EQU	10H	;Date Link Escape
DC1	EQU	11H	;Device Control 1 (X-ON)
DC2	EQU	12H	;Device Control 2
DC3	EQU	13H	;Device Control 3 (X-OFF)
DC4	EQU	14H	;Device Control 4
NAK	EQU	15H	;Negative Acknowledge
SYN	EQU	16H	;Synchronous Idle
ETB	EQU	17H	;End of Transmission Block
CAN	EQU	18H	;Cancel
EM	EQU	19H	;End of Medium
SB	EQU	1AH	;Substitute
ESC 	EQU    	1BH	;Escape
FS	EQU	1CH	;File Separator
GS	EQU	1DH	;Group Separator
RS	EQU	1EH	;Record Separator
US	EQU	1FH	;Unit Separator
;___________________________________________________________________
;
;  PATCHES:
;
;	
;	Change Logo for terminal and printer:
;	 (May be changed if anyone cares)
;
	IF	FAST
	ORG	190H
	DB	'Memory Mapped  Osborne I         ';Limit LOGO to 33 characters
	ENDIF
;
	IF	SMOOTH	
	ORG	190H
	DB	'Smooth Scrolling Osborne I       ';Limit LOGO to 33 characters
	ENDIF
;
	ORG	1B4H
	DB	'F10-40 Printer                   ';Limit LOGO to 33 characters
	ENDIF
;
;	TERMINAL PATCH AREA
;
	ORG	248h	;origin of WordStar terminal patch area
HITE	DB	24	;24 lines on screen (do not change)
WID	DB 	WIDTH	;change with WIDTH equate above.
;
	ORG	264H
	IF	FAST
UCRPOS	JMP	WCUR		;use direct cursor addressing routine.
	ENDIF
	IF 	NOT FAST
UCRPOS	DB	0,0,0C9h	;Not used if terminal emulated
	ENDIF
;
	ORG	2A4H
INISUB	JMP	ITERM   	;initialization routine - set arrow keys.
UNISUB	JMP	XTERM		;termination routine - reset arrow keys.
USELST	DB	1		;Enable character in last position to show
	DB	0,0,0		;Reserved bytes for expansion
DELCUS	DB	5		;Delay after cursor set
DELMIS	DB	3		;Delay after other functions
;
; The following section contains the primary code which implements
; smooth scrolling on the Osborne 1.  Be careful when modifying this
; section.
;
	IF	FAST
MEMAPV	DB	1		;Use memory-mapped video
MEMADR	DW	SCREEN		;Screen location
	ENDIF
	IF 	NOT FAST
MEMAPV	DB	0		;Use terminal driver
MEMADR	DB	0,0		;No memory address needed
	ENDIF

	IF	HILITE
HIBIV	DB	80h		;Use underline for highlight
	ENDIF
	IF	NOT HILITE	
HIBIV	DB	00h		;No highlighting
	ENDIF
HIBCUR	DB	80h		;cursor set on self
CRBLIV	DB	0FFh		;blink cursor on self
;
	ORG	2BAH
	IF 	FAST
UCNSTA	JMP	CONST		;get console status from BIOS
UCONI	DB	0,0,0C9H	;if you put JMP INCON here, arrow keys are bypassed
UCONO	JMP	OUTCON		;send console output
	ENDIF
	IF	NOT FAST
UCNSTA	DB	0,0,0C9h	;no special console status from BIOS
UCONI	DB	0,0,0C9h	;no special console input
UCONO	DB	0,0,0C9h	;no special console output
	ENDIF
;
	ORG	2D1H
DEL3	DB	64	;delay before help menus appear (was 25, now longer).
DEL4	DB	00	;delay after signon screen (made shorter).
;___________________________________________________________________
;
;	SPECIAL ROUTINES FOR OSBORNE 1
;	Not part of Micro Pro patch items
;
;	Note that these routines use addresses within BIOS.  Since BIOS
;	 may be in different memory locations in different systems (like
;	 single and double density), and since this section is reloaded
;	 whenever another program is run from Wordstar (R command), each
;	 routine recalculates the current BIOS location on each call, using
;	 the jump to the BIOS warm start routine found in location 0 
;	 (the address is found at address 1).
;
	ORG	02D9h	;(I found that 2D7 and 2D8 are used in Wordstar)
; 
;	Initialization routine -- clear screen, set arrow keys
;	 for Wordstar, and turn off auto horizontal scroll.
;
ITERM	MVI	C,26		;clear screen code in C
	CALL	CONOUT		;send it
;
	LXI	B,0504H	 ;^E^D	;set arrow keys
	LXI	D,1813H	 ;^X^S	; to Wordstar
	XRA	A		;turn off horizontal scroll
;
AUTOS	LHLD	1		;fetch BIOS address
	IF	SMOOTH
	MVI	L,68H		;offset for auto scroll flag in BIOS
	MOV	M,A		;set auto horizontal scroll flag
	ENDIF
;
	MVI	L,7FH		;offset of pointer to arrow keys
	MOV	A,M		;fetch pointer to arrow keys
	INX	H		; and store in HL.
	MOV	H,M
	MOV	L,A
;
	MOV	M,B		
	INX	H		;      Set arrow keys
	MOV	M,C		
	INX	H
	MOV	M,D		
	INX	H
	MOV	M,E		
;
	RET			
;
; 	Termination routine - reset arrow keys to CP/M, and turn
;	on auto horizontal scroll.
;
XTERM	LXI	B,0B0CH	 ;^K^L	;set arrow keys
	LXI	D,0A08H	 ;^J^H	;  to CP/M
	MVI	A,0FFH		;turn on horizontal scroll
	JMP	AUTOS
;
;	Output from console routine
;
OUTCON	MOV	C,A		;get it in C where CP/M can use it
CONOUT	LHLD	1		;fetch BIOS address
	MVI	L,0CH		;offset for console output routine
	PCHL			;jump to it
;
CONST	LHLD	1		;fetch BIOS address
	MVI	L,06H		;offset for console status routine
	PCHL			;jump to it
;
;	Position cursor by brute force in BMRAM
;
WCUR	LXI	H,SCREEN	;Put screen start address in HL 
	DAD	D		;Add position of cursor in DE to HL
	SHLD	CURSOR		;Save new cursor position
	RET
;	
;	Special automatic scrolling routines and highlight toggle
;
SCROL	PUSH	H		;SAVE WORDSTAR REGISTERS
	PUSH	D
	PUSH	B
;
;	Turn hilight off if OD^ flag off
;
	IF	HILITE AND HTGLE

	CALL	TOGGLE	;toggle underline highlight with ^OD

	ENDIF
;
;
	IF	SPECL	;special scroll mode - adjust scroll column with 
			;  right margin width
	LDA	3728H		;Fetch current right margin.
	CPI	DWIDTH+1
	MVI	C,COLSCR-1	;load default screen column
	JC	JUMP2		;jump if right margin <= 52
	MOV	A,C		;put default screen column in A
	MVI	C,10		;subtract 10 from default screen column
	SUB	C		;
	MOV	C,A		;load new screen column into C 
JUMP2	LDA	371EH		;Fetch Wordstar's current column
	SUB	C		;Check if past adjusted scroll column
	ENDIF
;
	IF	NOT SPECL
	LDA	371EH		;Fetch Wordstar's current column
	SUI	COLSCR-1	;CHECK IF PAST SCROLL COLUMN
	ENDIF
;
	JNC	SCROL1		;YES - CONTINUE
	XRA	A		;NO - SET SCREEN TO COLUMN 1
SCROL1	CPI	WIDTH-DWIDTH	;CHECK IF CLEAR AT RIGHT SIDE
	JC	SCROL2		;NO - CONTINUE
	MVI	A,WIDTH-DWIDTH	;YES - STOP AT RIGHT SIDE
SCROL2	ADI	' '		;ADD CURSOR OFFSET
;
	PUSH	PSW		;SAVE X SCREEN POSITION
	MVI	C,ESC		;SEND SCREEN POSITIONING
	CALL	CONOUT		;  ESCAPE SEQUENCE
	MVI	C,'S'
	CALL  	CONOUT
	MVI	C,' '
	CALL	CONOUT
	POP	PSW		;RETRIEVE X SCREEN POSITION, 
	CALL	OUTCON		;  AND OUTPUT
;	
	POP	B		;RESTORE WORDSTAR REGISTERS
	POP 	D
	POP 	H
;
	JMP	1BBBH		;JUMP BACK TO WORDSTAR
;
; >>>>>>>>>  DO NOT LET THESE PATCH ROUTINES EXTEND BEYOND  <<<<<<<<<<
; >>>>>>>>>  035BH, AS 035CH AND ABOVE ARE USED BY WORDSTAR <<<<<<<<<<
;
	IF	SMOOTH
	ORG	1BB4h			;input prompt/command response in Wordstar
	CALL	SCROL			;don't reset to column 1 
;					; (messes up command prompts).
	ORG	30D2h			;input data character
	JMP	SCROL			; go directly to auto horizontal scroll routine
	ENDIF
;
;	Subroutine to toggle underline highlight with ^OD
;
;
	IF	HILITE AND HTGLE

	ORG	0A40H
TOGGLE	LDA	0225H	;OD^ flag, FFH for on, 0 for off
	ORA	A	;set zero flag if zero 
	LXI	H,3721H	;modify WS for highlight 
	JZ	JUMP4	;jump if zero
	MVI	M,80H
	INX	H	;increment HL
	MVI	M,0FFH
	RET
JUMP4	MVI	M,00H
	INX	H
	MVI	M,7FH
	RET
	ENDIF

;   (can use space here, 0A3D - 0A6D inclusive)

;   Part of print spooling patch:

	IF	SPOOL

	ORG	0A66H
JSPOOL	CALL	0E12DH

;		<<<<< 0E52DH for single density Osbornes >>>>>

	ANA	A
	RNZ
	CMC
	RET

	ENDIF

;	<<<<<<< mustn't go past 0A6DH >>>>>>>


;
;   Patches to correct video address calculations when
;   the screen width is less than 128 columns.  These 
;   patches are to places where Wordstar uses the WID
;   variable in address calculations.  They force the
;   use of the real 128 column video memory width 
;   instead, so that the correct address is calculated.
;
	IF	FAST	
;
	ORG	202BH		;signon screen display
	MVI	A,128
	NOP
;
	ORG	204FH		;scroll up code
	MVI	L,128
	NOP
;
	ORG	234CH		;general-purpose address calculation routine
	MVI	A,128
	NOP
;
	ORG	2E74H		;affects scroll down code
	LXI	H,8018H
;
	ENDIF
;___________________________________________________________________
;
; 	PROGRAM OPTION PATCH SECTION
;
;	 (Flags are 0FFH for on, 000H for off).
;
ON	EQU	0FFH
OFF	EQU	000H
;
	ORG	360H
ITHELP	DB	2		;initial help level: 0,1,2, or 3 (^JHn)
NITHLF	DB	ON		;????
ITITOG	DB	ON 		;Insert mode flag (^V)
ITDSDR	DB	ON		;Directory display flag (^KF)
	ORG	366H
INITPF	DB	08		;Line height (in 1/48's)
	DB	66		;Paper length (in lines) (.PLn)
	DW	528 		;Paper length (in 1/48's) 
	DB	08		;Line height repeated here
	DB	03		;Top margin (in lines) (.MTn)
	DW	24  		;Top margin (in 1/48's)
	DB	08		;Line height repeated again
	DB	02		;Heading margin (in lines) (.HMn)
	DW	16  		;Heading margin (in 1/48's)
	DB	08		;Line height repeated again
	DB	08		;Bottom margin (in lines) (.MBn)
	DW	64  		;Bottom margin (in 1/48's)
	DB	08 		;Line height repeated again
	DB	02		;Footing margin (in lines) (.FMn)
	DW	16  		;Footing margin (in 1/48's)
	DB	08 		;Line height repeated again
	DB	0 		;Must be 0 for standard char width
	DB	10 		;Standard char width (1/120's)(12=10char/inch)
	DB	12 		;Alternate char width (1/120's)(10=12/inch)
	DB	08		;Page offset in characters (.POn)
INITLM	DB	1-1 		;Left margin minus 1
INITRM	DB	52-1		;Right margin minus 1
INITSR	DB	3 		;Superscript roll (in 1/48's) 
	ORG	385H
INITWF	DB	ON		;Word wrap flag (^OW)
	DB	OFF		;Justification flag (^OJ)
	DB	ON		;Variable tabs flag (^OV)
	DB	OFF		;Soft hyphen entry flag (^OE)
	DB	OFF		;Hyphen help flag (^OH)
	DB	OFF		;Print control display flag (^OD)
	DB	ON		;Ruler display flag (^OT)
	DB	ON		;Dynamic page break flag
	DB	ON		;Page break display flag (^OP)
	DB	1		;Line spacing: 1-5 (.LS)
	ORG	391H
NONDOC	DB	OFF		;Enter WS in Non-document mode (???)
DECCHR	DB	'.'		;Decimal tab character 
	ORG	394H
DOTCHR	DB	'.'		;DOT command character
	ORG	396H
DOTSON	DB	ON		;Enable dynamic DOT command interpretation
	ORG	399H
HZONE	DB	4		;Hyphenation (3=shorter words, 5=longer words)
	ORG	3CAH	;change defaults in print command:
PODBLK	DB	OFF		;Disk file output from Print flag
	DB	OFF		;Use forms feeds during print
	DB	OFF		;Suppress page format during print
	DB	OFF		;Pause between pages during print
	ORG	3D3H
ITPOPN	DB	OFF		;Omit page numbers during print
	DB	ON		;Micro justify flag
	DB	ON		;Bidirectional print flag
	ORG	3D8H
RVELIM	DB	','		;Delimiter character in data file
	ORG	3DBH
VARCH1	DB	'&'		;Variable start
VARCH2	DB	'&'		;Variable end
	ORG	422H		
AUTOBS	DB	0		;Automatic backspace (???)
;___________________________________________________________________
;
;   PRINTER PATCH SECTION
;
;	This section will be different for each printer.  Most 
;	parameters will consist of a character count, followed 
;	by a string of ASCII characters.
;
; CAUTION - Make sure to leave the same number of bytes defined
;	       as were previously defined for each parameter,
;	       by adding or deleting trailing zeroes as needed.
;
	ORG	691H
BLDSTR	DB	2		;Number of strikes for boldface
			;>>>> WARNING <<<< must be 2 for daisywheel
			; printers or microspacing will be wrong
DBLSTR	DB	2		;Number of strikes for doublestrike
	ORG	696H
PSCRLF	DB	2,CR,LF 	;Advance to next line sequence
	DB	0,0,0,0,0,0,0,0	
PSCR	DB	1,CR,0,0,0,0,0	;Return carriage for overprint
PSHALF	DB	0,0,0,0,0,0,0	;Half line feed sequence
PBACKS	DB	1,BS,0,0,0,0	;Backspace character sequence
PALT	DB	0,0,0,0,0	;Alternate pitch (^PA)
PSTD	DB	0,0,0,0,0	;Standard pitch (^PN)
ROLUP	DB	0,0,0,0,0	;Superscript character sequence
ROLDOW	DB	0,0,0,0,0	;Supscript character sequence
USR1	DB	0,0,0,0,0	;User sequence 1 (^PQ)
USR2	DB	0,0,0,0,0	;User sequence 2 (^PW)
USR3	DB	1,ESC,0,0,0	;User sequence 3 (^PE)
USR4	DB	1,LF,0,0,0	;User sequence 4 (^PR)
RIBBON	DB	1,RS,0,0,0	;Alternate ribbon (^PY) - Full underline
RIBOFF	DB	1,US,0,0,0	;Standard ribbon (^PY) - Stop underlining
PSINIT	DB	0,0,0,0		;Printer initialization sequence
	DB	0,0,0,0,0,0,0   ;
	DB	0,0,0,0,0,0	
PSFINI	DB	1,CR,0,0	;Printer ending sequence
	DB	0,0,0,0,0,0	
	DB	0,0,0,0,0,0	
	ORG	70BH
SOCHR	DB	'-'		;Character used for strikeout
ULCHR	DB	'_'		;Character used for underlining

;
;	For F10-40 printers, slow character output to the printer (see 
;	Portable Companion, January 1983, p. 14
;
	IF	SLOWPR

	ORG	0797H
	DB	7AH

	ORG	07A1H
	DB	7AH

	ENDIF 

;
;	Print spooling modification (FOGHORN 11/83, p. 7)
;
	IF	SPOOL

	ORG	0718H
	DB	0FFH
	ORG	071AH
	JMP	JSPOOL

	ENDIF

	END
