Previous 15994 Revisions Next

r7795 Monday 12th April, 2010 at 15:54:07 UTC by Angelo Salese
Added fill parameter to image_battery_load / image_battery_load_by_name, and fixed SNES NVRAM fill to be 1, fixes Super Drift Out SRAM data
[src/mess]image.c image.h
[src/mess/devices]multcart.c ti99cart.c
[src/mess/drivers]gba.c
[src/mess/machine]gb.c genesis.c nes.c sms.c snescart.c wswan.c

src/mess/devices/ti99cart.c
r7794r7795
2929{
3030   /* PCB device associated to this cartridge. If NULL, the slot is empty. */
3131   running_device *pcb;
32   
32
3333        /* GROM buffer size. */
3434        int grom_size;
35       
35
3636        /* ROM page. */
3737        int rom_page;
3838        /* RAM page. */
3939        int ram_page;
40       
40
4141        /* ROM buffer size. All banks have equal sizes. */
4242        int rom_size;
4343        /* RAM buffer size. All banks have equal sizes. */
4444        int ram_size;
45       
45
4646        /* pointer to GROM data. */
4747        UINT8 *grom_ptr;
48       
48
4949        /* GROM buffered data output. */
5050        /*        UINT8 grom_buffer; */ /* Now handled by the multicart system. */
51       
51
5252        /* ROM buffer. We are using this for both 16 bit (99/4a) and 8 bit
5353        (99/8) access. */
5454        void *rom_ptr;
55       
55
5656        /* ROM buffer for the second bank of paged cartridges. Other cartridges
5757        usually store their ROM in one large file. */
5858        void *rom2_ptr;
59       
59
6060        /* RAM buffer. The persistence service is done by the cartridge system.
6161        The RAM space is a consecutive space; all banks are in one buffer. */
6262        void *ram_ptr;
r7794r7795
8989   /* Reserves space for all cartridges. This is also used in the legacy
9090   cartridge system, but only for slot 0. */
9191   cartridge_t cartridge[NUMBER_OF_CARTRIDGE_SLOTS];
92   
92
9393   /* Determines which slot is currently active. This value is changed when there
9494   are accesses to other GROM base addresses. */
9595   int active_slot;
96   
96
9797   /* Used in order to enforce a special slot. This value is retrieved
9898   from the dipswitch setting. A value of -1 means automatic, that is,
9999   the grom base switch is used. Values 0 .. max refer to the
100100   respective slot. */
101101   int fixed_slot;
102   
102
103103   /* Holds the highest index of a cartridge being plugged in plus one.
104104   If we only have one cartridge inserted, we don't want to get a
105105   selection option, so we just mirror the memory contents. */
106106   int next_free_slot;
107   
107
108108   /* Counts the number of slots which currently contain legacy format
109109   cartridge images. */
110110   int legacy_slots;
111   
111
112112   /* Counts the number of slots which currently contain new format
113113   cartridge images. */
114114   int multi_slots;
115   
115
116116   /* Legacy mode. Stores the slot number where the cartridge part is mounted.
117117   Index is from slotc_type_t. */
118118   int legacy_slotnumber[5];
119   
119
120120   /* current address pointer for the active GROM in port (16 bits) */
121121   UINT16 grom_address;
122122   /* GROM data buffer */
r7794r7795
290290      systems, i.e. it should be shifted left by 1.
291291      // 1001 1wbb bbbb bbr0
292292   */
293   cartridge_slot_set(device, (offset>>2) & 0x00ff);   
294   
295   if (offset & 0x0002)
293   cartridge_slot_set(device, (offset>>2) & 0x00ff);
294
295   if (offset & 0x0002)
296296      grom_write_address(cartslots, data);
297297   else
298298      cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
299      /* TODO: write to GRAM */   
299      /* TODO: write to GRAM */
300300}
301301
302302/*
r7794r7795
309309   /* When reading, reset the hi/lo flag byte for writing.
310310   TODO: Verify this with a real machine. */
311311   cartslots->waddr_LSB = FALSE;
312   
312
313313   /* Address reading is done in two steps; first, the high byte
314314   is transferred, then the low byte. */
315315   if (cartslots->raddr_LSB)
r7794r7795
352352      systems, i.e. it should be shifted left by 1.
353353      1001 1wbb bbbb bbr0
354354   */
355   cartridge_slot_set(device, (offset>>2) & 0x00ff);   
356   
357   if (offset & 0x0002)
355   cartridge_slot_set(device, (offset>>2) & 0x00ff);
356
357   if (offset & 0x0002)
358358      return grom_read_address(cartslots);
359359
360360   /* Handle the legacy mode. */
r7794r7795
370370      one cartridge, this entails that the second cartridge is
371371      different (all zeros), and so we get a meaningless selection
372372      option between cartridge 1 and 1 and 1 ...
373     
373
374374      So if next_free_slot==1, we have one cartridge in slot 0.
375375      In that case we trick the OS to believe that the addressed
376376      cartridge appears at all locations which causes it to assume a
r7794r7795
391391         /* TODO: replace this using a bitmap of the available GROMs */
392392         if ((cartslots->grom_address < 0x6000) || (cartslots->grom_address > (cartridge->grom_size+0x6000)))
393393            value = 0;
394         else
394         else
395395         {
396396            /* Buffered GROM access. We use a (virtual) common buffer to avoid implementing this for each cartridge. */
397397            value = (UINT8)cartslots->grom_buffer;
r7794r7795
409409      /* The program counter wraps at each GROM chip size (8K),
410410      so 0x5fff + 1 = 0x4000. */
411411      cartslots->grom_address = ((cartslots->grom_address + 1) & 0x1FFF) | (cartslots->grom_address & 0xE000);
412     
412
413413      /* Reset the read and write address flipflops. */
414414      cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
415415   }
r7794r7795
441441   cartridge_t *cartridge;
442442   running_device *cartsys = cartslot->owner;
443443   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
444   
444
445445   void *socketcont;
446446   int reslength;
447447   int i;
448   
448
449449   int slotnumber = get_index_from_tagname(cartslot)-1;
450450   assert(slotnumber>=0 && slotnumber<NUMBER_OF_CARTRIDGE_SLOTS);
451   
451
452452   /* There is a cartridge in this slot, check the maximum slot number. */
453453   if (cartslots->next_free_slot <= slotnumber)
454454   {
455455      cartslots->next_free_slot = slotnumber+1;
456456   }
457457   cartridge = &cartslots->cartridge[slotnumber];
458   
458
459459   /* Get the socket which is retrieved by the multicart instance in
460460   the state of the cartslot instance. */
461461   socketcont = cartslot_get_socket(cartslot, "grom_socket");
r7794r7795
465465      cartridge->grom_ptr = (UINT8 *)socketcont;
466466      cartridge->grom_size = reslength;
467467   }
468   
468
469469   socketcont = cartslot_get_socket(cartslot, "rom_socket");
470470   reslength = cartslot_get_resource_length(cartslot, "rom_socket");
471471   if (socketcont != NULL)
r7794r7795
480480            cont16b[i] = BIG_ENDIANIZE_INT16(cont16b[i]);
481481      }
482482   }
483   
483
484484   socketcont = cartslot_get_socket(cartslot, "rom2_socket");
485485//  reslength = cartslot_get_resource_length(cartslot, "rom2_socket");  /* cannot differ from rom_socket */
486486   if (socketcont != NULL)
r7794r7795
20132013         /* If we are here, we have a multicart. */
20142014         ti99_pcb_t *pcb = (ti99_pcb_t *)pcbdev->token;
20152015         cartslot_t *cart = (cartslot_t *)image->token;
2016         
2016
20172017         /* try opening this as a multicart */
20182018         /* This line requires that cartslot_t be included in cartslot.h,
20192019         otherwise one cannot make use of multicart handling within such a
20202020         custom LOAD function. */
20212021         multicart_open_error me = multicart_open(image_filename(image), image->machine->gamedrv->name, MULTICART_FLAGS_LOAD_RESOURCES, &cart->mc);
2022         
2022
20232023         /* Now that we have loaded the image files, let the PCB put them all
20242024         together. This means we put the images in a structure which allows
20252025         for a quick access by the memory handlers. Every PCB defines an
r7794r7795
20282028            result = pcb->assemble(image);
20292029         else
20302030            fatalerror("Error loading multicart: %s\n", multicart_error_text(me));
2031         
2031
20322032         /* This is for legacy support. If we have no multicart left
20332033         but there are still legacy dumps, we switch to legacy mode. */
20342034         if (result != INIT_FAIL)
r7794r7795
21312131      access beyond the image size must be detected. */
21322132      if ((cartslots->grom_address < 0x6000) || (cartslots->grom_address > (cartridge->grom_size+0x6000)))
21332133         return 0;
2134     
2134
21352135      value =  (UINT8)cartslots->grom_buffer;
21362136      /* read ahead */
21372137      cartslots->grom_buffer = cartridge->grom_ptr[cartslots->grom_address-0x6000];
r7794r7795
21392139      /* The program counter wraps at each GROM chip size (8K),
21402140      so 0x5fff + 1 = 0x4000. */
21412141      cartslots->grom_address = ((cartslots->grom_address + 1) & 0x1FFF) | (cartslots->grom_address & 0xE000);
2142     
2142
21432143      /* Reset the read and write address flipflops. */
21442144      cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
21452145   }
r7794r7795
25142514         if (ti99_is_99_8())
25152515         {
25162516            // printf("** is 99/8\n");
2517            image_battery_load(image, cart8rom+0x1000,0x1000);
2517            image_battery_load(image, cart8rom+0x1000,0x1000, 0x00);
25182518            cartslots->cartridge[id].ram_ptr = cart8rom +  0x1000;
25192519         }
25202520         else
25212521         {
2522            image_battery_load(image, cartrom+0x800,0x1000);
2522            image_battery_load(image, cartrom+0x800,0x1000, 0x00);
25232523            for (i = 0x800; i < 0x1000; i++)
25242524               cartrom[i] = BIG_ENDIANIZE_INT16(cartrom[i]);
25252525            cartslots->cartridge[id].ram_ptr = (UINT16 *)cartrom +  0x800;
r7794r7795
25332533         if (ti99_is_99_8())
25342534         {
25352535            // printf("** is 99/8\n");
2536            image_battery_load(image, cart8rom+0x0c00, 0x0400);
2536            image_battery_load(image, cart8rom+0x0c00, 0x0400, 0x00);
25372537            cartslots->cartridge[id].ram_ptr = cart8rom +  0xc00;
25382538         }
25392539         else
25402540         {
2541            image_battery_load(image, cartrom+0x0600, 0x0400);
2541            image_battery_load(image, cartrom+0x0600, 0x0400, 0x00);
25422542            for (i = 0x0600; i < 0x0800; i++)
25432543               cartrom[i] = BIG_ENDIANIZE_INT16(cartrom[i]);
25442544            cartslots->cartridge[id].ram_ptr = (UINT16 *)cartrom +  0x600;
r7794r7795
27092709
27102710   /* Allows to manually lock the cartslot system to a specific slot.
27112711      We take slot numbers from 0 (automatic mode) to the maximum. */
2712   
2712
27132713   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
27142714   int slotnumber = (input_port_read(device->machine, "CFG") >> config_cartslot_bit) & config_cartslot_mask;
27152715   assert(slotnumber>=0 && slotnumber<=255);
r7794r7795
27342734   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
27352735   int slot = cartslots->active_slot;
27362736   cartridge_t *cart;
2737   
2737
27382738   /* Sanity check. Higher slots are always empty. */
27392739   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
27402740      return 0;
2741   
2741
27422742   /* Same as above (GROM read): If there is only one cartridge there
27432743   is no use of trying other banks. There is one issue with the
27442744   selection mechanism: When the console probes the GROM banks and
r7794r7795
27492749   around this with the following line. */
27502750   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
27512751      slot=0;
2752   
2752
27532753   cart = &cartslots->cartridge[slot];
2754   
2754
27552755   /* Idle the CPU */
27562756        cpu_adjust_icount(devtag_get_device(device->machine, "maincpu"),-4);
2757       
2757
27582758   // Alternatively:
27592759   // cpu_spinuntil_time(device->machine->firstcpu, ATTOTIME_IN_USEC(6));
2760   
2760
27612761   //  printf("rpk = %d, bin = %d\n", cartslots->multi_slots,cartslots->legacy_slots);
2762   
2762
27632763   /* Handle legacy mode. */
27642764   if (in_legacy_mode(device))
27652765   {
27662766      return ti99_cart_r_legacy(device, offset, mem_mask);
27672767   }
2768   
2768
27692769   if (!slot_is_empty(device, slot))
27702770   {
27712771      //      printf("accessing cartridge in slot %d\n", slot);
src/mess/devices/multcart.c
r7794r7795
257257         if (resource->filename == NULL)
258258            return MCERR_OUT_OF_MEMORY;
259259
260         image_battery_load_by_name(resource->filename, resource->ptr, resource->length);
260         image_battery_load_by_name(resource->filename, resource->ptr, resource->length, 0x00);
261261      }
262262      /* else this type is volatile, in which case we just have
263263            a memory expansion */
src/mess/image.c
r7794r7795
18301830    to the function.
18311831-------------------------------------------------*/
18321832
1833void image_battery_load_by_name(const char *filename, void *buffer, int length)
1833void image_battery_load_by_name(const char *filename, void *buffer, int length, int fill)
18341834{
18351835    file_error filerr;
18361836    mame_file *file;
r7794r7795
18471847    }
18481848
18491849    /* fill remaining bytes (if necessary) */
1850    memset(((char *) buffer) + bytes_read, '\0', length - bytes_read);
1850    memset(((char *) buffer) + bytes_read, fill, length - bytes_read);
18511851}
18521852
18531853
r7794r7795
18581858    image name.
18591859-------------------------------------------------*/
18601860
1861void image_battery_load(running_device *image, void *buffer, int length)
1861void image_battery_load(running_device *image, void *buffer, int length, int fill)
18621862{
18631863    char *basename_noext;
18641864    astring *fname;
r7794r7795
18691869
18701870    fname = astring_assemble_4(astring_alloc(), image->machine->gamedrv->name, PATH_SEPARATOR, basename_noext, ".nv");
18711871
1872    image_battery_load_by_name(astring_c(fname), buffer, length);
1872    image_battery_load_by_name(astring_c(fname), buffer, length, fill);
18731873    astring_free(fname);
18741874    free(basename_noext);
18751875}
src/mess/image.h
r7794r7795
306306  image; typically for cartridges.
307307****************************************************************************/
308308
309void image_battery_load_by_name(const char *filename, void *buffer, int length);
309void image_battery_load_by_name(const char *filename, void *buffer, int length, int fill);
310310void image_battery_save_by_name(const char *filename, const void *buffer, int length);
311311
312void image_battery_load(running_device *img, void *buffer, int length);
312void image_battery_load(running_device *img, void *buffer, int length, int fill);
313313void image_battery_save(running_device *img, const void *buffer, int length);
314314
315315
src/mess/machine/gb.c
r7794r7795
19261926   /* Load the saved RAM if this cart has a battery */
19271927   if( gb_driver_data.CartType & BATTERY && gb_driver_data.RAMBanks )
19281928   {
1929      image_battery_load( image, gb_driver_data.gb_cart_ram, gb_driver_data.RAMBanks * 0x2000 );
1929      image_battery_load( image, gb_driver_data.gb_cart_ram, gb_driver_data.RAMBanks * 0x2000, 0x00 );
19301930   }
19311931
19321932   return INIT_PASS;
src/mess/machine/sms.c
r7794r7795
13391339   }
13401340
13411341   /* Load battery backed RAM, if available */
1342   image_battery_load(image, sms_state.cartridge[index].cartSRAM, sizeof(UINT8) * NVRAM_SIZE);
1342   image_battery_load(image, sms_state.cartridge[index].cartSRAM, sizeof(UINT8) * NVRAM_SIZE, 0x00);
13431343
13441344   return INIT_PASS;
13451345}
src/mess/machine/wswan.c
r7794r7795
14331433   if ( eeprom.size != 0 )
14341434   {
14351435      eeprom.data = auto_alloc_array(image->machine, UINT8, eeprom.size );
1436      image_battery_load( image, eeprom.data, eeprom.size );
1436      image_battery_load( image, eeprom.data, eeprom.size, 0x00 );
14371437      eeprom.page = eeprom.data;
14381438   }
14391439
src/mess/machine/nes.c
r7794r7795
642642      /* Attempt to load a battery file for this ROM. If successful, we */
643643      /* must wait until later to move it to the system memory. */
644644      if (nes.battery)
645         image_battery_load(image, battery_data, BATTERY_SIZE);
645         image_battery_load(image, battery_data, BATTERY_SIZE, 0x00);
646646
647647   }
648648   else if ((magic[0] == 'U') && (magic[1] == 'N') && (magic[2] == 'I') && (magic[3] == 'F')) /* If header starts with 'UNIF' it is UNIF */
r7794r7795
937937   image_fseek(image, 0, SEEK_END);
938938   nes_fds.sides = (image_ftell(image) - header) / 65500;
939939   nes_fds.data = (UINT8*)image_malloc(image, nes_fds.sides * 65500);
940   
940
941941   /* if there is an header, skip it */
942942   image_fseek(image, header, SEEK_SET);
943943
src/mess/machine/snescart.c
r7794r7795
128128
129129   battery_ram = (UINT8*)malloc(snes_cart.sram_max);
130130   ptr = battery_ram;
131   image_battery_load(devtag_get_device(machine, "cart"), battery_ram, snes_cart.sram_max);
131   image_battery_load(devtag_get_device(machine, "cart"), battery_ram, snes_cart.sram_max, 0xff);
132132
133133   if (snes_cart.mode == SNES_MODE_20)
134134   {
src/mess/machine/genesis.c
r7794r7795
578578static void alloc_sram(running_machine *machine)
579579{
580580   genesis_sram = auto_alloc_array(machine, UINT16, (genesis_sram_end - genesis_sram_start + 1) / sizeof(UINT16));
581   image_battery_load(devtag_get_device(machine, "cart"), genesis_sram, genesis_sram_end - genesis_sram_start + 1);
581   image_battery_load(devtag_get_device(machine, "cart"), genesis_sram, genesis_sram_end - genesis_sram_start + 1, 0x00);
582582   memcpy(megadriv_backupram, genesis_sram, genesis_sram_end - genesis_sram_start + 1);
583583}
584584
src/mess/drivers/gba.c
r7794r7795
24442444   // if save media was found, reload it
24452445   if (state->nvsize > 0)
24462446   {
2447      image_battery_load(image, state->nvptr, state->nvsize);
2447      image_battery_load(image, state->nvptr, state->nvsize, 0x00);
24482448      state->nvimage = image;
24492449   }
24502450   else

Previous 15994 Revisions Next


© 1998-2018 The MESS Team