Browse code

Improved error messages

neauoire authored on 25/07/2021 00:09:46
Showing 4 changed files
... ...
@@ -4052,10 +4052,8 @@ int
4052 4052
 loaduxn(Uxn *u, char *filepath)
4053 4053
 {
4054 4054
 	FILE *f;
4055
-	if(!(f = fopen(filepath, "rb"))) {
4056
-		fprintf(stderr, "Halted: Missing input rom.\n");
4055
+	if(!(f = fopen(filepath, "rb"))) 
4057 4056
 		return 0;
4058
-	}
4059 4057
 	fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f);
4060 4058
 	fprintf(stderr, "Uxn loaded[%s].\n", filepath);
4061 4059
 	return 1;
... ...
@@ -180,10 +180,8 @@ int
180 180
 loaduxn(Uxn *u, char *filepath)
181 181
 {
182 182
 	FILE *f;
183
-	if(!(f = fopen(filepath, "rb"))) {
184
-		fprintf(stderr, "Halted: Missing input rom.\n");
183
+	if(!(f = fopen(filepath, "rb")))
185 184
 		return 0;
186
-	}
187 185
 	fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f);
188 186
 	fprintf(stderr, "Uxn loaded[%s].\n", filepath);
189 187
 	return 1;
... ...
@@ -137,9 +137,9 @@ sublabel(char *src, char *scope, char *name)
137 137
 #pragma mark - Parser
138 138
 
139 139
 static int
140
-error(char *name, char *id)
140
+error(char *name, char *msg)
141 141
 {
142
-	fprintf(stderr, "Error: %s[%s]\n", name, id);
142
+	fprintf(stderr, "%s: %s\n", name, msg);
143 143
 	return 0;
144 144
 }
145 145
 
... ...
@@ -366,11 +366,11 @@ main(int argc, char *argv[])
366 366
 {
367 367
 	FILE *f;
368 368
 	if(argc < 3)
369
-		return !error("Usage", "input.tal output.rom");
369
+		return !error("usage", "input.tal output.rom");
370 370
 	if(!(f = fopen(argv[1], "r")))
371
-		return !error("Open", "Failed");
371
+		return !error("Load", "Failed to open source.");
372 372
 	if(!pass1(f) || !pass2(f))
373
-		return !error("Assembly", "Failed");
373
+		return !error("Assembly", "Failed to assemble rom.");
374 374
 	fwrite(p.data + TRIM, p.length - TRIM, 1, fopen(argv[2], "wb"));
375 375
 	fclose(f);
376 376
 	cleanup(argv[2]);
... ...
@@ -44,7 +44,7 @@ clamp(int val, int min, int max)
44 44
 static int
45 45
 error(char *msg, const char *err)
46 46
 {
47
-	fprintf(stderr, "Error %s: %s\n", msg, err);
47
+	fprintf(stderr, "%s: %s\n", msg, err);
48 48
 	return 0;
49 49
 }
50 50
 
... ...
@@ -130,26 +130,26 @@ init(void)
130 130
 {
131 131
 	SDL_AudioSpec as;
132 132
 	if(!initppu(&ppu, 64, 40))
133
-		return error("PPU", "Init failure");
133
+		return error("ppu", "Init failure");
134 134
 	gRect.x = PAD;
135 135
 	gRect.y = PAD;
136 136
 	gRect.w = ppu.width;
137 137
 	gRect.h = ppu.height;
138 138
 	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
139
-		return error("Init", SDL_GetError());
139
+		return error("sdl", SDL_GetError());
140 140
 	gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom, SDL_WINDOW_SHOWN);
141 141
 	if(gWindow == NULL)
142
-		return error("Window", SDL_GetError());
142
+		return error("sdl_window", SDL_GetError());
143 143
 	gRenderer = SDL_CreateRenderer(gWindow, -1, 0);
144 144
 	if(gRenderer == NULL)
145
-		return error("Renderer", SDL_GetError());
145
+		return error("sdl_renderer", SDL_GetError());
146 146
 	SDL_RenderSetLogicalSize(gRenderer, ppu.width + PAD * 2, ppu.height + PAD * 2);
147 147
 	bgTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2);
148 148
 	if(bgTexture == NULL || SDL_SetTextureBlendMode(bgTexture, SDL_BLENDMODE_NONE))
149
-		return error("Texture", SDL_GetError());
149
+		return error("sdl_texture", SDL_GetError());
150 150
 	fgTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2);
151 151
 	if(fgTexture == NULL || SDL_SetTextureBlendMode(fgTexture, SDL_BLENDMODE_BLEND))
152
-		return error("Texture", SDL_GetError());
152
+		return error("sdl_texture", SDL_GetError());
153 153
 	SDL_UpdateTexture(bgTexture, NULL, ppu.bg.pixels, 4);
154 154
 	SDL_UpdateTexture(fgTexture, NULL, ppu.fg.pixels, 4);
155 155
 	SDL_StartTextInput();
... ...
@@ -163,7 +163,7 @@ init(void)
163 163
 	as.userdata = NULL;
164 164
 	audio_id = SDL_OpenAudioDevice(NULL, 0, &as, NULL, 0);
165 165
 	if(!audio_id)
166
-		return error("Audio", SDL_GetError());
166
+		return error("sdl_audio", SDL_GetError());
167 167
 	return 1;
168 168
 }
169 169
 
... ...
@@ -409,13 +409,11 @@ main(int argc, char **argv)
409 409
 	SDL_CreateThread(stdin_handler, "stdin", NULL);
410 410
 
411 411
 	if(argc < 2)
412
-		return error("Input", "usage: uxnemu file.rom");
413
-	if(!bootuxn(&u))
414
-		return error("Boot", "Failed");
412
+		return error("usage", "uxnemu file.rom");
415 413
 	if(!loaduxn(&u, argv[1]))
416
-		return error("Load", "Failed");
414
+		return error("Load", "Failed to open rom.");
417 415
 	if(!init())
418
-		return error("Init", "Failed");
416
+		return error("Init", "Failed to initialize emulator.");
419 417
 
420 418
 	portuxn(&u, 0x0, "system", system_talk);
421 419
 	devconsole = portuxn(&u, 0x1, "console", console_talk);