| ... | ... |
@@ -45,11 +45,12 @@ system_cmd(Uint8 *ram, Uint16 addr) |
| 45 | 45 |
} |
| 46 | 46 |
} |
| 47 | 47 |
|
| 48 |
-void |
|
| 49 |
-system_inspect(Uxn *u) |
|
| 48 |
+int |
|
| 49 |
+system_error(char *msg, const char *err) |
|
| 50 | 50 |
{
|
| 51 |
- system_print(&u->wst, "wst"); |
|
| 52 |
- system_print(&u->rst, "rst"); |
|
| 51 |
+ fprintf(stderr, "%s: %s\n", msg, err); |
|
| 52 |
+ fflush(stderr); |
|
| 53 |
+ return 0; |
|
| 53 | 54 |
} |
| 54 | 55 |
|
| 55 | 56 |
int |
| ... | ... |
@@ -66,6 +67,13 @@ system_load(Uxn *u, char *filename) |
| 66 | 67 |
return 1; |
| 67 | 68 |
} |
| 68 | 69 |
|
| 70 |
+void |
|
| 71 |
+system_inspect(Uxn *u) |
|
| 72 |
+{
|
|
| 73 |
+ system_print(&u->wst, "wst"); |
|
| 74 |
+ system_print(&u->rst, "rst"); |
|
| 75 |
+} |
|
| 76 |
+ |
|
| 69 | 77 |
/* IO */ |
| 70 | 78 |
|
| 71 | 79 |
void |
| ... | ... |
@@ -81,7 +89,7 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port) |
| 81 | 89 |
} |
| 82 | 90 |
} |
| 83 | 91 |
|
| 84 |
-/* Error */ |
|
| 92 |
+/* Errors */ |
|
| 85 | 93 |
|
| 86 | 94 |
int |
| 87 | 95 |
uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr) |
| ... | ... |
@@ -18,6 +18,7 @@ WITH REGARD TO THIS SOFTWARE. |
| 18 | 18 |
|
| 19 | 19 |
int system_load(Uxn *u, char *filename); |
| 20 | 20 |
void system_inspect(Uxn *u); |
| 21 |
+int system_error(char *msg, const char *err); |
|
| 21 | 22 |
void system_deo(Uxn *u, Uint8 *d, Uint8 port); |
| 22 | 23 |
int console_input(Uxn *u, char c, int type); |
| 23 | 24 |
void console_deo(Uint8 *d, Uint8 port); |
| ... | ... |
@@ -20,13 +20,6 @@ WITH REGARD TO THIS SOFTWARE. |
| 20 | 20 |
Uint16 deo_mask[] = {0x6a08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
|
| 21 | 21 |
Uint16 dei_mask[] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
|
| 22 | 22 |
|
| 23 |
-static int |
|
| 24 |
-emu_error(char *msg, const char *err) |
|
| 25 |
-{
|
|
| 26 |
- fprintf(stderr, "Error %s: %s\n", msg, err); |
|
| 27 |
- return 1; |
|
| 28 |
-} |
|
| 29 |
- |
|
| 30 | 23 |
Uint8 |
| 31 | 24 |
uxn_dei(Uxn *u, Uint8 addr) |
| 32 | 25 |
{
|
| ... | ... |
@@ -54,11 +47,11 @@ main(int argc, char **argv) |
| 54 | 47 |
Uxn u; |
| 55 | 48 |
int i = 1; |
| 56 | 49 |
if(i == argc) |
| 57 |
- return emu_error("Usage", "uxncli game.rom args");
|
|
| 50 |
+ return system_error("usage", "uxncli game.rom args");
|
|
| 58 | 51 |
if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)))) |
| 59 |
- return emu_error("Boot", "Failed");
|
|
| 52 |
+ return system_error("Boot", "Failed");
|
|
| 60 | 53 |
if(!system_load(&u, argv[i++])) |
| 61 |
- return emu_error("Load", "Failed");
|
|
| 54 |
+ return system_error("Load", "Failed");
|
|
| 62 | 55 |
if(i == argc) |
| 63 | 56 |
u.dev[0x17] = CONSOLE_END; |
| 64 | 57 |
if(!uxn_eval(&u, PAGE_PROGRAM)) |
| ... | ... |
@@ -63,14 +63,6 @@ static Uint64 exec_deadline, deadline_interval, ms_interval; |
| 63 | 63 |
|
| 64 | 64 |
char *rom_path; |
| 65 | 65 |
|
| 66 |
-static int |
|
| 67 |
-error(char *msg, const char *err) |
|
| 68 |
-{
|
|
| 69 |
- fprintf(stderr, "%s: %s\n", msg, err); |
|
| 70 |
- fflush(stderr); |
|
| 71 |
- return 0; |
|
| 72 |
-} |
|
| 73 |
- |
|
| 74 | 66 |
static int |
| 75 | 67 |
clamp(int val, int min, int max) |
| 76 | 68 |
{
|
| ... | ... |
@@ -192,9 +184,9 @@ set_size(void) |
| 192 | 184 |
SDL_RenderSetLogicalSize(gRenderer, uxn_screen.width + PAD * 2, uxn_screen.height + PAD * 2); |
| 193 | 185 |
gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC, uxn_screen.width, uxn_screen.height); |
| 194 | 186 |
if(gTexture == NULL || SDL_SetTextureBlendMode(gTexture, SDL_BLENDMODE_NONE)) |
| 195 |
- return error("gTexture", SDL_GetError());
|
|
| 187 |
+ return system_error("gTexture", SDL_GetError());
|
|
| 196 | 188 |
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0) |
| 197 |
- return error("SDL_UpdateTexture", SDL_GetError());
|
|
| 189 |
+ return system_error("SDL_UpdateTexture", SDL_GetError());
|
|
| 198 | 190 |
set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom); |
| 199 | 191 |
return 1; |
| 200 | 192 |
} |
| ... | ... |
@@ -205,7 +197,7 @@ redraw(void) |
| 205 | 197 |
if(gRect.w != uxn_screen.width || gRect.h != uxn_screen.height) set_size(); |
| 206 | 198 |
screen_redraw(&uxn_screen); |
| 207 | 199 |
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0) |
| 208 |
- error("SDL_UpdateTexture", SDL_GetError());
|
|
| 200 |
+ system_error("SDL_UpdateTexture", SDL_GetError());
|
|
| 209 | 201 |
SDL_RenderClear(gRenderer); |
| 210 | 202 |
SDL_RenderCopy(gRenderer, gTexture, NULL, &gRect); |
| 211 | 203 |
SDL_RenderPresent(gRenderer); |
| ... | ... |
@@ -223,19 +215,19 @@ init(void) |
| 223 | 215 |
as.samples = 512; |
| 224 | 216 |
as.userdata = NULL; |
| 225 | 217 |
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) |
| 226 |
- return error("sdl", SDL_GetError());
|
|
| 218 |
+ return system_error("sdl", SDL_GetError());
|
|
| 227 | 219 |
gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (WIDTH + PAD * 2) * zoom, (HEIGHT + PAD * 2) * zoom, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
| 228 | 220 |
if(gWindow == NULL) |
| 229 |
- return error("sdl_window", SDL_GetError());
|
|
| 221 |
+ return system_error("sdl_window", SDL_GetError());
|
|
| 230 | 222 |
gRenderer = SDL_CreateRenderer(gWindow, -1, 0); |
| 231 | 223 |
if(gRenderer == NULL) |
| 232 |
- return error("sdl_renderer", SDL_GetError());
|
|
| 224 |
+ return system_error("sdl_renderer", SDL_GetError());
|
|
| 233 | 225 |
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xff); |
| 234 | 226 |
audio_id = SDL_OpenAudioDevice(NULL, 0, &as, NULL, 0); |
| 235 | 227 |
if(!audio_id) |
| 236 |
- error("sdl_audio", SDL_GetError());
|
|
| 228 |
+ system_error("sdl_audio", SDL_GetError());
|
|
| 237 | 229 |
if(SDL_NumJoysticks() > 0 && SDL_JoystickOpen(0) == NULL) |
| 238 |
- error("sdl_joystick", SDL_GetError());
|
|
| 230 |
+ system_error("sdl_joystick", SDL_GetError());
|
|
| 239 | 231 |
stdin_event = SDL_RegisterEvents(1); |
| 240 | 232 |
audio0_event = SDL_RegisterEvents(POLYPHONY); |
| 241 | 233 |
SDL_DetachThread(stdin_thread = SDL_CreateThread(stdin_handler, "stdin", NULL)); |
| ... | ... |
@@ -256,12 +248,12 @@ start(Uxn *u, char *rom) |
| 256 | 248 |
{
|
| 257 | 249 |
free(u->ram); |
| 258 | 250 |
if(!uxn_boot(u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)))) |
| 259 |
- return error("Boot", "Failed to start uxn.");
|
|
| 251 |
+ return system_error("Boot", "Failed to start uxn.");
|
|
| 260 | 252 |
if(!system_load(u, rom)) |
| 261 |
- return error("Boot", "Failed to load rom.");
|
|
| 253 |
+ return system_error("Boot", "Failed to load rom.");
|
|
| 262 | 254 |
exec_deadline = SDL_GetPerformanceCounter() + deadline_interval; |
| 263 | 255 |
if(!uxn_eval(u, PAGE_PROGRAM)) |
| 264 |
- return error("Boot", "Failed to eval rom.");
|
|
| 256 |
+ return system_error("Boot", "Failed to eval rom.");
|
|
| 265 | 257 |
SDL_SetWindowTitle(gWindow, rom); |
| 266 | 258 |
return 1; |
| 267 | 259 |
} |
| ... | ... |
@@ -367,7 +359,7 @@ handle_events(Uxn *u) |
| 367 | 359 |
while(SDL_PollEvent(&event)) {
|
| 368 | 360 |
/* Window */ |
| 369 | 361 |
if(event.type == SDL_QUIT) |
| 370 |
- return error("Run", "Quit.");
|
|
| 362 |
+ return system_error("Run", "Quit.");
|
|
| 371 | 363 |
else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED) |
| 372 | 364 |
redraw(); |
| 373 | 365 |
else if(event.type == SDL_DROPFILE) {
|
| ... | ... |
@@ -465,7 +457,7 @@ run(Uxn *u) |
| 465 | 457 |
Uint16 screen_vector; |
| 466 | 458 |
/* .System/halt */ |
| 467 | 459 |
if(u->dev[0x0f]) |
| 468 |
- return error("Run", "Ended.");
|
|
| 460 |
+ return system_error("Run", "Ended.");
|
|
| 469 | 461 |
frame_end = now + frame_interval; |
| 470 | 462 |
exec_deadline = now + deadline_interval; |
| 471 | 463 |
if(!handle_events(u)) |
| ... | ... |
@@ -492,7 +484,7 @@ main(int argc, char **argv) |
| 492 | 484 |
Uxn u = {0};
|
| 493 | 485 |
int i = 1; |
| 494 | 486 |
if(!init()) |
| 495 |
- return error("Init", "Failed to initialize emulator.");
|
|
| 487 |
+ return system_error("Init", "Failed to initialize emulator.");
|
|
| 496 | 488 |
/* default resolution */ |
| 497 | 489 |
screen_resize(&uxn_screen, WIDTH, HEIGHT); |
| 498 | 490 |
/* default zoom */ |
| ... | ... |
@@ -502,11 +494,11 @@ main(int argc, char **argv) |
| 502 | 494 |
set_zoom(DM.w / 1280); |
| 503 | 495 |
/* load rom */ |
| 504 | 496 |
if(i == argc) |
| 505 |
- return error("usage", "uxnemu [-2x][-3x] file.rom");
|
|
| 497 |
+ return system_error("usage", "uxnemu [-2x][-3x] file.rom");
|
|
| 506 | 498 |
if(i == argc - 1) |
| 507 | 499 |
u.dev[0x17] = CONSOLE_END; |
| 508 | 500 |
if(!start(&u, argv[i])) |
| 509 |
- return error("Start", "Failed");
|
|
| 501 |
+ return system_error("Start", "Failed");
|
|
| 510 | 502 |
rom_path = argv[i++]; |
| 511 | 503 |
/* read arguments */ |
| 512 | 504 |
for(; i < argc; i++) {
|