summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Zsolt Vasvari <zsoltvas@mamedev.org>2008-03-03 04:10:51 +0000
committer Zsolt Vasvari <zsoltvas@mamedev.org>2008-03-03 04:10:51 +0000
commit62466dd08f6c56a02f2c4ed67048fcd7da68acc3 (patch)
tree7e0226b8aafc712ed7f13ec463d85811fdba1921
parente31f9a631301dace92853014f9c8a909f7e02d3e (diff)
- Added PORT_CHANGED macro which calls a callback if the given port changes.
Usage is very similar to PORT_CUSTOM. See the Astro Invader driver for an example - Removed input_port_set_changed_callback and converted all users to PORT_CHANGED The only difference between the old callback and the ones supplied by PORT_CHANGED is that values passed by PORT_CHANGED are normalized to start at bit 0, just like PORT_CUSTOM.
-rw-r--r--src/emu/inptport.c122
-rw-r--r--src/emu/inptport.h19
-rw-r--r--src/mame/drivers/arcadia.c35
-rw-r--r--src/mame/drivers/astinvad.c12
-rw-r--r--src/mame/drivers/naomi.c5
-rw-r--r--src/mame/drivers/segag80r.c9
-rw-r--r--src/mame/drivers/segag80v.c10
-rw-r--r--src/mame/drivers/zaxxon.c9
-rw-r--r--src/mame/includes/dc.h4
-rw-r--r--src/mame/machine/dc.c94
-rw-r--r--src/mame/video/dc.c8
11 files changed, 156 insertions, 171 deletions
diff --git a/src/emu/inptport.c b/src/emu/inptport.c
index 0d93e6cba50..88052d23120 100644
--- a/src/emu/inptport.c
+++ b/src/emu/inptport.c
@@ -169,6 +169,15 @@ struct _custom_port_info
};
+typedef struct _changed_port_info changed_port_info;
+struct _changed_port_info
+{
+ changed_port_info * next; /* linked list */
+ input_port_entry * port; /* pointer to the input port referenced */
+ UINT8 shift; /* right shift to apply before calling callback */
+};
+
+
typedef struct _input_bit_info input_bit_info;
struct _input_bit_info
{
@@ -178,16 +187,6 @@ struct _input_bit_info
};
-typedef struct _changed_callback_info changed_callback_info;
-struct _changed_callback_info
-{
- changed_callback_info *next; /* linked list */
- UINT32 mask; /* mask we care about */
- input_port_changed_func callback;/* callback */
- void * param; /* parameter */
-};
-
-
typedef struct _input_port_info input_port_info;
struct _input_port_info
{
@@ -202,8 +201,7 @@ struct _input_port_info
input_bit_info bit[MAX_BITS_PER_PORT]; /* info about each bit in the port */
analog_port_info * analoginfo; /* pointer to linked list of analog port info */
custom_port_info * custominfo; /* pointer to linked list of custom port info */
- changed_callback_info *change_notify;/* list of people to notify if things change */
- UINT32 changed_last_value;
+ changed_port_info * changedinfo;/* pointer to linked list of changed port info */
};
@@ -1040,7 +1038,7 @@ static void setup_record(running_machine *machine);
static void input_port_exit(running_machine *machine);
static void input_port_load(int config_type, xml_data_node *parentnode);
static void input_port_save(int config_type, xml_data_node *parentnode);
-static void input_port_vblank_start(void);
+static void input_port_vblank_start(running_machine *machine);
static void input_port_vblank_end(void);
static void update_digital_joysticks(void);
static void update_analog_port(int port);
@@ -1159,7 +1157,7 @@ static void on_vblank(running_machine *machine, screen_state *screen, int vblank
{
/* VBLANK starting - read keyboard & update the status of the input ports */
if (vblank_state)
- input_port_vblank_start();
+ input_port_vblank_start(machine);
/* VBLANK ending - update IPT_VBLANK input ports */
else
@@ -1341,6 +1339,25 @@ static void input_port_postload(void)
port_info[portnum].custominfo = info;
}
+ /* if this is a changed input, add it to the list */
+ else if (port->changed != NULL)
+ {
+ changed_port_info *info;
+
+ /* allocate memory */
+ info = auto_malloc(sizeof(*info));
+ memset(info, 0, sizeof(*info));
+
+ /* fill in the data */
+ info->port = port;
+ for (mask = port->mask; !(mask & 1); mask >>= 1)
+ info->shift++;
+
+ /* hook in the list */
+ info->next = port_info[portnum].changedinfo;
+ port_info[portnum].changedinfo = info;
+ }
+
/* if this is an analog port, create an info struct for it */
else if (IS_ANALOG(port))
{
@@ -1522,7 +1539,7 @@ static void input_port_postload(void)
}
/* run an initial update */
- input_port_vblank_start();
+ input_port_vblank_start(Machine);
}
@@ -2141,6 +2158,12 @@ static void input_port_detokenize(input_port_init_params *param, const input_por
port->custom_param = (void *)TOKEN_GET_PTR(ipt, voidptr);
break;
+ /* changed callbacks */
+ case INPUT_TOKEN_CHANGED:
+ port->changed = TOKEN_GET_PTR(ipt, changedptr);
+ port->changed_param = (void *)TOKEN_GET_PTR(ipt, voidptr);
+ break;
+
/* dip switch definition */
case INPUT_TOKEN_DIPNAME:
TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
@@ -2857,7 +2880,7 @@ void input_port_update_defaults(void)
*
*************************************/
-static void input_port_vblank_start(void)
+static void input_port_vblank_start(running_machine *machine)
{
int ui_visible = ui_is_menu_active() || ui_is_slider_active();
int portnum, bitnum;
@@ -2875,6 +2898,7 @@ profiler_mark(PROFILER_INPUT);
{
input_port_info *portinfo = &port_info[portnum];
input_bit_info *info;
+ changed_port_info *changed;
/* compute the VBLANK mask */
portinfo->vblank = 0;
@@ -2882,7 +2906,7 @@ profiler_mark(PROFILER_INPUT);
if (info->port->type == IPT_VBLANK)
{
portinfo->vblank ^= info->port->mask;
- if (Machine->screen[0].vblank == 0)
+ if (machine->screen[0].vblank == 0)
logerror("Warning: you are using IPT_VBLANK with vblank_time = 0. You need to increase vblank_time for IPT_VBLANK to work.\n");
}
@@ -2969,6 +2993,22 @@ profiler_mark(PROFILER_INPUT);
/* note that analog ports are handled instantaneously at port read time */
}
+
+ /* call changed handlers */
+ for (changed = portinfo->changedinfo; changed; changed = changed->next)
+ if (input_port_condition(changed->port))
+ {
+ input_port_entry *port = changed->port;
+
+ UINT32 new_unmasked_value = readinputport(portnum);
+ UINT32 newval = (new_unmasked_value & port->mask) >> changed->shift;
+ UINT32 oldval = (port->changed_last_value & port->mask) >> changed->shift;
+
+ if (newval != oldval)
+ (*port->changed)(machine, port->changed_param, oldval, newval);
+
+ port->changed_last_value = new_unmasked_value;
+ }
}
#ifdef MESS
@@ -2976,23 +3016,6 @@ profiler_mark(PROFILER_INPUT);
inputx_update();
#endif
- /* call changed handlers */
- for (portnum = 0; portnum < MAX_INPUT_PORTS; portnum++)
- if (port_info[portnum].change_notify != NULL)
- {
- changed_callback_info *cbinfo;
- UINT32 newvalue = readinputport(portnum);
- UINT32 oldvalue = port_info[portnum].changed_last_value;
- UINT32 delta = newvalue ^ oldvalue;
-
- /* call all the callbacks whose mask matches the requested mask */
- for (cbinfo = port_info[portnum].change_notify; cbinfo; cbinfo = cbinfo->next)
- if (delta & cbinfo->mask)
- (*cbinfo->callback)(cbinfo->param, oldvalue & cbinfo->mask, newvalue & cbinfo->mask);
-
- port_info[portnum].changed_last_value = newvalue;
- }
-
/* handle playback/record */
for (portnum = 0; portnum < MAX_INPUT_PORTS; portnum++)
{
@@ -3006,11 +3029,11 @@ profiler_mark(PROFILER_INPUT);
}
/* store speed read from INP file, if extended INP */
- if (Machine->playback_file != NULL && extended_inp)
+ if (machine->playback_file != NULL && extended_inp)
{
UINT32 dummy;
- mame_fread(Machine->playback_file, &rec_speed, sizeof(rec_speed));
- mame_fread(Machine->playback_file, &dummy, sizeof(dummy));
+ mame_fread(machine->playback_file, &rec_speed, sizeof(rec_speed));
+ mame_fread(machine->playback_file, &dummy, sizeof(dummy));
framecount++;
rec_speed *= 100;
totalspeed += rec_speed;
@@ -3493,31 +3516,6 @@ void input_port_set_digital_value(int portnum, UINT32 value, UINT32 mask)
/*************************************
*
- * Input port callbacks
- *
- *************************************/
-
-void input_port_set_changed_callback(int port, UINT32 mask, void (*callback)(void *, UINT32, UINT32), void *param)
-{
- input_port_info *portinfo = &port_info[port];
- changed_callback_info *cbinfo;
-
- assert_always(mame_get_phase(Machine) == MAME_PHASE_INIT, "Can only call input_port_set_changed_callback() at init time!");
- assert_always((port >= 0) && (port < MAX_INPUT_PORTS), "Invalid port number passed to input_port_set_changed_callback()!");
-
- cbinfo = auto_malloc(sizeof(*cbinfo));
- cbinfo->next = portinfo->change_notify;
- cbinfo->mask = mask;
- cbinfo->callback = callback;
- cbinfo->param = param;
-
- portinfo->change_notify = cbinfo;
-}
-
-
-
-/*************************************
- *
* Return position of crosshair axis
*
*************************************/
diff --git a/src/emu/inptport.h b/src/emu/inptport.h
index c8b7bae6fdf..b71fab797cf 100644
--- a/src/emu/inptport.h
+++ b/src/emu/inptport.h
@@ -42,6 +42,9 @@
/* macro for a custom callback functions (PORT_CUSTOM) */
#define CUSTOM_INPUT(name) UINT32 name(void *param)
+/* macro for port changed callback functions (PORT_CHANGED) */
+#define INPUT_CHANGED(name) void name(running_machine *machine, void *param, UINT32 oldval, UINT32 newval)
+
/* sequence types for input_port_seq() call */
enum _input_seq_type
@@ -355,6 +358,7 @@ enum
INPUT_TOKEN_INVERT,
INPUT_TOKEN_UNUSED,
INPUT_TOKEN_CUSTOM,
+ INPUT_TOKEN_CHANGED,
INPUT_TOKEN_DIPNAME,
INPUT_TOKEN_DIPSETTING,
INPUT_TOKEN_DIPLOCATION,
@@ -498,7 +502,7 @@ typedef struct _input_port_init_params input_port_init_params;
/* a custom input port callback function */
typedef UINT32 (*input_port_custom_func)(void *param);
-typedef void (*input_port_changed_func)(void *param, UINT32 oldval, UINT32 newval);
+typedef void (*input_port_changed_func)(running_machine *machine, void *param, UINT32 oldval, UINT32 newval);
/* this type is used to encode input port definitions */
@@ -508,6 +512,7 @@ union _input_port_token
TOKEN_COMMON_FIELDS
const input_port_token *tokenptr;
input_port_custom_func customptr;
+ input_port_changed_func changedptr;
};
@@ -560,7 +565,10 @@ struct _input_port_entry
const char *name; /* user-friendly name to display */
input_seq seq; /* input sequence affecting the input bits */
input_port_custom_func custom;/* custom callback routine */
- void * custom_param; /* parameter for callback routine */
+ void * custom_param; /* parameter for custom callback routine */
+ input_port_changed_func changed;/* changed callback routine */
+ void * changed_param; /* parameter for changed callback routine */
+ UINT32 changed_last_value; /* the last value for changed detection purposes */
/* valid if type is between __ipt_analog_start and __ipt_analog_end */
struct
@@ -783,6 +791,12 @@ struct _ext_inp_header
TOKEN_PTR(customptr, _callback), \
TOKEN_PTR(voidptr, _param),
+/* changed callbacks */
+#define PORT_CHANGED(_callback, _param) \
+ TOKEN_UINT32_PACK1(INPUT_TOKEN_CHANGED, 8), \
+ TOKEN_PTR(changedptr, _callback), \
+ TOKEN_PTR(voidptr, _param),
+
/* dip switch definition */
#define PORT_DIPNAME(_mask,_default,_name) \
TOKEN_UINT32_PACK1(INPUT_TOKEN_DIPNAME, 8), \
@@ -917,7 +931,6 @@ const char *input_port_name(const input_port_entry *in);
const input_seq *input_port_seq(input_port_entry *in, input_seq_type seqtype);
const input_seq *input_port_default_seq(int type, int player, input_seq_type seqtype);
int input_port_condition(const input_port_entry *in);
-void input_port_set_changed_callback(int port, UINT32 mask, input_port_changed_func callback, void *param);
const char *port_type_to_token(int type, int player);
int token_to_port_type(const char *string, int *player);
diff --git a/src/mame/drivers/arcadia.c b/src/mame/drivers/arcadia.c
index 0908b2da7bf..ef5ee109ed5 100644
--- a/src/mame/drivers/arcadia.c
+++ b/src/mame/drivers/arcadia.c
@@ -78,20 +78,6 @@ static WRITE16_HANDLER( arcadia_multibios_change_game )
/*************************************
*
- * Special port handlers
- *
- *************************************/
-
-static CUSTOM_INPUT( arcadia_coin_counter_r )
-{
- /* return coin counter values */
- return *(UINT8 *)param & 3;
-}
-
-
-
-/*************************************
- *
* CIA-A port A access:
*
* PA7 = game port 1, pin 6 (fire)
@@ -170,7 +156,14 @@ static void arcadia_cia_0_portb_w(UINT8 data)
*
*************************************/
-static void coin_changed_callback(void *param, UINT32 oldval, UINT32 newval)
+static CUSTOM_INPUT( coin_counter_r )
+{
+ /* return coin counter values */
+ return *(UINT8 *)param & 3;
+}
+
+
+static INPUT_CHANGED( coin_changed_callback )
{
UINT8 *counter = param;
@@ -230,8 +223,8 @@ static INPUT_PORTS_START( arcadia )
PORT_SERVICE_NO_TOGGLE( 0x02, IP_ACTIVE_LOW )
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 )
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
- PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(arcadia_coin_counter_r, &coin_counter[0])
- PORT_BIT( 0xc0, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(arcadia_coin_counter_r, &coin_counter[1])
+ PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(coin_counter_r, &coin_counter[0])
+ PORT_BIT( 0xc0, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(coin_counter_r, &coin_counter[1])
PORT_START_TAG("JOY0DAT")
PORT_BIT( 0x0303, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(amiga_joystick_convert, "P1JOY")
@@ -261,8 +254,8 @@ static INPUT_PORTS_START( arcadia )
PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
PORT_START_TAG("COINS")
- PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
- PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
+ PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(coin_changed_callback, &coin_counter[0])
+ PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 ) PORT_CHANGED(coin_changed_callback, &coin_counter[1])
INPUT_PORTS_END
@@ -683,10 +676,6 @@ static void arcadia_init(void)
biosrom = (UINT16 *)memory_region(REGION_USER2);
if (biosrom[0] != 0x4afc)
generic_decode(REGION_USER2, 6, 1, 0, 2, 3, 4, 5, 7);
-
- /* request notifications when the coins change */
- input_port_set_changed_callback(port_tag_to_index("COINS"), 0x01, coin_changed_callback, &coin_counter[0]);
- input_port_set_changed_callback(port_tag_to_index("COINS"), 0x02, coin_changed_callback, &coin_counter[1]);
}
diff --git a/src/mame/drivers/astinvad.c b/src/mame/drivers/astinvad.c
index 4464f24e3f9..17b81f1a417 100644
--- a/src/mame/drivers/astinvad.c
+++ b/src/mame/drivers/astinvad.c
@@ -201,12 +201,10 @@ static MACHINE_START( kamikaze )
}
-static INTERRUPT_GEN( spaceint_interrupt )
+static INPUT_CHANGED( spaceint_coin_inserted )
{
- if (readinputport(2) & 1) /* coin */
- cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
-
- cpunum_set_input_line(machine, 0, 0, HOLD_LINE);
+ /* coin insertion causes an NMI */
+ cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
}
@@ -453,7 +451,7 @@ static INPUT_PORTS_START( spaceint )
PORT_DIPSETTING( 0x08, DEF_STR( 1C_2C ) )
PORT_START_TAG("IN2")
- PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_IMPULSE(1) /* causes NMI */
+ PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(spaceint_coin_inserted, 0)
PORT_START_TAG("IN3")
PORT_DIPNAME( 0xff, 0x00, DEF_STR( Cabinet ) )
@@ -538,7 +536,7 @@ static MACHINE_DRIVER_START( spaceint )
MDRV_CPU_ADD(Z80, MASTER_CLOCK) /* a guess */
MDRV_CPU_PROGRAM_MAP(spaceint_map,0)
MDRV_CPU_IO_MAP(spaceint_portmap,0)
- MDRV_CPU_VBLANK_INT("main", spaceint_interrupt)
+ MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
/* video hardware */
MDRV_VIDEO_START(spaceint)
diff --git a/src/mame/drivers/naomi.c b/src/mame/drivers/naomi.c
index 27d8456f862..075341e416e 100644
--- a/src/mame/drivers/naomi.c
+++ b/src/mame/drivers/naomi.c
@@ -750,9 +750,10 @@ static INPUT_PORTS_START( naomi )
PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(2)
PORT_START_TAG("IN4")
PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_PLAYER(2)
+
PORT_START_TAG("COINS")
- PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
- PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
+ PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(dc_coin_slots_callback, &dc_coin_counts[0])
+ PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 ) PORT_CHANGED(dc_coin_slots_callback, &dc_coin_counts[1])
INPUT_PORTS_END
static const struct AICAinterface aica_interface =
diff --git a/src/mame/drivers/segag80r.c b/src/mame/drivers/segag80r.c
index 59468399a3c..c04b2b51533 100644
--- a/src/mame/drivers/segag80r.c
+++ b/src/mame/drivers/segag80r.c
@@ -156,19 +156,16 @@ static UINT8 *mainram;
*
*************************************/
-static void service_switch(void *param, UINT32 oldval, UINT32 newval)
+static INPUT_CHANGED( service_switch )
{
/* pressing the service switch sends an NMI */
if (newval)
- cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, PULSE_LINE);
+ cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
}
static MACHINE_START( g80r )
{
- /* request a callback if the service switch is pressed */
- input_port_set_changed_callback(port_tag_to_index("SERVICESW"), 0x01, service_switch, NULL);
-
/* register for save states */
}
@@ -467,7 +464,7 @@ static INPUT_PORTS_START( g80r_generic )
PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNUSED ) /* P1.30 */
PORT_START_TAG("SERVICESW")
- PORT_SERVICE_NO_TOGGLE( 0x01, IP_ACTIVE_HIGH )
+ PORT_SERVICE_NO_TOGGLE( 0x01, IP_ACTIVE_HIGH ) PORT_CHANGED(service_switch, 0)
INPUT_PORTS_END
diff --git a/src/mame/drivers/segag80v.c b/src/mame/drivers/segag80v.c
index 74d66bb67da..b0e78342fa6 100644
--- a/src/mame/drivers/segag80v.c
+++ b/src/mame/drivers/segag80v.c
@@ -133,7 +133,6 @@
***************************************************************************/
#include "driver.h"
-#include "deprecat.h"
#include "sound/ay8910.h"
#include "sound/samples.h"
#include "audio/segasnd.h"
@@ -179,19 +178,16 @@ static UINT8 spinner_count;
*
*************************************/
-static void service_switch(void *param, UINT32 oldval, UINT32 newval)
+static INPUT_CHANGED( service_switch )
{
/* pressing the service switch sends an NMI */
if (newval)
- cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, PULSE_LINE);
+ cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
}
static MACHINE_START( g80v )
{
- /* request a callback if the service switch is pressed */
- input_port_set_changed_callback(port_tag_to_index("SERVICESW"), 0x01, service_switch, NULL);
-
/* register for save states */
state_save_register_global_array(mult_data);
state_save_register_global(mult_result);
@@ -508,7 +504,7 @@ static INPUT_PORTS_START( g80v_generic )
PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNUSED ) /* P1.30 */
PORT_START_TAG("SERVICESW")
- PORT_SERVICE_NO_TOGGLE( 0x01, IP_ACTIVE_HIGH )
+ PORT_SERVICE_NO_TOGGLE( 0x01, IP_ACTIVE_HIGH ) PORT_CHANGED(service_switch, 0)
INPUT_PORTS_END
diff --git a/src/mame/drivers/zaxxon.c b/src/mame/drivers/zaxxon.c
index abb0acd1fd0..b0bf2802a01 100644
--- a/src/mame/drivers/zaxxon.c
+++ b/src/mame/drivers/zaxxon.c
@@ -355,11 +355,11 @@ static UINT16 razmataz_counter;
*
*************************************/
-static void service_switch(void *param, UINT32 oldval, UINT32 newval)
+static INPUT_CHANGED( service_switch )
{
/* pressing the service switch sends an NMI */
if (newval)
- cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, PULSE_LINE);
+ cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
}
@@ -387,9 +387,6 @@ static WRITE8_HANDLER( int_enable_w )
static MACHINE_START( zaxxon )
{
- /* request a callback if the service switch is pressed */
- input_port_set_changed_callback(port_tag_to_index("SERVICESW"), 0x01, service_switch, NULL);
-
/* register for save states */
state_save_register_global(int_enabled);
}
@@ -567,7 +564,7 @@ static INPUT_PORTS_START( zaxxon )
PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_IMPULSE(1)
PORT_START_TAG("SERVICESW")
- PORT_SERVICE_NO_TOGGLE( 0x01, IP_ACTIVE_HIGH )
+ PORT_SERVICE_NO_TOGGLE( 0x01, IP_ACTIVE_HIGH ) PORT_CHANGED(service_switch, 0)
PORT_START_TAG("DSW02")
PORT_DIPNAME( 0x03, 0x03, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SW1:!1,!2")
diff --git a/src/mame/includes/dc.h b/src/mame/includes/dc.h
index 8c3c9e57f58..f7d8231e152 100644
--- a/src/mame/includes/dc.h
+++ b/src/mame/includes/dc.h
@@ -34,8 +34,10 @@ MACHINE_RESET( dc );
int compute_interrupt_level(void);
void update_interrupt_status(void);
+INPUT_CHANGED( dc_coin_slots_callback );
-extern UINT32 sysctrl_regs[0x200/4];
+extern UINT32 dc_sysctrl_regs[0x200/4];
+extern UINT32 dc_coin_counts[2];
/*address*/
#define SB_C2DSTAT ((0x005F6800-0x005F6800)/4)
diff --git a/src/mame/machine/dc.c b/src/mame/machine/dc.c
index 14e149bb864..6ff0d07f322 100644
--- a/src/mame/machine/dc.c
+++ b/src/mame/machine/dc.c
@@ -118,14 +118,14 @@ enum
MAPLE_STATUS = 0x21,
};
-UINT32 sysctrl_regs[0x200/4];
+UINT32 dc_sysctrl_regs[0x200/4];
+UINT32 dc_coin_counts[2];
static UINT32 maple_regs[0x100/4];
static UINT32 dc_rtcregister[4];
static UINT32 g1bus_regs[0x100/4];
extern UINT32 dma_offset;
static UINT8 maple0x86data1[0x80];
static UINT8 maple0x86data2[0x400];
-static UINT32 coin_counts[8];
static const UINT32 maple0x82answer[]=
{
@@ -163,25 +163,25 @@ int compute_interrupt_level(void)
{
UINT32 ln,lx,le;
- ln=sysctrl_regs[SB_ISTNRM] & sysctrl_regs[SB_IML6NRM];
- lx=sysctrl_regs[SB_ISTEXT] & sysctrl_regs[SB_IML6EXT];
- le=sysctrl_regs[SB_ISTERR] & sysctrl_regs[SB_IML6ERR];
+ ln=dc_sysctrl_regs[SB_ISTNRM] & dc_sysctrl_regs[SB_IML6NRM];
+ lx=dc_sysctrl_regs[SB_ISTEXT] & dc_sysctrl_regs[SB_IML6EXT];
+ le=dc_sysctrl_regs[SB_ISTERR] & dc_sysctrl_regs[SB_IML6ERR];
if (ln | lx | le)
{
return 6;
}
- ln=sysctrl_regs[SB_ISTNRM] & sysctrl_regs[SB_IML4NRM];
- lx=sysctrl_regs[SB_ISTEXT] & sysctrl_regs[SB_IML4EXT];
- le=sysctrl_regs[SB_ISTERR] & sysctrl_regs[SB_IML4ERR];
+ ln=dc_sysctrl_regs[SB_ISTNRM] & dc_sysctrl_regs[SB_IML4NRM];
+ lx=dc_sysctrl_regs[SB_ISTEXT] & dc_sysctrl_regs[SB_IML4EXT];
+ le=dc_sysctrl_regs[SB_ISTERR] & dc_sysctrl_regs[SB_IML4ERR];
if (ln | lx | le)
{
return 4;
}
- ln=sysctrl_regs[SB_ISTNRM] & sysctrl_regs[SB_IML2NRM];
- lx=sysctrl_regs[SB_ISTEXT] & sysctrl_regs[SB_IML2EXT];
- le=sysctrl_regs[SB_ISTERR] & sysctrl_regs[SB_IML2ERR];
+ ln=dc_sysctrl_regs[SB_ISTNRM] & dc_sysctrl_regs[SB_IML2NRM];
+ lx=dc_sysctrl_regs[SB_ISTEXT] & dc_sysctrl_regs[SB_IML2EXT];
+ le=dc_sysctrl_regs[SB_ISTERR] & dc_sysctrl_regs[SB_IML2ERR];
if (ln | lx | le)
{
return 2;
@@ -194,22 +194,22 @@ void update_interrupt_status(void)
{
int level;
- if (sysctrl_regs[SB_ISTERR])
+ if (dc_sysctrl_regs[SB_ISTERR])
{
- sysctrl_regs[SB_ISTNRM] |= IST_ERROR;
+ dc_sysctrl_regs[SB_ISTNRM] |= IST_ERROR;
}
else
{
- sysctrl_regs[SB_ISTNRM] &= ~IST_ERROR;
+ dc_sysctrl_regs[SB_ISTNRM] &= ~IST_ERROR;
}
- if (sysctrl_regs[SB_ISTEXT])
+ if (dc_sysctrl_regs[SB_ISTEXT])
{
- sysctrl_regs[SB_ISTNRM] |= IST_G1G2EXTSTAT;
+ dc_sysctrl_regs[SB_ISTNRM] |= IST_G1G2EXTSTAT;
}
else
{
- sysctrl_regs[SB_ISTNRM] &= ~IST_G1G2EXTSTAT;
+ dc_sysctrl_regs[SB_ISTNRM] &= ~IST_G1G2EXTSTAT;
}
level=compute_interrupt_level();
@@ -226,11 +226,11 @@ READ64_HANDLER( dc_sysctrl_r )
#if DEBUG_SYSCTRL
if ((reg != 0x40) && (reg != 0x41) && (reg != 0x42) && (reg != 0x23) && (reg > 2)) // filter out IRQ status reads
{
- mame_printf_verbose("SYSCTRL: [%08x] read %x @ %x (reg %x: %s), mask %llx (PC=%x)\n", 0x5f6800+reg*4, sysctrl_regs[reg], offset, reg, sysctrl_names[reg], mem_mask, activecpu_get_pc());
+ mame_printf_verbose("SYSCTRL: [%08x] read %x @ %x (reg %x: %s), mask %llx (PC=%x)\n", 0x5f6800+reg*4, dc_sysctrl_regs[reg], offset, reg, sysctrl_names[reg], mem_mask, activecpu_get_pc());
}
#endif
- return (UINT64)sysctrl_regs[reg] << shift;
+ return (UINT64)dc_sysctrl_regs[reg] << shift;
}
WRITE64_HANDLER( dc_sysctrl_w )
@@ -242,37 +242,37 @@ WRITE64_HANDLER( dc_sysctrl_w )
reg = decode_reg_64(offset, mem_mask, &shift);
dat = (UINT32)(data >> shift);
- old = sysctrl_regs[reg];
- sysctrl_regs[reg] = dat; // 5f6800+off*4=dat
+ old = dc_sysctrl_regs[reg];
+ dc_sysctrl_regs[reg] = dat; // 5f6800+off*4=dat
switch (reg)
{
case SB_C2DST:
- ddtdata.destination=sysctrl_regs[SB_C2DSTAT];
- ddtdata.length=sysctrl_regs[SB_C2DLEN];
+ ddtdata.destination=dc_sysctrl_regs[SB_C2DSTAT];
+ ddtdata.length=dc_sysctrl_regs[SB_C2DLEN];
ddtdata.size=1;
ddtdata.direction=0;
ddtdata.channel=2;
ddtdata.mode=25; //011001
cpunum_set_info_ptr(0,CPUINFO_PTR_SH4_EXTERNAL_DDT_DMA,&ddtdata);
#if DEBUG_SYSCTRL
- mame_printf_verbose("SYSCTRL: Ch2 dma %x from %08x to %08x (lmmode0=%d lmmode1=%d)\n", sysctrl_regs[SB_C2DLEN], ddtdata.source-ddtdata.length, sysctrl_regs[SB_C2DSTAT],sysctrl_regs[SB_LMMODE0],sysctrl_regs[SB_LMMODE1]);
+ mame_printf_verbose("SYSCTRL: Ch2 dma %x from %08x to %08x (lmmode0=%d lmmode1=%d)\n", dc_sysctrl_regs[SB_C2DLEN], ddtdata.source-ddtdata.length, dc_sysctrl_regs[SB_C2DSTAT],dc_sysctrl_regs[SB_LMMODE0],dc_sysctrl_regs[SB_LMMODE1]);
#endif
- sysctrl_regs[SB_C2DSTAT]=sysctrl_regs[SB_C2DSTAT]+ddtdata.length;
- sysctrl_regs[SB_C2DLEN]=0;
- sysctrl_regs[SB_C2DST]=0;
- sysctrl_regs[SB_ISTNRM] |= IST_DMA_CH2;
+ dc_sysctrl_regs[SB_C2DSTAT]=dc_sysctrl_regs[SB_C2DSTAT]+ddtdata.length;
+ dc_sysctrl_regs[SB_C2DLEN]=0;
+ dc_sysctrl_regs[SB_C2DST]=0;
+ dc_sysctrl_regs[SB_ISTNRM] |= IST_DMA_CH2;
break;
case SB_ISTNRM:
- sysctrl_regs[SB_ISTNRM] = old & ~(dat | 0xC0000000); // bits 31,30 ro
+ dc_sysctrl_regs[SB_ISTNRM] = old & ~(dat | 0xC0000000); // bits 31,30 ro
break;
case SB_ISTEXT:
- sysctrl_regs[SB_ISTEXT] = old;
+ dc_sysctrl_regs[SB_ISTEXT] = old;
break;
case SB_ISTERR:
- sysctrl_regs[SB_ISTERR] = old & ~dat;
+ dc_sysctrl_regs[SB_ISTERR] = old & ~dat;
break;
}
update_interrupt_status();
@@ -530,10 +530,10 @@ WRITE64_HANDLER( dc_maple_w )
maple0x86data2[pos+14]=readinputportbytag("IN4"); // bits 2Ppush3 2Ppush4 2Ppush5 2Ppush6 2Ppush7 2Ppush8 ...
// second function
maple0x86data2[pos+15]=1; // report
- maple0x86data2[pos+16]=(coin_counts[0] >> 8) & 0xff; // 1CONDITION, 1SLOT COIN(bit13-8)
- maple0x86data2[pos+17]=coin_counts[0] & 0xff; // 1SLOT COIN(bit7-0)
- maple0x86data2[pos+18]=(coin_counts[1] >> 8) & 0xff; // 2CONDITION, 2SLOT COIN(bit13-8)
- maple0x86data2[pos+19]=coin_counts[1] & 0xff; // 2SLOT COIN(bit7-0)
+ maple0x86data2[pos+16]=(dc_coin_counts[0] >> 8) & 0xff; // 1CONDITION, 1SLOT COIN(bit13-8)
+ maple0x86data2[pos+17]=dc_coin_counts[0] & 0xff; // 1SLOT COIN(bit7-0)
+ maple0x86data2[pos+18]=(dc_coin_counts[1] >> 8) & 0xff; // 2CONDITION, 2SLOT COIN(bit13-8)
+ maple0x86data2[pos+19]=dc_coin_counts[1] & 0xff; // 2SLOT COIN(bit7-0)
// third function
maple0x86data2[pos+20]=1; // report
maple0x86data2[pos+21]=0xff; // channel 1 bits 7-0
@@ -620,18 +620,13 @@ WRITE64_HANDLER( dc_maple_w )
}
}
-static void coin_slots_callback(void *param, UINT32 oldval, UINT32 newval)
+INPUT_CHANGED( dc_coin_slots_callback )
{
-UINT32 a,b,c;
+ UINT32 *counter = param;
- c = (newval ^ oldval) & newval;
- b = 1;
- for (a=0;a < 2;a++)
- {
- if (c & b)
- coin_counts[a]++;
- b = b << 1;
- }
+ /* check for a 0 -> 1 transition */
+ if (!oldval && newval)
+ *counter += 1;
}
READ64_HANDLER( dc_gdrom_r )
@@ -717,7 +712,7 @@ WRITE64_HANDLER( dc_g1_ctrl_w )
mame_printf_verbose("G1CTRL: transfer %x from ROM %08x to sdram %08x\n", g1bus_regs[SB_GDLEN], dma_offset, g1bus_regs[SB_GDSTAR]);
cpunum_set_info_ptr(0, CPUINFO_PTR_SH4_EXTERNAL_DDT_DMA, &ddtdata);
g1bus_regs[SB_GDST]=0;
- sysctrl_regs[SB_ISTNRM] |= IST_DMA_GDROM;
+ dc_sysctrl_regs[SB_ISTNRM] |= IST_DMA_GDROM;
}
break;
}
@@ -813,7 +808,6 @@ WRITE64_HANDLER( dc_rtc_w )
MACHINE_START( dc )
{
- input_port_set_changed_callback(port_tag_to_index("COINS"), 0x03, coin_slots_callback, NULL);
}
MACHINE_RESET( dc )
@@ -823,12 +817,12 @@ MACHINE_RESET( dc )
/* halt the ARM7 */
cpunum_set_input_line(machine, 1, INPUT_LINE_RESET, ASSERT_LINE);
- memset(sysctrl_regs, 0, sizeof(sysctrl_regs));
+ memset(dc_sysctrl_regs, 0, sizeof(dc_sysctrl_regs));
memset(maple_regs, 0, sizeof(maple_regs));
memset(dc_rtcregister, 0, sizeof(dc_rtcregister));
- memset(coin_counts, 0, sizeof(coin_counts));
+ memset(dc_coin_counts, 0, sizeof(dc_coin_counts));
- sysctrl_regs[SB_SBREV] = 0x0b;
+ dc_sysctrl_regs[SB_SBREV] = 0x0b;
for (a=0;a < 0x80;a++)
maple0x86data1[a]=0x11+a;
diff --git a/src/mame/video/dc.c b/src/mame/video/dc.c
index 0d27420428e..42a5bc94808 100644
--- a/src/mame/video/dc.c
+++ b/src/mame/video/dc.c
@@ -303,7 +303,7 @@ WRITE64_HANDLER( ta_fifo_poly_w )
a = 1 << 21;
break;
}
- sysctrl_regs[SB_ISTNRM] |= a;
+ dc_sysctrl_regs[SB_ISTNRM] |= a;
update_interrupt_status();
tafifo_listtype= -1; // no list being received
}
@@ -611,7 +611,7 @@ static void pvr_build_parameterconfig(void)
TIMER_CALLBACK(vbout)
{
- sysctrl_regs[SB_ISTNRM] |= IST_VBL_OUT; // V Blank-out interrupt
+ dc_sysctrl_regs[SB_ISTNRM] |= IST_VBL_OUT; // V Blank-out interrupt
update_interrupt_status();
timer_adjust_oneshot(vbout_timer, attotime_never, 0);
@@ -655,7 +655,7 @@ VIDEO_UPDATE(dc)
if (start_render_received)
{
start_render_received=0;
- sysctrl_regs[SB_ISTNRM] |= IST_EOR_TSP; // TSP end of render
+ dc_sysctrl_regs[SB_ISTNRM] |= IST_EOR_TSP; // TSP end of render
update_interrupt_status();
}
return 0;
@@ -663,7 +663,7 @@ VIDEO_UPDATE(dc)
void dc_vblank(void)
{
- sysctrl_regs[SB_ISTNRM] |= IST_VBL_IN; // V Blank-in interrupt
+ dc_sysctrl_regs[SB_ISTNRM] |= IST_VBL_IN; // V Blank-in interrupt
update_interrupt_status();
timer_adjust_oneshot(vbout_timer, video_screen_get_time_until_pos(0, 0, 0), 0);