;----------------------------------------------------
;
;BYTESAVER EPROM PROGRAMMER CONTROL PROGRAM
;
;VERSION 1.4 - 10 SEP 77
;
;
;JEFFREY W. SHOOK
;P. O. BOX 185
;ROCKY POINT, NEW YORK 11778
;
;MODIFIED BY:
;
;BARRY A. WATZMAN, CDP
;2330 MILLENNIUM LN.
;RESTON, VA. 22091
;-----------------------------------------------------
;
;SYMBOL DEFINITIONS
;
BDOS	EQU	5		;CP/M BDOS ENTRY POINT
RCON	EQU	1
WCONB	EQU	9
CR	EQU	0DH		;ASCII CARRIAGE RETURN
LF	EQU	0AH		;ASCII LINE FEED
STATL	EQU	0FFH		;IMSAI CONSOLE STATUS LED'S
BYTSAV	EQU	0E000H		;BYTESAVER START ADDRESS
BEGDAT	EQU	1000H		;START OF DATA FOR EPROMS
NPASS	EQU	255		;NUMBER OF PROGRAMMING PASSES
				;THIS VALUE FOR BYTESAVER WITH
				;1.0 MSEC. PROGRAM PULSE
;
;MAIN PROGRAM CODE
;
	ORG	100H		;CP/M STARTS EXECUTION HERE
;
;INITIALIZATION
;
	LXI	SP,STACK
	MVI	A,0		;CLEAR CONSOLE STATUS LED'S
	OUT	STATL
;
;PRINT SIGNON MESSAGE & GET FUNCTION
;
	LXI	D,SGNMSG	;SIGN-ON MESSAGE
	CALL	PRTMSG
GTFUNC:	LXI	D,FUNCMSG	;POINT TO FUNCTION MESSAGE
	CALL	PRTMSG
GTFNC1:	CALL	INCH
	CPI	'X'
	JZ	GOCPM
	CPI	'D'
	JZ	DDT		;RETURN TO DDT VIA RST 7
	CPI	'C'
	JZ	GDANS		;VALID ANSWER
	CPI	'P'
	JZ	GDANS		;VALID ANSWER
	CPI	'E'
	JZ	GDANS		;VALID ANSWER
	LXI	D,WHATMSG
	CALL	PRTMSG		;TELL USER ANSWER'S INVALID
	JMP	GTFNC1		;GET FUNCTION AGAIN
GDANS:	STA	FUNCT		;SAVE REQUESTED FUNCTION
	CALL	RANGE		;GET EPROM ADDRESS RANGE
	CALL	ERASED		;CHECK IF PROMS ERASED
	CALL	PROGRM		;BURN IN EPROMS
	CALL	COMPAR		;CHECK IF TRANSFER CORRECT
	JMP	GTFUNC		;DO IT ALL AGAIN
;
;RETURN TO DDT VIA RST 7
;
DDT:	RST	7
;
;RETURN TO CP/M
;
GOCPM:	JMP	0		;REBOOT CP/M
;
;THIS SUBROUTINE GETS THE EPROM NUMBERS (0-7) TO BE
;PROGRAMMED/VERIFIED AND CONVERTS THEM TO ADDRESSES
;
RANGE:	LXI	D,RNGMSG1
	CALL	PRTMSG
	CALL	GTPROM
	JNC	GTBEG
	LXI	D,PRMMSG
	CALL	PRTMSG
	JMP	RANGE
GTBEG:	SHLD	BEGPRM
	LXI	D,RNGMSG2
	CALL	PRTMSG
	CALL	GTPROM
	JNC	GTEND
	LXI	D,PRMMSG
	CALL	PRTMSG
	JMP	RANGE
GTEND:	LXI	D,256*4
	DAD	D
	SHLD	ENDPRM
	LDA	ENDPRM+1
	LXI	H,BEGPRM+1
	CMP	M
	JZ	BAD
	RNC
BAD:	ORA	A
	RZ
	LXI	D,PRMMSG
	CALL	PRTMSG
	JMP	RANGE
;
;THIS ROUTINE GETS A SINGLE PROM POSITION AND CONVERTS
;IT TO A STARTING ADDRESS
;
GTPROM:	CALL	INCH
	SUI	'0'
	RC
	CPI	8
	JC	GTPM1
	CMC
	RET
GTPM1:	MVI	L,0
	MOV	H,A
	DAD	H
	DAD	H
	LXI	D,BYTSAV
	DAD	D
	XRA	A		;CLEAR CARRY
	RET
;
;ROUTINE TO CHECK IF PROMS ERASED
;
ERASED:	LDA	FUNCT
	CPI	'C'
	RZ
	LHLD	BEGPRM
	LXI	D,ERMSG
ERASE1:	MOV	A,M
	CPI	0FFH
	JNZ	ERASE2
	INX	H
	LDA	ENDPRM+1
	CMP	H
	JNZ	ERASE1
	JMP	PRTMSG
ERASE2:	LXI	D,NERMSG
	JMP	PRTMSG
