mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-23 06:15:10 +00:00
Completed struct implementation
This commit is contained in:
parent
15bb0ea9c5
commit
15bab0f74a
2 changed files with 43 additions and 34 deletions
62
assembler.c
62
assembler.c
|
@ -91,45 +91,49 @@ findmacro(char *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
Label *
|
Label *
|
||||||
findlabelplain(char *s)
|
findlabel(char *s)
|
||||||
{
|
{
|
||||||
int i;
|
int i, rng = scin(s, '.');
|
||||||
|
char name[64];
|
||||||
|
scpy(s, name, rng > 0 ? rng + 1 : 64);
|
||||||
for(i = 0; i < labelslen; ++i)
|
for(i = 0; i < labelslen; ++i)
|
||||||
if(scmp(labels[i].name, s, 64))
|
if(scmp(labels[i].name, name, 64))
|
||||||
return &labels[i];
|
return &labels[i];
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Label *
|
Uint16
|
||||||
findlabelmacro(char *s)
|
findlabeladdr(char *s)
|
||||||
{
|
{
|
||||||
int i, o = 0, pti = scin(s, '.');
|
int i, o = 0;
|
||||||
char name[64], param[64];
|
char *param;
|
||||||
Label *l;
|
Label *l = findlabel(s);
|
||||||
if(pti > 0) {
|
if(scin(s, '.') < 1)
|
||||||
scpy(s, name, pti + 1);
|
return l->addr;
|
||||||
scpy(s + pti + 1, param, 64);
|
param = s + scin(s, '.') + 1;
|
||||||
} else
|
|
||||||
scpy(s, name, 64);
|
|
||||||
if(!(l = findlabelplain(name)) || !l->macro)
|
|
||||||
return NULL;
|
|
||||||
/* find macro offset */
|
|
||||||
for(i = 0; i < l->macro->len; ++i) {
|
for(i = 0; i < l->macro->len; ++i) {
|
||||||
if(scmp(l->macro->params[i], param, 64)) {
|
if(scmp(l->macro->params[i], param, 64))
|
||||||
l->offset = o;
|
return l->addr + o;
|
||||||
break;
|
|
||||||
}
|
|
||||||
o += l->macro->length[i];
|
o += l->macro->length[i];
|
||||||
}
|
}
|
||||||
return l;
|
printf("Warning %s.%s[%s]\n", l->name, param, l->macro->name);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Label *
|
Uint8
|
||||||
findlabel(char *s)
|
findlabellen(char *s)
|
||||||
{
|
{
|
||||||
if(scin(s, '.') > 0)
|
int i;
|
||||||
return findlabelmacro(s);
|
char *param;
|
||||||
return findlabelplain(s);
|
Label *l = findlabel(s);
|
||||||
|
if(scin(s, '.') < 1)
|
||||||
|
return l->len;
|
||||||
|
param = s + scin(s, '.') + 1;
|
||||||
|
for(i = 0; i < l->macro->len; ++i)
|
||||||
|
if(scmp(l->macro->params[i], param, 64))
|
||||||
|
return l->macro->length[i];
|
||||||
|
printf("Warning %s.%s[%s]\n", l->name, param, l->macro->name);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
|
@ -356,9 +360,9 @@ pass2(FILE *f)
|
||||||
else if(w[0] == '+' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)shex(w + 1), 1);
|
else if(w[0] == '+' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)shex(w + 1), 1);
|
||||||
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 2) pushbyte((Sint8)(shex(w + 1) * -1), 1);
|
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 2) pushbyte((Sint8)(shex(w + 1) * -1), 1);
|
||||||
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)(shex(w + 1) * -1), 1);
|
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)(shex(w + 1) * -1), 1);
|
||||||
else if(w[0] == '=' && (l = findlabel(w + 1)) && l->len){ pushshort(l->addr + l->offset, 1); pushbyte(findopcode(l->len == 2 ? "STR2" : "STR"),0); }
|
else if(w[0] == '=' && (l = findlabel(w + 1)) && l->len){ pushshort(findlabeladdr(w+1), 1); pushbyte(findopcode(findlabellen(w+1) == 2? "STR2" : "STR"), 0); }
|
||||||
else if(w[0] == '~' && (l = findlabel(w + 1)) && l->len){ pushshort(l->addr + l->offset, 1); pushbyte(findopcode(l->len == 2 ? "LDR2" : "LDR"),0); }
|
else if(w[0] == '~' && (l = findlabel(w + 1)) && l->len){ pushshort(findlabeladdr(w+1), 1); pushbyte(findopcode(findlabellen(w+1) == 2 ? "LDR2" : "LDR"), 0); }
|
||||||
else if((l = findlabel(w + 1))) pushshort(l->addr + l->offset, w[0] == ',');
|
else if((l = findlabel(w + 1))) pushshort(findlabeladdr(w+1), w[0] == ',');
|
||||||
else {
|
else {
|
||||||
return error("Unknown label in second pass", w);
|
return error("Unknown label in second pass", w);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,16 +4,21 @@
|
||||||
:dev/w fff9 ( std write port )
|
:dev/w fff9 ( std write port )
|
||||||
|
|
||||||
&Rect2d { x 2 y 2 width 2 height 2 }
|
&Rect2d { x 2 y 2 width 2 height 2 }
|
||||||
|
&ColorRGB { r 1 g 1 b 1 }
|
||||||
|
|
||||||
;rc1 Rect2d
|
;rc1 Rect2d
|
||||||
|
;red ColorRGB
|
||||||
( TODO )
|
|
||||||
|
|
||||||
|0100 @RESET
|
|0100 @RESET
|
||||||
|
|
||||||
#abcd ,rc1.height STR2
|
( byte mode )
|
||||||
,rc1.height LDR2
|
#ff =red.r
|
||||||
,rc1.height LDR2
|
~red.r
|
||||||
|
|
||||||
|
( short mode )_
|
||||||
|
#1234 =rc1.x
|
||||||
|
#abcd =rc1.height
|
||||||
|
~rc1.height
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue