summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/ti99/internal/ioport.h
blob: 6b468007edaba5af7a39dc4e03c06110b1f31850 (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
// license:LGPL-2.1+
// copyright-holders:Michael Zapf
/****************************************************************************
     I/O port
*****************************************************************************/

#ifndef MAME_BUS_TI99_INTERNAL_IOPORT_H
#define MAME_BUS_TI99_INTERNAL_IOPORT_H

#pragma once

#include "bus/ti99/ti99defs.h"

namespace bus { namespace ti99 { namespace internal {

extern const device_type IOPORT;

class ioport_device;

/********************************************************************
    Common parent class of all devices attached to the I/O port
********************************************************************/
class ioport_attached_device : public device_t
{
public:
	ioport_attached_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
		device_t(mconfig, type, tag, owner, clock),
		m_ioport(nullptr)
	{ }

	// Methods called from the console / ioport
	virtual DECLARE_READ8Z_MEMBER( readz ) { }
	virtual void write(offs_t offset, uint8_t data) { }
	virtual DECLARE_SETADDRESS_DBIN_MEMBER( setaddress_dbin ) { }
	virtual DECLARE_READ8Z_MEMBER( crureadz ) { }
	virtual void cruwrite(offs_t offset, uint8_t data) { }
	virtual DECLARE_WRITE_LINE_MEMBER( memen_in ) { }
	virtual DECLARE_WRITE_LINE_MEMBER( msast_in ) { }
	virtual DECLARE_WRITE_LINE_MEMBER( clock_in ) { }

	void set_ioport(ioport_device* ioport) { m_ioport = ioport; }

protected:
	// Methods called from the external device
	DECLARE_WRITE_LINE_MEMBER( set_extint );
	DECLARE_WRITE_LINE_MEMBER( set_ready );
private:
	ioport_device* m_ioport;
};

/********************************************************************
    I/O port
********************************************************************/

class ioport_device : public device_t, public device_slot_interface
{
	friend class ioport_attached_device;

public:
	template <typename U>
	ioport_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, U &&opts, const char *dflt)
		: ioport_device(mconfig, tag, owner, clock)
	{
		option_reset();
		opts(*this);
		set_default_option(dflt);
		set_fixed(false);
	}

	ioport_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	// Methods called from the console
	DECLARE_READ8Z_MEMBER( readz );
	void write(offs_t offset, uint8_t data);
	DECLARE_SETADDRESS_DBIN_MEMBER( setaddress_dbin );
	DECLARE_READ8Z_MEMBER( crureadz );
	void cruwrite(offs_t offset, uint8_t data);
	DECLARE_WRITE_LINE_MEMBER( memen_in );
	DECLARE_WRITE_LINE_MEMBER( msast_in );
	DECLARE_WRITE_LINE_MEMBER( clock_in );

	// Callbacks
	auto extint_cb() { return m_console_extint.bind(); }
	auto ready_cb() { return m_console_ready.bind(); }

protected:
	void device_start() override;
	void device_config_complete() override;

	// Methods called back from the external device
	devcb_write_line m_console_extint;   // EXTINT line
	devcb_write_line m_console_ready;  // READY line

private:
	ioport_attached_device*    m_connected;
};
}   }  } // end namespace bus::ti99::internal

DECLARE_DEVICE_TYPE_NS(TI99_IOPORT, bus::ti99::internal, ioport_device)

void ti99_ioport_options_plain(device_slot_interface &device);
void ti99_ioport_options_evpc(device_slot_interface &device);

#endif /* __TI99IOPORT__ */