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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
/*
SST Multi-Purpose Flash (MPF)
(c) 2001-2007 Tim Schuerewegen
SST39VF020 - 256 KByte
SST39VF400A - 512 Kbyte
*/
#include "sst39vfx.h"
#define LOG_LEVEL 1
#define _logerror(level,x) do { if (LOG_LEVEL > level) logerror x; } while (0)
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
typedef struct _sst39vfx_t sst39vfx_t;
struct _sst39vfx_t
{
UINT8 *data;
UINT32 size;
UINT8 swap;
};
enum
{
TYPE_SST39VF020,
TYPE_SST39VF400A
};
/***************************************************************************
INLINE FUNCTIONS
***************************************************************************/
INLINE sst39vfx_t *get_token(device_t *device)
{
assert(device != NULL);
assert(device->type() == SST39VF020 || device->type() == SST39VF400A);
return (sst39vfx_t *) downcast<sst39vf020_device *>(device)->token();
}
INLINE const sst39vfx_config *get_config(device_t *device)
{
assert(device != NULL);
assert(device->type() == SST39VF020 || device->type() == SST39VF400A);
return (const sst39vfx_config *)device->static_config();
}
/***************************************************************************
IMPLEMENTATION
***************************************************************************/
static void common_start(device_t *device, int device_type)
{
sst39vfx_t *flash = get_token(device);
const sst39vfx_config *config = get_config(device);
_logerror( 0, ("sst39vfx_init (%d)\n", device_type));
memset(flash, 0, sizeof(sst39vfx_t));
switch (device_type)
{
case TYPE_SST39VF020 : flash->size = 256 * 1024; break;
case TYPE_SST39VF400A : flash->size = 512 * 1024; break;
}
flash->data = auto_alloc_array(device->machine(), UINT8, flash->size);
#ifdef LSB_FIRST
if (config->cpu_endianess != ENDIANNESS_LITTLE) flash->swap = config->cpu_datawidth / 8; else flash->swap = 0;
#else
if (config->cpu_endianess != ENDIANNESS_BIG) flash->swap = config->cpu_datawidth / 8; else flash->swap = 0;
#endif
state_save_register_item_pointer(device->machine(), "sst39vfx", device->tag(), 0, flash->data, flash->size);
state_save_register_item(device->machine(), "sst39vfx", device->tag(), 0, flash->swap);
}
static DEVICE_START( sst39vf020 )
{
common_start(device, TYPE_SST39VF020);
}
static DEVICE_START( sst39vf400a )
{
common_start(device, TYPE_SST39VF400A);
}
UINT8* sst39vfx_get_base( device_t *device)
{
sst39vfx_t *flash = get_token(device);
return flash->data;
}
UINT32 sst39vfx_get_size( device_t *device)
{
sst39vfx_t *flash = get_token(device);
return flash->size;
}
/*
#define OFFSET_SWAP(offset,width) (offset & (~(width - 1))) | (width - 1 - (offset & (width - 1)))
*/
#ifdef UNUSED_FUNCTION
READ8_HANDLER( sst39vfx_r )
{
_logerror( 1, ("sst39vfx_r (%08X)\n", offset));
if (flash->swap) offset = OFFSET_SWAP( offset, flash->swap);
return flash->data[offset];
}
WRITE8_HANDLER( sst39vfx_w )
{
_logerror( 1, ("sst39vfx_w (%08X/%02X)\n", offset, data));
if (flash->swap) offset = OFFSET_SWAP( offset, flash->swap);
flash->data[offset] = data;
}
#endif
static void sst39vfx_swap( device_t *device)
{
int i, j;
UINT8 *base, temp[8];
sst39vfx_t *flash = get_token(device);
base = flash->data;
for (i=0;i<flash->size;i+=flash->swap)
{
memcpy( temp, base, flash->swap);
for (j=flash->swap-1;j>=0;j--) *base++ = temp[j];
}
}
void sst39vfx_load(device_t *device, emu_file *file)
{
sst39vfx_t *flash = get_token(device);
_logerror( 0, ("sst39vfx_load (%p)\n", file));
file->read(flash->data, flash->size);
if (flash->swap) sst39vfx_swap(device);
}
void sst39vfx_save(device_t *device, emu_file *file)
{
sst39vfx_t *flash = get_token(device);
_logerror( 0, ("sst39vfx_save (%p)\n", file));
if (flash->swap) sst39vfx_swap(device);
file->write(flash->data, flash->size);
if (flash->swap) sst39vfx_swap(device);
}
#if 0
NVRAM_HANDLER( sst39vfx )
{
_logerror( 0, ("nvram_handler_sst39vfx (%p/%d)\n", file, read_or_write));
if (read_or_write)
{
sst39vfx_save( file);
}
else
{
if (file)
{
sst39vfx_load( file);
}
else
{
memset( flash->data, 0xFF, flash->size);
}
}
}
#endif
/*-------------------------------------------------
DEVICE_GET_INFO( sst39vf020 )
-------------------------------------------------*/
DEVICE_GET_INFO( sst39vf020 )
{
switch (state)
{
/* --- the following bits of info are returned as 64-bit signed integers --- */
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(sst39vfx_t); break;
/* --- the following bits of info are returned as pointers to data or functions --- */
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(sst39vf020); break;
case DEVINFO_FCT_STOP: /* Nothing */ break;
case DEVINFO_FCT_RESET: /* Nothing */ break;
/* --- the following bits of info are returned as NULL-terminated strings --- */
case DEVINFO_STR_NAME: strcpy(info->s, "SST39VF020"); break;
case DEVINFO_STR_FAMILY: strcpy(info->s, "SST39VFxx"); break;
case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
case DEVINFO_STR_CREDITS: /* Nothing */ break;
}
}
DEVICE_GET_INFO( sst39vf400a )
{
switch (state)
{
/* --- the following bits of info are returned as NULL-terminated strings --- */
case DEVINFO_STR_NAME: strcpy(info->s, "SST39VF400A"); break;
/* --- the following bits of info are returned as pointers to data or functions --- */
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(sst39vf400a); break;
default: DEVICE_GET_INFO_CALL(sst39vf020); break;
}
}
const device_type SST39VF020 = &device_creator<sst39vf020_device>;
sst39vf020_device::sst39vf020_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, SST39VF020, "SST39VF020", tag, owner, clock)
{
m_token = global_alloc_array_clear(UINT8, sizeof(sst39vfx_t));
}
sst39vf020_device::sst39vf020_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, type, name, tag, owner, clock)
{
m_token = global_alloc_array_clear(UINT8, sizeof(sst39vfx_t));
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void sst39vf020_device::device_config_complete()
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void sst39vf020_device::device_start()
{
DEVICE_START_NAME( sst39vf020 )(this);
}
const device_type SST39VF400A = &device_creator<sst39vf400a_device>;
sst39vf400a_device::sst39vf400a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: sst39vf020_device(mconfig, SST39VF400A, "SST39VF400A", tag, owner, clock)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void sst39vf400a_device::device_start()
{
DEVICE_START_NAME( sst39vf400a )(this);
}
|