Previous 15994 Revisions Next

r5298 Thursday 23rd July, 2009 at 00:07:10 UTC by Nathan Woods
[TI99] Fixed crash when accessing empty slots [Michael Zapf]
[src/mess/devices]ti99cart.c

src/mess/devices/ti99cart.c
r5297r5298
21132113   for (i=0; i < NUMBER_OF_CARTRIDGE_SLOTS; i++)
21142114   {
21152115      cartslots->cartridge[i].pcb = NULL;
2116      clear_slot(device, i);
21162117   }
21172118   
21182119   /* Initialize the legacy system. */
r5297r5298
21462147READ16_DEVICE_HANDLER( ti99_multicart_r )
21472148{
21482149   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2149   cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot];
2150   int slot = cartslots->active_slot;
2151   cartridge_t *cart;
2152     
2153   /* Sanity check. Higher slots are always empty. */
2154   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
2155      return 0;
2156     
2157   /* Same as above (GROM read): If there is only one cartridge there
2158      is no use of trying other banks. There is one issue with the
2159      selection mechanism: When the console probes the GROM banks and
2160      we have a ROM-only cartridge plugged in, it checks bank 0 and bank 1,
2161      finds no GROM, and then fails to dummy-check bank 0 again which would
2162      have set our cartridge expander to slot 0. But in slot 1 there is no
2163      ROM cartridge, so nothing shows up in the selection list. We work
2164      around this with the following line. */
2165   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
2166      slot=0;
21502167
2168   cart = &cartslots->cartridge[slot];
2169
21512170   /* Idle the CPU */
21522171        cpu_adjust_icount(cputag_get_cpu(device->machine, "maincpu"),-4);
21532172
r5297r5298
21622181      return ti99_cart_r_legacy(device, offset, mem_mask);
21632182   }   
21642183   
2165   if (cart->pcb!=NULL)
2184   if (!slot_is_empty(device, slot))
21662185   {
2167//      printf("accessing cartridge in slot %d\n", cartslots->active_slot);
2186//      printf("accessing cartridge in slot %d\n", slot);
21682187      ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token;
2188//      printf("address=%lx, offset=%lx\n", pcbdef, offset);
21692189      return (*pcbdef->read)(cart->pcb, offset, mem_mask);
21702190   }
21712191   else
21722192   {
2173//      printf("No cartridge in slot %d\n", cartslots->active_slot);
2193//      printf("No cartridge in slot %d\n", slot);
21742194      return 0;
21752195   }
21762196}
r5297r5298
21882208WRITE16_DEVICE_HANDLER( ti99_multicart_w )
21892209{
21902210   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2211   int slot = cartslots->active_slot;
2212   cartridge_t *cart;
2213     
2214   /* Sanity check. Higher slots are always empty. */
2215   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
2216      return;
2217     
2218   /* Same as above (READ16). */
2219   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
2220      slot=0;
21912221
2192   cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot];
2222   cart = &cartslots->cartridge[slot];
21932223   
21942224   /* Idle the CPU */
21952225        cpu_adjust_icount(cputag_get_cpu(device->machine, "maincpu"),-4);
r5297r5298
22022232   }   
22032233   else
22042234   {
2205      if (cart->pcb!=NULL)
2235      if (!slot_is_empty(device, slot))
22062236      {
2207//         printf("writing to cartridge in slot %d\n", cartslots->active_slot);
2237//         printf("writing to cartridge in slot %d\n", slot);
22082238         ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token;
22092239         (*pcbdef->write)(cart->pcb, offset, data, mem_mask);
22102240      }
r5297r5298
22192249READ8_DEVICE_HANDLER( ti99_multicart_cru_r )
22202250{
22212251   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2222   cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot];
2252   cartridge_t *cart;
2253   
2254   int slot = cartslots->active_slot;
2255     
2256   /* Sanity check. Higher slots are always empty. */
2257   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
2258      return 0;
2259     
2260   /* Same as above (READ16). */
2261   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
2262      slot=0;
22232263
2224   if (cart->pcb!=NULL)
2264   cart = &cartslots->cartridge[slot];
2265   
2266   if (!slot_is_empty(device, slot))
22252267   {
22262268      ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token;
22272269      if (pcbdef->cruread != NULL)
r5297r5298
22362278WRITE8_DEVICE_HANDLER( ti99_multicart_cru_w )
22372279{
22382280   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2239   cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot];
2281   cartridge_t *cart;
2282   
2283   int slot = cartslots->active_slot;
2284     
2285   /* Sanity check. Higher slots are always empty. */
2286   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
2287      return;
2288     
2289   /* Same as above (READ16). */
2290   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
2291      slot=0;
22402292
2241   if (cart->pcb!=NULL)
2293   cart = &cartslots->cartridge[slot];
2294
2295   if (!slot_is_empty(device, slot))
22422296   {
22432297      ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token;
22442298      if (pcbdef->cruwrite != NULL)
r5297r5298
22532307READ8_DEVICE_HANDLER(ti99_multicart8_r)
22542308{
22552309   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2256   cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot];
2310   cartridge_t *cart;
2311   
2312   int slot = cartslots->active_slot;
2313     
2314   /* Sanity check. Higher slots are always empty. */
2315   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
2316      return 0;
2317     
2318   /* Same as above (READ16). */
2319   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
2320      slot=0;
22572321
2322   cart = &cartslots->cartridge[slot];
2323
22582324   /* Idle the CPU. TODO: Check whether this is correct for this machine. */
22592325        cpu_adjust_icount(cputag_get_cpu(device->machine, "maincpu"),-4);
22602326
r5297r5298
22642330      return ti99_cart_r_legacy8(device, offset);
22652331   }   
22662332   
2267   if (cart->pcb!=NULL)
2333   if (!slot_is_empty(device, slot))
22682334   {
2269//      printf("accessing cartridge in slot %d\n", cartslots->active_slot);
2335//      printf("accessing cartridge in slot %d\n", slot);
22702336      ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token;
22712337      return (*pcbdef->read8)(cart->pcb, offset);
22722338   }
22732339   else
22742340   {
2275//      printf("No cartridge in slot %d\n", cartslots->active_slot);
2341//      printf("No cartridge in slot %d\n", slot);
22762342      return 0;
22772343   }
22782344}
r5297r5298
22802346WRITE8_DEVICE_HANDLER(ti99_multicart8_w)
22812347{
22822348   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2349   cartridge_t *cart;
2350   
2351   int slot = cartslots->active_slot;
2352     
2353   /* Sanity check. Higher slots are always empty. */
2354   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
2355      return;
2356     
2357   /* Same as above (READ16). */
2358   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
2359      slot=0;
22832360
2284   cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot];
2361   cart = &cartslots->cartridge[slot];
22852362
22862363   /* Idle the CPU. TODO: Check whether this is correct for this machine. */
22872364        cpu_adjust_icount(cputag_get_cpu(device->machine, "maincpu"),-4);
r5297r5298
22932370   }   
22942371   else
22952372   {
2296      if (cart->pcb!=NULL)
2373      if (!slot_is_empty(device, slot))
22972374      {
22982375         ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token;
22992376         (*pcbdef->write8)(cart->pcb, offset, data);
r5297r5298
23102387   MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM)
23112388   MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER)
23122389   MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX)
2313//   MDRV_CARTSLOT_PCBTYPE(6, "gk", TI99_CARTRIDGE_PCB_GK)
23142390   
23152391   MDRV_CARTSLOT_START(ti99_cartridge)
23162392   MDRV_CARTSLOT_LOAD(ti99_cartridge)
r5297r5298
23242400   MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM)
23252401   MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER)
23262402   MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX)
2327//   MDRV_CARTSLOT_PCBTYPE(6, "gk", TI99_CARTRIDGE_PCB_GK)
2403
23282404   MDRV_CARTSLOT_START(ti99_cartridge)
23292405   MDRV_CARTSLOT_LOAD(ti99_cartridge)
23302406   MDRV_CARTSLOT_UNLOAD(ti99_cartridge)
r5297r5298
23372413   MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM)
23382414   MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER)
23392415   MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX)
2340//   MDRV_CARTSLOT_PCBTYPE(6, "gk", TI99_CARTRIDGE_PCB_GK)
2416
23412417   MDRV_CARTSLOT_START(ti99_cartridge)
23422418   MDRV_CARTSLOT_LOAD(ti99_cartridge)
23432419   MDRV_CARTSLOT_UNLOAD(ti99_cartridge)
r5297r5298
23502426   MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM)
23512427   MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER)
23522428   MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX)
2353//   MDRV_CARTSLOT_PCBTYPE(6, "gk", TI99_CARTRIDGE_PCB_GK)
2429
23542430   MDRV_CARTSLOT_START(ti99_cartridge)
23552431   MDRV_CARTSLOT_LOAD(ti99_cartridge)
23562432   MDRV_CARTSLOT_UNLOAD(ti99_cartridge)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team