Previous 15994 Revisions Next

r9901 Monday 3rd January, 2011 at 04:11:43 UTC by Robbbert
[TEC1] Converted to MODERN.
[src/mess/drivers]tec1.c

src/mess/drivers/tec1.c
r9900r9901
4242It's only taken 25 years to get around to emulating it...
4343
4444***************************************************************************/
45#define ADDRESS_MAP_MODERN
4546
4647#include "emu.h"
4748#include "cpu/z80/z80.h"
r9900r9901
5354{
5455public:
5556   tec1_state(running_machine &machine, const driver_device_config_base &config)
56      : driver_device(machine, config) { }
57      : driver_device(machine, config),
58        m_maincpu(*this, "maincpu"),
59        m_speaker(*this, "speaker")
60   { }
5761
58   emu_timer *kbd_timer;
59   UINT8 kbd;
60   UINT8 segment;
61   UINT8 digit;
62   device_t *speaker;
63   UINT8 kbd_row;
62   required_device<cpu_device> m_maincpu;
63   required_device<device_t> m_speaker;
64   emu_timer *m_kbd_timer;
65   DECLARE_READ8_MEMBER( tec1_kbd_r );
66   DECLARE_WRITE8_MEMBER( tec1_digit_w );
67   DECLARE_WRITE8_MEMBER( tec1_segment_w );
68   UINT8 m_kbd;
69   UINT8 m_segment;
70   UINT8 m_digit;
71   UINT8 m_kbd_row;
72   void tec1_display();
73   UINT8 tec1_convert_col_to_bin( UINT8 col, UINT8 row );
6474};
6575
6676
r9900r9901
7181    Display
7282
7383***************************************************************************/
74
75static void tec1_display(tec1_state *state)
84void tec1_state::tec1_display()
7685{
7786   UINT8 i;
7887   for (i = 0; i < 6; i++)
79      if (state->digit & (1 << i))
80         output_set_digit_value(5-i, state->segment);
88      if (m_digit & (1 << i))
89         output_set_digit_value(5-i, m_segment);
8190}
8291
83static WRITE8_HANDLER( tec1_segment_w )
92WRITE8_MEMBER( tec1_state::tec1_segment_w )
8493{
85   tec1_state *state = space->machine->driver_data<tec1_state>();
8694/*  d7 segment d
8795    d6 segment e
8896    d5 segment c
r9900r9901
92100    d1 segment f
93101    d0 segment a */
94102
95   state->segment = BITSWAP8(data, 4, 2, 1, 6, 7, 5, 3, 0);
96   if (state->digit) tec1_display(state);
103   m_segment = BITSWAP8(data, 4, 2, 1, 6, 7, 5, 3, 0);
104   if (m_digit) tec1_display();
97105}
98106
99static WRITE8_HANDLER( tec1_digit_w )
107WRITE8_MEMBER( tec1_state::tec1_digit_w )
100108{
101   tec1_state *state = space->machine->driver_data<tec1_state>();
102109/*  d7 speaker
103110    d6 not used
104111    d5 data digit 1
r9900r9901
108115    d1 address digit 3
109116    d0 address digit 4 */
110117
111   speaker_level_w(state->speaker, (data & 0x80) ? 1 : 0);
118   speaker_level_w(m_speaker, (data & 0x80) ? 1 : 0);
112119
113   state->digit = data & 0x3f;
114   if (state->digit) tec1_display(state);
120   m_digit = data & 0x3f;
121   if (m_digit) tec1_display();
115122}
116123
117124
r9900r9901
121128
122129***************************************************************************/
123130
124static READ8_HANDLER( tec1_kbd_r )
131READ8_MEMBER( tec1_state::tec1_kbd_r )
125132{
126   tec1_state *state = space->machine->driver_data<tec1_state>();
127   cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE);
128   return state->kbd;
133   cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE);
134   return m_kbd;
129135}
130136
131static UINT8 tec1_convert_col_to_bin( UINT8 col, UINT8 row )
137UINT8 tec1_state::tec1_convert_col_to_bin( UINT8 col, UINT8 row )
132138{
133139   UINT8 data = row;
134140
r9900r9901
147153   return data;
148154}
149155
150
151static const char *const keynames[] = { "LINE0", "LINE1", "LINE2", "LINE3" };
152
153156static TIMER_CALLBACK( tec1_kbd_callback )
154157{
158   static const char *const keynames[] = { "LINE0", "LINE1", "LINE2", "LINE3" };
155159   tec1_state *state = machine->driver_data<tec1_state>();
156/* 74C923 4 by 5 key encoder. */
157   /* if previous key is still held, bail out */
158   if (input_port_read(machine, keynames[state->kbd_row]))
159      if (tec1_convert_col_to_bin(input_port_read(machine, keynames[state->kbd_row]), state->kbd_row) == state->kbd)
160    /* 74C923 4 by 5 key encoder. */
161    /* if previous key is still held, bail out */
162   if (input_port_read(machine, keynames[state->m_kbd_row]))
163      if (state->tec1_convert_col_to_bin(input_port_read(machine, keynames[state->m_kbd_row]), state->m_kbd_row) == state->m_kbd)
160164         return;
161165
162   state->kbd_row++;
163   state->kbd_row &= 3;
166   state->m_kbd_row++;
167   state->m_kbd_row &= 3;
164168
165169   /* see if a key pressed */
166   if (input_port_read(machine, keynames[state->kbd_row]))
170   if (input_port_read(machine, keynames[state->m_kbd_row]))
167171   {
168      state->kbd = tec1_convert_col_to_bin(input_port_read(machine, keynames[state->kbd_row]), state->kbd_row);
172      state->m_kbd = state->tec1_convert_col_to_bin(input_port_read(machine, keynames[state->m_kbd_row]), state->m_kbd_row);
169173      cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, HOLD_LINE);
170174   }
171175}
r9900r9901
180184static MACHINE_START( tec1 )
181185{
182186   tec1_state *state = machine->driver_data<tec1_state>();
183   state->kbd_timer = timer_alloc(machine,  tec1_kbd_callback, NULL );
184   timer_adjust_periodic( state->kbd_timer, attotime_zero, 0, ATTOTIME_IN_HZ(500) );
185   state->speaker = machine->device("speaker");
187   state->m_kbd_timer = timer_alloc(machine,  tec1_kbd_callback, NULL );
188   timer_adjust_periodic( state->m_kbd_timer, attotime_zero, 0, ATTOTIME_IN_HZ(500) );
186189}
187190
188191static MACHINE_RESET( tec1 )
189192{
190193   tec1_state *state = machine->driver_data<tec1_state>();
191   state->kbd = 0;
194   state->m_kbd = 0;
192195}
193196
194197
r9900r9901
199202
200203***************************************************************************/
201204
202static ADDRESS_MAP_START( tec1_map, ADDRESS_SPACE_PROGRAM, 8 )
205static ADDRESS_MAP_START( tec1_map, ADDRESS_SPACE_PROGRAM, 8, tec1_state )
203206   ADDRESS_MAP_GLOBAL_MASK(0x3fff)
204207   AM_RANGE(0x0000, 0x07ff) AM_ROM
205208   AM_RANGE(0x0800, 0x17ff) AM_RAM
206209ADDRESS_MAP_END
207210
208static ADDRESS_MAP_START( tec1_io, ADDRESS_SPACE_IO, 8 )
211static ADDRESS_MAP_START( tec1_io, ADDRESS_SPACE_IO, 8, tec1_state )
209212   ADDRESS_MAP_GLOBAL_MASK(0x07)
210213   AM_RANGE(0x00, 0x00) AM_READ(tec1_kbd_r)
211214   AM_RANGE(0x01, 0x01) AM_WRITE(tec1_digit_w)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team