summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/drivers/marywu.cpp
blob: ba5a66d5e8b39e25ccb14907b68916099984ad48 (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
// license:GPL-2.0+
// copyright-holders:Felipe Sanches
/*************************************************************************

  This is a driver for a gambling board with a yet unknown name.
  The PCB is labeled with: WU- MARY-1A
  And there's a text string in the ROM that says: "Music by: SunKiss Chen"

  Driver by Felipe Sanches

  TODO:
  * Figure out where exactly all devices are mapped to (the devices are
    2 sound chips, the 2kb SRAM, the 8bit dipswitches,
    31 LEDs, 13 modules of double-digit 7-seg displays and 4 push-buttons).
  * we may also have user inputs from the coin slot and from the
    cabinet buttons, for making bets.
**************************************************************************/

#include "emu.h"
#include "cpu/mcs51/mcs51.h"
#include "machine/i8279.h"
#include "sound/ay8910.h"
#include "speaker.h"

#include "marywu.lh"

class marywu_state : public driver_device
{
public:
	marywu_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag)
		, m_digits(*this, "digit%u", 0U)
		, m_leds(*this, "led%u", 0U)
	{ }

	DECLARE_WRITE8_MEMBER(display_7seg_data_w);
	DECLARE_WRITE8_MEMBER(multiplex_7seg_w);
	DECLARE_WRITE8_MEMBER(ay1_port_a_w);
	DECLARE_WRITE8_MEMBER(ay1_port_b_w);
	DECLARE_WRITE8_MEMBER(ay2_port_a_w);
	DECLARE_WRITE8_MEMBER(ay2_port_b_w);
	DECLARE_READ8_MEMBER(keyboard_r);
	void marywu(machine_config &config);
	void io_map(address_map &map);
	void program_map(address_map &map);
private:
	uint8_t m_selected_7seg_module;
	virtual void machine_start() override;
	output_finder<32> m_digits;
	output_finder<30> m_leds;
};

static INPUT_PORTS_START( marywu )
	PORT_START("KEYS1")
	PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_1)
	PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_2)
	PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_3)
	PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_4)
	PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_5)
	PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_6)
	PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_7)
	PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)

	PORT_START("KEYS2")
	PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Q)
	PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_W)
	PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_E)
	PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_R)
	PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_T)
	PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Y)
	PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_U)
	PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_I)

	PORT_START("DSW")
	PORT_DIPNAME( 0x01, 0x01, "Unknown bit #0" )    PORT_DIPLOCATION("DSW:1")
		PORT_DIPSETTING(0x01, DEF_STR( On ) )
		PORT_DIPSETTING(0x00, DEF_STR( Off ) )
	PORT_DIPNAME( 0x02, 0x02, "Unknown bit #1" )    PORT_DIPLOCATION("DSW:2")
		PORT_DIPSETTING(0x02, DEF_STR( On ) )
		PORT_DIPSETTING(0x00, DEF_STR( Off ) )
	PORT_DIPNAME( 0x04, 0x04, "Unknown bit #2" )    PORT_DIPLOCATION("DSW:3")
		PORT_DIPSETTING(0x04, DEF_STR( On ) )
		PORT_DIPSETTING(0x00, DEF_STR( Off ) )
	PORT_DIPNAME( 0x08, 0x08, "Unknown bit #3" )    PORT_DIPLOCATION("DSW:4")
		PORT_DIPSETTING(0x08, DEF_STR( On ) )
		PORT_DIPSETTING(0x00, DEF_STR( Off ) )
	PORT_DIPNAME( 0x10, 0x10, "Unknown bit #4" )    PORT_DIPLOCATION("DSW:5")
		PORT_DIPSETTING(0x10, DEF_STR( On ) )
		PORT_DIPSETTING(0x00, DEF_STR( Off ) )
	PORT_DIPNAME( 0x20, 0x20, "Unknown bit #5" )    PORT_DIPLOCATION("DSW:6")
		PORT_DIPSETTING(0x20, DEF_STR( On ) )
		PORT_DIPSETTING(0x00, DEF_STR( Off ) )
	PORT_DIPNAME( 0x40, 0x40, "Unknown bit #6" )    PORT_DIPLOCATION("DSW:7")
		PORT_DIPSETTING(0x40, DEF_STR( On ) )
		PORT_DIPSETTING(0x00, DEF_STR( Off ) )
	PORT_DIPNAME( 0x80, 0x80, "Unknown bit #7" )    PORT_DIPLOCATION("DSW:8")
		PORT_DIPSETTING(0x80, DEF_STR( On ) )
		PORT_DIPSETTING(0x00, DEF_STR( Off ) )

	PORT_START("PUSHBUTTONS")
	PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_UNUSED )
	PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_UNUSED )
	PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_UNUSED )
	PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED )
	PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)
	PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_S)
	PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_D)
	PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_F)
INPUT_PORTS_END

WRITE8_MEMBER( marywu_state::ay1_port_a_w )
{
	for (uint8_t i=0; i<8; i++){
		m_leds[i] = BIT(data, i);
	}
}

WRITE8_MEMBER( marywu_state::ay1_port_b_w )
{
	for (uint8_t i=0; i<8; i++){
		m_leds[i+8] = BIT(data, i);
	}
}

