summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/st/replay.cpp
blob: f7df23a2dccc0a21545c983b9181595874561958 (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
// license:BSD-3-Clause
// copyright-holders: Olivier Galibert

// Microdeal ST Replay

// A 8-bit mono DAC and a 8-bit mono ADC on a cartridge, with a vague
// lowpass filter.

// A peculiarity of the ST cartridge port is that it's readonly.  So
// writing to the DAC is done by reading at an appropriate address.

#include "emu.h"
#include "replay.h"

#include "sound/adc.h"
#include "sound/dac.h"
#include "speaker.h"

namespace {

class st_replay_device : public device_t, public device_stcart_interface
{
public:
	st_replay_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0);
	virtual ~st_replay_device();

	virtual void map(address_space_installer &space) override;

protected:
	virtual void device_start() override ATTR_COLD;
	virtual void device_reset() override ATTR_COLD;
	virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;

private:
	required_device<zn449_device> m_adc;
	required_device<zn429e_device> m_dac;
	required_device<microphone_device> m_mic;
	required_device<speaker_device> m_speaker;

	void cartmap(address_map &map) ATTR_COLD;

	u16 dac_w(offs_t data);
	u8 adc_r();
};

st_replay_device::st_replay_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, ST_REPLAY, tag, owner, clock),
	device_stcart_interface(mconfig, *this),
	m_adc(*this, "adc"),
	m_dac(*this, "dac"),
	m_mic(*this, "mic"),
	m_speaker(*this, "speaker")
{
}

st_replay_device::~st_replay_device()
{
}

u16 st_replay_device::dac_w(offs_t data)
{
	m_dac->write(data);
	return 0xffff;
}

u8 st_replay_device::adc_r()
{
	double tm = machine().time().as_double();
	s8 level = 127 * sin(tm*440*2*M_PI);
	return level + 0x80;
}

void st_replay_device::map(address_space_installer &space)
{
	space.install_device(0xfa0000, 0xfbffff, *this, &st_replay_device::cartmap);
}

void st_replay_device::cartmap(address_map &map)
{
	map(0x00000, 0x001ff).r(FUNC(st_replay_device::dac_w)).mirror(0xfe00);
	map(0x10001, 0x10001).r(m_adc, FUNC(zn449_device::read)).mirror(0xfffe);
}

void st_replay_device::device_add_mconfig(machine_config &config)
{
	MICROPHONE(config, m_mic, 1).front_center();
	m_mic->add_route(0, m_adc, 1.0, 0);

	ZN449(config, m_adc);

	// ZN429D the schematics say, not sure if any significant difference
	ZN429E(config, m_dac);
	m_dac->add_route(0, m_speaker, 1.0, 0);

	SPEAKER(config, m_speaker, 1).front_center();
}

void st_replay_device::device_start()
{
}

void st_replay_device::device_reset()
{
}

} // anonymous namespace

DEFINE_DEVICE_TYPE_PRIVATE(ST_REPLAY, device_stcart_interface, st_replay_device, "st_replay", "Microdeal ST Replay")