diff options
author | Aaron Giles <aaron@aarongiles.com> | 2011-04-27 05:11:18 +0000 |
---|---|---|
committer | Aaron Giles <aaron@aarongiles.com> | 2011-04-27 05:11:18 +0000 |
commit | 919913f118760c0ca41ab63512bd5c106f6fd840 (patch) | |
tree | cd6c115c8e9c5280ac4bd16eabfe69c7341151c2 /src/emu/cpu/adsp2100/adsp2100.c | |
parent | 84f2c31f7d6f6c667427b1d60c83e6dc9f420d60 (diff) |
Collapsed device_config and device_t into one class. Updated all
existing modern devices and the legacy wrappers to work in this
environment. This in general greatly simplifies writing a modern
device. [Aaron Giles]
General notes:
* some more cleanup probably needs to happen behind this change,
but I needed to get it in before the next device modernization
or import from MESS :)
* new template function device_creator which automatically defines
the static function that creates the device; use this instead of
creating a static_alloc_device_config function
* added device_stop() method which is called at around the time
the previous device_t's destructor was called; if you auto_free
anything, do it here because the machine is gone when the
destructor is called
* changed the static_set_* calls to pass a device_t & instead of
a device_config *
* for many devices, the static config structure member names over-
lapped the device's names for devcb_* functions; in these cases
the members in the interface were renamed to have a _cb suffix
* changed the driver_enumerator to only cache 100 machine_configs
because caching them all took a ton of memory; fortunately this
implementation detail is completely hidden behind the
driver_enumerator interface
* got rid of the macros for creating derived classes; doing it
manually is now clean enough that it isn't worth hiding the
details in a macro
Diffstat (limited to 'src/emu/cpu/adsp2100/adsp2100.c')
-rw-r--r-- | src/emu/cpu/adsp2100/adsp2100.c | 379 |
1 files changed, 156 insertions, 223 deletions
diff --git a/src/emu/cpu/adsp2100/adsp2100.c b/src/emu/cpu/adsp2100/adsp2100.c index e5c261f21e2..bdc335e1057 100644 --- a/src/emu/cpu/adsp2100/adsp2100.c +++ b/src/emu/cpu/adsp2100/adsp2100.c @@ -131,205 +131,13 @@ #include "adsp2100.h" -//************************************************************************** -// DEVICE DEFINITIONS -//************************************************************************** - -const device_type ADSP2100 = adsp2100_device_config::static_alloc_device_config; -const device_type ADSP2101 = adsp2101_device_config::static_alloc_device_config; -const device_type ADSP2104 = adsp2104_device_config::static_alloc_device_config; -const device_type ADSP2105 = adsp2105_device_config::static_alloc_device_config; -const device_type ADSP2115 = adsp2115_device_config::static_alloc_device_config; -const device_type ADSP2181 = adsp2181_device_config::static_alloc_device_config; - - - -//************************************************************************** -// TRIVIAL IMPLEMENTATIONS -//************************************************************************** - -DEFINE_TRIVIAL_DERIVED_DEVICE(adsp2104_device_config, adsp2101_device_config, adsp2104_device, adsp2101_device, "ADSP-2104", CHIP_TYPE_ADSP2104) -DEFINE_TRIVIAL_DERIVED_DEVICE(adsp2105_device_config, adsp2101_device_config, adsp2105_device, adsp2101_device, "ADSP-2105", CHIP_TYPE_ADSP2105) -DEFINE_TRIVIAL_DERIVED_DEVICE(adsp2115_device_config, adsp2101_device_config, adsp2115_device, adsp2101_device, "ADSP-2115", CHIP_TYPE_ADSP2115) - - - -//************************************************************************** -// ADSP21XX DEVICE CONFIG -//************************************************************************** - -//------------------------------------------------- -// adsp21xx_device_config - constructor -//------------------------------------------------- - -adsp21xx_device_config::adsp21xx_device_config(const machine_config &mconfig, device_type type, const char *name, const char *tag, const device_config *owner, UINT32 clock, UINT32 chiptype) - : cpu_device_config(mconfig, type, name, tag, owner, clock), - m_program_config("program", ENDIANNESS_LITTLE, 32, 14, -2), - m_data_config("data", ENDIANNESS_LITTLE, 16, 14, -1), - m_chip_type(chiptype) -{ - m_sport_rx_callback = NULL; - m_sport_tx_callback = NULL; - m_timer_fired = NULL; -} - -adsp2100_device_config::adsp2100_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) - : adsp21xx_device_config(mconfig, static_alloc_device_config, "ADSP-2100", tag, owner, clock, CHIP_TYPE_ADSP2100) { } - -adsp2101_device_config::adsp2101_device_config(const machine_config &mconfig, device_type type, const char *name, const char *tag, const device_config *owner, UINT32 clock, UINT32 chiptype) - : adsp21xx_device_config(mconfig, type, name, tag, owner, clock, chiptype) { } - -adsp2181_device_config::adsp2181_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) - : adsp21xx_device_config(mconfig, static_alloc_device_config, "ADSP-2181", tag, owner, clock, CHIP_TYPE_ADSP2181), - m_io_config("I/O", ENDIANNESS_LITTLE, 16, 11, -1) { } - - -//------------------------------------------------- -// static_alloc_device_config - allocate a new -// configuration object -//------------------------------------------------- - -device_config *adsp2100_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) -{ - return global_alloc(adsp2100_device_config(mconfig, tag, owner, clock)); -} - -device_config *adsp2101_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) -{ - return global_alloc(adsp2101_device_config(mconfig, static_alloc_device_config, "ADSP-2101", tag, owner, clock, CHIP_TYPE_ADSP2101)); -} - -device_config *adsp2181_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) -{ - return global_alloc(adsp2181_device_config(mconfig, tag, owner, clock)); -} - - -//------------------------------------------------- -// alloc_device - allocate a new device object -//------------------------------------------------- - -device_t *adsp2100_device_config::alloc_device(running_machine &machine) const -{ - return auto_alloc(machine, adsp2100_device(machine, *this)); -} - -device_t *adsp2101_device_config::alloc_device(running_machine &machine) const -{ - return auto_alloc(machine, adsp2101_device(machine, *this)); -} - -device_t *adsp2181_device_config::alloc_device(running_machine &machine) const -{ - return auto_alloc(machine, adsp2181_device(machine, *this)); -} - - -//------------------------------------------------- -// static_set_config - set the configuration -// structure -//------------------------------------------------- - -void adsp21xx_device_config::static_set_config(device_config *device, const adsp21xx_config &config) -{ - adsp21xx_device_config *adsp = downcast<adsp21xx_device_config *>(device); - *static_cast<adsp21xx_config *>(adsp) = config; -} - - -//------------------------------------------------- -// execute_min_cycles - return minimum number of -// cycles it takes for one instruction to execute -//------------------------------------------------- - -UINT32 adsp21xx_device_config::execute_min_cycles() const -{ - return 1; -} - - -//------------------------------------------------- -// execute_max_cycles - return maximum number of -// cycles it takes for one instruction to execute -//------------------------------------------------- - -UINT32 adsp21xx_device_config::execute_max_cycles() const -{ - return 1; -} - - -//------------------------------------------------- -// execute_input_lines - return the number of -// input/interrupt lines -//------------------------------------------------- - -UINT32 adsp2100_device_config::execute_input_lines() const -{ - return 4; -} - -UINT32 adsp2101_device_config::execute_input_lines() const -{ - return 5; -} - -UINT32 adsp2181_device_config::execute_input_lines() const -{ - return 9; -} - - -//------------------------------------------------- -// memory_space_config - return the configuration -// of the specified address space, or NULL if -// the space doesn't exist -//------------------------------------------------- - -const address_space_config *adsp2100_device_config::memory_space_config(address_spacenum spacenum) const -{ - return (spacenum == AS_PROGRAM) ? &m_program_config : - (spacenum == AS_DATA) ? &m_data_config : - NULL; -} - -const address_space_config *adsp2101_device_config::memory_space_config(address_spacenum spacenum) const -{ - return (spacenum == AS_PROGRAM) ? &m_program_config : - (spacenum == AS_DATA) ? &m_data_config : - NULL; -} - -const address_space_config *adsp2181_device_config::memory_space_config(address_spacenum spacenum) const -{ - return (spacenum == AS_PROGRAM) ? &m_program_config : - (spacenum == AS_DATA) ? &m_data_config : - (spacenum == AS_IO) ? &m_io_config : - NULL; -} - - -//------------------------------------------------- -// disasm_min_opcode_bytes - return the length -// of the shortest instruction, in bytes -//------------------------------------------------- - -UINT32 adsp21xx_device_config::disasm_min_opcode_bytes() const -{ - return 4; -} - - -//------------------------------------------------- -// disasm_max_opcode_bytes - return the length -// of the longest instruction, in bytes -//------------------------------------------------- - -UINT32 adsp21xx_device_config::disasm_max_opcode_bytes() const -{ - return 4; -} - +// device type definitions +const device_type ADSP2100 = &device_creator<adsp2100_device>; +const device_type ADSP2101 = &device_creator<adsp2101_device>; +const device_type ADSP2104 = &device_creator<adsp2104_device>; +const device_type ADSP2105 = &device_creator<adsp2105_device>; +const device_type ADSP2115 = &device_creator<adsp2115_device>; +const device_type ADSP2181 = &device_creator<adsp2181_device>; //************************************************************************** @@ -340,9 +148,11 @@ UINT32 adsp21xx_device_config::disasm_max_opcode_bytes() const // adsp21xx_device - constructor //------------------------------------------------- -adsp21xx_device::adsp21xx_device(running_machine &_machine, const adsp21xx_device_config &config) - : cpu_device(_machine, config), - m_config(config), +adsp21xx_device::adsp21xx_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, UINT32 chiptype) + : cpu_device(mconfig, type, name, tag, owner, clock), + m_program_config("program", ENDIANNESS_LITTLE, 32, 14, -2), + m_data_config("data", ENDIANNESS_LITTLE, 16, 14, -1), + m_chip_type(chiptype), m_pc(0), m_ppc(0), m_loop(0), @@ -371,9 +181,9 @@ adsp21xx_device::adsp21xx_device(running_machine &_machine, const adsp21xx_devic m_icntl(0), m_ifc(0), m_icount(0), - m_mstat_mask((config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2101) ? 0x7f : 0x0f), - m_imask_mask((config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2181) ? 0x3ff : - (config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2101) ? 0x3f : 0x0f) + m_mstat_mask((m_chip_type >= CHIP_TYPE_ADSP2101) ? 0x7f : 0x0f), + m_imask_mask((m_chip_type >= CHIP_TYPE_ADSP2181) ? 0x3ff : + (m_chip_type >= CHIP_TYPE_ADSP2101) ? 0x3f : 0x0f) { // initialize remaining state memset(&m_core, 0, sizeof(m_core)); @@ -390,6 +200,10 @@ adsp21xx_device::adsp21xx_device(running_machine &_machine, const adsp21xx_devic memset(&m_irq_state, 0, sizeof(m_irq_state)); memset(&m_irq_latch, 0, sizeof(m_irq_latch)); + m_sport_rx_callback = NULL; + m_sport_tx_callback = NULL; + m_timer_fired = NULL; + // create the tables create_tables(); @@ -463,14 +277,27 @@ adsp21xx_device::adsp21xx_device(running_machine &_machine, const adsp21xx_devic m_shift_xregs[7] = &m_core.sr.srx.sr1; } -adsp2100_device::adsp2100_device(running_machine &_machine, const adsp2100_device_config &config) - : adsp21xx_device(_machine, config) { } +adsp2100_device::adsp2100_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : adsp21xx_device(mconfig, ADSP2100, "ADSP-2100", tag, owner, clock, CHIP_TYPE_ADSP2100) { } -adsp2101_device::adsp2101_device(running_machine &_machine, const adsp2101_device_config &config) - : adsp21xx_device(_machine, config) { } +adsp2101_device::adsp2101_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : adsp21xx_device(mconfig, ADSP2101, "ADSP-2101", tag, owner, clock, CHIP_TYPE_ADSP2101) { } -adsp2181_device::adsp2181_device(running_machine &_machine, const adsp2181_device_config &config) - : adsp21xx_device(_machine, config) { } +adsp2101_device::adsp2101_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, UINT32 chiptype) + : adsp21xx_device(mconfig, type, name, tag, owner, clock, chiptype) { } + +adsp2104_device::adsp2104_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : adsp2101_device(mconfig, ADSP2104, "ADSP-2104", tag, owner, clock, CHIP_TYPE_ADSP2104) { } + +adsp2105_device::adsp2105_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : adsp2101_device(mconfig, ADSP2105, "ADSP-2105", tag, owner, clock, CHIP_TYPE_ADSP2105) { } + +adsp2115_device::adsp2115_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : adsp2101_device(mconfig, ADSP2115, "ADSP-2115", tag, owner, clock, CHIP_TYPE_ADSP2115) { } + +adsp2181_device::adsp2181_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : adsp21xx_device(mconfig, ADSP2181, "ADSP-2181", tag, owner, clock, CHIP_TYPE_ADSP2181), + m_io_config("I/O", ENDIANNESS_LITTLE, 16, 11, -1) { } //------------------------------------------------- @@ -498,6 +325,18 @@ adsp21xx_device::~adsp21xx_device() //------------------------------------------------- +// static_set_config - set the configuration +// structure +//------------------------------------------------- + +void adsp21xx_device::static_set_config(device_t &device, const adsp21xx_config &config) +{ + adsp21xx_device &adsp = downcast<adsp21xx_device &>(device); + static_cast<adsp21xx_config &>(adsp) = config; +} + + +//------------------------------------------------- // load_boot_data - load the boot data from an // 8-bit ROM //------------------------------------------------- @@ -757,7 +596,7 @@ void adsp21xx_device::device_start() state_add(ADSP2100_CNTR, "CNTR", m_cntr).mask(0x3fff); state_add(ADSP2100_ASTAT, "ASTAT", m_astat).mask(0xff); state_add(ADSP2100_SSTAT, "SSTAT", m_sstat).mask(0xff); - state_add(ADSP2100_MSTAT, "MSTAT", m_mstat).mask((m_config.m_chip_type == adsp21xx_device_config::CHIP_TYPE_ADSP2100) ? 0x0f : 0x7f).callimport(); + state_add(ADSP2100_MSTAT, "MSTAT", m_mstat).mask((m_chip_type == CHIP_TYPE_ADSP2100) ? 0x0f : 0x7f).callimport(); state_add(ADSP2100_PCSP, "PCSP", m_pc_sp).mask(0xff); state_add(STATE_GENSP, "GENSP", m_pc_sp).mask(0xff).noshow(); @@ -765,11 +604,11 @@ void adsp21xx_device::device_start() state_add(ADSP2100_STATSP, "STATSP", m_stat_sp).mask(0xf); state_add(ADSP2100_LOOPSP, "LOOPSP", m_loop_sp).mask(0xf); - state_add(ADSP2100_IMASK, "IMASK", m_imask).mask((m_config.m_chip_type == adsp21xx_device_config::CHIP_TYPE_ADSP2100) ? 0x00f : (m_config.m_chip_type == adsp21xx_device_config::CHIP_TYPE_ADSP2181) ? 0x3ff : 0x07f).callimport(); + state_add(ADSP2100_IMASK, "IMASK", m_imask).mask((m_chip_type == CHIP_TYPE_ADSP2100) ? 0x00f : (m_chip_type == CHIP_TYPE_ADSP2181) ? 0x3ff : 0x07f).callimport(); state_add(ADSP2100_ICNTL, "ICNTL", m_icntl).mask(0x1f).callimport(); for (int irqnum = 0; irqnum < 4; irqnum++) - if (irqnum < 4 || m_config.m_chip_type == adsp21xx_device_config::CHIP_TYPE_ADSP2100) + if (irqnum < 4 || m_chip_type == CHIP_TYPE_ADSP2100) state_add(ADSP2100_IRQSTATE0 + irqnum, tempstring.format("IRQ%d", irqnum), m_irq_state[irqnum]).mask(1).callimport(); state_add(ADSP2100_FLAGIN, "FLAGIN", m_flagin).mask(1); @@ -803,7 +642,7 @@ void adsp21xx_device::device_reset() write_reg2(0x0b, m_l[7]); write_reg2(0x03, m_i[7]); // reset PC and loops - m_pc = (m_config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2101) ? 0 : 4; + m_pc = (m_chip_type >= CHIP_TYPE_ADSP2101) ? 0 : 4; m_ppc = -1; m_loop = 0xffff; m_loop_condition = 0; @@ -836,6 +675,35 @@ void adsp21xx_device::device_reset() //------------------------------------------------- +// memory_space_config - return the configuration +// of the specified address space, or NULL if +// the space doesn't exist +//------------------------------------------------- + +const address_space_config *adsp2100_device::memory_space_config(address_spacenum spacenum) const +{ + return (spacenum == AS_PROGRAM) ? &m_program_config : + (spacenum == AS_DATA) ? &m_data_config : + NULL; +} + +const address_space_config *adsp2101_device::memory_space_config(address_spacenum spacenum) const +{ + return (spacenum == AS_PROGRAM) ? &m_program_config : + (spacenum == AS_DATA) ? &m_data_config : + NULL; +} + +const address_space_config *adsp2181_device::memory_space_config(address_spacenum spacenum) const +{ + return (spacenum == AS_PROGRAM) ? &m_program_config : + (spacenum == AS_DATA) ? &m_data_config : + (spacenum == AS_IO) ? &m_io_config : + NULL; +} + + +//------------------------------------------------- // state_import - import state into the device, // after it has been set //------------------------------------------------- @@ -911,6 +779,28 @@ void adsp21xx_device::state_string_export(const device_state_entry &entry, astri //------------------------------------------------- +// disasm_min_opcode_bytes - return the length +// of the shortest instruction, in bytes +//------------------------------------------------- + +UINT32 adsp21xx_device::disasm_min_opcode_bytes() const +{ + return 4; +} + + +//------------------------------------------------- +// disasm_max_opcode_bytes - return the length +// of the longest instruction, in bytes +//------------------------------------------------- + +UINT32 adsp21xx_device::disasm_max_opcode_bytes() const +{ + return 4; +} + + +//------------------------------------------------- // disasm_disassemble - call the disassembly // helper function //------------------------------------------------- @@ -1250,6 +1140,49 @@ void adsp21xx_device::create_tables() CORE EXECUTION LOOP ***************************************************************************/ +//------------------------------------------------- +// execute_min_cycles - return minimum number of +// cycles it takes for one instruction to execute +//------------------------------------------------- + +UINT32 adsp21xx_device::execute_min_cycles() const +{ + return 1; +} + + +//------------------------------------------------- +// execute_max_cycles - return maximum number of +// cycles it takes for one instruction to execute +//------------------------------------------------- + +UINT32 adsp21xx_device::execute_max_cycles() const +{ + return 1; +} + + +//------------------------------------------------- +// execute_input_lines - return the number of +// input/interrupt lines +//------------------------------------------------- + +UINT32 adsp2100_device::execute_input_lines() const +{ + return 4; +} + +UINT32 adsp2101_device::execute_input_lines() const +{ + return 5; +} + +UINT32 adsp2181_device::execute_input_lines() const +{ + return 9; +} + + void adsp21xx_device::execute_set_input(int inputnum, int state) { // update the latched state @@ -1312,7 +1245,7 @@ void adsp21xx_device::execute_run() // 00000001 0xxxxxxx xxxxxxxx dst = IO(x) // 00000001 1xxxxxxx xxxxxxxx IO(x) = dst // ADSP-218x only - if (m_config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2181) + if (m_chip_type >= CHIP_TYPE_ADSP2181) { if ((op & 0x008000) == 0x000000) write_reg0(op & 15, io_read((op >> 4) & 0x7ff)); @@ -1335,7 +1268,7 @@ void adsp21xx_device::execute_run() { if (op & 0x020) m_flagout = 0; if (op & 0x010) m_flagout ^= 1; - if (m_config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2101) + if (m_chip_type >= CHIP_TYPE_ADSP2101) { if (op & 0x080) m_fl0 = 0; if (op & 0x040) m_fl0 ^= 1; @@ -1453,7 +1386,7 @@ void adsp21xx_device::execute_run() break; case 0x0c: // 00001100 xxxxxxxx xxxxxxxx mode control - if (m_config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2101) + if (m_chip_type >= CHIP_TYPE_ADSP2101) { if (op & 0x000008) m_mstat = (m_mstat & ~MSTAT_GOMODE) | ((op << 5) & MSTAT_GOMODE); if (op & 0x002000) m_mstat = (m_mstat & ~MSTAT_INTEGER) | ((op >> 8) & MSTAT_INTEGER); @@ -1567,7 +1500,7 @@ void adsp21xx_device::execute_run() // 0010000x xxxxxxxx xxxxxxxx conditional MAC to MR if (condition(op & 15)) { - if (m_config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2181 && (op & 0x0018f0) == 0x000010) + if (m_chip_type >= CHIP_TYPE_ADSP2181 && (op & 0x0018f0) == 0x000010) mac_op_mr_xop(op); else mac_op_mr(op); @@ -1577,7 +1510,7 @@ void adsp21xx_device::execute_run() // 0010001x xxxxxxxx xxxxxxxx conditional ALU to AR if (condition(op & 15)) { - if (m_config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2181 && (op & 0x000010) == 0x000010) + if (m_chip_type >= CHIP_TYPE_ADSP2181 && (op & 0x000010) == 0x000010) alu_op_ar_const(op); else alu_op_ar(op); @@ -1587,7 +1520,7 @@ void adsp21xx_device::execute_run() // 0010010x xxxxxxxx xxxxxxxx conditional MAC to MF if (condition(op & 15)) { - if (m_config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2181 && (op & 0x0018f0) == 0x000010) + if (m_chip_type >= CHIP_TYPE_ADSP2181 && (op & 0x0018f0) == 0x000010) mac_op_mf_xop(op); else mac_op_mf(op); @@ -1597,7 +1530,7 @@ void adsp21xx_device::execute_run() // 0010011x xxxxxxxx xxxxxxxx conditional ALU to AF if (condition(op & 15)) { - if (m_config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2181 && (op & 0x000010) == 0x000010) + if (m_chip_type >= CHIP_TYPE_ADSP2181 && (op & 0x000010) == 0x000010) alu_op_af_const(op); else alu_op_af(op); @@ -1611,7 +1544,7 @@ void adsp21xx_device::execute_run() break; case 0x2a: case 0x2b: // 0010101x xxxxxxxx xxxxxxxx ALU to AR with internal data register move - if (m_config.m_chip_type >= adsp21xx_device_config::CHIP_TYPE_ADSP2181 && (op & 0x0000ff) == 0x0000aa) + if (m_chip_type >= CHIP_TYPE_ADSP2181 && (op & 0x0000ff) == 0x0000aa) alu_op_none(op); else { |