Route errors to stderr

This commit is contained in:
neauoire 2021-06-26 13:22:01 -07:00
parent 4e8375d8df
commit 2197e35667
2 changed files with 8 additions and 8 deletions

View File

@ -122,7 +122,7 @@ static const char *errors[] = {"underflow", "overflow", "division by zero"};
int
haltuxn(Uxn *u, Uint8 error, char *name, int id)
{
printf("Halted: %s %s#%04x, at 0x%04x\n", name, errors[error - 1], id, u->ram.ptr);
fprintf(stderr, "Halted: %s %s#%04x, at 0x%04x\n", name, errors[error - 1], id, u->ram.ptr);
u->ram.ptr = 0;
return 0;
}
@ -180,11 +180,11 @@ loaduxn(Uxn *u, char *filepath)
{
FILE *f;
if(!(f = fopen(filepath, "rb"))) {
printf("Halted: Missing input rom.\n");
fprintf(stderr, "Halted: Missing input rom.\n");
return 0;
}
fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f);
printf("Uxn loaded[%s].\n", filepath);
fprintf(stderr, "Uxn loaded[%s].\n", filepath);
return 1;
}
@ -196,6 +196,6 @@ portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8
d->u = u;
d->mem = u->ram.dat;
d->talk = talkfn;
printf("Device added #%02x: %s, at 0x%04x \n", id, name, d->addr);
fprintf(stderr, "Device added #%02x: %s, at 0x%04x \n", id, name, d->addr);
return d;
}

View File

@ -38,7 +38,7 @@ clamp(int val, int min, int max)
int
error(char *msg, const char *err)
{
printf("Error %s: %s\n", msg, err);
fprintf(stderr, "Error %s: %s\n", msg, err);
return 0;
}
@ -93,7 +93,7 @@ screencapture(void)
SDL_RenderReadPixels(gRenderer, NULL, format, surface->pixels, surface->pitch);
SDL_SaveBMP(surface, "screenshot.bmp");
SDL_FreeSurface(surface);
printf("Saved screenshot.bmp\n");
fprintf(stderr, "Saved screenshot.bmp\n");
}
void
@ -269,10 +269,10 @@ file_talk(Device *d, Uint8 b0, Uint8 w)
Uint16 addr = mempeek16(d->dat, b0 - 1);
FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w"));
if(f) {
printf("%s %04x %s %s: ", read ? "Loading" : "Saving", addr, read ? "from" : "to", name);
fprintf(stderr, "%s %04x %s %s: ", read ? "Loading" : "Saving", addr, read ? "from" : "to", name);
if(fseek(f, offset, SEEK_SET) != -1)
result = read ? fread(&d->mem[addr], 1, length, f) : fwrite(&d->mem[addr], 1, length, f);
printf("%04x bytes\n", result);
fprintf(stderr, "%04x bytes\n", result);
fclose(f);
}
mempoke16(d->dat, 0x2, result);