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
|
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria
/***************************************************************************
machine.c
Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
I/O ports)
***************************************************************************/
#include "emu.h"
#include "sound/samples.h"
#include "includes/galaga.h"
#include "includes/xevious.h"
/***************************************************************************
BATTLES CPU4(custum I/O Emulation) I/O Handlers
***************************************************************************/
TIMER_DEVICE_CALLBACK_MEMBER(battles_state::nmi_generate)
{
m_customio_prev_command = m_customio_command;
if( m_customio_command & 0x10 )
{
if( m_customio_command_count == 0 )
{
m_subcpu3->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
}
else
{
m_maincpu->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
m_subcpu3->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
}
}
else
{
m_maincpu->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
m_subcpu3->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
}
m_customio_command_count++;
}
uint8_t battles_state::customio0_r()
{
logerror("%s: custom I/O Read = %02x\n", machine().describe_context(), m_customio_command);
return m_customio_command;
}
uint8_t battles_state::customio3_r()
{
int return_data;
if( m_subcpu3->pc() == 0xAE ){
/* CPU4 0xAA - 0xB9 : waiting for MB8851 ? */
return_data = ( (m_customio_command & 0x10) << 3)
| 0x00
| (m_customio_command & 0x0f);
}else{
return_data = ( (m_customio_prev_command & 0x10) << 3)
| 0x60
| (m_customio_prev_command & 0x0f);
}
logerror("%s: custom I/O Read = %02x\n", machine().describe_context(), return_data);
return return_data;
}
void battles_state::customio0_w(uint8_t data)
{
logerror("%s: custom I/O Write = %02x\n", machine().describe_context(), data);
m_customio_command = data;
m_customio_command_count = 0;
switch (data)
{
case 0x10:
m_nmi_timer->reset();
return; /* nop */
}
m_nmi_timer->adjust(attotime::from_usec(166), 0, attotime::from_usec(166));
}
void battles_state::customio3_w(uint8_t data)
{
logerror("%s: custom I/O Write = %02x\n", machine().describe_context(), data);
m_customio_command = data;
}
uint8_t battles_state::customio_data0_r(offs_t offset)
{
logerror("%s: custom I/O parameter %02x Read = %02x\n", machine().describe_context(), offset, m_customio_data);
return m_customio_data;
}
uint8_t battles_state::customio_data3_r(offs_t offset)
{
logerror("%s: custom I/O parameter %02x Read = %02x\n", machine().describe_context(), offset, m_customio_data);
return m_customio_data;
}
void battles_state::customio_data0_w(offs_t offset, uint8_t data)
{
logerror("%s: custom I/O parameter %02x Write = %02x\n", machine().describe_context(), offset, data);
m_customio_data = data;
}
void battles_state::customio_data3_w(offs_t offset, uint8_t data)
{
logerror("%s: custom I/O parameter %02x Write = %02x\n", machine().describe_context(), offset, data);
m_customio_data = data;
}
void battles_state::cpu4_coin_w(uint8_t data)
{
m_leds[0] = BIT(data, 1); // Start 1
m_leds[1] = BIT(data, 0); // Start 2
machine().bookkeeping().coin_counter_w(0,data & 0x20);
machine().bookkeeping().coin_counter_w(1,data & 0x10);
machine().bookkeeping().coin_lockout_global_w(~data & 0x04);
}
void battles_state::noise_sound_w(offs_t offset, uint8_t data)
{
logerror("%s: 50%02x Write = %02x\n", machine().describe_context(), offset, data);
if( (m_sound_played == 0) && (data == 0xFF) ){
if( m_customio[0] == 0x40 ){
m_samples->start(0, 0);
}
else{
m_samples->start(0, 1);
}
}
m_sound_played = data;
}
uint8_t battles_state::input_port_r(offs_t offset)
{
switch ( offset )
{
default:
case 0: return ~bitswap<8>(ioport("IN1")->read(),2,3,1,0,6,7,5,4);
case 1: return ~ioport("IN0")->read() & 15;
case 2: return ~ioport("IN0")->read() >> 4;
case 3: return ~ioport("IN1")->read() & 15;
}
}
WRITE_LINE_MEMBER(battles_state::interrupt_4)
{
if (state)
m_subcpu3->set_input_line(0, HOLD_LINE);
}
|