summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/namco52.h
blob: b4f56762c9debe1432b3f739d628bda7fab6be73 (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
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
#ifndef MAME_AUDIO_NAMCO52_H
#define MAME_AUDIO_NAMCO52_H

#include "sound/discrete.h"
#include "cpu/mb88xx/mb88xx.h"

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

	template <typename T> void set_discrete(T &&tag) { m_discrete.set_tag(std::forward<T>(tag)); }
	void set_basenote(int node) { m_basenode = node; }
	void set_extclock(attoseconds_t clk) { m_extclock = clk; }
	auto romread_callback() { return m_romread.bind(); }
	auto si_callback() { return m_si.bind(); }
	namco_52xx_device &set_irq_duration(attotime t) { m_irq_duration = t; return *this; }

	DECLARE_WRITE_LINE_MEMBER( reset );
	WRITE_LINE_MEMBER( chip_select );
	void write(uint8_t data);

protected:
	// device-level overrides
	virtual void device_start() override;
	virtual const tiny_rom_entry *device_rom_region() const override;
	virtual void device_add_mconfig(machine_config &config) override;

	TIMER_CALLBACK_MEMBER( latch_callback );
	TIMER_CALLBACK_MEMBER( external_clock_pulse );

private:
	// internal state
	required_device<mb88_cpu_device> m_cpu;
	required_device<discrete_device> m_discrete;

	attotime m_irq_duration;
	int m_basenode;
	attoseconds_t m_extclock;
	emu_timer *m_extclock_pulse_timer;
	devcb_read8 m_romread;
	devcb_read8 m_si;

	uint8_t m_latched_cmd;
	uint32_t m_address;

	uint8_t K_r();
	DECLARE_READ_LINE_MEMBER( SI_r );
	uint8_t R0_r();
	uint8_t R1_r();
	void P_w(uint8_t data);
	void R2_w(uint8_t data);
	void R3_w(uint8_t data);
	void O_w(uint8_t data);
};

DECLARE_DEVICE_TYPE(NAMCO_52XX, namco_52xx_device)



/* discrete nodes */
#define NAMCO_52XX_P_DATA(base)     (base)


#endif  // MAME_AUDIO_NAMCO52_H