Reimplementation of patch sent in by Marc Schraffenberger
<marc@schraffenberger.com>: thank you for the rationale and inspiration!
... | ... |
@@ -1,4 +1,3 @@ |
1 |
-#include <stdio.h> |
|
2 | 1 |
#include "uxn.h" |
3 | 2 |
|
4 | 3 |
/* |
... | ... |
@@ -35,18 +34,6 @@ Uint16 mempeek16(Uint8 *m, Uint16 a) { return (mempeek8(m, a) << 8) + mempeek8(m |
35 | 34 |
void devpoke16(Device *d, Uint8 a, Uint16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); } |
36 | 35 |
Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); } |
37 | 36 |
|
38 |
-#ifndef NO_STACK_CHECKS |
|
39 |
-static const char *errors[] = {"underflow", "overflow", "division by zero"}; |
|
40 |
- |
|
41 |
-int |
|
42 |
-haltuxn(Uxn *u, Uint8 error, char *name, int id) |
|
43 |
-{ |
|
44 |
- fprintf(stderr, "Halted: %s %s#%04x, at 0x%04x\n", name, errors[error - 1], id, u->ram.ptr); |
|
45 |
- u->ram.ptr = 0; |
|
46 |
- return 0; |
|
47 |
-} |
|
48 |
-#endif |
|
49 |
- |
|
50 | 37 |
/* clang-format on */ |
51 | 38 |
|
52 | 39 |
#pragma mark - Core |
... | ... |
@@ -1,4 +1,3 @@ |
1 |
-#include <stdio.h> |
|
2 | 1 |
#include "uxn.h" |
3 | 2 |
|
4 | 3 |
/* |
... | ... |
@@ -117,16 +116,6 @@ void (*ops[])(Uxn *u) = { |
117 | 116 |
|
118 | 117 |
#pragma mark - Core |
119 | 118 |
|
120 |
-static const char *errors[] = {"underflow", "overflow", "division by zero"}; |
|
121 |
- |
|
122 |
-int |
|
123 |
-haltuxn(Uxn *u, Uint8 error, char *name, int id) |
|
124 |
-{ |
|
125 |
- fprintf(stderr, "Halted: %s %s#%04x, at 0x%04x\n", name, errors[error - 1], id, u->ram.ptr); |
|
126 |
- u->ram.ptr = 0; |
|
127 |
- return 0; |
|
128 |
-} |
|
129 |
- |
|
130 | 119 |
void |
131 | 120 |
opcuxn(Uxn *u, Uint8 instr) |
132 | 121 |
{ |
... | ... |
@@ -171,24 +160,13 @@ evaluxn(Uxn *u, Uint16 vec) |
171 | 160 |
int |
172 | 161 |
bootuxn(Uxn *u) |
173 | 162 |
{ |
174 |
- size_t i; |
|
163 |
+ unsigned int i; |
|
175 | 164 |
char *cptr = (char *)u; |
176 | 165 |
for(i = 0; i < sizeof(*u); i++) |
177 | 166 |
cptr[i] = 0; |
178 | 167 |
return 1; |
179 | 168 |
} |
180 | 169 |
|
181 |
-int |
|
182 |
-loaduxn(Uxn *u, char *filepath) |
|
183 |
-{ |
|
184 |
- FILE *f; |
|
185 |
- if(!(f = fopen(filepath, "rb"))) |
|
186 |
- return 0; |
|
187 |
- fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f); |
|
188 |
- fprintf(stderr, "Uxn loaded[%s].\n", filepath); |
|
189 |
- return 1; |
|
190 |
-} |
|
191 |
- |
|
192 | 170 |
Device * |
193 | 171 |
portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 w)) |
194 | 172 |
{ |
... | ... |
@@ -197,6 +175,6 @@ portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 |
197 | 175 |
d->u = u; |
198 | 176 |
d->mem = u->ram.dat; |
199 | 177 |
d->talk = talkfn; |
200 |
- fprintf(stderr, "Device added #%02x: %s, at 0x%04x \n", id, name, d->addr); |
|
178 |
+ (void)name; |
|
201 | 179 |
return d; |
202 | 180 |
} |
... | ... |
@@ -43,7 +43,7 @@ struct Uxn; |
43 | 43 |
void mempoke16(Uint8 *m, Uint16 a, Uint16 b); |
44 | 44 |
Uint16 mempeek16(Uint8 *m, Uint16 a); |
45 | 45 |
|
46 |
-int loaduxn(Uxn *c, char *filepath); |
|
47 | 46 |
int bootuxn(Uxn *c); |
48 | 47 |
int evaluxn(Uxn *u, Uint16 vec); |
48 |
+int haltuxn(Uxn *u, Uint8 error, char *name, int id); |
|
49 | 49 |
Device *portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *, Uint8, Uint8)); |
... | ... |
@@ -111,6 +111,16 @@ nil_talk(Device *d, Uint8 b0, Uint8 w) |
111 | 111 |
|
112 | 112 |
#pragma mark - Generics |
113 | 113 |
|
114 |
+static const char *errors[] = {"underflow", "overflow", "division by zero"}; |
|
115 |
+ |
|
116 |
+int |
|
117 |
+haltuxn(Uxn *u, Uint8 error, char *name, int id) |
|
118 |
+{ |
|
119 |
+ fprintf(stderr, "Halted: %s %s#%04x, at 0x%04x\n", name, errors[error - 1], id, u->ram.ptr); |
|
120 |
+ u->ram.ptr = 0; |
|
121 |
+ return 0; |
|
122 |
+} |
|
123 |
+ |
|
114 | 124 |
static void |
115 | 125 |
run(Uxn *u) |
116 | 126 |
{ |
... | ... |
@@ -121,6 +131,17 @@ run(Uxn *u) |
121 | 131 |
evaluxn(u, mempeek16(devconsole->dat, 0)); |
122 | 132 |
} |
123 | 133 |
|
134 |
+static int |
|
135 |
+loaduxn(Uxn *u, char *filepath) |
|
136 |
+{ |
|
137 |
+ FILE *f; |
|
138 |
+ if(!(f = fopen(filepath, "rb"))) |
|
139 |
+ return 0; |
|
140 |
+ fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f); |
|
141 |
+ fprintf(stderr, "Uxn loaded[%s].\n", filepath); |
|
142 |
+ return 1; |
|
143 |
+} |
|
144 |
+ |
|
124 | 145 |
int |
125 | 146 |
main(int argc, char **argv) |
126 | 147 |
{ |
... | ... |
@@ -411,6 +411,16 @@ stdin_handler(void *p) |
411 | 411 |
(void)p; |
412 | 412 |
} |
413 | 413 |
|
414 |
+static const char *errors[] = {"underflow", "overflow", "division by zero"}; |
|
415 |
+ |
|
416 |
+int |
|
417 |
+haltuxn(Uxn *u, Uint8 error, char *name, int id) |
|
418 |
+{ |
|
419 |
+ fprintf(stderr, "Halted: %s %s#%04x, at 0x%04x\n", name, errors[error - 1], id, u->ram.ptr); |
|
420 |
+ u->ram.ptr = 0; |
|
421 |
+ return 0; |
|
422 |
+} |
|
423 |
+ |
|
414 | 424 |
static void |
415 | 425 |
run(Uxn *u) |
416 | 426 |
{ |
... | ... |
@@ -465,6 +475,17 @@ run(Uxn *u) |
465 | 475 |
} |
466 | 476 |
} |
467 | 477 |
|
478 |
+static int |
|
479 |
+loaduxn(Uxn *u, char *filepath) |
|
480 |
+{ |
|
481 |
+ FILE *f; |
|
482 |
+ if(!(f = fopen(filepath, "rb"))) |
|
483 |
+ return 0; |
|
484 |
+ fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f); |
|
485 |
+ fprintf(stderr, "Uxn loaded[%s].\n", filepath); |
|
486 |
+ return 1; |
|
487 |
+} |
|
488 |
+ |
|
468 | 489 |
int |
469 | 490 |
main(int argc, char **argv) |
470 | 491 |
{ |