WRITE8_MEMBER( marywu_state::ay2_port_a_w )
{
	for (uint8_t i=0; i<8; i++){
		m_leds[i+16] = BIT(data, i);
	}
}

WRITE8_MEMBER( marywu_state::ay2_port_b_w )
{
	for (uint8_t i=0; i<6; i++){
		/* we only have 30 LEDs. The last 2 bits in this port are unused.  */
		m_leds[i+24] = BIT(data, i);
	}
}

WRITE8_MEMBER( marywu_state::multiplex_7seg_w )
{
	m_selected_7seg_module = data;
}

READ8_MEMBER( marywu_state::keyboard_r )
{
	switch(m_selected_7seg_module % 8){
	case 0: return ioport("KEYS1")->read();
		case 1: return ioport("KEYS2")->read();
		case 2: return ioport("DSW")->read();
		case 3: return ioport("PUSHBUTTONS")->read();
	default:
			return 0x00;
	}
}

WRITE8_MEMBER( marywu_state::display_7seg_data_w )
{
	static const uint8_t patterns[16] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7c, 0x07, 0x7f, 0x67, 0, 0, 0, 0, 0, 0 }; // HEF4511BP (7 seg display driver)

	m_digits[2 * m_selected_7seg_module + 0] = patterns[data & 0x0F];
	m_digits[2 * m_selected_7seg_module + 1] = patterns[data >> 4];
}

void marywu_state::program_map(address_map &map)
{
	map(0x0000, 0x7fff).rom();
}

void marywu_state::io_map(address_map &map)
{
	map(0x8000, 0x87ff).mirror(0x0800).ram(); /* HM6116: 2kbytes of Static RAM */
	map(0x9000, 0x9000).mirror(0x0ffc).w("ay1", FUNC(ay8910_device::data_address_w));
	map(0x9001, 0x9001).mirror(0x0ffc).rw("ay1", FUNC(ay8910_device::data_r), FUNC(ay8910_device::data_w));
	map(0x9002, 0x9002).mirror(0x0ffc).w("ay2", FUNC(ay8910_device::data_address_w));
	map(0x9003, 0x9003).mirror(0x0ffc).rw("ay2", FUNC(ay8910_device::data_r), FUNC(ay8910_device::data_w));
	map(0xb000, 0xb001).mirror(0x0ffe).rw("i8279", FUNC(i8279_device::read), FUNC(i8279_device::write));
	map(0xf000, 0xf000).noprw(); /* TODO: Investigate this. There's something going on at this address range. */
}

void marywu_state::machine_start()
{
	m_digits.resolve();
	m_leds.resolve();
}

MACHINE_CONFIG_START(marywu_state::marywu)
	/* basic machine hardware */
	MCFG_DEVICE_ADD("maincpu", I80C31, XTAL(10'738'635)) //actual CPU is a Winbond w78c31b-24
	MCFG_DEVICE_PROGRAM_MAP(program_map)
	MCFG_DEVICE_IO_MAP(io_map)
	//TODO: figure out what each bit is mapped to in the 80c31 ports P1 and P3

	/* Keyboard & display interface */
	MCFG_DEVICE_ADD("i8279", I8279, XTAL(10'738'635)) /* should it be perhaps a fraction of the XTAL clock ? */
	MCFG_I8279_OUT_SL_CB(WRITE8(*this, marywu_state, multiplex_7seg_w))          // select  block of 7seg modules by multiplexing the SL scan lines
	MCFG_I8279_IN_RL_CB(READ8(*this, marywu_state, keyboard_r))                  // keyboard Return Lines
	MCFG_I8279_OUT_DISP_CB(WRITE8(*this, marywu_state, display_7seg_data_w))

	/* Video */
	MCFG_DEFAULT_LAYOUT(layout_marywu)

	/* sound hardware */
	SPEAKER(config, "mono").front_center();
	MCFG_DEVICE_ADD("ay1", AY8910, XTAL(10'738'635)) /* should it be perhaps a fraction of the XTAL clock ? */
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
	MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(*this, marywu_state, ay1_port_a_w))
	MCFG_AY8910_PORT_B_WRITE_CB(WRITE8(*this, marywu_state, ay1_port_b_w))

	MCFG_DEVICE_ADD("ay2", AY8910, XTAL(10'738'635)) /* should it be perhaps a fraction of the XTAL clock ? */
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
	MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(*this, marywu_state, ay2_port_a_w))
	MCFG_AY8910_PORT_B_WRITE_CB(WRITE8(*this, marywu_state, ay2_port_b_w))
MACHINE_CONFIG_END

ROM_START( marywu )
	ROM_REGION( 0x8000, "maincpu", 0 )
	ROM_LOAD( "marywu_sunkiss_chen.rom", 0x0000, 0x8000, CRC(11f67c7d) SHA1(9c1fd1a5cc6e2b0d675f0217aa8ff21c30609a0c) )
ROM_END

//    YEAR  NAME    PARENT   MACHINE   INPUT   STATE         INIT        ROT   COMPANY      FULLNAME                                                FLAGS
GAME( ????, marywu, 0,       marywu,   marywu, marywu_state, empty_init, ROT0, "<unknown>", "unknown Labeled 'WU- MARY-1A' Music by: SunKiss Chen", MACHINE_NOT_WORKING )