diff z80_to_x86.c @ 792:724bbec47f86

Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
author Michael Pavone <pavone@retrodev.com>
date Sat, 25 Jul 2015 18:22:07 -0700
parents 7306b3967c51
children ab017fb09e77
line wrap: on
line diff
--- a/z80_to_x86.c	Sat Jul 25 18:19:00 2015 -0700
+++ b/z80_to_x86.c	Sat Jul 25 18:22:07 2015 -0700
@@ -7,6 +7,7 @@
 #include "z80_to_x86.h"
 #include "gen_x86.h"
 #include "mem.h"
+#include "util.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
@@ -256,8 +257,7 @@
 		ea->mode = MODE_UNUSED;
 		break;
 	default:
-		fprintf(stderr, "Unrecognized Z80 addressing mode %d\n", inst->addr_mode & 0x1F);
-		exit(1);
+		fatal_error("Unrecognized Z80 addressing mode %d\n", inst->addr_mode & 0x1F);
 	}
 }
 
@@ -1939,11 +1939,10 @@
 	default: {
 		char disbuf[80];
 		z80_disasm(inst, disbuf, address);
-		fprintf(stderr, "unimplemented instruction: %s at %X\n", disbuf, address);
 		FILE * f = fopen("zram.bin", "wb");
 		fwrite(context->mem_pointers[0], 1, 8 * 1024, f);
 		fclose(f);
-		exit(1);
+		fatal_error("unimplemented Z80 instruction: %s at %X\nZ80 RAM has been saved to zram.bin for debugging", disbuf, address);
 	}
 	}
 }
@@ -1952,8 +1951,7 @@
 {
 	if (!context->interp_code[opcode]) {
 		if (opcode == 0xCB || (opcode >= 0xDD && (opcode & 0xF) == 0xD)) {
-			fprintf(stderr, "Encountered prefix byte %X at address %X. Z80 interpeter doesn't support those yet.", opcode, context->pc);
-			exit(1);
+			fatal_error("Encountered prefix byte %X at address %X. Z80 interpeter doesn't support those yet.", opcode, context->pc);
 		}
 		uint8_t codebuf[8];
 		memset(codebuf, 0, sizeof(codebuf));
@@ -1961,8 +1959,7 @@
 		z80inst inst;
 		uint8_t * after = z80_decode(codebuf, &inst);
 		if (after - codebuf > 1) {
-			fprintf(stderr, "Encountered multi-byte Z80 instruction at %X. Z80 interpeter doesn't support those yet.", context->pc);
-			exit(1);
+			fatal_error("Encountered multi-byte Z80 instruction at %X. Z80 interpeter doesn't support those yet.", context->pc);
 		}
 
 		z80_options * opts = context->options;
@@ -2243,7 +2240,7 @@
 		if (opts->gen.deferred) {
 			address = opts->gen.deferred->address;
 			dprintf("defferred address: %X\n", address);
-			}
+		}
 	} while (opts->gen.deferred);
 }
 
@@ -2749,6 +2746,6 @@
 		opts->gen.code.last = native + 16;
 		check_cycles_int(&opts->gen, address);
 		opts->gen.code = tmp_code;
-}
+	}
 }