From: jeaw100@york.ac.uk [mailto:jeaw100@york.ac.uk]

Sent: Monday, August 25, 2008 1:45 AM
To: submit@mamedev.org
Subject: Stepper motor changes

Updated stepper motor code to use a MAME-style config interface, rather 
than a load of setting functions. Changed optic functions to use clearly

defined start and end points. Added standard layout for Starpoint units 
used in many machines. Updated all affected drivers.


PS. At one point, I was led to believe that the UPD sound chip would
have 
support for its messaging pins added, is this still pending (I have Phil

B's old source here if it's needed). Such support would prove very
useful 
for AGEMAME as many of the drivers in that that use that chip rely on it

for timing.
This commit is contained in:
Aaron Giles 2008-08-28 08:48:56 +00:00
parent 5299bac187
commit 66a19bd16b
5 changed files with 165 additions and 136 deletions

View File

@ -356,8 +356,8 @@ send data to them, although obviously there's no response. */
for ( i = 0; i < 6; i++)
{
Stepper_reset_position(i);
if ( Stepper_optic_state(i) ) pattern |= 1<<i;
stepper_reset_position(i);
if ( stepper_optic_state(i) ) pattern |= 1<<i;
}
optic_pattern = pattern;
@ -567,12 +567,12 @@ static WRITE8_HANDLER( reel34_w )
{
reel34_latch = data;
if ( Stepper_update(2, data ) ) reel_changed |= 0x04;
if ( Stepper_update(3, data>>4) ) reel_changed |= 0x08;
if ( stepper_update(2, data ) ) reel_changed |= 0x04;
if ( stepper_update(3, data>>4) ) reel_changed |= 0x08;
if ( Stepper_optic_state(2) ) optic_pattern |= 0x04;
if ( stepper_optic_state(2) ) optic_pattern |= 0x04;
else optic_pattern &= ~0x04;
if ( Stepper_optic_state(3) ) optic_pattern |= 0x08;
if ( stepper_optic_state(3) ) optic_pattern |= 0x08;
else optic_pattern &= ~0x08;
draw_reel((2));
@ -585,12 +585,12 @@ static WRITE8_HANDLER( reel56_w )
{
reel56_latch = data;
if ( Stepper_update(4, data ) ) reel_changed |= 0x10;
if ( Stepper_update(5, data>>4) ) reel_changed |= 0x20;
if ( stepper_update(4, data ) ) reel_changed |= 0x10;
if ( stepper_update(5, data>>4) ) reel_changed |= 0x20;
if ( Stepper_optic_state(4) ) optic_pattern |= 0x10;
if ( stepper_optic_state(4) ) optic_pattern |= 0x10;
else optic_pattern &= ~0x10;
if ( Stepper_optic_state(5) ) optic_pattern |= 0x20;
if ( stepper_optic_state(5) ) optic_pattern |= 0x20;
else optic_pattern &= ~0x20;
draw_reel((4));

View File

@ -401,8 +401,8 @@ static void mpu4_stepper_reset(void)
int pattern = 0,reel;
for (reel = 0; reel < 6; reel++)
{
Stepper_reset_position(reel);
if (Stepper_optic_state(reel)) pattern |= 1<<reel;
stepper_reset_position(reel);
if (stepper_optic_state(reel)) pattern |= 1<<reel;
}
optic_pattern = pattern;
}
@ -806,15 +806,15 @@ static const pia6821_interface pia_ic5_intf =
static WRITE8_HANDLER( pia_ic6_portb_w )
{
LOG(("%04x IC6 PIA Port B Set to %2x (Reel A and B)\n", activecpu_get_previouspc(),data));
Stepper_update(0, data & 0x0F );
Stepper_update(1, (data>>4) & 0x0F );
stepper_update(0, data & 0x0F );
stepper_update(1, (data>>4) & 0x0F );
/* if ( pia_get_output_cb2(1)) */
{
if ( Stepper_optic_state(0) ) optic_pattern |= 0x01;
if ( stepper_optic_state(0) ) optic_pattern |= 0x01;
else optic_pattern &= ~0x01;
if ( Stepper_optic_state(1) ) optic_pattern |= 0x02;
if ( stepper_optic_state(1) ) optic_pattern |= 0x02;
else optic_pattern &= ~0x02;
}
draw_reel((0));
@ -869,14 +869,14 @@ static const pia6821_interface pia_ic6_intf =
static WRITE8_HANDLER( pia_ic7_porta_w )
{
LOG(("%04x IC7 PIA Port A Set to %2x (Reel C and D)\n", activecpu_get_previouspc(),data));
Stepper_update(2, data & 0x0F );
Stepper_update(3, (data >> 4)& 0x0F );
stepper_update(2, data & 0x0F );
stepper_update(3, (data >> 4)& 0x0F );
/* if ( pia_get_output_cb2(1)) */
{
if ( Stepper_optic_state(2) ) optic_pattern |= 0x04;
if ( stepper_optic_state(2) ) optic_pattern |= 0x04;
else optic_pattern &= ~0x04;
if ( Stepper_optic_state(3) ) optic_pattern |= 0x08;
if ( stepper_optic_state(3) ) optic_pattern |= 0x08;
else optic_pattern &= ~0x08;
}
draw_reel((2));
@ -1229,6 +1229,13 @@ static INPUT_PORTS_START( connect4 )
PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_COIN4) PORT_NAME("100p")PORT_IMPULSE(5)
INPUT_PORTS_END
static const stepper_interface barcrest_reel_interface =
{
BARCREST_48STEP_REEL,
0,
8,
0x00
};
/* Common configurations */
static void mpu4_config_common(void)
@ -1257,10 +1264,10 @@ static MACHINE_START( mpu4mod2 )
Mechmtr_init(8);
/* setup 4 reels */
Stepper_init(0, BARCREST_48STEP_REEL);
Stepper_init(1, BARCREST_48STEP_REEL);
Stepper_init(2, BARCREST_48STEP_REEL);
Stepper_init(3, BARCREST_48STEP_REEL);
stepper_config(0, &barcrest_reel_interface);
stepper_config(1, &barcrest_reel_interface);
stepper_config(2, &barcrest_reel_interface);
stepper_config(3, &barcrest_reel_interface);
/* setup the standard oki MSC1937 display */
ROC10937_init(0, MSC1937,0);

View File

@ -1364,10 +1364,10 @@ MACHINE_START( mpu4_vid )
/* setup 4 reels (for hybrid machines) */
Stepper_init(0, BARCREST_48STEP_REEL);
Stepper_init(1, BARCREST_48STEP_REEL);
Stepper_init(2, BARCREST_48STEP_REEL);
Stepper_init(3, BARCREST_48STEP_REEL);
stepper_config(0, &barcrest_reel_interface);
stepper_config(1, &barcrest_reel_interface);
stepper_config(2, &barcrest_reel_interface);
stepper_config(3, &barcrest_reel_interface);
/* setup the standard oki MSC1937 display */

View File

@ -16,31 +16,31 @@
#include "driver.h"
#include "steppers.h"
#include "deprecat.h"
/* local prototypes */
// local prototypes ///////////////////////////////////////////////////////
static void update_optic(int which);
static void update_optic(int id);
/* local vars */
// local vars /////////////////////////////////////////////////////////////
static struct
typedef struct _stepper
{
UINT8 pattern, // coil pattern
old_pattern, // old coil pattern
type; // reel type
INT16 step_pos, // step position 0 - max_steps
max_steps; // maximum step position
const stepper_interface *intf;
UINT8 pattern, /* coil pattern */
old_pattern, /* old coil pattern */
type; /* reel type */
INT16 step_pos, /* step position 0 - max_steps */
max_steps; /* maximum step position */
INT16 index_pos, // position of index (in steps)
index_len, // length of index (in steps)
index_patt; // pattern needed on coils (0=don't care)
INT16 index_start, /* start position of index (in half steps) */
index_end, /* end position of index (in half steps) */
index_patt; /* pattern needed on coils (0=don't care) */
UINT8 optic;
} stepper;
} steppers[MAX_STEPPERS];
// step table, use previouspattern::newpattern as index
static stepper step[MAX_STEPPERS];
/* step table, use previouspattern::newpattern as index */
static const int StarpointStepTab[] =
{
0, //0000->0000 0->0
@ -316,8 +316,6 @@ static const int StarpointStepTab[] =
0 //1111->1111 F->F
};
///////////////////////////////////////////////////////////////////////////
static const int BarcrestStepTab[] =
{
0, //0000->0000 0->0
@ -341,8 +339,8 @@ static const int BarcrestStepTab[] =
0, //0001->0001 1->1
0, //0001->0010 1->2
1, //0001->0011 1->3
0,//0001->0100 1->4
0,//0001->0101 1->5
0, //0001->0100 1->4
0, //0001->0101 1->5
0, //0001->0110 1->6
0, //0001->0111 1->7
0, //0001->1000 1->8
@ -593,101 +591,107 @@ static const int BarcrestStepTab[] =
0 //1111->1111 F->F
};
///////////////////////////////////////////////////////////////////////////
/* useful interfaces */
void Stepper_init(int id, int type)
const stepper_interface starpoint_interface_48step =
{
STARPOINT_48STEP_REEL,
16,
24,
0x09
};
///////////////////////////////////////////////////////////////////////////
void stepper_config(int which, const stepper_interface *intf)
{
if ( id < MAX_STEPPERS )
assert_always(mame_get_phase(Machine) == MAME_PHASE_INIT, "Can only call stepper_config at init time!");
assert_always((which >= 0) && (which < MAX_STEPPERS), "stepper_config called on an invalid stepper motor!");
assert_always(intf, "stepper_config called with an invalid interface!");
step[which].intf = intf;
step[which].type = intf->type;
step[which].index_start = intf->index_start;/* location of first index value in half steps */
step[which].index_end = intf->index_end; /* location of last index value in half steps */
step[which].index_patt = intf->index_patt; /* hex value of coil pattern (0 if not needed)*/
step[which].pattern = 0;
step[which].old_pattern = 0;
step[which].step_pos = 0;
switch ( step[which].type )
{
steppers[id].index_pos = 16;
steppers[id].index_len = 8;
steppers[id].index_patt = 0x09;
steppers[id].pattern = 0;
steppers[id].old_pattern = 0;
steppers[id].step_pos = 0;
steppers[id].max_steps = (48*2);
steppers[id].type = type;
switch ( steppers[id].type )
{
case STARPOINT_48STEP_REEL : // STARPOINT RMxxx
break;
case BARCREST_48STEP_REEL : // Barcrest reel units have different coil windings and optic tabs
Stepper_set_index(id,0,16,0x09);
break;
case STARPOINT_144STEPS_DICE :// STARPOINT 1DCU DICE mechanism
steppers[id].max_steps = (144*2);
break;
}
state_save_register_item("Stepper", id, steppers[id].index_pos);
state_save_register_item("Stepper", id, steppers[id].index_len);
state_save_register_item("Stepper", id, steppers[id].index_patt);
state_save_register_item("Stepper", id, steppers[id].pattern);
state_save_register_item("Stepper", id, steppers[id].old_pattern);
state_save_register_item("Stepper", id, steppers[id].step_pos);
state_save_register_item("Stepper", id, steppers[id].max_steps);
state_save_register_item("Stepper", id, steppers[id].type);
case STARPOINT_48STEP_REEL: /* STARPOINT RMxxx */
case BARCREST_48STEP_REEL : /* Barcrest Reel unit */
step[which].max_steps = (48*2);
break;
case STARPOINT_144STEPS_DICE :/* STARPOINT 1DCU DICE mechanism */
step[which].max_steps = (144*2);
break;
}
state_save_register_item("stepper", which, step[which].index_start);
state_save_register_item("stepper", which, step[which].index_end);
state_save_register_item("stepper", which, step[which].index_patt);
state_save_register_item("stepper", which, step[which].pattern);
state_save_register_item("stepper", which, step[which].old_pattern);
state_save_register_item("stepper", which, step[which].step_pos);
state_save_register_item("stepper", which, step[which].max_steps);
state_save_register_item("stepper", which, step[which].type);
}
///////////////////////////////////////////////////////////////////////////
void Stepper_set_index(int id,int position,int length,int pattern)
int stepper_get_position(int which)
{
steppers[id].index_pos = position;//location of first index value in half steps
steppers[id].index_len = length; //number of half steps the index lasts
steppers[id].index_patt = pattern; //hex value of coil pattern
}
int Stepper_get_position(int id)
{
return steppers[id].step_pos;
return step[which].step_pos;
}
///////////////////////////////////////////////////////////////////////////
int Stepper_get_max(int id)
int stepper_get_max(int which)
{
return steppers[id].max_steps;
return step[which].max_steps;
}
///////////////////////////////////////////////////////////////////////////
static void update_optic(int id)
static void update_optic(int which)
{
int pos = steppers[id].step_pos,
index = steppers[id].index_pos;
int pos = step[which].step_pos,
start = step[which].index_start,
end = step[which].index_end;
if ( ( pos >= index ) && ( pos < index + steppers[id].index_len ) &&
( ( steppers[id].pattern == steppers[id].index_patt || steppers[id].index_patt==0) ||
( steppers[id].pattern == 0 &&
(steppers[id].old_pattern == steppers[id].index_patt || steppers[id].index_patt==0)
if ( (( pos >= start ) && ( pos <= end )) &&
( ( step[which].pattern == step[which].index_patt || step[which].index_patt==0) ||
( step[which].pattern == 0 &&
(step[which].old_pattern == step[which].index_patt || step[which].index_patt==0)
) ) )
{
steppers[id].optic = 1;
step[which].optic = 1;
}
else steppers[id].optic = 0;
else step[which].optic = 0;
}
///////////////////////////////////////////////////////////////////////////
void Stepper_reset_position(int id)
void stepper_reset_position(int which)
{
steppers[id].step_pos = 0;
steppers[id].pattern = 0x00;
steppers[id].old_pattern = 0x00;
step[which].step_pos = 0;
step[which].pattern = 0x00;
step[which].old_pattern = 0x00;
update_optic(id);
update_optic(which);
}
///////////////////////////////////////////////////////////////////////////
int Stepper_optic_state(int id)
int stepper_optic_state(int which)
{
int result = 0;
if ( id < MAX_STEPPERS )
if ( which < MAX_STEPPERS )
{
result = steppers[id].optic;
result = step[which].optic;
}
return result;
@ -695,47 +699,49 @@ int Stepper_optic_state(int id)
///////////////////////////////////////////////////////////////////////////
int Stepper_update(int id, UINT8 pattern)
int stepper_update(int which, UINT8 pattern)
{
int changed = 0;
pattern &= 0x0F;
if ( steppers[id].pattern != pattern )
{ // pattern changed
if ( step[which].pattern != pattern )
{ /* pattern changed */
int index,
steps,
pos;
if ( steppers[id].pattern )
if ( step[which].pattern )
{
steppers[id].old_pattern = steppers[id].pattern;
step[which].old_pattern = step[which].pattern;
}
steppers[id].pattern = pattern;
step[which].pattern = pattern;
index = (steppers[id].old_pattern << 4) | pattern;
switch ( steppers[id].type )
index = (step[which].old_pattern << 4) | pattern;
switch ( step[which].type )
{
default:
case STARPOINT_48STEP_REEL : // STARPOINT RMxxx
case STARPOINT_144STEPS_DICE : // STARPOINT 1DCU DICE mechanism
case STARPOINT_48STEP_REEL : /* STARPOINT RMxxx */
case STARPOINT_144STEPS_DICE : /* STARPOINT 1DCU DICE mechanism */
steps = StarpointStepTab[ index ];
break;
case BARCREST_48STEP_REEL : // Barcrest reel units have different windings
case BARCREST_48STEP_REEL : /* Barcrest reel units have different windings */
steps = BarcrestStepTab[ index ];
break;
}
// if ( id ==0 )logerror("Id %d Index %d Steps %d Pattern Old %02X New %02X\n",id,index,steps,steppers[id].old_pattern,steppers[id].pattern);
#if 0 /* Assists with new index generation */
if ( which ==0 )logerror("which %d Index %d Steps %d Pattern Old %02X New %02X\n",which,index,steps,step[which].old_pattern,step[which].pattern);
#endif
if ( steps )
{
pos = steppers[id].step_pos + steps;
pos = step[which].step_pos + steps;
if ( pos > steppers[id].max_steps ) pos -= steppers[id].max_steps;
else if ( pos < 0 ) pos += steppers[id].max_steps;
if ( pos > step[which].max_steps ) pos -= step[which].max_steps;
else if ( pos < 0 ) pos += step[which].max_steps;
steppers[id].step_pos = pos;
update_optic(id);
step[which].step_pos = pos;
update_optic(which);
changed++;
}

View File

@ -5,6 +5,11 @@
// Emulates : 48 step motors driven with full step or half step //
// also emulates the index optic //
// //
// 13-08-2008: J. Wallace - Added a rigid interface structure, //
// and removed unnecessary inline functions //
// Rewritten to make it more flexible //
// 26-01-2007: J. Wallace - Rewritten to make it more flexible //
// 26-01-2007: J. Wallace - Rewritten to make it more flexible //
// 26-01-2007: J. Wallace - Rewritten to make it more flexible //
// and to allow indices to be set in drivers //
// 29-12-2006: J. Wallace - Added state save support //
@ -18,23 +23,34 @@
#ifndef INC_STEPPERS
#define INC_STEPPERS
#define MAX_STEPPERS 8 // maximum number of steppers
#define MAX_STEPPERS 8 /* maximum number of steppers */
#define STARPOINT_48STEP_REEL 0 // STARPOINT RMXXX reel unit
#define BARCREST_48STEP_REEL 1 // Barcrest bespoke reel unit
#define STARPOINT_144STEPS_DICE 2 // STARPOINT 1DCU DICE mechanism - tech sheet available on request
#define STARPOINT_48STEP_REEL 0 /* STARPOINT RMXXX reel unit */
#define BARCREST_48STEP_REEL 1 /* Barcrest bespoke reel unit */
#define STARPOINT_144STEPS_DICE 2 /* STARPOINT 1DCU DICE mechanism */
void Stepper_init( int id, int type); // init a stepper motor
/*------------- Stepper motor interface structure -----------------*/
void Stepper_reset_position(int id); // reset a motor to position 0
typedef struct _stepper_interface stepper_interface;
struct _stepper_interface
{
UINT8 type; /* Reel unit type */
INT16 index_start;/* start position of index (in half steps) */
INT16 index_end; /* end position of index (in half steps) */
INT16 index_patt; /* pattern needed on coils (0=don't care) */
};
int Stepper_optic_state( int id); // read a motor's optics
extern const stepper_interface starpoint_interface_48step;
void Stepper_set_index(int id,int position,int length,int pattern);
void stepper_config(int which, const stepper_interface *intf);
int Stepper_update(int id, UINT8 pattern); // update a motor
void stepper_reset_position(int id); /* reset a motor to position 0 */
int Stepper_get_position(int id); // get current position in half steps
int stepper_optic_state( int id); /* read a motor's optics */
int Stepper_get_max(int id); // get maximum position in half steps
int stepper_update(int id, UINT8 pattern); /* update a motor */
int stepper_get_position(int id); /* get current position in half steps */
int stepper_get_max(int id); /* get maximum position in half steps */
#endif