summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/drivers/alnchase.c
blob: 1159ed829c62ac704b79ef0302a6bed827090595 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// license:BSD-3-Clause
// copyright-holders:hap
/***************************************************************************

  Tomy Alien Chase (manufactured in Japan)
  * boards are labeled TN-16
  * NEC uCOM-43 MCU, labeled D553C 258
  * red/green VFD display with color overlay, 2-sided*

  *Player one views the VFD from the front (grid+filament side) while the
  opposite player views it from the back side (through the conductive traces),
  basically a mirror-image.

  This is a space-themed tabletop VFD electronic game. To start, simply
  press [UP]. Hold a joystick direction to move around.

  NOTE!: MESS external artwork is required to be able to play


  TODO:
  - display should go off when sound is played, needs decay simulation?

***************************************************************************/

#include "emu.h"
#include "cpu/ucom4/ucom4.h"
#include "sound/speaker.h"

#include "alnchase.lh" // this is a test layout, external artwork is necessary


class alnchase_state : public driver_device
{
public:
	alnchase_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag),
		m_maincpu(*this, "maincpu"),
		m_button_matrix(*this, "IN"),
		m_speaker(*this, "speaker")
	{ }

	required_device<cpu_device> m_maincpu;
	required_ioport_array<2> m_button_matrix;
	required_device<speaker_sound_device> m_speaker;

	UINT8 m_input_mux;
	UINT32 m_plate;
	UINT16 m_grid;

	DECLARE_READ8_MEMBER(input_r);
	DECLARE_WRITE8_MEMBER(display_w);
	DECLARE_WRITE8_MEMBER(port_e_w);

	UINT32 m_vfd_state[0x10];
	void update_vfd();

	virtual void machine_start();
};



/***************************************************************************

  Display

***************************************************************************/

void alnchase_state::update_vfd()
{
	for (int i = 0; i < 9; i++)
		if (m_grid & (1 << i) && m_vfd_state[i] != m_plate)
		{
			// on difference, send to output
			for (int j = 0; j < 17; j++)
				output_set_lamp_value(i*100 + j, m_plate >> j & 1);

			m_vfd_state[i] = m_plate;
		}
}



/***************************************************************************

  I/O

***************************************************************************/

READ8_MEMBER(alnchase_state::input_r)
{
	UINT8 inp = 0;

	// read selected button rows
	for (int i = 0; i < 2; i++)
		if (m_input_mux >> i & 1)
			inp |= m_button_matrix[i]->read();

	return inp;
}

WRITE8_MEMBER(alnchase_state::display_w)
{
	int shift;

	if (offset <= NEC_UCOM4_PORTE)
	{
		// C/D/E0: vfd matrix grid
		shift = (offset - NEC_UCOM4_PORTC) * 4;
		m_grid = (m_grid & ~(0xf << shift)) | (data << shift);

		// C0(grid 0): input enable PL1
		// D0(grid 4): input enable PL2
		m_input_mux = (m_grid & 1) | (m_grid >> 3 & 2);
	}

	if (offset >= NEC_UCOM4_PORTE)
	{
		// E23/F/G/H/I: vfd matrix plate
		shift = (offset - NEC_UCOM4_PORTE) * 4;
		m_plate = ((m_plate << 2 & ~(0xf << shift)) | (data << shift)) >> 2;
	}

	update_vfd();
}

WRITE8_MEMBER(alnchase_state::port_e_w)
{
	display_w(space, offset, data);

	// E1: speaker out
	m_speaker->level_w(data >> 1 & 1);
}



/***************************************************************************

  Inputs

***************************************************************************/

/* physical button layout and labels is like this:

    POWER SOUND LEVEL PLAYER
     ON    ON    PRO   TWO        START
      o     o     |     |
      |     |     |     |       [joystick]
      |     |     o     o
     OFF   OFF   AMA   ONE     GAME 0,1,2,3

    1 PLAYER SIDE

    other player side only has a joystick
*/

static INPUT_PORTS_START( alnchase )
	PORT_START("IN.0") // C0 port A
	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT )
	PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT )
	PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN )
	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP )

	PORT_START("IN.1") // D0 port A
	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) // on non-mirrored view, swap P2 left/right
	PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) // "
	PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2)

	PORT_START("SW") // port B
	PORT_CONFNAME( 0x01, 0x01, "Players" )
	PORT_CONFSETTING(    0x01, "1" )
	PORT_CONFSETTING(    0x00, "2" )
	PORT_CONFNAME( 0x02, 0x00, DEF_STR( Difficulty ) )
	PORT_CONFSETTING(    0x00, "Amateur" )
	PORT_CONFSETTING(    0x02, "Professional" )
	PORT_BIT( 0x0c, IP_ACTIVE_HIGH, IPT_UNUSED )
INPUT_PORTS_END



/***************************************************************************

  Machine Config

***************************************************************************/

void alnchase_state::machine_start()
{
	// zerofill
	memset(m_vfd_state, 0, sizeof(m_vfd_state));
	m_input_mux = 0;
	m_plate = 0;
	m_grid = 0;

	// register for savestates
	save_item(NAME(m_vfd_state));
	save_item(NAME(m_input_mux));
	save_item(NAME(m_plate));
	save_item(NAME(m_grid));
}


static MACHINE_CONFIG_START( alnchase, alnchase_state )

	/* basic machine hardware */
	MCFG_CPU_ADD("maincpu", NEC_D553, XTAL_400kHz)
	MCFG_UCOM4_READ_A_CB(READ8(alnchase_state, input_r))
	MCFG_UCOM4_READ_B_CB(IOPORT("SW"))
	MCFG_UCOM4_WRITE_C_CB(WRITE8(alnchase_state, display_w))
	MCFG_UCOM4_WRITE_D_CB(WRITE8(alnchase_state, display_w))
	MCFG_UCOM4_WRITE_E_CB(WRITE8(alnchase_state, port_e_w))
	MCFG_UCOM4_WRITE_F_CB(WRITE8(alnchase_state, display_w))
	MCFG_UCOM4_WRITE_G_CB(WRITE8(alnchase_state, display_w))
	MCFG_UCOM4_WRITE_H_CB(WRITE8(alnchase_state, display_w))
	MCFG_UCOM4_WRITE_I_CB(WRITE8(alnchase_state, display_w))

	MCFG_DEFAULT_LAYOUT(layout_alnchase)

	/* no video! */

	/* sound hardware */
	MCFG_SPEAKER_STANDARD_MONO("mono")
	MCFG_SOUND_ADD("speaker", SPEAKER_SOUND, 0)
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
MACHINE_CONFIG_END



/***************************************************************************

  Game driver(s)

***************************************************************************/

ROM_START( alnchase )
	ROM_REGION( 0x0800, "maincpu", 0 )
	ROM_LOAD( "d553c-258", 0x0000, 0x0800, CRC(c5284ff5) SHA1(6a20aaacc9748f0e0335958f3cea482e36153704) )
ROM_END


CONS( 1984, alnchase, 0, 0, alnchase, alnchase, driver_device, 0, "Tomy", "Alien Chase", GAME_SUPPORTS_SAVE | GAME_REQUIRES_ARTWORK )