| ... | ... |
@@ -26,28 +26,39 @@ error(char *msg, const char *err) |
| 26 | 26 |
return 0; |
| 27 | 27 |
} |
| 28 | 28 |
|
| 29 |
+static void |
|
| 30 |
+inspect(Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) |
|
| 31 |
+{
|
|
| 32 |
+ Uint8 x, y; |
|
| 33 |
+ fprintf(stderr, "\n\n"); |
|
| 34 |
+ for(y = 0; y < 0x08; ++y) {
|
|
| 35 |
+ for(x = 0; x < 0x08; ++x) {
|
|
| 36 |
+ Uint8 p = y * 0x08 + x; |
|
| 37 |
+ fprintf(stderr, |
|
| 38 |
+ p == wptr ? "[%02x]" : " %02x ", |
|
| 39 |
+ stack[p]); |
|
| 40 |
+ } |
|
| 41 |
+ fprintf(stderr, "\n"); |
|
| 42 |
+ } |
|
| 43 |
+} |
|
| 44 |
+ |
|
| 29 | 45 |
#pragma mark - Devices |
| 30 | 46 |
|
| 31 | 47 |
static void |
| 32 | 48 |
system_talk(Device *d, Uint8 b0, Uint8 w) |
| 33 | 49 |
{
|
| 34 |
- if(!w) {
|
|
| 35 |
- d->dat[0x2] = d->u->wst.ptr; |
|
| 36 |
- d->dat[0x3] = d->u->rst.ptr; |
|
| 37 |
- } else if(b0 == 0xe) {
|
|
| 38 |
- Uint8 x, y; |
|
| 39 |
- fprintf(stderr, "\n\n"); |
|
| 40 |
- for(y = 0; y < 0x08; ++y) {
|
|
| 41 |
- for(x = 0; x < 0x08; ++x) {
|
|
| 42 |
- Uint8 p = y * 0x08 + x; |
|
| 43 |
- fprintf(stderr, |
|
| 44 |
- p == d->u->wst.ptr ? "[%02x]" : " %02x ", |
|
| 45 |
- d->u->wst.dat[p]); |
|
| 46 |
- } |
|
| 47 |
- fprintf(stderr, "\n"); |
|
| 50 |
+ if(!w) { /* read */
|
|
| 51 |
+ switch(b0) {
|
|
| 52 |
+ case 0x2: d->dat[0x2] = d->u->wst.ptr; break; |
|
| 53 |
+ case 0x3: d->dat[0x3] = d->u->rst.ptr; break; |
|
| 54 |
+ } |
|
| 55 |
+ } else { /* write */
|
|
| 56 |
+ switch(b0) {
|
|
| 57 |
+ case 0x2: d->u->wst.ptr = d->dat[0x2]; break; |
|
| 58 |
+ case 0x3: d->u->rst.ptr = d->dat[0x3]; break; |
|
| 59 |
+ case 0xf: d->u->ram.ptr = 0x0000; break; |
|
| 48 | 60 |
} |
| 49 |
- } else if(b0 == 0xf) |
|
| 50 |
- d->u->ram.ptr = 0x0000; |
|
| 61 |
+ } |
|
| 51 | 62 |
} |
| 52 | 63 |
|
| 53 | 64 |
static void |
| ... | ... |
@@ -120,11 +131,12 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id) |
| 120 | 131 |
static void |
| 121 | 132 |
run(Uxn *u) |
| 122 | 133 |
{
|
| 123 |
- if(!uxn_eval(u, PAGE_PROGRAM)) |
|
| 124 |
- error("Reset", "Failed");
|
|
| 125 |
- else if(mempeek16(devconsole->dat, 0)) |
|
| 126 |
- while(read(0, &devconsole->dat[0x2], 1) > 0) |
|
| 127 |
- uxn_eval(u, mempeek16(devconsole->dat, 0)); |
|
| 134 |
+ uxn_eval(u, PAGE_PROGRAM); |
|
| 135 |
+ while(read(0, &devconsole->dat[0x2], 1) > 0) {
|
|
| 136 |
+ if(devsystem->dat[0xe]) |
|
| 137 |
+ inspect(u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); |
|
| 138 |
+ uxn_eval(u, mempeek16(devconsole->dat, 0)); |
|
| 139 |
+ } |
|
| 128 | 140 |
} |
| 129 | 141 |
|
| 130 | 142 |
static int |
| ... | ... |
@@ -268,32 +268,44 @@ doctrl(Uxn *u, SDL_Event *event, int z) |
| 268 | 268 |
} else |
| 269 | 269 |
devctrl->dat[2] &= ~flag; |
| 270 | 270 |
} |
| 271 |
+static void |
|
| 272 |
+docolors(Device *d) |
|
| 273 |
+{
|
|
| 274 |
+ SDL_Color pal[16]; |
|
| 275 |
+ int i; |
|
| 276 |
+ for(i = 0; i < 4; ++i) {
|
|
| 277 |
+ pal[i].r = ((d->dat[0x8 + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; |
|
| 278 |
+ pal[i].g = ((d->dat[0xa + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; |
|
| 279 |
+ pal[i].b = ((d->dat[0xc + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; |
|
| 280 |
+ } |
|
| 281 |
+ for(i = 4; i < 16; ++i) {
|
|
| 282 |
+ pal[i].r = pal[i / 4].r; |
|
| 283 |
+ pal[i].g = pal[i / 4].g; |
|
| 284 |
+ pal[i].b = pal[i / 4].b; |
|
| 285 |
+ } |
|
| 286 |
+ SDL_SetPaletteColors(idxSurface->format->palette, pal, 0, 16); |
|
| 287 |
+ reqdraw = 1; |
|
| 288 |
+} |
|
| 271 | 289 |
|
| 272 | 290 |
#pragma mark - Devices |
| 273 | 291 |
|
| 274 | 292 |
static void |
| 275 | 293 |
system_talk(Device *d, Uint8 b0, Uint8 w) |
| 276 | 294 |
{
|
| 277 |
- if(!w) {
|
|
| 278 |
- d->dat[0x2] = d->u->wst.ptr; |
|
| 279 |
- d->dat[0x3] = d->u->rst.ptr; |
|
| 280 |
- } else if(b0 > 0x7 && b0 < 0xe) {
|
|
| 281 |
- SDL_Color pal[16]; |
|
| 282 |
- int i; |
|
| 283 |
- for(i = 0; i < 4; ++i) {
|
|
| 284 |
- pal[i].r = ((d->dat[0x8 + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; |
|
| 285 |
- pal[i].g = ((d->dat[0xa + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; |
|
| 286 |
- pal[i].b = ((d->dat[0xc + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; |
|
| 295 |
+ if(!w) { /* read */
|
|
| 296 |
+ switch(b0) {
|
|
| 297 |
+ case 0x2: d->dat[0x2] = d->u->wst.ptr; break; |
|
| 298 |
+ case 0x3: d->dat[0x3] = d->u->rst.ptr; break; |
|
| 287 | 299 |
} |
| 288 |
- for(i = 4; i < 16; ++i) {
|
|
| 289 |
- pal[i].r = pal[i / 4].r; |
|
| 290 |
- pal[i].g = pal[i / 4].g; |
|
| 291 |
- pal[i].b = pal[i / 4].b; |
|
| 300 |
+ } else { /* write */
|
|
| 301 |
+ switch(b0) {
|
|
| 302 |
+ case 0x2: d->u->wst.ptr = d->dat[0x2]; break; |
|
| 303 |
+ case 0x3: d->u->rst.ptr = d->dat[0x3]; break; |
|
| 304 |
+ case 0xf: d->u->ram.ptr = 0x0000; break; |
|
| 292 | 305 |
} |
| 293 |
- SDL_SetPaletteColors(idxSurface->format->palette, pal, 0, 16); |
|
| 294 |
- reqdraw = 1; |
|
| 295 |
- } else if(b0 == 0xf) |
|
| 296 |
- d->u->ram.ptr = 0x0000; |
|
| 306 |
+ if(b0 > 0x7 && b0 < 0xe) |
|
| 307 |
+ docolors(d); |
|
| 308 |
+ } |
|
| 297 | 309 |
} |
| 298 | 310 |
|
| 299 | 311 |
static void |
| ... | ... |
@@ -422,7 +434,7 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id) |
| 422 | 434 |
static void |
| 423 | 435 |
run(Uxn *u) |
| 424 | 436 |
{
|
| 425 |
- uxn_eval(u, 0x0100); |
|
| 437 |
+ uxn_eval(u, PAGE_PROGRAM); |
|
| 426 | 438 |
redraw(u); |
| 427 | 439 |
while(1) {
|
| 428 | 440 |
SDL_Event event; |