changeset 47:804d7465e0f9

Implemented ORG and fixed problems with constants using $, &, or @ to specify base
author lost
date Sun, 04 Jan 2009 07:25:03 +0000
parents b962cee20bf4
children 6de358e7903f
files src/Makefile.am src/expr.c src/instab.c src/list.c src/pseudo.c
diffstat 5 files changed, 34 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Sun Jan 04 07:07:00 2009 +0000
+++ b/src/Makefile.am	Sun Jan 04 07:25:03 2009 +0000
@@ -1,3 +1,3 @@
 bin_PROGRAMS = lwasm
-lwasm_SOURCES = main.c expr.c pass1.c pass2.c util.c instab.c parse.c lwasm.c insn_inh.c insn_rtor.c insn_rlist.c insn_rel.c insn_tfm.c insn_bitbit.c insn_indexed.c insn_gen.c insn_logicmem.c list.c symbol.c output.c
+lwasm_SOURCES = main.c expr.c pass1.c pass2.c util.c instab.c parse.c lwasm.c insn_inh.c insn_rtor.c insn_rlist.c insn_rel.c insn_tfm.c insn_bitbit.c insn_indexed.c insn_gen.c insn_logicmem.c list.c symbol.c output.c pseudo.c
 EXTRA_DIST = instab.h lwasm.h expr.h util.h
--- a/src/expr.c	Sun Jan 04 07:07:00 2009 +0000
+++ b/src/expr.c	Sun Jan 04 07:25:03 2009 +0000
@@ -318,7 +318,7 @@
 		int val = 0;
 		
 		(*p)++;
-		while (strchr("0123456789", **p))
+		while (**p && strchr("0123456789", **p))
 		{
 			val = val * 10 + (**p - '0');
 			(*p)++;
@@ -350,11 +350,13 @@
 		int val = 0, val2;
 		
 		(*p)++;
-		while (strchr("0123456789ABCDEFabcdef", **p))
+		debug_message(3, "Found prefix hex constant: %s", *p);
+		while (**p && strchr("0123456789ABCDEFabcdef", **p))
 		{
 			val2 = toupper(**p) - '0';
 			if (val2 > 9)
 				val2 -= 7;
+			debug_message(3, "Got char: %c (%d)", **p, val2);
 			val = val * 16 + val2;
 			(*p)++;
 		}
@@ -371,7 +373,7 @@
 		int val = 0;
 		
 		(*p)++;
-		while (strchr("01234567", **p))
+		while (**p && strchr("01234567", **p))
 		{
 			val = val * 8 + (**p - '0');
 			(*p)++;
--- a/src/instab.c	Sun Jan 04 07:07:00 2009 +0000
+++ b/src/instab.c	Sun Jan 04 07:25:03 2009 +0000
@@ -40,6 +40,7 @@
 extern OPFUNC(insn_logicmem);
 extern OPFUNC(insn_tfm);
 extern OPFUNC(insn_indexed);
+extern OPFUNC(pseudo_org);
 
 instab_t instab[] =
 {
@@ -283,6 +284,8 @@
 	{ "tstf",	{	0x115d,	-0x1,	-0x1,	-0x1	},	insn_inh },
 	{ "tstw",	{	0x105d,	-0x1,	-0x1,	-0x1	},	insn_inh },
 
+	{ "org",	{ -1, -1, -1, -1 },	pseudo_org },
+
 	/* flag end of table */	
 	{ NULL,		{ -0x1, -0x1, -0x1, -0x1 }, insn_inh }
 };
--- a/src/list.c	Sun Jan 04 07:07:00 2009 +0000
+++ b/src/list.c	Sun Jan 04 07:25:03 2009 +0000
@@ -69,12 +69,9 @@
 	{
 		fprintf(lf, "%04X ", l -> codeaddr);
 		
-		if (l -> codelen > 0)
+		for (c = 0; c < l -> codelen && c < 5; c++)
 		{
-			for (c = 0; c < l -> codelen && c < 5; c++)
-			{
-				fprintf(lf, "%02X", l -> bytes[c]);
-			}
+			fprintf(lf, "%02X", l -> bytes[c]);
 		}
 		while (c < 5)
 		{
--- a/src/pseudo.c	Sun Jan 04 07:07:00 2009 +0000
+++ b/src/pseudo.c	Sun Jan 04 07:25:03 2009 +0000
@@ -1,6 +1,6 @@
 /*
 pseudo.c
-Copyright © 2008 William Astle
+Copyright © 2009 William Astle
 
 This file is part of LWASM.
 
@@ -21,29 +21,38 @@
 This file implements the various pseudo operations.
 */
 
-#include <ctype.h>
 #include <stdlib.h>
-#include <string.h>
 #include "lwasm.h"
 #include "instab.h"
+#include "expr.h"
 
-#include <stdio.h>
 
-void pseudo_org(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_org)
 {
-	int v1, rval;
+	int rval;
+	lwasm_expr_stack_t *s;
 	
-	if (cl -> hassym)
+	if (l -> sym)
 	{
-		register_error(as, cl, ERR_SYM);
-		cl -> hassym = 0;
+		register_error(as, l, 1, "No symbol allowed with ORG");
 	}
-	rval = eval_expr(as, cl, optr, &v1);
-	cl -> addr = v1;
-	cl -> addrset = 1;
-	as -> addr = v1;
+	s = lwasm_evaluate_expr(as, l, *p, NULL);
+	if (!s)
+	{
+		register_error(as, l, 1, "Bad expression");
+		return;
+	}
+	if (!lwasm_expr_is_constant(s))
+	{
+		register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
+		return;
+	}
+	rval = lwasm_expr_get_value(s);
+	l -> codeaddr = rval;
+	as -> addr = rval;
 }
 
+/*
 void pseudo_include(asmstate_t *as, sourceline_t *cl, char **optr)
 {
 	int v1;
@@ -584,3 +593,4 @@
 	cl -> user_error = strdup(*optr);
 	errorp1(ERR_USER);
 }
+*/