Previous 15994 Revisions Next

r4095 Thursday 8th January, 2009 at 13:54:15 UTC by Miodrag Milanović
[AT45DBXX][SST39VFX] Converted to device
[docs]messnew.txt
[src/mess/drivers]cybiko.c
[src/mess/machine]at45dbxx.c at45dbxx.h cybiko.c sst39vfx.c sst39vfx.h

src/mess/machine/at45dbxx.c
r4094r4095
1212
1313#include "at45dbxx.h"
1414
15enum
16{
17   TYPE_AT45DB041,
18   TYPE_AT45DB081,
19   TYPE_AT45DB161
20};
21
1522#define LOG_LEVEL  1
1623#define _logerror(level,x)  do { if (LOG_LEVEL > level) logerror x; } while (0)
1724
r4094r4095
2431#define FLASH_MODE_SI  1 // input
2532#define FLASH_MODE_SO  2 // output
2633
34
35/***************************************************************************
36    TYPE DEFINITIONS
37***************************************************************************/
38
2739typedef struct
2840{
2941   int cs;    // chip select
r4094r4095
4658   UINT32 size, pos;
4759} AT45DBXX_IO;
4860
49typedef struct
61typedef struct _at45dbxx_t at45dbxx_t;
62struct _at45dbxx_t
5063{
5164   UINT8 *data;
5265   UINT32 size;
r4094r4095
5669   UINT8 si_byte, si_bits, so_byte, so_bits;
5770   AT45DBXX_CMD cmd;
5871   AT45DBXX_IO io;
59} AT45DBXX;
72};
6073
61static AT45DBXX flash;
6274
63static void at45dbxx_state_save(running_machine *machine);
64static void at45dbxx_reset(running_machine *machine);
75/***************************************************************************
76    INLINE FUNCTIONS
77***************************************************************************/
6578
66void at45dbxx_init(running_machine *machine, int type)
79INLINE at45dbxx_t *get_token(const device_config *device)
6780{
68   _logerror( 0, ("at45dbxx_init (%d)\n", type));
69   memset( &flash, 0, sizeof( flash));
70   switch (type)
81   assert(device != NULL);
82   return (at45dbxx_t *) device->token;
83}
84
85
86/***************************************************************************
87    IMPLEMENTATION
88***************************************************************************/
89
90static device_start_err common_start(const device_config *device, int device_type)
91{
92   at45dbxx_t *flash = get_token(device);
93   
94   _logerror( 0, ("at45dbxx_init (%d)\n", device_type));
95   memset( flash, 0, sizeof( flash));
96   switch (device_type)
7197   {
72      case AT45DB041 : flash.pages = 2048; flash.page_size = 264; flash.devid = 0x18; break;
73      case AT45DB081 : flash.pages = 4096; flash.page_size = 264; flash.devid = 0x20; break;
74      case AT45DB161 : flash.pages = 4096; flash.page_size = 528; flash.devid = 0x28; break;
98      case TYPE_AT45DB041 : flash->pages = 2048; flash->page_size = 264; flash->devid = 0x18; break;
99      case TYPE_AT45DB081 : flash->pages = 4096; flash->page_size = 264; flash->devid = 0x20; break;
100      case TYPE_AT45DB161 : flash->pages = 4096; flash->page_size = 528; flash->devid = 0x28; break;
75101   }
76   flash.size = flash.pages * flash.page_size;
77   flash.data = auto_malloc( flash.size);
78   flash.buffer1 = auto_malloc( flash.page_size);
79   flash.buffer2 = auto_malloc( flash.page_size);
80   at45dbxx_state_save(machine);
102   flash->size = flash->pages * flash->page_size;
103   flash->data = auto_malloc( flash->size);
104   flash->buffer1 = auto_malloc( flash->page_size);
105   flash->buffer2 = auto_malloc( flash->page_size);
106   
107   // data
108   state_save_register_item_pointer(device->machine, "at45dbxx", device->tag, 0, flash->data, flash->size);
109   // pins
110   state_save_register_item(device->machine, "at45dbxx", device->tag, 0, flash->pin.cs);
111   state_save_register_item(device->machine, "at45dbxx", device->tag, 0, flash->pin.sck);
112   state_save_register_item(device->machine, "at45dbxx", device->tag, 0, flash->pin.si);
113   state_save_register_item(device->machine, "at45dbxx", device->tag, 0, flash->pin.so);
114   state_save_register_item(device->machine, "at45dbxx", device->tag, 0, flash->pin.wp);
115   state_save_register_item(device->machine, "at45dbxx", device->tag, 0, flash->pin.reset);
116   state_save_register_item(device->machine, "at45dbxx", device->tag, 0, flash->pin.busy);
117   return DEVICE_START_OK;   
118}
81119
82   add_reset_callback(machine, at45dbxx_reset);
120static DEVICE_START( at45db041 )
121{
122   return common_start(device, TYPE_AT45DB041);
83123}
84124
85static void at45dbxx_reset(running_machine *machine)
125static DEVICE_START( at45db081 )
86126{
127   return common_start(device, TYPE_AT45DB081);
128}
129
130static DEVICE_START( at45db161 )
131{
132   return common_start(device, TYPE_AT45DB161);
133}
134
135static DEVICE_RESET( at45dbxx )
136{
137   at45dbxx_t *flash = get_token(device);
87138   _logerror( 1, ("at45dbxx_reset\n"));
88139   // mode
89   flash.mode = FLASH_MODE_SI;
140   flash->mode = FLASH_MODE_SI;
90141   // command
91   memset( &flash.cmd.data[0], 0, sizeof( flash.cmd.data));
92   flash.cmd.size = 0;
142   memset( &flash->cmd.data[0], 0, sizeof( flash->cmd.data));
143   flash->cmd.size = 0;
93144   // input/output
94   flash.io.data = NULL;
95   flash.io.size = 0;
96   flash.io.pos  = 0;
145   flash->io.data = NULL;
146   flash->io.size = 0;
147   flash->io.pos  = 0;
97148   // pins
98   flash.pin.cs    = 0;
99   flash.pin.sck   = 0;
100   flash.pin.si    = 0;
101   flash.pin.so    = 0;
102   flash.pin.wp    = 0;
103   flash.pin.reset = 0;
104   flash.pin.busy  = 0;
149   flash->pin.cs    = 0;
150   flash->pin.sck   = 0;
151   flash->pin.si    = 0;
152   flash->pin.so    = 0;
153   flash->pin.wp    = 0;
154   flash->pin.reset = 0;
155   flash->pin.busy  = 0;
105156   // output
106   flash.so_byte = 0;
107   flash.so_bits = 0;
157   flash->so_byte = 0;
158   flash->so_bits = 0;
108159   // input
109   flash.si_byte = 0;
110   flash.si_bits = 0;
160   flash->si_byte = 0;
161   flash->si_bits = 0;
111162}
112163
113static void at45dbxx_state_save(running_machine *machine)
164static UINT8 at45dbxx_read_byte( const device_config *device)
114165{
115   const char *name = "at45dbxx";
116   // data
117   state_save_register_item_pointer(machine, name, NULL, 0, flash.data, flash.size);
118   // pins
119   state_save_register_item(machine, name, NULL, 0, flash.pin.cs);
120   state_save_register_item(machine, name, NULL, 0, flash.pin.sck);
121   state_save_register_item(machine, name, NULL, 0, flash.pin.si);
122   state_save_register_item(machine, name, NULL, 0, flash.pin.so);
123   state_save_register_item(machine, name, NULL, 0, flash.pin.wp);
124   state_save_register_item(machine, name, NULL, 0, flash.pin.reset);
125   state_save_register_item(machine, name, NULL, 0, flash.pin.busy);
126}
127
128static UINT8 at45dbxx_read_byte( running_machine *machine)
129{
130166   UINT8 data;
167   at45dbxx_t *flash = get_token(device);
131168   // check mode
132   if ((flash.mode != FLASH_MODE_SO) || (!flash.io.data)) return 0;
169   if ((flash->mode != FLASH_MODE_SO) || (!flash->io.data)) return 0;
133170   // read byte
134   data = flash.io.data[flash.io.pos++];
135   _logerror( 2, ("at45dbxx_read_byte (%02X) (%03d/%03d)\n", data, flash.io.pos, flash.io.size));
136   if (flash.io.pos == flash.io.size) flash.io.pos = 0;
171   data = flash->io.data[flash->io.pos++];
172   _logerror( 2, ("at45dbxx_read_byte (%02X) (%03d/%03d)\n", data, flash->io.pos, flash->io.size));
173   if (flash->io.pos == flash->io.size) flash->io.pos = 0;
137174   return data;
138175}
139176
140static void flash_set_io( running_machine *machine, UINT8* data, UINT32 size, UINT32 pos)
177static void flash_set_io( const device_config *device, UINT8* data, UINT32 size, UINT32 pos)
141178{
142   flash.io.data = data;
143   flash.io.size = size;
144   flash.io.pos  = pos;
179   at45dbxx_t *flash = get_token(device);
180   flash->io.data = data;
181   flash->io.size = size;
182   flash->io.pos  = pos;
145183}
146184
147static UINT32 flash_get_page_addr( running_machine *machine)
185static UINT32 flash_get_page_addr( const device_config *device)
148186{
149   switch (flash.devid)
187   at45dbxx_t *flash = get_token(device);
188   switch (flash->devid)
150189   {
151      case 0x18 : return ((flash.cmd.data[1] & 0x0F) << 7) | ((flash.cmd.data[2] & 0xFE) >> 1);
152      case 0x20 : return ((flash.cmd.data[1] & 0x1F) << 7) | ((flash.cmd.data[2] & 0xFE) >> 1);
153      case 0x28 : return ((flash.cmd.data[1] & 0x3F) << 6) | ((flash.cmd.data[2] & 0xFC) >> 2);
190      case 0x18 : return ((flash->cmd.data[1] & 0x0F) << 7) | ((flash->cmd.data[2] & 0xFE) >> 1);
191      case 0x20 : return ((flash->cmd.data[1] & 0x1F) << 7) | ((flash->cmd.data[2] & 0xFE) >> 1);
192      case 0x28 : return ((flash->cmd.data[1] & 0x3F) << 6) | ((flash->cmd.data[2] & 0xFC) >> 2);
154193      default   : return 0;
155194   }
156195}
157196
158static UINT32 flash_get_byte_addr( running_machine *machine)
197static UINT32 flash_get_byte_addr( const device_config *device)
159198{
160   switch (flash.devid)
199   at45dbxx_t *flash = get_token(device);
200   switch (flash->devid)
161201   {
162202      case 0x18 : // fall-through
163      case 0x20 : return ((flash.cmd.data[2] & 0x01) << 8) | ((flash.cmd.data[3] & 0xFF) >> 0);
164      case 0x28 : return ((flash.cmd.data[2] & 0x03) << 8) | ((flash.cmd.data[3] & 0xFF) >> 0);
203      case 0x20 : return ((flash->cmd.data[2] & 0x01) << 8) | ((flash->cmd.data[3] & 0xFF) >> 0);
204      case 0x28 : return ((flash->cmd.data[2] & 0x03) << 8) | ((flash->cmd.data[3] & 0xFF) >> 0);
165205      default   : return 0;
166206   }
167207}
168208
169static void at45dbxx_write_byte(running_machine *machine,  UINT8 data)
209static void at45dbxx_write_byte(const device_config *device,  UINT8 data)
170210{
211   at45dbxx_t *flash = get_token(device);
171212   // check mode
172   if (flash.mode != FLASH_MODE_SI) return;
213   if (flash->mode != FLASH_MODE_SI) return;
173214   // process byte
174   if (flash.cmd.size < 8)
215   if (flash->cmd.size < 8)
175216   {
176217      UINT8 opcode;
177218      _logerror( 2, ("at45dbxx_write_byte (%02X)\n", data));
178219      // add to command buffer
179      flash.cmd.data[flash.cmd.size++] = data;
220      flash->cmd.data[flash->cmd.size++] = data;
180221      // check opcode
181      opcode = flash.cmd.data[0];
222      opcode = flash->cmd.data[0];
182223      switch (opcode)
183224      {
184225         // status register read
185226         case FLASH_CMD_57 :
186227         {
187228            // 8 bits command
188            if (flash.cmd.size == 1)
229            if (flash->cmd.size == 1)
189230            {
190231               _logerror( 1, ("at45dbxx opcode %02X - status register read\n", opcode));
191               flash.status = (flash.status & 0xC7) | flash.devid; // 80 = busy / 40 = compare fail
192               flash_set_io( machine, &flash.status, 1, 0);
193               flash.mode = FLASH_MODE_SO;
194               flash.cmd.size = 8;
232               flash->status = (flash->status & 0xC7) | flash->devid; // 80 = busy / 40 = compare fail
233               flash_set_io( device, &flash->status, 1, 0);
234               flash->mode = FLASH_MODE_SO;
235               flash->cmd.size = 8;
195236            }
196237         }
197238         break;
r4094r4095
199240         case FLASH_CMD_60 :
200241         {
201242            // 8 bits command + 4 bits reserved + 11 bits page address + 9 bits don't care
202            if (flash.cmd.size == 4)
243            if (flash->cmd.size == 4)
203244            {
204245               UINT32 page;
205246               UINT8 comp;
206               page = flash_get_page_addr(machine);
247               page = flash_get_page_addr(device);
207248               _logerror( 1, ("at45dbxx opcode %02X - main memory page to buffer 1 compare [%04X]\n", opcode, page));
208               comp = memcmp( flash.data + page * flash.page_size, flash.buffer1, flash.page_size) == 0 ? 0 : 1;
209               if (comp) flash.status |= 0x40; else flash.status &= ~0x40;
249               comp = memcmp( flash->data + page * flash->page_size, flash->buffer1, flash->page_size) == 0 ? 0 : 1;
250               if (comp) flash->status |= 0x40; else flash->status &= ~0x40;
210251               _logerror( 1, ("at45dbxx page compare %s\n", comp ? "failure" : "success"));
211               flash.mode = FLASH_MODE_SI;
212               flash.cmd.size = 8;
252               flash->mode = FLASH_MODE_SI;
253               flash->cmd.size = 8;
213254            }
214255         }
215256         break;
r4094r4095
217258         case FLASH_CMD_52 :
218259         {
219260            // 8 bits command + 4 bits reserved + 11 bits page address + 9 bits buffer address + 32 bits don't care
220            if (flash.cmd.size == 8)
261            if (flash->cmd.size == 8)
221262            {
222263               UINT32 page, byte;
223               page = flash_get_page_addr(machine);
224               byte = flash_get_byte_addr(machine);
264               page = flash_get_page_addr(device);
265               byte = flash_get_byte_addr(device);
225266               _logerror( 1, ("at45dbxx opcode %02X - main memory page read [%04X/%04X]\n", opcode, page, byte));
226               flash_set_io( machine, flash.data + page * flash.page_size, flash.page_size, byte);
227               flash.mode = FLASH_MODE_SO;
228               flash.cmd.size = 8;
267               flash_set_io( device, flash->data + page * flash->page_size, flash->page_size, byte);
268               flash->mode = FLASH_MODE_SO;
269               flash->cmd.size = 8;
229270            }
230271         }
231272         break;
r4094r4095
233274         case FLASH_CMD_82 :
234275         {
235276            // 8 bits command + 4 bits reserved + 11 bits page address + 9 bits buffer address
236            if (flash.cmd.size == 4)
277            if (flash->cmd.size == 4)
237278            {
238279               UINT32 page, byte;
239               page = flash_get_page_addr(machine);
240               byte = flash_get_byte_addr(machine);
280               page = flash_get_page_addr(device);
281               byte = flash_get_byte_addr(device);
241282               _logerror( 1, ("at45dbxx opcode %02X - main memory page program through buffer 1 [%04X/%04X]\n",opcode, page, byte));
242               flash_set_io( machine, flash.buffer1, flash.page_size, byte);
243               memset( flash.buffer1, 0xFF, flash.page_size);
244               flash.mode = FLASH_MODE_SI;
245               flash.cmd.size = 8;
283               flash_set_io( device, flash->buffer1, flash->page_size, byte);
284               memset( flash->buffer1, 0xFF, flash->page_size);
285               flash->mode = FLASH_MODE_SI;
286               flash->cmd.size = 8;
246287            }
247288         }
248289         break;
r4094r4095
250291         default :
251292         {
252293            _logerror( 1, ("at45dbxx opcode %02X - unknown\n", opcode));
253            flash.cmd.data[0] = 0;
254            flash.cmd.size = 0;
294            flash->cmd.data[0] = 0;
295            flash->cmd.size = 0;
255296         }
256297         break;
257298      }
258299   }
259300   else
260301   {
261      _logerror( 2, ("at45dbxx_write_byte (%02X) (%03d/%03d)\n", data, flash.io.pos + 1, flash.io.size));
302      _logerror( 2, ("at45dbxx_write_byte (%02X) (%03d/%03d)\n", data, flash->io.pos + 1, flash->io.size));
262303      // store byte
263      flash.io.data[flash.io.pos] = data;
264      flash.io.pos++;
265      if (flash.io.pos == flash.io.size) flash.io.pos = 0;
304      flash->io.data[flash->io.pos] = data;
305      flash->io.pos++;
306      if (flash->io.pos == flash->io.size) flash->io.pos = 0;
266307   }
267308}
268309
269int at45dbxx_pin_so( running_machine *machine)
310int at45dbxx_pin_so( const device_config *device)
270311{
271   if (flash.pin.cs == 0) return 0;
272   return flash.pin.so;
312   at45dbxx_t *flash = get_token(device);
313   if (flash->pin.cs == 0) return 0;
314   return flash->pin.so;
273315}
274316
275void at45dbxx_pin_si(running_machine *machine,  int data)
317void at45dbxx_pin_si(const device_config *device,  int data)
276318{
277   if (flash.pin.cs == 0) return;
278   flash.pin.si = data;
319   at45dbxx_t *flash = get_token(device);
320   if (flash->pin.cs == 0) return;
321   flash->pin.si = data;
279322}
280323
281void at45dbxx_pin_cs(running_machine *machine,  int data)
324void at45dbxx_pin_cs(const device_config *device,  int data)
282325{
326   at45dbxx_t *flash = get_token(device);
283327   // check if changed
284   if (flash.pin.cs == data) return;
328   if (flash->pin.cs == data) return;
285329   // cs low-to-high
286330   if (data != 0)
287331   {
288332      // complete program command
289      if ((flash.cmd.size >= 4) && (flash.cmd.data[0] == FLASH_CMD_82))
333      if ((flash->cmd.size >= 4) && (flash->cmd.data[0] == FLASH_CMD_82))
290334      {
291335         UINT32 page, byte;
292         page = flash_get_page_addr(machine);
293         byte = flash_get_byte_addr(machine);
336         page = flash_get_page_addr(device);
337         byte = flash_get_byte_addr(device);
294338         _logerror( 1, ("at45dbxx - program data stored in buffer 1 into selected page in main memory [%04X/%04X]\n", page, byte));
295         memcpy( flash.data + page * flash.page_size, flash.buffer1, flash.page_size);
339         memcpy( flash->data + page * flash->page_size, flash->buffer1, flash->page_size);
296340      }
297341      // reset
298      at45dbxx_reset(machine);
342      device_reset_at45dbxx(device);
299343   }
300344   // save cs
301   flash.pin.cs = data;
345   flash->pin.cs = data;
302346}
303347
304void at45dbxx_pin_sck(running_machine *machine,  int data)
348void at45dbxx_pin_sck(const device_config *device,  int data)
305349{
350   at45dbxx_t *flash = get_token(device);
306351   // check if changed
307   if (flash.pin.sck == data) return;
352   if (flash->pin.sck == data) return;
308353   // sck high-to-low
309354   if (data == 0)
310355   {
311356      // output (part 1)
312      if (flash.so_bits == 8)
357      if (flash->so_bits == 8)
313358      {
314         flash.so_bits = 0;
315         flash.so_byte = at45dbxx_read_byte(machine);
359         flash->so_bits = 0;
360         flash->so_byte = at45dbxx_read_byte(device);
316361      }
317362      // input
318      if (flash.pin.si) flash.si_byte = flash.si_byte | (1 << flash.si_bits);
319      flash.si_bits++;
320      if (flash.si_bits == 8)
363      if (flash->pin.si) flash->si_byte = flash->si_byte | (1 << flash->si_bits);
364      flash->si_bits++;
365      if (flash->si_bits == 8)
321366      {
322         flash.si_bits = 0;
323         at45dbxx_write_byte( machine, flash.si_byte);
324         flash.si_byte = 0;
367         flash->si_bits = 0;
368         at45dbxx_write_byte( device, flash->si_byte);
369         flash->si_byte = 0;
325370      }
326371      // output (part 2)
327      flash.pin.so = (flash.so_byte >> flash.so_bits) & 1;
328      flash.so_bits++;
372      flash->pin.so = (flash->so_byte >> flash->so_bits) & 1;
373      flash->so_bits++;
329374   }
330375   // save sck
331   flash.pin.sck = data;
376   flash->pin.sck = data;
332377}
333378
334void at45dbxx_load(running_machine *machine, mame_file *file)
379void at45dbxx_load(const device_config *device, mame_file *file)
335380{
381   at45dbxx_t *flash = get_token(device);
336382   _logerror( 0, ("at45dbxx_load (%p)\n", file));
337   mame_fread( file, flash.data, flash.size);
383   mame_fread( file, flash->data, flash->size);
338384}
339385
340void at45dbxx_save(running_machine *machine, mame_file *file)
386void at45dbxx_save(const device_config *device, mame_file *file)
341387{
388   at45dbxx_t *flash = get_token(device);
342389   _logerror( 0, ("at45dbxx_save (%p)\n", file));
343   mame_fwrite( file, flash.data, flash.size);
390   mame_fwrite( file, flash->data, flash->size);
344391}
345392
346393/*
r4094r4095
359406      }
360407      else
361408      {
362         memset( flash.data, 0xFF, flash.size);
409         memset( flash->data, 0xFF, flash->size);
363410      }
364411   }
365412}
366413*/
414
415
416/*-------------------------------------------------
417    DEVICE_SET_INFO( at45dbxx )
418-------------------------------------------------*/
419
420static DEVICE_SET_INFO( at45dbxx )
421{
422   switch (state)
423   {
424      /* no parameters to set */
425   }
426}
427
428
429
430/*-------------------------------------------------
431    DEVICE_GET_INFO( at45db041 )
432-------------------------------------------------*/
433
434DEVICE_GET_INFO( at45db041 )
435{
436   switch (state)
437   {
438      /* --- the following bits of info are returned as 64-bit signed integers --- */
439      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(at45dbxx_t);            break;
440      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
441      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
442
443      /* --- the following bits of info are returned as pointers to data or functions --- */
444      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(at45dbxx); break;
445      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(at45db041);   break;
446      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
447      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(at45dbxx);   break;
448
449      /* --- the following bits of info are returned as NULL-terminated strings --- */
450      case DEVINFO_STR_NAME:                     strcpy(info->s, "AT45DB041");               break;
451      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "AT45DBxx");               break;
452      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                     break;
453      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                  break;
454      case DEVINFO_STR_CREDITS:                  /* Nothing */                        break;
455   }
456}
457
458DEVICE_GET_INFO( at45db081 )
459{
460   switch (state)
461   {
462      /* --- the following bits of info are returned as NULL-terminated strings --- */
463      case DEVINFO_STR_NAME:                     strcpy(info->s, "AT45DB081");            break;
464
465      /* --- the following bits of info are returned as pointers to data or functions --- */
466      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(at45db081);   break;
467
468      default:                               DEVICE_GET_INFO_CALL(at45db041);            break;
469   }
470}
471
472DEVICE_GET_INFO( at45db161 )
473{
474   switch (state)
475   {
476      /* --- the following bits of info are returned as NULL-terminated strings --- */
477      case DEVINFO_STR_NAME:                     strcpy(info->s, "AT45DB161");            break;
478
479      /* --- the following bits of info are returned as pointers to data or functions --- */
480      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(at45db161);   break;
481
482      default:                               DEVICE_GET_INFO_CALL(at45db041);            break;
483   }
484}
src/mess/machine/at45dbxx.h
r4094r4095
1515
1616#include "driver.h"
1717
18enum
19{
20   AT45DB041,
21   AT45DB081,
22   AT45DB161
23};
2418
25// init/exit/reset
26void at45dbxx_init(running_machine *machine, int type);
19/***************************************************************************
20    MACROS
21***************************************************************************/
2722
23#define AT45DB041      DEVICE_GET_INFO_NAME(at45db041)
24
25#define MDRV_AT45DB041_ADD(_tag) \
26   MDRV_DEVICE_ADD(_tag, AT45DB041, 0) \
27
28#define MDRV_AT45DB041_REMOVE(_tag) \
29   MDRV_DEVICE_REMOVE(_tag, AT45DB041)
30
31#define AT45DB081      DEVICE_GET_INFO_NAME(at45db081)
32
33#define MDRV_AT45DB081_ADD(_tag) \
34   MDRV_DEVICE_ADD(_tag, AT45DB081, 0) \
35
36#define MDRV_AT45DB081_REMOVE(_tag) \
37   MDRV_DEVICE_REMOVE(_tag, AT45DB081)
38
39#define AT45DB161      DEVICE_GET_INFO_NAME(at45db161)
40
41#define MDRV_AT45DB161_ADD(_tag) \
42   MDRV_DEVICE_ADD(_tag, AT45DB161, 0) \
43
44#define MDRV_AT45DB161_REMOVE(_tag) \
45   MDRV_DEVICE_REMOVE(_tag, AT45DB161)
46
47
48/***************************************************************************
49    FUNCTION PROTOTYPES
50***************************************************************************/
51
52DEVICE_GET_INFO(at45db041);
53DEVICE_GET_INFO(at45db081);
54DEVICE_GET_INFO(at45db161);
55
2856// pins
29void at45dbxx_pin_cs(running_machine *machine,  int data);
30void at45dbxx_pin_sck(running_machine *machine,  int data);
31void at45dbxx_pin_si(running_machine *machine,  int data);
32int  at45dbxx_pin_so(running_machine *machine);
57void at45dbxx_pin_cs(const device_config *device, int data);
58void at45dbxx_pin_sck(const device_config *device,  int data);
59void at45dbxx_pin_si(const device_config *device,  int data);
60int  at45dbxx_pin_so(const device_config *device);
3361
3462// load/save
35void at45dbxx_load(running_machine *machine, mame_file *file);
36void at45dbxx_save(running_machine *machine, mame_file *file);
63void at45dbxx_load(const device_config *device, mame_file *file);
64void at45dbxx_save(const device_config *device, mame_file *file);
3765
3866// non-volatile ram handler
3967/*
src/mess/machine/sst39vfx.c
r4094r4095
1414#define LOG_LEVEL  1
1515#define _logerror(level,x)  do { if (LOG_LEVEL > level) logerror x; } while (0)
1616
17typedef struct
17/***************************************************************************
18    TYPE DEFINITIONS
19***************************************************************************/
20
21typedef struct _sst39vfx_t sst39vfx_t;
22struct _sst39vfx_t
1823{
1924   UINT8 *data;
2025   UINT32 size;
2126   UINT8 swap;
22} SST39VFX;
27};
2328
24static SST39VFX flash;
29enum
30{
31   TYPE_SST39VF020,
32   TYPE_SST39VF400A
33};
2534
26static void sst39vfx_state_save(running_machine *machine);
35/***************************************************************************
36    INLINE FUNCTIONS
37***************************************************************************/
2738
28void sst39vfx_init(running_machine *machine, int type, int cpu_datawidth, int cpu_endianess)
39INLINE sst39vfx_t *get_token(const device_config *device)
2940{
30   _logerror( 0, ("sst39vfx_init (%d)\n", type));
31   memset( &flash, 0, sizeof( flash));
32   switch (type)
41   assert(device != NULL);
42   return (sst39vfx_t *) device->token;
43}
44
45INLINE const sst39vfx_config *get_config(const device_config *device)
46{
47   assert(device != NULL);
48   return (const sst39vfx_config *) device->inline_config;
49}
50
51
52/***************************************************************************
53    IMPLEMENTATION
54***************************************************************************/
55
56static device_start_err common_start(const device_config *device, int device_type)
57{
58   sst39vfx_t *flash = get_token(device);
59   const sst39vfx_config *config = get_config(device);
60   
61   _logerror( 0, ("sst39vfx_init (%d)\n", device_type));
62   memset( flash, 0, sizeof( flash));
63   switch (device_type)
3364   {
34      case SST39VF020  : flash.size = 256 * 1024; break;
35      case SST39VF400A : flash.size = 512 * 1024; break;
65      case TYPE_SST39VF020  : flash->size = 256 * 1024; break;
66      case TYPE_SST39VF400A : flash->size = 512 * 1024; break;
3667   }
37   flash.data = auto_malloc( flash.size);
68   flash->data = auto_malloc( flash->size);
3869#ifdef LSB_FIRST
39   if (cpu_endianess != ENDIANNESS_LITTLE) flash.swap = cpu_datawidth / 8; else flash.swap = 0;
70   if (config->cpu_endianess != ENDIANNESS_LITTLE) flash->swap = config->cpu_datawidth / 8; else flash->swap = 0;
4071#else
41   if (cpu_endianess != ENDIANNESS_BIG) flash.swap = cpu_datawidth / 8; else flash.swap = 0;
72   if (config->cpu_endianess != ENDIANNESS_BIG) flash->swap = config->cpu_datawidth / 8; else flash->swap = 0;
4273#endif
43   sst39vfx_state_save(machine);
74
75   state_save_register_item_pointer(device->machine, "sst39vfx", device->tag, 0, flash->data, flash->size);
76   state_save_register_item(device->machine, "sst39vfx", device->tag, 0, flash->swap);
77   
78   return DEVICE_START_OK;   
4479}
4580
46static void sst39vfx_state_save(running_machine *machine)
81
82static DEVICE_START( sst39vf020 )
4783{
48   const char *name = "sst39vfx";
49   state_save_register_item_pointer(machine, name, NULL, 0, flash.data, flash.size);
50   state_save_register_item(machine, name, NULL, 0, flash.swap);
84   return common_start(device, TYPE_SST39VF020);
5185}
5286
53UINT8* sst39vfx_get_base( void)
87static DEVICE_START( sst39vf400a )
5488{
55   return flash.data;
89   return common_start(device, TYPE_SST39VF400A);
5690}
5791
58UINT32 sst39vfx_get_size( void)
92UINT8* sst39vfx_get_base( const device_config *device)
5993{
60   return flash.size;
94   sst39vfx_t *flash = get_token(device);
95   return flash->data;
6196}
6297
98UINT32 sst39vfx_get_size( const device_config *device)
99{
100   sst39vfx_t *flash = get_token(device);
101   return flash->size;
102}
103
63104/*
64105#define OFFSET_SWAP(offset,width) (offset & (~(width - 1))) | (width - 1 - (offset & (width - 1)))
65106*/
r4094r4095
68109READ8_HANDLER( sst39vfx_r )
69110{
70111   _logerror( 1, ("sst39vfx_r (%08X)\n", offset));
71   if (flash.swap) offset = OFFSET_SWAP( offset, flash.swap);
72   return flash.data[offset];
112   if (flash->swap) offset = OFFSET_SWAP( offset, flash->swap);
113   return flash->data[offset];
73114}
74115*/
75116
r4094r4095
77118WRITE8_HANDLER( sst39vfx_w )
78119{
79120   _logerror( 1, ("sst39vfx_w (%08X/%02X)\n", offset, data));
80   if (flash.swap) offset = OFFSET_SWAP( offset, flash.swap);
81   flash.data[offset] = data;
121   if (flash->swap) offset = OFFSET_SWAP( offset, flash->swap);
122   flash->data[offset] = data;
82123}
83124*/
84125
85static void sst39vfx_swap( void)
126static void sst39vfx_swap( const device_config *device)
86127{
87128   int i, j;
88129   UINT8 *base, temp[8];
89   base = flash.data;
90   for (i=0;i<flash.size;i+=flash.swap)
130   sst39vfx_t *flash = get_token(device);
131   
132   base = flash->data;
133   for (i=0;i<flash->size;i+=flash->swap)
91134   {
92      memcpy( temp, base, flash.swap);
93      for (j=flash.swap-1;j>=0;j--) *base++ = temp[j];
135      memcpy( temp, base, flash->swap);
136      for (j=flash->swap-1;j>=0;j--) *base++ = temp[j];
94137   }
95138}
96139
97void sst39vfx_load(running_machine *machine, mame_file *file)
140void sst39vfx_load(const device_config *device, mame_file *file)
98141{
142   sst39vfx_t *flash = get_token(device);
143   
99144   _logerror( 0, ("sst39vfx_load (%p)\n", file));
100   mame_fread( file, flash.data, flash.size);
101   if (flash.swap) sst39vfx_swap();
145   mame_fread( file, flash->data, flash->size);
146   if (flash->swap) sst39vfx_swap(device);
102147}
103148
104void sst39vfx_save(running_machine *machine, mame_file *file)
149void sst39vfx_save(const device_config *device, mame_file *file)
105150{
151   sst39vfx_t *flash = get_token(device);
152   
106153   _logerror( 0, ("sst39vfx_save (%p)\n", file));
107   if (flash.swap) sst39vfx_swap();
108   mame_fwrite( file, flash.data, flash.size);
109   if (flash.swap) sst39vfx_swap();
154   if (flash->swap) sst39vfx_swap(device);
155   mame_fwrite( file, flash->data, flash->size);
156   if (flash->swap) sst39vfx_swap(device);
110157}
111158
112159/*
r4094r4095
125172      }
126173      else
127174      {
128         memset( flash.data, 0xFF, flash.size);
175         memset( flash->data, 0xFF, flash->size);
129176      }
130177   }
131178}
132179*/
180/*-------------------------------------------------
181    DEVICE_SET_INFO( sst39vfx )
182-------------------------------------------------*/
183
184static DEVICE_SET_INFO( sst39vfx )
185{
186   switch (state)
187   {
188      /* no parameters to set */
189   }
190}
191
192
193
194/*-------------------------------------------------
195    DEVICE_GET_INFO( sst39vf020 )
196-------------------------------------------------*/
197
198DEVICE_GET_INFO( sst39vf020 )
199{
200   switch (state)
201   {
202      /* --- the following bits of info are returned as 64-bit signed integers --- */
203      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(sst39vfx_t);            break;
204      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = sizeof(sst39vfx_config);         break;
205      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
206
207      /* --- the following bits of info are returned as pointers to data or functions --- */
208      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(sst39vfx); break;
209      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(sst39vf020);   break;
210      case DEVINFO_FCT_STOP:                     /* Nothing */                           break;
211      case DEVINFO_FCT_RESET:                     /* Nothing */                           break;
212
213      /* --- the following bits of info are returned as NULL-terminated strings --- */
214      case DEVINFO_STR_NAME:                     strcpy(info->s, "SST39VF020");               break;
215      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "SST39VFxx");               break;
216      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                     break;
217      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                  break;
218      case DEVINFO_STR_CREDITS:                  /* Nothing */                           break;
219   }
220}
221
222DEVICE_GET_INFO( sst39vf400a )
223{
224   switch (state)
225   {
226      /* --- the following bits of info are returned as NULL-terminated strings --- */
227      case DEVINFO_STR_NAME:                     strcpy(info->s, "SST39VF400A");            break;
228
229      /* --- the following bits of info are returned as pointers to data or functions --- */
230      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(sst39vf400a);   break;
231
232      default:                               DEVICE_GET_INFO_CALL(sst39vf020);            break;
233   }
234}
src/mess/machine/sst39vfx.h
r4094r4095
1414
1515#include "driver.h"
1616
17enum
17/***************************************************************************
18    TYPE DEFINITIONS
19***************************************************************************/
20
21typedef struct _sst39vfx_config sst39vfx_config;
22struct _sst39vfx_config
1823{
19   SST39VF020,
20   SST39VF400A
24   int cpu_datawidth;
25   int cpu_endianess;
2126};
2227
23// init/exit/reset
24void sst39vfx_init(running_machine *machine, int type, int cpu_datawidth, int cpu_endianess);
28/***************************************************************************
29    MACROS
30***************************************************************************/
2531
32#define SST39VF020      DEVICE_GET_INFO_NAME(sst39vf020)
33
34#define MDRV_SST39VF020_ADD(_tag,_cpu_datawidth,_cpu_endianess) \
35   MDRV_DEVICE_ADD(_tag, SST39VF020, 0) \
36   MDRV_DEVICE_CONFIG_DATA32(sst39vfx_config, cpu_datawidth, _cpu_datawidth) \
37   MDRV_DEVICE_CONFIG_DATA32(sst39vfx_config, cpu_endianess, _cpu_endianess)
38
39#define MDRV_SST39VF020_REMOVE(_tag) \
40   MDRV_DEVICE_REMOVE(_tag, SST39VF020)   
41   
42#define SST39VF400A      DEVICE_GET_INFO_NAME(sst39vf400a)
43
44#define MDRV_SST39VF400A_ADD(_tag,_cpu_datawidth,_cpu_endianess) \
45   MDRV_DEVICE_ADD(_tag, SST39VF400A, 0) \
46   MDRV_DEVICE_CONFIG_DATA32(sst39vfx_config, cpu_datawidth, _cpu_datawidth) \
47   MDRV_DEVICE_CONFIG_DATA32(sst39vfx_config, cpu_endianess, _cpu_endianess)
48
49#define MDRV_SST39VF400A_REMOVE(_tag) \
50   MDRV_DEVICE_REMOVE(_tag, SST39VF400A)
51
52/***************************************************************************
53    FUNCTION PROTOTYPES
54***************************************************************************/
55
56DEVICE_GET_INFO(sst39vf020);
57DEVICE_GET_INFO(sst39vf400a);
58
2659// get base/size
27UINT8* sst39vfx_get_base( void);
28UINT32 sst39vfx_get_size( void);
60UINT8* sst39vfx_get_base( const device_config *device );
61UINT32 sst39vfx_get_size( const device_config *device );
2962
3063// read/write handler
3164/*
r4094r4095
3467*/
3568
3669// load/save
37void sst39vfx_load(running_machine *machine, mame_file *file);
38void sst39vfx_save(running_machine *machine, mame_file *file);
70void sst39vfx_load(const device_config *device, mame_file *file);
71void sst39vfx_save(const device_config *device, mame_file *file);
3972
4073// non-volatile ram handler
4174/*
src/mess/machine/cybiko.c
r4094r4095
195195   pcf8593_save(device, file);
196196}
197197
198static void cybiko_at45dbxx_load(running_machine *machine, mame_file *file)
199{
200   const device_config *device = devtag_get_device(machine, AT45DB041, "flash1");
201   at45dbxx_load(device, file);
202}
203
204static void cybiko_at45dbxx_save(running_machine *machine, mame_file *file)
205{
206   const device_config *device = devtag_get_device(machine, AT45DB041, "flash1");
207   at45dbxx_save(device, file);
208}
209
210static void cybiko_sst39vfx_load(running_machine *machine, mame_file *file)
211{
212   const device_config *device = devtag_get_device(machine, SST39VF020, "flash2");
213   sst39vfx_load(device, file);
214}
215
216static void cybiko_sst39vfx_save(running_machine *machine, mame_file *file)
217{
218   const device_config *device = devtag_get_device(machine, SST39VF020, "flash2");
219   sst39vfx_save(device, file);
220}
221
198222MACHINE_START( cybikov1 )
199223{
200224   _logerror( 0, ("machine_start_cybikov1\n"));
201225   // real-time clock
202226   nvram_system_load( machine, "rtc", cybiko_pcf8593_load, 0);
203227   // serial dataflash
204   at45dbxx_init(machine, AT45DB041);
205   nvram_system_load( machine, "flash1", &at45dbxx_load, 1);
228   nvram_system_load( machine, "flash1", cybiko_at45dbxx_load, 1);
206229   // serial port
207230   cybiko_rs232_init();
208231   // other
r4094r4095
211234
212235MACHINE_START( cybikov2 )
213236{
237   const device_config *flash2 = devtag_get_device(machine, SST39VF020, "flash2");
238   
214239   _logerror( 0, ("machine_start_cybikov2\n"));
215240   // real-time clock
216241   nvram_system_load( machine, "rtc", cybiko_pcf8593_load, 0);
217242   // serial dataflash
218   at45dbxx_init(machine, AT45DB041);
219   nvram_system_load( machine, "flash1", &at45dbxx_load, 1);
243   nvram_system_load( machine, "flash1", cybiko_at45dbxx_load, 1);
220244   // multi-purpose flash
221   sst39vfx_init(machine, SST39VF020, 16, ENDIANNESS_BIG);
222   nvram_system_load( machine, "flash2", &sst39vfx_load, 1);
223   memory_set_bankptr( machine, 2, sst39vfx_get_base());
245   nvram_system_load( machine, "flash2", cybiko_sst39vfx_load, 1);
246   memory_set_bankptr( machine, 2, sst39vfx_get_base(flash2));
224247   // serial port
225248   cybiko_rs232_init();
226249   // other
r4094r4095
229252
230253MACHINE_START( cybikoxt )
231254{
255   const device_config *flash2 = devtag_get_device(machine, SST39VF020, "flash2");
232256   _logerror( 0, ("machine_start_cybikoxt\n"));
233257   // real-time clock
234258   nvram_system_load( machine, "rtc", cybiko_pcf8593_load, 0);
235259   // multi-purpose flash
236   sst39vfx_init(machine, SST39VF400A, 16, ENDIANNESS_BIG);
237   nvram_system_load( machine, "flash1", &sst39vfx_load, 1);
238   memory_set_bankptr( machine, 2, sst39vfx_get_base());
260   nvram_system_load( machine, "flash1", cybiko_sst39vfx_load, 1);
261   memory_set_bankptr( machine, 2, sst39vfx_get_base(flash2));
239262   // serial port
240263   cybiko_rs232_init();
241264   // other
r4094r4095
274297   // real-time clock
275298   nvram_system_save( machine, "rtc", cybiko_pcf8593_save);
276299   // serial dataflash
277   nvram_system_save( machine, "flash1", &at45dbxx_save);
300   nvram_system_save( machine, "flash1", cybiko_at45dbxx_save);
278301   // serial port
279302   cybiko_rs232_exit();
280303}
r4094r4095
285308   // real-time clock
286309   nvram_system_save( machine, "rtc", cybiko_pcf8593_save);
287310   // serial dataflash
288   nvram_system_save( machine, "flash1", &at45dbxx_save);
311   nvram_system_save( machine, "flash1", cybiko_at45dbxx_save);
289312   // multi-purpose flash
290   nvram_system_save( machine, "flash2", &sst39vfx_save);
313   nvram_system_save( machine, "flash2", cybiko_sst39vfx_save);
291314   // serial port
292315   cybiko_rs232_exit();
293316}
r4094r4095
298321   // real-time clock
299322   nvram_system_save( machine, "rtc", cybiko_pcf8593_save);
300323   // multi-purpose flash
301   nvram_system_save( machine, "flash1", &sst39vfx_save);
324   nvram_system_save( machine, "flash1", cybiko_sst39vfx_save);
302325   // serial port
303326   cybiko_rs232_exit();
304327}
r4094r4095
456479      }
457480      break;
458481      // serial dataflash
459      case H8S_IO_PORT3 : if (at45dbxx_pin_so(space->machine)) data = data | H8S_P3_RXD1; break;
482      case H8S_IO_PORT3 :  {
483            const device_config *device = devtag_get_device(space->machine, AT45DB041, "flash1");
484            if (at45dbxx_pin_so(device)) data = data | H8S_P3_RXD1;
485         }
486         break;
487         
460488      // rs232
461489      case H8S_IO_PORT5 : if (cybiko_rs232_pin_rxd()) data = data | H8S_P5_RXD2; break;
462490      // real-time clock
r4094r4095
489517      // serial dataflash
490518      case H8S_IO_P3DR :
491519      {
492         at45dbxx_pin_cs ( space->machine, (data & H8S_P3_SCK0) ? 0 : 1);
493         at45dbxx_pin_si ( space->machine, (data & H8S_P3_TXD1) ? 1 : 0);
494         at45dbxx_pin_sck( space->machine, (data & H8S_P3_SCK1) ? 1 : 0);
520         const device_config *device = devtag_get_device(space->machine, AT45DB041, "flash1");
521         at45dbxx_pin_cs ( device, (data & H8S_P3_SCK0) ? 0 : 1);
522         at45dbxx_pin_si ( device, (data & H8S_P3_TXD1) ? 1 : 0);
523         at45dbxx_pin_sck( device, (data & H8S_P3_SCK1) ? 1 : 0);
495524      }
496525      break;
497526      // rs232
src/mess/drivers/cybiko.c
r4094r4095
1818//#include "cpu/h8s2xxx/h8s2xxx.h"
1919#include "video/hd66421.h"
2020#include "machine/pcf8593.h"
21
21#include "machine/at45dbxx.h"
22#include "machine/sst39vfx.h"
2223/* Layout */
2324#include "cybiko.lh"
2425
r4094r4095
285286//  MDRV_NVRAM_HANDLER( cybikov1)
286287   /* rtc */
287288   MDRV_PCF8593_ADD("rtc")
289   MDRV_AT45DB041_ADD("flash1")
288290MACHINE_DRIVER_END
289291
290292static MACHINE_DRIVER_START( cybikov2 )
r4094r4095
299301   MDRV_MACHINE_RESET( cybikov2)
300302   // non-volatile ram
301303//  MDRV_NVRAM_HANDLER( cybikov2)
304   MDRV_SST39VF020_ADD("flash2",16, ENDIANNESS_BIG)
302305MACHINE_DRIVER_END
303306
304307static MACHINE_DRIVER_START( cybikoxt )
r4094r4095
316319   MDRV_MACHINE_RESET( cybikoxt)
317320   // non-volatile ram
318321//  MDRV_NVRAM_HANDLER( cybikoxt)
322   MDRV_AT45DB041_REMOVE("flash1")
323   MDRV_SST39VF020_ADD("flash2",16, ENDIANNESS_BIG)
319324MACHINE_DRIVER_END
320325
321326//////////////
docs/messnew.txt
r4094r4095
2727Source Changes:
2828----------------
2929- Changed the DS1315 implementation to be a device.  [Nathan Woods]
30- Changed the AT45DBxx and SST39VFxx to be a device [Miodrag Milanovic]
3031
3132
32
33330.129
3434
3535New System Drivers Supported (in no particular order):

Previous 15994 Revisions Next


© 1998-2018 The MESS Team