summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/bbc/1mhzbus/beebopl.cpp
blob: 36c1cbe561fc9ad9bddb061101f87c4fefc787ff (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

    BeebOPL FM Synthesiser emulation

    https://github.com/JudgeBeeb/BeebOPL

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


#include "emu.h"
#include "beebopl.h"
#include "speaker.h"


//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE(BBC_BEEBOPL, bbc_beebopl_device, "beebopl", "BeebOPL FM Synthesiser")


//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

void bbc_beebopl_device::device_add_mconfig(machine_config &config)
{
	SPEAKER(config, "speaker").front_center();

	YM3812(config, m_ym3812, 3.579_MHz_XTAL);
	m_ym3812->irq_handler().set(DEVICE_SELF_OWNER, FUNC(bbc_1mhzbus_slot_device::irq_w));
	m_ym3812->add_route(ALL_OUTPUTS, "speaker", 1.0);

	BBC_1MHZBUS_SLOT(config, m_1mhzbus, DERIVED_CLOCK(1, 1), bbc_1mhzbus_devices, nullptr);
	m_1mhzbus->irq_handler().set(DEVICE_SELF_OWNER, FUNC(bbc_1mhzbus_slot_device::irq_w));
	m_1mhzbus->nmi_handler().set(DEVICE_SELF_OWNER, FUNC(bbc_1mhzbus_slot_device::nmi_w));
}


//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  bbc_beebopl_device - constructor
//-------------------------------------------------

bbc_beebopl_device::bbc_beebopl_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: device_t(mconfig, BBC_BEEBOPL, tag, owner, clock)
	, device_bbc_1mhzbus_interface(mconfig, *this)
	, m_1mhzbus(*this, "1mhzbus")
	, m_ym3812(*this, "ym3812")
{
}


//**************************************************************************
//  IMPLEMENTATION
//**************************************************************************

uint8_t bbc_beebopl_device::fred_r(offs_t offset)
{
	uint8_t data = 0xff;

	if ((offset & 0xfe) == 0x04)
	{
		data = m_ym3812->read(offset);
	}

	data &= m_1mhzbus->fred_r(offset);

	return data;
}

void bbc_beebopl_device::fred_w(offs_t offset, uint8_t data)
{
	if ((offset & 0xfe) == 0x04)
	{
		m_ym3812->write(offset, data);
	}

	m_1mhzbus->fred_w(offset, data);
}

uint8_t bbc_beebopl_device::jim_r(offs_t offset)
{
	return m_1mhzbus->jim_r(offset);
}

void bbc_beebopl_device::jim_w(offs_t offset, uint8_t data)
{
	m_1mhzbus->jim_w(offset, data);
}