Previous 15994 Revisions Next

r8143 Sunday 23rd May, 2010 at 00:35:13 UTC by R. Belmont
[GBA] Use core flash emulation for GBA flash saves; extend core to support GBA chip types.
[src/emu/machine]intelfsh.c intelfsh.h
[src/mess/drivers]gba.c
[src/mess/includes]gba.h

src/emu/machine/intelfsh.c
r8142r8143
3939   int bits;
4040   int status;
4141   int erase_sector;
42   int sector_is_4k;
4243   INT32 flash_mode;
4344   INT32 flash_master_lock;
4445   int device_id;
r8142r8143
8990   c = &chips[ chip ];
9091
9192   c->type = type;
93   c->sector_is_4k = 0;
9294   switch( c->type )
9395   {
9496   case FLASH_INTEL_28F016S5:
r8142r8143
135137      c->maker_id = 0xc2;
136138      c->device_id = 0x51;
137139      break;
140
141   case FLASH_PANASONIC_MN63F805MNP:
142      c->bits = 8;
143      c->size = 0x10000;
144      c->maker_id = 0x32;
145      c->device_id = 0x1b;
146      c->sector_is_4k = 1;
147      break;
148
149   case FLASH_SANYO_LE26FV10N1TS:
150      c->bits = 8;
151      c->size = 0x20000;
152      c->maker_id = 0x62;
153      c->device_id = 0x13;
154      c->sector_is_4k = 1;
155      break;
138156   }
139157   if( data == NULL )
140158   {
r8142r8143
248266      break;
249267   }
250268
251//  logerror( "%s: intelflash_read( %d, %08x ) %08x\n", cpuexec_describe_context(machine), chip, address, data );
269//   logerror( "intelflash_read( %d, %08x ) %08x\n", chip, address, data );
252270
253271   return data;
254272}
r8142r8143
263281   }
264282   c = &chips[ chip ];
265283
266//  logerror( "%s: intelflash_write( %d, %08x, %08x )\n", cpuexec_describe_context(machine), chip, address, data );
284//   logerror( "intelflash_write( %d, %08x, %08x )\n", chip, address, data );
267285
268286   switch( c->flash_mode )
269287   {
r8142r8143
298316         c->flash_mode = FM_READSTATUS;
299317         break;
300318      case 0xaa:   // AMD ID select part 1
301         if( ( address & 0xffff ) == 0x555 )
319         if( ( address & 0xfff ) == 0x555 )
302320         {
303321            c->flash_mode = FM_READAMDID1;
304322         }
r8142r8143
313331      {
314332         c->flash_mode = FM_READAMDID2;
315333      }
334      else if( ( address & 0xffff ) == 0x2aaa && ( data & 0xff ) == 0x55 )
335      {
336         c->flash_mode = FM_READAMDID2;
337      }
316338      else
317339      {
318340         logerror( "unexpected %08x=%02x in FM_READAMDID1\n", address, data & 0xff );
r8142r8143
324346      {
325347         c->flash_mode = FM_READAMDID3;
326348      }
349      else if( ( address & 0xffff ) == 0x5555 && ( data & 0xff ) == 0x90 )
350      {
351         c->flash_mode = FM_READAMDID3;
352      }
327353      else if( ( address & 0xffff ) == 0x555 && ( data & 0xff ) == 0x80 )
328354      {
329355         c->flash_mode = FM_ERASEAMD1;
330356      }
357      else if( ( address & 0xffff ) == 0x5555 && ( data & 0xff ) == 0x80 )
358      {
359         c->flash_mode = FM_ERASEAMD1;
360      }
331361      else if( ( address & 0xffff ) == 0x555 && ( data & 0xff ) == 0xa0 )
332362      {
333363         c->flash_mode = FM_BYTEPROGRAM;
334364      }
365      else if( ( address & 0xffff ) == 0x5555 && ( data & 0xff ) == 0xa0 )
366      {
367         c->flash_mode = FM_BYTEPROGRAM;
368      }
335369      else if( ( address & 0xffff ) == 0x555 && ( data & 0xff ) == 0xf0 )
336370      {
337371         c->flash_mode = FM_NORMAL;
338372      }
373      else if( ( address & 0xffff ) == 0x5555 && ( data & 0xff ) == 0xf0 )
374      {
375         c->flash_mode = FM_NORMAL;
376      }
339377      else
340378      {
341379         logerror( "unexpected %08x=%02x in FM_READAMDID2\n", address, data & 0xff );
r8142r8143
343381      }
344382      break;
345383   case FM_ERASEAMD1:
346      if( ( address & 0xffff ) == 0x555 && ( data & 0xff ) == 0xaa )
384      if( ( address & 0xfff ) == 0x555 && ( data & 0xff ) == 0xaa )
347385      {
348386         c->flash_mode = FM_ERASEAMD2;
349387      }
r8142r8143
357395      {
358396         c->flash_mode = FM_ERASEAMD3;
359397      }
398      else if( ( address & 0xffff ) == 0x2aaa && ( data & 0xff ) == 0x55 )
399      {
400         c->flash_mode = FM_ERASEAMD3;
401      }
360402      else
361403      {
362404         logerror( "unexpected %08x=%02x in FM_ERASEAMD2\n", address, data & 0xff );
363405      }
364406      break;
365407   case FM_ERASEAMD3:
366      if( ( address & 0xffff ) == 0x555 && ( data & 0xff ) == 0x10 )
408      if( ( address & 0xfff ) == 0x555 && ( data & 0xff ) == 0x10 )
367409      {
368410         // chip erase
369411         memset( c->flash_memory, 0xff, c->size);
r8142r8143
376418      else if( ( data & 0xff ) == 0x30 )
377419      {
378420         // sector erase
379         // clear the 64k block containing the current address to all 0xffs
421         // clear the 4k/64k block containing the current address to all 0xffs
380422         switch( c->bits )
381423         {
382424         case 8:
383425            {
384426               UINT8 *flash_memory = (UINT8 *)c->flash_memory;
385               memset( &flash_memory[ address & ~0xffff ], 0xff, 64 * 1024 );
386               c->erase_sector = address & ~0xffff;
427               if (c->sector_is_4k)
428               {
429                  memset( &flash_memory[ address & ~0xfff ], 0xff, 4 * 1024 );
430                  c->erase_sector = address & ~0xfff;
431               }
432               else
433               {
434                  memset( &flash_memory[ address & ~0xffff ], 0xff, 64 * 1024 );
435                  c->erase_sector = address & ~0xffff;
436               }
387437            }
388438            break;
389439         case 16:
390440            {
391441               UINT16 *flash_memory = (UINT16 *)c->flash_memory;
392               memset( &flash_memory[ address & ~0x7fff ], 0xff, 64 * 1024 );
393               c->erase_sector = address & ~0x7fff;
442               if (c->sector_is_4k)
443               {
444                   memset( &flash_memory[ address & ~0x7ff ], 0xff, 4 * 1024 );
445                  c->erase_sector = address & ~0x7ff;
446               }
447               else
448               {
449                   memset( &flash_memory[ address & ~0x7fff ], 0xff, 64 * 1024 );
450                  c->erase_sector = address & ~0x7fff;
451               }
394452            }
395453            break;
396454         }
src/emu/machine/intelfsh.h
r8142r8143
1616#define FLASH_INTEL_E28F400 ( 6 )
1717#define FLASH_SHARP_UNK128MBIT ( 7 )
1818#define FLASH_MACRONIX_29L001MC ( 8 )
19#define FLASH_PANASONIC_MN63F805MNP ( 9 )
20#define FLASH_SANYO_LE26FV10N1TS ( 10 )
1921
2022extern void intelflash_init( running_machine *machine, int chip, int type, void *data );
2123extern UINT32 intelflash_read( int chip, UINT32 address );
src/mess/includes/gba.h
r8142r8143
118118#define TILEOBJ_VFLIP         0x0800
119119#define TILEOBJ_PALETTE         0xf000
120120
121// states for carts with flash saves
122121enum
123122{
124    FLASH_IDLEBYTE0,
125    FLASH_IDLEBYTE1,
126    FLASH_IDLEBYTE2,
127    FLASH_IDENT,
128    FLASH_ERASEBYTE0,
129    FLASH_ERASEBYTE1,
130    FLASH_ERASEBYTE2,
131    FLASH_ERASE_ALL,
132    FLASH_ERASE_4K,
133    FLASH_WRITE
134};
135
136enum
137{
138123   EEP_IDLE,
139124   EEP_COMMAND,
140125   EEP_ADDR,
r8142r8143
200185   UINT32 gba_sram[0x10000/4];
201186   UINT8 gba_eeprom[0x2000];
202187   UINT32 gba_flash[0x20000/4];
203   UINT32 flash_size;   // 64k or 128k
204   UINT8 flash_state;
205   UINT8 flash_page;
206   UINT16 flash_id;
188   UINT32 flash_size;
189   UINT32 flash_mask;
207190   int eeprom_state, eeprom_command, eeprom_count, eeprom_addr, eeprom_bits;
208191   UINT8 eep_data;
209192
src/mess/drivers/gba.c
r8142r8143
2323#include "includes/gba.h"
2424#include "includes/gb.h"
2525#include "sound/dac.h"
26#include "machine/intelfsh.h"
2627
27#define VERBOSE_LEVEL   (2)
28#define VERBOSE_LEVEL   (0)
2829
2930INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...)
3031{
r8142r8143
20102011
20112012   memset(state, 0, sizeof(state));
20122013   state->SOUNDBIAS = 0x0200;
2013   state->flash_state = FLASH_IDLEBYTE0;
20142014   state->eeprom_state = EEP_IDLE;
20152015   state->SIOMULTI0 = 0xffff;
20162016   state->SIOMULTI1 = 0xffff;
r8142r8143
21072107   COMBINE_DATA(&state->gba_sram[offset]);
21082108}
21092109
2110/*static const char *flash_states[] =
2111{
2112   "IDLEBYTE0", "IDLEBYTE1", "IDLEBYTE2", "IDENT",
2113   "ERASEBYTE0", "ERASEBYTE1", "ERASEBYTE2", "ERASE_ALL", "ERASE_4K", "WRITE"
2114};*/
2115
21162110static READ32_HANDLER( flash_r )
21172111{
2118   UINT32 rv;
2119   
21202112   gba_state *state = (gba_state *)space->machine->driver_data;
2113   UINT32 rv;
21212114
2122   switch (state->flash_state)
2123   {
2124      case FLASH_IDENT:
2125         if (offset == 0)
2126            rv = (state->gba_flash[0] & 0xffff0000) | state->flash_id;
2127         else
2128            rv = state->gba_flash[offset];
2129            break;
2115   rv = 0;
2116   offset &= state->flash_mask;
2117   if (mem_mask & 0xff) rv |= intelflash_read(0, offset*4);
2118   if (mem_mask & 0xff00) rv |= intelflash_read(0, (offset*4)+1)<<8;
2119   if (mem_mask & 0xff0000) rv |= intelflash_read(0, (offset*4)+2)<<16;
2120   if (mem_mask & 0xff000000) rv |= intelflash_read(0, (offset*4)+3)<<24;
21302121
2131      default:
2132         rv = state->gba_flash[offset];
2133         break;
2134   }
2135
2136//   printf("flash_r: @ %x (mask %x) (state %s) (PC=%x) = %x\n", offset, mem_mask, flash_states[state->flash_state], cpu_get_pc(space->cpu), rv&mem_mask);
2137
21382122   return rv;
21392123}
21402124
r8142r8143
21422126{
21432127   gba_state *state = (gba_state *)space->machine->driver_data;
21442128
2145//   printf("flash_w: %x @ %x (mask %x) (state=%s) (PC=%x)\n", data, offset, mem_mask, flash_states[state->flash_state], cpu_get_pc(space->cpu));
2146
2147   switch (state->flash_state)
2129   offset &= state->flash_mask;
2130   switch (mem_mask)
21482131   {
2149      case FLASH_IDLEBYTE0:
2150      case FLASH_ERASEBYTE0:
2151         if (offset == 0x5555/4 && mem_mask == 0xff00)
2152         {
2153            if ((data & mem_mask) == 0x0000aa00)
2154            {
2155               if (state->flash_state == FLASH_ERASEBYTE0)
2156               {
2157                  state->flash_state = FLASH_ERASEBYTE1;
2158               }
2159               else
2160               {
2161                  state->flash_state = FLASH_IDLEBYTE1;
2162               }
2163            }
2164         }
2132      case 0xff:
2133         intelflash_write(0, offset*4, data&0xff);
21652134         break;
2166      case FLASH_IDLEBYTE1:
2167      case FLASH_ERASEBYTE1:
2168         if (offset == 0x2aaa/4 && mem_mask == 0xff0000)
2169         {
2170            if ((data & mem_mask) == 0x00550000)
2171            {
2172               if (state->flash_state == FLASH_IDLEBYTE1)
2173                  state->flash_state = FLASH_IDLEBYTE2;
2174               else if (state->flash_state == FLASH_ERASEBYTE1)
2175                  state->flash_state = FLASH_ERASEBYTE2;
2176            }
2177         }
2135      case 0xff00:
2136         intelflash_write(0, (offset*4)+1, (data>>8)&0xff);
21782137         break;
2179      case FLASH_IDLEBYTE2:
2180      case FLASH_ERASEBYTE2:
2181         if (offset == 0x5555/4 && mem_mask == 0xff00)
2182         {
2183            if (state->flash_state == FLASH_IDLEBYTE2)
2184            {
2185               switch ((data & mem_mask) >> 8)
2186               {
2187               case 0x80:
2188                  state->flash_state = FLASH_ERASEBYTE0;
2189                  break;
2190               case 0x90:
2191                  state->flash_state = FLASH_IDENT;
2192                  break;
2193                case 0xa0:
2194                  state->flash_state = FLASH_WRITE;
2195                  break;
2196               }
2197            }
2198            else if (state->flash_state == FLASH_ERASEBYTE2)
2199            {
2200               if ((data & mem_mask) == 0x00001000)
2201               {
2202                  UINT32 flashWord;
2203                  for (flashWord = 0; flashWord < state->flash_size/4; flashWord++)
2204                  {
2205                     state->gba_flash[flashWord] = 0xffffffff;
2206                  }
2207                  state->flash_state = FLASH_ERASE_ALL;
2208               }
2209            }
2210         }
2211         else if ((offset & 0xffffc3ff) == 0 && (data & mem_mask) == 0x00000030)
2212         {
2213            UINT32 flashWord;
2214            state->flash_page = offset >> 10;
2215            for (flashWord = offset; flashWord < offset + 0x1000/4; flashWord++)
2216            {
2217               state->gba_flash[flashWord] = 0xffffffff;
2218            }
2219            state->flash_state = FLASH_ERASE_4K;
2220         }
2138      case 0xff0000:
2139         intelflash_write(0, (offset*4)+2, (data>>16)&0xff);
22212140         break;
2222      case FLASH_IDENT:
2223         // Hack; any sensibly-written game should follow up with the relevant read, which will reset the state to FLASH_IDLEBYTE0.
2224         state->flash_state = FLASH_IDLEBYTE0;
2225         flash_w(space, offset, data, mem_mask);
2141      case 0xff000000:
2142         intelflash_write(0, (offset*4)+3, (data>>24)&0xff);
22262143         break;
2227      case FLASH_ERASE_4K:
2228         // Hack; any sensibly-written game should follow up with the relevant read, which will reset the state to FLASH_IDLEBYTE0.
2229         state->flash_state = FLASH_IDLEBYTE0;
2230         flash_w(space, offset, data, mem_mask);
2144      default:
2145         fatalerror("Unknown mem_mask for GBA flash_w %x\n", mem_mask);
22312146         break;
2232      case FLASH_ERASE_ALL:
2233         // Hack; any sensibly-written game should follow up with the relevant read, which will reset the state to FLASH_IDLEBYTE0.
2234         state->flash_state = FLASH_IDLEBYTE0;
2235         flash_w(space, offset, data, mem_mask);
2236         break;
2237      case FLASH_WRITE:
2238         COMBINE_DATA(&state->gba_flash[offset]);
2239         state->flash_state = FLASH_IDLEBYTE0;
2240         break;
22412147   }
22422148}
22432149
r8142r8143
23932299   gba_state *state = (gba_state *)image->machine->driver_data;
23942300
23952301   state->nvsize = 0;
2302   state->flash_size = 0;
23962303   state->nvptr = (UINT8 *)NULL;
23972304
23982305   if (image_software_entry(image) == NULL)
r8142r8143
24392346         state->nvptr = (UINT8 *)&state->gba_flash;
24402347         state->nvsize = 0x20000;
24412348         state->flash_size = 0x20000;
2442         state->flash_id = 0x1362;
2349         state->flash_mask = 0x1ffff/4;
24432350
24442351         memory_install_read32_handler(cpu_get_address_space(devtag_get_device(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe01ffff, 0, 0, flash_r);
24452352         memory_install_write32_handler(cpu_get_address_space(devtag_get_device(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe01ffff, 0, 0, flash_w);
r8142r8143
24502357         state->nvptr = (UINT8 *)&state->gba_flash;
24512358         state->nvsize = 0x10000;
24522359         state->flash_size = 0x10000;
2453         state->flash_id = 0x1b32;
2360         state->flash_mask = 0xffff/4;
24542361
2455         memory_install_read32_handler(cpu_get_address_space(devtag_get_device(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash_r);
2456         memory_install_write32_handler(cpu_get_address_space(devtag_get_device(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash_w);
2362         memory_install_read32_handler(cpu_get_address_space(devtag_get_device(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, flash_r);
2363         memory_install_write32_handler(cpu_get_address_space(devtag_get_device(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, flash_w);
24572364         break;
24582365      }
24592366      else if (!memcmp(&ROM[i], "SIIRTC_V", 8))
r8142r8143
24752382      state->nvsize = 0;
24762383   }
24772384
2385   // init the flash here so it gets the contents from the battery_load above
2386   if (state->flash_size > 0)
2387   {
2388      if (state->flash_size == 0x10000)
2389      {
2390         intelflash_init(image->machine, 0, FLASH_PANASONIC_MN63F805MNP, &state->gba_flash);
2391      }
2392      else
2393      {
2394         intelflash_init(image->machine, 0, FLASH_SANYO_LE26FV10N1TS, &state->gba_flash);
2395      }
2396   }
2397
24782398   // mirror the ROM
24792399   switch (cart_size)
24802400   {

Previous 15994 Revisions Next


© 1998-2018 The MESS Team