mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-30 01:33:01 +00:00
Cleanup
This commit is contained in:
parent
0027296839
commit
e162b4f083
7 changed files with 27 additions and 26 deletions
|
@ -118,7 +118,6 @@ A device that works like a NES controller, each button is a bit from a single by
|
|||
|
||||
- Includes
|
||||
- Defines
|
||||
- Print unused labels
|
||||
|
||||
## Refs
|
||||
|
||||
|
|
33
assembler.c
33
assembler.c
|
@ -17,17 +17,17 @@ typedef unsigned short Uint16;
|
|||
typedef signed short Sint16;
|
||||
|
||||
typedef struct {
|
||||
int ptr;
|
||||
Uint8 data[65536];
|
||||
Uint8 data[256 * 256];
|
||||
Uint16 ptr;
|
||||
} Program;
|
||||
|
||||
typedef struct {
|
||||
Uint8 len, length[16], size, refs;
|
||||
char name[64], params[16][64];
|
||||
Uint8 len, length[16], size;
|
||||
} Macro;
|
||||
|
||||
typedef struct {
|
||||
Uint8 len, offset;
|
||||
Uint8 len, offset, refs;
|
||||
Uint16 addr;
|
||||
char name[64];
|
||||
Macro *macro;
|
||||
|
@ -222,6 +222,7 @@ makelabel(char *name, Uint16 addr, Uint8 len, Macro *m)
|
|||
l = &labels[labelslen++];
|
||||
l->addr = addr;
|
||||
l->len = len;
|
||||
l->refs = 0;
|
||||
scpy(name, l->name, 64);
|
||||
if(m)
|
||||
l->macro = m;
|
||||
|
@ -246,9 +247,10 @@ makevariable(char *id, Uint16 *addr, FILE *f)
|
|||
Macro *m = NULL;
|
||||
fscanf(f, "%s", wv);
|
||||
origin = *addr;
|
||||
if((m = findmacro(wv)))
|
||||
if((m = findmacro(wv))) {
|
||||
len = m->size;
|
||||
else
|
||||
m->refs++;
|
||||
} else
|
||||
len = shex(wv);
|
||||
*addr += len;
|
||||
return makelabel(id, origin, len, m);
|
||||
|
@ -349,17 +351,29 @@ 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) == 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] == '=' && (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(findlabeladdr(w+1), 1); pushbyte(findopcode(findlabellen(w+1) == 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 ? "STR2" : "STR"), 0); l->refs++;}
|
||||
else if(w[0] == '~' && (l = findlabel(w + 1)) && l->len){ pushshort(findlabeladdr(w+1), 1); pushbyte(findopcode(findlabellen(w+1) == 2 ? "LDR2" : "LDR"), 0); l->refs++;}
|
||||
else if(w[0] == '=' && sihx(w + 1)) { pushshort(shex(w + 1), 1); pushbyte(findopcode("STR2"), 0); }
|
||||
else if(w[0] == '~' && sihx(w + 1)) { pushshort(shex(w + 1), 1); pushbyte(findopcode("LDR2"), 0); }
|
||||
else if((l = findlabel(w + 1))) pushshort(findlabeladdr(w+1), w[0] == ',');
|
||||
else if((l = findlabel(w + 1))) { pushshort(findlabeladdr(w+1), w[0] == ','); l->refs++; }
|
||||
else return error("Unknown label in second pass", w);
|
||||
/* clang-format on */
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < labelslen; ++i)
|
||||
if(!labels[i].refs)
|
||||
printf("--- Unused label: %s\n", labels[i].name);
|
||||
for(i = 0; i < macroslen; ++i)
|
||||
if(!macros[i].refs)
|
||||
printf("--- Unused macro: %s\n", macros[i].name);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -373,5 +387,6 @@ main(int argc, char *argv[])
|
|||
fwrite(p.data, sizeof(p.data), 1, fopen(argv[2], "wb"));
|
||||
fclose(f);
|
||||
printf("Assembled %s.\n\n", argv[2]);
|
||||
cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
|
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 examples/gui.hover.usm bin/boot.rom
|
||||
./bin/assembler examples/dev.mouse.usm bin/boot.rom
|
||||
./bin/emulator bin/boot.rom
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
;label Label2d
|
||||
;cat Point2d
|
||||
;mouse Point2d
|
||||
;pos Point2d
|
||||
;color 1
|
||||
;timer 1
|
||||
|
||||
|
@ -106,9 +105,7 @@ RTS
|
|||
@animate-polycat-tail-next2
|
||||
( look-at )
|
||||
~mouse.x ~cat.x #0008 ADD2 GTH2 ,animate-polycat-right ROT JMP? POP2
|
||||
@animate-polycat-left
|
||||
~mouse.y ~cat.y #0008 ADD2 GTH2 ,animate-polycat-left-down ROT JMP? POP2
|
||||
@animate-polycat-left-up
|
||||
,polycat #0040 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
|
||||
,polycat #0050 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
|
||||
RTS
|
||||
|
@ -118,7 +115,6 @@ RTS
|
|||
RTS
|
||||
@animate-polycat-right
|
||||
~mouse.y ~cat.y #0008 ADD2 GTH2 ,animate-polycat-right-down ROT JMP? POP2
|
||||
@animate-polycat-right-up
|
||||
,polycat #0060 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
|
||||
,polycat #0070 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
|
||||
RTS
|
||||
|
@ -217,9 +213,6 @@ RTS
|
|||
0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
|
||||
]
|
||||
|
||||
@chord0_text [ no chord ] <1 .00
|
||||
@chord1_text [ chord 1_ ] <1 .00
|
||||
@chord2_text [ chord _2 ] <1 .00
|
||||
@mouse0_text [ no click ] <1 .00
|
||||
@mouse1_text [ mouse 1_ ] <1 .00
|
||||
@mouse2_text [ mouse _2 ] <1 .00
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
&Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
||||
&Mouse { x 2 y 2 state 1 chord 1 }
|
||||
|
||||
&Label2d { x 2 y 2 color 1 addr 2 }
|
||||
&Picture2d { x 2 y 2 width 2 height 2 color 1 addr 2 }
|
||||
&Rect2d { x1 2 y1 2 x2 2 y2 2 }
|
||||
&Point2d { x 2 y 2 }
|
||||
|
||||
|
@ -95,11 +93,9 @@ RTS
|
|||
RTS
|
||||
|
||||
@clear_icn [ 0000 0000 0000 0000 ]
|
||||
@pointer_icn [ 80c0 e0f0 f8e0 1000 ]
|
||||
@pointer_icn [ 80c0 e0f0 f8e0 1000 ]
|
||||
@hand_icn [ 4040 4070 f8f8 f870 ]
|
||||
|
||||
@text [ Label Text ] <1 .00 ( add characters to memory )
|
||||
|
||||
|d000 @ERROR BRK
|
||||
|
||||
|FF10 ;dev/screen Screen
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
&Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
||||
|
||||
&Picture2d { x 2 y 2 width 2 height 2 color 1 addr 2 }
|
||||
&Point2d { x 2 y 2 }
|
||||
|
||||
;pict Picture2d
|
||||
|
||||
|
|
|
@ -6,13 +6,12 @@
|
|||
&Label2d { x 2 y 2 color 1 addr 2 }
|
||||
&Picture2d { x 2 y 2 width 2 height 2 color 1 addr 2 }
|
||||
&Rect2d { x1 2 y1 2 x2 2 y2 2 }
|
||||
&Point2d { x 2 y 2 }
|
||||
|
||||
;label Label2d
|
||||
;pict Picture2d
|
||||
;rect Rect2d
|
||||
|
||||
;color 1 ;x1 2 ;x2 2 ;y1 2 ;y2 2
|
||||
;color 1
|
||||
|
||||
|0100 @RESET
|
||||
|
||||
|
|
Loading…
Reference in a new issue