TITLE	'INSTALL OR REMOVE REMOTE CONSOLE'

;THIS PROGRAM WILL INSTALL OR REMOVE
;REMOTE CONSOLE IN 1.4 CP/M.
;
;*** THIS IS FOR 8 INCH FLOPPY DISK WITH CP/M STARTING
;    ON TRACK 0, SECTOR 2.
;
;NAME:	INSTALL.ASM

; 2-6-80   BUG IN INPUT ROUTINE FIXED FOR CP/M 2.0
;

;WRITTEN BY DALE HEATHERINGTON
;
;COPYRIGHT 1979, D.C. HAYES ASSOCIATES, INC.

;THIS PROGRAM ONLY WORKS WITH VERSION 1.4 CP/M.
;IT LOADS THE FIRST 128 BYTES OF THE CP/M CCP MODULE
;INTO RAM AT 80 HEX.  THIS IS ASSUMED TO BE ON TRACK ZERO,
;SECTOR 2.  IF THE USER TYPES "I" TO INSTALL REMOTE CONSOLE
;THE PROGRAM WILL INSERT "REMOTE" INTO THE CCP CONSOLE BUFFER
;ALONG WITH IT LENGTH, 6.  IT THEN WRITES THIS MODIFIED SECTOR
;OF THE CCP BACK TO THE DISK.  "REMOVE" WORKS THE SAME
;EXCEPT THAT IT SETS THE LENGTH TO 0 AND WRITES 6 SPACES TO
;THE CONSOLE BUFFER.  
;     WHEN CP/M WARM BOOTS IT CHECKS THE CONSOLE BUFFER TO SEE
;IF IT HAS ANY THING IN IT.  IF IT DOES CP/M READS IT AND 
;PERFORMS THE FUNCTION.  IN THIS CASE IT WILL LOAD AND EXECUTE
;THE FILE "REMOTE.COM",  THE REMOTE CONSOLE PROGRAM.


	ORG 100H
BDOS	EQU	5
CR2	EQU	82H	;MICROMODEM 100 CONTROL REGISTER 2

CR	EQU	0DH	;ASCII CARRAGE RETURN


	JMP	START


;THE CBIOS JUMP TABLE IS MOVED HERE


BOOT:	DS	3
WBOOT:	DS	3
CONST:	DS	3
CONIN:	DS	3
CONOUT:	DS	3
LIST:	DS	3
PUNCH:	DS	3
READER:	DS	3
HOME:	DS	3
SELDSK:	DS	3
SETTRK:	DS	3
SETSEC:	DS	3
SETDMA:	DS	3
READ:	DS	3
WRITE:	DS	3

START:	LXI	SP,STACK
	LHLD	1	;GET WARM BOOT ADDRESS
	DCX	H
	DCX	H
	DCX	H
	LXI	D,BOOT	;DESTINATION ADDRESS
	MVI	B,15*3	;NUMBER OF BYTES TO MOVE
	CALL	MOVE	;MOVE THE CBIOS JUMP TABLE 
	LXI	B,80H
	CALL	SETDMA	;SET DMA ADDRESS TO 80H
	MVI	C,0
	CALL	SETTRK	;SET TRACK TO 0
	MVI	C,2
	CALL	SETSEC	;SET SECTOR TO 2
	CALL	READ	;READ IN FIRST SECTOR OF CPM
QQ:	CALL	PRINT
	DB	'INSTALL OR REMOVE ? (I OR R)',CR
	CALL	INPUT	;GET REPLY
	CPI	'I'
	JZ	INSTALL
	CPI	'R'
	JZ	REMOVE
	JMP	QQ


;CONSOLE INPUT ROUTINE

INPUT:	PUSH	H
	PUSH	D
	PUSH	B
	MVI	C,1
	CALL	5
	NOP
	CPI	60H
	JC	IN1
	SUI	20H	;CONVERT TO UPPER CASE
IN1:	POP	B
	POP	D
	POP	H
	RET

CRLF:	CALL	PRINT
	DB	CR
	RET


;PRINTS ASCII STRINGS POINTED TO BY TOP OF STACK
; TO CONSOLE.

PRINT:	XTHL		;GET STRING POINTER
	PUSH	PSW
	PUSH	B
PO1:	MOV	A,M
	INX	H
	CPI	'@'	;NO CR IF @ IS END OF STRING
	JZ	NOCR
	CALL	COUT
	CPI	CR	;CARRAGE RET?
	JZ	THEEND
	JMP	PO1
THEEND:	CALL	PRINT
	DB	0AH,0,0,0,'@'
NOCR:	POP	B
	POP	PSW
	XTHL
	RET

;CONSOLE OUTPUT ROUTINE

COUT:	PUSH	PSW
	PUSH	B
	PUSH	D
	PUSH	H
	MOV	E,A
	MVI	C,2	;WRITE CONSOLE
	CALL	5
	POP	H
	POP	D
	POP	B
	POP	PSW
	RET


;GENERAL PURPOSE MEMORY TO MEMORY BLOCK MOVE ROUTINE
; HL POINT TO THE SOURCE,  DE POINT TO THE DESTINATION
;  THE B REGISTER HAS THE COUNT.


MOVE:	MOV	A,M
	STAX	D
	INX	H
	INX	D
	DCR	B
	JNZ	MOVE
	RET



;THIS ROUTINE PUTS "REMOTE" INTO THE CCP CONSOLE BUFFER

INSTALL:	
	LXI	H,INSTL
	LXI	D,87H
	MVI	B,7
	CALL	MOVE
	CALL	WRITE	;WRITE SECTOR TO DISK
	CALL	CRLF
	CALL	PRINT
	DB	'CP/M REMOTE CONSOLE INSTALLED',CR
	JMP	0

;THIS ROUTINE CLEARS THE CCP CONSOLE BUFFER


REMOVE:	LXI	H,REMV
	LXI	D,87H
	MVI	B,7
	CALL	MOVE
	CALL	WRITE
	CALL	CRLF
	CALL	PRINT
	DB	'CP/M REMOTE CONSOLE REMOVED',CR
	XRA	A		;ZERO A
	OUT	CR2		;MAKE SURE MODEM PHONE LINE IS HUNG UP
	JMP	0

;THESE ARE THE STRINGS WHICH ARE PUT IN THE
;CCP CONSOLE BUFFER

INSTL:	DB	6,'REMOTE'

REMV:	DB	0,'      '




	DS	256
STACK:


	END	100H
