changeset 238:a9a14e6b4bc8

Fixed os9 module CRC calculation
author lost
date Sat, 15 Aug 2009 05:26:02 +0000
parents dca5938a64aa
children 1106ec189e4f
files lwasm/lwasm.c lwasm/lwasm.h lwasm/os9.c
diffstat 3 files changed, 26 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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;
+		}
 	}
 }
 
--- 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
--- 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;
 }