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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
// license:BSD-3-Clause
// copyright-holders:Fabio Priuli
#ifndef MAME_BUS_MEGADRIVE_EEPROM_H
#define MAME_BUS_MEGADRIVE_EEPROM_H
#pragma once
#include "md_slot.h"
#include "machine/i2cmem.h"
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
// ======================> md_std_eeprom_device
class md_std_eeprom_device : public device_t,
public device_md_cart_interface
{
public:
// construction/destruction
md_std_eeprom_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);
protected:
md_std_eeprom_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, const XTAL &clock);
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override;
virtual void device_add_mconfig(machine_config &config) override;
// reading and writing
virtual uint16_t read(offs_t offset) override;
virtual void write(offs_t offset, uint16_t data, uint16_t mem_mask = ~0) override;
required_device<i2cmem_device> m_i2cmem;
uint8_t m_i2c_mem, m_i2c_clk;
};
// ======================> md_eeprom_nbajam_device
class md_eeprom_nbajam_device : public md_std_eeprom_device
{
public:
// construction/destruction
md_eeprom_nbajam_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);
protected:
// device-level overrides
virtual void device_add_mconfig(machine_config &config) override;
// reading and writing
virtual uint16_t read(offs_t offset) override;
virtual void write(offs_t offset, uint16_t data, uint16_t mem_mask = ~0) override;
};
// ======================> md_eeprom_nbajamte_device
class md_eeprom_nbajamte_device : public md_std_eeprom_device
{
public:
// construction/destruction
md_eeprom_nbajamte_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);
protected:
// device-level overrides
virtual void device_add_mconfig(machine_config &config) override;
// reading and writing
virtual uint16_t read(offs_t offset) override;
virtual void write(offs_t offset, uint16_t data, uint16_t mem_mask = ~0) override;
};
// ======================> md_eeprom_cslam_device (same read/write as nbajamte, but different I2C type)
class md_eeprom_cslam_device : public md_std_eeprom_device
{
public:
// construction/destruction
md_eeprom_cslam_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);
protected:
// device-level overrides
virtual void device_add_mconfig(machine_config &config) override;
// reading and writing
virtual uint16_t read(offs_t offset) override;
virtual void write(offs_t offset, uint16_t data, uint16_t mem_mask = ~0) override;
};
// ======================> md_eeprom_nflqb_device (same read/write as nbajamte, but different I2C type)
class md_eeprom_nflqb_device : public md_std_eeprom_device
{
public:
// construction/destruction
md_eeprom_nflqb_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);
protected:
// device-level overrides
virtual void device_add_mconfig(machine_config &config) override;
// reading and writing
virtual uint16_t read(offs_t offset) override;
virtual void write(offs_t offset, uint16_t data, uint16_t mem_mask = ~0) override;
};
// ======================> md_eeprom_nhlpa_device
class md_eeprom_nhlpa_device : public md_std_eeprom_device
{
public:
// construction/destruction
md_eeprom_nhlpa_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);
protected:
// device-level overrides
virtual void device_add_mconfig(machine_config &config) override;
// reading and writing
virtual uint16_t read(offs_t offset) override;
virtual void write(offs_t offset, uint16_t data, uint16_t mem_mask = ~0) override;
};
// ======================> md_eeprom_blara_device (same read/write as codemast, but different I2C type)
class md_eeprom_blara_device : public md_std_eeprom_device
{
public:
// construction/destruction
md_eeprom_blara_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);
protected:
// device-level overrides
virtual void device_add_mconfig(machine_config &config) override;
// reading and writing
virtual uint16_t read(offs_t offset) override;
virtual void write(offs_t offset, uint16_t data, uint16_t mem_mask = ~0) override;
};
// ======================> md_eeprom_mode1_device
class md_eeprom_mode1_device : public md_std_eeprom_device
{
public:
// construction/destruction
md_eeprom_mode1_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);
protected:
// device-level overrides
virtual void device_add_mconfig(machine_config &config) override;
};
// device type definition
DECLARE_DEVICE_TYPE(MD_STD_EEPROM, md_std_eeprom_device)
DECLARE_DEVICE_TYPE(MD_EEPROM_NBAJAM, md_eeprom_nbajam_device)
DECLARE_DEVICE_TYPE(MD_EEPROM_NBAJAMTE, md_eeprom_nbajamte_device)
DECLARE_DEVICE_TYPE(MD_EEPROM_CSLAM, md_eeprom_cslam_device)
DECLARE_DEVICE_TYPE(MD_EEPROM_NFLQB, md_eeprom_nflqb_device)
DECLARE_DEVICE_TYPE(MD_EEPROM_NHLPA, md_eeprom_nhlpa_device)
DECLARE_DEVICE_TYPE(MD_EEPROM_BLARA, md_eeprom_blara_device)
DECLARE_DEVICE_TYPE(MD_EEPROM_MODE1, md_eeprom_mode1_device)
// TEMPORARY ADDITION UNTIL WE FIND OUT WHAT IS MISSING IN THE CORE X24C02 CODE
// THIS IS A CUSTOM I2C EEPROM EMULATION THAT ALLOWS NBA JAM TO WORK
enum
{
STATE_I2C_IDLE = 0,
STATE_I2C_WAIT_STOP,
STATE_I2C_DEVSEL,
STATE_I2C_GET_WORD_ADDR,
STATE_I2C_WRITE_DATA,
STATE_I2C_READ_DATA
};
// ======================> md_eeprom_nbajam_alt_device
class md_eeprom_nbajam_alt_device : public md_std_eeprom_device
{
public:
// construction/destruction
md_eeprom_nbajam_alt_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);
// reading and writing
virtual uint16_t read(offs_t offset) override;
virtual void write(offs_t offset, uint16_t data, uint16_t mem_mask = ~0) override;
protected:
// device-level overrides
virtual void device_start() override;
private:
void eeprom_i2c_init();
void idle_devsel_check();
void eeprom_i2c_update();
uint8_t eeprom_i2c_out();
std::vector<uint8_t> m_sram;
// EEPROM runtime vars
uint8_t m_eeprom_sda; // current SDA
uint8_t m_eeprom_prev_sda; // previous SDA
uint8_t m_eeprom_scl; // current SCL
uint8_t m_eeprom_prev_scl; // previous SCL
uint8_t m_eeprom_cnt; // operation count in 0-9
uint8_t m_eeprom_readwrite; // read/write bit
uint16_t m_eeprom_slave_mask; // dev addr
uint16_t m_eeprom_word_address; // memory addr
uint16_t m_eeprom_devsel; // selected device
uint16_t m_eeprom_byte; // byte to be written
int m_eeprom_cur_state; // current state
// EEPROM physical characteristics (configured at init)
uint16_t m_eeprom_mask; // size of the memory - 1
uint16_t m_eeprom_pagewrite_mask; // max number of bytes that can be written in a single write cycle
};
DECLARE_DEVICE_TYPE(MD_EEPROM_NBAJAM_ALT, md_eeprom_nbajam_alt_device)
#endif // MAME_BUS_MEGADRIVE_EEPROM_H
|