summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/mos6529.h
blob: abddc4175c7da99092b0f2f0f08f03deb264e855 (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
109
110
111
112
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    MOS Technology 6529 Single Port Interface Adapter emulation

**********************************************************************
                            _____   _____
                   R/W   1 |*    \_/     | 20  Vdd
                    P0   2 |             | 19  _CS
                    P1   3 |             | 18  D0
                    P2   4 |             | 17  D1
                    P3   5 |   MOS6529   | 16  D2
                    P4   6 |             | 15  D3
                    P5   7 |             | 14  D4
                    P6   8 |             | 13  D5
                    P7   9 |             | 12  D6
                   Vss  10 |_____________| 11  D7

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

#ifndef MAME_MACHINE_MOS6529_H
#define MAME_MACHINE_MOS6529_H

#pragma once




//**************************************************************************
//  INTERFACE CONFIGURATION MACROS
//**************************************************************************

#define MCFG_MOS6529_P0_HANDLER(_devcb) \
	downcast<mos6529_device &>(*device).set_p0_handler(DEVCB_##_devcb);

#define MCFG_MOS6529_P1_HANDLER(_devcb) \
	downcast<mos6529_device &>(*device).set_p1_handler(DEVCB_##_devcb);

#define MCFG_MOS6529_P2_HANDLER(_devcb) \
	downcast<mos6529_device &>(*device).set_p2_handler(DEVCB_##_devcb);

#define MCFG_MOS6529_P3_HANDLER(_devcb) \
	downcast<mos6529_device &>(*device).set_p3_handler(DEVCB_##_devcb);

#define MCFG_MOS6529_P4_HANDLER(_devcb) \
	downcast<mos6529_device &>(*device).set_p4_handler(DEVCB_##_devcb);

#define MCFG_MOS6529_P5_HANDLER(_devcb) \
	downcast<mos6529_device &>(*device).set_p5_handler(DEVCB_##_devcb);

#define MCFG_MOS6529_P6_HANDLER(_devcb) \
	downcast<mos6529_device &>(*device).set_p6_handler(DEVCB_##_devcb);

#define MCFG_MOS6529_P7_HANDLER(_devcb) \
	downcast<mos6529_device &>(*device).set_p7_handler(DEVCB_##_devcb);


//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

// ======================> mos6529_device

class mos6529_device :  public device_t
{
public:
	// construction/destruction
	mos6529_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	template <class Object> devcb_base &set_p0_handler(Object &&cb) { return m_p0_handler.set_callback(std::forward<Object>(cb)); }
	template <class Object> devcb_base &set_p1_handler(Object &&cb) { return m_p1_handler.set_callback(std::forward<Object>(cb)); }
	template <class Object> devcb_base &set_p2_handler(Object &&cb) { return m_p2_handler.set_callback(std::forward<Object>(cb)); }
	template <class Object> devcb_base &set_p3_handler(Object &&cb) { return m_p3_handler.set_callback(std::forward<Object>(cb)); }
	template <class Object> devcb_base &set_p4_handler(Object &&cb) { return m_p4_handler.set_callback(std::forward<Object>(cb)); }
	template <class Object> devcb_base &set_p5_handler(Object &&cb) { return m_p5_handler.set_callback(std::forward<Object>(cb)); }
	template <class Object> devcb_base &set_p6_handler(Object &&cb) { return m_p6_handler.set_callback(std::forward<Object>(cb)); }
	template <class Object> devcb_base &set_p7_handler(Object &&cb) { return m_p7_handler.set_callback(std::forward<Object>(cb)); }

	DECLARE_READ8_MEMBER( read );
	DECLARE_WRITE8_MEMBER( write );

	DECLARE_WRITE_LINE_MEMBER( write_p0 ) { if (state) m_input |= 1; else m_input &= ~1; }
	DECLARE_WRITE_LINE_MEMBER( write_p1 ) { if (state) m_input |= 2; else m_input &= ~2; }
	DECLARE_WRITE_LINE_MEMBER( write_p2 ) { if (state) m_input |= 4; else m_input &= ~4; }
	DECLARE_WRITE_LINE_MEMBER( write_p3 ) { if (state) m_input |= 8; else m_input &= ~8; }
	DECLARE_WRITE_LINE_MEMBER( write_p4 ) { if (state) m_input |= 16; else m_input &= ~16; }
	DECLARE_WRITE_LINE_MEMBER( write_p5 ) { if (state) m_input |= 32; else m_input &= ~32; }
	DECLARE_WRITE_LINE_MEMBER( write_p6 ) { if (state) m_input |= 64; else m_input &= ~64; }
	DECLARE_WRITE_LINE_MEMBER( write_p7 ) { if (state) m_input |= 128; else m_input &= ~128; }

protected:
	// device-level overrides
	virtual void device_start() override;

	uint8_t m_input;

	devcb_write_line m_p0_handler;
	devcb_write_line m_p1_handler;
	devcb_write_line m_p2_handler;
	devcb_write_line m_p3_handler;
	devcb_write_line m_p4_handler;
	devcb_write_line m_p5_handler;
	devcb_write_line m_p6_handler;
	devcb_write_line m_p7_handler;
};


// device type definition
DECLARE_DEVICE_TYPE(MOS6529, mos6529_device)

#endif // MAME_MACHINE_MOS6529_H