Minor cleanup
This commit is contained in:
parent
3280c2031b
commit
677515924a
53
assembler.c
53
assembler.c
|
@ -256,12 +256,6 @@ int
|
|||
walktoken(char *w)
|
||||
{
|
||||
Macro *m;
|
||||
if((m = findmacro(w))) {
|
||||
int i, res = 0;
|
||||
for(i = 0; i < m->len; ++i)
|
||||
res += walktoken(m->items[i]);
|
||||
return res;
|
||||
}
|
||||
if(findopcode(w) || scmp(w, "BRK", 4))
|
||||
return 1;
|
||||
switch(w[0]) {
|
||||
|
@ -274,6 +268,12 @@ walktoken(char *w)
|
|||
case '-': /* signed negative */
|
||||
case '#': return (slen(w + 1) == 2 ? 2 : 3);
|
||||
}
|
||||
if((m = findmacro(w))) {
|
||||
int i, res = 0;
|
||||
for(i = 0; i < m->len; ++i)
|
||||
res += walktoken(m->items[i]);
|
||||
return res;
|
||||
}
|
||||
return error("Unknown label in first pass", w);
|
||||
}
|
||||
|
||||
|
@ -293,38 +293,32 @@ parsetoken(char *w)
|
|||
pushbyte((Sint8)(l->addr - p.ptr - 3), 1);
|
||||
l->refs++;
|
||||
return 1;
|
||||
}
|
||||
if(w[0] == '=' && (l = findlabel(w + 1))) {
|
||||
} else if(w[0] == '=' && (l = findlabel(w + 1))) {
|
||||
if(!findlabellen(w + 1) || findlabellen(w + 1) > 2)
|
||||
return error("Invalid load helper", w);
|
||||
return error("Invalid store helper", w);
|
||||
pushshort(findlabeladdr(w + 1), 1);
|
||||
pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "STR"), 0);
|
||||
l->refs++;
|
||||
return 1;
|
||||
}
|
||||
if(w[0] == '~' && (l = findlabel(w + 1))) {
|
||||
} else if(w[0] == '~' && (l = findlabel(w + 1))) {
|
||||
if(!findlabellen(w + 1) || findlabellen(w + 1) > 2)
|
||||
return error("Invalid load helper", w);
|
||||
pushshort(findlabeladdr(w + 1), 1);
|
||||
pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "LDR"), 0);
|
||||
l->refs++;
|
||||
return 1;
|
||||
}
|
||||
if((op = findopcode(w)) || scmp(w, "BRK", 4)) {
|
||||
} else if((op = findopcode(w)) || scmp(w, "BRK", 4)) {
|
||||
pushbyte(op, 0);
|
||||
return 1;
|
||||
}
|
||||
if(w[0] == '.' && (l = findlabel(w + 1))) {
|
||||
} else if(w[0] == '.' && (l = findlabel(w + 1))) {
|
||||
pushshort(findlabeladdr(w + 1), 0);
|
||||
l->refs++;
|
||||
return 1;
|
||||
}
|
||||
if(w[0] == ',' && (l = findlabel(w + 1))) {
|
||||
} else if(w[0] == ',' && (l = findlabel(w + 1))) {
|
||||
pushshort(findlabeladdr(w + 1), 1);
|
||||
l->refs++;
|
||||
return 1;
|
||||
}
|
||||
if(w[0] == '#' && sihx(w + 1)) {
|
||||
} else if(w[0] == '#' && sihx(w + 1)) {
|
||||
if(slen(w + 1) == 2)
|
||||
pushbyte(shex(w + 1), 1);
|
||||
else if(slen(w + 1) == 4)
|
||||
|
@ -332,18 +326,14 @@ parsetoken(char *w)
|
|||
else
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(w[0] == '+' && sihx(w + 1)) {
|
||||
} else if(w[0] == '+' && sihx(w + 1)) {
|
||||
if(slen(w + 1) == 2)
|
||||
pushbyte((Sint8)shex(w + 1), 1);
|
||||
else if(slen(w + 1) == 4)
|
||||
pushshort((Sint16)shex(w + 1), 1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(w[0] == '-' && sihx(w + 1)) {
|
||||
} else if(w[0] == '-' && sihx(w + 1)) {
|
||||
if(slen(w + 1) == 2)
|
||||
pushbyte((Sint8)(shex(w + 1) * -1), 1);
|
||||
else if(slen(w + 1) == 4)
|
||||
|
@ -351,17 +341,13 @@ parsetoken(char *w)
|
|||
else
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if((m = findmacro(w))) {
|
||||
int i, res = 0;
|
||||
for(i = 0; i < m->len; ++i) {
|
||||
} else if((m = findmacro(w))) {
|
||||
int i;
|
||||
for(i = 0; i < m->len; ++i)
|
||||
if(!parsetoken(m->items[i]))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -399,10 +385,9 @@ pass1(FILE *f)
|
|||
if(shex(w + 1) < addr)
|
||||
return error("Memory Overwrite", w);
|
||||
addr = shex(w + 1);
|
||||
} else {
|
||||
} else
|
||||
addr += walktoken(w);
|
||||
}
|
||||
}
|
||||
rewind(f);
|
||||
return 1;
|
||||
}
|
||||
|
|
2
build.sh
2
build.sh
|
@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
|
|||
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
|
||||
|
||||
# run
|
||||
./bin/assembler projects/software/left.usm bin/boot.rom
|
||||
./bin/assembler projects/software/nasu.usm bin/boot.rom
|
||||
./bin/emulator bin/boot.rom
|
||||
|
|
Loading…
Reference in New Issue