1 // license:BSD-3-Clause
2 // copyright-holders:smf,Barry Rodewald
3 /***************************************************************************
4 
5     x2212.h
6 
7     Xicor X2212 256 x 4 bit Nonvolatile Static RAM.
8 
9 ****************************************************************************
10                              ____   ____
11                      A7   1 |*   \_/    | 18  Vcc
12                      A4   2 |           | 17  A6
13                      A3   3 |           | 16  A5
14                      A2   4 |           | 15  I/O4
15                      A1   5 |   X2212   | 14  I/O3
16                      A0   6 |           | 13  I/O2
17                     /CS   7 |           | 12  I/O1
18                     Vss   8 |           | 11  /WE
19                  /STORE   9 |___________| 10  /ARRAY RECALL
20 
21 ***************************************************************************/
22 
23 #ifndef MAME_MACHINE_X2212_H
24 #define MAME_MACHINE_X2212_H
25 
26 #pragma once
27 
28 
29 
30 //**************************************************************************
31 //  TYPE DEFINITIONS
32 //**************************************************************************
33 
34 
35 // ======================> x2212_device
36 
37 class x2212_device : public device_t, public device_nvram_interface
38 {
39 public:
40 	// construction/destruction
41 	x2212_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);
42 
43 	// some systems (like many early Atari games) wire up the /STORE signal
44 	// to fire on power-down, effectively creating an "auto-save" functionality
set_auto_save(bool auto_save)45 	void set_auto_save(bool auto_save) { m_auto_save = auto_save; }
46 
47 	// I/O operations
48 	u8 read(address_space &space, offs_t offset);
49 	void write(offs_t offset, uint8_t data);
50 
51 	void store(int state);
52 	void recall(int state);
53 
54 protected:
55 	x2212_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, int size_data);
56 
57 	// device-level overrides
58 	virtual void device_start() override;
59 
60 	// device_nvram_interface overrides
61 	virtual void nvram_default() override;
62 	virtual void nvram_read(emu_file &file) override;
63 	virtual void nvram_write(emu_file &file) override;
64 
65 private:
66 	// configuration state
67 	bool                        m_auto_save;
68 
69 	// internal state
70 	std::unique_ptr<u8[]> m_sram;
71 	std::unique_ptr<u8[]> m_e2prom;
72 
73 	bool        m_store;
74 	bool        m_array_recall;
75 
76 	int const m_size_data;
77 	optional_region_ptr<u8> m_default_data;
78 
79 	// internal helpers
80 	void do_store();
81 	void do_recall();
82 };
83 
84 class x2210_device : public x2212_device
85 {
86 public:
87 	x2210_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);
88 };
89 
90 
91 // device type definition
92 DECLARE_DEVICE_TYPE(X2212, x2212_device)
93 DECLARE_DEVICE_TYPE(X2210, x2210_device)
94 
95 #endif // MAME_MACHINE_X2212_H
96