summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/sunmouse/sunmouse.h
blob: 1de841a01bb08d417a45843d414b13d503d2d4f9 (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
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
#ifndef MAME_BUS_SUNMOUSE_SUNMOUSE_H
#define MAME_BUS_SUNMOUSE_SUNMOUSE_H

#pragma once

#include "diserial.h"


class device_sun_mouse_port_interface;


class sun_mouse_port_device : public device_t, public device_single_card_slot_interface<device_sun_mouse_port_interface>
{
	friend class device_sun_mouse_port_interface;

public:
	template <typename T>
	sun_mouse_port_device(machine_config const &mconfig, char const *tag, device_t *owner, T &&opts, char const *dflt)
		: sun_mouse_port_device(mconfig, tag, owner)
	{
		option_reset();
		opts(*this);
		set_default_option(dflt);
		set_fixed(false);
	}
	sun_mouse_port_device(machine_config const &mconfig, char const *tag, device_t *owner, const XTAL &clock = XTAL());
	virtual ~sun_mouse_port_device();

	// configuration helpers
	auto rxd_handler() { return m_rxd_handler.bind(); }

	DECLARE_WRITE_LINE_MEMBER( write_txd );

	DECLARE_READ_LINE_MEMBER( rxd_r ) { return m_rxd; }

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

	virtual void device_config_complete() override;
	virtual void device_resolve_objects() override;
	virtual void device_start() override;

	int m_rxd;

	devcb_write_line m_rxd_handler;

private:
	device_sun_mouse_port_interface *m_dev;
};


class device_sun_mouse_port_interface : public device_interface
{
	friend class sun_mouse_port_device;

public:
	virtual ~device_sun_mouse_port_interface() override;

protected:
	device_sun_mouse_port_interface(machine_config const &mconfig, device_t &device);

	virtual DECLARE_WRITE_LINE_MEMBER( input_txd ) { }

	DECLARE_WRITE_LINE_MEMBER( output_rxd ) { m_port->m_rxd_handler(m_port->m_rxd = state ? 0 : 1); }

	sun_mouse_port_device *m_port;

	static constexpr int START_BIT_COUNT = 1;
	static constexpr int DATA_BIT_COUNT = 8;
	static constexpr device_serial_interface::parity_t PARITY = device_serial_interface::PARITY_NONE;
	static constexpr device_serial_interface::stop_bits_t STOP_BITS = device_serial_interface::STOP_BITS_1;
	static constexpr int BAUD = 1'200;
};


DECLARE_DEVICE_TYPE(SUNMOUSE_PORT, sun_mouse_port_device)


void default_sun_mouse_devices(device_slot_interface &device);

#endif // MAME_BUS_SUNMOUSE_SUNMOUSE_H