summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/machine/ds1302.h
blob: 7b97d58be657b2f2f5296e3069723d7c3142f80d (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
/**********************************************************************

    DALLAS DS1302

    RTC + BACKUP RAM

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

#pragma once

#ifndef __DS1302_H__
#define __DS1302_H__

#include "emu.h"



/***************************************************************************
    DEVICE CONFIGURATION MACROS
***************************************************************************/

#define MCFG_DS1302_ADD(_tag) \
	MCFG_DEVICE_ADD(_tag, DS1302, 0)


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


// ======================> ds1302_device_config

class ds1302_device_config : public device_config
{
    friend class ds1302_device;

    // construction/destruction
    ds1302_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);

public:
    // allocators
    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
    virtual device_t *alloc_device(running_machine &machine) const;
};



// ======================> ds1302_device

class ds1302_device :  public device_t
{
    friend class ds1302_device_config;

    // construction/destruction
    ds1302_device(running_machine &_machine, const ds1302_device_config &_config);

public:

	void ds1302_dat_w(UINT32 offset, UINT8 data);
	void ds1302_clk_w(UINT32 offset, UINT8 data);
	UINT8 ds1302_read(UINT32 offset);

protected:
    // device-level overrides
    virtual void device_start();
    virtual void device_reset();
    virtual void device_post_load() { }
    virtual void device_clock_changed() { }

private:

	UINT32 m_shift_in;
	UINT8  m_shift_out;
	UINT8  m_icount;
	UINT8  m_last_clk;
	UINT8  m_last_cmd;
	UINT8  m_sram[0x20];

    const ds1302_device_config &m_config;
};


// device type definition
extern const device_type DS1302;



/***************************************************************************
    PROTOTYPES
***************************************************************************/

extern WRITE8_DEVICE_HANDLER( ds1302_dat_w );
extern WRITE8_DEVICE_HANDLER( ds1302_clk_w );
extern READ8_DEVICE_HANDLER( ds1302_read );


#endif /* __DS1302_H__ */