MODULA - M2PROT.ZIP - CRC.A

 
Output of file : CRC.A contained in archive : M2PROT.ZIP

(* module CRC *)

(*
Cyclic redundancy check and checksum routines for JPI Modula-2
by Carl Neiburger
169 N. 25th St.
San Jose, Calif. 95116

CompuServe No. 72336,2257

*)

sameCS = 1 - ( (model / 1) & 1 )
sameDS = 1 - ( (model / 2) & 1 )
LongAddr = ( (model / 4) & 1 ) | ( (model / 2) & 1 )
RegParam = (model / 16) & 1
LongOrStakParam = LongAddr | (RegParam-1)
(*%F sameCS *)
frame = 6
(*%E *)
(*%T sameCS *)
frame = 4
(*%E *)

module CRC

section
segment _TEXT(CODE,28H); segment _DATA(DATA, 28H)

select _DATA
CRC16table:
dw 00000H, 01021H, 02042H, 03063H, 04084H, 050A5H, 060C6H, 070E7H
dw 08108H, 09129H, 0A14AH, 0B16BH, 0C18CH, 0D1ADH, 0E1CEH, 0F1EFH
dw 01231H, 00210H, 03273H, 02252H, 052B5H, 04294H, 072F7H, 062D6H
dw 09339H, 08318H, 0B37BH, 0A35AH, 0D3BDH, 0C39CH, 0F3FFH, 0E3DEH
dw 02462H, 03443H, 00420H, 01401H, 064E6H, 074C7H, 044A4H, 05485H
dw 0A56AH, 0B54BH, 08528H, 09509H, 0E5EEH, 0F5CFH, 0C5ACH, 0D58DH
dw 03653H, 02672H, 01611H, 00630H, 076D7H, 066F6H, 05695H, 046B4H
dw 0B75BH, 0A77AH, 09719H, 08738H, 0F7DFH, 0E7FEH, 0D79DH, 0C7BCH
dw 048C4H, 058E5H, 06886H, 078A7H, 00840H, 01861H, 02802H, 03823H
dw 0C9CCH, 0D9EDH, 0E98EH, 0F9AFH, 08948H, 09969H, 0A90AH, 0B92BH
dw 05AF5H, 04AD4H, 07AB7H, 06A96H, 01A71H, 00A50H, 03A33H, 02A12H
dw 0DBFDH, 0CBDCH, 0FBBFH, 0EB9EH, 09B79H, 08B58H, 0BB3BH, 0AB1AH
dw 06CA6H, 07C87H, 04CE4H, 05CC5H, 02C22H, 03C03H, 00C60H, 01C41H
dw 0EDAEH, 0FD8FH, 0CDECH, 0DDCDH, 0AD2AH, 0BD0BH, 08D68H, 09D49H
dw 07E97H, 06EB6H, 05ED5H, 04EF4H, 03E13H, 02E32H, 01E51H, 00E70H
dw 0FF9FH, 0EFBEH, 0DFDDH, 0CFFCH, 0BF1BH, 0AF3AH, 09F59H, 08F78H
dw 09188H, 081A9H, 0B1CAH, 0A1EBH, 0D10CH, 0C12DH, 0F14EH, 0E16FH
dw 01080H, 000A1H, 030C2H, 020E3H, 05004H, 04025H, 07046H, 06067H
dw 083B9H, 09398H, 0A3FBH, 0B3DAH, 0C33DH, 0D31CH, 0E37FH, 0F35EH
dw 002B1H, 01290H, 022F3H, 032D2H, 04235H, 05214H, 06277H, 07256H
dw 0B5EAH, 0A5CBH, 095A8H, 08589H, 0F56EH, 0E54FH, 0D52CH, 0C50DH
dw 034E2H, 024C3H, 014A0H, 00481H, 07466H, 06447H, 05424H, 04405H
dw 0A7DBH, 0B7FAH, 08799H, 097B8H, 0E75FH, 0F77EH, 0C71DH, 0D73CH
dw 026D3H, 036F2H, 00691H, 016B0H, 06657H, 07676H, 04615H, 05634H
dw 0D94CH, 0C96DH, 0F90EH, 0E92FH, 099C8H, 089E9H, 0B98AH, 0A9ABH
dw 05844H, 04865H, 07806H, 06827H, 018C0H, 008E1H, 03882H, 028A3H
dw 0CB7DH, 0DB5CH, 0EB3FH, 0FB1EH, 08BF9H, 09BD8H, 0ABBBH, 0BB9AH
dw 04A75H, 05A54H, 06A37H, 07A16H, 00AF1H, 01AD0H, 02AB3H, 03A92H
dw 0FD2EH, 0ED0FH, 0DD6CH, 0CD4DH, 0BDAAH, 0AD8BH, 09DE8H, 08DC9H
dw 07C26H, 06C07H, 05C64H, 04C45H, 03CA2H, 02C83H, 01CE0H, 00CC1H
dw 0EF1FH, 0FF3EH, 0CF5DH, 0DF7CH, 0AF9BH, 0BFBAH, 08FD9H, 09FF8H
dw 06E17H, 07E36H, 04E55H, 05E74H, 02E93H, 03EB2H, 00ED1H, 01EF0H

