; This will only be used in the ROM version, and hence needs the IF at the beginning

.text

CRCtest::

	movea.l	#$802000,a0	; start address of text space
	movea.l	#End_of_text,a1	; end of text space
	bsr.b	Do_CRC

	movea.l	#End_of_text+8,a0
	movea.l	#End_of_data,a1
	suba.l	#Blob1,a1	; get length in RAM
	adda.l	a0,a1		; to give endpoint in ROM
	bsr.b	Do_CRC

	rts

BadCRC::	message "CRC check failure - please reload"

Do_CRC::
	move.l	a1,d0
	sub.l	a0,d0
;	addq.l	#3,d0
	asr.l	#2,d0
	subq.l	#1,d0

	moveq.l	#0,d1
	moveq.l	#0,d2
	swap	d0

.lop0:	swap	d0

.lop:	move.l	(a0)+,d3
	rol.l	#3,d1
	rol.l	#5,d2
	eor.l	d3,d1
	eor.l	d3,d2

	dbra	d0,.lop
	swap	d0
	dbra	d0,.lop0

	tst.l	(a1)
	bne.b	crc_test_stop
	move.l	d1,(a1)+
	move.l	d2,(a1)+
	rts

crc_test_stop:
	cmp.l	(a1)+,d1
	beq.b	.ok1
	bsr	BadCRC
.ok1:	cmp.l	(a1)+,d2
	beq.b	.ok2
	bsr	BadCRC

.ok2:	rts

;================================

RAMROM:	movea.l	#End_of_text+8,a0
	movea.l	#Blob1,a1
.lp:	cmp.l	(a0)+,(a1)+
	beq.b	.lp
	illegal
