uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit fa6b8a176931a08f1f9cb700af758ddeda1ccfde
parent c5b8595fb50876007fbeb486d0fb82af2e25e7c3
Author: neauoire <aliceffekt@gmail.com>
Date:   Sat, 24 Jul 2021 17:09:46 -0700

Improved error messages

Diffstat:
Msrc/uxn-fast.c | 4+---
Msrc/uxn.c | 4+---
Msrc/uxnasm.c | 10+++++-----
Msrc/uxnemu.c | 24+++++++++++-------------
4 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/src/uxn-fast.c b/src/uxn-fast.c @@ -4052,10 +4052,8 @@ int loaduxn(Uxn *u, char *filepath) { FILE *f; - if(!(f = fopen(filepath, "rb"))) { - fprintf(stderr, "Halted: Missing input rom.\n"); + if(!(f = fopen(filepath, "rb"))) return 0; - } fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f); fprintf(stderr, "Uxn loaded[%s].\n", filepath); return 1; diff --git a/src/uxn.c b/src/uxn.c @@ -180,10 +180,8 @@ int loaduxn(Uxn *u, char *filepath) { FILE *f; - if(!(f = fopen(filepath, "rb"))) { - fprintf(stderr, "Halted: Missing input rom.\n"); + if(!(f = fopen(filepath, "rb"))) return 0; - } fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f); fprintf(stderr, "Uxn loaded[%s].\n", filepath); return 1; diff --git a/src/uxnasm.c b/src/uxnasm.c @@ -137,9 +137,9 @@ sublabel(char *src, char *scope, char *name) #pragma mark - Parser static int -error(char *name, char *id) +error(char *name, char *msg) { - fprintf(stderr, "Error: %s[%s]\n", name, id); + fprintf(stderr, "%s: %s\n", name, msg); return 0; } @@ -366,11 +366,11 @@ main(int argc, char *argv[]) { FILE *f; if(argc < 3) - return !error("Usage", "input.tal output.rom"); + return !error("usage", "input.tal output.rom"); if(!(f = fopen(argv[1], "r"))) - return !error("Open", "Failed"); + return !error("Load", "Failed to open source."); if(!pass1(f) || !pass2(f)) - return !error("Assembly", "Failed"); + return !error("Assembly", "Failed to assemble rom."); fwrite(p.data + TRIM, p.length - TRIM, 1, fopen(argv[2], "wb")); fclose(f); cleanup(argv[2]); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -44,7 +44,7 @@ clamp(int val, int min, int max) static int error(char *msg, const char *err) { - fprintf(stderr, "Error %s: %s\n", msg, err); + fprintf(stderr, "%s: %s\n", msg, err); return 0; } @@ -130,26 +130,26 @@ init(void) { SDL_AudioSpec as; if(!initppu(&ppu, 64, 40)) - return error("PPU", "Init failure"); + return error("ppu", "Init failure"); gRect.x = PAD; gRect.y = PAD; gRect.w = ppu.width; gRect.h = ppu.height; if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) - return error("Init", SDL_GetError()); + return error("sdl", SDL_GetError()); gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom, SDL_WINDOW_SHOWN); if(gWindow == NULL) - return error("Window", SDL_GetError()); + return error("sdl_window", SDL_GetError()); gRenderer = SDL_CreateRenderer(gWindow, -1, 0); if(gRenderer == NULL) - return error("Renderer", SDL_GetError()); + return error("sdl_renderer", SDL_GetError()); SDL_RenderSetLogicalSize(gRenderer, ppu.width + PAD * 2, ppu.height + PAD * 2); bgTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2); if(bgTexture == NULL || SDL_SetTextureBlendMode(bgTexture, SDL_BLENDMODE_NONE)) - return error("Texture", SDL_GetError()); + return error("sdl_texture", SDL_GetError()); fgTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2); if(fgTexture == NULL || SDL_SetTextureBlendMode(fgTexture, SDL_BLENDMODE_BLEND)) - return error("Texture", SDL_GetError()); + return error("sdl_texture", SDL_GetError()); SDL_UpdateTexture(bgTexture, NULL, ppu.bg.pixels, 4); SDL_UpdateTexture(fgTexture, NULL, ppu.fg.pixels, 4); SDL_StartTextInput(); @@ -163,7 +163,7 @@ init(void) as.userdata = NULL; audio_id = SDL_OpenAudioDevice(NULL, 0, &as, NULL, 0); if(!audio_id) - return error("Audio", SDL_GetError()); + return error("sdl_audio", SDL_GetError()); return 1; } @@ -409,13 +409,11 @@ main(int argc, char **argv) SDL_CreateThread(stdin_handler, "stdin", NULL); if(argc < 2) - return error("Input", "usage: uxnemu file.rom"); - if(!bootuxn(&u)) - return error("Boot", "Failed"); + return error("usage", "uxnemu file.rom"); if(!loaduxn(&u, argv[1])) - return error("Load", "Failed"); + return error("Load", "Failed to open rom."); if(!init()) - return error("Init", "Failed"); + return error("Init", "Failed to initialize emulator."); portuxn(&u, 0x0, "system", system_talk); devconsole = portuxn(&u, 0x1, "console", console_talk);