diff options
author | 2011-04-27 05:11:18 +0000 | |
---|---|---|
committer | 2011-04-27 05:11:18 +0000 | |
commit | 919913f118760c0ca41ab63512bd5c106f6fd840 (patch) | |
tree | cd6c115c8e9c5280ac4bd16eabfe69c7341151c2 /src/emu/cpu/cosmac | |
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/cosmac')
-rw-r--r-- | src/emu/cpu/cosmac/cosmac.c | 259 | ||||
-rw-r--r-- | src/emu/cpu/cosmac/cosmac.h | 92 |
2 files changed, 141 insertions, 210 deletions
diff --git a/src/emu/cpu/cosmac/cosmac.c b/src/emu/cpu/cosmac/cosmac.c index df6b5a3c7eb..cc20ab3e138 100644 --- a/src/emu/cpu/cosmac/cosmac.c +++ b/src/emu/cpu/cosmac/cosmac.c @@ -28,14 +28,6 @@ ALLOW_SAVE_TYPE(cosmac_device::cosmac_state); //************************************************************************** -// DEVICE DEFINITIONS -//************************************************************************** - -const device_type COSMAC = cosmac_device_config::static_alloc_device_config; - - - -//************************************************************************** // CONSTANTS //************************************************************************** @@ -182,116 +174,33 @@ const cosmac_device::ophandler cosmac_device::s_opcodetable[256] = //************************************************************************** -// COSMAC DEVICE CONFIG +// DEVICE INTERFACE //************************************************************************** -//------------------------------------------------- -// cosmac_device_config - constructor -//------------------------------------------------- - -cosmac_device_config::cosmac_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) - : cpu_device_config(mconfig, static_alloc_device_config, "COSMAC", tag, owner, clock), - m_program_config("program", ENDIANNESS_LITTLE, 8, 16), - m_io_config("io", ENDIANNESS_LITTLE, 8, 3) -{ -} - - -//------------------------------------------------- -// static_alloc_device_config - allocate a new -// configuration object -//------------------------------------------------- - -device_config *cosmac_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) -{ - return global_alloc(cosmac_device_config(mconfig, tag, owner, clock)); -} - - -//------------------------------------------------- -// alloc_device - allocate a new device object -//------------------------------------------------- - -device_t *cosmac_device_config::alloc_device(running_machine &machine) const -{ - return auto_alloc(machine, cosmac_device(machine, *this)); -} +// device type definition +const device_type COSMAC = &device_creator<cosmac_device>; //------------------------------------------------- -// execute_min_cycles - return minimum number of -// cycles it takes for one instruction to execute -//------------------------------------------------- - -UINT32 cosmac_device_config::execute_min_cycles() const -{ - return 8 * 2; -} - - -//------------------------------------------------- -// execute_max_cycles - return maximum number of -// cycles it takes for one instruction to execute -//------------------------------------------------- - -UINT32 cosmac_device_config::execute_max_cycles() const -{ - return 8 * 3; -} - - -//------------------------------------------------- -// execute_input_lines - return the number of -// input/interrupt lines -//------------------------------------------------- - -UINT32 cosmac_device_config::execute_input_lines() const -{ - return 7; -} - - -//------------------------------------------------- -// memory_space_config - return the configuration -// of the specified address space, or NULL if -// the space doesn't exist -//------------------------------------------------- - -const address_space_config *cosmac_device_config::memory_space_config(address_spacenum spacenum) const -{ - switch (spacenum) - { - case AS_PROGRAM: - return &m_program_config; - - case AS_IO: - return &m_io_config; - - default: - return NULL; - } -} - - -//------------------------------------------------- -// disasm_min_opcode_bytes - return the length -// of the shortest instruction, in bytes -//------------------------------------------------- - -UINT32 cosmac_device_config::disasm_min_opcode_bytes() const -{ - return 1; -} - - -//------------------------------------------------- -// disasm_max_opcode_bytes - return the length -// of the longest instruction, in bytes +// cosmac_device - constructor //------------------------------------------------- -UINT32 cosmac_device_config::disasm_max_opcode_bytes() const +cosmac_device::cosmac_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : cpu_device(mconfig, COSMAC, "COSMAC", tag, owner, clock), + m_program_config("program", ENDIANNESS_LITTLE, 8, 16), + m_io_config("io", ENDIANNESS_LITTLE, 8, 3), + m_op(0), + m_state(COSMAC_STATE_1_RESET), + m_mode(COSMAC_MODE_RESET), + m_irq(0), + m_dmain(0), + m_dmaout(0), + m_program(NULL), + m_io(NULL), + m_direct(NULL) { - return 3; + for (int i = 0; i < 4; i++) + EF[i] = 0; } @@ -301,7 +210,7 @@ UINT32 cosmac_device_config::disasm_max_opcode_bytes() const // complete //------------------------------------------------- -void cosmac_device_config::device_config_complete() +void cosmac_device::device_config_complete() { // inherit a copy of the static data const cosmac_interface *intf = reinterpret_cast<const cosmac_interface *>(static_config()); @@ -324,33 +233,6 @@ void cosmac_device_config::device_config_complete() } - -//************************************************************************** -// DEVICE INTERFACE -//************************************************************************** - -//------------------------------------------------- -// cosmac_device - constructor -//------------------------------------------------- - -cosmac_device::cosmac_device(running_machine &_machine, const cosmac_device_config &config) - : cpu_device(_machine, config), - m_op(0), - m_state(COSMAC_STATE_1_RESET), - m_mode(COSMAC_MODE_RESET), - m_irq(0), - m_dmain(0), - m_dmaout(0), - m_program(NULL), - m_io(NULL), - m_direct(NULL), - m_config(config) -{ - for (int i = 0; i < 4; i++) - EF[i] = 0; -} - - //------------------------------------------------- // device_start - start up the device //------------------------------------------------- @@ -384,18 +266,18 @@ void cosmac_device::device_start() state_add(COSMAC_Q, "Q", m_q).mask(0x1).noshow(); // resolve callbacks - devcb_resolve_read_line(&m_in_wait_func, &m_config.m_in_wait_func, this); - devcb_resolve_read_line(&m_in_clear_func, &m_config.m_in_clear_func, this); - devcb_resolve_read_line(&m_in_ef_func[0], &m_config.m_in_ef1_func, this); - devcb_resolve_read_line(&m_in_ef_func[1], &m_config.m_in_ef2_func, this); - devcb_resolve_read_line(&m_in_ef_func[2], &m_config.m_in_ef3_func, this); - devcb_resolve_read_line(&m_in_ef_func[3], &m_config.m_in_ef4_func, this); - devcb_resolve_write_line(&m_out_q_func, &m_config.m_out_q_func, this); - devcb_resolve_read8(&m_in_dma_func, &m_config.m_in_dma_func, this); - devcb_resolve_write8(&m_out_dma_func, &m_config.m_out_dma_func, this); - m_out_sc_func = m_config.m_out_sc_func; - devcb_resolve_write_line(&m_out_tpa_func, &m_config.m_out_tpa_func, this); - devcb_resolve_write_line(&m_out_tpb_func, &m_config.m_out_tpb_func, this); + devcb_resolve_read_line(&m_in_wait_func, &m_in_wait_cb, this); + devcb_resolve_read_line(&m_in_clear_func, &m_in_clear_cb, this); + devcb_resolve_read_line(&m_in_ef_func[0], &m_in_ef1_cb, this); + devcb_resolve_read_line(&m_in_ef_func[1], &m_in_ef2_cb, this); + devcb_resolve_read_line(&m_in_ef_func[2], &m_in_ef3_cb, this); + devcb_resolve_read_line(&m_in_ef_func[3], &m_in_ef4_cb, this); + devcb_resolve_write_line(&m_out_q_func, &m_out_q_cb, this); + devcb_resolve_read8(&m_in_dma_func, &m_in_dma_cb, this); + devcb_resolve_write8(&m_out_dma_func, &m_out_dma_cb, this); + m_out_sc_func = m_out_sc_cb; + devcb_resolve_write_line(&m_out_tpa_func, &m_out_tpa_cb, this); + devcb_resolve_write_line(&m_out_tpb_func, &m_out_tpb_cb, this); // register our state for saving save_item(NAME(m_op)); @@ -435,6 +317,28 @@ void cosmac_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 *cosmac_device::memory_space_config(address_spacenum spacenum) const +{ + switch (spacenum) + { + case AS_PROGRAM: + return &m_program_config; + + case AS_IO: + return &m_io_config; + + default: + return NULL; + } +} + + +//------------------------------------------------- // state_import - import state into the device, // after it has been set //------------------------------------------------- @@ -486,6 +390,28 @@ void cosmac_device::state_string_export(const device_state_entry &entry, astring //------------------------------------------------- +// disasm_min_opcode_bytes - return the length +// of the shortest instruction, in bytes +//------------------------------------------------- + +UINT32 cosmac_device::disasm_min_opcode_bytes() const +{ + return 1; +} + + +//------------------------------------------------- +// disasm_max_opcode_bytes - return the length +// of the longest instruction, in bytes +//------------------------------------------------- + +UINT32 cosmac_device::disasm_max_opcode_bytes() const +{ + return 3; +} + + +//------------------------------------------------- // disasm_disassemble - call the disassembly // helper function //------------------------------------------------- @@ -570,6 +496,39 @@ offs_t cosmac_device::get_memory_address() } //------------------------------------------------- +// execute_min_cycles - return minimum number of +// cycles it takes for one instruction to execute +//------------------------------------------------- + +UINT32 cosmac_device::execute_min_cycles() const +{ + return 8 * 2; +} + + +//------------------------------------------------- +// execute_max_cycles - return maximum number of +// cycles it takes for one instruction to execute +//------------------------------------------------- + +UINT32 cosmac_device::execute_max_cycles() const +{ + return 8 * 3; +} + + +//------------------------------------------------- +// execute_input_lines - return the number of +// input/interrupt lines +//------------------------------------------------- + +UINT32 cosmac_device::execute_input_lines() const +{ + return 7; +} + + +//------------------------------------------------- // execute_set_input - //------------------------------------------------- diff --git a/src/emu/cpu/cosmac/cosmac.h b/src/emu/cpu/cosmac/cosmac.h index ed755d1496a..f461256bf22 100644 --- a/src/emu/cpu/cosmac/cosmac.h +++ b/src/emu/cpu/cosmac/cosmac.h @@ -105,9 +105,6 @@ enum cosmac_state_code }; -// device type definition -extern const device_type COSMAC; - //************************************************************************** @@ -122,90 +119,60 @@ typedef void (*cosmac_out_sc_func)(device_t *device, cosmac_state_code sc); struct cosmac_interface { - devcb_read_line m_in_wait_func; - devcb_read_line m_in_clear_func; - devcb_read_line m_in_ef1_func; - devcb_read_line m_in_ef2_func; - devcb_read_line m_in_ef3_func; - devcb_read_line m_in_ef4_func; - devcb_write_line m_out_q_func; - devcb_read8 m_in_dma_func; - devcb_write8 m_out_dma_func; - cosmac_out_sc_func m_out_sc_func; - devcb_write_line m_out_tpa_func; - devcb_write_line m_out_tpb_func; + devcb_read_line m_in_wait_cb; + devcb_read_line m_in_clear_cb; + devcb_read_line m_in_ef1_cb; + devcb_read_line m_in_ef2_cb; + devcb_read_line m_in_ef3_cb; + devcb_read_line m_in_ef4_cb; + devcb_write_line m_out_q_cb; + devcb_read8 m_in_dma_cb; + devcb_write8 m_out_dma_cb; + cosmac_out_sc_func m_out_sc_cb; + devcb_write_line m_out_tpa_cb; + devcb_write_line m_out_tpb_cb; }; #define COSMAC_INTERFACE(name) \ const cosmac_interface (name) = -// ======================> cosmac_device_config - -class cosmac_device_config : public cpu_device_config, - public cosmac_interface -{ - friend class cosmac_device; - - // construction/destruction - cosmac_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); - -public: - // allocators - static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); - virtual device_t *alloc_device(running_machine &machine) const; - -protected: - // device_config overrides - virtual void device_config_complete(); - - // device_config_execute_interface overrides - virtual UINT32 execute_min_cycles() const; - virtual UINT32 execute_max_cycles() const; - virtual UINT32 execute_input_lines() const; - - // device_config_memory_interface overrides - virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const; - - // device_config_disasm_interface overrides - virtual UINT32 disasm_min_opcode_bytes() const; - virtual UINT32 disasm_max_opcode_bytes() const; - - // inline data - const address_space_config m_program_config; - const address_space_config m_io_config; -}; - - - // ======================> cosmac_device -class cosmac_device : public cpu_device +class cosmac_device : public cpu_device, + public cosmac_interface { - friend class cosmac_device_config; - +public: // construction/destruction - cosmac_device(running_machine &_machine, const cosmac_device_config &config); + cosmac_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); -public: // public interfaces offs_t get_memory_address(); protected: // device-level overrides + virtual void device_config_complete(); virtual void device_start(); virtual void device_reset(); // device_execute_interface overrides + virtual UINT32 execute_min_cycles() const; + virtual UINT32 execute_max_cycles() const; + virtual UINT32 execute_input_lines() const; virtual void execute_run(); virtual void execute_set_input(int inputnum, int state); + // device_memory_interface overrides + virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const; + // device_state_interface overrides virtual void state_import(const device_state_entry &entry); virtual void state_export(const device_state_entry &entry); virtual void state_string_export(const device_state_entry &entry, astring &string); // device_disasm_interface overrides + virtual UINT32 disasm_min_opcode_bytes() const; + virtual UINT32 disasm_max_opcode_bytes() const; virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options); // helpers @@ -336,6 +303,9 @@ protected: void out(); void inp(); + const address_space_config m_program_config; + const address_space_config m_io_config; + // device callbacks devcb_resolved_read_line m_in_wait_func; devcb_resolved_read_line m_in_clear_func; @@ -404,9 +374,11 @@ protected: typedef void (cosmac_device::*ophandler)(); static const ophandler s_opcodetable[256]; - - const cosmac_device_config &m_config; }; +// device type definition +extern const device_type COSMAC; + + #endif /* __COSMAC_H__ */ |