summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/74166.h
blob: 44642fec20a1070590a452692a14e7ed7f037564 (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
// license: BSD-3-Clause
// copyright-holders: Dirk Best
/***************************************************************************

    SN54/74166

    8-Bit Parallel-In/Serial-Out Shift Register

               ___ ___
       SER  1 |*  u   | 16  VCC
         A  2 |       | 15  SH//LD
         B  3 |       | 14  H
         C  4 |       | 13  QH
         D  5 |       | 12  G
   CLK INH  6 |       | 11  F
       CLK  7 |       | 10  E
       GND  8 |_______|  9  /CLR

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

#ifndef MAME_DEVICES_MACHINE_74166_H
#define MAME_DEVICES_MACHINE_74166_H

#pragma once

#include "machine/timer.h"


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

#define MCFG_TTL166_ADD(_tag) \
	MCFG_DEVICE_ADD(_tag, TTL166, 0)

#define MCFG_TTL166_DATA_CB(_devcb) \
	devcb = &ttl166_device::set_data_callback(*device, DEVCB_##_devcb);

#define MCFG_TTL166_QH_CB(_devcb) \
	devcb = &ttl166_device::set_qh_callback(*device, DEVCB_##_devcb);


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

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

	// configuration
	template <class Object> static devcb_base &set_data_callback(device_t &device, Object &&cb)
		{ return downcast<ttl166_device &>(device).m_data_cb.set_callback(std::forward<Object>(cb)); }

	template <class Object> static devcb_base &set_qh_callback(device_t &device, Object &&cb)
		{ return downcast<ttl166_device &>(device).m_qh_cb.set_callback(std::forward<Object>(cb)); }

	DECLARE_WRITE_LINE_MEMBER(serial_w);
	DECLARE_WRITE_LINE_MEMBER(clock_w);
	DECLARE_WRITE_LINE_MEMBER(shift_load_w);

protected:
	// device-level overrides
	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_start() override;
	virtual void device_reset() override;

private:
	required_device<timer_device> m_timer;

	// callbacks
	devcb_read8 m_data_cb;
	devcb_write_line m_qh_cb;

	// state
	uint8_t m_data;
	int m_ser;
	int m_clk;
	int m_shld;

	TIMER_DEVICE_CALLBACK_MEMBER(qh_output);
};


// device type definition
DECLARE_DEVICE_TYPE(TTL166, ttl166_device)

#endif // MAME_DEVICES_MACHINE_74166_H