;
;ROUTINE TO ACTUALLY PROGRAM THE PROMS
;
PROGRM:	LDA	FUNCT
	CPI	'P'
	RNZ
	LXI	D,PWRMSG
	CALL	PRTMSG
	CALL	INCH
	CPI	CR
	JNZ	PROGRM
	LXI	D,PGMMSG
	CALL	PRTMSG
	LXI	B,NPASS
	MOV	A,B
	CMA
	OUT	STATL
PROGR2:	PUSH	B
	LXI	D,BEGDAT
	LHLD	BEGPRM
PROGR3:	LDAX	D
	MOV	M,A
	INX	D
	INX	H
	LDA	ENDPRM+1
	CMP	H
	JNZ	PROGR3
	POP	B		;GET PASS COUNT
	DCX	B
	MOV	A,C		;DSIPLAY COUNT ON STATUS LIGHTS
	CMA
	OUT	STATL
	MOV	A,B		;CHECK FOR PASSES = 0
	ORA	C
	JNZ	PROGR2		;LOOP IF NOT LAST PASS
	LXI	D,OFFMSG
	CALL	PRTMSG
PROGR5:	CALL	INCH
	CPI	CR
	JNZ	PROGR5
	RET
;
;COMPARE ROUTINE TO COMPARE PROM'S TO MEMORY
;
COMPAR:	LDA	FUNCT
	CPI	'E'
	RZ
	LXI	D,BEGDAT
	LHLD	BEGPRM
COMPA1:	LDAX	D
	CMP	M
	JNZ	COMPA2
	INX	H
	INX	D
	LDA	ENDPRM+1
	CMP	H
	JNZ	COMPA1
	LXI	D,OKMSG
	JMP	PRTMSG
COMPA2	LXI	D,BADMSG
;
;ROUTINE TO PRINT MESSAGE TERMINATED BY $ ON CONSOLE
;
PRTMSG:	MVI	C,WCONB		;PRINT MESSAGE ON CONSOLE
	JMP	BDOS
;
;CHARACTER INPUT ROUTINE
;
INCH:	PUSH	B
	PUSH	D
	PUSH	H
	MVI	C,RCON
	CALL	BDOS
	POP	H
	POP	D
	POP	B
	RET
;
;CONSOLE MESSAGES
;
SGNMSG:	DB	CR,LF,CR,LF
	DB	'CROMEMCO BYTESAVER 2708 EPROM PROGRAMMER'
	DB	CR,LF,'RELEASE 1.4',CR,LF,'$'
FUNCMSG:DB	CR,LF,'SELECT OPTIONS:',CR,LF,CR,LF
	DB	'     E - VERIFY ERASED',CR,LF
	DB	'     C - COMPARE TO CONTENTS OF 1000H',CR,LF
	DB	'     P - PROGRAM TO CONTENTS OF 1000H',CR,LF
	DB	'     D - EXIT TO DDT',CR,LF
	DB	'     X - EXIT TO CP/M',CR,LF,CR,LF,':$'
WHATMSG:DB	CR,LF,CR,LF,'THAT WASN''T ONE OF THE'
	DB	' CHOICES !!!',CR,LF,CR,LF,'TRY AGAIN'
	DB	CR,LF,':$'
RNGMSG1:DB	CR,LF,'EPROM SOCKET POSITION (0 - 7)',CR,LF
	DB	'FIRST? ','$'
RNGMSG2:DB	CR,LF,'LAST ? ','$'
PRMMSG:	DB	CR,LF,CR,LF,'RANGE INVALID; MUST BE BETWEEN'
	DB	' 0 - 7,'
	DB	CR,LF,'AND END MUST BE > BEGINNING. TRY AGAIN.'
	DB	CR,LF,'$'
ERMSG:	DB	CR,LF,CR,LF
	DB	'EPROMS ARE ERASED.',CR,LF,'$'
NERMSG:	DB	CR,LF,CR,LF
	DB	'EPROMS NOT ERASED !',CR,LF,'$'
PWRMSG:	DB	CR,LF
	DB	'TURN PROGRAM POWER ON',CR,LF
	DB	'TYPE CR TO CONTINUE ','$'
PGMMSG:	DB	CR,LF,CR,LF
	DB	'PROGRAMMING NOW IN PROGRESS',CR,LF
	DB	'PLEASE WAIT 2 MINUTES PER EPROM'
	DB	CR,LF,CR,LF,'$'
OFFMSG:	DB	'PROGRAMMING COMPLETE',CR,LF
	DB	'TURN PROGRAM POWER OFF',CR,LF
	DB	'TYPE CR TO CONTINUE',CR,LF,'$'
OKMSG:	DB	CR,LF,CR,LF,'EPROMS CORRECTLY PROGRAMMED'
	DB	CR,LF,'$'
BADMSG:	DB	CR,LF,CR,LF,'EPROM COMPARE ERROR!',CR,LF,'$'
;
;STORAGE ALLOCATIONS
;
BEGPRM:	DS	2		;EPROM START ADDRESS
ENDPRM:	DS	2		;EPROM END ADDRESS
FUNCT:	DS	1		;SELECTED FUNCTION
	DS	40H		;PROGRAM STACK AREA
STACK:	EQU	$
	END