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

    Konami K056800 (MIRAC)
    Sound interface


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

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

struct k056800_state
{
	UINT8                host_reg[8];
	UINT8                sound_reg[8];

	emu_timer            *sound_cpu_timer;
	UINT8                sound_cpu_irq1_enable;
	k056800_irq_cb       irq_cb;
};

/*****************************************************************************
    INLINE FUNCTIONS
*****************************************************************************/

INLINE k056800_state *k056800_get_safe_token( device_t *device )
{
	assert(device != NULL);
	assert(device->type() == K056800);

	return (k056800_state *)downcast<k056800_device *>(device)->token();
}

INLINE const k056800_interface *k056800_get_interface( device_t *device )
{
	assert(device != NULL);
	assert((device->type() == K056800));
	return (const k056800_interface *) device->static_config();
}

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


static UINT8 k056800_host_reg_r( device_t *device, int reg )
{
	k056800_state *k056800 = k056800_get_safe_token(device);
	UINT8 value = k056800->host_reg[reg];
	if (reg == 2)
		value &= ~3; // suppress VOLWR busy flags

	return value;
}

static void k056800_host_reg_w( device_t *device, int reg, UINT8 data )
{
	k056800_state *k056800 = k056800_get_safe_token(device);

	k056800->sound_reg[reg] = data;

	if (reg == 7)
		k056800->irq_cb(device->machine(), 1);
}

static UINT8 k056800_sound_reg_r( device_t *device, int reg )
{
	k056800_state *k056800 = k056800_get_safe_token(device);
	return k056800->sound_reg[reg];
}

static void k056800_sound_reg_w( device_t *device, int reg, UINT8 data )
{
	k056800_state *k056800 = k056800_get_safe_token(device);

	if (reg == 4)
		k056800->sound_cpu_irq1_enable = data & 0x01;

	k056800->host_reg[reg] = data;
}

static TIMER_CALLBACK( k056800_sound_cpu_timer_tick )
{
	k056800_state *k056800 = (k056800_state *)ptr;

	if (k056800->sound_cpu_irq1_enable)
		k056800->irq_cb(machine, 0);
}

READ32_DEVICE_HANDLER( k056800_host_r )
{
	UINT32 r = 0;

	if (ACCESSING_BITS_24_31)
		r |= k056800_host_reg_r(device, (offset * 4) + 0) << 24;

	if (ACCESSING_BITS_16_23)
		r |= k056800_host_reg_r(device, (offset * 4) + 1) << 16;

	if (ACCESSING_BITS_8_15)
		r |= k056800_host_reg_r(device, (offset * 4) + 2) << 8;

	if (ACCESSING_BITS_0_7)
		r |= k056800_host_reg_r(device, (offset * 4) + 3) << 0;


	return r;
}

WRITE32_DEVICE_HANDLER( k056800_host_w )
{
	if (ACCESSING_BITS_24_31)
		k056800_host_reg_w(device, (offset * 4) + 0, (data >> 24) & 0xff);

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

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

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

}

READ16_DEVICE_HANDLER( k056800_sound_r )
{
	return k056800_sound_reg_r(device, offset);
}

WRITE16_DEVICE_HANDLER( k056800_sound_w )
{
	k056800_sound_reg_w(device, offset, data);
}

/*****************************************************************************
    DEVICE INTERFACE
*****************************************************************************/

static DEVICE_START( k056800 )
{
	k056800_state *k056800 = k056800_get_safe_token(device);
	const k056800_interface *intf = k056800_get_interface(device);
	attotime timer_period = attotime::from_hz(device->clock()) * 14700 * 3;

	k056800->irq_cb = intf->irq_cb;

	k056800->sound_cpu_timer = device->machine().scheduler().timer_alloc(FUNC(k056800_sound_cpu_timer_tick), k056800);
	k056800->sound_cpu_timer->adjust(timer_period, 0, timer_period);

	device->save_item(NAME(k056800->host_reg));
	device->save_item(NAME(k056800->sound_reg));
	device->save_item(NAME(k056800->sound_cpu_irq1_enable));
}

static DEVICE_RESET( k056800 )
{
	k056800_state *k056800 = k056800_get_safe_token(device);

	memset(k056800->host_reg, 0, sizeof(k056800->host_reg));
	memset(k056800->sound_reg, 0, sizeof(k056800->sound_reg));

	k056800->sound_cpu_irq1_enable = 0;
}

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)
{
	m_token = global_alloc_clear(k056800_state);
}

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

void k056800_device::device_config_complete()
{
}

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

void k056800_device::device_start()
{
	DEVICE_START_NAME( k056800 )(this);
}

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

void k056800_device::device_reset()
{
	DEVICE_RESET_NAME( k056800 )(this);
}