diff src/output.c @ 46:b962cee20bf4

Ported output modules forward from old version
author lost
date Sun, 04 Jan 2009 07:07:00 +0000
parents 34568fab6058
children 6de358e7903f
line wrap: on
line diff
--- a/src/output.c	Sun Jan 04 06:54:58 2009 +0000
+++ b/src/output.c	Sun Jan 04 07:07:00 2009 +0000
@@ -1,6 +1,6 @@
 /*
 output.c
-Copyright © 2008 William Astle
+Copyright © 2009 William Astle
 
 This file is part of LWASM.
 
@@ -35,7 +35,7 @@
 void write_code_decb(asmstate_t *as, FILE *of);
 void write_code_rawrel(asmstate_t *as, FILE *of);
 
-void write_code(asmstate_t *as)
+void lwasm_output(asmstate_t *as)
 {
 	FILE *of;
 	
@@ -88,15 +88,15 @@
 */
 void write_code_rawrel(asmstate_t *as, FILE *of)
 {
-	sourceline_t *cl;
+	lwasm_line_t *cl;
 	
-	for (cl = as -> source_head; cl; cl = cl -> next)
+	for (cl = as -> lineshead; cl; cl = cl -> next)
 	{
-		if (cl -> nocode)
+		if (cl -> codelen == 0)
 			continue;
 		
-		fseek(of, cl -> addr, SEEK_SET);
-		fwrite(cl -> codebytes, cl -> numcodebytes, 1, of);
+		fseek(of, cl -> codeaddr, SEEK_SET);
+		fwrite(cl -> bytes, cl -> codelen, 1, of);
 	}
 }
 
@@ -107,41 +107,39 @@
 */
 void write_code_raw(asmstate_t *as, FILE *of)
 {
-	sourceline_t *cl;
+	lwasm_line_t *cl;
 	
-	for (cl = as -> source_head; cl; cl = cl -> next)
+	for (cl = as -> lineshead; cl; cl = cl -> next)
 	{
-		if (cl -> nocode && cl -> len > 0)
+		if (cl -> nocodelen)
 		{
 			int i;
-			for (i = 0; i < cl -> len; i++)
+			for (i = 0; i < cl -> nocodelen; i++)
 				fwrite("\0", 1, 1, of);
 			continue;
 		}
-		if (cl -> nocode)
-			continue;
-		
-		fwrite(cl -> codebytes, cl -> numcodebytes, 1, of);
+		fwrite(cl -> bytes, cl -> codelen, 1, of);
 	}
 }
 
 void write_code_decb(asmstate_t *as, FILE *of)
 {
 	long preambloc;
-	sourceline_t *cl;
+	lwasm_line_t *cl;
 	int blocklen = -1;
 	int nextcalc = -1;
 	unsigned char outbuf[5];
 	
-	for (cl = as -> source_head; cl; cl = cl -> next)
+	for (cl = as -> lineshead; cl; cl = cl -> next)
 	{
-		if (cl -> nocode)
+		if (cl -> nocodelen)
 			continue;
-		if (cl -> addr != nextcalc && cl -> numcodebytes > 0)
+		if (cl -> codeaddr != nextcalc && cl -> codelen > 0)
 		{
 			// need preamble here
 			if (blocklen > 0)
 			{
+				// update previous preamble if needed
 				fseek(of, preambloc, SEEK_SET);
 				outbuf[0] = (blocklen >> 8) & 0xFF;
 				outbuf[1] = blocklen & 0xFF;
@@ -149,7 +147,7 @@
 				fseek(of, 0, SEEK_END);
 			}
 			blocklen = 0;
-			nextcalc = cl -> addr;
+			nextcalc = cl -> codeaddr;
 			outbuf[0] = 0x00;
 			outbuf[1] = 0x00;
 			outbuf[2] = 0x00;
@@ -158,9 +156,9 @@
 			preambloc = ftell(of) + 1;
 			fwrite(outbuf, 5, 1, of);
 		}
-		nextcalc += cl -> numcodebytes;
-		fwrite(cl -> codebytes, cl -> numcodebytes, 1, of);
-		blocklen += cl -> numcodebytes;
+		nextcalc += cl -> codelen;
+		fwrite(cl -> bytes, cl -> codelen, 1, of);
+		blocklen += cl -> codelen;
 	}
 	if (blocklen > 0)
 	{