Improved error messages
This commit is contained in:
parent
c5b8595fb5
commit
fa6b8a1769
|
@ -4052,10 +4052,8 @@ int
|
||||||
loaduxn(Uxn *u, char *filepath)
|
loaduxn(Uxn *u, char *filepath)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
if(!(f = fopen(filepath, "rb"))) {
|
if(!(f = fopen(filepath, "rb")))
|
||||||
fprintf(stderr, "Halted: Missing input rom.\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f);
|
fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f);
|
||||||
fprintf(stderr, "Uxn loaded[%s].\n", filepath);
|
fprintf(stderr, "Uxn loaded[%s].\n", filepath);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -180,10 +180,8 @@ int
|
||||||
loaduxn(Uxn *u, char *filepath)
|
loaduxn(Uxn *u, char *filepath)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
if(!(f = fopen(filepath, "rb"))) {
|
if(!(f = fopen(filepath, "rb")))
|
||||||
fprintf(stderr, "Halted: Missing input rom.\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f);
|
fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f);
|
||||||
fprintf(stderr, "Uxn loaded[%s].\n", filepath);
|
fprintf(stderr, "Uxn loaded[%s].\n", filepath);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
10
src/uxnasm.c
10
src/uxnasm.c
|
@ -137,9 +137,9 @@ sublabel(char *src, char *scope, char *name)
|
||||||
#pragma mark - Parser
|
#pragma mark - Parser
|
||||||
|
|
||||||
static int
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,11 +366,11 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
if(argc < 3)
|
if(argc < 3)
|
||||||
return !error("Usage", "input.tal output.rom");
|
return !error("usage", "input.tal output.rom");
|
||||||
if(!(f = fopen(argv[1], "r")))
|
if(!(f = fopen(argv[1], "r")))
|
||||||
return !error("Open", "Failed");
|
return !error("Load", "Failed to open source.");
|
||||||
if(!pass1(f) || !pass2(f))
|
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"));
|
fwrite(p.data + TRIM, p.length - TRIM, 1, fopen(argv[2], "wb"));
|
||||||
fclose(f);
|
fclose(f);
|
||||||
cleanup(argv[2]);
|
cleanup(argv[2]);
|
||||||
|
|
24
src/uxnemu.c
24
src/uxnemu.c
|
@ -44,7 +44,7 @@ clamp(int val, int min, int max)
|
||||||
static int
|
static int
|
||||||
error(char *msg, const char *err)
|
error(char *msg, const char *err)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error %s: %s\n", msg, err);
|
fprintf(stderr, "%s: %s\n", msg, err);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,26 +130,26 @@ init(void)
|
||||||
{
|
{
|
||||||
SDL_AudioSpec as;
|
SDL_AudioSpec as;
|
||||||
if(!initppu(&ppu, 64, 40))
|
if(!initppu(&ppu, 64, 40))
|
||||||
return error("PPU", "Init failure");
|
return error("ppu", "Init failure");
|
||||||
gRect.x = PAD;
|
gRect.x = PAD;
|
||||||
gRect.y = PAD;
|
gRect.y = PAD;
|
||||||
gRect.w = ppu.width;
|
gRect.w = ppu.width;
|
||||||
gRect.h = ppu.height;
|
gRect.h = ppu.height;
|
||||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
|
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);
|
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)
|
if(gWindow == NULL)
|
||||||
return error("Window", SDL_GetError());
|
return error("sdl_window", SDL_GetError());
|
||||||
gRenderer = SDL_CreateRenderer(gWindow, -1, 0);
|
gRenderer = SDL_CreateRenderer(gWindow, -1, 0);
|
||||||
if(gRenderer == NULL)
|
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);
|
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);
|
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))
|
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);
|
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))
|
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(bgTexture, NULL, ppu.bg.pixels, 4);
|
||||||
SDL_UpdateTexture(fgTexture, NULL, ppu.fg.pixels, 4);
|
SDL_UpdateTexture(fgTexture, NULL, ppu.fg.pixels, 4);
|
||||||
SDL_StartTextInput();
|
SDL_StartTextInput();
|
||||||
|
@ -163,7 +163,7 @@ init(void)
|
||||||
as.userdata = NULL;
|
as.userdata = NULL;
|
||||||
audio_id = SDL_OpenAudioDevice(NULL, 0, &as, NULL, 0);
|
audio_id = SDL_OpenAudioDevice(NULL, 0, &as, NULL, 0);
|
||||||
if(!audio_id)
|
if(!audio_id)
|
||||||
return error("Audio", SDL_GetError());
|
return error("sdl_audio", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,13 +409,11 @@ main(int argc, char **argv)
|
||||||
SDL_CreateThread(stdin_handler, "stdin", NULL);
|
SDL_CreateThread(stdin_handler, "stdin", NULL);
|
||||||
|
|
||||||
if(argc < 2)
|
if(argc < 2)
|
||||||
return error("Input", "usage: uxnemu file.rom");
|
return error("usage", "uxnemu file.rom");
|
||||||
if(!bootuxn(&u))
|
|
||||||
return error("Boot", "Failed");
|
|
||||||
if(!loaduxn(&u, argv[1]))
|
if(!loaduxn(&u, argv[1]))
|
||||||
return error("Load", "Failed");
|
return error("Load", "Failed to open rom.");
|
||||||
if(!init())
|
if(!init())
|
||||||
return error("Init", "Failed");
|
return error("Init", "Failed to initialize emulator.");
|
||||||
|
|
||||||
portuxn(&u, 0x0, "system", system_talk);
|
portuxn(&u, 0x0, "system", system_talk);
|
||||||
devconsole = portuxn(&u, 0x1, "console", console_talk);
|
devconsole = portuxn(&u, 0x1, "console", console_talk);
|
||||||
|
|
Loading…
Reference in New Issue