Mercurial > repos > blastem
comparison m68k_core.c @ 1506:ded16f3d7eb4 mame_interp
Super hacky integration of the version of Musashi from MAME
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 27 Dec 2017 13:46:52 -0800 |
parents | ffe45c5b8390 |
children | 2455662378ed |
comparison
equal
deleted
inserted
replaced
1471:2e6320d261ff | 1506:ded16f3d7eb4 |
---|---|
8 #include "68kinst.h" | 8 #include "68kinst.h" |
9 #include "backend.h" | 9 #include "backend.h" |
10 #include "gen.h" | 10 #include "gen.h" |
11 #include "util.h" | 11 #include "util.h" |
12 #include "serialize.h" | 12 #include "serialize.h" |
13 #include "musashi/m68kcpu.h" | |
13 #include <stdio.h> | 14 #include <stdio.h> |
14 #include <stddef.h> | 15 #include <stddef.h> |
15 #include <stdlib.h> | 16 #include <stdlib.h> |
16 #include <string.h> | 17 #include <string.h> |
17 | 18 |
1167 void start_68k_context(m68k_context * context, uint32_t address) | 1168 void start_68k_context(m68k_context * context, uint32_t address) |
1168 { | 1169 { |
1169 code_ptr addr = get_native_address_trans(context, address); | 1170 code_ptr addr = get_native_address_trans(context, address); |
1170 m68k_options * options = context->options; | 1171 m68k_options * options = context->options; |
1171 context->should_return = 0; | 1172 context->should_return = 0; |
1173 #ifdef USE_NATIVE | |
1172 options->start_context(addr, context); | 1174 options->start_context(addr, context); |
1175 #else | |
1176 while (!context->should_return) { | |
1177 if (context->current_cycle >= context->target_cycle) { | |
1178 context->target_cycle += 4 * options->gen.clock_divider; | |
1179 } | |
1180 m68k_cpu_execute((m68000_base_device *)context); | |
1181 if (!context->should_return) { | |
1182 sync_components(context, 0); | |
1183 } | |
1184 } | |
1185 #endif | |
1173 } | 1186 } |
1174 | 1187 |
1175 void resume_68k(m68k_context *context) | 1188 void resume_68k(m68k_context *context) |
1176 { | 1189 { |
1190 #ifdef USE_NATIVE | |
1177 code_ptr addr = context->resume_pc; | 1191 code_ptr addr = context->resume_pc; |
1178 context->resume_pc = NULL; | 1192 context->resume_pc = NULL; |
1179 m68k_options * options = context->options; | 1193 m68k_options * options = context->options; |
1180 context->should_return = 0; | 1194 context->should_return = 0; |
1181 options->start_context(addr, context); | 1195 options->start_context(addr, context); |
1196 #else | |
1197 start_68k_context(context, 0); | |
1198 #endif | |
1182 } | 1199 } |
1183 | 1200 |
1184 void m68k_reset(m68k_context * context) | 1201 void m68k_reset(m68k_context * context) |
1185 { | 1202 { |
1203 #ifdef USE_NATIVE | |
1186 //TODO: Actually execute the M68K reset vector rather than simulating some of its behavior | 1204 //TODO: Actually execute the M68K reset vector rather than simulating some of its behavior |
1187 uint16_t *reset_vec = get_native_pointer(0, (void **)context->mem_pointers, &context->options->gen); | 1205 uint16_t *reset_vec = get_native_pointer(0, (void **)context->mem_pointers, &context->options->gen); |
1188 context->aregs[7] = reset_vec[0] << 16 | reset_vec[1]; | 1206 context->aregs[7] = reset_vec[0] << 16 | reset_vec[1]; |
1189 uint32_t address = reset_vec[2] << 16 | reset_vec[3]; | 1207 uint32_t address = reset_vec[2] << 16 | reset_vec[3]; |
1208 #else | |
1209 m68k_reset_cpu((m68000_base_device *)context); | |
1210 uint32_t address = 0; | |
1211 #endif | |
1190 start_68k_context(context, address); | 1212 start_68k_context(context, address); |
1191 } | 1213 } |
1192 | 1214 |
1193 void m68k_options_free(m68k_options *opts) | 1215 void m68k_options_free(m68k_options *opts) |
1194 { | 1216 { |
1198 } | 1220 } |
1199 | 1221 |
1200 | 1222 |
1201 m68k_context * init_68k_context(m68k_options * opts, m68k_reset_handler reset_handler) | 1223 m68k_context * init_68k_context(m68k_options * opts, m68k_reset_handler reset_handler) |
1202 { | 1224 { |
1225 #ifdef USE_NATIVE | |
1203 size_t ctx_size = sizeof(m68k_context) + ram_size(&opts->gen) / (1 << opts->gen.ram_flags_shift) / 8; | 1226 size_t ctx_size = sizeof(m68k_context) + ram_size(&opts->gen) / (1 << opts->gen.ram_flags_shift) / 8; |
1204 m68k_context * context = malloc(ctx_size); | 1227 m68k_context * context = malloc(ctx_size); |
1205 memset(context, 0, ctx_size); | 1228 memset(context, 0, ctx_size); |
1206 context->options = opts; | 1229 context->options = opts; |
1230 #else | |
1231 m68000_base_device *device = malloc(sizeof(m68000_base_device));; | |
1232 memset(device, 0, sizeof(m68000_base_device)); | |
1233 m68k_context *context = &device->c; | |
1234 context->options = opts; | |
1235 m68k_init_cpu_m68000(device); | |
1236 | |
1237 #endif | |
1207 context->int_cycle = CYCLE_NEVER; | 1238 context->int_cycle = CYCLE_NEVER; |
1208 context->status = 0x27; | 1239 context->status = 0x27; |
1209 context->reset_handler = (code_ptr)reset_handler; | 1240 context->reset_handler = (code_ptr)reset_handler; |
1210 return context; | 1241 return context; |
1211 } | 1242 } |