summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/tx1.h
blob: 6e52079332abd5893a865fd26f850a6615eb51b0 (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
// license:BSD-3-Clause
// copyright-holders:Philip Bennett
/***************************************************************************

    Tatsumi TX-1/Buggy Boy sound hardware

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

#ifndef MAME_AUDIO_TX1_H
#define MAME_AUDIO_TX1_H

#pragma once

#include "machine/i8255.h"
#include "sound/ay8910.h"

class tx1_sound_device : public device_t, public device_sound_interface
{
public:
	tx1_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	DECLARE_WRITE16_MEMBER( z80_busreq_w );
	DECLARE_READ16_MEMBER( dipswitches_r );
	DECLARE_READ16_MEMBER( z80_shared_r );
	DECLARE_WRITE16_MEMBER( z80_shared_w );

	DECLARE_WRITE8_MEMBER( z80_intreq_w );

	DECLARE_WRITE8_MEMBER( ts_w );
	DECLARE_READ8_MEMBER( ts_r );

	DECLARE_READ8_MEMBER( pit8253_r );
	DECLARE_WRITE8_MEMBER( pit8253_w );

	INTERRUPT_GEN_MEMBER( z80_irq );

protected:

	DECLARE_WRITE8_MEMBER( tx1_ppi_latch_w );
	DECLARE_WRITE8_MEMBER( tx1_coin_cnt_w );
	DECLARE_READ8_MEMBER( tx1_ppi_porta_r );
	DECLARE_READ8_MEMBER( tx1_ppi_portb_r );

	DECLARE_WRITE8_MEMBER( ay8910_a_w );
	DECLARE_WRITE8_MEMBER( ay8910_b_w );

	/*************************************
	 *
	 *  8253 Programmable Interval Timer
	 *
	 *************************************/
	struct pit8253_state
	{
		union
		{
#ifdef LSB_FIRST
			struct { uint8_t LSB; uint8_t MSB; } as8bit;
#else
			struct { uint8_t MSB; uint8_t LSB; } as8bit;
#endif
			uint16_t val;
		} counts[3];

		int idx[3];
	};

	tx1_sound_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

	// device-level overrides
	virtual ioport_constructor device_input_ports() const override;
	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_start() override;
	virtual void device_reset() override;

	// sound stream update overrides
	virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override;

	void tx1_sound_io(address_map &map);
	void tx1_sound_prg(address_map &map);

	// internal state
	required_device<cpu_device> m_audiocpu;
	required_shared_ptr<uint8_t> m_z80_ram;
	optional_device<i8255_device> m_ppi;

	required_ioport m_dsw;
	required_ioport m_steering;
	required_ioport m_accelerator;
	required_ioport m_brake;
	optional_ioport m_ppi_portd;

	sound_stream *m_stream;
	uint32_t m_freq_to_step;
	uint32_t m_step0;
	uint32_t m_step1;
	uint32_t m_step2;

	pit8253_state m_pit8253;

	uint8_t m_ay_outputa;
	uint8_t m_ay_outputb;

	uint8_t m_ppi_latch_a;
	uint8_t m_ppi_latch_b;
	uint32_t m_ts;

	stream_sample_t m_pit0;
	stream_sample_t m_pit1;
	stream_sample_t m_pit2;

	double m_weights0[4];
	double m_weights1[3];
	double m_weights2[3];
	int m_eng0[4];
	int m_eng1[4];
	int m_eng2[4];

	int m_noise_lfsra;
	int m_noise_lfsrb;
	int m_noise_lfsrc;
	int m_noise_lfsrd;
	int m_noise_counter;
	uint8_t m_ym1_outputa;
	uint8_t m_ym2_outputa;
	uint8_t m_ym2_outputb;
	uint16_t m_eng_voltages[16];
};

class tx1j_sound_device : public tx1_sound_device
{
public:
	tx1j_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

protected:

	// device-level overrides
	virtual ioport_constructor device_input_ports() const override;
};

class buggyboy_sound_device : public tx1_sound_device
{
public:
	buggyboy_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	DECLARE_WRITE8_MEMBER( ym2_a_w );
	DECLARE_WRITE8_MEMBER( ym2_b_w );

protected:
	buggyboy_sound_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

	// device-level overrides
	virtual ioport_constructor device_input_ports() const override;
	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_start() override;
	virtual void device_reset() override;

	// sound stream update overrides
	virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override;

	DECLARE_WRITE8_MEMBER( ym1_a_w );

	DECLARE_READ8_MEMBER( bb_analog_r );
	DECLARE_WRITE8_MEMBER( bb_coin_cnt_w );

	virtual bool has_coin_counters() { return false; }

	void buggyboy_sound_io(address_map &map);
	void buggyboy_sound_prg(address_map &map);

	required_device_array<ym2149_device, 2> m_ym;
};

class buggyboyjr_sound_device : public buggyboy_sound_device
{
public:
	buggyboyjr_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

protected:
	// device-level overrides
	virtual ioport_constructor device_input_ports() const override;
	virtual void device_add_mconfig(machine_config &config) override;

	DECLARE_READ8_MEMBER( bbjr_analog_r );

	virtual bool has_coin_counters() override { return true; }

	void buggybjr_sound_prg(address_map &map);
};

DECLARE_DEVICE_TYPE(TX1_SOUND, tx1_sound_device)
DECLARE_DEVICE_TYPE(TX1J_SOUND, tx1j_sound_device)
DECLARE_DEVICE_TYPE(BUGGYBOY_SOUND, buggyboy_sound_device)
DECLARE_DEVICE_TYPE(BUGGYBOYJR_SOUND, buggyboyjr_sound_device)

#endif // MAME_AUDIO_TX1_H