;----------------------------------------------------
;
;BYTESAVER EPROM PROGRAMMER CONTROL PROGRAM
;
;VERSION 1.5 - 16 JUN 79
;
;
;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	08000H		;BYTESAVER START ADDRESS
BEGDAT	EQU	1000H		;START OF DATA FOR EPROMS
MOVRAM	EQU	4000H		;RAM DEST FOR PROM-RAM MOVES
BNORM	EQU	01H		;MEMORY BANK IN WHICH NORMAL RAM RESIDES
B2708	EQU	02H		;MEMORY BANK IN WHICH 2708 BYTSVR RESIDES
B2716	EQU	04H		;MEMORY BANK IN WHICH 2716 BYTSVR RESIDES
BSPORT	EQU	40H		;MEMORY BANK SELECT PORT
;
;MAIN PROGRAM CODE
;
	ORG	100H		;CP/M STARTS EXECUTION HERE
;
;INITIALIZATION
;
START:	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	'M'		;VALID ANSWER
	JZ	GDANS
	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
GDANS1:	LXI	D,TYPMSG	;POINT TO TYPE MESSAGE
	CALL	PRTMSG
	CALL	INCH
	CPI	'1'
	JNZ	TRY2
	MVI	A,0FFH
	STA	TYPE
	MVI	A,B2708
	STA	BANK
	JMP	FUNC1A
TRY2:	CPI	'2'
	JNZ	GDANS1
	XRA	A
	STA	TYPE
	MVI	A,B2716
	STA	BANK
FUNC1A:	CALL	RANGE		;GET EPROM ADDRESS RANGE
	CALL	MOVE
	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
	LDA	TYPE
	ORA	A
	JNZ	GTEND1
	DAD	D		;ADD ANOTHER 1K FOR 2716'S
GTEND1:	DCX	H		;DCR, SINCE LAST ADDR IS XXFFH
	SHLD	ENDPRM
	LDA	ENDPRM+1
	LXI	H,BEGPRM+1
	CMP	M
	JZ	BAD
	RNC
BAD:	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
	LDA	TYPE		;GET TYPE
	ORA	A
	JNZ	GTPM2		;2708
	DAD	H		;2716
GTPM2:	LXI	D,BYTSAV
	DAD	D
	XRA	A		;CLEAR CARRY
	RET
;
;MOVE ROUTINE TO PUT ROM CODE INTO RAM
;
MOVE:	LDA	FUNCT
	CPI	'M'
	RNZ
	LHLD	BEGPRM
	LXI	D,MOVRAM
	LDA	BANK
	OUT	BSPORT
MOVE1:	MOV	A,M
	STAX	D
	INX	H
	INX	D
	LDA	ENDPRM+1
	INR	A
	CMP	H
	JNZ	MOVE1
	MVI	A,BNORM
	OUT	BSPORT
	LXI	D,MOVDMSG
	JMP	PRTMSG
;
;ROUTINE TO CHECK IF PROMS ERASED
;
ERASED:	LDA	FUNCT
	CPI	'C'
	RZ
	CPI	'M'
	RZ
	LHLD	BEGPRM
	LXI	D,ERMSG
	LDA	BANK
	OUT	BSPORT
ERASE1:	MOV	A,M
	CPI	0FFH
	JNZ	ERASE2
	INX	H
	LDA	ENDPRM+1
	INR	A		;SEE IF WENT TO NEXT PAGE
	CMP	H
	JNZ	ERASE1
	MVI	A,BNORM
	OUT	BSPORT
	JMP	PRTMSG
ERASE2:	MVI	A,BNORM
	OUT	BSPORT
	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
	LDA	BANK		;GET BANK NO.
	OUT	BSPORT
	LDA	TYPE		;TYPE IS ALSO THE NUMBER OF PASSES
	MOV	B,A
	CMA
	OUT	STATL
PROGR2:	PUSH	B
	LXI	D,BEGDAT
	LHLD	BEGPRM
PROGR3:	LDAX	D
	MOV	M,A
	INX	D
	INX	H
	LDA	ENDPRM+1
	INR	A
	CMP	H
	JNZ	PROGR3
	POP	B		;GET PASS COUNT
	DCR	B
	MOV	A,B		;DISPLAY COUNT ON STATUS LIGHTS
	CMA
	OUT	STATL
	MOV	A,B		;CHECK FOR PASSES = 0
	CPI	255		;SEE IF 2716 DONE
	JZ	DONE
	ORA	A
	JNZ	PROGR2		;LOOP IF NOT LAST PASS
DONE:	MVI	A,BNORM
	OUT	BSPORT
	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
	CPI	'M'
	RZ
	LXI	D,BEGDAT
	LHLD	BEGPRM
	LDA	BANK
	OUT	BSPORT
COMPA1:	LDAX	D
	CMP	M
	JNZ	COMPA2
	INX	H
	INX	D
	LDA	ENDPRM+1
	INR	A
	CMP	H
	JNZ	COMPA1
	MVI	A,BNORM
	OUT	BSPORT
	LXI	D,OKMSG
	JMP	PRTMSG
COMPA2:	MVI	A,BNORM
	OUT	BSPORT
	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/INTEL 2716 EPROM PROGRAMMER'
	DB	CR,LF,'RELEASE 1.5',CR,LF,'$'
TYPMSG:	DB	CR,LF,CR,LF,'ENTER PROM TYPE:',CR,LF
	DB	09H,'1 - 1K 2708',CR,LF
	DB	09H,'2 - 2K INTEL 2716 OR TI 2516',CR,LF
	DB	CR,LF,':$'
MOVDMSG:DB	CR,LF,CR,LF,'EPROM CONTENTS MOVED',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	'     M - MOVE PROM CONTENTS TO 4000H',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,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
TYPE:	DB	0		;0 = 2716, 0FFH = 2708
BANK:	DB	0		;MEMORY BANK BURNER ASSIGNED TO
	DS	40H		;PROGRAM STACK AREA
STACK:	EQU	$
	END	START