summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/sound/k056800.c
blob: d8e70b25f7541f2b71032921c4d959665e420b65 (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
/***********************************************************************

    Konami K056800 (MIRAC)
    Sound interface


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

#include "emu.h"
#include "sound/k056800.h"


const device_type K056800 = &device_creator<k056800_device>;

k056800_device::k056800_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
				: device_t(mconfig, K056800, "Konami 056800 MIRAC", tag, owner, clock, "k056800", __FILE__)
{
}

//-------------------------------------------------
//  device_config_complete - perform any
//  operations now that the configuration is
//  complete
//-------------------------------------------------

void k056800_device::device_config_complete()
{
	// inherit a copy of the static data
	const k056800_interface *intf = reinterpret_cast<const k056800_interface *>(static_config());
	if (intf != NULL)
		*static_cast<k056800_interface *>(this) = *intf;

	// or initialize to defaults if none provided
	else
	{
		m_irq_cb = NULL;
	}
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void k056800_device::device_start()
{
	attotime timer_period = attotime::from_hz(clock()) * 14700 * 3;

	m_irq_cb_func = m_irq_cb;

	m_sound_cpu_timer = timer_alloc(TIMER_TICK_SOUND_CPU);
	m_sound_cpu_timer->adjust(timer_period, 0, timer_period);

	save_item(NAME(m_host_reg));
	save_item(NAME(m_sound_reg));
	save_item(NAME(m_sound_cpu_irq1_enable));
}

//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void k056800_device::device_reset()
{
	memset(m_host_reg, 0, sizeof(m_host_reg));
	memset(m_sound_reg, 0, sizeof(m_sound_reg));

	m_sound_cpu_irq1_enable = 0;
}


/*****************************************************************************
    DEVICE HANDLERS
*****************************************************************************/


UINT8 k056800_device::host_reg_r( int reg )
{
	UINT8 value = m_host_reg[reg];
	if (reg == 2)
		value &= ~3; // suppress VOLWR busy flags

	return value;
}

void k056800_device::host_reg_w( int reg, UINT8 data )
{
	m_sound_reg[reg] = data;

	if (reg == 7)
		m_irq_cb(machine(), 1);
}

UINT8 k056800_device::sound_reg_r( int reg )
{
	return m_sound_reg[reg];
}

void k056800_device::sound_reg_w( int reg, UINT8 data )
{
	if (reg == 4)
		m_sound_cpu_irq1_enable = data & 0x01;

	m_host_reg[reg] = data;
}

void k056800_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	switch (id)
	{
		case TIMER_TICK_SOUND_CPU:
			if (m_sound_cpu_irq1_enable)
				m_irq_cb_func(machine(), 0);
			break;

			default:
			assert_always(FALSE, "Unknown id in k056800_device::device_timer");
	}
}

READ32_MEMBER( k056800_device::host_r )
{
	UINT32 r = 0;

	if (ACCESSING_BITS_24_31)
		r |= host_reg_r((offset * 4) + 0) << 24;

	if (ACCESSING_BITS_16_23)
		r |= host_reg_r((offset * 4) + 1) << 16;

	if (ACCESSING_BITS_8_15)
		r |= host_reg_r((offset * 4) + 2) << 8;

	if (ACCESSING_BITS_0_7)
		r |= host_reg_r((offset * 4) + 3) << 0;


	return r;
}

WRITE32_MEMBER( k056800_device::host_w )
{
	if (ACCESSING_BITS_24_31)
		host_reg_w((offset * 4) + 0, (data >> 24) & 0xff);

	if (ACCESSING_BITS_16_23)
		host_reg_w((offset * 4) + 1, (data >> 16) & 0xff);

	if (ACCESSING_BITS_8_15)
		host_reg_w((offset * 4) + 2, (data >> 8) & 0xff);

	if (ACCESSING_BITS_0_7)
		host_reg_w((offset * 4) + 3, (data >> 0) & 0xff);

}

READ16_MEMBER( k056800_device::sound_r )
{
	return sound_reg_r(offset);
}

WRITE16_MEMBER( k056800_device::sound_w )
{
	sound_reg_w(offset, data);
}