;ROMSUM--COMPUTES CHECKSUM OF ANY AREA OF MEMORY
;INTENDED FOR TESTING ROMS AGAINST KNOWN VALUE
;WRITTEN BY RUSS BAKKE
;02-17-83
;
	ORG	100H
	LXI	D,MSG1
AGAIN	CALL	MSG
	CALL	RHV	;GET START ADDR
	SHLD	START	;SAVE IT
	LXI	D,MSG2
	CALL	MSG
	CALL	RHV	;GET STOP ADDR
	INX	H	;ADD 1
	SHLD	STOP	;SAVE IT
	LXI	D,0	;CLEAR WORKING REG
	LHLD	START
;
BYTE	MVI	B,8	;BIT COUNTER
	MOV	A,M	;GET BYTE
;
BIT	MOV	C,A	;SAVE IT
;THIS FORMS THE XOR OF 4 BITS IN DE
;AND LSB OF A
	PUSH	B
	PUSH	D
	PUSH	PSW
	MVI	B,6	;BIT 6 OF E
	MOV	A,E
BIT1	RAR
	DCR	B
	JNZ	BIT1
	MOV	B,A
	POP	PSW
	XRA	B
	XRA	D	;BIT 0 OF D
	MVI	B,3
	CALL	XORBD
	MVI	B,4	;4 MORE
	CALL	XORBD
	POP	D
	RAR	;PUT BIT INTO CARRY
	MOV	A,E	;MOVE INTO E
	RAL
	MOV	E,A	;& ON INTO D
	MOV	A,D
	RAL
	MOV	D,A
	POP	B
	MOV	A,C
	RAR	;NEXT BIT
	DCR	B
	JNZ	BIT
;
	INX	H
	LDA	STOP+1
	CMP	H
	JNZ	BYTE
	LDA	STOP
	CMP	L
	JNZ	BYTE
;
;DONE
	PUSH	D
	LXI	D,MSG3
	CALL	MSG
	POP	D
	CALL	DWORD	;DISPLAY DE
	LXI	D,MSG4
	CALL	MSG
	MVI	C,RDCON
	CALL	DOS	;GET 1 CHAR
	CPI	'Y'
	RNZ
	LXI	D,MSG1A
	JMP	AGAIN
;
;SUBROUTINES
;XORBD--XOR BIT FROM D
XORBD	PUSH	PSW
	MOV	A,D
XOR1	RAR
	DCR	B
	JNZ	XOR1
	MOV	B,A
	POP	PSW
	XRA	B
	RET
;
;DWORD--DISPLAY DE AS HEX WORD
DWORD	PUSH	D
	MOV	A,D
	CALL	DBYT
	POP	D
	MOV	A,E
;
;DBYT--DISPLAY A AS HEX
DBYT	PUSH PSW
	RRC
	RRC
	RRC
	RRC
	CALL	TAD
	POP	PSW
;
;TAD--CONVERT A TO ASCII & DISPL.
TAD	ANI	0FH
	ADI	90H
	DAA
	ACI	40H
	DAA
	MOV	E,A
;
;COUT--OUTPUT CHAR IN E
COUT	MVI	C,WRCON
	JMP	DOS
;
;MSG--OUTPUT BUFFER AT DE
MSG	MVI	C,PUTBUF
	JMP	DOS
;
;RHV--READ A HEX VALUE, RET IN HL
RHV	LXI	D,BUFFER
	MVI	A,6	;BUFFER LENGTH
	STAX	D
	MVI	C,GETBUF
	CALL	DOS
	MVI	E,LF	;ADD LF
	CALL	COUT
	LXI	D,BUFFER+1
	LDAX	D	;CHAR COUNT
	INX	D
	LXI	H,0
	MOV	B,A
RH1	LDAX	D
	CALL	AHTB	;CONVERT TO HEX
	DAD	H
	DAD	H
	DAD	H
	DAD	H;*16
	ADD	L
	MOV	L,A
	INX	D	;NEXT CHAR
	DCR	B
	JNZ	RH1
	RET
;
;AHTB--CONVERT A FROM ASCII TO HEX
AHTB	SUI	30H
	RC
	ADI	0E9H
	RC
	ADI	6
	JP	AH1
	ADI	7
	RC
AH1	ADI	0AH
	ORA	A
	RET
;
;
;MESSAGES
MSG1	DB 'ROM SIGNATURE ANALYSIS'
;
MSG1A	DB	CR,LF
	DB 'ENTER STARTING ADDRESS IN HEX: $'
;
MSG2	DB 'ENTER ENDING ADDRESS IN HEX: $'
;
MSG3	DB 'CHECKSUM IS $'
;
MSG4	DB	CR,LF
	DB 'AGAIN? $'
;
;STORAGE
START	DS	2
STOP	DS	2
BUFFER	DS	6
;
;EQUATES
DOS	EQU	5	;DOS CALL
;
;DOS FUNCTIONS
RDCON	EQU	1
WRCON	EQU	2
PUTBUF	EQU	9
GETBUF	EQU	10
CR	EQU	0DH
LF	EQU	0AH
