1 // license:BSD-3-Clause
2 // copyright-holders:Raphael Nabet, Michael Zapf
3 /*
4 ATMEL AT29 family
5
6 Michael Zapf
7 August 2015
8 */
9
10 #ifndef MAME_MACHINE_AT29X_H
11 #define MAME_MACHINE_AT29X_H
12
13 #pragma once
14
15
DECLARE_DEVICE_TYPE(AT29C020,at29c020_device)16 DECLARE_DEVICE_TYPE(AT29C020, at29c020_device)
17 DECLARE_DEVICE_TYPE(AT29C040, at29c040_device)
18 DECLARE_DEVICE_TYPE(AT29C040A, at29c040a_device)
19
20 class at29x_device : public device_t, public device_nvram_interface
21 {
22 public:
23 uint8_t read(offs_t offset);
24 void write(offs_t offset, uint8_t data);
25
26 protected:
27 at29x_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, int memory_size, int device_id, int sector_size);
28
29 virtual void device_start(void) override;
30 virtual void device_reset(void) override;
31 virtual void device_stop(void) override;
32 virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
33
34 void nvram_default() override;
35 void nvram_read(emu_file &file) override;
36 void nvram_write(emu_file &file) override;
37
38 int get_sector_number(offs_t address) { return address / m_sector_size; }
39
40 const int m_memory_size; // bytes
41 int m_word_width;
42 const int m_device_id;
43 const int m_sector_size;
44 int m_cycle_time; // ms
45 int m_boot_block_size;
46 int m_version;
47 int m_address_mask;
48 int m_sector_mask;
49
50 private:
51 enum s_cmd_t
52 {
53 CMD_0 = 0,
54 CMD_1,
55 CMD_2
56 };
57
58 enum s_pgm_t
59 {
60 PGM_0 = 0,
61 PGM_1,
62 PGM_2,
63 PGM_3
64 };
65
66 void sync_flags(void);
67
68 std::unique_ptr<uint8_t[]> m_eememory;
69
70 bool m_lower_bbl; // set when lower boot block lockout is enabled
71 bool m_higher_bbl; // set when upper boot block lockout is enabled
72 bool m_sdp; // set when in software data protect mode
73
74 bool m_id_mode; // set when in chip id mode
75 s_cmd_t m_cmd; // command state
76 bool m_enabling_bbl; // set when a boot block lockout command is expecting its parameter
77 bool m_long_sequence; // set if 0x80 command has just been executed (some command require this prefix)
78 s_pgm_t m_pgm; // programming state
79 bool m_enabling_sdb; // set when a sdp enable command is in progress
80 bool m_disabling_sdb; // set when a sdp disable command is in progress
81 bool m_toggle_bit; // indicates flashing in progress (toggles for each query)
82
83 std::unique_ptr<uint8_t[]> m_programming_buffer;
84 int m_programming_last_offset;
85 emu_timer* m_programming_timer;
86 };
87
88 /*
89 Variants
90 */
91 class at29c020_device : public at29x_device
92 {
93 public:
94 at29c020_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0);
95 };
96
97 class at29c040_device : public at29x_device
98 {
99 public:
100 at29c040_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0);
101 };
102
103 class at29c040a_device : public at29x_device
104 {
105 public:
106 at29c040a_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0);
107 };
108
109 #endif // MAME_MACHINE_AT29X_H
110