Previous 15994 Revisions Next

r10167 Sunday 23rd January, 2011 at 22:24:49 UTC by Tim Schuerewegen
[GBA] Improved NVRAM chip detection by reducing the number of false positives. If more than one NVRAM chip is detected, NVRAM is disabled until someone picks the correct one and adds it to the driver.
[src/mess/drivers]gba.c

src/mess/drivers/gba.c
r10166r10167
23322332   }
23332333}
23342334
2335#define   GBA_CHIP_EEPROM    (1 << 0)
2336#define   GBA_CHIP_SRAM      (1 << 1)
2337#define   GBA_CHIP_FLASH     (1 << 2)
2338#define   GBA_CHIP_FLASH_1M  (1 << 3)
2339#define   GBA_CHIP_RTC       (1 << 4)
2340#define   GBA_CHIP_FLASH_512 (1 << 5)
2341#define   GBA_CHIP_EEPROM_8K (1 << 6)
2342
2343static UINT32 gba_detect_chip( UINT8 *data, int size)
2344{
2345   int i;
2346   UINT32 chip = 0;
2347   for (i = 0; i < size; i++)
2348   {
2349      if (!memcmp(&data[i], "EEPROM_", 7))
2350      {
2351         chip |= GBA_CHIP_EEPROM;
2352      }
2353      else if ((!memcmp(&data[i], "SRAM_", 5))) // || (!memcmp(&data[i], "ADVANCEWARS", 11))) //advance wars 1 & 2 has SRAM, but no "SRAM_" string can be found inside the ROM space
2354      {
2355         chip |= GBA_CHIP_SRAM;
2356      }
2357      else if (!memcmp(&data[i], "FLASH1M_", 8))
2358      {
2359         chip |= GBA_CHIP_FLASH_1M;
2360      }
2361      else if (!memcmp(&data[i], "FLASH512_", 9))
2362      {
2363         chip |= GBA_CHIP_FLASH_512;
2364      }
2365      else if (!memcmp(&data[i], "FLASH_", 6))
2366      {
2367         chip |= GBA_CHIP_FLASH;
2368      }
2369      else if (!memcmp(&data[i], "SIIRTC_V", 8))
2370      {
2371         chip |= GBA_CHIP_RTC;
2372      }
2373   }
2374   return chip;
2375}
2376
23352377static DEVICE_IMAGE_LOAD( gba_cart )
23362378{
23372379   UINT8 *ROM = image.device().machine->region("cartridge")->base();
2338   int i;
23392380   UINT32 cart_size;
23402381   UINT8 game_code[4] = { 0 };
2341   int game_noflash, game_eeprom_large;
2382   UINT32 chip;
23422383   gba_state *state = image.device().machine->driver_data<gba_state>();
23432384
23442385   state->nvsize = 0;
r10166r10167
23612402      memcpy(game_code, ROM + 0xAC, 4);
23622403   }
23632404
2364    // "Backyard Hockey" and "Banjo-Kazooie" false positive for "FLASH"
2365   game_noflash = (!memcmp(game_code, "BYHE", 4)) || (!memcmp(game_code, "BKZE", 4)) || (!memcmp(game_code, "BKZX", 4));
2405   chip = gba_detect_chip( ROM, cart_size);
23662406
2367   // "Bomberman Max 2", "Broken Sword" and "Custom Robo GX" require 14 bit EEPROM addressing
2368   game_eeprom_large = ((!memcmp(game_code, "AMHE", 4)) || (!memcmp(game_code, "AMYJ", 4)) || (!memcmp(game_code, "AMYE", 4))
2369      || (!memcmp(game_code, "AMHP", 4)) || (!memcmp(game_code, "AMHJ", 4)) || (!memcmp(game_code, "AMYP", 4))
2370      || (!memcmp(game_code, "ABJE", 4)) || (!memcmp(game_code, "ABJP", 4)) || (!memcmp(game_code, "ARJJ", 4)));
2407   {
2408      char s[256], *p = s;
2409      if (chip == 0) p += sprintf( p, " NONE");
2410      if (chip & GBA_CHIP_EEPROM) p += sprintf( p, " EEPROM");
2411      if (chip & GBA_CHIP_EEPROM_8K) p += sprintf( p, " EEPROM_8K");
2412      if (chip & GBA_CHIP_FLASH) p += sprintf( p, " FLASH");
2413      if (chip & GBA_CHIP_FLASH_1M) p += sprintf( p, " FLASH_1M");
2414      if (chip & GBA_CHIP_FLASH_512) p += sprintf( p, " FLASH_512");
2415      if (chip & GBA_CHIP_SRAM) p += sprintf( p, " SRAM");
2416      if (chip & GBA_CHIP_RTC) p += sprintf( p, " RTC");
2417      mame_printf_info( "GBA: Detected%s\n", s);
2418   }
23712419
2372   for (i = 0; i < cart_size; i++)
23732420   {
2374      if (!memcmp(&ROM[i], "EEPROM_", 7))
2421      int count = 0;
2422      if (chip & GBA_CHIP_EEPROM) count++;
2423      if (chip & GBA_CHIP_EEPROM_8K) count++;
2424      if (chip & GBA_CHIP_FLASH) count++;
2425      if (chip & GBA_CHIP_FLASH_1M) count++;
2426      if (chip & GBA_CHIP_FLASH_512) count++;
2427      if (chip & GBA_CHIP_SRAM) count++;
2428      if (count > 1)
23752429      {
2376         state->nvptr = (UINT8 *)&state->gba_eeprom;
2377         state->nvsize = 0x2000;
2378
2379         if (game_eeprom_large)
2380         {
2381            state->eeprom_addr_bits = 14;
2382         }
2430         chip &= ~(GBA_CHIP_EEPROM | GBA_CHIP_EEPROM_8K | GBA_CHIP_FLASH | GBA_CHIP_FLASH_1M | GBA_CHIP_FLASH_512 | GBA_CHIP_SRAM);
2431         if      (!memcmp(game_code, "ABFJ", 4)) chip |= GBA_CHIP_SRAM;   // 0059 - Breath of Fire - Ryuu no Senshi (JPN)
2432         else if (!memcmp(game_code, "AHMJ", 4)) chip |= GBA_CHIP_EEPROM; // 0364 - Dai-Mahjong (JPN)
2433         else if (!memcmp(game_code, "A2GJ", 4)) chip |= GBA_CHIP_EEPROM; // 0399 - Advance GT2 (JPN)
2434         else if (!memcmp(game_code, "AK9E", 4)) chip |= GBA_CHIP_EEPROM; // 0479 - Medabots AX - Rokusho Version (USA)
2435         else if (!memcmp(game_code, "AK8E", 4)) chip |= GBA_CHIP_EEPROM; // 0480 - Medabots AX - Metabee Version (USA)
2436         else if (!memcmp(game_code, "AK9P", 4)) chip |= GBA_CHIP_EEPROM; // 0515 - Medabots AX - Rokusho Version (EUR)
2437         else if (!memcmp(game_code, "AGIJ", 4)) chip |= GBA_CHIP_EEPROM; // 0548 - Medarot G - Kuwagata Version (JPN)
2438         else if (!memcmp(game_code, "A3DJ", 4)) chip |= GBA_CHIP_EEPROM; // 0567 - Disney Sports - American Football (JPN)
2439         else if (!memcmp(game_code, "AF7J", 4)) chip |= GBA_CHIP_EEPROM; // 0605 - Tokimeki Yume Series 1 - Ohanaya-san ni Narou! (JPN)
2440         else if (!memcmp(game_code, "AH7J", 4)) chip |= GBA_CHIP_EEPROM; // 0617 - Nakayoshi Pet Advance Series 1 - Kawaii Hamster (JPN)
2441         else if (!memcmp(game_code, "AGHJ", 4)) chip |= GBA_CHIP_EEPROM; // 0620 - Medarot G - Kabuto Version (JPN)
2442         else if (!memcmp(game_code, "AR8E", 4)) chip |= GBA_CHIP_SRAM;   // 0727 - Rocky (USA)
2443         else if (!memcmp(game_code, "ALUE", 4)) chip |= GBA_CHIP_EEPROM; // 0751 - Super Monkey Ball Jr. (USA)
23832444         else
23842445         {
2385            state->eeprom_addr_bits = 6;
2446            mame_printf_warning( "GBA: NVRAM is disabled because multiple NVRAM chips were detected!\n");
23862447         }
2448      }
2449   }
23872450
2388         if (cart_size <= (16 * 1024 * 1024))
2389         {
2390            memory_install_read32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_r);
2391            memory_install_write32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_w);
2392         }
2393         else
2394         {
2395            memory_install_read32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_r);
2396            memory_install_write32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_w);
2397         }
2398         break;
2399      }
2400      else if ((!memcmp(&ROM[i], "SRAM_", 5)) || (!memcmp(&ROM[i], "ADVANCEWARS", 11))) //advance wars 1 & 2 has SRAM, but no "SRAM_" string can be found inside the ROM space
2451   // "Bomberman Max 2", "Broken Sword", "Custom Robo GX" and "Classic NES Series - Excitebike" require 14 bit EEPROM addressing
2452   if (chip & GBA_CHIP_EEPROM)
2453   {
2454      if ((!memcmp(game_code, "AMHE", 4)) || (!memcmp(game_code, "AMYJ", 4)) || (!memcmp(game_code, "AMYE", 4))
2455         || (!memcmp(game_code, "AMHP", 4)) || (!memcmp(game_code, "AMHJ", 4)) || (!memcmp(game_code, "AMYP", 4))
2456         || (!memcmp(game_code, "ABJE", 4)) || (!memcmp(game_code, "ABJP", 4)) || (!memcmp(game_code, "ARJJ", 4))
2457         || (!memcmp(game_code, "FEBE", 4)))
24012458      {
2402         state->nvptr = (UINT8 *)&state->gba_sram;
2403         state->nvsize = 0x10000;
2404
2405         memory_install_read32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_r);
2406         memory_install_write32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_w);
2407         break;
2459         chip = (chip & ~GBA_CHIP_EEPROM) | GBA_CHIP_EEPROM_8K;
24082460      }
2409      else if (!memcmp(&ROM[i], "FLASH1M_", 8))
2410      {
2411         state->nvptr = NULL;
2412         state->nvsize = 0;
2413         state->flash_size = 0x20000;
2414         state->flash_mask = 0x1ffff/4;
2461   }
24152462
2416         memory_install_read32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe01ffff, 0, 0, flash_r);
2417         memory_install_write32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe01ffff, 0, 0, flash_w);
2418         break;
2419      }
2420      else if ((!memcmp(&ROM[i], "FLASH", 5)) && (!game_noflash))
2463   if ((chip & GBA_CHIP_EEPROM) || (chip & GBA_CHIP_EEPROM_8K))
2464   {
2465      state->nvptr = (UINT8 *)&state->gba_eeprom;
2466      state->nvsize = 0x2000;
2467
2468      state->eeprom_addr_bits = (chip & GBA_CHIP_EEPROM_8K) ? 14 : 6;
2469
2470      if (cart_size <= (16 * 1024 * 1024))
24212471      {
2422         state->nvptr = NULL;
2423         state->nvsize = 0;
2424         state->flash_size = 0x10000;
2425         state->flash_mask = 0xffff/4;
2426
2427         memory_install_read32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, flash_r);
2428         memory_install_write32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, flash_w);
2429         break;
2472         memory_install_read32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_r);
2473         memory_install_write32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_w);
24302474      }
2431      else if (!memcmp(&ROM[i], "SIIRTC_V", 8))
2475      else
24322476      {
2433         mame_printf_verbose("game has RTC\n");
2434         break;
2477         memory_install_read32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_r);
2478         memory_install_write32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_w);
24352479      }
24362480   }
24372481
2482   if (chip & GBA_CHIP_SRAM)
2483   {
2484      state->nvptr = (UINT8 *)&state->gba_sram;
2485      state->nvsize = 0x10000;
2486
2487      memory_install_read32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_r);
2488      memory_install_write32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_w);
2489   }
2490
2491   if (chip & GBA_CHIP_FLASH_1M)
2492   {
2493      state->nvptr = NULL;
2494      state->nvsize = 0;
2495      state->flash_size = 0x20000;
2496      state->flash_mask = 0x1ffff/4;
2497
2498      memory_install_read32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe01ffff, 0, 0, flash_r);
2499      memory_install_write32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe01ffff, 0, 0, flash_w);
2500   }
2501
2502   if ((chip & GBA_CHIP_FLASH) || (chip & GBA_CHIP_FLASH_512))
2503   {
2504      state->nvptr = NULL;
2505      state->nvsize = 0;
2506      state->flash_size = 0x10000;
2507      state->flash_mask = 0xffff/4;
2508
2509      memory_install_read32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, flash_r);
2510      memory_install_write32_handler(cpu_get_address_space(image.device().machine->device("maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, flash_w);
2511   }
2512
2513   if (chip & GBA_CHIP_RTC)
2514   {
2515      mame_printf_verbose("game has RTC\n");
2516   }
2517
24382518   // if save media was found, reload it
24392519   if (state->nvsize > 0)
24402520   {

Previous 15994 Revisions Next


© 1998-2018 The MESS Team