aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2012-04-27 04:27:36 +0000
committerDimitri Sokolyuk <demon@dim13.org>2012-04-27 04:27:36 +0000
commitd0f296b1ea0af4ad6eb4ab462110da8fbd46e947 (patch)
treedbb607bc06bc6b036f4d9bce02bb5dd11ea77cd5
parentc3af840a1f82594f93425f3eb7a1085638d8f636 (diff)
switch args ordred according to spec
-rw-r--r--Makefile3
-rw-r--r--emu.c18
-rw-r--r--gramar.y21
3 files changed, 24 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 5b35564..7040e7b 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,8 @@ NOMAN=
CFLAGS+=`sdl-config --cflags`
LDADD+= `sdl-config --libs` -lcurses -lSDL_image
DEBUG+= -Wall
-#DEBUG+= -ggdb -pg
+DEBUG+= -ggdb
+#DEBUG+= -pg
YFLAGS+= -v
.include <bsd.prog.mk>
diff --git a/emu.c b/emu.c
index aa5d9e7..feb2e35 100644
--- a/emu.c
+++ b/emu.c
@@ -115,7 +115,7 @@ hwi(unsigned short *a)
cycle += 4;
}
-void (*extop[nExt])(unsigned short *a) = {
+void (*extop[nExt])(unsigned short *) = {
[NOP] = nop,
[JSR] = jsr,
[BRK] = stop,
@@ -380,7 +380,7 @@ std(unsigned short *b, unsigned short *a)
cycle += 2;
}
-void (*op[nOpt])(unsigned short *a, unsigned short *b) = {
+void (*op[nOpt])(unsigned short *, unsigned short *) = {
[EXT] = ext,
[SET] = set,
[ADD] = add,
@@ -486,7 +486,7 @@ fetcharg(int a, int barg)
int
step(unsigned short *m, unsigned short *r)
{
- unsigned short c, o, *a, *b, s;
+ unsigned short c, o, *a, *b, s, tmp;
if (!run)
return -1;
@@ -499,15 +499,9 @@ step(unsigned short *m, unsigned short *r)
s = reg[SP]; /* store SP */
o = c & 0x1f;
-
- /* don't fetch first arg for extended opcodes */
- reg[Aux] = (c >> 5) & 0x1f;
- b = o ? fetcharg(reg[Aux], 1) : &reg[Aux];
a = fetcharg((c >> 10) & 0x3f, 0);
-
- #if 0
- fprintf(stderr, "%x %x, %x\n", o, *b, *a);
- #endif
+ tmp = (c >> 5) & 0x1f;
+ b = o ? fetcharg(tmp, 1) : &tmp;
if (skip) {
skip = 0;
@@ -516,7 +510,7 @@ step(unsigned short *m, unsigned short *r)
if (op[o])
op[o](b, a);
else {
- warnx("wrong opcode 0x%x(0x%x, 0x%x)", o, *b, *a);
+ warnx("wrong opcode 0x%x (0x%x, 0x%x)", o, *b, *a);
++errors;
}
}
diff --git a/gramar.y b/gramar.y
index d5ec24a..5430429 100644
--- a/gramar.y
+++ b/gramar.y
@@ -30,6 +30,7 @@ void yyerror(const char *, ...);
void push(int, char *);
void popop(int);
void popall(void);
+void popallr(void);
void addref(char *);
#if YYDEBUG
@@ -83,7 +84,7 @@ struct label {
%left SHIFTL SHIFTR
%left PLUS MINUS
%left EMUL EDIV EMOD
-%left ENOT UMINUS
+%left ENOT NEG
%%
@@ -96,12 +97,12 @@ statement
: opcode operand COMMA operand
{
popop(($4 << 10) | ($2 << 5) | $1);
- popall();
+ popallr();
}
| extended operand
{
popop(($2 << 10) | ($1 << 5));
- popall();
+ popallr();
}
| noop { popop($1 << 5); }
| DP STRING { addref($2); }
@@ -129,7 +130,7 @@ block
expr
: NUMBER { $$ = $1; }
- | MINUS expr %prec UMINUS { $$ = -$2; }
+ | MINUS expr %prec NEG { $$ = -$2; }
| ENOT expr { $$ = ~$2; }
| expr PLUS expr { $$ = $1 + $3; }
| expr MINUS expr { $$ = $1 - $3; }
@@ -294,7 +295,7 @@ popall(void)
{
int n = sp;
- while (sp > 0) {
+ while (sp) {
buffer[pc] = stack[n - sp].val;
label[pc].label = stack[n - sp].label;
label[pc++].lineno = stack[n - sp--].lineno;
@@ -302,6 +303,16 @@ popall(void)
}
void
+popallr(void)
+{
+ while (sp) {
+ buffer[pc] = stack[--sp].val;
+ label[pc].label = stack[sp].label;
+ label[pc++].lineno = stack[sp].lineno;
+ }
+}
+
+void
addref(char *s)
{
ref[rp].label = s;