
; VDO-OVR.ASM		

; a set of overlays  to VDO.COM       10 April, 1985
; to provide cosmetic changes and function key support
; [this patch does not make use of the source code]

; R. Gaspari	  Comm Labs RBBS      (213) 648-0805  

; ****************************************************
;             GENERAL EQUATES
; ****************************************************

CLEAR	EQU	 04H	  ; your terminal clear screen code (usually 1Ah)
BLOCK	EQU	 'K'	  ; your preferred block command  (either K or O)
	
BDOS    EQU      0005H
CR      EQU      0DH
LF      EQU      0AH
;
; *****************************************************
;          INTERNAL CHANGES TO VDO.COM                
; *****************************************************

	ORG	1347H	  ; this implements your selection of
	DB	BLOCK-40H ; choice of ^K or ^O (chosen above)
	ORG	0FD0H
	DB	BLOCK	  ; same task, different location
	ORG	12ADH
	DB	BLOCK	  ; ditto
			  ; credit to finding the locations above
			  ; to VDO.PAT by  BOB BROOKS,  3-15-85
	ORG	0177H	  ; this implements your selection of
	DB	CLEAR	  ; your terminal's CLR SCREEN code

; *****************************************************
;       PATCH TO ALLOW USE OF FUNCTION KEYS
; *****************************************************

	ORG	01C3H	  ; this location is inside the
	JMP	KEY   	  ; original char input routine


        ORG      14E0H	  ; this is past the 1480h end of the orig 
			  ; VDO.COM so that some space is allowed
			  ; for bookkeeping by VDO.
KEY:  			  ; added procedure to trap function keys
	CALL	KEYFN	  ; call the subroutine
	POP	B	  ; replace the POPs overwritten by JMP KEY
	POP	D			
	POP	H			
	RET			;return to VDO.COM (RET from 01B5h)
KEYFN:				;subroutine to replace fn keys
	CPI	0FH		;trap ^O
	JZ	KEYFN0			
	CPI	80H		;assume all keys with bit 8 set
				;will want to be changed
	JNC	KEYFN0			
	RET			;char input not in classes above
KEYFN0:				;...will not be changed by KEYFN0
	MOV	D,A		;save the char for future use
	LXI	H,KEYTABL	;prepare to search table
KEYFN1:				;start the search
	MOV	A,D		;retrieve orig character
	CMP	M		;compare the char to the table
	JZ	KEYFN4		;if match go make exchange
KEYFN2:				;no match so continue search
	INX	H		;next byte in the table
	INX	H
	MOV	A,M		;move it in for inspection
	CPI	0FFH		;because FF marks end of table
	JNZ	KEYFN1		;if not end continue search
	MVI	A,0   		;no more char in table so...
	RET			;return a zero (RET from KEYFN)
KEYFN4:				;substitution
	INX	H		;the substitution is the byte 
	MOV	A,M		;....after the match
	RET			;....so return with it (RET KEYFN)
KEYTABL:			;my function key replacement table
	DB	82H,05H		;if  up-arrow    send  ^E
	DB	86H,04H		;if  right-arrow send  ^D
	DB	88H,13H		;if  left-arrow  send  ^S
	DB	8AH,18H		;if  down-arrow  send  ^X
	DB	0DBH,0BH    	;if  fct key F1  send  ^K
				;		
	DB	0E3H,0BH	;    F9  = ^K
	DB	0E4H,0BH	;    F10 = ^K
	DB	0E5H,15H	;    F11 = ^U
	DB	0E8H,16H	;    F14 = ^V	
	DB	0E9H,07H	;    F15 = ^G
	DB	0EAH,0BH	; SH-F1  = ^K
	DB	0EBH,0BH	; SH-F2  = ^K
	DB	0F2H,0BH	; SH-F9  = ^K
	DB	0F3H,0BH	; SH-F10 = ^K   
	DB	0F4H,11H	; SH-F11 = ^Q
	DB	0F7H,0EH	; SH-F14 = ^N
	DB	0F8H,19H	; SH-F15 = ^Y
	DB	089H,12H	; arrow NE = ^R
	DB	083H,03H	; arrow SE = ^C
	DB	085H,11H	; cursor 5 = ^Q
	DB	094H,01H	; CNTL rt arrow = ^A
	DB	096H,06H	; CNTL lt arrow = ^F

	DB	0Fh,0Bh		; make ^O same as ^K (why not?)

	DB	0FFH,0FFh	;important -- marks end of table
;				;end of subroutine KEY

KEYEND 	EQU	$	 ; IMPORTANT --- this address MUST be less than
			 ; 15C0h where the TEXT file will be located.
			 ; Check your  .PRN  file after Assembly.
   
; *****************************************************
;     PRELIMINARY ROUTINES BEFORE NORMAL EXECUTION
; *****************************************************

        ORG      0100H	  ; at beginning of the program...
        JMP      FRILLS	  ; ...go here first for prelim routines

	ORG	KEYEND		; frills located after function 
FRILLS:				; key patch above
	CALL	ROUTINE1	; #1 is RBBS check
	CALL	ROUTINE2	; #2 is print initial message
	CALL	ROUTINE3	; #3 is cursor lock on (NS only) 

			  ; this subroutine re-creates VDO.COM	
        MVI     A,31H     ; into its original form before
        STA     0100H     ; "JMP FRILLS" overwrote it
	MVI	A,0B2H
	STA	0101H	  ; 31h, B2h, 14h  were contents
	MVI	A,014H	  ; at 0100h before overwritten
	STA	0102H
	JMP	0100H	  ; this executes VDO as normal

