# HG changeset patch # User lost # Date 1250313962 0 # Node ID a9a14e6b4bc89402433370be1742234978c459d3 # Parent dca5938a64aa084530827bb80f10c83a7a281167 Fixed os9 module CRC calculation diff -r dca5938a64aa -r a9a14e6b4bc8 lwasm/lwasm.c --- a/lwasm/lwasm.c Fri Aug 14 04:20:15 2009 +0000 +++ b/lwasm/lwasm.c Sat Aug 15 05:26:02 2009 +0000 @@ -103,16 +103,21 @@ // calc the CRC b &= 0xff; - b ^= (as -> crc) >> 16; - as -> crc <<= 8; - as -> crc ^= b << 1; - as -> crc ^= b << 6; - b ^= b << 1; - b ^= b << 2; - b ^= b << 4; + b ^= (as -> crc)[0]; + (as -> crc)[0] = (as -> crc)[1]; + (as -> crc)[1] = (as -> crc)[2]; + (as -> crc)[1] ^= (b >> 7); + (as -> crc)[2] = (b << 1); + (as -> crc)[1] ^= (b >> 2); + (as -> crc)[2] ^= (b << 6); + b ^= (b << 1); + b ^= (b << 2); + b ^= (b << 4); if (b & 0x80) - as -> crc ^= 0x800021; - as -> crc &= 0xffffff; + { + (as -> crc)[0] ^= 0x80; + (as -> crc)[2] ^= 0x21; + } } } diff -r dca5938a64aa -r a9a14e6b4bc8 lwasm/lwasm.h --- a/lwasm/lwasm.h Fri Aug 14 04:20:15 2009 +0000 +++ b/lwasm/lwasm.h Sat Aug 15 05:26:02 2009 +0000 @@ -188,7 +188,7 @@ // for os9 mode int inmod; // in a module? - unsigned long crc; // running crc count + unsigned char crc[3]; // running crc count } asmstate_t; // do not rewrite XXX,r to ,r if XXX evaluates to 0 diff -r dca5938a64aa -r a9a14e6b4bc8 lwasm/os9.c --- a/lwasm/os9.c Fri Aug 14 04:20:15 2009 +0000 +++ b/lwasm/os9.c Sat Aug 15 05:26:02 2009 +0000 @@ -113,7 +113,9 @@ as -> addr = 0; // init crc - as -> crc = 0xffffff; + as -> crc[0] = 0xff; + as -> crc[1] = 0xff; + as -> crc[2] = 0xff; as -> inmod = 1; // sync bytes @@ -138,7 +140,7 @@ lwasm_emit(as, l, ~(0x87 ^ 0xCD ^ (modvals[0] >> 8) ^ (modvals[0] & 0xff) ^ (modvals[1] >> 8) ^ (modvals[1] & 0xff) ^ modvals[2] ^ modvals[3])); - + // module type specific output // note that these are handled the same for all so // there need not be any special casing @@ -154,7 +156,7 @@ OPFUNC(pseudo_emod) { - unsigned long tcrc; + unsigned char tcrc[3]; if (as -> outformat != OUTPUT_OS9) { @@ -169,9 +171,11 @@ } // don't mess with CRC! - tcrc = as -> crc; - lwasm_emit(as, l, tcrc >> 16); - lwasm_emit(as, l, tcrc >> 8); - lwasm_emit(as, l, tcrc); + tcrc[0] = as -> crc[0] ^ 0xff; + tcrc[1] = as -> crc[1] ^ 0xff; + tcrc[2] = as -> crc[2] ^ 0xff; + lwasm_emit(as, l, tcrc[0]); + lwasm_emit(as, l, tcrc[1]); + lwasm_emit(as, l, tcrc[2]); as -> inmod = 0; }