;CHECKSUM ANY CP/M FILE
	ORG	100H
	JMP	START
ID	DB	'CKSUM AS OF 7/20/77',0DH,0AH,'$'
;INIT LOCAL STACK
START	LXI	H,0
	DAD	SP
	SHLD	STACK
	LXI	SP,STACK
;PRINT ID MESSAGE
	LXI	D,ID
	MVI	C,PRINT
	CALL	BDOS
;OPEN THE FILE
	LXI	D,FCB
	MVI	C,OPEN
	CALL	BDOS
	INR	A
	JNZ	LINE
	CALL	ERXIT
	DB	'++FILE NOT FOUND$'
ERXIT	POP	D	;GET MSG
	MVI	C,PRINT
	CALL	BDOS
EXIT	LHLD	STACK
	SPHL		;RESTORE STACK
	RET
;OPENED OK
LINE	MVI	A,0DH
	CALL	TYPE
	MVI	A,0AH
	CALL	TYPE
	MVI	B,16	;# OF HEX PER LINE
LOOP	PUSH	B	;SAVE DIGIT COUNT
	CALL	FREAD
	ORA	A
	JNZ	CKERR
	LXI	H,80H
	XRA	A
CKSLP	ADD	M
	INR	L
	JNZ	CKSLP
	CALL	XOB
	POP	B
	DCR	B
	JNZ	LOOP
	JMP	LINE
;NON-ZERO DISK RETURN CODE
CKERR	DCR	A
	JZ	EOF
	CALL	ERXIT
	DB	'*++DISK READ ERROR$'
EOF	CALL	ERXIT
	DB	0DH,0AH,'++EOF$'
XOB	PUSH	PSW
	RAR
	RAR
	RAR
	RAR
	CALL	NIBBL
	POP	PSW
	CALL	NIBBL
	MVI	A,' '
	CALL	TYPE
	RET
NIBBL	ANI	0FH
	CPI	10
	JC	ISNUM
	ADI	7
ISNUM	ADI	'0'
TYPE	PUSH	B
	PUSH	D
	PUSH	H
	MOV	E,A
	MVI	C,WRCON
	CALL	BDOS
	POP	H
	POP	D
	POP	B
	RET
;FILE READ
FREAD	LXI	D,FCB
	MVI	C,READ
	CALL	BDOS
	RET		;PROG SHOULD CHECK STAT
	DS	30
STACK	DS	2
;
; BDOS EQUATES (VERSION 3)
;
RDCON	EQU	1
WRCON	EQU	2
PRINT	EQU	9
OPEN	EQU	15	;0FFH=NOT FOUND
CLOSE	EQU	16	;   "	"
SRCHF	EQU	17	;   "	"
SRCHN	EQU	18	;   "	"
DELT	EQU	19	;NO RET CODE
READ	EQU	20	;0=OK, 1=EOF
WRITE	EQU	21	;0=OK, 1=ERR, 2=?, 0FFH=NO DIR SPC
MAKE	EQU	22	;0FFH=BAD
REN	EQU	23	;0FFH=BAD
STDMA	EQU	26
BDOS	EQU	5
FCB	EQU	5CH
