Commit Graph

30 Commits

Author SHA1 Message Date
Aaron Giles
28fdb61512 Move overridable device->rom_region(), device->machine_config_additions(), and
device->input_ports() to protected methods. Added non-virtual wrappers around
them.
2011-03-30 06:27:49 +00:00
Aaron Giles
2ad5072023 BIG update.
Remove redundant machine items from address_space and device_t.
Neither machine nor m_machine are directly accessible anymore.
Instead a new getter machine() is available which returns a
machine reference. So:

  space->machine->xxx   ==>  space->machine().xxx
  device->machine->yyy  ==>  device->machine().yyy

Globally changed all running_machine pointers to running_machine
references. Any function/method that takes a running_machine takes
it as a required parameter (1 or 2 exceptions). Being consistent
here gets rid of a lot of odd &machine or *machine, but it does
mean a very large bulk change across the project.

Structs which have a running_machine * now have that variable
renamed to m_machine, and now have a shiny new machine() method
that works like the space and device methods above. Since most of
these are things that should eventually be devices anyway, consider
this a step in that direction.

98% of the update was done with regex searches. The changes are
architected such that the compiler will catch the remaining
errors:

// find things that use an embedded machine directly and replace
// with a machine() getter call
S: ->machine->
R: ->machine\(\)\.

// do the same if via a reference
S: \.machine->
R: \.machine\(\)\.

// convert function parameters to running_machine &
S: running_machine \*machine([^;])
R: running_machine \&machine\1

// replace machine-> with machine.
S: machine->
R: machine\.

// replace &machine() with machine()
S: \&([()->a-z0-9_]+machine\(\))
R: \1

// sanity check: look for this used as a cast
(running_machine &)
// and change to this:
*(running_machine *)
2011-03-29 15:50:04 +00:00
Aaron Giles
202d7680a4 Created new enum type address_spacenum for specifying an address
space by index. Update functions and methods that accepted an
address space index to take an address_spacenum instead. Note that
this means you can't use a raw integer in ADDRESS_SPACE macros, so
instead of 0 use the enumerated AS_0.

Standardized the project on the shortened constants AS_* over the
older ADDRESS_SPACE_*. Removed the latter to prevent confusion.
Also centralized the location of these definitions to memory.h.
2011-03-27 07:37:24 +00:00
Aaron Giles
4b3aa02618 Added device_t::memory() to fetch a reference to the memory interface,
or assert if not present.

Split address_space::install_[legacy_]handler into 
install_[legacy_]read_handler, install_[legacy_]write_handler,
and install_[legacy_]readwrite_handler.

Added variants of address_space handler installers which don't take
mirror or mask parameters, since this is by far the most common case.

Deprecated API cleanup. Simple search & replace:
cpu_suspend                          ==> device_suspend
cpu_resume                           ==> device_resume
cpu_yield                            ==> device_yield
cpu_spin                             ==> device_spin
cpu_spinuntil_trigger                ==> device_spin_until_trigger
cpu_spinuntil_time                   ==> device_spin_until_time
cpu_spinuntil_int                    ==> device_spin_until_interrupt
cpu_eat_cycles                       ==> device_eat_cycles
cpu_adjust_icount                    ==> device_adjust_icount
cpu_triggerint                       ==> device_triggerint
cpu_set_input_line                   ==> device_set_input_line
cpu_set_input_line_vector            ==> device_set_input_line_vector
cpu_set_input_line_and_vector        ==> device_set_input_line_and_vector
cpu_set_irq_callback                 ==> device_set_irq_callback

More complex changes:
device_memory(device)                ==>  device->memory()
device_get_space(device, spacenum)   ==>  device->memory().space(spacenum)
cpu_get_address_space(cpu, spacenum) ==> cpu->memory().space(spacenum)
cputag_get_address_space(mach, tag, spacenum) ==> mach->device("tag")->memory().space(spacenum)
cputag_get_clock(mach, tag)          ==> mach->device("tag")->unscaled_clock()
cputag_set_clock(mach, tag, hz)      ==> mach->device("tag")->set_unscaled_clock(hz)

