summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/jvs13551.cpp
blob: 877ccd6302fff9037edeae880715d4d71948d907 (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
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
#include "emu.h"
#include "jvs13551.h"

#include "cpu/tlcs90/tlcs90.h"

DEFINE_DEVICE_TYPE(SEGA_837_13551, sega_837_13551_device, "jvs13551", "Sega 837-13551 I/O Board")

WRITE_LINE_MEMBER(sega_837_13551_device::jvs13551_coin_1_w)
{
	if(state)
		inc_coin(0);
}

WRITE_LINE_MEMBER(sega_837_13551_device::jvs13551_coin_2_w)
{
	if(state)
		inc_coin(1);
}

static INPUT_PORTS_START(sega_837_13551_coins)
	PORT_START("COINS")
	PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_COIN1) PORT_WRITE_LINE_DEVICE_MEMBER(DEVICE_SELF, sega_837_13551_device, jvs13551_coin_1_w)
	PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_COIN2) PORT_WRITE_LINE_DEVICE_MEMBER(DEVICE_SELF, sega_837_13551_device, jvs13551_coin_2_w)
INPUT_PORTS_END

ROM_START( jvs13551 )
	// TMP90PH44N firmwares
	ROM_REGION( 0x4000, "iomcu", ROMREGION_ERASE )
	// Sega 838-13683-93
	ROM_LOAD( "sp5001.bin",   0x0000, 0x4000, CRC(3456c8cc) SHA1(f3b66ab1d2eab32e97b46077e3ed2ab5b2982325))
	// Sega 838-13683-93 Rev.B
	ROM_LOAD( "sp5001-b.bin", 0x0000, 0x4000, CRC(28b5fb84) SHA1(8784024548d24b6a43057f06de1d53ce3a34eb12))
	// Sega 838-13683-02
	ROM_LOAD( "sp5002-a.bin", 0x0000, 0x4000, CRC(72983a0f) SHA1(aa13276347bc643ef93e81e9ab7c905deb16c415))
	// Sega 837-13551-92 0007 Type1
	ROM_LOAD( "315-6215.bin", 0x0000, 0x4000, CRC(98202738) SHA1(8c4dc85438298e31e25f69542804a78ff0e20962))
ROM_END

const tiny_rom_entry *sega_837_13551_device::device_rom_region() const
{
	return ROM_NAME(jvs13551);
}

void sega_837_13551_device::device_add_mconfig(machine_config &config)
{
	TMP90PH44(config, "iomcu", 10000000); // unknown clock
}

ioport_constructor sega_837_13551_device::device_input_ports() const
{
	return INPUT_PORTS_NAME(sega_837_13551_coins);
}

sega_837_13551_device::sega_837_13551_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : jvs_device(mconfig, SEGA_837_13551, tag, owner, clock)
, port(*this, {finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG})
{
}

const char *sega_837_13551_device::device_id()
{
	return "SEGA ENTERPRISES,LTD.;I/O BD JVS;837-13551";
}

uint8_t sega_837_13551_device::command_format_version()
{
	return 0x11;
}

uint8_t sega_837_13551_device::jvs_standard_version()
{
	return 0x20;
}

uint8_t sega_837_13551_device::comm_method_version()
{
	return 0x10;
}

void sega_837_13551_device::device_start()
{
	jvs_device::device_start();
	save_item(NAME(coin_counter));
}

void sega_837_13551_device::device_reset()
{
	jvs_device::device_reset();
	coin_counter[0] = 0;
	coin_counter[1] = 0;
}

void sega_837_13551_device::inc_coin(int coin)
{
	coin_counter[coin]++;
	if(coin_counter[coin] == 16384)
		coin_counter[coin] = 0;
}


void sega_837_13551_device::function_list(uint8_t *&buf)
{
	// SW input - 2 players, 13 bits
	*buf++ = 0x01; *buf++ = 2; *buf++ = 13; *buf++ = 0;

	// Coin input - 2 slots
	*buf++ = 0x02; *buf++ = 2; *buf++ = 0; *buf++ = 0;

	// Analog input - 8 channels
	*buf++ = 0x03; *buf++ = 8; *buf++ = 16; *buf++ = 0;

	// Driver out - 6 channels
	*buf++ = 0x12; *buf++ = 6; *buf++ = 0; *buf++ = 0;
}

bool sega_837_13551_device::coin_counters(uint8_t *&buf, uint8_t count)
{
	if(count > 2)
		return false;

	*buf++ = coin_counter[0] >> 8; *buf++ = coin_counter[0];

	if(count > 1) {
		*buf++ = coin_counter[1] >> 8; *buf++ = coin_counter[1];
	}

	return true;
}

bool sega_837_13551_device::coin_add(uint8_t slot, int32_t count)
{
	if(slot < 1 || slot > 2)
		return false;

	coin_counter[slot-1] += count;

	return true;
}

bool sega_837_13551_device::switches(uint8_t *&buf, uint8_t count_players, uint8_t bytes_per_switch)
{
	if(count_players > 2 || bytes_per_switch > 2)
		return false;

	*buf++ = port[0] ? port[0]->read() : 0;
	for(int i=0; i<count_players; i++) {
		uint32_t val = port[1+i] ? port[1+i]->read() : 0;
		for(int j=0; j<bytes_per_switch; j++)
			*buf++ = val >> ((1-j) << 3);
	}
	return true;

}

bool sega_837_13551_device::analogs(uint8_t *&buf, uint8_t count)
{
	if(count > 8)
		return false;
	for(int i=0; i<count; i++) {
		uint16_t val = port[3+i] ? port[3+i]->read() : 0x8000;
		*buf++ = val >> 8;
		*buf++ = val;
	}
	return true;
}

bool sega_837_13551_device::swoutputs(uint8_t count, const uint8_t *vals)
{
	// WARNING! JVS standard have reversed bits count order
	// so "board have 6 output bits" means 6 MSB bits is used, the same rules for input too
	if(count > 1)
		return false;
	jvs_outputs = vals[0] & 0xfc;
	logerror("837-13551: output %02x\n", jvs_outputs);
	if (port[11])
	{
		port[11]->write(jvs_outputs, 0xfc);
	}
	return true;
}

bool sega_837_13551_device::swoutputs(uint8_t id, uint8_t val)
{
	if(id > 6)
		return false;
	handle_output(port[11], id, val);
	logerror("837-13551: output %d, %d\n", id, val);
	return true;
}