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

    Konami K056800 (MIRAC)
    Sound interface


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

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

typedef struct _k056800_state k056800_state;
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( running_device *device )
{
	assert(device != NULL);
	assert(device->type() == K056800);

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

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

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


static UINT8 k056800_host_reg_r( running_device *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( running_device *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( running_device *device, int reg )
{
	k056800_state *k056800 = k056800_get_safe_token(device);
	return k056800->sound_reg[reg];
}

static void k056800_sound_reg_w( running_device *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_mul(ATTOTIME_IN_HZ(44100), 128);	// roughly 2.9us

	k056800->irq_cb = intf->irq_cb;

	k056800->sound_cpu_timer = timer_alloc(device->machine, k056800_sound_cpu_timer_tick, k056800);
	timer_adjust_periodic(k056800->sound_cpu_timer, timer_period, 0, timer_period);

	state_save_register_device_item_array(device, 0, k056800->host_reg);
	state_save_register_device_item_array(device, 0, k056800->sound_reg);
	state_save_register_device_item(device, 0, 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;
}


static const char DEVTEMPLATE_SOURCE[] = __FILE__;

#define DEVTEMPLATE_ID( p, s )	p##k056800##s
#define DEVTEMPLATE_FEATURES	DT_HAS_START | DT_HAS_RESET
#define DEVTEMPLATE_NAME		"Konami 056800 MIRAC"
#define DEVTEMPLATE_FAMILY		"Konami custom"
#include "devtempl.h"