Some regex'es for the more prevalent cases above:
S: cpu_get_address_space( *)\(( *)([^,]+)( *), *
R: \3->memory().space\1\(\2
S: cputag_get_address_space( *)\(( *)([^,]+)( *),( *)([^,]+)( *), *
R: \3->device\1\(\2\6\7\)->memory().space\1\(\2
S: cputag_get_clock( *)\(( *)([^,]+)( *),( *)([^ )]+) *\)
R: \3->device\1\(\2\6\7\)->unscaled_clock\(\)
2011-03-27 01:19:26 +00:00
Miodrag Milanovic
569f818281 Input ports can now be added to device, names are formed as sub tags from parent device tag. [Miodrag Milanovic] 2011-02-13 17:45:31 +00:00
Miodrag Milanovic
fd5b5140a5 Removed short name as parameter from device_config this way it is not mandatory any more.
Most of files is rolled back to previous state. (no whatsnew)
2011-02-11 10:10:39 +00:00
Miodrag Milanovic
601056b130 - Added shortname to devices in order to make ROM loading per device possible. [Miodrag Milanovic]
- Updated all devices containing ROM regions to have short names and all modern devices too
- Created new validation to check existence of short name if device contain ROM region defined
2011-02-10 19:08:37 +00:00
Aaron Giles
0e627f1a54 Convert emu_timers to objects. Move implementation and management of
timers into the scheduler. Retain TIMER devices as a separate wrapper
in timer.c/.h. Inline wrappers are currently provided for all timer
operations; a future update will bulk clean these up.

Rather than using macros which hide generation of a string-ified name
for callback functions, the new methods require passing both a function
pointer plus a name string. A new macro FUNC() can be used to output
both, and another macro MFUNC() can be used to output a stub-wrapped
class member as a callback.

Also added a time() method on the machine, so that machine->time() gives
the current emulated time. A wrapper for timer_get_time is currently
provided but will be bulk replaced in the future.

For this update, convert all classic timer_alloc, timer_set, 
timer_pulse, and timer_call_after_resynch calls into method calls on 
the scheduler. 

For new device timers, added methods to the device_t class that make 
creating and managing these much simpler. Modern devices were updated
to use these.

Here are the regexes used; some manual cleanup (compiler-caught) will
be needed since regex doesn't handle nested parentheses cleanly

1. Convert timer_call_after_resynch calls
timer_call_after_resynch( *)\(( *)([^,;]+), *([^,;]+), *([^,;]+), *([^);]+)\)
\3->scheduler().synchronize\1\(\2FUNC(\6), \5, \4\)

2. Clean up trailing 0, NULL parameters
(synchronize[^;]+), 0, NULL\)
\1)

3. Clean up trailing NULL parameters
(synchronize[^;]+), NULL\)
\1)

4. Clean up completely empty parameter lists
synchronize\(FUNC\(NULL\)\)
synchronize()

5. Convert timer_set calls
timer_set( *)\(( *)([^,;]+), *([^,;]+), *([^,;]+), *([^,;]+), *([^);]+)\)
\3->scheduler().timer_set\1\(\2\4, FUNC(\7), \6, \5\)

6. Clean up trailing 0, NULL parameters
(timer_set[^;]+), 0, NULL\)
\1)

7. Clean up trailing NULL parameters
(timer_set[^;]+), NULL\)
\1)

8. Convert timer_set calls
timer_pulse( *)\(( *)([^,;]+), *([^,;]+), *([^,;]+), *([^,;]+), *([^);]+)\)
\3->scheduler().timer_pulse\1\(\2\4, FUNC(\7), \6, \5\)

9. Clean up trailing 0, NULL parameters
(timer_pulse[^;]+), 0, NULL\)
\1)

10. Clean up trailing NULL parameters
(timer_pulse[^;]+), NULL\)
\1)

