mirror of
https://github.com/holub/mame
synced 2025-04-25 09:50:04 +03:00
updated upd7002 to use delegates. nw.
This commit is contained in:
parent
94220382ed
commit
b605b791dd
@ -21,33 +21,15 @@ upd7002_device::upd7002_device(const machine_config &mconfig, const char *tag, d
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// device_config_complete - perform any
|
||||
// operations now that the configuration is
|
||||
// complete
|
||||
//-------------------------------------------------
|
||||
|
||||
void upd7002_device::device_config_complete()
|
||||
{
|
||||
// inherit a copy of the static data
|
||||
const upd7002_interface *intf = reinterpret_cast<const upd7002_interface *>(static_config());
|
||||
if (intf != NULL)
|
||||
*static_cast<upd7002_interface *>(this) = *intf;
|
||||
|
||||
// or initialize to defaults if none provided
|
||||
else
|
||||
{
|
||||
get_analogue_func = NULL;
|
||||
eoc_func = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// device_start - device-specific startup
|
||||
//-------------------------------------------------
|
||||
|
||||
void upd7002_device::device_start()
|
||||
{
|
||||
m_get_analogue_cb.bind_relative_to(*owner());
|
||||
m_eoc_cb.bind_relative_to(*owner());
|
||||
|
||||
// register for state saving
|
||||
save_item(NAME(m_status));
|
||||
save_item(NAME(m_data1));
|
||||
@ -99,7 +81,7 @@ void upd7002_device::device_timer(emu_timer &timer, device_timer_id id, int para
|
||||
|
||||
// call the EOC function with EOC from status
|
||||
// eoc_r(0) this has just been set to 0
|
||||
if (eoc_func) (eoc_func)(this,0);
|
||||
if (!m_eoc_cb.isnull()) m_eoc_cb(0);
|
||||
m_conversion_counter=0;
|
||||
}
|
||||
break;
|
||||
@ -153,13 +135,13 @@ WRITE8_MEMBER( upd7002_device::write )
|
||||
|
||||
// call the EOC function with EOC from status
|
||||
// eoc_r(0) this has just been set to 1
|
||||
if (eoc_func) eoc_func(this, 1);
|
||||
if (!m_eoc_cb.isnull()) m_eoc_cb(1);
|
||||
|
||||
/* the uPD7002 works by sampling the analogue value at the start of the conversion
|
||||
so it is read hear and stored until the end of the A to D conversion */
|
||||
|
||||
// this function should return a 16 bit value.
|
||||
m_digitalvalue = get_analogue_func(this, m_status & 0x03);
|
||||
m_digitalvalue = m_get_analogue_cb(m_status & 0x03);
|
||||
|
||||
m_conversion_counter++;
|
||||
|
||||
|
@ -15,37 +15,32 @@
|
||||
TYPE DEFINITIONS
|
||||
***************************************************************************/
|
||||
|
||||
typedef int (*upd7002_get_analogue_func)(device_t *device, int channel_number);
|
||||
#define UPD7002_GET_ANALOGUE(name) int name(device_t *device, int channel_number )
|
||||
typedef device_delegate<int (int channel_number)> upd7002_get_analogue_delegate;
|
||||
#define UPD7002_GET_ANALOGUE(name) int name(int channel_number)
|
||||
|
||||
typedef void (*upd7002_eoc_func)(device_t *device, int data);
|
||||
#define UPD7002_EOC(name) void name(device_t *device, int data )
|
||||
typedef device_delegate<void (int data)> upd7002_eoc_delegate;
|
||||
#define UPD7002_EOC(name) void name(int data)
|
||||
|
||||
|
||||
struct upd7002_interface
|
||||
{
|
||||
upd7002_get_analogue_func get_analogue_func;
|
||||
upd7002_eoc_func eoc_func;
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
MACROS
|
||||
***************************************************************************/
|
||||
|
||||
class upd7002_device : public device_t,
|
||||
public upd7002_interface
|
||||
class upd7002_device : public device_t
|
||||
{
|
||||
public:
|
||||
upd7002_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
|
||||
~upd7002_device() {}
|
||||
|
||||
DECLARE_READ8_MEMBER ( eoc_r );
|
||||
DECLARE_READ8_MEMBER ( read );
|
||||
DECLARE_WRITE8_MEMBER ( write );
|
||||
static void set_get_analogue_callback(device_t &device, upd7002_get_analogue_delegate callback) { downcast<upd7002_device &>(device).m_get_analogue_cb = callback; }
|
||||
static void set_eoc_callback(device_t &device, upd7002_eoc_delegate callback) { downcast<upd7002_device &>(device).m_eoc_cb = callback; }
|
||||
|
||||
DECLARE_READ8_MEMBER(eoc_r);
|
||||
DECLARE_READ8_MEMBER(read);
|
||||
DECLARE_WRITE8_MEMBER(write);
|
||||
|
||||
protected:
|
||||
// device-level overrides
|
||||
virtual void device_config_complete();
|
||||
virtual void device_start();
|
||||
virtual void device_reset();
|
||||
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
|
||||
@ -84,6 +79,9 @@ private:
|
||||
only then at the end of the second conversion will the conversion complete function run */
|
||||
int m_conversion_counter;
|
||||
|
||||
upd7002_get_analogue_delegate m_get_analogue_cb;
|
||||
upd7002_eoc_delegate m_eoc_cb;
|
||||
|
||||
enum
|
||||
{
|
||||
TIMER_CONVERSION_COMPLETE
|
||||
@ -97,9 +95,10 @@ extern const device_type UPD7002;
|
||||
DEVICE CONFIGURATION MACROS
|
||||
***************************************************************************/
|
||||
|
||||
#define MCFG_UPD7002_ADD(_tag, _intrf) \
|
||||
MCFG_DEVICE_ADD(_tag, UPD7002, 0) \
|
||||
MCFG_DEVICE_CONFIG(_intrf)
|
||||
#define MCFG_UPD7002_GET_ANALOGUE_CB(_class, _method) \
|
||||
upd7002_device::set_get_analogue_callback(*device, upd7002_get_analogue_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#define MCFG_UPD7002_EOC_CB(_class, _method) \
|
||||
upd7002_device::set_eoc_callback(*device, upd7002_eoc_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#endif /* UPD7002_H_ */
|
||||
|
@ -764,7 +764,9 @@ static MACHINE_CONFIG_DERIVED( bbcb, bbca )
|
||||
MCFG_VIA6522_IRQ_HANDLER(WRITELINE(bbc_state, bbcb_via_user_irq_w))
|
||||
|
||||
/* adc */
|
||||
MCFG_UPD7002_ADD("upd7002", bbc_uPD7002)
|
||||
MCFG_DEVICE_ADD("upd7002", UPD7002, 0)
|
||||
MCFG_UPD7002_GET_ANALOGUE_CB(bbc_state, BBC_get_analogue_input)
|
||||
MCFG_UPD7002_EOC_CB(bbc_state, BBC_uPD7002_EOC)
|
||||
|
||||
/* printer */
|
||||
MCFG_CENTRONICS_ADD("centronics", centronics_printers, "image")
|
||||
@ -821,7 +823,9 @@ static MACHINE_CONFIG_DERIVED( bbcb_us, bbca )
|
||||
MCFG_VIA6522_IRQ_HANDLER(WRITELINE(bbc_state, bbcb_via_user_irq_w))
|
||||
|
||||
/* adc */
|
||||
MCFG_UPD7002_ADD("upd7002", bbc_uPD7002)
|
||||
MCFG_DEVICE_ADD("upd7002", UPD7002, 0)
|
||||
MCFG_UPD7002_GET_ANALOGUE_CB(bbc_state, BBC_get_analogue_input)
|
||||
MCFG_UPD7002_EOC_CB(bbc_state, BBC_uPD7002_EOC)
|
||||
|
||||
/* printer */
|
||||
MCFG_CENTRONICS_ADD("centronics", centronics_printers, "image")
|
||||
@ -965,7 +969,9 @@ static MACHINE_CONFIG_START( bbcm, bbc_state )
|
||||
MCFG_CLOCK_SIGNAL_HANDLER(WRITELINE(bbc_state, write_acia_clock))
|
||||
|
||||
/* adc */
|
||||
MCFG_UPD7002_ADD("upd7002", bbc_uPD7002)
|
||||
MCFG_DEVICE_ADD("upd7002", UPD7002, 0)
|
||||
MCFG_UPD7002_GET_ANALOGUE_CB(bbc_state, BBC_get_analogue_input)
|
||||
MCFG_UPD7002_EOC_CB(bbc_state, BBC_uPD7002_EOC)
|
||||
|
||||
/* system via */
|
||||
MCFG_DEVICE_ADD("via6522_0", VIA6522, 1000000)
|
||||
|
@ -48,6 +48,10 @@ public:
|
||||
m_via6522_1(*this, "via6522_1"),
|
||||
m_upd7002(*this, "upd7002"),
|
||||
m_i8271(*this, "i8271"),
|
||||
m_joy0(*this, "JOY0"),
|
||||
m_joy1(*this, "JOY1"),
|
||||
m_joy2(*this, "JOY2"),
|
||||
m_joy3(*this, "JOY3"),
|
||||
m_region_maincpu(*this, "maincpu"),
|
||||
m_region_user1(*this, "user1"),
|
||||
m_region_user2(*this, "user2"),
|
||||
@ -152,9 +156,11 @@ public:
|
||||
DECLARE_WRITE_LINE_MEMBER(write_dcd_serial);
|
||||
DECLARE_WRITE_LINE_MEMBER(write_cts_serial);
|
||||
DECLARE_INPUT_CHANGED_MEMBER( trigger_reset );
|
||||
|
||||
DECLARE_WRITE_LINE_MEMBER(bbc_i8271_interrupt);
|
||||
|
||||
UPD7002_GET_ANALOGUE(BBC_get_analogue_input);
|
||||
UPD7002_EOC(BBC_uPD7002_EOC);
|
||||
|
||||
int exp_rom_load(device_image_interface &image, int index);
|
||||
DECLARE_DEVICE_IMAGE_LOAD_MEMBER( bbc_exp_rom );
|
||||
DECLARE_DEVICE_IMAGE_LOAD_MEMBER( bbcm_cart );
|
||||
@ -176,6 +182,7 @@ public: // HACK FOR MC6845
|
||||
optional_device<via6522_device> m_via6522_1;
|
||||
optional_device<upd7002_device> m_upd7002;
|
||||
optional_device<i8271_device> m_i8271;
|
||||
required_ioport m_joy0, m_joy1, m_joy2, m_joy3;
|
||||
|
||||
required_memory_region m_region_maincpu;
|
||||
required_memory_region m_region_user1;
|
||||
@ -417,8 +424,4 @@ extern const mc6845_interface bbc_mc6845_intf;
|
||||
extern const i8271_interface bbc_i8271_interface;
|
||||
extern const wd17xx_interface bbc_wd17xx_interface;
|
||||
|
||||
/* tape support */
|
||||
|
||||
extern const upd7002_interface bbc_uPD7002;
|
||||
|
||||
#endif /* BBC_H_ */
|
||||
|
@ -1153,36 +1153,28 @@ WRITE_LINE_MEMBER(bbc_state::bbcb_via_user_irq_w)
|
||||
BBC Joystick Support
|
||||
**************************************/
|
||||
|
||||
static UPD7002_GET_ANALOGUE(BBC_get_analogue_input)
|
||||
UPD7002_GET_ANALOGUE(bbc_state::BBC_get_analogue_input)
|
||||
{
|
||||
switch(channel_number)
|
||||
switch (channel_number)
|
||||
{
|
||||
case 0:
|
||||
return ((0xff-device->machine().root_device().ioport("JOY0")->read())<<8);
|
||||
return ((0xff - m_joy0->read()) << 8);
|
||||
case 1:
|
||||
return ((0xff-device->machine().root_device().ioport("JOY1")->read())<<8);
|
||||
return ((0xff - m_joy1->read()) << 8);
|
||||
case 2:
|
||||
return ((0xff-device->machine().root_device().ioport("JOY2")->read())<<8);
|
||||
return ((0xff - m_joy2->read()) << 8);
|
||||
case 3:
|
||||
return ((0xff-device->machine().root_device().ioport("JOY3")->read())<<8);
|
||||
return ((0xff - m_joy3->read()) << 8);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static UPD7002_EOC(BBC_uPD7002_EOC)
|
||||
UPD7002_EOC(bbc_state::BBC_uPD7002_EOC)
|
||||
{
|
||||
via6522_device *via_0 = device->machine().device<via6522_device>("via6522_0");
|
||||
via_0->write_cb1(data);
|
||||
m_via6522_0->write_cb1(data);
|
||||
}
|
||||
|
||||
const upd7002_interface bbc_uPD7002 =
|
||||
{
|
||||
BBC_get_analogue_input,
|
||||
BBC_uPD7002_EOC
|
||||
};
|
||||
|
||||
|
||||
/***************************************
|
||||
BBC 2C199 Serial Interface Cassette
|
||||
****************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user