diff lwasm/lwasm.c @ 236:a58f49a77441

Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
author lost
date Fri, 14 Aug 2009 03:22:26 +0000
parents bae1e3ecdce1
children a9a14e6b4bc8
line wrap: on
line diff
--- a/lwasm/lwasm.c	Fri Jun 12 05:25:41 2009 +0000
+++ b/lwasm/lwasm.c	Fri Aug 14 03:22:26 2009 +0000
@@ -79,6 +79,13 @@
 		register_error(as, l, 1, "Output not allowed inside BSS sections");
 		return;
 	}
+	
+	if (as -> outformat == OUTPUT_OS9 && as -> inmod == 0)
+	{
+		register_error(as, l, 1, "Output not allowed outside of module in OS9 mode");
+		return;
+	}
+	
 	if (as -> passnum == 1)
 		return;
 
@@ -90,6 +97,23 @@
 	}
 	l -> bytes[l -> codelen] = b & 0xff;
 	l -> codelen += 1;
+	
+	if (as -> outformat == OUTPUT_OS9 && as -> inmod)
+	{
+		// 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;
+		if (b & 0x80)
+			as -> crc ^= 0x800021;
+		as -> crc &= 0xffffff;
+	}
 }
 
 void lwasm_emitop(asmstate_t *as, lwasm_line_t *l, int o)