changeset 65:31d8e85706e7

Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
author lost
date Mon, 05 Jan 2009 01:40:01 +0000
parents aaddd47219b4
children aa9d9fedfdf4
files src/insn_gen.c src/instab.c src/pass2.c src/pseudo.c
diffstat 4 files changed, 21 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/insn_gen.c	Mon Jan 05 01:27:08 2009 +0000
+++ b/src/insn_gen.c	Mon Jan 05 01:40:01 2009 +0000
@@ -38,7 +38,8 @@
 	lwasm_expr_stack_t *s;
 	int f8 = 0;
 	int f16 = 0;
-	
+	int isdp = 0;
+		
 	optr2 = *optr;
 	while (*optr2 && !isspace(*optr2) && *optr2 != ',') optr2++
 		/* do nothing */ ;
@@ -67,7 +68,7 @@
 			register_error(as, l, 1, "Bad expression");
 			return;
 		}
-		if (!lwasm_expr_is_constant(s))
+		if (!lwasm_expr_is_constant(s) && as -> passnum == 1)
 		{
 			f16 = 1;
 			l -> fsize = 2;
@@ -75,8 +76,11 @@
 		}
 		v1 = lwasm_expr_get_value(s);
 		lwasm_expr_stack_free(s);
+
+		if (((v1 >> 8) & 0xff) == (as -> dpval & 0xff))
+			isdp = 1;
 		
-		if (f8 || (!f16 && v1 >= -128 && v1 <= 255))
+		if (f8 || (!f16 && isdp))
 		{
 			v1 = v1 & 0xffff;
 			tv = v1 - ((as -> dpval) << 8);
--- a/src/instab.c	Mon Jan 05 01:27:08 2009 +0000
+++ b/src/instab.c	Mon Jan 05 01:40:01 2009 +0000
@@ -69,7 +69,7 @@
 extern OPFUNC(pseudo_endc);
 extern OPFUNC(pseudo_macro);
 extern OPFUNC(pseudo_endm);
-
+extern OPFUNC(pseudo_setdp);
 extern OPFUNC(pseudo_set);
 
 instab_t instab[] =
@@ -356,6 +356,7 @@
 	{ "macro",	{ -1, -1, -1, -1}, 	pseudo_macro,	1,	0 },
 	{ "endm",	{ -1, -1, -1, -1},	pseudo_endm,	1,	1 },	
 
+	{ "setdp", 	{ -1, -1, -1, -1},	pseudo_setdp },
 	{ "set",	{ -1, -1, -1, -1},	pseudo_set,	0,	0,	1 },
 
 	/* flag end of table */	
--- a/src/pass2.c	Mon Jan 05 01:27:08 2009 +0000
+++ b/src/pass2.c	Mon Jan 05 01:40:01 2009 +0000
@@ -43,7 +43,8 @@
 	as -> inmacro = 0;
 	as -> nextcontext = 1;
 	as -> skiplines = 0;
-
+	as -> dpval = 0;
+	
 	// iterate over all the lines and re-parse them
 	for (l = as -> lineshead; l && !(as -> endseen); l = l -> next)
 	{
--- a/src/pseudo.c	Mon Jan 05 01:27:08 2009 +0000
+++ b/src/pseudo.c	Mon Jan 05 01:40:01 2009 +0000
@@ -396,42 +396,19 @@
 	lwasm_register_symbol(as, l, l -> sym, rval, SYMBOL_SET);
 }
 
-/*
-void pseudo_setdp(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_setdp)
 {
-	int rval, v1;
+	int rval;
 
-	if (cl -> hassym)
-	{
-		register_error(as, cl, ERR_SYM);
-		cl -> hassym = 0;
-		return;
-	}
-	else
-	{
-		rval = eval_expr(as, cl, optr, &v1);
-		if (rval == -1)
-		{
-			errorp1(ERR_FORWARD);
-		}
-		if (rval < 0)
-		{
-			cl -> opcode = -1;
-			return;
-		}
-	}
-	// setdp needs to resolve properly on pass 2
-	if (v1 > 0xff || v1 < 0)
-	{
-		errorp1(ERR_OVERFLOW);
-	}	
-	as -> dpval = v1 & 0xff;
-	cl -> dpval = v1 & 0xff;
-	cl -> issetdp = 1;
-	cl -> numcodebytes = 0;
-//printf("%s\n", "SETDP2");
+	// setdp is needed on both passes	
+	if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST | EXPR_PASS2CONST | EXPR_BYTE, &rval) < 0)
+		rval = 0;
+
+	l -> symaddr = rval & 0xFF;
+	l -> addrset = 2;
+	
+	as -> dpval = rval & 0xFF;
 }
-*/
 
 OPFUNC(pseudo_fcc)
 {