Previous 199869 Revisions Next

r34445 Saturday 17th January, 2015 at 23:07:48 UTC by hap
added led decay simulation as usual
[src/mess/drivers]splitsec.c

trunk/src/mess/drivers/splitsec.c
r242956r242957
2525   splitsec_state(const machine_config &mconfig, device_type type, const char *tag)
2626      : driver_device(mconfig, type, tag),
2727      m_maincpu(*this, "maincpu"),
28//      m_button_matrix(*this, "IN"),
28      m_button_matrix(*this, "IN"),
2929      m_speaker(*this, "speaker")
3030   { }
3131
3232   required_device<cpu_device> m_maincpu;
33//   required_ioport_array<4> m_button_matrix;
33   required_ioport_array<2> m_button_matrix;
3434   required_device<speaker_sound_device> m_speaker;
3535
3636   UINT16 m_r;
3737   UINT16 m_o;
3838
39   UINT16 m_leds_state[0x10];
40   UINT16 m_leds_cache[0x10];
41   UINT8 m_leds_decay[0x100];
42
3943   DECLARE_READ8_MEMBER(read_k);
4044   DECLARE_WRITE16_MEMBER(write_o);
4145   DECLARE_WRITE16_MEMBER(write_r);
4246
47   TIMER_DEVICE_CALLBACK_MEMBER(leds_decay_tick);
48   void leds_update();
49
4350   virtual void machine_start();
4451};
4552
r242956r242957
4754
4855/***************************************************************************
4956
57  LEDs
58
59***************************************************************************/
60
61// The device strobes the outputs very fast, it is unnoticeable to the user.
62// To prevent flickering here, we need to simulate a decay.
63
64// decay time, in steps of 10ms
65#define LEDS_DECAY_TIME 4
66
67void splitsec_state::leds_update()
68{
69   UINT16 active_state[0x10];
70
71   for (int i = 0; i < 0x10; i++)
72   {
73      // update current state
74      if (m_r >> i & 1)
75         m_leds_state[i] = m_o;
76
77      active_state[i] = 0;
78
79      for (int j = 0; j < 0x10; j++)
80      {
81         int di = j << 4 | i;
82
83         // turn on powered leds
84         if (m_leds_state[i] >> j & 1)
85            m_leds_decay[di] = LEDS_DECAY_TIME;
86
87         // determine active state
88         int ds = (m_leds_decay[di] != 0) ? 1 : 0;
89         active_state[i] |= (ds << j);
90      }
91   }
92
93   // on difference, send to output
94   for (int i = 0; i < 0x10; i++)
95      if (m_leds_cache[i] != active_state[i])
96      {
97         for (int j = 0; j < 8; j++)
98            output_set_lamp_value(i*10 + j, active_state[i] >> j & 1);
99      }
100
101   memcpy(m_leds_cache, active_state, sizeof(m_leds_cache));
102}
103
104TIMER_DEVICE_CALLBACK_MEMBER(splitsec_state::leds_decay_tick)
105{
106   // slowly turn off unpowered leds
107   for (int i = 0; i < 0x100; i++)
108      if (!(m_leds_state[i & 0xf] >> (i>>4) & 1) && m_leds_decay[i])
109         m_leds_decay[i]--;
110
111   leds_update();
112}
113
114
115
116/***************************************************************************
117
50118  I/O
51119
52120***************************************************************************/
53121
54122READ8_MEMBER(splitsec_state::read_k)
55123{
56   return 0;
124   UINT8 k = 0;
125
126   // read selected button rows
127   for (int i = 0; i < 2; i++)
128      if (m_r >> (i+9) & 1)
129         k |= m_button_matrix[i]->read();
130
131   return k;
57132}
58133
59134WRITE16_MEMBER(splitsec_state::write_r)
60135{
136   // R8: speaker out
137   m_speaker->level_w(data >> 8 & 1);
138   
139   // R9,R10: input mux
140   // R0-R7: led columns
61141   m_r = data;
142   leds_update();
62143}
63144
64145WRITE16_MEMBER(splitsec_state::write_o)
65146{
147   // O0-O6: led rows
148   // O7: N/C
66149   m_o = data;
150   leds_update();
67151}
68152
69153
r242956r242957
75159***************************************************************************/
76160
77161static INPUT_PORTS_START( splitsec )
162   PORT_START("IN.0") // R9
163   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT )
164   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP )
165   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT )
166   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
167
168   PORT_START("IN.1") // R10
169   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN )
170   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Select")
171   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Start")
172   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
78173INPUT_PORTS_END
79174
80175
r242956r242957
87182
88183void splitsec_state::machine_start()
89184{
185   // zerofill
186   memset(m_leds_state, 0, sizeof(m_leds_state));
187   memset(m_leds_cache, 0, sizeof(m_leds_cache));
188   memset(m_leds_decay, 0, sizeof(m_leds_decay));
189
90190   m_r = 0;
91191   m_o = 0;
92192
193   // register for savestates
194   save_item(NAME(m_leds_state));
195   save_item(NAME(m_leds_cache));
196   save_item(NAME(m_leds_decay));
197
93198   save_item(NAME(m_r));
94199   save_item(NAME(m_o));
95200}
r242956r242957
103208   MCFG_TMS1XXX_WRITE_O_CB(WRITE16(splitsec_state, write_o))
104209   MCFG_TMS1XXX_WRITE_R_CB(WRITE16(splitsec_state, write_r))
105210
211   MCFG_TIMER_DRIVER_ADD_PERIODIC("leds_decay", splitsec_state, leds_decay_tick, attotime::from_msec(10))
212
106213   MCFG_DEFAULT_LAYOUT(layout_splitsec)
107214
108215   /* no video! */


Previous 199869 Revisions Next


© 1997-2024 The MAME Team