mirror of
https://github.com/holub/mame
synced 2025-07-05 09:57:47 +03:00
dc-ctrl.cpp: better encapsulation/inheritance (nw)
This commit is contained in:
parent
f74f8b29dc
commit
bf064046bd
@ -5,23 +5,27 @@
|
||||
|
||||
/*******************************
|
||||
*
|
||||
* Dreamcast Controller
|
||||
* Common abstract class
|
||||
*
|
||||
******************************/
|
||||
|
||||
DEFINE_DEVICE_TYPE(DC_CONTROLLER, dc_controller_device, "dcctrl", "Dreamcast Controller")
|
||||
|
||||
dc_controller_device::dc_controller_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
|
||||
maple_device(mconfig, DC_CONTROLLER, tag, owner, clock)
|
||||
dc_common_device::dc_common_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
|
||||
maple_device(mconfig, type, tag, owner, clock)
|
||||
{
|
||||
memset(port_tag, 0, sizeof(port_tag));
|
||||
|
||||
id = "Dreamcast Controller";
|
||||
license = "Produced By or Under License From SEGA ENTERPRISES,LTD.";
|
||||
versions = "Version 1.010,1998/09/28,315-6211-AB ,Analog Module : The 4th Edition.5/8 +DF";
|
||||
}
|
||||
|
||||
void dc_controller_device::maple_w(const uint32_t *data, uint32_t in_size)
|
||||
void dc_common_device::device_start()
|
||||
{
|
||||
maple_device::device_start();
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
port[i] = ioport(port_tag[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void dc_common_device::maple_w(const uint32_t *data, uint32_t in_size)
|
||||
{
|
||||
switch(data[0] & 0xff) {
|
||||
case 0x01: // Device request
|
||||
@ -51,6 +55,22 @@ void dc_controller_device::maple_w(const uint32_t *data, uint32_t in_size)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************
|
||||
*
|
||||
* Dreamcast Controller
|
||||
*
|
||||
******************************/
|
||||
|
||||
DEFINE_DEVICE_TYPE(DC_CONTROLLER, dc_controller_device, "dcctrl", "Dreamcast Controller")
|
||||
|
||||
dc_controller_device::dc_controller_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
|
||||
dc_common_device(mconfig, DC_CONTROLLER, tag, owner, clock)
|
||||
{
|
||||
id = "Dreamcast Controller";
|
||||
license = "Produced By or Under License From SEGA ENTERPRISES,LTD.";
|
||||
versions = "Version 1.010,1998/09/28,315-6211-AB ,Analog Module : The 4th Edition.5/8 +DF";
|
||||
}
|
||||
|
||||
void dc_controller_device::fixed_status(uint32_t *dest)
|
||||
{
|
||||
@ -94,16 +114,6 @@ void dc_controller_device::read(uint32_t *dest)
|
||||
((port[7] ? port[7]->read() : 0x80) << 24);
|
||||
}
|
||||
|
||||
void dc_controller_device::device_start()
|
||||
{
|
||||
maple_device::device_start();
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
port[i] = ioport(port_tag[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************
|
||||
*
|
||||
* Dreamcast Keyboard
|
||||
@ -113,54 +123,20 @@ void dc_controller_device::device_start()
|
||||
DEFINE_DEVICE_TYPE(DC_KEYBOARD, dc_keyboard_device, "dckb", "Dreamcast Keyboard")
|
||||
|
||||
dc_keyboard_device::dc_keyboard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
|
||||
maple_device(mconfig, DC_KEYBOARD, tag, owner, clock)
|
||||
dc_common_device(mconfig, DC_KEYBOARD, tag, owner, clock)
|
||||
{
|
||||
memset(port_tag, 0, sizeof(port_tag));
|
||||
|
||||
id = "92key Keyboard for JPN";
|
||||
license = "Produced By or Under License From SEGA ENTERPRISES,LTD.";
|
||||
versions = "Version 1.000,1998/06/12,315-6215-AD ,Key Scan Module: The 1st Edition. 05/20";
|
||||
}
|
||||
|
||||
void dc_keyboard_device::maple_w(const uint32_t *data, uint32_t in_size)
|
||||
{
|
||||
switch(data[0] & 0xff) {
|
||||
case 0x01: // Device request
|
||||
reply_start(5, 0x20, 29);
|
||||
fixed_status(reply_buffer+1);
|
||||
reply_ready_with_delay();
|
||||
break;
|
||||
|
||||
case 0x02: // All status request
|
||||
reply_start(6, 0x20, 49);
|
||||
fixed_status(reply_buffer+1);
|
||||
free_status(reply_buffer+29);
|
||||
reply_ready_with_delay();
|
||||
break;
|
||||
|
||||
case 0x03: // reset - we're stateless where it matters
|
||||
reply_start(7, 0x20, 0);
|
||||
reply_ready_with_delay();
|
||||
break;
|
||||
|
||||
case 0x09: // get condition
|
||||
if(1 || (in_size >= 2 && data[1] == 0x01000000)) {
|
||||
reply_start(8, 0x20, 4);
|
||||
read(reply_buffer+1);
|
||||
reply_ready_with_delay();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dc_keyboard_device::fixed_status(uint32_t *dest)
|
||||
{
|
||||
// 00000040 00102000 0800000000000000000
|
||||
dest[0] = 0x40000000; // Keyboard
|
||||
dest[1] = 0x00201000; // 1st function
|
||||
dest[2] = 0x00000008; // No 2nd function
|
||||
dest[3] = 0x00000000; // No 3rd function
|
||||
dest[4] = 0x00000002; // Japan region
|
||||
dest[4] = 0x00000002; // Japan region, no expansion
|
||||
copy_with_spaces(((uint8_t *)dest) + 18, id, 30);
|
||||
copy_with_spaces(((uint8_t *)dest) + 48, license, 60);
|
||||
dest[27] = 0x0190015e; // standby 35mA, max 40mA
|
||||
@ -187,13 +163,3 @@ void dc_keyboard_device::read(uint32_t *dest)
|
||||
((port[7] ? port[7]->read() : 0) << 24);
|
||||
}
|
||||
|
||||
void dc_keyboard_device::device_start()
|
||||
{
|
||||
maple_device::device_start();
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
port[i] = ioport(port_tag[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,29 +9,29 @@
|
||||
|
||||
#define MCFG_DC_CONTROLLER_ADD(_tag, _host_tag, _host_port, d0, d1, a0, a1, a2, a3, a4, a5) \
|
||||
MCFG_MAPLE_DEVICE_ADD(_tag, DC_CONTROLLER, 0, _host_tag, _host_port) \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(0, d0); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(1, d1); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(2, a0); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(3, a1); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(4, a2); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(5, a3); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(6, a4); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(7, a5);
|
||||
downcast<dc_common_device &>(*device).set_port_tag(0, d0); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(1, d1); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(2, a0); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(3, a1); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(4, a2); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(5, a3); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(6, a4); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(7, a5);
|
||||
|
||||
#define MCFG_DC_CONTROLLER_SET_ID(id) \
|
||||
downcast<dc_controller_device &>(*device).set_id(id);
|
||||
downcast<dc_common_device &>(*device).set_id(id);
|
||||
|
||||
#define MCFG_DC_CONTROLLER_SET_LICENSE(license) \
|
||||
downcast<dc_controller_device &>(*device).set_license(license);
|
||||
downcast<dc_common_device &>(*device).set_license(license);
|
||||
|
||||
#define MCFG_DC_CONTROLLER_SET_VERSIONS(versions) \
|
||||
ddowncast<dc_controller_device &>(*device).set_versions(versions);
|
||||
ddowncast<dc_common_device &>(*device).set_versions(versions);
|
||||
|
||||
class dc_controller_device : public maple_device
|
||||
class dc_common_device : public maple_device
|
||||
{
|
||||
public:
|
||||
// construction/destruction
|
||||
dc_controller_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
|
||||
dc_common_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
|
||||
|
||||
void set_port_tag(int port, const char *tag) { port_tag[port] = tag; }
|
||||
void set_id(const char *new_id) { id = new_id; }
|
||||
@ -44,50 +44,52 @@ protected:
|
||||
// device-level overrides
|
||||
virtual void device_start() override;
|
||||
|
||||
private:
|
||||
void fixed_status(uint32_t *dest);
|
||||
void free_status(uint32_t *dest);
|
||||
void read(uint32_t *dest);
|
||||
|
||||
const char *port_tag[8];
|
||||
const char *id, *license, *versions;
|
||||
|
||||
ioport_port *port[8];
|
||||
|
||||
virtual void fixed_status(uint32_t *dest) = 0;
|
||||
virtual void free_status(uint32_t *dest) = 0;
|
||||
virtual void read(uint32_t *dest) = 0;
|
||||
};
|
||||
|
||||
class dc_controller_device : public dc_common_device
|
||||
{
|
||||
public:
|
||||
// construction/destruction
|
||||
dc_controller_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
|
||||
|
||||
private:
|
||||
void fixed_status(uint32_t *dest) override;
|
||||
void free_status(uint32_t *dest) override;
|
||||
void read(uint32_t *dest) override;
|
||||
};
|
||||
|
||||
#define MCFG_DC_KEYBOARD_ADD(_tag, _host_tag, _host_port, d0, d1, a0, a1, a2, a3, a4, a5) \
|
||||
MCFG_MAPLE_DEVICE_ADD(_tag, DC_KEYBOARD, 0, _host_tag, _host_port) \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(0, d0); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(1, d1); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(2, a0); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(3, a1); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(4, a2); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(5, a3); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(6, a4); \
|
||||
downcast<dc_controller_device &>(*device).set_port_tag(7, a5);
|
||||
downcast<dc_common_device &>(*device).set_port_tag(0, d0); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(1, d1); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(2, a0); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(3, a1); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(4, a2); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(5, a3); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(6, a4); \
|
||||
downcast<dc_common_device &>(*device).set_port_tag(7, a5);
|
||||
|
||||
|
||||
class dc_keyboard_device : public maple_device
|
||||
class dc_keyboard_device : public dc_common_device
|
||||
{
|
||||
public:
|
||||
// construction/destruction
|
||||
dc_keyboard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
|
||||
|
||||
void maple_w(const uint32_t *data, uint32_t in_size) override;
|
||||
|
||||
protected:
|
||||
// device-level overrides
|
||||
virtual void device_start() override;
|
||||
//protected:
|
||||
|
||||
private:
|
||||
void fixed_status(uint32_t *dest);
|
||||
void free_status(uint32_t *dest);
|
||||
void read(uint32_t *dest);
|
||||
|
||||
const char *port_tag[8];
|
||||
const char *id, *license, *versions;
|
||||
|
||||
ioport_port *port[8];
|
||||
void fixed_status(uint32_t *dest) override;
|
||||
void free_status(uint32_t *dest) override;
|
||||
void read(uint32_t *dest) override;
|
||||
};
|
||||
|
||||
DECLARE_DEVICE_TYPE(DC_CONTROLLER, dc_controller_device)
|
||||
|
Loading…
Reference in New Issue
Block a user