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
113
114
115
116
117
118
119
|
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/**********************************************************************
DALLAS DS2404
RTC + BACKUP RAM
**********************************************************************/
#ifndef MAME_MACHINE_DS2404_H
#define MAME_MACHINE_DS2404_H
#pragma once
/***************************************************************************
DEVICE CONFIGURATION MACROS
***************************************************************************/
#define MCFG_DS2404_REF_YEAR(_ref_year) \
downcast<ds2404_device &>(*device).set_ref_year(_ref_year);
#define MCFG_DS2404_REF_MONTH(_ref_month) \
downcast<ds2404_device &>(*device).set_ref_month(_ref_month);
#define MCFG_DS2404_REF_DAY(_ref_day) \
downcast<ds2404_device &>(*device).set_ref_day(_ref_day);
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
// ======================> ds2404_device
class ds2404_device : public device_t, public device_nvram_interface
{
public:
// construction/destruction
ds2404_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
// inline configuration helpers
void set_ref_year(uint32_t year) { m_ref_year = year; }
void set_ref_month(uint8_t month) { m_ref_month = month; }
void set_ref_day(uint8_t day) { m_ref_day = day; }
/* 1-wire interface reset */
DECLARE_WRITE8_MEMBER(ds2404_1w_reset_w);
/* 3-wire interface reset */
DECLARE_WRITE8_MEMBER(ds2404_3w_reset_w);
DECLARE_READ8_MEMBER(ds2404_data_r);
DECLARE_WRITE8_MEMBER(ds2404_data_w);
DECLARE_WRITE8_MEMBER(ds2404_clk_w);
protected:
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override { }
virtual void device_post_load() override { }
virtual void device_clock_changed() override { }
// device_nvram_interface overrides
virtual void nvram_default() override;
virtual void nvram_read(emu_file &file) override;
virtual void nvram_write(emu_file &file) override;
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
private:
void ds2404_rom_cmd(uint8_t cmd);
void ds2404_cmd(uint8_t cmd);
uint8_t ds2404_readmem();
void ds2404_writemem(uint8_t value);
enum DS2404_STATE
{
DS2404_STATE_IDLE = 1, /* waiting for ROM command, in 1-wire mode */
DS2404_STATE_COMMAND, /* waiting for memory command */
DS2404_STATE_ADDRESS1, /* waiting for address bits 0-7 */
DS2404_STATE_ADDRESS2, /* waiting for address bits 8-15 */
DS2404_STATE_OFFSET, /* waiting for ending offset */
DS2404_STATE_INIT_COMMAND,
DS2404_STATE_READ_MEMORY, /* Read Memory command active */
DS2404_STATE_WRITE_SCRATCHPAD, /* Write Scratchpad command active */
DS2404_STATE_READ_SCRATCHPAD, /* Read Scratchpad command active */
DS2404_STATE_COPY_SCRATCHPAD /* Copy Scratchpad command active */
};
emu_timer *m_tick_timer;
// configuration state
uint32_t m_ref_year;
uint8_t m_ref_month;
uint8_t m_ref_day;
uint16_t m_address;
uint16_t m_offset;
uint16_t m_end_offset;
uint8_t m_a1;
uint8_t m_a2;
uint8_t m_sram[512]; /* 4096 bits */
uint8_t m_ram[32]; /* scratchpad ram, 256 bits */
uint8_t m_rtc[5]; /* 40-bit RTC counter */
DS2404_STATE m_state[8];
int m_state_ptr;
};
// device type definition
DECLARE_DEVICE_TYPE(DS2404, ds2404_device)
#endif // MAME_MACHINE_DS2404_H
|