Previous 15994 Revisions Next

r12047 Saturday 25th June, 2011 at 06:19:24 UTC by Miodrag Milanović
No more need for RPK support for AES, since softlists are used (no whatsnew)
[src/mess]mess.mak
[src/mess/devices]aescart.c aescart.h
[src/mess/drivers]ng_aes.c

src/mess/devices/aescart.c
r12046r12047
1/**********************************************************************
2
3    aescart.c
4
5    Neo-Geo AES cartridge management
6    R. Belmont, 2009
7
8    Based on ti99cart.c by Michael Zapf
9
10    We leave the support in place for multiple slots in case MAME
11    uses this at some future point for MVS multi-cart.
12
13*********************************************************************/
14#include "emu.h"
15#include "aescart.h"
16#include "imagedev/cartslot.h"
17#include "imagedev/multcart.h"
18#include "includes/neogeo.h"
19
20typedef int assmfct(running_machine &machine, device_t *);
21
22enum
23{
24   AESCART_FCT_ASSM = DEVINFO_FCT_DEVICE_SPECIFIC,
25   AESCART_FCT_DISASSM
26};
27
28struct _aes_multicart_t
29{
30   /* Reserves space for all cartridges. This is also used in the legacy
31       cartridge system, but only for slot 0. */
32   aescartridge_t cartridge[AES_NUMBER_OF_CARTRIDGE_SLOTS];
33
34   /* Determines which slot is currently active. This value is changed when there
35    are accesses to other GROM base addresses. */
36   int active_slot;
37
38   /* Used in order to enforce a special slot. This value is retrieved
39       from the dipswitch setting. A value of -1 means automatic, that is,
40       the grom base switch is used. Values 0 .. max refer to the
41       respective slot. */
42   int fixed_slot;
43
44   /* Holds the highest index of a cartridge being plugged in plus one.
45       If we only have one cartridge inserted, we don't want to get a
46       selection option, so we just mirror the memory contents. */
47   int next_free_slot;
48
49   /* Counts the number of slots which currently contain legacy format
50       cartridge images. */
51   int legacy_slots;
52
53   /* Counts the number of slots which currently contain new format
54       cartridge images. */
55   int multi_slots;
56};
57typedef struct _aes_multicart_t aes_multicart_t;
58
59#define AUTO -1
60
61/* Access to the pcb. Contained in the token of the pcb instance. */
62struct _aes_pcb_t
63{
64   /* Link up to the cartridge structure which contains this pcb. */
65   aescartridge_t *cartridge;
66
67   /* Function to assemble this cartridge. */
68   assmfct   *assemble;
69
70   /* Function to disassemble this cartridge. */
71   assmfct   *disassemble;
72};
73typedef struct _aes_pcb_t aes_pcb_t;
74
75INLINE aes_multicart_t *get_safe_token(device_t *device)
76{
77   assert(device != NULL);
78   assert(device->type() == AES_MULTICART);
79
80   return (aes_multicart_t *)downcast<legacy_device_base *>(device)->token();
81}
82
83INLINE aes_pcb_t *get_safe_pcb_token(device_t *device)
84{
85   assert(device != NULL);
86   assert(device->type() == AES_CARTRIDGE_PCB_NONE || device->type() == AES_CARTRIDGE_PCB_STD);
87
88   return (aes_pcb_t *)downcast<legacy_device_base *>(device)->token();
89}
90
91INLINE cartslot_t *get_safe_cartslot_token(device_t *device)
92{
93   assert(device != NULL);
94   assert(device->type() == CARTSLOT);
95
96   return (cartslot_t *)downcast<legacy_device_base *>(device)->token();
97}
98
99/*
100    Find the index of the cartridge name. We assume the format
101    <name><number>, i.e. the number is the longest string from the right
102    which can be interpreted as a number.
103*/
104static int get_index_from_tagname(device_t *image)
105{
106   const char *tag = image->tag();
107   int maxlen = strlen(tag);
108   int i;
109   for (i=maxlen-1; i >=0; i--)
110      if (tag[i] < 48 || tag[i] > 57) break;
111
112   return atoi(tag+i+1);
113}
114
115/*
116    Common routine to assemble cartridges from resources.
117*/
118static aescartridge_t *assemble_common(running_machine &machine, device_t *cartslot)
119{
120   /* Pointer to the cartridge structure. */
121   aescartridge_t *cartridge;
122   device_t *cartsys = cartslot->owner();
123   aes_multicart_t *cartslots = get_safe_token(cartsys);
124   UINT8 *socketcont, *romrgn;
125   int reslength, i, blockofs;
126   char sprname1[16], sprname2[16];
127
128   int slotnumber = get_index_from_tagname(cartslot)-1;
129   assert(slotnumber>=0 && slotnumber<AES_NUMBER_OF_CARTRIDGE_SLOTS);
130
131   /* There is a cartridge in this slot, check the maximum slot number. */
132   if (cartslots->next_free_slot <= slotnumber)
133   {
134      cartslots->next_free_slot = slotnumber+1;
135   }
136   cartridge = &cartslots->cartridge[slotnumber];
137
138   // check for up to 4 program ROMs
139   romrgn = (UINT8 *)machine.region("maincpu")->base();
140   blockofs = 0;
141   for (i = 0; i < 4; i++)
142   {
143      sprintf(sprname1, "p%d", i+1);
144
145      socketcont = (UINT8*)cartslot_get_socket(cartslot, sprname1);
146      reslength = cartslot_get_resource_length(cartslot, sprname1);
147
148      if (socketcont != NULL)
149      {
150         memcpy(romrgn+blockofs, socketcont, reslength);
151         blockofs += reslength;
152      }
153   }
154
155   // 1 m1 ROM
156   socketcont = (UINT8*)cartslot_get_socket(cartslot, "m1");
157   reslength = cartslot_get_resource_length(cartslot, "m1");
158   if (socketcont != NULL)
159   {
160      romrgn = (UINT8 *)machine.region("audiocpu")->base();
161
162      memcpy(romrgn, socketcont, reslength);
163      // mirror (how does this really work?)
164      memcpy(romrgn+0x10000, socketcont, reslength);
165   }
166
167   // up to 8 YM sample ROMs
168   romrgn = (UINT8 *)machine.region("ymsnd")->base();
169   blockofs = 0;
170   for (i = 0; i < 8; i++)
171   {
172      sprintf(sprname1, "v1%d", i+1);
173
174      socketcont = (UINT8*)cartslot_get_socket(cartslot, sprname1);
175      reslength = cartslot_get_resource_length(cartslot, sprname1);
176
177      if (socketcont != NULL)
178      {
179         memcpy(romrgn+blockofs, socketcont, reslength);
180         blockofs += reslength;
181      }
182   }
183
184   // up to 8 YM delta-T sample ROMs
185   romrgn = (UINT8 *)machine.region("ymsnd.deltat")->base();
186   blockofs = 0;
187   for (i = 0; i < 8; i++)
188   {
189      sprintf(sprname1, "v2%d", i+1);
190
191      socketcont = (UINT8*)cartslot_get_socket(cartslot, sprname1);
192      reslength = cartslot_get_resource_length(cartslot, sprname1);
193
194      if (socketcont != NULL)
195      {
196         memcpy(romrgn+blockofs, socketcont, reslength);
197         blockofs += reslength;
198      }
199   }
200
201   // 1 s1 ROM
202   socketcont = (UINT8*)cartslot_get_socket(cartslot, "s1");
203   reslength = cartslot_get_resource_length(cartslot, "s1");
204   if (socketcont != NULL)
205   {
206      romrgn = (UINT8 *)machine.region("fixed")->base();
207
208      memcpy(romrgn, socketcont, reslength);
209   }
210
211   // up to 8 sprite ROMs in byte-interleaved pairs
212   romrgn = (UINT8 *)machine.region("sprites")->base();
213   blockofs = 0;
214   for (i = 0; i < 8; i+=2)
215   {
216      UINT8 *spr1, *spr2;
217      int j;
218
219      sprintf(sprname1, "c%d", i+1);
220      sprintf(sprname2, "c%d", i+2);
221
222      spr1 = (UINT8*)cartslot_get_socket(cartslot, sprname1);
223      spr2 = (UINT8*)cartslot_get_socket(cartslot, sprname2);
224      reslength = cartslot_get_resource_length(cartslot, sprname1);
225
226      if ((spr1) && (spr2))
227      {
228         for (j = 0; j < reslength; j++)
229         {
230            romrgn[blockofs + (j*2)] = spr1[j];
231            romrgn[blockofs + (j*2) + 1] = spr2[j];
232         }
233
234         blockofs += reslength*2;
235      }
236   }
237
238   return cartridge;
239}
240
241static void set_pointers(device_t *pcb, int index)
242{
243   device_t *cartsys = pcb->owner()->owner();
244   aes_multicart_t *cartslots = get_safe_token(cartsys);
245   aes_pcb_t *pcb_def = get_safe_pcb_token(pcb);
246
247   pcb_def->assemble = (assmfct *)downcast<const legacy_cart_slot_device_base *>(pcb)->get_legacy_fct(AESCART_FCT_ASSM);
248   pcb_def->disassemble = (assmfct *)downcast<const legacy_cart_slot_device_base *>(pcb)->get_legacy_fct(AESCART_FCT_DISASSM);
249
250   pcb_def->cartridge = &cartslots->cartridge[index];
251   pcb_def->cartridge->pcb = pcb;
252}
253
254/*****************************************************************************
255  Cartridge type: None
256    This PCB device is just a pseudo device; the legacy mode is handled
257    by dedicated functions.
258******************************************************************************/
259static DEVICE_START(aes_pcb_none)
260{
261   /* device is aes_cartslot:cartridge:pcb */
262//  printf("DEVICE_START(aes_pcb_none), tag of device=%s\n", device->tag());
263   set_pointers(device, get_index_from_tagname(device->owner())-1);
264}
265
266/*****************************************************************************
267  Cartridge type: Standard
268    Most cartridges are built in this type. This includes word-swapped program,
269    z80 program, YM samples, delta-T samples, sprites, and sfix.
270******************************************************************************/
271
272static DEVICE_START(aes_pcb_std)
273{
274   /* device is aes_cartslot:cartridge:pcb */
275//  printf("DEVICE_START(aes_pcb_std), tag of device=%s\n", device->tag());
276   set_pointers(device, get_index_from_tagname(device->owner())-1);
277}
278
279/*
280    The standard cartridge assemble routine. We just call the common
281    function here.
282*/
283static int assemble_std(running_machine &machine, device_t *image)
284{
285//  aescartridge_t *cart;
286//  printf("assemble_std, %s\n", image->tag);
287   /*cart = */assemble_common(machine, image);
288
289   return IMAGE_INIT_PASS;
290}
291
292/*
293    Removes pointers and restores the state before plugging in the
294    cartridge.
295    The pointer to the location after the last cartridge is adjusted.
296    As it seems, we can use the same function for the disassembling of all
297    cartridge types.
298*/
299static int disassemble_std(device_t *image)
300{
301//  int slotnumber;
302//  int i;
303//  aescartridge_t *cart;
304//  device_t *cartsys = image->owner();
305//  aes_multicart_t *cartslots = (aes_multicart_t *)cartsys->token;
306
307//  slotnumber = get_index_from_tagname(image)-1;
308//  printf("Disassemble cartridge %d\n", slotnumber);
309#if 0
310   /* Search the highest remaining cartridge. */
311   cartslots->next_free_slot = 0;
312   for (i=AES_NUMBER_OF_CARTRIDGE_SLOTS-1; i >= 0; i--)
313   {
314      if (i != slotnumber)
315      {
316         if (0) //!slot_is_empty(cartsys, i))    (for future use?)
317         {
318            cartslots->next_free_slot = i+1;
319//              printf("Setting new next_free_slot to %d\n", cartslots->next_free_slot);
320            break;
321         }
322      }
323   }
324#endif
325   /* Do we have RAM? If so, swap the bytes (undo the BIG_ENDIANIZE) */
326//  cart = &cartslots->cartridge[slotnumber];
327
328//  clear_slot(cartsys, slotnumber);
329
330   return IMAGE_INIT_PASS;
331}
332
333/*****************************************************************************
334  Device metadata
335******************************************************************************/
336
337static DEVICE_GET_INFO(aes_cart_common)
338{
339   switch(state)
340   {
341      /* --- the following bits of info are returned as 64-bit signed integers --- */
342      case DEVINFO_INT_TOKEN_BYTES:
343         info->i = sizeof(aes_pcb_t);
344         break;
345      case DEVINFO_INT_INLINE_CONFIG_BYTES:
346         info->i = 0;
347         break;
348
349      /* --- the following bits of info are returned as pointers to functions --- */
350      case DEVINFO_FCT_START:
351         info->start = DEVICE_START_NAME(aes_pcb_std);
352         break;
353      case DEVINFO_FCT_STOP:
354         /* Nothing */
355         break;
356      case DEVINFO_FCT_RESET:
357         /* Nothing */
358         break;
359
360      case AESCART_FCT_ASSM:
361         info->f = (genf *) assemble_std;
362         break;
363
364      case AESCART_FCT_DISASSM:
365         info->f = (genf *) disassemble_std;
366         break;
367
368      /* --- the following bits of info are returned as NULL-terminated strings --- */
369      case DEVINFO_STR_NAME:
370         strcpy(info->s, "AES standard cartridge pcb");
371         break;
372      case DEVINFO_STR_FAMILY:
373         strcpy(info->s, "AES cartridge pcb");
374         break;
375      case DEVINFO_STR_VERSION:
376         strcpy(info->s, "1.0");
377         break;
378      case DEVINFO_STR_SOURCE_FILE:
379         strcpy(info->s, __FILE__);
380         break;
381      case DEVINFO_STR_CREDITS:
382         /* Nothing */
383         break;
384   }
385}
386
387DEVICE_GET_INFO(aes_cartridge_pcb_none)
388{
389   switch(state)
390   {
391      case DEVINFO_FCT_START:
392         info->start = DEVICE_START_NAME(aes_pcb_none);
393         break;
394
395      case DEVINFO_STR_NAME:
396         strcpy(info->s, "AES empty cartridge");
397         break;
398
399      default:
400         DEVICE_GET_INFO_CALL(aes_cart_common);
401         break;
402   }
403}
404
405DEVICE_GET_INFO(aes_cartridge_pcb_std)
406{
407   DEVICE_GET_INFO_CALL(aes_cart_common);
408}
409
410/*****************************************************************************
411  The cartridge handling of the multi-cartridge system.
412  Every cartridge contains a PCB device. The memory handlers delegate the calls
413  to the respective handlers of the cartridges.
414******************************************************************************/
415/*
416    Initialize a cartridge. Each cartridge contains a PCB device.
417*/
418static DEVICE_START( aes_cartridge )
419{
420   cartslot_t *cart = get_safe_cartslot_token(device);
421
422   /* find the PCB device */
423   cart->pcb_device = device->subdevice(TAG_PCB);
424}
425
426// handle protected carts
427static void install_protection(device_image_interface& image)
428{
429   neogeo_state *state = image.device().machine().driver_data<neogeo_state>();
430   const char *crypt_feature = image.get_feature( "crypt" );
431
432   if(crypt_feature == NULL)
433      return;
434
435   if(strcmp(crypt_feature,"fatfury2_prot") == 0)
436   {
437      fatfury2_install_protection(image.device().machine());
438      logerror("Installed Fatal Fury 2 protection\n");
439   }
440   if(strcmp(crypt_feature,"kof99_crypt") == 0)
441   {
442      kof99_decrypt_68k(image.device().machine());
443      state->m_fixed_layer_bank_type = 1;
444      kof99_neogeo_gfx_decrypt(image.device().machine(), 0x00);
445      kof99_install_protection(image.device().machine());
446      logerror("Decrypted KOF99 code and graphics.\n");
447   }
448   if(strcmp(crypt_feature,"mslug3_crypt") == 0)
449   {
450      state->m_fixed_layer_bank_type = 1;
451      kof99_neogeo_gfx_decrypt(image.device().machine(), 0xad);
452      logerror("Decrypted Metal Slug 3 graphics\n");
453   }
454   if(strcmp(crypt_feature,"matrim_crypt") == 0)
455   {
456      matrim_decrypt_68k(image.device().machine());
457      neo_pcm2_swap(image.device().machine(), 1);
458      state->m_fixed_layer_bank_type = 2;
459      neogeo_cmc50_m1_decrypt(image.device().machine());
460      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x6a);
461      logerror("Decrypted Matrimelee code, sound and graphics\n");
462   }
463   if(strcmp(crypt_feature,"svc_crypt") == 0)
464   {
465      svc_px_decrypt(image.device().machine());
466      neo_pcm2_swap(image.device().machine(), 3);
467      state->m_fixed_layer_bank_type = 2;
468      neogeo_cmc50_m1_decrypt(image.device().machine());
469      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x57);
470      install_pvc_protection(image.device().machine());
471      logerror("Decrypted SvC code, sound and graphics.\n");
472   }
473   if(strcmp(crypt_feature,"samsho5_crypt") == 0)
474   {
475      samsho5_decrypt_68k(image.device().machine());
476      neo_pcm2_swap(image.device().machine(), 4);
477      state->m_fixed_layer_bank_type = 1;
478      neogeo_cmc50_m1_decrypt(image.device().machine());
479      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x0f);
480      logerror("Decrypted Samurai Shodown V code, sound and graphics.\n");
481   }
482   if(strcmp(crypt_feature,"kof2000_crypt") == 0)
483   {
484      kof2000_decrypt_68k(image.device().machine());
485      state->m_fixed_layer_bank_type = 2;
486      neogeo_cmc50_m1_decrypt(image.device().machine());
487      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x00);
488      kof2000_install_protection(image.device().machine());
489      logerror("Decrypted KOF2000 code, sound and graphics.\n");
490   }
491   if(strcmp(crypt_feature,"kof2001_crypt") == 0)
492   {
493      state->m_fixed_layer_bank_type = 1;
494      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x1e);
495      neogeo_cmc50_m1_decrypt(image.device().machine());
496      logerror("Decrypted KOF2001 code and graphics.\n");
497   }
498   if(strcmp(crypt_feature,"kof2002_crypt") == 0)
499   {
500      kof2002_decrypt_68k(image.device().machine());
501      neo_pcm2_swap(image.device().machine(), 0);
502      neogeo_cmc50_m1_decrypt(image.device().machine());
503      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0xec);
504      logerror("Decrypted KOF2002 code, sound and graphics.\n");
505   }
506   if(strcmp(crypt_feature,"mslug4_crypt") == 0)
507   {
508      state->m_fixed_layer_bank_type = 1; /* USA violent content screen is wrong -- not a bug, confirmed on real hardware! */
509      neogeo_cmc50_m1_decrypt(image.device().machine());
510      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x31);
511      neo_pcm2_snk_1999(image.device().machine(), 8);
512      logerror("Decrypted Metal Slug 4 code, sound and graphics.\n");
513   }
514   if(strcmp(crypt_feature,"mslug5_crypt") == 0)
515   {
516      mslug5_decrypt_68k(image.device().machine());
517      neo_pcm2_swap(image.device().machine(), 2);
518      state->m_fixed_layer_bank_type = 1;
519      neogeo_cmc50_m1_decrypt(image.device().machine());
520      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x19);
521      install_pvc_protection(image.device().machine());
522      logerror("Decrypted Metal Slug 5 code and graphics, and installed protection routines.\n");
523   }
524   if(strcmp(crypt_feature,"kof2003_crypt") == 0)
525   {
526      kof2003h_decrypt_68k(image.device().machine());
527      neo_pcm2_swap(image.device().machine(), 5);
528      state->m_fixed_layer_bank_type = 2;
529      neogeo_cmc50_m1_decrypt(image.device().machine());
530      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x9d);
531      install_pvc_protection(image.device().machine());
532      logerror("Decrypted KOF2003 code and graphicss, and installed protection routines.\n");
533   }
534   if(strcmp(crypt_feature,"samsho5s_crypt") == 0)
535   {
536      samsh5sp_decrypt_68k(image.device().machine());
537      neo_pcm2_swap(image.device().machine(), 6);
538      state->m_fixed_layer_bank_type = 1;
539      neogeo_cmc50_m1_decrypt(image.device().machine());
540      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x0d);
541   }
542}
543
544/*
545    Load the cartridge image files. Apart from reading, we set pointers
546    to the image files so that during runtime we do not need search
547    operations.
548*/
549static DEVICE_IMAGE_LOAD( aes_cartridge )
550{
551   device_t *pcbdev = cartslot_get_pcb(image);
552   aes_pcb_t *pcb;
553   cartslot_t *cart;
554   multicart_open_error me;
555   UINT32 size;
556   device_t* ym = image.device().machine().device("ymsnd");
557
558   // first check software list
559   if(image.software_entry() != NULL)
560   {
561      // create memory regions
562      size = image.get_software_region_length("maincpu");
563      image.device().machine().region_free("maincpu");
564      image.device().machine().region_alloc("maincpu",size,1, ENDIANNESS_LITTLE);
565      memcpy(image.device().machine().region("maincpu")->base(),image.get_software_region("maincpu"),size);
566      size = image.get_software_region_length("fixed");
567      image.device().machine().region_free("fixed");
568      image.device().machine().region_alloc("fixed",size,1, ENDIANNESS_LITTLE);
569      memcpy(image.device().machine().region("fixed")->base(),image.get_software_region("fixed"),size);
570      size = image.get_software_region_length("audiocpu");
571      image.device().machine().region_free("audiocpu");
572      image.device().machine().region_alloc("audiocpu",size,1, ENDIANNESS_LITTLE);
573      memcpy(image.device().machine().region("audiocpu")->base(),image.get_software_region("audiocpu"),size);
574      size = image.get_software_region_length("ymsnd");
575      image.device().machine().region_free("ymsnd");
576      image.device().machine().region_alloc("ymsnd",size,1, ENDIANNESS_LITTLE);
577      memcpy(image.device().machine().region("ymsnd")->base(),image.get_software_region("ymsnd"),size);
578      if(image.get_software_region("ymsnd.deltat") != NULL)
579      {
580         size = image.get_software_region_length("ymsnd.deltat");
581         image.device().machine().region_free("ymsnd.deltat");
582         image.device().machine().region_alloc("ymsnd.deltat",size,1, ENDIANNESS_LITTLE);
583         memcpy(image.device().machine().region("ymsnd.deltat")->base(),image.get_software_region("ymsnd.deltat"),size);
584      }
585      else
586         image.device().machine().region_free("ymsnd.deltat");  // removing the region will fix sound glitches in non-Delta-T games
587      ym->reset();
588      size = image.get_software_region_length("sprites");
589      image.device().machine().region_free("sprites");
590      image.device().machine().region_alloc("sprites",size,1, ENDIANNESS_LITTLE);
591      memcpy(image.device().machine().region("sprites")->base(),image.get_software_region("sprites"),size);
592      if(image.get_software_region("audiocrypt") != NULL)  // encrypted Z80 code
593      {
594         size = image.get_software_region_length("audiocrypt");
595         image.device().machine().region_alloc("audiocrypt",size,1, ENDIANNESS_LITTLE);
596         memcpy(image.device().machine().region("audiocrypt")->base(),image.get_software_region("audiocrypt"),size);
597      }
598
599      // setup cartridge ROM area
600      image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x000080,0x0fffff,"cart_rom");
601      memory_set_bankptr(image.device().machine(),"cart_rom",&image.device().machine().region("maincpu")->base()[0x80]);
602
603      // handle possible protection
604      install_protection(image);
605
606      return IMAGE_INIT_PASS;
607   }
608
609   if (pcbdev == NULL)
610      fatalerror("Error loading multicart: no pcb found.");
611
612   /* If we are here, we have a multicart. */
613   pcb = get_safe_pcb_token(pcbdev);
614   cart = get_safe_cartslot_token(&image.device());
615
616   /* try opening this as a multicart */
617   /* This line requires that cartslot_t be included in cartslot.h,
618    otherwise one cannot make use of multicart handling within such a
619    custom LOAD function. */
620   me = multicart_open(image.device().machine().options(), image.filename(), image.device().machine().system().name, MULTICART_FLAGS_LOAD_RESOURCES, &cart->mc);
621
622   /* Now that we have loaded the image files, let the PCB put them all
623    together. This means we put the images in a structure which allows
624    for a quick access by the memory handlers. Every PCB defines an
625    own assembly method. */
626    if (me != MCERR_NONE)
627      fatalerror("Error loading multicart: %s", multicart_error_text(me));
628
629   return pcb->assemble(pcbdev->machine(), image);
630}
631
632/*
633    This is called when the cartridge is unplugged (or the emulator is
634    stopped).
635*/
636static DEVICE_IMAGE_UNLOAD( aes_cartridge )
637{
638   device_t *pcbdev;
639
640   if (downcast<legacy_device_base *>(&image.device())->token() == NULL)
641   {
642      /* This means something went wrong during the pcb
643           identification (e.g. one of the cartridge files was not
644           found). We do not need to (and cannot) unload
645           the cartridge. */
646      return;
647   }
648   pcbdev = cartslot_get_pcb(image);
649
650   if (pcbdev != NULL)
651   {
652      aes_pcb_t *pcb = get_safe_pcb_token(pcbdev);
653      cartslot_t *cart = get_safe_cartslot_token(&image.device());
654
655      //  printf("unload\n");
656      if (cart->mc != NULL)
657      {
658         /* Remove pointers and de-big-endianize RAM contents. */
659         pcb->disassemble(pcbdev->machine(), image);
660
661         /* Close the multicart; all RAM resources will be
662               written to disk */
663         multicart_close(pcbdev->machine().options(), cart->mc);
664         cart->mc = NULL;
665      }
666//      else
667//          fatalerror("Lost pointer to multicart in cartridge. Report bug.");
668   }
669}
670
671/*****************************************************************************
672  The overall multi-cartridge slot system. It contains instances of
673  cartridges which contain PCB devices. The memory handlers delegate the calls
674  to the respective handlers of the cartridges.
675
676  Note that the term "multi-cartridge system" and "multicart" are not the same:
677  A "multicart" may contain multiple resources, organized on a PCB. The multi-
678  cart system may thus host multiple multicarts.
679
680  Actually, the name of the device should be changed (however, the device name
681  length is limited)
682******************************************************************************/
683/*
684    Instantiation of a multicart system for the Neo Geo AES.
685*/
686static DEVICE_START(aes_multicart)
687{
688   int i;
689//  printf("DEVICE_START(aes_multicart)\n");
690   aes_multicart_t *cartslots = get_safe_token(device);
691
692   /* Save this in the shortcut; we don't want to look for it each time
693       that we have a memory access. And currently we do not plan for
694       multiple multicart instances. */
695   cartslots->active_slot = 0;
696   cartslots->next_free_slot = 0;
697
698   for (i=0; i < AES_NUMBER_OF_CARTRIDGE_SLOTS; i++)
699   {
700      cartslots->cartridge[i].pcb = NULL;
701   }
702
703   cartslots->multi_slots = 0;
704
705   /* The cartslot system is initialized now. The cartridges themselves
706       need to check whether their parts are available. */
707}
708
709static DEVICE_STOP(aes_multicart)
710{
711//  printf("DEVICE_STOP(aes_multicart)\n");
712}
713
714static MACHINE_CONFIG_FRAGMENT(aes_multicart)
715   MCFG_CARTSLOT_ADD("cartridge1")
716   MCFG_CARTSLOT_EXTENSION_LIST("rpk,bin")
717   MCFG_CARTSLOT_PCBTYPE(0, "none", AES_CARTRIDGE_PCB_NONE)
718   MCFG_CARTSLOT_PCBTYPE(1, "standard", AES_CARTRIDGE_PCB_STD)
719
720   MCFG_CARTSLOT_START(aes_cartridge)
721   MCFG_CARTSLOT_LOAD(aes_cartridge)
722   MCFG_CARTSLOT_UNLOAD(aes_cartridge)
723   MCFG_CARTSLOT_INTERFACE("aes_cart")
724   MCFG_CARTSLOT_MANDATORY
725MACHINE_CONFIG_END
726
727
728DEVICE_GET_INFO(aes_multicart)
729{
730   switch (state)
731   {
732      /* --- the following bits of info are returned as pointers to data --- */
733      case DEVINFO_PTR_MACHINE_CONFIG:
734         info->machine_config = MACHINE_CONFIG_NAME(aes_multicart); break;
735
736      /* --- the following bits of info are returned as NULL-terminated strings --- */
737      case DEVINFO_STR_NAME:
738         strcpy(info->s, "AES Cartridge handler");
739         break;
740
741      case DEVINFO_INT_TOKEN_BYTES: /* private storage, automatically allocated */
742         info->i = sizeof(aes_multicart_t);
743         break;
744
745      case DEVINFO_STR_FAMILY:
746         strcpy(info->s, "Cartridge slot");
747         break;
748      case DEVINFO_STR_VERSION:
749         strcpy(info->s, "1.0");
750         break;
751      case DEVINFO_STR_SOURCE_FILE:
752         strcpy(info->s, __FILE__);
753         break;
754      /* --- the following bits of info are returned as pointers to functions --- */
755      case DEVINFO_FCT_START:
756         info->start = DEVICE_START_NAME(aes_multicart);
757         break;
758      case DEVINFO_FCT_STOP:
759         info->stop = DEVICE_STOP_NAME(aes_multicart);
760         break;
761      case DEVINFO_FCT_RESET:
762         /* Nothing */
763         break;
764   }
765}
766
767DEFINE_LEGACY_CART_SLOT_DEVICE(AES_MULTICART, aes_multicart);
768DEFINE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_NONE, aes_cartridge_pcb_none);
769DEFINE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_STD, aes_cartridge_pcb_std);
src/mess/devices/aescart.h
r12046r12047
1/*********************************************************************
2
3    aescart.h
4
5    AES cartridge management
6
7*********************************************************************/
8
9#ifndef __AESCART_H__
10#define __AESCART_H__
11
12#include "image.h"
13#include "imagedev/cartslot.h"
14
15DECLARE_LEGACY_CART_SLOT_DEVICE(AES_MULTICART, aes_multicart);
16DECLARE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_NONE, aes_cartridge_pcb_none);
17DECLARE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_STD, aes_cartridge_pcb_std);
18
19/* There's only 1 slot in an AES */
20#define AES_NUMBER_OF_CARTRIDGE_SLOTS 1
21
22/* Generic AES cartridge structure. */
23struct _aescartridge_t
24{
25   /* PCB device associated to this cartridge. If NULL, the slot is empty. */
26   device_t *pcb;
27};
28typedef struct _aescartridge_t aescartridge_t;
29
30#define MCFG_AES_CARTRIDGE_ADD(_tag) \
31   MCFG_DEVICE_ADD(_tag, AES_MULTICART, 0)
32
33#endif /* __AESCART_H__ */
src/mess/drivers/ng_aes.c
r12046r12047
3434#include "machine/pd4990a.h"
3535#include "cpu/z80/z80.h"
3636#include "sound/2610intf.h"
37#include "devices/aescart.h"
3837#include "imagedev/cartslot.h"
3938#ifdef MESS
4039#include "neogeo.lh"
r12046r12047
12141213   return ret;
12151214}
12161215
1216// handle protected carts
1217static void install_protection(device_image_interface& image)
1218{
1219   neogeo_state *state = image.device().machine().driver_data<neogeo_state>();
1220   const char *crypt_feature = image.get_feature( "crypt" );
12171221
1222   if(crypt_feature == NULL)
1223      return;
1224
1225   if(strcmp(crypt_feature,"fatfury2_prot") == 0)
1226   {
1227      fatfury2_install_protection(image.device().machine());
1228      logerror("Installed Fatal Fury 2 protection\n");
1229   }
1230   if(strcmp(crypt_feature,"kof99_crypt") == 0)
1231   {
1232      kof99_decrypt_68k(image.device().machine());
1233      state->m_fixed_layer_bank_type = 1;
1234      kof99_neogeo_gfx_decrypt(image.device().machine(), 0x00);
1235      kof99_install_protection(image.device().machine());
1236      logerror("Decrypted KOF99 code and graphics.\n");
1237   }
1238   if(strcmp(crypt_feature,"mslug3_crypt") == 0)
1239   {
1240      state->m_fixed_layer_bank_type = 1;
1241      kof99_neogeo_gfx_decrypt(image.device().machine(), 0xad);
1242      logerror("Decrypted Metal Slug 3 graphics\n");
1243   }
1244   if(strcmp(crypt_feature,"matrim_crypt") == 0)
1245   {
1246      matrim_decrypt_68k(image.device().machine());
1247      neo_pcm2_swap(image.device().machine(), 1);
1248      state->m_fixed_layer_bank_type = 2;
1249      neogeo_cmc50_m1_decrypt(image.device().machine());
1250      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x6a);
1251      logerror("Decrypted Matrimelee code, sound and graphics\n");
1252   }
1253   if(strcmp(crypt_feature,"svc_crypt") == 0)
1254   {
1255      svc_px_decrypt(image.device().machine());
1256      neo_pcm2_swap(image.device().machine(), 3);
1257      state->m_fixed_layer_bank_type = 2;
1258      neogeo_cmc50_m1_decrypt(image.device().machine());
1259      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x57);
1260      install_pvc_protection(image.device().machine());
1261      logerror("Decrypted SvC code, sound and graphics.\n");
1262   }
1263   if(strcmp(crypt_feature,"samsho5_crypt") == 0)
1264   {
1265      samsho5_decrypt_68k(image.device().machine());
1266      neo_pcm2_swap(image.device().machine(), 4);
1267      state->m_fixed_layer_bank_type = 1;
1268      neogeo_cmc50_m1_decrypt(image.device().machine());
1269      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x0f);
1270      logerror("Decrypted Samurai Shodown V code, sound and graphics.\n");
1271   }
1272   if(strcmp(crypt_feature,"kof2000_crypt") == 0)
1273   {
1274      kof2000_decrypt_68k(image.device().machine());
1275      state->m_fixed_layer_bank_type = 2;
1276      neogeo_cmc50_m1_decrypt(image.device().machine());
1277      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x00);
1278      kof2000_install_protection(image.device().machine());
1279      logerror("Decrypted KOF2000 code, sound and graphics.\n");
1280   }
1281   if(strcmp(crypt_feature,"kof2001_crypt") == 0)
1282   {
1283      state->m_fixed_layer_bank_type = 1;
1284      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x1e);
1285      neogeo_cmc50_m1_decrypt(image.device().machine());
1286      logerror("Decrypted KOF2001 code and graphics.\n");
1287   }
1288   if(strcmp(crypt_feature,"kof2002_crypt") == 0)
1289   {
1290      kof2002_decrypt_68k(image.device().machine());
1291      neo_pcm2_swap(image.device().machine(), 0);
1292      neogeo_cmc50_m1_decrypt(image.device().machine());
1293      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0xec);
1294      logerror("Decrypted KOF2002 code, sound and graphics.\n");
1295   }
1296   if(strcmp(crypt_feature,"mslug4_crypt") == 0)
1297   {
1298      state->m_fixed_layer_bank_type = 1; /* USA violent content screen is wrong -- not a bug, confirmed on real hardware! */
1299      neogeo_cmc50_m1_decrypt(image.device().machine());
1300      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x31);
1301      neo_pcm2_snk_1999(image.device().machine(), 8);
1302      logerror("Decrypted Metal Slug 4 code, sound and graphics.\n");
1303   }
1304   if(strcmp(crypt_feature,"mslug5_crypt") == 0)
1305   {
1306      mslug5_decrypt_68k(image.device().machine());
1307      neo_pcm2_swap(image.device().machine(), 2);
1308      state->m_fixed_layer_bank_type = 1;
1309      neogeo_cmc50_m1_decrypt(image.device().machine());
1310      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x19);
1311      install_pvc_protection(image.device().machine());
1312      logerror("Decrypted Metal Slug 5 code and graphics, and installed protection routines.\n");
1313   }
1314   if(strcmp(crypt_feature,"kof2003_crypt") == 0)
1315   {
1316      kof2003h_decrypt_68k(image.device().machine());
1317      neo_pcm2_swap(image.device().machine(), 5);
1318      state->m_fixed_layer_bank_type = 2;
1319      neogeo_cmc50_m1_decrypt(image.device().machine());
1320      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x9d);
1321      install_pvc_protection(image.device().machine());
1322      logerror("Decrypted KOF2003 code and graphicss, and installed protection routines.\n");
1323   }
1324   if(strcmp(crypt_feature,"samsho5s_crypt") == 0)
1325   {
1326      samsh5sp_decrypt_68k(image.device().machine());
1327      neo_pcm2_swap(image.device().machine(), 6);
1328      state->m_fixed_layer_bank_type = 1;
1329      neogeo_cmc50_m1_decrypt(image.device().machine());
1330      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x0d);
1331   }
1332}
1333
1334/*
1335    Load the cartridge image files. Apart from reading, we set pointers
1336    to the image files so that during runtime we do not need search
1337    operations.
1338*/
1339static DEVICE_IMAGE_LOAD( aes_cartridge )
1340{
1341   UINT32 size;
1342   device_t* ym = image.device().machine().device("ymsnd");
1343
1344   // first check software list
1345   if(image.software_entry() != NULL)
1346   {
1347      // create memory regions
1348      size = image.get_software_region_length("maincpu");
1349      image.device().machine().region_free("maincpu");
1350      image.device().machine().region_alloc("maincpu",size,1, ENDIANNESS_LITTLE);
1351      memcpy(image.device().machine().region("maincpu")->base(),image.get_software_region("maincpu"),size);
1352      size = image.get_software_region_length("fixed");
1353      image.device().machine().region_free("fixed");
1354      image.device().machine().region_alloc("fixed",size,1, ENDIANNESS_LITTLE);
1355      memcpy(image.device().machine().region("fixed")->base(),image.get_software_region("fixed"),size);
1356      size = image.get_software_region_length("audiocpu");
1357      image.device().machine().region_free("audiocpu");
1358      image.device().machine().region_alloc("audiocpu",size,1, ENDIANNESS_LITTLE);
1359      memcpy(image.device().machine().region("audiocpu")->base(),image.get_software_region("audiocpu"),size);
1360      size = image.get_software_region_length("ymsnd");
1361      image.device().machine().region_free("ymsnd");
1362      image.device().machine().region_alloc("ymsnd",size,1, ENDIANNESS_LITTLE);
1363      memcpy(image.device().machine().region("ymsnd")->base(),image.get_software_region("ymsnd"),size);
1364      if(image.get_software_region("ymsnd.deltat") != NULL)
1365      {
1366         size = image.get_software_region_length("ymsnd.deltat");
1367         image.device().machine().region_free("ymsnd.deltat");
1368         image.device().machine().region_alloc("ymsnd.deltat",size,1, ENDIANNESS_LITTLE);
1369         memcpy(image.device().machine().region("ymsnd.deltat")->base(),image.get_software_region("ymsnd.deltat"),size);
1370      }
1371      else
1372         image.device().machine().region_free("ymsnd.deltat");  // removing the region will fix sound glitches in non-Delta-T games
1373      ym->reset();
1374      size = image.get_software_region_length("sprites");
1375      image.device().machine().region_free("sprites");
1376      image.device().machine().region_alloc("sprites",size,1, ENDIANNESS_LITTLE);
1377      memcpy(image.device().machine().region("sprites")->base(),image.get_software_region("sprites"),size);
1378      if(image.get_software_region("audiocrypt") != NULL)  // encrypted Z80 code
1379      {
1380         size = image.get_software_region_length("audiocrypt");
1381         image.device().machine().region_alloc("audiocrypt",size,1, ENDIANNESS_LITTLE);
1382         memcpy(image.device().machine().region("audiocrypt")->base(),image.get_software_region("audiocrypt"),size);
1383      }
1384
1385      // setup cartridge ROM area
1386      image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x000080,0x0fffff,"cart_rom");
1387      memory_set_bankptr(image.device().machine(),"cart_rom",&image.device().machine().region("maincpu")->base()[0x80]);
1388
1389      // handle possible protection
1390      install_protection(image);
1391
1392      return IMAGE_INIT_PASS;
1393   }
1394   return IMAGE_INIT_FAIL;
1395}
1396
12181397/*************************************
12191398 *
12201399 *  Machine initialization
r12046r12047
17521931
17531932   MCFG_MEMCARD_HANDLER(neogeo)
17541933
1755   MCFG_AES_CARTRIDGE_ADD("aes_multicart")
1756//  MCFG_CARTSLOT_ADD("cart")
1757//  MCFG_CARTSLOT_MANDATORY
1758
1759//  MCFG_CARTSLOT_LOAD(aes_cart)
1760
1934    MCFG_CARTSLOT_ADD("cart")
1935   MCFG_CARTSLOT_LOAD(aes_cartridge)
1936   MCFG_CARTSLOT_INTERFACE("aes_cart")
1937   MCFG_CARTSLOT_MANDATORY
1938   
17611939   MCFG_SOFTWARE_LIST_ADD("cart_list","aes")
17621940MACHINE_CONFIG_END
17631941
src/mess/mess.mak
r12046r12047
14231423
14241424$(MESSOBJ)/snk.a:            \
14251425   $(MESS_DRIVERS)/ng_aes.o   \
1426   $(MESS_DEVICES)/aescart.o   \
14271426   $(MESS_DRIVERS)/ngp.o      \
14281427   $(MESS_VIDEO)/k1ge.o      \
14291428

Previous 15994 Revisions Next


© 1998-2018 The MESS Team