11. Convert timer_alloc calls
timer_alloc( *)\(( *)([^,;]+), *([^,;]+), *([^);]+)\)
\3->scheduler().timer_alloc\1\(\2FUNC(\4), \5\)

12. Clean up trailing NULL parameters
(timer_alloc[^;]+), NULL\)
\1)

13. Clean up trailing 0 parameters
(timer_alloc[^;]+), 0\)
\1)

14. Fix oddities introduced
\&m_machine->scheduler()
m_machine.scheduler()
2011-02-06 07:15:01 +00:00
Aaron Giles
ba6d1bd8a3 MDRV_* -> MCFG_*
There hasn't been a machine driver for many years.
2010-12-31 21:18:45 +00:00
Aaron Giles
1dc0cbbda6 For legacy CPUs, track whether we have initialized, and if we haven't,
don't call the exit callback in the destructor.
2010-08-26 16:00:27 +00:00
Aaron Giles
47dd9fe568 De-converted MACHINE_DRIVER from tokens back to constructor functions, regaining
type safety. If legacy devices still use inline data, those types are not checked.
However, new devices no longer have access to the generic m_inline_data. Instead
their MDRV_* macros should map to calls to static functions in the device config
class which downcast a generic device_config to the specific device config, and
then set the appropriate values. This is not to be done inline in order to prevent
further code bloat in the constructors. See eeprom/7474/i2cmem/okim6295 for examples.

#ifdef'ed several unused machine driver definitions that weren't referenced.
2010-08-26 15:21:19 +00:00
Aaron Giles
fe47da274e Return to type safety. Changed address maps back into functions that build
up the definition, rather than the whole tokenizing system, which lost type
checking. Added a new module addrmap.c which implements the address map
classes, and changed the macros to call methods on the address_map and
address_map_entry classes which are strongly typed.

Fixed a few incorrectly specified memory map entries along the way. Please
double-check to make sure the behavior is expected in: twincobr.c, lordgun.c,
galaxold.c.

This change also means that since the address_maps are now constructor
functions, they are detected when not used, so a number of #ifdef UNUSED_CODE
were added around dangling address map definitions.

Also included with this change:
- removed cputag_clocks_to_attotime() and cputag_attotime_to_clocks() in
   favor of just expanding the class
- same for cputag_suspend() and cputag_resume()
2010-08-01 21:04:03 +00:00
Aaron Giles
4df35a02d9 Whoops, forgot this. 2010-07-07 21:04:32 +00:00
Aaron Giles
20fe094c0e Remove the global clock accessors and cpu_* aliases:
cpu_get_clock -> device_get_clock
cpu_set_clock -> device_set_clock
cpu_get_clockscale -> device_get_clock_scale
cpu_set_clockscale -> device_set_clock_scale

