summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/devcpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/devcpu.c')
-rw-r--r--src/emu/devcpu.c325
1 files changed, 132 insertions, 193 deletions
diff --git a/src/emu/devcpu.c b/src/emu/devcpu.c
index cddecf11f7a..53b3907c751 100644
--- a/src/emu/devcpu.c
+++ b/src/emu/devcpu.c
@@ -43,144 +43,6 @@
//**************************************************************************
-// CPU DEVICE CONFIGURATION
-//**************************************************************************
-
-//-------------------------------------------------
-// cpu_device_config - constructor
-//-------------------------------------------------
-
-cpu_device_config::cpu_device_config(const machine_config &mconfig, device_type type, const char *name, const char *tag, const device_config *owner, UINT32 clock)
- : device_config(mconfig, type, name, tag, owner, clock),
- device_config_execute_interface(mconfig, *this),
- device_config_memory_interface(mconfig, *this),
- device_config_state_interface(mconfig, *this),
- device_config_disasm_interface(mconfig, *this)
-{
-}
-
-
-//-------------------------------------------------
-// legacy_cpu_device_config - constructor
-//-------------------------------------------------
-
-legacy_cpu_device_config::legacy_cpu_device_config(const machine_config &mconfig, device_type type, const char *tag, const device_config *owner, UINT32 clock, cpu_get_info_func get_info)
- : cpu_device_config(mconfig, type, "CPU", tag, owner, clock),
- m_get_info(get_info)
-{
- // build up our address spaces; legacy devices don't have logical spaces
- memset(m_space_config, 0, sizeof(m_space_config));
- for (address_spacenum spacenum = AS_0; spacenum < ARRAY_LENGTH(m_space_config); spacenum++)
- {
- m_space_config[spacenum].m_name = (spacenum == 1) ? "data" : (spacenum == 2) ? "i/o" : "program";
- m_space_config[spacenum].m_endianness = static_cast<endianness_t>(get_legacy_config_int(DEVINFO_INT_ENDIANNESS));
- m_space_config[spacenum].m_databus_width = get_legacy_config_int(DEVINFO_INT_DATABUS_WIDTH + spacenum);
- m_space_config[spacenum].m_addrbus_width = get_legacy_config_int(DEVINFO_INT_ADDRBUS_WIDTH + spacenum);
- m_space_config[spacenum].m_addrbus_shift = get_legacy_config_int(DEVINFO_INT_ADDRBUS_SHIFT + spacenum);
- m_space_config[spacenum].m_logaddr_width = get_legacy_config_int(CPUINFO_INT_LOGADDR_WIDTH + spacenum);
- if (m_space_config[spacenum].m_logaddr_width == 0)
- m_space_config[spacenum].m_logaddr_width = m_space_config[spacenum].m_addrbus_width;
- m_space_config[spacenum].m_page_shift = get_legacy_config_int(CPUINFO_INT_PAGE_SHIFT + spacenum);
- m_space_config[spacenum].m_internal_map = reinterpret_cast<address_map_constructor>(get_legacy_config_fct(DEVINFO_PTR_INTERNAL_MEMORY_MAP + spacenum));
- m_space_config[spacenum].m_default_map = reinterpret_cast<address_map_constructor>(get_legacy_config_fct(DEVINFO_PTR_DEFAULT_MEMORY_MAP + spacenum));
- }
-
- // set the real name
- m_name = get_legacy_config_string(DEVINFO_STR_NAME);
- m_shortname = get_legacy_config_string(DEVINFO_STR_SHORTNAME);
- m_searchpath = m_shortname;
-}
-
-
-//-------------------------------------------------
-// execute_clocks_to_cycles - convert the raw
-// clock into cycles per second
-//-------------------------------------------------
-
-UINT64 legacy_cpu_device_config::execute_clocks_to_cycles(UINT64 clocks) const
-{
- UINT32 multiplier = get_legacy_config_int(CPUINFO_INT_CLOCK_MULTIPLIER);
- UINT32 divider = get_legacy_config_int(CPUINFO_INT_CLOCK_DIVIDER);
-
- if (multiplier == 0) multiplier = 1;
- if (divider == 0) divider = 1;
-
- return (clocks * multiplier + divider - 1) / divider;
-}
-
-
-//-------------------------------------------------
-// execute_cycles_to_clocks - convert a cycle
-// count back to raw clocks
-//-------------------------------------------------
-
-UINT64 legacy_cpu_device_config::execute_cycles_to_clocks(UINT64 cycles) const
-{
- UINT32 multiplier = get_legacy_config_int(CPUINFO_INT_CLOCK_MULTIPLIER);
- UINT32 divider = get_legacy_config_int(CPUINFO_INT_CLOCK_DIVIDER);
-
- if (multiplier == 0) multiplier = 1;
- if (divider == 0) divider = 1;
-
- return (cycles * divider + multiplier - 1) / multiplier;
-}
-
-
-//-------------------------------------------------
-// get_legacy_config_int - return a legacy
-// integer value
-//-------------------------------------------------
-
-INT64 legacy_cpu_device_config::get_legacy_config_int(UINT32 state) const
-{
- cpuinfo info = { 0 };
- (*m_get_info)(this, NULL, state, &info);
- return info.i;
-}
-
-
-//-------------------------------------------------
-// get_legacy_config_ptr - return a legacy
-// pointer value
-//-------------------------------------------------
-
-void *legacy_cpu_device_config::get_legacy_config_ptr(UINT32 state) const
-{
- cpuinfo info = { 0 };
- (*m_get_info)(this, NULL, state, &info);
- return info.p;
-}
-
-
-//-------------------------------------------------
-// get_legacy_config_fct - return a legacy
-// function value
-//-------------------------------------------------
-
-genf *legacy_cpu_device_config::get_legacy_config_fct(UINT32 state) const
-{
- cpuinfo info = { 0 };
- (*m_get_info)(this, NULL, state, &info);
- return info.f;
-}
-
-
-//-------------------------------------------------
-// get_legacy_config_string - return a legacy
-// string value
-//-------------------------------------------------
-
-const char *legacy_cpu_device_config::get_legacy_config_string(UINT32 state) const
-{
- cpuinfo info;
- info.s = get_temp_string_buffer();
- (*m_get_info)(this, NULL, state, &info);
- return info.s;
-}
-
-
-
-//**************************************************************************
// CPU RUNNING DEVICE
//**************************************************************************
@@ -188,12 +50,12 @@ const char *legacy_cpu_device_config::get_legacy_config_string(UINT32 state) con
// cpu_device - constructor
//-------------------------------------------------
-cpu_device::cpu_device(running_machine &machine, const cpu_device_config &config)
- : device_t(machine, config),
- device_execute_interface(machine, config, *this),
- device_memory_interface(machine, config, *this),
- device_state_interface(machine, config, *this),
- device_disasm_interface(machine, config, *this)
+cpu_device::cpu_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
+ : device_t(mconfig, type, name, tag, owner, clock),
+ device_execute_interface(mconfig, *this),
+ device_memory_interface(mconfig, *this),
+ device_state_interface(mconfig, *this),
+ device_disasm_interface(mconfig, *this)
{
}
@@ -211,33 +73,55 @@ cpu_device::~cpu_device()
// legacy_cpu_device - constructor
//-------------------------------------------------
-legacy_cpu_device::legacy_cpu_device(running_machine &machine, const legacy_cpu_device_config &config)
- : cpu_device(machine, config),
- m_cpu_config(config),
+legacy_cpu_device::legacy_cpu_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock, cpu_get_info_func get_info)
+ : cpu_device(mconfig, type, "CPU", tag, owner, clock),
+ m_get_info(get_info),
m_token(NULL),
- m_set_info(reinterpret_cast<cpu_set_info_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_SET_INFO))),
- m_execute(reinterpret_cast<cpu_execute_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_EXECUTE))),
- m_burn(reinterpret_cast<cpu_burn_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_BURN))),
- m_translate(reinterpret_cast<cpu_translate_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_TRANSLATE))),
- m_read(reinterpret_cast<cpu_read_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_READ))),
- m_write(reinterpret_cast<cpu_write_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_WRITE))),
- m_readop(reinterpret_cast<cpu_readop_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_READOP))),
- m_disassemble(reinterpret_cast<cpu_disassemble_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_DISASSEMBLE))),
- m_state_import(reinterpret_cast<cpu_state_io_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_IMPORT_STATE))),
- m_state_export(reinterpret_cast<cpu_state_io_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_EXPORT_STATE))),
- m_string_export(reinterpret_cast<cpu_string_io_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_EXPORT_STRING))),
- m_exit(reinterpret_cast<cpu_exit_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_EXIT))),
+ m_set_info(reinterpret_cast<cpu_set_info_func>(get_legacy_fct(CPUINFO_FCT_SET_INFO))),
+ m_execute(reinterpret_cast<cpu_execute_func>(get_legacy_fct(CPUINFO_FCT_EXECUTE))),
+ m_burn(reinterpret_cast<cpu_burn_func>(get_legacy_fct(CPUINFO_FCT_BURN))),
+ m_translate(reinterpret_cast<cpu_translate_func>(get_legacy_fct(CPUINFO_FCT_TRANSLATE))),
+ m_read(reinterpret_cast<cpu_read_func>(get_legacy_fct(CPUINFO_FCT_READ))),
+ m_write(reinterpret_cast<cpu_write_func>(get_legacy_fct(CPUINFO_FCT_WRITE))),
+ m_readop(reinterpret_cast<cpu_readop_func>(get_legacy_fct(CPUINFO_FCT_READOP))),
+ m_disassemble(reinterpret_cast<cpu_disassemble_func>(get_legacy_fct(CPUINFO_FCT_DISASSEMBLE))),
+ m_state_import(reinterpret_cast<cpu_state_io_func>(get_legacy_fct(CPUINFO_FCT_IMPORT_STATE))),
+ m_state_export(reinterpret_cast<cpu_state_io_func>(get_legacy_fct(CPUINFO_FCT_EXPORT_STATE))),
+ m_string_export(reinterpret_cast<cpu_string_io_func>(get_legacy_fct(CPUINFO_FCT_EXPORT_STRING))),
+ m_exit(reinterpret_cast<cpu_exit_func>(get_legacy_fct(CPUINFO_FCT_EXIT))),
m_using_legacy_state(false),
m_inited(false)
{
+ // build up our address spaces; legacy devices don't have logical spaces
+ memset(m_space_config, 0, sizeof(m_space_config));
+ for (address_spacenum spacenum = AS_0; spacenum < ARRAY_LENGTH(m_space_config); spacenum++)
+ {
+ m_space_config[spacenum].m_name = (spacenum == 1) ? "data" : (spacenum == 2) ? "i/o" : "program";
+ m_space_config[spacenum].m_endianness = static_cast<endianness_t>(get_legacy_int(DEVINFO_INT_ENDIANNESS));
+ m_space_config[spacenum].m_databus_width = get_legacy_int(DEVINFO_INT_DATABUS_WIDTH + spacenum);
+ m_space_config[spacenum].m_addrbus_width = get_legacy_int(DEVINFO_INT_ADDRBUS_WIDTH + spacenum);
+ m_space_config[spacenum].m_addrbus_shift = get_legacy_int(DEVINFO_INT_ADDRBUS_SHIFT + spacenum);
+ m_space_config[spacenum].m_logaddr_width = get_legacy_int(CPUINFO_INT_LOGADDR_WIDTH + spacenum);
+ if (m_space_config[spacenum].m_logaddr_width == 0)
+ m_space_config[spacenum].m_logaddr_width = m_space_config[spacenum].m_addrbus_width;
+ m_space_config[spacenum].m_page_shift = get_legacy_int(CPUINFO_INT_PAGE_SHIFT + spacenum);
+ m_space_config[spacenum].m_internal_map = reinterpret_cast<address_map_constructor>(get_legacy_fct(DEVINFO_PTR_INTERNAL_MEMORY_MAP + spacenum));
+ m_space_config[spacenum].m_default_map = reinterpret_cast<address_map_constructor>(get_legacy_fct(DEVINFO_PTR_DEFAULT_MEMORY_MAP + spacenum));
+ }
+
+ // set the real name
+ m_name = get_legacy_string(DEVINFO_STR_NAME);
+ m_shortname = get_legacy_string(DEVINFO_STR_SHORTNAME);
+ m_searchpath = m_shortname;
+
memset(&m_partial_frame_period, 0, sizeof(m_partial_frame_period));
- int tokenbytes = m_cpu_config.get_legacy_config_int(CPUINFO_INT_CONTEXT_SIZE);
+ int tokenbytes = get_legacy_int(CPUINFO_INT_CONTEXT_SIZE);
if (tokenbytes == 0)
- throw emu_fatalerror("Device %s specifies a 0 context size!\n", tag());
+ throw emu_fatalerror("Device %s specifies a 0 context size!\n", tag);
// allocate memory for the token
- m_token = auto_alloc_array_clear(machine, UINT8, tokenbytes);
+ m_token = global_alloc_array_clear(UINT8, tokenbytes);
}
@@ -247,9 +131,7 @@ legacy_cpu_device::legacy_cpu_device(running_machine &machine, const legacy_cpu_
legacy_cpu_device::~legacy_cpu_device()
{
- // call the CPU's exit function if present
- if (m_inited && m_exit != NULL)
- (*m_exit)(this);
+ global_free(m_token);
}
@@ -260,7 +142,7 @@ legacy_cpu_device::~legacy_cpu_device()
void legacy_cpu_device::device_start()
{
// standard init
- cpu_init_func init = reinterpret_cast<cpu_init_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_INIT));
+ cpu_init_func init = reinterpret_cast<cpu_init_func>(get_legacy_fct(CPUINFO_FCT_INIT));
(*init)(this, static_standard_irq_callback);
m_inited = true;
@@ -270,7 +152,7 @@ void legacy_cpu_device::device_start()
m_using_legacy_state = true;
for (int index = 0; index < MAX_REGS; index++)
{
- const char *string = get_legacy_runtime_string(CPUINFO_STR_REGISTER + index);
+ const char *string = get_legacy_string(CPUINFO_STR_REGISTER + index);
if (strchr(string, ':') != NULL)
{
astring tempstr(string);
@@ -293,7 +175,7 @@ void legacy_cpu_device::device_start()
state_add(STATE_GENPC, "curpc", m_state_io).callimport().callexport().formatstr("%8s").noshow();
state_add(STATE_GENPCBASE, "curpcbase", m_state_io).callimport().callexport().formatstr("%8s").noshow();
- const char *string = get_legacy_runtime_string(CPUINFO_STR_FLAGS);
+ const char *string = get_legacy_string(CPUINFO_STR_FLAGS);
if (string != NULL && string[0] != 0)
{
astring flagstr;
@@ -303,7 +185,7 @@ void legacy_cpu_device::device_start()
}
// get our icount pointer
- m_icountptr = reinterpret_cast<int *>(get_legacy_runtime_ptr(CPUINFO_PTR_INSTRUCTION_COUNTER));
+ m_icountptr = reinterpret_cast<int *>(get_legacy_ptr(CPUINFO_PTR_INSTRUCTION_COUNTER));
assert(m_icountptr != 0);
*m_icountptr = 0;
}
@@ -315,15 +197,62 @@ void legacy_cpu_device::device_start()
void legacy_cpu_device::device_reset()
{
- cpu_reset_func reset = reinterpret_cast<cpu_reset_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_RESET));
+ cpu_reset_func reset = reinterpret_cast<cpu_reset_func>(get_legacy_fct(CPUINFO_FCT_RESET));
if (reset != NULL)
(*reset)(this);
}
//-------------------------------------------------
-// execute - execute for the provided number of
-// cycles
+// device_stop - clean up before the machine goes
+// away
+//-------------------------------------------------
+
+void legacy_cpu_device::device_stop()
+{
+ // call the CPU's exit function if present
+ if (m_inited && m_exit != NULL)
+ (*m_exit)(this);
+}
+
+
+//-------------------------------------------------
+// execute_clocks_to_cycles - convert the raw
+// clock into cycles per second
+//-------------------------------------------------
+
+UINT64 legacy_cpu_device::execute_clocks_to_cycles(UINT64 clocks) const
+{
+ UINT32 multiplier = get_legacy_int(CPUINFO_INT_CLOCK_MULTIPLIER);
+ UINT32 divider = get_legacy_int(CPUINFO_INT_CLOCK_DIVIDER);
+
+ if (multiplier == 0) multiplier = 1;
+ if (divider == 0) divider = 1;
+
+ return (clocks * multiplier + divider - 1) / divider;
+}
+
+
+//-------------------------------------------------
+// execute_cycles_to_clocks - convert a cycle
+// count back to raw clocks
+//-------------------------------------------------
+
+UINT64 legacy_cpu_device::execute_cycles_to_clocks(UINT64 cycles) const
+{
+ UINT32 multiplier = get_legacy_int(CPUINFO_INT_CLOCK_MULTIPLIER);
+ UINT32 divider = get_legacy_int(CPUINFO_INT_CLOCK_DIVIDER);
+
+ if (multiplier == 0) multiplier = 1;
+ if (divider == 0) divider = 1;
+
+ return (cycles * divider + multiplier - 1) / multiplier;
+}
+
+
+//-------------------------------------------------
+// execute_run - execute for the provided number
+// of cycles
//-------------------------------------------------
void legacy_cpu_device::execute_run()
@@ -402,7 +331,7 @@ bool legacy_cpu_device::memory_readop(offs_t offset, int size, UINT64 &value)
void legacy_cpu_device::device_debug_setup()
{
- cpu_debug_init_func init = reinterpret_cast<cpu_debug_init_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_DEBUG_INIT));
+ cpu_debug_init_func init = reinterpret_cast<cpu_debug_init_func>(get_legacy_fct(CPUINFO_FCT_DEBUG_INIT));
if (init != NULL)
(*init)(this);
}
@@ -445,51 +374,61 @@ offs_t legacy_cpu_device::disasm_disassemble(char *buffer, offs_t pc, const UINT
//-------------------------------------------------
-// get_legacy_runtime_int - call the get info
-// function to retrieve an integer value
+// get_legacy_int - return a legacy integer value
//-------------------------------------------------
-INT64 legacy_cpu_device::get_legacy_runtime_int(UINT32 state)
+INT64 legacy_cpu_device::get_legacy_int(UINT32 state) const
{
cpuinfo info = { 0 };
- (*m_cpu_config.m_get_info)(&m_cpu_config, this, state, &info);
+ (*m_get_info)(const_cast<legacy_cpu_device *>(this), state, &info);
return info.i;
}
//-------------------------------------------------
-// get_legacy_runtime_ptr - call the get info
-// function to retrieve a pointer value
+// get_legacy_ptr - return a legacy pointer value
//-------------------------------------------------
-void *legacy_cpu_device::get_legacy_runtime_ptr(UINT32 state)
+void *legacy_cpu_device::get_legacy_ptr(UINT32 state) const
{
cpuinfo info = { 0 };
- (*m_cpu_config.m_get_info)(&m_cpu_config, this, state, &info);
+ (*m_get_info)(const_cast<legacy_cpu_device *>(this), state, &info);
return info.p;
}
//-------------------------------------------------
-// get_legacy_runtime_string - call the get info
-// function to retrieve a string value
+// get_legacy_fct - return a legacy function value
+//-------------------------------------------------
+
+genf *legacy_cpu_device::get_legacy_fct(UINT32 state) const
+{
+ cpuinfo info = { 0 };
+ (*m_get_info)(const_cast<legacy_cpu_device *>(this), state, &info);
+ return info.f;
+}
+
+
+//-------------------------------------------------
+// get_legacy_string - return a legacy
+// string value
//-------------------------------------------------
-const char *legacy_cpu_device::get_legacy_runtime_string(UINT32 state)
+const char *legacy_cpu_device::get_legacy_string(UINT32 state) const
{
cpuinfo info;
info.s = get_temp_string_buffer();
- (*m_cpu_config.m_get_info)(&m_cpu_config, this, state, &info);
+ (*m_get_info)(const_cast<legacy_cpu_device *>(this), state, &info);
return info.s;
}
//-------------------------------------------------
-// set_legacy_runtime_int - call the get info
-// function to set an integer value
+// set_legacy_int - call the get info function
+// to set an integer value
//-------------------------------------------------
-void legacy_cpu_device::set_legacy_runtime_int(UINT32 state, INT64 value)
+void legacy_cpu_device::set_legacy_int(UINT32 state, INT64 value)
{
cpuinfo info = { 0 };
info.i = value;
@@ -505,7 +444,7 @@ void legacy_cpu_device::state_import(const device_state_entry &entry)
if (entry.index() == STATE_GENFLAGS)
; // do nothing
else
- set_legacy_runtime_int(CPUINFO_INT_REGISTER + entry.index(), m_state_io);
+ set_legacy_int(CPUINFO_INT_REGISTER + entry.index(), m_state_io);
}
else if (m_state_import != NULL)
(*m_state_import)(this, entry);
@@ -518,13 +457,13 @@ void legacy_cpu_device::state_export(const device_state_entry &entry)
{
if (entry.index() == STATE_GENFLAGS)
{
- const char *temp = get_legacy_runtime_string(CPUINFO_STR_FLAGS);
+ const char *temp = get_legacy_string(CPUINFO_STR_FLAGS);
m_state_io = 0;
while (*temp != 0)
m_state_io = ((m_state_io << 5) | (m_state_io >> (64-5))) ^ *temp++;
}
else
- m_state_io = get_legacy_runtime_int(CPUINFO_INT_REGISTER + entry.index());
+ m_state_io = get_legacy_int(CPUINFO_INT_REGISTER + entry.index());
}
else if (m_state_export != NULL)
(*m_state_export)(this, entry);
@@ -536,9 +475,9 @@ void legacy_cpu_device::state_string_export(const device_state_entry &entry, ast
if (m_using_legacy_state)
{
if (entry.index() == STATE_GENFLAGS)
- string.cpy(get_legacy_runtime_string(CPUINFO_STR_FLAGS));
+ string.cpy(get_legacy_string(CPUINFO_STR_FLAGS));
else
- string.cpy(strchr(get_legacy_runtime_string(CPUINFO_STR_REGISTER + entry.index()), ':') + 1);
+ string.cpy(strchr(get_legacy_string(CPUINFO_STR_REGISTER + entry.index()), ':') + 1);
}
else if (m_string_export != NULL)
(*m_string_export)(this, entry, string);