select _TEXT

(*%F RegParam *)
(*%T LongAddr *)
Sseg = 6+frame; Sofs = 4 + frame; Slen = 2+frame; CRC = frame; RetSize = 8
(*%E *)
(*%F LongAddr *)
Sofs = 4+frame; Slen = 2+ frame; CRC = frame; RetSize = 6
(*%E *)
(*%E *)
(*%T RegParam *)
RetSize = 0
(*%E *)
public CRC$DoCRC:
(*%F RegParam *)
push bp
mov bp,sp
(*%E *)
(*%T LongAddr *)
push ds
(*%E *)
push si
push di
(*%F RegParam *)
(*%T LongAddr *)
lds si, [bp][Sofs]
(*%E *)
(*%F LongAddr *)
mov si, ds
mov es, si
mov si, [bp][Sofs]
(*%E *)
mov cx,[bp][Slen]
mov ax,[bp][CRC]
(*%E *)
(*%T RegParam *)
(*%T LongAddr *)
mov si, ax (* offset *)
mov ds, bx (* segment *)
mov ax, dx (* CRC; CX = L *)
(*%E *)
(*%F LongAddr *)
mov si, ax (* offset *)
mov ax, cx (* CRC *)
mov cx, bx (* L *)
(*%E *)
(*%E *)
(*%T LongAddr *)
mov di, seg CRC16table
mov es, di
mov di, CRC16table
(*%E *)
(*%F LongAddr *)
mov di, CRC16table (* we won't bother with es *)
(*%E *)
jcxz CRC16Return
CRCloop:
mov bl,ah
mov ah,al
xor bh,bh
lodsb
xor bl,al
shl bx,1
xor al, al
xor ax,es:[di][bx]
loop CRCloop
CRC16Return:
pop di
pop si
(*%T LongAddr *)
pop ds
(*%E *)
(*%F RegParam *)
pop bp
(*%E *)
(*%F sameCS *)
ret far RetSize
(*%E *)
(*%T sameCS *)
ret RetSize
(*%E *)

section; segment _TEXT(CODE,28H); segment _DATA(DATA, 28H)

select _DATA
[email protected]:
dw 0000H, 1189H, 2312H, 329BH, 4624H, 57ADH, 6536H, 74BFH
dw 8C48H, 9DC1H, 0AF5AH, 0BED3H, 0CA6CH, 0DBE5H, 0E97EH, 0F8F7H
dw 1081H, 108H, 3393H, 221AH, 56A5H, 472CH, 75B7H, 643EH
dw 9CC9H, 8D40H, 0BFDBH, 0AE52H, 0DAEDH, 0CB64H, 0F9FFH, 0E876H
dw 2102H, 308BH, 0210H, 1399H, 6726H, 76AFH, 4434H, 55BDH
dw 0AD4AH, 0BCC3H, 8E58H, 9FD1H, 0EB6EH, 0FAE7H, 0C87CH, 0D9F5H
dw 3183H, 200AH, 1291H, 318H, 77A7H, 662EH, 54B5H, 453CH
dw 0BDCBH, 0AC42H, 9ED9H, 8F50H, 0FBEFH, 0EA66H, 0D8FDH, 0C974H
dw 4204H, 538DH, 6116H, 709FH, 420H, 15A9H, 2732H, 36BBH
dw 0CE4CH, 0DFC5H, 0ED5EH, 0FCD7H, 8868H, 99E1H, 0AB7AH, 0BAF3H
dw 5285H, 430CH, 7197H, 601EH, 14A1H, 528H, 37B3H, 263AH
dw 0DECDH, 0CF44H, 0FDDFH, 0EC56H, 98E9H, 8960H, 0BBFBH, 0AA72H
dw 6306H, 728FH, 4014H, 519DH, 2522H, 34ABH, 630H, 17B9H
dw 0EF4EH, 0FEC7H, 0CC5CH, 0DDD5H, 0A96AH, 0B8E3H, 8A78H, 9BF1H
dw 7387H, 620EH, 5095H, 411CH, 35A3H, 242AH, 16B1H, 738H
dw 0FFCFH, 0EE46H, 0DCDDH, 0CD54H, 0B9EBH, 0A862H, 9AF9H, 8B70H
dw 8408H, 9581H, 0A71AH, 0B693H, 0C22CH, 0D3A5H, 0E13EH, 0F0B7H
dw 840H, 19C9H, 2B52H, 3ADBH, 4E64H, 5FEDH, 6D76H, 7CFFH
dw 9489H, 8500H, 0B79BH, 0A612H, 0D2ADH, 0C324H, 0F1BFH, 0E036H
dw 18C1H, 948H, 3BD3H, 2A5AH, 5EE5H, 4F6CH, 7DF7H, 6C7EH
dw 0A50AH, 0B483H, 8618H, 9791H, 0E32EH, 0F2A7H, 0C03CH, 0D1B5H
dw 2942H, 38CBH, 0A50H, 1BD9H, 6F66H, 7EEFH, 4C74H, 5DFDH
dw 0B58BH, 0A402H, 9699H, 8710H, 0F3AFH, 0E226H, 0D0BDH, 0C134H
dw 39C3H, 284AH, 1AD1H, 0B58H, 7FE7H, 6E6EH, 5CF5H, 4D7CH
dw 0C60CH, 0D785H, 0E51EH, 0F497H, 8028H, 91A1H, 0A33AH, 0B2B3H
dw 4A44H, 5BCDH, 6956H, 78DFH, 0C60H, 1DE9H, 2F72H, 3EFBH
dw 0D68DH, 0C704H, 0F59FH, 0E416H, 90A9H, 8120H, 0B3BBH, 0A232H
dw 5AC5H, 4B4CH, 79D7H, 685EH, 1CE1H, 0D68H, 3FF3H, 2E7AH
dw 0E70EH, 0F687H, 0C41CH, 0D595H, 0A12AH, 0B0A3H, 8238H, 93B1H
dw 6B46H, 7ACFH, 4854H, 59DDH, 2D62H, 3CEBH, 0E70H, 1FF9H
dw 0F78FH, 0E606H, 0D49DH, 0C514H, 0B1ABH, 0A022H, 92B9H, 8330H
dw 7BC7H, 6A4EH, 58D5H, 495CH, 3DE3H, 2C6AH, 1EF1H, 0F78H

select _TEXT

(*%F RegParam *)
(*%T LongAddr *)
Sseg = 6+frame; Sofs = 4 + frame; Slen = 2+frame; CRC = frame; RetSize = 8
(*%E *)
(*%F LongAddr *)
Sofs = 4+frame; Slen = 2+ frame; CRC = frame; RetSize = 6
(*%E *)
(*%E *)
(*%T RegParam *)
RetSize = 0
(*%E *)
public CRC$DoKCRC:
(*%F RegParam *)
push bp
mov bp,sp
(*%E *)
(*%T LongAddr *)
push ds
(*%E *)
push si
push di
(*%F RegParam *)
(*%T LongAddr *)
lds si, [bp][Sofs]
(*%E *)
(*%F LongAddr *)
mov si, ds
mov es, si
mov si, [bp][Sofs]
(*%E *)
mov cx,[bp][Slen]
mov bx,[bp][CRC]
(*%E *)
(*%T RegParam *)
(*%T LongAddr *)
mov si, ax
mov ds, bx
mov bx, dx (* CX = L; BX = CRC *)
(*%E *)
(*%F LongAddr *)
mov si, ds
mov es, si
mov si, ax
xchg bx, cx (* BX = CRC; CX = L *)
(*%E *)
(*%E *)
jcxz Return
(*%T LongAddr *)
mov di, seg [email protected]
mov es, di
mov di, [email protected]
(*%E *)
(*%F LongAddr *)
mov di, [email protected] (* we won't bother with es *)
(*%E *)
cld (* just to be safe *)
LoopTop:
lodsb
xor ah, ah (* keep empty *)
xor al, bl (* C xor ( Crc MOD 100H ) *)
xchg ax, bx (* get table pointer in BX *)
shl bx, 1 (* make it a word pointer *)
(*%T LongAddr *)
mov bx, es:[di][bx] (* look up value *)
(*%E *)
(*%F LongAddr *)
mov bx, [di][bx] (* look up value *)
(*%E *)
xor bl, ah (* CRC = (Crc >> 8) xor KCrcTable[C]) *)
loop LoopTop
Return:
mov ax, bx (* return CRC *)
pop di
pop si
(*%T LongAddr *)
pop ds
(*%E *)
(*%F RegParam *)
pop bp
(*%E *)
(*%F sameCS *)
ret far RetSize
(*%E *)
(*%T sameCS *)
ret RetSize
(*%E *)

section; segment _TEXT(CODE,28H); select _TEXT

(*%F RegParam *)
(*%T LongAddr *)
Sseg = 6+frame; Sofs = 4 + frame; Slen = 2+frame; CRC = frame; RetSize = 8
(*%E *)
(*%F LongAddr *)
Sofs = 4+frame; Slen = 2+ frame; CRC = frame; RetSize = 6
(*%E *)
(*%E *)
(*%T RegParam *)
RetSize = 0
(*%E *)
public CRC$DoCks:
(*%F RegParam *)
push bp
mov bp,sp
(*%E *)
(*%T LongAddr *)
push ds
(*%E *)
push si
(*%F RegParam *)
(*%T LongAddr *)
lds si, [bp][Sofs]
(*%E *)
(*%F LongAddr *)
mov si, [bp][Sofs]
(*%E *)
mov cx,[bp][Slen]
mov bx,[bp][CRC]
(*%E *)
(*%T RegParam *)
(*%T LongAddr *)
mov si, ax
mov ds, bx
mov bx, dx (* CX = L; BX = CRC *)
(*%E *)
(*%F LongAddr *)
mov si, ax
xchg bx, cx (* BX = CRC; CX = L *)
(*%E *)
(*%E *)
jcxz Return
Chk0:
lodsb (* al = next buffer element *)
add bl, al
loop Chk0 (* continue *)
Return:
mov al, bl
xor ah,ah
pop si
(*%T LongAddr *)
pop ds
(*%E *)
(*%F RegParam *)
pop bp
(*%E *)
(*%F sameCS *)
ret far RetSize
(*%E *)
(*%T sameCS *)
ret near RetSize
(*%E *)

section; segment _TEXT(CODE,28H);

(*%F RegParam *)
(*%T LongAddr *)
Sseg = 6+frame; Sofs = 4 + frame; Slen = 2+frame; CRC = frame; RetSize = 8
(*%E *)
(*%F LongAddr *)
Sofs = 4+frame; Slen = 2+ frame; CRC = frame; RetSize = 6
(*%E *)
(*%E *)
(*%T RegParam *)
RetSize = 0
(*%E *)
public CRC$DoBCks:
(*%F RegParam *)
push bp
mov bp,sp
(*%E *)
(*%T LongAddr *)
push ds
(*%E *)
push si
(*%F RegParam *)
(*%T LongAddr *)
lds si, [bp][Sofs]
(*%E *)
(*%F LongAddr *)
mov si, [bp][Sofs]
(*%E *)
mov cx,[bp][Slen]
mov bx,[bp][CRC]
(*%E *)
(*%T RegParam *)
(*%T LongAddr *)
mov si, ax
mov ds, bx
mov bx, dx (* CX = L; BX = CRC *)
(*%E *)
(*%F LongAddr *)
mov si, ax
xchg bx, cx (* BX = CRC; CX = L *)
(*%E *)
(*%E *)
jcxz Return
xor bh, bh (* use for addition *)
BChk0:
shl bl,1
adc bl,bh
lodsb
add bl,al
adc bl,bh
loop BChk0 (* continue *)
Return:
mov ax, bx
pop si
(*%T LongAddr *)
pop ds
(*%E *)
(*%F RegParam *)
pop bp
(*%E *)
(*%F sameCS *)
ret far RetSize
(*%E *)
(*%T sameCS *)
ret near RetSize
(*%E *)

section
segment _TEXT(CODE,28H); segment _DATA(DATA, 28H)

select _DATA
CRC32table:
dw 00000H, 00000H, 03096H, 07707H, 0612CH, 0EE0EH, 051BAH, 09909H
dw 0C419H, 0076DH, 0F48FH, 0706AH, 0A535H, 0E963H, 095A3H, 09E64H
dw 08832H, 00EDBH, 0B8A4H, 079DCH, 0E91EH, 0E0D5H, 0D988H, 097D2H
dw 04C2BH, 009B6H, 07CBDH, 07EB1H, 02D07H, 0E7B8H, 01D91H, 090BFH
dw 01064H, 01DB7H, 020F2H, 06AB0H, 07148H, 0F3B9H, 041DEH, 084BEH
dw 0D47DH, 01ADAH, 0E4EBH, 06DDDH, 0B551H, 0F4D4H, 085C7H, 083D3H
dw 09856H, 0136CH, 0A8C0H, 0646BH, 0F97AH, 0FD62H, 0C9ECH, 08A65H
dw 05C4FH, 01401H, 06CD9H, 06306H, 03D63H, 0FA0FH, 00DF5H, 08D08H
dw 020C8H, 03B6EH, 0105EH, 04C69H, 041E4H, 0D560H, 07172H, 0A267H
dw 0E4D1H, 03C03H, 0D447H, 04B04H, 085FDH, 0D20DH, 0B56BH, 0A50AH
dw 0A8FAH, 035B5H, 0986CH, 042B2H, 0C9D6H, 0DBBBH, 0F940H, 0ACBCH
dw 06CE3H, 032D8H, 05C75H, 045DFH, 00DCFH, 0DCD6H, 03D59H, 0ABD1H
dw 030ACH, 026D9H, 0003AH, 051DEH, 05180H, 0C8D7H, 06116H, 0BFD0H
dw 0F4B5H, 021B4H, 0C423H, 056B3H, 09599H, 0CFBAH, 0A50FH, 0B8BDH
dw 0B89EH, 02802H, 08808H, 05F05H, 0D9B2H, 0C60CH, 0E924H, 0B10BH
dw 07C87H, 02F6FH, 04C11H, 05868H, 01DABH, 0C161H, 02D3DH, 0B666H
dw 04190H, 076DCH, 07106H, 001DBH, 020BCH, 098D2H, 0102AH, 0EFD5H
dw 08589H, 071B1H, 0B51FH, 006B6H, 0E4A5H, 09FBFH, 0D433H, 0E8B8H
dw 0C9A2H, 07807H, 0F934H, 00F00H, 0A88EH, 09609H, 09818H, 0E10EH
dw 00DBBH, 07F6AH, 03D2DH, 0086DH, 06C97H, 09164H, 05C01H, 0E663H
dw 051F4H, 06B6BH, 06162H, 01C6CH, 030D8H, 08565H, 0004EH, 0F262H
dw 095EDH, 06C06H, 0A57BH, 01B01H, 0F4C1H, 08208H, 0C457H, 0F50FH
dw 0D9C6H, 065B0H, 0E950H, 012B7H, 0B8EAH, 08BBEH, 0887CH, 0FCB9H
dw 01DDFH, 062DDH, 02D49H, 015DAH, 07CF3H, 08CD3H, 04C65H, 0FBD4H
dw 06158H, 04DB2H, 051CEH, 03AB5H, 00074H, 0A3BCH, 030E2H, 0D4BBH
dw 0A541H, 04ADFH, 095D7H, 03DD8H, 0C46DH, 0A4D1H, 0F4FBH, 0D3D6H
dw 0E96AH, 04369H, 0D9FCH, 0346EH, 08846H, 0AD67H, 0B8D0H, 0DA60H
dw 02D73H, 04404H, 01DE5H, 03303H, 04C5FH, 0AA0AH, 07CC9H, 0DD0DH
dw 0713CH, 05005H, 041AAH, 02702H, 01010H, 0BE0BH, 02086H, 0C90CH
dw 0B525H, 05768H, 085B3H, 0206FH, 0D409H, 0B966H, 0E49FH, 0CE61H
dw 0F90EH, 05EDEH, 0C998H, 029D9H, 09822H, 0B0D0H, 0A8B4H, 0C7D7H
dw 03D17H, 059B3H, 00D81H, 02EB4H, 05C3BH, 0B7BDH, 06CADH, 0C0BAH
dw 08320H, 0EDB8H, 0B3B6H, 09ABFH, 0E20CH, 003B6H, 0D29AH, 074B1H
dw 04739H, 0EAD5H, 077AFH, 09DD2H, 02615H, 004DBH, 01683H, 073DCH
dw 00B12H, 0E363H, 03B84H, 09464H, 06A3EH, 00D6DH, 05AA8H, 07A6AH
dw 0CF0BH, 0E40EH, 0FF9DH, 09309H, 0AE27H, 00A00H, 09EB1H, 07D07H
dw 09344H, 0F00FH, 0A3D2H, 08708H, 0F268H, 01E01H, 0C2FEH, 06906H
dw 0575DH, 0F762H, 067CBH, 08065H, 03671H, 0196CH, 006E7H, 06E6BH
dw 01B76H, 0FED4H, 02BE0H, 089D3H, 07A5AH, 010DAH, 04ACCH, 067DDH
dw 0DF6FH, 0F9B9H, 0EFF9H, 08EBEH, 0BE43H, 017B7H, 08ED5H, 060B0H
dw 0A3E8H, 0D6D6H, 0937EH, 0A1D1H, 0C2C4H, 038D8H, 0F252H, 04FDFH
dw 067F1H, 0D1BBH, 05767H, 0A6BCH, 006DDH, 03FB5H, 0364BH, 048B2H
dw 02BDAH, 0D80DH, 01B4CH, 0AF0AH, 04AF6H, 03603H, 07A60H, 04104H
dw 0EFC3H, 0DF60H, 0DF55H, 0A867H, 08EEFH, 0316EH, 0BE79H, 04669H
dw 0B38CH, 0CB61H, 0831AH, 0BC66H, 0D2A0H, 0256FH, 0E236H, 05268H
dw 07795H, 0CC0CH, 04703H, 0BB0BH, 016B9H, 02202H, 0262FH, 05505H
dw 03BBEH, 0C5BAH, 00B28H, 0B2BDH, 05A92H, 02BB4H, 06A04H, 05CB3H
dw 0FFA7H, 0C2D7H, 0CF31H, 0B5D0H, 09E8BH, 02CD9H, 0AE1DH, 05BDEH
dw 0C2B0H, 09B64H, 0F226H, 0EC63H, 0A39CH, 0756AH, 0930AH, 0026DH
dw 006A9H, 09C09H, 0363FH, 0EB0EH, 06785H, 07207H, 05713H, 00500H
dw 04A82H, 095BFH, 07A14H, 0E2B8H, 02BAEH, 07BB1H, 01B38H, 00CB6H
dw 08E9BH, 092D2H, 0BE0DH, 0E5D5H, 0EFB7H, 07CDCH, 0DF21H, 00BDBH
dw 0D2D4H, 086D3H, 0E242H, 0F1D4H, 0B3F8H, 068DDH, 0836EH, 01FDAH
dw 016CDH, 081BEH, 0265BH, 0F6B9H, 077E1H, 06FB0H, 04777H, 018B7H
dw 05AE6H, 08808H, 06A70H, 0FF0FH, 03BCAH, 06606H, 00B5CH, 01101H
dw 09EFFH, 08F65H, 0AE69H, 0F862H, 0FFD3H, 0616BH, 0CF45H, 0166CH
dw 0E278H, 0A00AH, 0D2EEH, 0D70DH, 08354H, 04E04H, 0B3C2H, 03903H
dw 02661H, 0A767H, 016F7H, 0D060H, 0474DH, 04969H, 077DBH, 03E6EH
dw 06A4AH, 0AED1H, 05ADCH, 0D9D6H, 00B66H, 040DFH, 03BF0H, 037D8H
dw 0AE53H, 0A9BCH, 09EC5H, 0DEBBH, 0CF7FH, 047B2H, 0FFE9H, 030B5H
dw 0F21CH, 0BDBDH, 0C28AH, 0CABAH, 09330H, 053B3H, 0A3A6H, 024B4H
dw 03605H, 0BAD0H, 00693H, 0CDD7H, 05729H, 054DEH, 067BFH, 023D9H
dw 07A2EH, 0B366H, 04AB8H, 0C461H, 01B02H, 05D68H, 02B94H, 02A6FH
dw 0BE37H, 0B40BH, 08EA1H, 0C30CH, 0DF1BH, 05A05H, 0EF8DH, 02D02H

select _TEXT

(*%F RegParam *)
(*%T LongAddr *)
Sseg = 8+frame; Sofs = 6 + frame; Slen = 4+frame; CRC = frame; RetSize = 10
(*%E *)
(*%F LongAddr *)
Sofs = 6+frame; Slen = 4+ frame; CRC = frame; RetSize = 8
(*%E *)
(*%E *)
(*%T RegParam *)
(*%T LongAddr *)
CRC = frame; RetSize = 4
(*%E *)
(*%F LongAddr *)
RetSize = 0
(*%E *)
(*%E *)
public CRC$DoC32:
(*%F RegParam *)
push bp
mov bp,sp
(*%E *)
(*%T RegParam *)(*%T LongAddr *)
push bp
mov bp,sp
(*%E *)(*%E *)
(*%T LongAddr *)
push ds
(*%E *)
push si
push di
(*%F RegParam *)
mov cx,[bp][Slen]
les ax,[bp][CRC]
mov dx,es (* CX = L *)
(*%T LongAddr *)
lds si, [bp][Sofs]
(*%E *)
(*%F LongAddr *)
mov si, ds
mov es, si
mov si, [bp][Sofs]
(*%E *)
(*%E *)
(*%T RegParam *)
(*%T LongAddr *)
mov si, ax (* offset *)
mov ds, bx (* segment *)
les ax,[bp][CRC]
mov dx,es (* CX = L *)
(*%E *)
(*%F LongAddr *)
mov si, ax (* offset *)
mov ax, cx (* CRC *)
mov cx, bx (* Len *) (* DX keeps high CRC *)
(*%E *)
(*%E *)
(*%T LongAddr *)
mov di, seg CRC32table (* just use di to save segment *)
(*%E *)
(*%F LongAddr *)
mov di, CRC32table (* use as pointer *)
(*%E *)
jcxz CRC32Return
CRC32loop:
xor bh,bh
mov bl,al
lodsb
xor bl,al
mov al,ah
mov ah,dl
mov dl,dh
xor dh,dh
shl bx,1
shl bx,1
(*%F LongAddr *)
les bx,[di][bx]
(*%E *)
(*%T LongAddr *)
mov es, di (* restore es *)
les bx, es:[CRC32table][bx]
(*%E *)
xor ax,bx
mov bx,es
xor dx,bx
loop CRC32loop
CRC32Return:
pop di
pop si
(*%T LongAddr *)
pop ds
(*%T RegParam *)
pop bp
(*%E *)
(*%E *)
(*%F RegParam *)
pop bp
(*%E *)
(*%F sameCS *)
ret far RetSize
(*%E *)
(*%T sameCS *)
ret RetSize
(*%E *)

end