Mercurial > repos > blastem
comparison genesis.c @ 1507:2455662378ed mame_interp
Added MAME Z80 core, re-enabled 68K tracing in Musashi core, disabled a bunch of code gen stuff when using interpreters from MAME
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 30 Dec 2017 18:27:06 -0800 |
parents | ded16f3d7eb4 |
children | b7ecd0d6a77b |
comparison
equal
deleted
inserted
replaced
1506:ded16f3d7eb4 | 1507:2455662378ed |
---|---|
238 #endif | 238 #endif |
239 | 239 |
240 static void z80_next_int_pulse(z80_context * z_context) | 240 static void z80_next_int_pulse(z80_context * z_context) |
241 { | 241 { |
242 genesis_context * gen = z_context->system; | 242 genesis_context * gen = z_context->system; |
243 vdp_run_context(gen->vdp, z_context->current_cycle); | |
243 z_context->int_pulse_start = vdp_next_vint_z80(gen->vdp); | 244 z_context->int_pulse_start = vdp_next_vint_z80(gen->vdp); |
244 z_context->int_pulse_end = z_context->int_pulse_start + Z80_INT_PULSE_MCLKS; | 245 z_context->int_pulse_end = z_context->int_pulse_start + Z80_INT_PULSE_MCLKS; |
245 z_context->im2_vector = 0xFF; | 246 z_context->im2_vector = 0xFF; |
246 } | 247 } |
247 | 248 |
342 } | 343 } |
343 if (!address && (gen->header.enter_debugger || gen->header.save_state)) { | 344 if (!address && (gen->header.enter_debugger || gen->header.save_state)) { |
344 context->sync_cycle = context->current_cycle + 1; | 345 context->sync_cycle = context->current_cycle + 1; |
345 } | 346 } |
346 adjust_int_cycle(context, v_context); | 347 adjust_int_cycle(context, v_context); |
348 #ifdef USE_NATIVE | |
347 if (address) { | 349 if (address) { |
348 if (gen->header.enter_debugger) { | 350 if (gen->header.enter_debugger) { |
349 gen->header.enter_debugger = 0; | 351 gen->header.enter_debugger = 0; |
350 debugger(context, address); | 352 debugger(context, address); |
351 } | 353 } |
386 } | 388 } |
387 } else if(gen->header.save_state) { | 389 } else if(gen->header.save_state) { |
388 context->sync_cycle = context->current_cycle + 1; | 390 context->sync_cycle = context->current_cycle + 1; |
389 } | 391 } |
390 } | 392 } |
393 #endif | |
391 #ifdef REFRESH_EMULATION | 394 #ifdef REFRESH_EMULATION |
392 last_sync_cycle = context->current_cycle; | 395 last_sync_cycle = context->current_cycle; |
393 #endif | 396 #endif |
394 return context; | 397 return context; |
395 } | 398 } |
908 | 911 |
909 static uint8_t z80_read_bank(uint32_t location, void * vcontext) | 912 static uint8_t z80_read_bank(uint32_t location, void * vcontext) |
910 { | 913 { |
911 z80_context * context = vcontext; | 914 z80_context * context = vcontext; |
912 genesis_context *gen = context->system; | 915 genesis_context *gen = context->system; |
916 | |
913 if (gen->bus_busy) { | 917 if (gen->bus_busy) { |
918 #ifdef USE_NATIVE | |
914 context->current_cycle = context->sync_cycle; | 919 context->current_cycle = context->sync_cycle; |
915 } | 920 #else |
921 context->m_icount = 0; | |
922 #endif | |
923 } | |
924 | |
916 //typical delay from bus arbitration | 925 //typical delay from bus arbitration |
926 #ifdef USE_NATIVE | |
917 context->current_cycle += 3 * MCLKS_PER_Z80; | 927 context->current_cycle += 3 * MCLKS_PER_Z80; |
928 #else | |
929 context->m_icount -= 3; | |
930 #endif | |
918 //TODO: add cycle for an access right after a previous one | 931 //TODO: add cycle for an access right after a previous one |
919 //TODO: Below cycle time is an estimate based on the time between 68K !BG goes low and Z80 !MREQ goes high | 932 //TODO: Below cycle time is an estimate based on the time between 68K !BG goes low and Z80 !MREQ goes high |
920 // Needs a new logic analyzer capture to get the actual delay on the 68K side | 933 // Needs a new logic analyzer capture to get the actual delay on the 68K side |
921 gen->m68k->current_cycle += 8 * MCLKS_PER_68K; | 934 gen->m68k->current_cycle += 8 * MCLKS_PER_68K; |
922 | 935 |
936 static void *z80_write_bank(uint32_t location, void * vcontext, uint8_t value) | 949 static void *z80_write_bank(uint32_t location, void * vcontext, uint8_t value) |
937 { | 950 { |
938 z80_context * context = vcontext; | 951 z80_context * context = vcontext; |
939 genesis_context *gen = context->system; | 952 genesis_context *gen = context->system; |
940 if (gen->bus_busy) { | 953 if (gen->bus_busy) { |
954 #ifdef USE_NATIVE | |
941 context->current_cycle = context->sync_cycle; | 955 context->current_cycle = context->sync_cycle; |
956 #else | |
957 context->m_icount = 0; | |
958 #endif | |
942 } | 959 } |
943 //typical delay from bus arbitration | 960 //typical delay from bus arbitration |
961 #ifdef USE_NATIVE | |
944 context->current_cycle += 3 * MCLKS_PER_Z80; | 962 context->current_cycle += 3 * MCLKS_PER_Z80; |
963 #else | |
964 context->m_icount -= 3; | |
965 #endif | |
945 //TODO: add cycle for an access right after a previous one | 966 //TODO: add cycle for an access right after a previous one |
946 //TODO: Below cycle time is an estimate based on the time between 68K !BG goes low and Z80 !MREQ goes high | 967 //TODO: Below cycle time is an estimate based on the time between 68K !BG goes low and Z80 !MREQ goes high |
947 // Needs a new logic analyzer capture to get the actual delay on the 68K side | 968 // Needs a new logic analyzer capture to get the actual delay on the 68K side |
948 gen->m68k->current_cycle += 8 * MCLKS_PER_68K; | 969 gen->m68k->current_cycle += 8 * MCLKS_PER_68K; |
949 | 970 |
1036 } | 1057 } |
1037 char const *parts[] = {gen->header.save_dir, PATH_SEP, slotname}; | 1058 char const *parts[] = {gen->header.save_dir, PATH_SEP, slotname}; |
1038 char *statepath = alloc_concat_m(3, parts); | 1059 char *statepath = alloc_concat_m(3, parts); |
1039 deserialize_buffer state; | 1060 deserialize_buffer state; |
1040 uint32_t pc = 0; | 1061 uint32_t pc = 0; |
1041 uint8_t ret; | 1062 uint8_t ret = 0; |
1042 if (load_from_file(&state, statepath)) { | 1063 if (load_from_file(&state, statepath)) { |
1043 genesis_deserialize(&state, gen); | 1064 genesis_deserialize(&state, gen); |
1044 free(state.data); | 1065 free(state.data); |
1045 //HACK | 1066 //HACK |
1046 pc = gen->m68k->last_prefetch_address; | 1067 pc = gen->m68k->last_prefetch_address; |
1047 ret = 1; | 1068 ret = 1; |
1048 } else { | 1069 } else { |
1070 #ifdef USE_NATIVE | |
1049 strcpy(statepath + strlen(statepath)-strlen("state"), "gst"); | 1071 strcpy(statepath + strlen(statepath)-strlen("state"), "gst"); |
1050 pc = load_gst(gen, statepath); | 1072 pc = load_gst(gen, statepath); |
1051 ret = pc != 0; | 1073 ret = pc != 0; |
1052 } | 1074 #endif |
1075 } | |
1076 #ifdef USE_NATIVE | |
1053 if (ret) { | 1077 if (ret) { |
1054 gen->m68k->resume_pc = get_native_address_trans(gen->m68k, pc); | 1078 gen->m68k->resume_pc = get_native_address_trans(gen->m68k, pc); |
1055 } | 1079 } |
1080 #endif | |
1056 free(statepath); | 1081 free(statepath); |
1057 return ret; | 1082 return ret; |
1058 } | 1083 } |
1059 | 1084 |
1060 static void start_genesis(system_header *system, char *statefile) | 1085 static void start_genesis(system_header *system, char *statefile) |
1070 genesis_deserialize(&state, gen); | 1095 genesis_deserialize(&state, gen); |
1071 free(state.data); | 1096 free(state.data); |
1072 //HACK | 1097 //HACK |
1073 pc = gen->m68k->last_prefetch_address; | 1098 pc = gen->m68k->last_prefetch_address; |
1074 } else { | 1099 } else { |
1100 #ifdef USE_NATIVE | |
1075 pc = load_gst(gen, statefile); | 1101 pc = load_gst(gen, statefile); |
1076 if (!pc) { | 1102 if (!pc) { |
1077 fatal_error("Failed to load save state %s\n", statefile); | 1103 fatal_error("Failed to load save state %s\n", statefile); |
1078 } | 1104 } |
1105 #endif | |
1079 } | 1106 } |
1080 printf("Loaded %s\n", statefile); | 1107 printf("Loaded %s\n", statefile); |
1108 #ifdef USE_NATIVE | |
1081 if (gen->header.enter_debugger) { | 1109 if (gen->header.enter_debugger) { |
1082 gen->header.enter_debugger = 0; | 1110 gen->header.enter_debugger = 0; |
1083 insert_breakpoint(gen->m68k, pc, gen->header.debugger_type == DEBUGGER_NATIVE ? debugger : gdb_debug_enter); | 1111 insert_breakpoint(gen->m68k, pc, gen->header.debugger_type == DEBUGGER_NATIVE ? debugger : gdb_debug_enter); |
1084 } | 1112 } |
1113 #endif | |
1085 adjust_int_cycle(gen->m68k, gen->vdp); | 1114 adjust_int_cycle(gen->m68k, gen->vdp); |
1086 start_68k_context(gen->m68k, pc); | 1115 start_68k_context(gen->m68k, pc); |
1087 } else { | 1116 } else { |
1117 #ifdef USE_NATIVE | |
1088 if (gen->header.enter_debugger) { | 1118 if (gen->header.enter_debugger) { |
1089 gen->header.enter_debugger = 0; | 1119 gen->header.enter_debugger = 0; |
1090 uint32_t address = gen->cart[2] << 16 | gen->cart[3]; | 1120 uint32_t address = gen->cart[2] << 16 | gen->cart[3]; |
1091 insert_breakpoint(gen->m68k, address, gen->header.debugger_type == DEBUGGER_NATIVE ? debugger : gdb_debug_enter); | 1121 insert_breakpoint(gen->m68k, address, gen->header.debugger_type == DEBUGGER_NATIVE ? debugger : gdb_debug_enter); |
1092 } | 1122 } |
1123 #endif | |
1093 m68k_reset(gen->m68k); | 1124 m68k_reset(gen->m68k); |
1094 } | 1125 } |
1095 handle_reset_requests(gen); | 1126 handle_reset_requests(gen); |
1096 return; | 1127 return; |
1097 } | 1128 } |