comparison 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
comparison
equal deleted inserted replaced
791:60686f8d5e48 792:724bbec47f86
5 */ 5 */
6 #include "z80inst.h" 6 #include "z80inst.h"
7 #include "z80_to_x86.h" 7 #include "z80_to_x86.h"
8 #include "gen_x86.h" 8 #include "gen_x86.h"
9 #include "mem.h" 9 #include "mem.h"
10 #include "util.h"
10 #include <stdio.h> 11 #include <stdio.h>
11 #include <stdlib.h> 12 #include <stdlib.h>
12 #include <stddef.h> 13 #include <stddef.h>
13 #include <string.h> 14 #include <string.h>
14 15
254 break; 255 break;
255 case Z80_UNUSED: 256 case Z80_UNUSED:
256 ea->mode = MODE_UNUSED; 257 ea->mode = MODE_UNUSED;
257 break; 258 break;
258 default: 259 default:
259 fprintf(stderr, "Unrecognized Z80 addressing mode %d\n", inst->addr_mode & 0x1F); 260 fatal_error("Unrecognized Z80 addressing mode %d\n", inst->addr_mode & 0x1F);
260 exit(1);
261 } 261 }
262 } 262 }
263 263
264 void z80_save_ea(code_info *code, z80inst * inst, z80_options * opts) 264 void z80_save_ea(code_info *code, z80inst * inst, z80_options * opts)
265 { 265 {
1937 case Z80_OUTD: 1937 case Z80_OUTD:
1938 case Z80_OTDR:*/ 1938 case Z80_OTDR:*/
1939 default: { 1939 default: {
1940 char disbuf[80]; 1940 char disbuf[80];
1941 z80_disasm(inst, disbuf, address); 1941 z80_disasm(inst, disbuf, address);
1942 fprintf(stderr, "unimplemented instruction: %s at %X\n", disbuf, address);
1943 FILE * f = fopen("zram.bin", "wb"); 1942 FILE * f = fopen("zram.bin", "wb");
1944 fwrite(context->mem_pointers[0], 1, 8 * 1024, f); 1943 fwrite(context->mem_pointers[0], 1, 8 * 1024, f);
1945 fclose(f); 1944 fclose(f);
1946 exit(1); 1945 fatal_error("unimplemented Z80 instruction: %s at %X\nZ80 RAM has been saved to zram.bin for debugging", disbuf, address);
1947 } 1946 }
1948 } 1947 }
1949 } 1948 }
1950 1949
1951 uint8_t * z80_interp_handler(uint8_t opcode, z80_context * context) 1950 uint8_t * z80_interp_handler(uint8_t opcode, z80_context * context)
1952 { 1951 {
1953 if (!context->interp_code[opcode]) { 1952 if (!context->interp_code[opcode]) {
1954 if (opcode == 0xCB || (opcode >= 0xDD && (opcode & 0xF) == 0xD)) { 1953 if (opcode == 0xCB || (opcode >= 0xDD && (opcode & 0xF) == 0xD)) {
1955 fprintf(stderr, "Encountered prefix byte %X at address %X. Z80 interpeter doesn't support those yet.", opcode, context->pc); 1954 fatal_error("Encountered prefix byte %X at address %X. Z80 interpeter doesn't support those yet.", opcode, context->pc);
1956 exit(1);
1957 } 1955 }
1958 uint8_t codebuf[8]; 1956 uint8_t codebuf[8];
1959 memset(codebuf, 0, sizeof(codebuf)); 1957 memset(codebuf, 0, sizeof(codebuf));
1960 codebuf[0] = opcode; 1958 codebuf[0] = opcode;
1961 z80inst inst; 1959 z80inst inst;
1962 uint8_t * after = z80_decode(codebuf, &inst); 1960 uint8_t * after = z80_decode(codebuf, &inst);
1963 if (after - codebuf > 1) { 1961 if (after - codebuf > 1) {
1964 fprintf(stderr, "Encountered multi-byte Z80 instruction at %X. Z80 interpeter doesn't support those yet.", context->pc); 1962 fatal_error("Encountered multi-byte Z80 instruction at %X. Z80 interpeter doesn't support those yet.", context->pc);
1965 exit(1);
1966 } 1963 }
1967 1964
1968 z80_options * opts = context->options; 1965 z80_options * opts = context->options;
1969 code_info *code = &opts->gen.code; 1966 code_info *code = &opts->gen.code;
1970 check_alloc_code(code, ZMAX_NATIVE_SIZE); 1967 check_alloc_code(code, ZMAX_NATIVE_SIZE);
2241 } while (!z80_is_terminal(&inst)); 2238 } while (!z80_is_terminal(&inst));
2242 process_deferred(&opts->gen.deferred, context, (native_addr_func)z80_get_native_address); 2239 process_deferred(&opts->gen.deferred, context, (native_addr_func)z80_get_native_address);
2243 if (opts->gen.deferred) { 2240 if (opts->gen.deferred) {
2244 address = opts->gen.deferred->address; 2241 address = opts->gen.deferred->address;
2245 dprintf("defferred address: %X\n", address); 2242 dprintf("defferred address: %X\n", address);
2246 } 2243 }
2247 } while (opts->gen.deferred); 2244 } while (opts->gen.deferred);
2248 } 2245 }
2249 2246
2250 void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks, uint32_t clock_divider) 2247 void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks, uint32_t clock_divider)
2251 { 2248 {
2747 code_info tmp_code = opts->gen.code; 2744 code_info tmp_code = opts->gen.code;
2748 opts->gen.code.cur = native; 2745 opts->gen.code.cur = native;
2749 opts->gen.code.last = native + 16; 2746 opts->gen.code.last = native + 16;
2750 check_cycles_int(&opts->gen, address); 2747 check_cycles_int(&opts->gen, address);
2751 opts->gen.code = tmp_code; 2748 opts->gen.code = tmp_code;
2752 } 2749 }
2753 } 2750 }
2754 2751