... | ... |
@@ -17,17 +17,17 @@ typedef unsigned short Uint16; |
17 | 17 |
typedef signed short Sint16; |
18 | 18 |
|
19 | 19 |
typedef struct { |
20 |
- int ptr; |
|
21 |
- Uint8 data[65536]; |
|
20 |
+ Uint8 data[256 * 256]; |
|
21 |
+ Uint16 ptr; |
|
22 | 22 |
} Program; |
23 | 23 |
|
24 | 24 |
typedef struct { |
25 |
+ Uint8 len, length[16], size, refs; |
|
25 | 26 |
char name[64], params[16][64]; |
26 |
- Uint8 len, length[16], size; |
|
27 | 27 |
} Macro; |
28 | 28 |
|
29 | 29 |
typedef struct { |
30 |
- Uint8 len, offset; |
|
30 |
+ Uint8 len, offset, refs; |
|
31 | 31 |
Uint16 addr; |
32 | 32 |
char name[64]; |
33 | 33 |
Macro *macro; |
... | ... |
@@ -222,6 +222,7 @@ makelabel(char *name, Uint16 addr, Uint8 len, Macro *m) |
222 | 222 |
l = &labels[labelslen++]; |
223 | 223 |
l->addr = addr; |
224 | 224 |
l->len = len; |
225 |
+ l->refs = 0; |
|
225 | 226 |
scpy(name, l->name, 64); |
226 | 227 |
if(m) |
227 | 228 |
l->macro = m; |
... | ... |
@@ -246,9 +247,10 @@ makevariable(char *id, Uint16 *addr, FILE *f) |
246 | 247 |
Macro *m = NULL; |
247 | 248 |
fscanf(f, "%s", wv); |
248 | 249 |
origin = *addr; |
249 |
- if((m = findmacro(wv))) |
|
250 |
+ if((m = findmacro(wv))) { |
|
250 | 251 |
len = m->size; |
251 |
- else |
|
252 |
+ m->refs++; |
|
253 |
+ } else |
|
252 | 254 |
len = shex(wv); |
253 | 255 |
*addr += len; |
254 | 256 |
return makelabel(id, origin, len, m); |
... | ... |
@@ -349,17 +351,29 @@ pass2(FILE *f) |
349 | 351 |
else if(w[0] == '+' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)shex(w + 1), 1); |
350 | 352 |
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 2) pushbyte((Sint8)(shex(w + 1) * -1), 1); |
351 | 353 |
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)(shex(w + 1) * -1), 1); |
352 |
- else if(w[0] == '=' && (l = findlabel(w + 1)) && l->len){ pushshort(findlabeladdr(w+1), 1); pushbyte(findopcode(findlabellen(w+1) == 2 ? "STR2" : "STR"), 0); } |
|
353 |
- else if(w[0] == '~' && (l = findlabel(w + 1)) && l->len){ pushshort(findlabeladdr(w+1), 1); pushbyte(findopcode(findlabellen(w+1) == 2 ? "LDR2" : "LDR"), 0); } |
|
354 |
+ 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++;} |
|
355 |
+ 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++;} |
|
354 | 356 |
else if(w[0] == '=' && sihx(w + 1)) { pushshort(shex(w + 1), 1); pushbyte(findopcode("STR2"), 0); } |
355 | 357 |
else if(w[0] == '~' && sihx(w + 1)) { pushshort(shex(w + 1), 1); pushbyte(findopcode("LDR2"), 0); } |
356 |
- else if((l = findlabel(w + 1))) pushshort(findlabeladdr(w+1), w[0] == ','); |
|
358 |
+ else if((l = findlabel(w + 1))) { pushshort(findlabeladdr(w+1), w[0] == ','); l->refs++; } |
|
357 | 359 |
else return error("Unknown label in second pass", w); |
358 | 360 |
/* clang-format on */ |
359 | 361 |
} |
360 | 362 |
return 1; |
361 | 363 |
} |
362 | 364 |
|
365 |
+void |
|
366 |
+cleanup(void) |
|
367 |
+{ |
|
368 |
+ int i; |
|
369 |
+ for(i = 0; i < labelslen; ++i) |
|
370 |
+ if(!labels[i].refs) |
|
371 |
+ printf("--- Unused label: %s\n", labels[i].name); |
|
372 |
+ for(i = 0; i < macroslen; ++i) |
|
373 |
+ if(!macros[i].refs) |
|
374 |
+ printf("--- Unused macro: %s\n", macros[i].name); |
|
375 |
+} |
|
376 |
+ |
|
363 | 377 |
int |
364 | 378 |
main(int argc, char *argv[]) |
365 | 379 |
{ |
... | ... |
@@ -373,5 +387,6 @@ main(int argc, char *argv[]) |
373 | 387 |
fwrite(p.data, sizeof(p.data), 1, fopen(argv[2], "wb")); |
374 | 388 |
fclose(f); |
375 | 389 |
printf("Assembled %s.\n\n", argv[2]); |
390 |
+ cleanup(); |
|
376 | 391 |
return 0; |
377 | 392 |
} |
... | ... |
@@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr |
20 | 20 |
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator |
21 | 21 |
|
22 | 22 |
# run |
23 |
-./bin/assembler examples/gui.hover.usm bin/boot.rom |
|
23 |
+./bin/assembler examples/dev.mouse.usm bin/boot.rom |
|
24 | 24 |
./bin/emulator bin/boot.rom |
... | ... |
@@ -10,7 +10,6 @@ |
10 | 10 |
;label Label2d |
11 | 11 |
;cat Point2d |
12 | 12 |
;mouse Point2d |
13 |
-;pos Point2d |
|
14 | 13 |
;color 1 |
15 | 14 |
;timer 1 |
16 | 15 |
|
... | ... |
@@ -106,9 +105,7 @@ RTS |
106 | 105 |
@animate-polycat-tail-next2 |
107 | 106 |
( look-at ) |
108 | 107 |
~mouse.x ~cat.x #0008 ADD2 GTH2 ,animate-polycat-right ROT JMP? POP2 |
109 |
- @animate-polycat-left |
|
110 | 108 |
~mouse.y ~cat.y #0008 ADD2 GTH2 ,animate-polycat-left-down ROT JMP? POP2 |
111 |
- @animate-polycat-left-up |
|
112 | 109 |
,polycat #0040 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR |
113 | 110 |
,polycat #0050 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR |
114 | 111 |
RTS |
... | ... |
@@ -118,7 +115,6 @@ RTS |
118 | 115 |
RTS |
119 | 116 |
@animate-polycat-right |
120 | 117 |
~mouse.y ~cat.y #0008 ADD2 GTH2 ,animate-polycat-right-down ROT JMP? POP2 |
121 |
- @animate-polycat-right-up |
|
122 | 118 |
,polycat #0060 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR |
123 | 119 |
,polycat #0070 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR |
124 | 120 |
RTS |
... | ... |
@@ -217,9 +213,6 @@ RTS |
217 | 213 |
0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c |
218 | 214 |
] |
219 | 215 |
|
220 |
-@chord0_text [ no chord ] <1 .00 |
|
221 |
-@chord1_text [ chord 1_ ] <1 .00 |
|
222 |
-@chord2_text [ chord _2 ] <1 .00 |
|
223 | 216 |
@mouse0_text [ no click ] <1 .00 |
224 | 217 |
@mouse1_text [ mouse 1_ ] <1 .00 |
225 | 218 |
@mouse2_text [ mouse _2 ] <1 .00 |
... | ... |
@@ -4,8 +4,6 @@ |
4 | 4 |
&Sprite { pad 8 x 2 y 2 addr 2 color 1 } |
5 | 5 |
&Mouse { x 2 y 2 state 1 chord 1 } |
6 | 6 |
|
7 |
-&Label2d { x 2 y 2 color 1 addr 2 } |
|
8 |
-&Picture2d { x 2 y 2 width 2 height 2 color 1 addr 2 } |
|
9 | 7 |
&Rect2d { x1 2 y1 2 x2 2 y2 2 } |
10 | 8 |
&Point2d { x 2 y 2 } |
11 | 9 |
|
... | ... |
@@ -95,11 +93,9 @@ RTS |
95 | 93 |
RTS |
96 | 94 |
|
97 | 95 |
@clear_icn [ 0000 0000 0000 0000 ] |
98 |
-@pointer_icn [ 80c0 e0f0 f8e0 1000 ] |
|
96 |
+@pointer_icn [ 80c0 e0f0 f8e0 1000 ] |
|
99 | 97 |
@hand_icn [ 4040 4070 f8f8 f870 ] |
100 | 98 |
|
101 |
-@text [ Label Text ] <1 .00 ( add characters to memory ) |
|
102 |
- |
|
103 | 99 |
|d000 @ERROR BRK |
104 | 100 |
|
105 | 101 |
|FF10 ;dev/screen Screen |
... | ... |
@@ -6,13 +6,12 @@ |
6 | 6 |
&Label2d { x 2 y 2 color 1 addr 2 } |
7 | 7 |
&Picture2d { x 2 y 2 width 2 height 2 color 1 addr 2 } |
8 | 8 |
&Rect2d { x1 2 y1 2 x2 2 y2 2 } |
9 |
-&Point2d { x 2 y 2 } |
|
10 | 9 |
|
11 | 10 |
;label Label2d |
12 | 11 |
;pict Picture2d |
13 | 12 |
;rect Rect2d |
14 | 13 |
|
15 |
-;color 1 ;x1 2 ;x2 2 ;y1 2 ;y2 2 |
|
14 |
+;color 1 |
|
16 | 15 |
|
17 | 16 |
|0100 @RESET |
18 | 17 |
|