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
|
#include "driver.h"
#include "konamiic.h"
/* Konami K056800 (MIRAC) */
static UINT8 K056800_host_reg[8];
static UINT8 K056800_sound_reg[8];
static emu_timer *K056800_sound_cpu_timer;
static int K056800_sound_cpu_irq1_enable;
static void (*K056800_sound_irq_callback)(int);
static UINT8 K056800_host_reg_r(int reg)
{
UINT8 value = 0;
value = K056800_host_reg[reg];
if (reg == 2) value &= ~3; // suppress VOLWR busy flags
return value;
}
static void K056800_host_reg_w(int reg, UINT8 data)
{
K056800_sound_reg[reg] = data;
if (reg == 7)
{
K056800_sound_irq_callback(1);
}
}
static UINT8 K056800_sound_reg_r(int reg)
{
return K056800_sound_reg[reg];
}
static void K056800_sound_reg_w(int reg, UINT8 data)
{
if (reg == 4)
{
K056800_sound_cpu_irq1_enable = data & 0x01;
}
K056800_host_reg[reg] = data;
}
static TIMER_CALLBACK( K056800_sound_cpu_timer_tick )
{
if (K056800_sound_cpu_irq1_enable)
{
K056800_sound_irq_callback(0);
}
}
void K056800_init(void (* irq_callback)(int))
{
attotime timer_period;
K056800_sound_irq_callback = irq_callback;
memset(K056800_host_reg, 0, sizeof(K056800_host_reg));
memset(K056800_sound_reg, 0, sizeof(K056800_sound_reg));
timer_period = attotime_mul(ATTOTIME_IN_HZ(44100), 128); // roughly 2.9us
K056800_sound_cpu_timer = timer_alloc(K056800_sound_cpu_timer_tick);
timer_adjust(K056800_sound_cpu_timer, timer_period, 0, timer_period);
}
READ32_HANDLER(K056800_host_r)
{
UINT32 r = 0;
if (!(mem_mask & 0xff000000))
{
r |= K056800_host_reg_r((offset*4)+0) << 24;
}
if (!(mem_mask & 0x00ff0000))
{
r |= K056800_host_reg_r((offset*4)+1) << 16;
}
if (!(mem_mask & 0x0000ff00))
{
r |= K056800_host_reg_r((offset*4)+2) << 8;
}
if (!(mem_mask & 0x000000ff))
{
r |= K056800_host_reg_r((offset*4)+3) << 0;
}
return r;
}
WRITE32_HANDLER(K056800_host_w)
{
if (!(mem_mask & 0xff000000))
{
K056800_host_reg_w((offset*4)+0, (data >> 24) & 0xff);
}
if (!(mem_mask & 0x00ff0000))
{
K056800_host_reg_w((offset*4)+1, (data >> 16) & 0xff);
}
if (!(mem_mask & 0x0000ff00))
{
K056800_host_reg_w((offset*4)+2, (data >> 8) & 0xff);
}
if (!(mem_mask & 0x000000ff))
{
K056800_host_reg_w((offset*4)+3, (data >> 0) & 0xff);
}
}
READ16_HANDLER(K056800_sound_r)
{
return K056800_sound_reg_r(offset);
}
WRITE16_HANDLER(K056800_sound_w)
{
K056800_sound_reg_w(offset, data);
}
|