*************************************************************************
*                     Device Masher System
*         Calculation of CRC headers for .DMS/.FMS files
*************************************************************************

Calculate_DMS_Header_CRC
		MOVEQ	#$32,D0
		LEA	Header,A0
		BSR	Calc_CRC
		MOVE.W	D0,InfoHeaderCRC
		RTS

Calculate_TR_Header_CRC
		MOVEQ	#$12,D0
		LEA	HeaderID1,A0
		BSR	Calc_CRC
		MOVE.W	D0,Hcrc_
		RTS

Calculate_TR_DATA_CRC			;PACKED
		MOVE.W	Packlength,D0
		LEA	TR_DATA,A0
		BSR	Calc_CRC
		MOVE.W	D0,Dcrc_
		rts

Calc_CRC	MOVE.L	D2,-(A7)
		LEA	CRC_TAB,A1
		SUBQ.W	#1,D0
		MOVEQ	#0,D1
.l1		MOVEQ	#0,D2
		MOVE.B	(A0)+,D2
		EOR.B	D1,D2
		ADD.W	D2,D2
		LSR.W	#8,D1
		MOVE.W	(A1,D2.W),D2
		EOR.W	D2,D1
		DBRA	D0,.l1
		MOVE.W	D1,D0
		MOVE.L	(A7)+,D2
		RTS

CRC_TAB	dc.l	$C0C1,$C1810140,$C30103C0,$280C241,$C60106C0,$780C741
	dc.l	$500C5C1,$C4810440,$CC010CC0,$D80CD41,$F00CFC1,$CE810E40
	dc.l	$A00CAC1,$CB810B40,$C90109C0,$880C841,$D80118C0,$1980D941
	dc.l	$1B00DBC1,$DA811A40,$1E00DEC1,$DF811F40,$DD011DC0
	dc.l	$1C80DC41,$1400D4C1,$D5811540,$D70117C0,$1680D641
	dc.l	$D20112C0,$1380D341,$1100D1C1,$D0811040,$F00130C0
	dc.l	$3180F141,$3300F3C1,$F2813240,$3600F6C1,$F7813740
	dc.l	$F50135C0,$3480F441,$3C00FCC1,$FD813D40,$FF013FC0
	dc.l	$3E80FE41,$FA013AC0,$3B80FB41,$3900F9C1,$F8813840
	dc.l	$2800E8C1,$E9812940,$EB012BC0,$2A80EA41,$EE012EC0
	dc.l	$2F80EF41,$2D00EDC1,$EC812C40,$E40124C0,$2580E541
	dc.l	$2700E7C1,$E6812640,$2200E2C1,$E3812340,$E10121C0
	dc.l	$2080E041,$A00160C0,$6180A141,$6300A3C1,$A2816240
	dc.l	$6600A6C1,$A7816740,$A50165C0,$6480A441,$6C00ACC1
	dc.l	$AD816D40,$AF016FC0,$6E80AE41,$AA016AC0,$6B80AB41
	dc.l	$6900A9C1,$A8816840,$7800B8C1,$B9817940,$BB017BC0
	dc.l	$7A80BA41,$BE017EC0,$7F80BF41,$7D00BDC1,$BC817C40
	dc.l	$B40174C0,$7580B541,$7700B7C1,$B6817640,$7200B2C1
	dc.l	$B3817340,$B10171C0,$7080B041,$500090C1,$91815140
	dc.l	$930153C0,$52809241,$960156C0,$57809741,$550095C1
	dc.l	$94815440,$9C015CC0,$5D809D41,$5F009FC1,$9E815E40
	dc.l	$5A009AC1,$9B815B40,$990159C0,$58809841,$880148C0
	dc.l	$49808941,$4B008BC1,$8A814A40,$4E008EC1,$8F814F40
	dc.l	$8D014DC0,$4C808C41,$440084C1,$85814540,$870147C0
	dc.l	$46808641,$820142C0,$43808341,$410081C1,$80814040