Search: device_get_clock([ \t]*)\(([ \t]*)([^)]+)
Replace: \3->unscaled_clock\1\(\2

Search: device_set_clock([ \t]*)\(([ \t]*)([^,]+),[ \t]*
Replace: \3->set_unscaled_clock\1\(\2

Search: device_get_clock_scale([ \t]*)\(([ \t]*)([^)]+)
Replace: \3->clock_scale\1\(\2

Search: device_set_clock_scale([ \t]*)\(([ \t]*)([^,]+),[ \t]*
Replace: \3->set_clock_scale\1\(\2
2010-07-07 21:01:36 +00:00
Aaron Giles
30662dcdef Cleanups and version bump. 2010-07-06 17:30:28 +00:00
Aaron Giles
5d21c672af Moved debugging structure away from CPUs only and attached to all
devices. Debugger now creates one for each device. C++-ified most
debugger operations to hang off the debugging class, and updated
most callers. This still needs a little cleanup, but it fixes most
issues introduced when the CPUs were moved to their own devices.

Got rid of cpu_count, cpu_first, cpu_next, etc. as they were badly 
broken. Also removed cpu_is_executing, cpu_is_suspended,
cpu_get_local_time, and cpu_abort_timeslice.

Some minor name changes:
  state_value() -> state()
  state_set_value() -> set_state()
2010-07-06 00:52:36 +00:00
Aaron Giles
c70c5fee5a Created CPU-specific device types for all CPUs, using new macros
DECLARE_LEGACY_CPU_DEVICE and DEFINE_LEGACY_CPU_DEVICE. Changed CPUs
to be their own device types, rather than all of type CPU with a
special internal subtype. Note that as part of this process I removed
the CPU_ prefix from the ALL-CAPS device name, so CPU_Z80 is just
plain old Z80 now. This required changing a couple of names like
8080 to I8080 so that there was an alphabetic first character.

Added memory interfaces to the list of fast-access interfaces. To do
this properly I had to add a separate method to devices which is
called immediately after construction, when it is possible to perform
dynamic_casts on fully-constructed objects. (This is just internal,
no changes necessary to the devices themselves.)

Some additional notes:
 * SH2 and SH4 had typedefs that conflicted with their CPU_-less names
    so I bulk renamed to structures to sh2_state and sh4_state; RB, feel
    free to choose alternate names if you don't like 'em
 * SCSP was caught doing something to the 3rd indexed CPU. Since several
    systems that use SCSP don't even have 3 CPUs, I had no idea what
    this was supposed to do, so I changed to it reference "audiocpu"
    assuming that stv was the assumed target. This is really gross and
    should be a configuration parameter, not a hard-coded assumption.
2010-07-03 00:12:44 +00:00
Aaron Giles
46e30c4f68 Remove obsolete type. 2010-07-02 15:54:09 +00:00
Aaron Giles
af9e6f531f Kill cpu_get_sp(). 2010-07-02 13:29:03 +00:00
Aaron Giles
7bdb4bf083 Use UINT64s for converting cycles <-> clocks. 2010-07-01 05:01:12 +00:00
Aaron Giles
de771cbfeb Remove the following functions:
cpu_get_total_cycles()   == cpudevice->total_cycles()
  cpu_clocks_to_attotime() == cpudevice->cycles_to_attotime()
  cpu_attotime_to_clocks() == cpudevice->attotime_to_cycles()

In some cases, I updated existing code that fetched and cached 
devices to fetch them as cpu_device so that these can be called
without casting.

In other cases, I did the quick & dirty thing which was to downcast
a generic device to a cpu_device and then call the function.

Note that cpu_clocks_to_attotime() and cpu_attotime_to_clocks()
were previously mapping to the device-level functions
clocks_to_attotime() and attotime_to_clocks(). This was different
behavior than before the big devices change, so with this update
I have fixed it to match the previous behavior (i.e., map cycles
not clocks).

This may impact timing of drivers that used these functions on
CPUs that have clock dividers or multipliers.
2010-07-01 00:34:46 +00:00
Miodrag Milanovic
63e8e8fe98 Modified way device_type constants are defined in order to get unidasm compile [Miodrag Milanovic] 2010-06-29 09:02:17 +00:00
Aaron Giles
41b9dbb9ac Made the machine_config a proper object. Added detokenize method to
this object which can be called multiple times to append new devices
after the initial machine configuration is set up. Updated member
variables to match new naming convention.

Changed the running_machine to take a constructed machine_config
object in the constructor, instead of creating one itself, for
consistency. Also added machine->total_colors() as a shortcut to 
machine->config->m_total_colors.
2010-06-28 06:40:44 +00:00
Aaron Giles
50767de707 Changed device name from an overridable function to a parameter passed to
the device_config constructor. In situations where the proper name is not 
known at construction time, a generic name can be specified and then 
overridden later once the configuration is complete.
2010-06-25 15:30:51 +00:00
Aaron Giles
861db1eb49 Cleanups and version bump. 2010-06-17 06:55:54 +00:00
Aaron Giles
b8f916e17e Change cpu_device into a base class. Rename old cpu_device to legacy_cpu_device.
Update interfaces as appropriate.
2010-06-17 03:33:24 +00:00
Aaron Giles
019793c78f Cache pointer to exit function to prevent crashes on teardown. 2010-06-09 22:02:21 +00:00
Aaron Giles
eba2c14060 Change cpu execute function to just use the icount stuffed by
the scheduler, rather than manging an incoming cycle count. It was
confusing to have multiple sources of cycle counts.
2010-06-09 16:20:50 +00:00
Aaron Giles
5e04468569 Changed CPU callbacks to use cpu_device, eliminating a bunch of casting. 2010-06-08 17:35:49 +00:00
Aaron Giles
100564d412 WARNING: There are likely to be regressions in both functionality and
performance as a result of this change. Do not panic; report issues to the
list in the short term and I will look into them. There are probably also
some details I forgot to mention. Please ask questions if anything is not
clear.

NOTE: This is a major internal change to the way devices are handled in
MAME. There is a small impact on drivers, but the bulk of the changes are
to the devices themselves. Full documentation on the new device handling
is in progress at http://mamedev.org/devwiki/index.php/MAME_Device_Basics

Defined two new casting helpers: [Aaron Giles]

  downcast<type>(value) should be used for safe and efficient downcasting
  from a base class to a derived class. It wraps static_cast<> by adding
  an assert that a matching dynamic_cast<> returns the same result in 
  debug builds.
  
  crosscast<type>(value) should be used for safe casting from one type to
  another in multiple inheritance scenarios. It compiles to a 
  dynamic_cast<> plus an assert on the result. Since it does not optimize
  down to static_cast<>, you should prefer downcast<> over crosscast<>
  when you can.
  
Redefined running_device to be a proper C++ class (now called device_t).
Same for device_config (still called device_config). All devices and
device_configs must now be derived from these base classes. This means
each device type now has a pair of its own unique classes that describe
the device. Drivers are encouraged to use the specific device types
instead of the generic running_device or device_t classes. Drivers that
have a state class defined in their header file are encouraged to use
initializers off the constructor to locate devices. [Aaron Giles]

Removed the following fields from the device and device configuration
classes as they never were necessary or provided any use: device class,
device family, source file, version, credits. [Aaron Giles]

Added templatized variant of machine->device() which performs a downcast
as part of the device fetch. Thus machine->device<timer_device>("timer")
will locate a device named "timer", downcast it to a timer_device, and
assert if the downcast fails. [Aaron Giles]

Removed most publically accessible members of running_device/device_t in
favor of inline accessor functions. The only remaining public member is
machine. Thus all references to device->type are now device->type(), etc.
[Aaron Giles]

Created a number of device interface classes which are designed to be mix-
ins for the device classes, providing specific extended functionality and
information. There are standard interface classes for sound, execution,
state, nvram, memory, and disassembly. Devices can opt into 0 or more of
these classes. [Aaron Giles]

Converted the classic CPU device to a standard device that uses the
execution, state, memory, and disassembly interfaces. Used this new class
(cpu_device) to implement the existing CPU device interface. In the future
it will be possible to convert each CPU core to its own device type, but 
for now they are still all CPU devices with a cpu_type() that specifies
exactly which kind of CPU. [Aaron Giles] 

Created a new header devlegcy.h which wraps the old device interface using
some special template classes. To use these with an existing device,
simply remove from the device header the DEVICE_GET_INFO() declaration and
the #define mapping the ALL_CAPS name to the DEVICE_GET_INFO. In their
place #include "devlegcy.h" and use the DECLARE_LEGACY_DEVICE() macro.
In addition, there is a DECLARE_LEGACY_SOUND_DEVICE() macro for wrapping
existing sound devices into new-style devices, and a 
DECLARE_LEGACY_NVRAM_DEVICE() for wrapping NVRAM devices. Also moved the
token and inline_config members to the legacy device class, as these are
not used in modern devices. [Aaron Giles]

Converted the standard base devices (VIDEO_SCREEN, SPEAKER, and TIMER) 
from legacy devices to the new C++ style. Also renamed VIDEO_SCREEN to
simply SCREEN. The various global functions that were previously used to
access information or modify the state of these devices are now replaced
by methods on the device classes. Specifically:

  video_screen_configure()             == screen->configure()
  video_screen_set_visarea()           == screen->set_visible_area()
  video_screen_update_partial()        == screen->update_partial()
  video_screen_update_now()            == screen->update_now()
  video_screen_get_vpos()              == screen->vpos()
  video_screen_get_hpos()              == screen->hpos()
  video_screen_get_vblank()            == screen->vblank()
  video_screen_get_hblank()            == screen->hblank()
  video_screen_get_width()             == screen->width()
  video_screen_get_height()            == screen->height()
  video_screen_get_visible_area()      == screen->visible_area()
  video_screen_get_time_until_pos()    == screen->time_until_pos()
  video_screen_get_time_until_vblank_start() == 
                                 screen->time_until_vblank_start()
  video_screen_get_time_until_vblank_end() == 
                                 screen->time_until_vblank_end()
  video_screen_get_time_until_update() == screen->time_until_update()
  video_screen_get_scan_period()       == screen->scan_period()
  video_screen_get_frame_period()      == screen->frame_period()
  video_screen_get_frame_number()      == screen->frame_number()

  timer_device_adjust_oneshot()        == timer->adjust()
  timer_device_adjust_periodic()       == timer->adjust()
  timer_device_reset()                 == timer->reset()
  timer_device_enable()                == timer->enable()
  timer_device_enabled()               == timer->enabled()
  timer_device_get_param()             == timer->param()
  timer_device_set_param()             == timer->set_param()
  timer_device_get_ptr()               == timer->get_ptr()
  timer_device_set_ptr()               == timer->set_ptr()
  timer_device_timeelapsed()           == timer->time_elapsed()
  timer_device_timeleft()              == timer->time_left()
  timer_device_starttime()             == timer->start_time()
  timer_device_firetime()              == timer->fire_time()

Updated all drivers that use the above functions to fetch the specific
device type (timer_device or screen_device) and call the appropriate
method. [Aaron Giles]

Changed machine->primary_screen and the 'screen' parameter to VIDEO_UPDATE
to specifically pass in a screen_device object. [Aaron Giles]

Defined a new custom interface for the Z80 daisy chain. This interface
behaves like the standard interfaces, and can be added to any device that
implements the Z80 daisy chain behavior. Converted all existing Z80 daisy
chain devices to new-style devices that inherit this interface.
[Aaron Giles]

Changed the way CPU state tables are built up. Previously, these were data
structures defined by a CPU core which described all the registers and how
to output them. This functionality is now part of the state interface and
is implemented via the device_state_entry class. Updated all CPU cores
which were using the old data structure to use the new form. The syntax is
currently awkward, but will be cleaner for CPUs that are native new 
devices. [Aaron Giles]

Converted the okim6295 and eeprom devices to the new model. These were
necessary because they both require multiple interfaces to operate and it
didn't make sense to create legacy device templates for these single cases.
(okim6295 needs the sound interface and the memory interface, while eeprom
requires both the nvram and memory interfaces). [Aaron Giles]

Changed parameters in a few callback functions from pointers to references
in situations where they are guaranteed to never be NULL. [Aaron Giles]

Removed MDRV_CPU_FLAGS() which was only used for disabling a CPU. Changed
it to MDRV_DEVICE_DISABLE() instead. Updated drivers. [Aaron Giles]

Reorganized the token parsing for machine configurations. The core parsing
code knows how to create/replace/remove devices, but all device token
parsing is now handled in the device_config class, which in turn will make
use of any interface classes or device-specific token handling for custom
token processing. [Aaron Giles]

Moved many validity checks out of validity.c and into the device interface
classes. For example, address space validation is now part of the memory
interface class. [Aaron Giles]

Consolidated address space parameters (bus width, endianness, etc.) into
a single address_space_config class. Updated all code that queried for
address space parameters to use the new mechanism. [Aaron Giles]
2010-06-08 06:09:57 +00:00