Previous 199869 Revisions Next

r36426 Sunday 15th March, 2015 at 02:53:05 UTC by hap
ticalc1x.c cleanup part 1
[src/mess/drivers]ticalc1x.c

trunk/src/mess/drivers/ticalc1x.c
r244937r244938
1414
1515#include "emu.h"
1616#include "cpu/tms0980/tms0980.h"
17#include "sound/speaker.h"
1718
19// internal artwork
1820#include "ti1270.lh"
1921#include "ti30.lh"
2022#include "tisr16.lh"
r244937r244938
2729   ticalc1x_state(const machine_config &mconfig, device_type type, const char *tag)
2830      : driver_device(mconfig, type, tag),
2931      m_maincpu(*this, "maincpu"),
30      m_button_matrix(*this, "IN")
32      m_inp_matrix(*this, "IN"),
33      m_speaker(*this, "speaker"),
34      m_display_wait(33),
35      m_display_maxy(1),
36      m_display_maxx(0)
3137   { }
3238
39   // devices
3340   required_device<cpu_device> m_maincpu;
34   optional_ioport_array<11> m_button_matrix; // up to 11 rows
41   optional_ioport_array<11> m_inp_matrix; // max 11
42   optional_device<speaker_sound_device> m_speaker;
3543
36   UINT16 m_r;
37   UINT16 m_o;
38   bool m_power_on;
44   // misc common
45   UINT16 m_r;                         // MCU R-pins data
46   UINT16 m_o;                         // MCU O-pins data
47   UINT16 m_inp_mux;                   // multiplexed inputs mask
48   bool m_power_on;                    // TMS0980 power-on state
3949
40   UINT16 m_display_state[0x10];
41   UINT16 m_display_cache[0x10];
42   UINT8 m_display_decay[0x100];
50   UINT8 read_inputs(int columns);
51   DECLARE_INPUT_CHANGED_MEMBER(tms0980_power_button);
52   DECLARE_WRITE_LINE_MEMBER(tms0980_auto_power_off);
4353
54   virtual void machine_reset();
55   virtual void machine_start();
56
57   // display common
58   int m_display_wait;                 // led/lamp off-delay in microseconds (default 33ms)
59   int m_display_maxy;                 // display matrix number of rows
60   int m_display_maxx;                 // display matrix number of columns
61   
62   UINT32 m_display_state[0x20];       // display matrix rows data
63   UINT16 m_7seg_mask[0x20];           // if not 0, display matrix row is a 7seg, mask indicates connected segments
64   UINT32 m_display_cache[0x20];       // (internal use)
65   UINT8 m_display_decay[0x20][0x20];  // (internal use)
66
67   TIMER_DEVICE_CALLBACK_MEMBER(display_decay_tick);
68   void display_update();
69   void display_matrix(int maxx, int maxy, UINT32 setx, UINT32 sety);
70   
71   // calculator-specific handlers
4472   DECLARE_READ8_MEMBER(tisr16_read_k);
4573   DECLARE_WRITE16_MEMBER(tisr16_write_o);
4674   DECLARE_WRITE16_MEMBER(tisr16_write_r);
r244937r244938
5785   DECLARE_READ8_MEMBER(ti30_read_k);
5886   DECLARE_WRITE16_MEMBER(ti30_write_o);
5987   DECLARE_WRITE16_MEMBER(ti30_write_r);
88};
6089
61   DECLARE_INPUT_CHANGED_MEMBER(power_button);
62   DECLARE_WRITE_LINE_MEMBER(auto_power_off);
6390
64   TIMER_DEVICE_CALLBACK_MEMBER(display_decay_tick);
65   void display_update();
91// machine_start/reset
6692
67   virtual void machine_reset();
68   virtual void machine_start();
69};
93void ticalc1x_state::machine_start()
94{
95   // zerofill
96   memset(m_display_state, 0, sizeof(m_display_state));
97   memset(m_display_cache, 0, sizeof(m_display_cache));
98   memset(m_display_decay, 0, sizeof(m_display_decay));
99   memset(m_7seg_mask, 0, sizeof(m_7seg_mask));
100   
101   m_o = 0;
102   m_r = 0;
103   m_inp_mux = 0;
104   m_power_on = false;
70105
106   // register for savestates
107   save_item(NAME(m_display_maxy));
108   save_item(NAME(m_display_maxx));
109   save_item(NAME(m_display_wait));
71110
111   save_item(NAME(m_display_state));
112   save_item(NAME(m_display_cache));
113   save_item(NAME(m_display_decay));
114   save_item(NAME(m_7seg_mask));
72115
116   save_item(NAME(m_o));
117   save_item(NAME(m_r));
118   save_item(NAME(m_inp_mux));
119   save_item(NAME(m_power_on));
120}
121
122void ticalc1x_state::machine_reset()
123{
124   m_power_on = true;
125}
126
127
128
73129/***************************************************************************
74130
75  LED Display
131  Helper Functions
76132
77133***************************************************************************/
78134
79// Devices with TMS09x0 strobe the outputs very fast, it is unnoticeable to the user.
135// The device may strobe the outputs very fast, it is unnoticeable to the user.
80136// To prevent flickering here, we need to simulate a decay.
81137
82// decay time, in steps of 1ms
83#define DISPLAY_DECAY_TIME 50
84
85138void ticalc1x_state::display_update()
86139{
87   UINT16 active_state[0x10];
140   UINT32 active_state[0x20];
88141
89   for (int i = 0; i < 0x10; i++)
142   for (int y = 0; y < m_display_maxy; y++)
90143   {
91      active_state[i] = 0;
144      active_state[y] = 0;
92145
93      for (int j = 0; j < 0x10; j++)
146      for (int x = 0; x < m_display_maxx; x++)
94147      {
95         int di = j << 4 | i;
96
97148         // turn on powered segments
98         if (m_power_on && m_display_state[i] >> j & 1)
99            m_display_decay[di] = DISPLAY_DECAY_TIME;
149         if (m_power_on && m_display_state[y] >> x & 1)
150            m_display_decay[y][x] = m_display_wait;
100151
101152         // determine active state
102         int ds = (m_display_decay[di] != 0) ? 1 : 0;
103         active_state[i] |= (ds << j);
153         int ds = (m_display_decay[y][x] != 0) ? 1 : 0;
154         active_state[y] |= (ds << x);
104155      }
105156   }
106157
107158   // on difference, send to output
108   for (int i = 0; i < 0x10; i++)
109      if (m_display_cache[i] != active_state[i])
159   for (int y = 0; y < m_display_maxy; y++)
160      if (m_display_cache[y] != active_state[y])
110161      {
111         output_set_digit_value(i, active_state[i]);
162         if (m_7seg_mask[y] != 0)
163            output_set_digit_value(y, active_state[y] & m_7seg_mask[y]);
112164
113         for (int j = 0; j < 8; j++)
114            output_set_lamp_value(i*10 + j, active_state[i] >> j & 1);
165         const int mul = (m_display_maxx <= 10) ? 10 : 100;
166         for (int x = 0; x < m_display_maxx; x++)
167            output_set_lamp_value(y * mul + x, active_state[y] >> x & 1);
115168      }
116169
117170   memcpy(m_display_cache, active_state, sizeof(m_display_cache));
r244937r244938
120173TIMER_DEVICE_CALLBACK_MEMBER(ticalc1x_state::display_decay_tick)
121174{
122175   // slowly turn off unpowered segments
123   for (int i = 0; i < 0x100; i++)
124      if (!(m_display_state[i & 0xf] >> (i>>4) & 1) && m_display_decay[i])
125         m_display_decay[i]--;
176   for (int y = 0; y < m_display_maxy; y++)
177      for (int x = 0; x < m_display_maxx; x++)
178         if (!(m_display_state[y] >> x & 1) && m_display_decay[y][x] != 0)
179            m_display_decay[y][x]--;
180   
181   display_update();
182}
126183
184void ticalc1x_state::display_matrix(int maxx, int maxy, UINT32 setx, UINT32 sety)
185{
186   m_display_maxx = maxx;
187   m_display_maxy = maxy;
188
189   // update current state
190   UINT32 mask = (1 << maxx) - 1;
191   for (int y = 0; y < maxy; y++)
192      m_display_state[y] = (sety >> y & 1) ? (setx & mask) : 0;
193   
127194   display_update();
128195}
129196
130197
198UINT8 ticalc1x_state::read_inputs(int columns)
199{
200   UINT8 ret = 0;
131201
202   // read selected input rows
203   for (int i = 0; i < columns; i++)
204      if (m_inp_mux >> i & 1)
205         ret |= m_inp_matrix[i]->read();
206
207   return ret;
208}
209
210
211// devices with a TMS0980 can auto power-off
212
213WRITE_LINE_MEMBER(ticalc1x_state::tms0980_auto_power_off)
214{
215   if (state)
216   {
217      m_power_on = false;
218      m_maincpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
219   }
220}
221
222INPUT_CHANGED_MEMBER(ticalc1x_state::tms0980_power_button)
223{
224   m_power_on = (bool)(FPTR)param;
225   m_maincpu->set_input_line(INPUT_LINE_RESET, m_power_on ? CLEAR_LINE : ASSERT_LINE);
226}
227
228
229
132230/***************************************************************************
133231
134232  I/O
r244937r244938
159257   // read selected button rows
160258   for (int i = 0; i < 11; i++)
161259      if (m_r >> i & 1)
162         k |= m_button_matrix[i]->read();
260         k |= m_inp_matrix[i]->read();
163261
164262   return k;
165263}
r244937r244938
191289   // read selected button rows
192290   for (int i = 0; i < 7; i++)
193291      if (m_o >> (i+1) & 1)
194         k |= m_button_matrix[i]->read();
292         k |= m_inp_matrix[i]->read();
195293
196294   return k;
197295}
198296
199297WRITE16_MEMBER(ticalc1x_state::ti1270_write_r)
200298{
299   m_display_maxx = 8;
300   m_display_maxy = 8;
301
201302   // R0-R7: select digit (right-to-left)
202303   for (int i = 0; i < 8; i++)
304   {
305      m_7seg_mask[i] = 0xff;
203306      m_display_state[i] = (data >> i & 1) ? m_o : 0;
307   }
204308
205309   display_update();
206310}
r244937r244938
222326   // read selected button rows
223327   for (int i = 0; i < 4; i++)
224328      if (m_o >> (i+1) & 1)
225         k |= m_button_matrix[i]->read();
329         k |= m_inp_matrix[i]->read();
226330
227331   return k;
228332}
229333
230334WRITE16_MEMBER(ticalc1x_state::wizatron_write_r)
231335{
336   m_display_maxx = 8;
337   m_display_maxy = 9;
338
232339   // R0-R8: select digit (right-to-left)
233340   // note: 3rd digit is custom(not 7seg), for math symbols
234341   for (int i = 0; i < 9; i++)
342   {
343      m_7seg_mask[i] = 0x7f;
235344      m_display_state[i] = (data >> i & 1) ? m_o : 0;
345   }
236346
237347   // 6th digit only has A and G for =
238348   m_display_state[3] &= 0x41;
r244937r244938
256366READ8_MEMBER(ticalc1x_state::ti30_read_k)
257367{
258368   // the Vss row is always on
259   UINT8 k = m_button_matrix[8]->read();
369   UINT8 k = m_inp_matrix[8]->read();
260370
261371   // read selected button rows
262372   for (int i = 0; i < 8; i++)
263373      if (m_o >> i & 1)
264         k |= m_button_matrix[i]->read();
374         k |= m_inp_matrix[i]->read();
265375
266376   return k;
267377}
268378
269379WRITE16_MEMBER(ticalc1x_state::ti30_write_r)
270380{
381   m_display_maxx = 8;
382   m_display_maxy = 9;
383
271384   // R0-R8: select digit
272385   UINT8 o = BITSWAP8(m_o,7,5,2,1,4,0,6,3);
273386   for (int i = 0; i < 9; i++)
387   {
388      m_7seg_mask[i] = 0xff;
274389      m_display_state[i] = (data >> i & 1) ? o : 0;
390   }
275391
276392   // 1st digit only has segments B,F,G,DP
277393   m_display_state[0] &= 0xe2;
r244937r244938
294410
295411***************************************************************************/
296412
297INPUT_CHANGED_MEMBER(ticalc1x_state::power_button)
298{
299   m_power_on = (bool)(FPTR)param;
300   m_maincpu->set_input_line(INPUT_LINE_RESET, m_power_on ? CLEAR_LINE : ASSERT_LINE);
301}
302
303413static INPUT_PORTS_START( tisr16 )
304414   PORT_START("IN.0") // R0
305415   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED )
r244937r244938
496606
497607   // note: even though power buttons are on the matrix, they are not CPU-controlled
498608   PORT_START("IN.8") // Vss!
499   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PGUP) PORT_CODE(KEYCODE_DEL) PORT_NAME("ON/C") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, power_button, (void *)true)
609   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PGUP) PORT_CODE(KEYCODE_DEL) PORT_NAME("ON/C") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, tms0980_power_button, (void *)true)
500610   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_X) PORT_NAME("1/x")
501611   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_R) PORT_NAME(UTF8_SQUAREROOT"x")
502612   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q) PORT_NAME("x" UTF8_POW_2)
503   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PGDN) PORT_NAME("OFF") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, power_button, (void *)false)
613   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PGDN) PORT_NAME("OFF") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, tms0980_power_button, (void *)false)
504614INPUT_PORTS_END
505615
506616
r244937r244938
559669
560670   // note: even though power buttons are on the matrix, they are not CPU-controlled
561671   PORT_START("IN.8") // Vss!
562   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_DEL) PORT_CODE(KEYCODE_PGUP) PORT_NAME("C/ON") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, power_button, (void *)true)
672   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_DEL) PORT_CODE(KEYCODE_PGUP) PORT_NAME("C/ON") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, tms0980_power_button, (void *)true)
563673   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_G) PORT_NAME("DEC")
564674   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_J) PORT_NAME("OCT")
565675   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_H) PORT_NAME("HEX")
566   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PGDN) PORT_NAME("OFF") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, power_button, (void *)false)
676   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PGDN) PORT_NAME("OFF") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, tms0980_power_button, (void *)false)
567677INPUT_PORTS_END
568678
569679
r244937r244938
623733
624734   // note: even though power buttons are on the matrix, they are not CPU-controlled
625735   PORT_START("IN.8") // Vss!
626   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PGUP) PORT_CODE(KEYCODE_DEL) PORT_NAME("ON/C") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, power_button, (void *)true)
736   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PGUP) PORT_CODE(KEYCODE_DEL) PORT_NAME("ON/C") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, tms0980_power_button, (void *)true)
627737   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_NAME("2nd")
628738   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q) PORT_NAME("x" UTF8_POW_2"  " UTF8_SQUAREROOT"x")
629739   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_L) PORT_NAME("ln(x)  e" UTF8_POW_X)
630   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PGDN) PORT_NAME("OFF") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, power_button, (void *)false)
740   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_PGDN) PORT_NAME("OFF") PORT_CHANGED_MEMBER(DEVICE_SELF, ticalc1x_state, tms0980_power_button, (void *)false)
631741INPUT_PORTS_END
632742
633743
r244937r244938
638748
639749***************************************************************************/
640750
641WRITE_LINE_MEMBER(ticalc1x_state::auto_power_off)
642{
643   // TMS0980 auto power-off opcode
644   if (state)
645   {
646      m_power_on = false;
647      m_maincpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
648   }
649}
650
651
652void ticalc1x_state::machine_reset()
653{
654   m_power_on = true;
655}
656
657void ticalc1x_state::machine_start()
658{
659   // zerofill
660   memset(m_display_state, 0, sizeof(m_display_state));
661   memset(m_display_cache, 0, sizeof(m_display_cache));
662   memset(m_display_decay, 0, sizeof(m_display_decay));
663
664   m_r = 0;
665   m_o = 0;
666   m_power_on = false;
667
668   // register for savestates
669   save_item(NAME(m_display_state));
670   save_item(NAME(m_display_cache));
671   save_item(NAME(m_display_decay));
672
673   save_item(NAME(m_r));
674   save_item(NAME(m_o));
675   save_item(NAME(m_power_on));
676}
677
678
679751static MACHINE_CONFIG_START( tisr16, ticalc1x_state )
680752
681753   /* basic machine hardware */
r244937r244938
739811   MCFG_TMS1XXX_READ_K_CB(READ8(ticalc1x_state, ti30_read_k))
740812   MCFG_TMS1XXX_WRITE_O_CB(WRITE16(ticalc1x_state, ti30_write_o))
741813   MCFG_TMS1XXX_WRITE_R_CB(WRITE16(ticalc1x_state, ti30_write_r))
742   MCFG_TMS1XXX_POWER_OFF_CB(WRITELINE(ticalc1x_state, auto_power_off))
814   MCFG_TMS1XXX_POWER_OFF_CB(WRITELINE(ticalc1x_state, tms0980_auto_power_off))
743815
744816   MCFG_DEFAULT_LAYOUT(layout_ti30)
745817MACHINE_CONFIG_END


Previous 199869 Revisions Next


© 1997-2024 The MAME Team