;....
; End of preliminary routines.  Note that everything after KEYEND
; will be overwritten by the text file so never put anything here
; that needs to stay here after editing has started.  These routines
; are done at start-up and forgotton afterwards.


; ******************************************************
;               PRELIMINARY ROUTINE  #1
;     THIS DISALLOWS OPERATION IF  RBBS  IS IN OPERATION
; ******************************************************

ROUTINE1:
	LDA	004FH
	CPI	43H
	JNZ	ENDROUTE1
	MVI	C,9
	LXI	D,BBSMSG
	CALL	BDOS
	JMP	0
BBSMSG:
	DB	CR,LF,LF,LF
	DB	' VDO  is not executable while in Bulletin Board'
	DB	' operation.',CR,LF,LF,LF
	DB	'$'
ENDROUTE1:
	RET

; **********************************************************
;             	PRELIMINARY ROUTINE #2			
;      THIS PRINTS A NICE LEAD-IN MESSAGE BEFORE EXECUTION
; **********************************************************
			  ; for personal preferences, this
            		  ; preliminary message is printed
ROUTINE2:
	MVI	E,CLEAR	  ; clear screen
	MVI	C,02
	CALL	BDOS

        MVI      C,9
        LXI      D,MESSAGE
        CALL     BDOS     ; print message
;
        MVI     C,1
        CALL    BDOS      ; enter any key
	PUSH    PSW	  ; store to check later if ^C
	MVI	E,CLEAR	  ; then continue
	MVI	C,02
	CALL	BDOS	  ; clear screen again
				
	POP	PSW    	  ; this allows for graceful exit
	CPI	3	  ; ...if ^C entered in response to
	JZ	0	  ; ..."Enter any key to continue" 
	JMP	ENDROUTE2

MESSAGE:
        DB      CR,LF,LF,LF
        DB      ' VDO.COM is a full screen editor with'
        DB      ' commands similar to WORDSTAR.',CR,LF,LF
	DB	' This version patched for function key'
	DB	' support for Northstar Advantage. ',CR,LF,LF
        DB      ' Enter    ^',BLOCK,'^X    to save and exit. ',CR,LF
        DB      9,'    \',CR,LF,9,'     \',CR,LF 
	DB	9,'      \_______   IMPORTANT! '
	DB	CR,LF,LF,LF,LF,LF,LF,LF,LF,LF,LF
        DB      ' Enter any key to continue  ----  ','$'

ENDROUTE2:
	RET

; ****************************************************************
;                PRELIMINARY ROUTINE  #3		
;     SET CURSOR LOCK -ON-	(FOR NORTHSTAR ONLY)	
; ****************************************************************

; For Northstar Advantage only.   Sets cursor lock ON at start-up.

; This prelim routine feature is particularly important if patch
; is used which activates the cursor (arrow) keys.
ROUTINE3:

	DI			;...this new code
	CALL	CURSOR		;this calls the cursor set routine
	EI
	JMP	ENDROUTE3
CURSOR:				;set cursor-lock subroutine
	LXI	H,0401H		;04 is code to send to F0 register
	CALL	STATE		;01 is the bit to check if lock set
	JZ	CURSOR		;do over if flip state went wrong way
	RET			;return from CURSOR subroutine to MAIN	
STATE:
	MVI	C,4
	CALL	0F606H		;HDRREG addr
	MOV	A,B
	MOV	E,A
	ANI	0F8H

	ORA	H
	MOV	B,A
	CALL	CUR2

	ANA	L
	PUSH	PSW
	MOV	B,E
	CALL	CUR2
	POP	PSW
	RET
CUR2:			;Write I/O control register WRCIO
	IN	0D0H
	MOV	D,A
	MVI	C,4
	CALL	0F609H		;HWRREG I/O addr
CUR3:	IN	0D0H
	XRA	D
	JP	CUR3
	IN	0D0H
	RET			;end of CURSOR subroutine

ENDROUTE3:
	RET

; *************************************************************
;		END OF PRELIMINARY ROUTINES
; *************************************************************

        END		  ; everything after END is ignored
			  ; by the assembler

;*************************************************************
;    GENERAL USAGE INSTRUCTIONS FOR USING  ASM  OVERLAYS 
;*************************************************************

;               I N S T R U C T I O N S
;
;
; First, edit this file to your preferences using any editor.
; VDO.COM should work very well for this.
;
; Second, assemble this file using Digital Research's CP/M
; assembler ASM.COM.  For the file VDO-OVR.ASM,  enter ASM VDO-OVR
;
; Lastly, use DDT to overlay the resulting HEX file from the ASM step
; onto VDO.COM.  The procedure for this overlay follows:
;
;		A>DDT VDO.COM
;		DDT VERS 2.2
;		NEXT  PC
;		1480 0100		(size varies with version)
;		-IVDO-OVR.HEX		(note the "I" command)
;		-R			("R" loads in the .HEX file)
;		NEXT  PC
;		1722 0000
;		-G0			(return to CP/M)
;		A>SAVE 23 VDO.COM	(now have a modified .COM file)
;
; =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =
A>SAVE 2