Previous 199869 Revisions Next

r33661 Wednesday 3rd December, 2014 at 21:01:58 UTC by hap
added leds decay simulation (copypasted from ticalc1x.c)
[src/mess/drivers]cnsector.c
[src/mess/layout]cnsector.lay

trunk/src/mess/drivers/cnsector.c
r242172r242173
3232
3333   UINT16 m_o;
3434
35   UINT16 m_leds_state[0x10];
36   UINT16 m_leds_cache[0x10];
37   UINT8 m_leds_decay[0x100];
38
3539   DECLARE_READ8_MEMBER(read_k);
3640   DECLARE_WRITE16_MEMBER(write_o);
3741   DECLARE_WRITE16_MEMBER(write_r);
3842
43   TIMER_DEVICE_CALLBACK_MEMBER(leds_decay_tick);
44   void leds_update();
45
3946   virtual void machine_start();
4047};
4148
r242172r242173
4350
4451/***************************************************************************
4552
53  LEDs
54
55***************************************************************************/
56
57// Devices with TMS09x0 strobe the outputs very fast, it is unnoticeable to the user.
58// To prevent flickering here, we need to simulate a decay.
59
60// decay time, in steps of 10ms
61#define LEDS_DECAY_TIME 4
62
63void cnsector_state::leds_update()
64{
65   UINT16 active_state[0x10];
66   
67   for (int i = 0; i < 0x10; i++)
68   {
69      active_state[i] = 0;
70     
71      for (int j = 0; j < 0x10; j++)
72      {
73         int di = j << 4 | i;
74         
75         // turn on powered leds
76         if (m_leds_state[i] >> j & 1)
77            m_leds_decay[di] = LEDS_DECAY_TIME;
78         
79         // determine active state
80         int ds = (m_leds_decay[di] != 0) ? 1 : 0;
81         active_state[i] |= (ds << j);
82      }
83   }
84   
85   // on difference, send to output
86   for (int i = 0; i < 0x10; i++)
87      if (m_leds_cache[i] != active_state[i])
88         output_set_digit_value(i, active_state[i]);
89   
90   memcpy(m_leds_cache, active_state, sizeof(m_leds_cache));
91}
92
93TIMER_DEVICE_CALLBACK_MEMBER(cnsector_state::leds_decay_tick)
94{
95   // slowly turn off unpowered leds
96   for (int i = 0; i < 0x100; i++)
97      if (!(m_leds_state[i & 0xf] >> (i>>4) & 1) && m_leds_decay[i])
98         m_leds_decay[i]--;
99   
100   leds_update();
101}
102
103
104
105/***************************************************************************
106
46107  I/O
47108
48109***************************************************************************/
r242172r242173
61122
62123WRITE16_MEMBER(cnsector_state::write_r)
63124{
64   // R0-R5: select digit
125   // R0-R5: select digit (right-to-left)
65126   for (int i = 0; i < 6; i++)
66      output_set_digit_value(i, (data >> i & 1) ? m_o : 0);
127      m_leds_state[i] = (data >> i & 1) ? m_o : 0;
128   leds_update();
67129
68130   // R6-R9: direction leds
69131   for (int i = 6; i < 10; i++)
r242172r242173
127189
128190void cnsector_state::machine_start()
129191{
192   memset(m_leds_state, 0, sizeof(m_leds_state));
193   memset(m_leds_cache, 0, sizeof(m_leds_cache));
194   memset(m_leds_decay, 0, sizeof(m_leds_decay));
130195   m_o = 0;
131196   
132197   save_item(NAME(m_o));
r242172r242173
141206   MCFG_TMS1XXX_WRITE_O_CB(WRITE16(cnsector_state, write_o))
142207   MCFG_TMS1XXX_WRITE_R_CB(WRITE16(cnsector_state, write_r))
143208   
209   MCFG_TIMER_DRIVER_ADD_PERIODIC("leds_decay", cnsector_state, leds_decay_tick, attotime::from_msec(10))
210
144211   MCFG_DEFAULT_LAYOUT(layout_cnsector)
145212
146213   /* no video! */
trunk/src/mess/layout/cnsector.lay
r242172r242173
1818   <view name="Internal Layout">
1919      <bounds left="0" right="200" top="0" bottom="200" />
2020
21      <bezel name="digit0" element="digit">
21      <bezel name="digit5" element="digit">
2222         <bounds x="0" y="0" width="10" height="15" />
2323      </bezel>
24      <bezel name="digit1" element="digit">
25         <bounds x="10" y="0" width="10" height="15" />
26      </bezel>
27      <bezel name="digit2" element="digit">
24      <bezel name="digit4" element="digit">
2825         <bounds x="20" y="0" width="10" height="15" />
2926      </bezel>
3027      <bezel name="digit3" element="digit">
31         <bounds x="30" y="0" width="10" height="15" />
32      </bezel>
33      <bezel name="digit4" element="digit">
3428         <bounds x="40" y="0" width="10" height="15" />
3529      </bezel>
36      <bezel name="digit5" element="digit">
30      <bezel name="digit2" element="digit">
3731         <bounds x="50" y="0" width="10" height="15" />
3832      </bezel>
33      <bezel name="digit1" element="digit">
34         <bounds x="60" y="0" width="10" height="15" />
35      </bezel>
36      <bezel name="digit0" element="digit">
37         <bounds x="70" y="0" width="10" height="15" />
38      </bezel>
3939
4040      <bezel name="lamp0" element="lamp">
4141         <bounds x="20" y="20" width="5" height="5" />


Previous 199869 Revisions Next


© 1997-2024 The MAME Team