summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/namco68.cpp
blob: 571002f87e6f99ecc59bd3b8aff553bd795113f5 (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
// license:BSD-3-Clause
// copyright-holders:David Haywood, K.Wilkins

/*
TODO:
output support, Golly Ghost is currently hacking this based on DPRAM in the namcos2.cpp driver side!
some of this can likely be moved into the actual MCU core too

*/

#include "emu.h"
#include "machine/namco68.h"

DEFINE_DEVICE_TYPE(NAMCOC68, namcoc68_device, "namcoc68", "Namco C68 I/O")

namcoc68_device::namcoc68_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, NAMCOC68, tag, owner, clock),
	m_mcu(*this, "mcu"),
	m_in_pb_cb(*this),
	m_in_pb2_cb(*this),
	m_in_pc_cb(*this),
	m_in_ph_cb(*this),
	m_in_pdsw_cb(*this),
	m_port_analog_in_cb{{*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}},
	m_port_dial_in_cb{{*this}, {*this}, {*this}, {*this}},
	m_dp_in(*this),
	m_dp_out(*this)
{
}

ROM_START( namcoc68 )
	ROM_REGION( 0x8000, "mcu", 0 )
	ROM_LOAD( "c68.3d",  0x000000, 0x008000, CRC(ca64550a) SHA1(38d1ad1b1287cadef0c999aff9357927315f8e6b) )
ROM_END



READ8_MEMBER(namcoc68_device::c68_p5_r)
{
	return (m_player_mux) ? m_in_pb2_cb() : m_in_pb_cb();
}

WRITE8_MEMBER(namcoc68_device::c68_p3_w)
{
	m_player_mux = (data & 0x80) ? 1 : 0;
}

READ8_MEMBER(namcoc68_device::ack_mcu_vbl_r)
{
	m_mcu->set_input_line(m37450_device::M3745X_INT1_LINE, CLEAR_LINE);
	return 0;
}

READ8_MEMBER(namcoc68_device::dpram_byte_r)
{
	return m_dp_in(offset);
}

WRITE8_MEMBER(namcoc68_device::dpram_byte_w)
{
	m_dp_out(offset,data);
}

void namcoc68_device::c68_default_am(address_map &map)
{
	/* input ports and dips are mapped here */
	map(0x2000, 0x2000).r(FUNC(namcoc68_device::mcudsw_r));
	map(0x3000, 0x3000).r(FUNC(namcoc68_device::mcudi0_r));
	map(0x3001, 0x3001).r(FUNC(namcoc68_device::mcudi1_r));
	map(0x3002, 0x3002).r(FUNC(namcoc68_device::mcudi2_r));
	map(0x3003, 0x3003).r(FUNC(namcoc68_device::mcudi3_r));
	map(0x5000, 0x57ff).rw(FUNC(namcoc68_device::dpram_byte_r), FUNC(namcoc68_device::dpram_byte_w));
	map(0x6000, 0x6fff).r(FUNC(namcoc68_device::ack_mcu_vbl_r)); // VBL ack
	map(0x8000, 0xffff).rom().region("mcu", 0);
}

void namcoc68_device::device_add_mconfig(machine_config &config)
{
	m3745x_device* device = &M37450(config, m_mcu, DERIVED_CLOCK(1, 1)); // ugly, needs modernizing
	MCFG_M3745X_ADC14_CALLBACKS(READ8(*this, namcoc68_device, mcuan0_r), READ8(*this, namcoc68_device, mcuan1_r), READ8(*this, namcoc68_device, mcuan2_r), READ8(*this, namcoc68_device, mcuan3_r))
	MCFG_M3745X_ADC58_CALLBACKS(READ8(*this, namcoc68_device, mcuan4_r), READ8(*this, namcoc68_device, mcuan5_r), READ8(*this, namcoc68_device, mcuan6_r), READ8(*this, namcoc68_device, mcuan7_r))
	MCFG_M3745X_PORT3_CALLBACKS(READ8(*this, namcoc68_device, mcuh_r), WRITE8(*this, namcoc68_device, c68_p3_w))    // coins/test/service
	MCFG_M3745X_PORT5_CALLBACKS(READ8(*this, namcoc68_device, c68_p5_r), NOOP) // muxed player 1/2
	MCFG_M3745X_PORT6_CALLBACKS(READ8(*this, namcoc68_device, mcuc_r), NOOP) // unused in sgunner2
	MCFG_DEVICE_PROGRAM_MAP(c68_default_am)
}

void namcoc68_device::device_resolve_objects()
{
	m_in_pb_cb.resolve_safe(0xff);
	m_in_pb2_cb.resolve_safe(0xff);
	m_in_pc_cb.resolve_safe(0xff);
	m_in_ph_cb.resolve_safe(0xff);
	m_in_pdsw_cb.resolve_safe(0xff);

	for (auto &cb : m_port_analog_in_cb)
		cb.resolve_safe(0xff);

	for (auto &cb : m_port_dial_in_cb)
		cb.resolve_safe(0xff);

	m_dp_in.resolve_safe(0xff);
	m_dp_out.resolve_safe();
}

void namcoc68_device::device_start()
{
}

void namcoc68_device::device_reset()
{
	m_player_mux = 0;
}

const tiny_rom_entry *namcoc68_device::device_rom_region() const
{
	return ROM_NAME(namcoc68);
}