Previous 15994 Revisions Next

r2439 Tuesday 22nd April, 2008 at 21:17:09 UTC by Cowering
[Genesis] Cleanup custom handlers into MACHINE_RESET (warning, one changed MAME core file)
[src/mame/drivers]megadriv.c
[src/mess/drivers]genesis.c

src/mame/drivers/megadriv.c
r2438r2439
5353
5454#define MEGADRIV_VDP_VRAM(address) megadrive_vdp_vram[(address)&0x7fff]
5555
56#ifdef MESS
57extern void setup_megadriv_custom_mappers(running_machine *);
58#endif
59
5660/* the same on all systems? */
5761#define MASTER_CLOCK      53693100
5862/* timing details */
r2438r2439
48164820
48174821   memset(megadrive_ram,0x00,0x10000);
48184822
4819
4823#ifdef MESS
4824   setup_megadriv_custom_mappers(machine);
4825#endif
48204826}
48214827
48224828void megadriv_stop_scanline_timer(void)
src/mess/drivers/genesis.c
r2438r2439
5050
5151#include "driver.h"
5252#include "sound/2612intf.h"
53#include "includes/genesis.h"
53//#include "includes/genesis.h"
5454#include "devices/cartslot.h"
5555#include "../../mame/drivers/megadriv.h"
5656#include "cpu/m68000/m68000.h"
5757
58static int is_ssf2 = 0;
59static int is_redcliff = 0;
60static int is_radica = 0;
61static int is_kof99 = 0;
62static int is_soulb = 0;
63static int is_mjlovr = 0;
64static int is_squir = 0;
65static int squirrel_king_extra = 0;
66static int is_smous = 0;
67static int is_smb = 0;
68static int is_elfwor = 0;
69static int is_lionk2 = 0;
58static UINT16 squirrel_king_extra = 0;
7059static UINT16 lion2_prot1_data, lion2_prot2_data;
71static int is_rx3 = 0;
72static int is_bugsl = 0;
73static int is_sbub = 0;
74static int is_smb2 = 0;
75static int is_kof98 = 0;
76static int is_kaiju = 0;
77static int is_chifi3 = 0;
78static int is_realtec = 0;
79static int realtek_bank_addr=0, realtek_bank_size=0, realtek_old_bank_addr;
80static int is_19in1 = 0;
81static int is_15in1 = 0;
60static UINT16 realtek_bank_addr=0, realtek_bank_size=0, realtek_old_bank_addr;
8261
62static int genesis_last_loaded_image_length = -1;
63
64//where a fresh copy of rom is stashed for reset and banking setup
65#define VIRGIN_COPY_GEN 0xd00000
66
8367static UINT8 *genesis_sram;
8468static int genesis_sram_start;
8569static int genesis_sram_len = 0;
8670static int genesis_sram_active;
8771static int genesis_sram_readonly;
8872
73
8974static READ16_HANDLER( genesis_sram_read )
9075{
91        UINT16 retval = 0;
76   UINT16 retval = 0;
9277
93        offset <<= 1;
78   offset <<= 1;
9479
95        if (genesis_sram_active)
96        {
97                retval |= genesis_sram[offset] << 8;
98                retval |= genesis_sram[offset ^ 1] & 0xff;
99        }
80   if (genesis_sram_active)
81   {
82      retval |= genesis_sram[offset] << 8;
83      retval |= genesis_sram[offset ^ 1] & 0xff;
84   }
10085
101        return retval;
86   return retval;
10287}
10388
10489
10590static WRITE16_HANDLER( genesis_sram_write )
10691{
107        offset <<= 1;
92   offset <<= 1;
10893
109        if (!genesis_sram_readonly)
110        {
111                genesis_sram[offset] = data >> 8;
112                genesis_sram[offset ^ 1] = data & 0xff;
113        }
94   if (!genesis_sram_readonly)
95   {
96      genesis_sram[offset] = data >> 8;
97      genesis_sram[offset ^ 1] = data & 0xff;
98   }
11499}
115100
116101
r2438r2439
206191
207192   genesis_sram = NULL;
208193   genesis_sram_start = genesis_sram_len = genesis_sram_active = genesis_sram_readonly = 0;
209   is_ssf2 = is_redcliff = is_radica = is_kof99 = is_soulb = is_mjlovr = is_squir = is_smous = is_elfwor = is_lionk2 = is_rx3 = is_bugsl = is_sbub = is_smb2 = is_kof98 = is_kaiju = is_chifi3 = is_realtec = is_19in1 = is_15in1 = 0;
210194
211195   rawROM = memory_region(REGION_CPU1);
212        ROM = rawROM /*+ 512 */;
196    ROM = rawROM /*+ 512 */;
213197
214        length = image_fread(image, rawROM + 0x2000, 0x600000);
198    length = image_fread(image, rawROM + 0x2000, 0x600000);
215199   logerror("image length = 0x%x\n", length);
216200
217201   if (genesis_isSMD(&rawROM[0x2200],(unsigned)length))   /* is this a SMD file..? */
r2438r2439
262246   /* BIN it is, then */
263247   {
264248      relocate = 0x2000;
249      genesis_last_loaded_image_length = length; // this will be -1 for MD and SMD so can't map those roms to custom mappers (yet)
265250
266      if (length == 0x500000 && !strncmp((char *)&ROM[0x0120+relocate], "SUPER STREET FIGHTER2", 21))
267      {
268         is_ssf2 = 1;
269      }
270      // detect the 'Romance of the Three Kingdoms - Battle of Red Cliffs' rom, already decoded from .mdx format
271      if (length == 0x200000)
272      {
273          static unsigned char redcliffsig[] = { 0x10, 0x39, 0x00, 0x40, 0x00, 0x04}; // move.b  ($400004).l,d0
274          if (!memcmp(&ROM[0xce560+relocate],&redcliffsig[0],sizeof(redcliffsig)))
275         {
276            is_redcliff = 1;
277         }
278      }
279      // detect the Radica TV games.. these probably should be a seperate driver since they are a seperate 'console'
280      if (length == 0x400000)
281      {
282          static unsigned char radicasig[] = { 0xd0, 0x30, 0x39, 0x00, 0xa1, 0x30}; // jmp (a0) move.w ($a130xx),d0
283251
284          if (!memcmp(&ROM[0x3c031d+relocate],&radicasig[0],sizeof(radicasig))) // ssf+gng
285         {
286            is_radica = 1;
287         }
288          if (!memcmp(&ROM[0x3f031d+relocate],&radicasig[0],sizeof(radicasig))) // 6in1 vol 1
289         {
290            is_radica = 1;
291         }
292
293      }
294
295      // detect the King of Fighters '99 unlicensed game
296      if (length == 0x300000)
297      {
298          static unsigned char kof99sig[] = { 0x20, 0x3c, 0x30, 0x00, 0x00, 0xa1}; // move.l  #$300000A1,d0
299
300          if (!memcmp(&ROM[0x1fd0d2+relocate],&kof99sig[0],sizeof(kof99sig)))
301         {
302            is_kof99 = 1;
303         }
304      }
305
306      // detect the Soul Blade unlicensed game
307      if (length == 0x400000)
308      {
309          static unsigned char soulbsig[] = { 0x33, 0xfc, 0x00, 0x0c, 0x00, 0xff}; // move.w  #$C,($FF020A).l (what happens if check fails)
310
311          if (!memcmp(&ROM[0x028460+relocate],&soulbsig[0],sizeof(soulbsig)))
312         {
313            is_soulb = 1;
314         }
315      }
316
317      // detect Mahjong Lover unlicensed game
318      if (length == 0x100000)
319      {
320          static unsigned char mjlovrsig[] = { 0x13, 0xf9, 0x00, 0x40, 0x00, 0x00}; // move.b  ($400000).l,($FFFF0C).l (partial)
321
322          if (!memcmp(&ROM[0x01b24+relocate],&mjlovrsig[0],sizeof(mjlovrsig)))
323         {
324            is_mjlovr = 1;
325         }
326      }
327      // detect Squirrel King unlicensed game
328      if (length == 0x100000)
329      {
330          static unsigned char squirsig[] = { 0x26, 0x79, 0x00, 0xff, 0x00, 0xfa};
331
332          if (!memcmp(&ROM[0x03b4+relocate],&squirsig[0],sizeof(squirsig)))
333         {
334            is_squir = 1;
335         }
336      }
337      if (length == 0x80000)
338      {
339          static unsigned char smoussig[] = { 0x4d, 0xf9, 0x00, 0x40, 0x00, 0x02};
340
341          if (!memcmp(&ROM[0x08c8+relocate],&smoussig[0],sizeof(smoussig)))
342         {
343            is_smous = 1;
344         }
345      }
346      if (length >= 0x200000)
347      {
348         static unsigned char smb2sig[] = { 0x4e, 0xb9, 0x00, 0x0f, 0x25, 0x84};
349
350         if (!memcmp(&ROM[0xf24d6+relocate],&smb2sig[0],sizeof(smb2sig)))
351         {
352            is_smb2 = 1;
353         }
354      }
355      if (length >= 0x200000)
356      {
357         static unsigned char smb2sig[] = { 0x4e, 0xb9, 0x00, 0x0f, 0x25, 0x84};
358
359         if (!memcmp(&ROM[0xf24d6+relocate],&smb2sig[0],sizeof(smb2sig)))
360         {
361            is_smb2 = 1;
362         }
363      }
364
365      if (length == 0x200000)
366      {
367         static unsigned char kaijusig[] = { 0x19, 0x7c, 0x00, 0x01, 0x00, 0x00};
368
369         if (!memcmp(&ROM[0x674e + relocate],&kaijusig[0],sizeof(kaijusig)))
370         {
371            is_kaiju = 1;
372         }
373      }
374
375      if (length == 0x200000)
376      {
377         static unsigned char chifi3sig[] = { 0xb6, 0x16, 0x66, 0x00, 0x00, 0x4a};
378
379         if (!memcmp(&ROM[0x1780 + relocate],&chifi3sig[0],sizeof(chifi3sig)))
380         {
381            is_chifi3 = 1;
382         }
383      }
384
385
386      if (length == 0x200000)
387      {
388         static unsigned char lionk2sig[] = { 0x26, 0x79, 0x00, 0xff, 0x00, 0xf4};
389
390         if (!memcmp(&ROM[0x03c2+relocate],&lionk2sig[0],sizeof(lionk2sig)))
391         {
392            is_lionk2 = 1;
393         }
394      }
395
396      if (length == 0x100000)
397      {
398         static unsigned char bugslsig[] = { 0x20, 0x12, 0x13, 0xc0, 0x00, 0xff};
399
400         if (!memcmp(&ROM[0xee0d0+relocate],&bugslsig[0],sizeof(bugslsig)))
401         {
402            is_bugsl = 1;
403         }
404      }
405
406      if (length == 0x100000 && !strncmp((char *)&ROM[0x0172+relocate], "GAME : ELF WOR", 14))
407      {
408         is_elfwor = 1;
409      }
410      if (length == 0x200000)
411      {
412         static unsigned char rx3sig[] = { 0x66, 0x00, 0x00, 0x0e, 0x30, 0x3c};
413         if (!memcmp(&ROM[0xc8b90+relocate],&rx3sig[0],sizeof(rx3sig)))
414         {
415            is_rx3 = 1;
416         }
417      }
418      if (length == 0x100000)
419      {
420         static unsigned char sbubsig[] = { 0x0c, 0x39, 0x00, 0x55, 0x00, 0x40}; //    cmpi.b  #$55,($400000).l
421         if (!memcmp(&ROM[0x123e4+relocate],&sbubsig[0],sizeof(sbubsig)))
422         {
423            is_sbub = 1;
424         }
425      }
426      if (length == 0x200000)
427      {
428         static unsigned char kof98sig[] = { 0x9b, 0xfc, 0x00, 0x00, 0x4a, 0x00};
429         if (!memcmp(&ROM[0x56ae2+relocate],&kof98sig[0],sizeof(kof98sig)))
430         {
431            is_kof98 = 1;
432         }
433      }
434      if (length == 0x80000) {
435         if (!strncmp((char *)&ROM[0x7e30e + relocate],"SEGA",4)) is_realtec = 1; // Whac a Critter/mallet legend
436         if (!strncmp((char *)&ROM[0x7e100 + relocate],"SEGA",4)) is_realtec = 1; // Defend the Earth
437         if (!strncmp((char *)&ROM[0x7e1e6 + relocate],"SEGA",4)) is_realtec = 1; // Funnyworld/ballonboy
438      }
439      // detect 'Super 19 in 1'
440      if (length == 0x400000)
441      {
442          static unsigned char s19in1sig[] = { 0x13, 0xc0, 0x00, 0xa1, 0x30, 0x38};
443
444          if (!memcmp(&ROM[0x1e700+relocate],&s19in1sig[0],sizeof(s19in1sig))) // super19in1
445         {
446            is_19in1 = 1;
447         }
448
449      }
450      // detect 'Super 15 in 1'
451      if (length == 0x200000)
452      {
453          static unsigned char s15in1sig[] = { 0x22, 0x3c, 0x00, 0xa1, 0x30, 0x00};
454
455          if (!memcmp(&ROM[0x17bb2+relocate],&s15in1sig[0],sizeof(s15in1sig))) // super15in1
456         {
457            is_15in1 = 1;
458         }
459      }
460
461   }
462
463252   ROM = memory_region(REGION_CPU1);   /* 68000 ROM region */
464253
465254    for (ptr = 0; ptr < 0x502000; ptr += 2)      /* mangle bytes for littleendian machines */
r2438r2439
474263      ROM[ptr + 1] = ROM[relocate + ptr + 1];
475264#endif
476265   }
266   memcpy(&ROM[VIRGIN_COPY_GEN],&ROM[0x000000],0x500000);  // store a copy of data for MACHINE_RESET processing
477267
478   if (is_ssf2)
479   {
480      memcpy(&ROM[0x800000],&ROM[0x400000],0x100000);
481      memcpy(&ROM[0x400000],&ROM[0x000000],0x400000);
482   }
483   if (is_19in1) {
484      UINT8 *ROM = memory_region(REGION_CPU1);
485      memcpy(&ROM[0x400000],&ROM[0x000000],0x400000); // allow hard reset to menu
486   }
487   if (is_15in1) {
488      UINT8 *ROM = memory_region(REGION_CPU1);
489      memcpy(&ROM[0x400000],&ROM[0x000000],0x200000); // allow hard reset to menu
490   }
491
492   if (is_realtec)
493   {
494      UINT32 mirroraddr;
495      /* Realtec mapper!*/
496      UINT8 *ROM = memory_region(REGION_CPU1);
497      memcpy(&ROM[0x400000],&ROM[0x000000],0x80000);
498      for (mirroraddr = 0; mirroraddr < 0x400000;mirroraddr+=0x2000) {
499         memcpy(ROM+mirroraddr, ROM +  0x47e000, 0x002000); /* copy last 8kb across the whole rom region */
500      }
501   }
502
503   if (is_kaiju)
504   {
505      memcpy(&ROM[0x400000],&ROM[0x000000],0x200000);
506      memcpy(&ROM[0x600000],&ROM[0x000000],0x200000);
507   }
508
509   if (is_radica)
510   {
511      memcpy(&ROM[0x400000], &ROM[0], 0x400000); // keep a copy for later banking.. making use of huge ROM_REGION allocated to genesis driver
512      memcpy(&ROM[0x800000], &ROM[0], 0x400000); // wraparound banking (from hazemd code)
513   }
514   if (is_chifi3)
515   {
516      memcpy(ROM + 0x400000, ROM + 0x000000, 0x200000);
517      memcpy(ROM + 0x600000, ROM + 0x000000, 0x200000);
518   }
519
520
521        /* check if cart has battery save */
522   genesis_sram_len = 0;
523   genesis_sram = NULL;
524   if (ROM[0x1b1] == 'R' && ROM[0x1b0] == 'A')
525   {
526      genesis_sram_start = (ROM[0x1b5] << 24 | ROM[0x1b4] << 16 | ROM[0x1b7] << 8 | ROM[0x1b6]);
527      genesis_sram_len = (ROM[0x1b9] << 24 | ROM[0x1b8] << 16 | ROM[0x1bb] << 8 | ROM[0x1ba]);
528   }
529
530   if (genesis_sram_start != genesis_sram_len)
531   {
532                if (genesis_sram_start & 1)
533                        genesis_sram_start -= 1;
534                if (!(genesis_sram_len & 1))
535                        genesis_sram_len += 1;
536      genesis_sram_len -= (genesis_sram_start - 1);
537      genesis_sram = auto_malloc (genesis_sram_len);
538      memset(genesis_sram, 0, genesis_sram_len);
539      image_battery_load(image_from_devtype_and_index(IO_CARTSLOT,0), genesis_sram, genesis_sram_len);
540
541                if (length - 0x200 < genesis_sram_start)
542      {
543                        genesis_sram_active = 1;
544      }
545
546                memory_install_read16_handler(image->machine, 0, ADDRESS_SPACE_PROGRAM, genesis_sram_start & 0x3fffff, (genesis_sram_start + genesis_sram_len - 1) & 0x3fffff, 0, 0, genesis_sram_read);
547
548                memory_install_write16_handler(image->machine, 0, ADDRESS_SPACE_PROGRAM, genesis_sram_start & 0x3fffff, (genesis_sram_start + genesis_sram_len - 1) & 0x3fffff, 0, 0, genesis_sram_write);
549                memory_install_write16_handler(image->machine, 0, ADDRESS_SPACE_PROGRAM, 0xa130f0, 0xa130f1, 0, 0, genesis_sram_toggle);
550   }
551
552268   return INIT_PASS;
553
269   }
554270bad:
555271   return INIT_FAIL;
556272}
557
558273/* we don't use the bios rom (its not needed and only provides security on early models) */
559274
560275ROM_START(genesis)
561//   ROM_REGION(0x1415000, REGION_CPU1, ROMREGION_ERASEFF)
562   ROM_REGION(0x0a00000, REGION_CPU1, ROMREGION_ERASEFF)
276   ROM_REGION(0x1415000, REGION_CPU1, ROMREGION_ERASEFF)
563277   ROM_REGION( 0x10000, REGION_CPU2, ROMREGION_ERASEFF)
564278ROM_END
565279
566280ROM_START(gensvp)
567//   ROM_REGION(0x1415000, REGION_CPU1, ROMREGION_ERASEFF)
568   ROM_REGION(0x0a00000, REGION_CPU1, ROMREGION_ERASEFF)
281   ROM_REGION(0x1415000, REGION_CPU1, ROMREGION_ERASEFF)
569282   ROM_REGION( 0x10000, REGION_CPU2, ROMREGION_ERASEFF)
570283ROM_END
571284
572285ROM_START(megadriv)
573//   ROM_REGION(0x1415000, REGION_CPU1, ROMREGION_ERASEFF)
574   ROM_REGION(0x0a00000, REGION_CPU1, ROMREGION_ERASEFF)
286   ROM_REGION(0x1415000, REGION_CPU1, ROMREGION_ERASEFF)
575287   ROM_REGION( 0x10000, REGION_CPU2, ROMREGION_ERASEFF)
576288ROM_END
577289
578290ROM_START(megadrij)
579//   ROM_REGION(0x1415000, REGION_CPU1, ROMREGION_ERASEFF)
580   ROM_REGION(0x0a00000, REGION_CPU1, ROMREGION_ERASEFF)
291   ROM_REGION(0x1415000, REGION_CPU1, ROMREGION_ERASEFF)
581292   ROM_REGION( 0x10000, REGION_CPU2, ROMREGION_ERASEFF)
582293ROM_END
583294
r2438r2439
654365   }
655366}
656367
657WRITE16_HANDLER( realtec_402000_w )
368static WRITE16_HANDLER( realtec_402000_w )
658369{
659370   realtek_bank_addr = 0;
660371   realtek_bank_size = (data>>8)&0x1f;
661372}
662373
663WRITE16_HANDLER( realtec_400000_w )
374static WRITE16_HANDLER( realtec_400000_w )
664375{
665376   int bankdata = (data >> 9) & 0x7;
666377
r2438r2439
673384   memcpy(ROM+ realtek_bank_size*0x20000, ROM +  (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000);
674385}
675386
676WRITE16_HANDLER( realtec_404000_w )
387static WRITE16_HANDLER( realtec_404000_w )
677388{
678389   int bankdata = (data >> 8) & 0x3;
679390   UINT8 *ROM = memory_region(REGION_CPU1);
r2438r2439
688399   }
689400}
690401
691WRITE16_HANDLER( g_chifi3_bank_w )
402static WRITE16_HANDLER( g_chifi3_bank_w )
692403{
693404   UINT8 *ROM = memory_region(REGION_CPU1);
694405
r2438r2439
731442
732443}
733444
734READ16_HANDLER( g_chifi3_prot_r )
445static READ16_HANDLER( g_chifi3_prot_r )
735446{
736447   UINT32 retdat;
737448
r2438r2439
803514}
804515
805516// Soulblade handler from HazeMD
806READ16_HANDLER( soulb_0x400006_r )
517static READ16_HANDLER( soulb_0x400006_r )
807518{
808519   return 0xf000;
809520}
810521
811READ16_HANDLER( soulb_0x400002_r )
522static READ16_HANDLER( soulb_0x400002_r )
812523{
813524   return 0x9800;
814525}
815526
816READ16_HANDLER( soulb_0x400004_r )
527static READ16_HANDLER( soulb_0x400004_r )
817528{
818529   return 0xc900;
819530}
820531
821532// Mahjong Lover handler from HazeMD
822READ16_HANDLER( mjlovr_prot_1_r )
533static READ16_HANDLER( mjlovr_prot_1_r )
823534{
824535   return 0x9000;
825536}
826537
827READ16_HANDLER( mjlovr_prot_2_r )
538static READ16_HANDLER( mjlovr_prot_2_r )
828539{
829540   return 0xd300;
830541}
831542
832543// Super Mario Bros handler from HazeMD
833READ16_HANDLER( smbro_prot_r )
544static READ16_HANDLER( smbro_prot_r )
834545{
835546   return 0xc;
836547}
837548
838549
839550// Smart Mouse handler from HazeMD
840READ16_HANDLER( smous_prot_r )
551static READ16_HANDLER( smous_prot_r )
841552{
842553   switch (offset)
843554   {
r2438r2439
851562}
852563
853564// Super Bubble Bobble MD handler from HazeMD
854READ16_HANDLER( sbub_extra1_r )
565static READ16_HANDLER( sbub_extra1_r )
855566{
856567   return 0x5500;
857568}
858569
859READ16_HANDLER( sbub_extra2_r )
570static READ16_HANDLER( sbub_extra2_r )
860571{
861572   return 0x0f00;
862573}
863574
864575// KOF99 handler from HazeMD
865READ16_HANDLER( kof99_0xA13002_r )
576static READ16_HANDLER( kof99_0xA13002_r )
866577{
867578   // write 02 to a13002.. shift right 1?
868579   return 0x01;
869580}
870581
871READ16_HANDLER( kof99_00A1303E_r )
582static READ16_HANDLER( kof99_00A1303E_r )
872583{
873584   // write 3e to a1303e.. shift right 1?
874585   return 0x1f;
875586}
876587
877READ16_HANDLER( kof99_0xA13000_r )
588static READ16_HANDLER( kof99_0xA13000_r )
878589{
879590   // no write, startup check, chinese message if != 0
880591   return 0x0;
r2438r2439
882593
883594// Radica handler from HazeMD
884595
885READ16_HANDLER( radica_bank_select )
596static READ16_HANDLER( radica_bank_select )
886597{
887598   int bank = offset&0x3f;
888599   UINT8 *ROM = memory_region(REGION_CPU1);
r2438r2439
892603
893604// ROTK Red Cliff handler from HazeMD
894605
895READ16_HANDLER( redclif_prot_r )
606static READ16_HANDLER( redclif_prot_r )
896607{
897608   return -0x56 << 8;
898609}
899610
900READ16_HANDLER( redclif_prot2_r )
611static READ16_HANDLER( redclif_prot2_r )
901612{
902613   return 0x55 << 8;
903614}
904615
905616// Squirrel King handler from HazeMD, this does not give screen garbage like HazeMD compile If you reset it twice
906READ16_HANDLER( squirrel_king_extra_r )
617static READ16_HANDLER( squirrel_king_extra_r )
907618{
908619   return squirrel_king_extra;
909620
910621}
911WRITE16_HANDLER( squirrel_king_extra_w )
622static WRITE16_HANDLER( squirrel_king_extra_w )
912623{
913624   squirrel_king_extra = data;
914625}
915626
916627// Lion King 2 handler from HazeMD
917READ16_HANDLER( lion2_prot1_r )
628static READ16_HANDLER( lion2_prot1_r )
918629{
919630   return lion2_prot1_data;
920631}
921632
922READ16_HANDLER( lion2_prot2_r )
633static READ16_HANDLER( lion2_prot2_r )
923634{
924635   return lion2_prot2_data;
925636}
926637
927WRITE16_HANDLER ( lion2_prot1_w )
638static WRITE16_HANDLER ( lion2_prot1_w )
928639{
929640   lion2_prot1_data = data;
930641}
931642
932WRITE16_HANDLER ( lion2_prot2_w )
643static WRITE16_HANDLER ( lion2_prot2_w )
933644{
934645   lion2_prot2_data = data;
935646}
936647
937648// Rockman X3 handler from HazeMD
938READ16_HANDLER( rx3_extra_r )
649static READ16_HANDLER( rx3_extra_r )
939650{
940651   return 0xc;
941652}
942653
943654// King of Fighters 98 handler from HazeMD
944READ16_HANDLER( g_kof98_aa_r )
655static READ16_HANDLER( g_kof98_aa_r )
945656{
946657   return 0xaa00;
947658}
948659
949READ16_HANDLER( g_kof98_0a_r )
660static READ16_HANDLER( g_kof98_0a_r )
950661{
951662   return 0x0a00;
952663}
953664
954READ16_HANDLER( g_kof98_00_r )
665static READ16_HANDLER( g_kof98_00_r )
955666{
956667   return 0x0000;
957668}
958669
959670// Super Mario Bros 2 handler from HazeMD
960READ16_HANDLER( smb2_extra_r )
671static READ16_HANDLER( smb2_extra_r )
961672{
962673   return 0xa;
963674}
964675
965676// Bug's Life handler from HazeMD
966READ16_HANDLER( bugl_extra_r )
677static READ16_HANDLER( bugl_extra_r )
967678{
968679   return 0x28;
969680}
970681
971682// Elf Wor handler from HazeMD (DFJustin says the title is 'Linghuan Daoshi Super Magician')
972READ16_HANDLER( elfwor_0x400000_r )
683static READ16_HANDLER( elfwor_0x400000_r )
973684{
974685   return 0x5500;
975686}
976687
977READ16_HANDLER( elfwor_0x400002_r )
688static READ16_HANDLER( elfwor_0x400002_r )
978689{
979690   return 0x0f00;
980691}
981692
982READ16_HANDLER( elfwor_0x400004_r )
693static READ16_HANDLER( elfwor_0x400004_r )
983694{
984695   return 0xc900;
985696}
986697
987READ16_HANDLER( elfwor_0x400006_r )
698static READ16_HANDLER( elfwor_0x400006_r )
988699{
989700   return 0x1800;
990701}
r2438r2439
1002713{
1003714   if (genesis_sram)
1004715   {
1005                add_exit_callback(machine, genesis_machine_stop);
716      add_exit_callback(machine, genesis_machine_stop);
1006717   }
1007718
1008   if (is_ssf2)
719
720}
721
722static DRIVER_INIT( genusa )
723{
724   DRIVER_INIT_CALL(gencommon);
725   DRIVER_INIT_CALL(megadriv);
726}
727
728static DRIVER_INIT( geneur )
729{
730   DRIVER_INIT_CALL(gencommon);
731   DRIVER_INIT_CALL(megadrie);
732}
733
734static DRIVER_INIT( genjpn )
735{
736   DRIVER_INIT_CALL(gencommon);
737   DRIVER_INIT_CALL(megadrij);
738}
739
740// only looks for == in the compare for LSB systems
741static int allendianmemcmp(const void *s1, const void *s2, size_t n)
742{
743unsigned char *realbuf;
744
745#ifdef LSB_FIRST
746unsigned char flippedbuf[64];
747unsigned int i;
748
749if ((n & 1) || (n > 63)) return -1 ; // don't want odd sized buffers or too large a compare
750for (i = 0; i < n; i++) flippedbuf[i] = *((char *)s2 + (i ^ 1));
751realbuf = flippedbuf;
752
753#else
754
755realbuf = s2;
756
757#endif
758return memcmp(s1,realbuf,n);
759}
760
761void setup_megadriv_custom_mappers(running_machine *machine)
762{
763   static int relocate = VIRGIN_COPY_GEN;
764   unsigned char *ROM;
765   UINT32 mirroraddr;
766
767   ROM = memory_region(REGION_CPU1);
768
769   if (genesis_last_loaded_image_length == 0x500000 && !allendianmemcmp((char *)&ROM[0x0120+relocate], "SUPER STREET FIGHTER2 ", 22))
1009770   {
771      memcpy(&ROM[0x800000],&ROM[VIRGIN_COPY_GEN+0x400000],0x100000);
772      memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x400000);
773      memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x400000);
1010774      memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA130F0, 0xA130FF, 0, 0, genesis_ssf2_bank_w);
1011775   }
1012   if (is_kaiju)
776   /* detect the 'Romance of the Three Kingdoms - Battle of Red Cliffs' rom, already decoded from .mdx format */
777   if (genesis_last_loaded_image_length == 0x200000)
1013778   {
1014      memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x700000, 0x7fffff, 0, 0, g_kaiju_bank_w );
779      static unsigned char redcliffsig[] = { 0x10, 0x39, 0x00, 0x40, 0x00, 0x04}; // move.b  ($400004).l,d0
780      if (!allendianmemcmp(&ROM[0xce560+relocate],&redcliffsig[0],sizeof(redcliffsig)))
781      {
782         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, redclif_prot2_r );
783         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, redclif_prot_r );
784      }
1015785   }
1016   if (is_chifi3)
786   /* detect the Radica TV games.. these probably should be a seperate driver since they are a seperate 'console' */
787   if (genesis_last_loaded_image_length == 0x400000)
1017788   {
1018      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x4fffff, 0, 0, g_chifi3_prot_r );
1019      memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_chifi3_bank_w );
789      static unsigned char radicasig[] = { 0x4e, 0xd0, 0x30, 0x39, 0x00, 0xa1}; // jmp (a0) move.w ($a130xx),d0
1020790
791      if (!allendianmemcmp(&ROM[0x3c031c+relocate],&radicasig[0],sizeof(radicasig)) ||
792          !allendianmemcmp(&ROM[0x3f031c+relocate],&radicasig[0],sizeof(radicasig))) // ssf+gng + radica vol1
793      {
794         memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x400000); // keep a copy for later banking.. making use of huge ROM_REGION allocated to genesis driver
795         memcpy(&ROM[0x800000],&ROM[VIRGIN_COPY_GEN],0x400000); // wraparound banking (from hazemd code)
796         memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x400000);
797         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa1307f, 0, 0, radica_bank_select );
798      }
799
1021800   }
1022801
1023   if (is_radica)
802   // detect the King of Fighters '99 unlicensed game
803   if (genesis_last_loaded_image_length == 0x300000)
1024804   {
1025      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa1307f, 0, 0, radica_bank_select );
1026   }
805      static unsigned char kof99sig[] = { 0x20, 0x3c, 0x30, 0x00, 0x00, 0xa1}; // move.l  #$300000A1,d0
1027806
1028   if (is_kof99) {
1029      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, kof99_0xA13000_r );
1030      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13002, 0xA13003, 0, 0, kof99_0xA13002_r );
1031      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA1303e, 0xA1303f, 0, 0, kof99_00A1303E_r );
807      if (!allendianmemcmp(&ROM[0x1fd0d2+relocate],&kof99sig[0],sizeof(kof99sig)))
808      {
809         //memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x300000);
810         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, kof99_0xA13000_r );
811         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13002, 0xA13003, 0, 0, kof99_0xA13002_r );
812         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA1303e, 0xA1303f, 0, 0, kof99_00A1303E_r );
813      }
1032814   }
1033815
1034   if (is_soulb) {
1035      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, soulb_0x400006_r );
1036      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, soulb_0x400002_r );
1037      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, soulb_0x400004_r );
1038   }
1039
1040   if (is_redcliff)
816   // detect the Soul Blade unlicensed game
817   if (genesis_last_loaded_image_length == 0x400000)
1041818   {
1042      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, redclif_prot2_r );
1043      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, redclif_prot_r );
819      static unsigned char soulbsig[] = { 0x33, 0xfc, 0x00, 0x0c, 0x00, 0xff}; // move.w  #$C,($FF020A).l (what happens if check fails)
820
821      if (!allendianmemcmp(&ROM[0x028460+relocate],&soulbsig[0],sizeof(soulbsig)))
822      {
823         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, soulb_0x400006_r );
824         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, soulb_0x400002_r );
825         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, soulb_0x400004_r );
826      }
1044827   }
1045828
1046   if (is_mjlovr)
829   // detect Mahjong Lover unlicensed game
830   if (genesis_last_loaded_image_length == 0x100000)
1047831   {
1048      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, mjlovr_prot_1_r );
1049      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x401000, 0x401001, 0, 0, mjlovr_prot_2_r );
1050   }
832      static unsigned char mjlovrsig[] = { 0x13, 0xf9, 0x00, 0x40, 0x00, 0x00}; // move.b  ($400000).l,($FFFF0C).l (partial)
1051833
1052   if (is_squir)
834      if (!allendianmemcmp(&ROM[0x01b24+relocate],&mjlovrsig[0],sizeof(mjlovrsig)))
835      {
836         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, mjlovr_prot_1_r );
837         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x401000, 0x401001, 0, 0, mjlovr_prot_2_r );
838      }
839   }
840   // detect Squirrel King unlicensed game
841   if (genesis_last_loaded_image_length == 0x100000)
1053842   {
1054      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, squirrel_king_extra_r);
1055      memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, squirrel_king_extra_w);
843      static unsigned char squirsig[] = { 0x26, 0x79, 0x00, 0xff, 0x00, 0xfa};
844
845      if (!allendianmemcmp(&ROM[0x03b4+relocate],&squirsig[0],sizeof(squirsig)))
846      {
847         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, squirrel_king_extra_r);
848         memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, squirrel_king_extra_w);
849      }
1056850   }
1057   if (is_smous)
851   if (genesis_last_loaded_image_length == 0x80000)
1058852   {
1059      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, smous_prot_r );
853      static unsigned char smoussig[] = { 0x4d, 0xf9, 0x00, 0x40, 0x00, 0x02};
854
855      if (!allendianmemcmp(&ROM[0x08c8+relocate],&smoussig[0],sizeof(smoussig)))
856      {
857         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, smous_prot_r );
858      }
1060859   }
1061   if (is_smb)
860   if (genesis_last_loaded_image_length >= 0x200000)
1062861   {
1063      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa13001, 0, 0, smbro_prot_r );
862      static unsigned char smbsig[] = { 0x20, 0x4d, 0x41, 0x52, 0x49, 0x4f};
863
864      if (!allendianmemcmp(&ROM[0xc8cb0+relocate],&smbsig[0],sizeof(smbsig)))
865      {
866         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, smbro_prot_r );
867      }
1064868   }
1065   if (is_smb2)
869   if (genesis_last_loaded_image_length >= 0x200000)
1066870   {
1067      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, smb2_extra_r);
871      static unsigned char smb2sig[] = { 0x4e, 0xb9, 0x00, 0x0f, 0x25, 0x84};
872
873      if (!allendianmemcmp(&ROM[0xf24d6+relocate],&smb2sig[0],sizeof(smb2sig)))
874      {
875         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, smb2_extra_r);
876      }
1068877   }
1069   if (is_19in1)
878   if (genesis_last_loaded_image_length == 0x200000)
1070879   {
1071      memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13039, 0, 0, s19in1_bank);
880      static unsigned char kaijusig[] = { 0x19, 0x7c, 0x00, 0x01, 0x00, 0x00};
881
882      if (!allendianmemcmp(&ROM[0x674e + relocate],&kaijusig[0],sizeof(kaijusig)))
883      {
884         memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x200000);
885         memcpy(&ROM[0x600000],&ROM[VIRGIN_COPY_GEN],0x200000);
886         memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x200000);
887
888         memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x700000, 0x7fffff, 0, 0, g_kaiju_bank_w );
889      }
1072890   }
1073   if (is_15in1)
891
892   if (genesis_last_loaded_image_length == 0x200000)
1074893   {
1075      memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13039, 0, 0, s19in1_bank);
894      static unsigned char chifi3sig[] = { 0xb6, 0x16, 0x66, 0x00, 0x00, 0x4a};
895
896      if (!allendianmemcmp(&ROM[0x1780 + relocate],&chifi3sig[0],sizeof(chifi3sig)))
897      {
898         memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x200000);
899         memcpy(&ROM[0x600000],&ROM[VIRGIN_COPY_GEN],0x200000);
900         memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x200000);
901
902         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x4fffff, 0, 0, g_chifi3_prot_r );
903         memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_chifi3_bank_w );
904      }
1076905   }
1077   if (is_realtec)
906
907
908   if (genesis_last_loaded_image_length == 0x200000)
1078909   {
1079      realtek_old_bank_addr = -1;
1080      memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, realtec_400000_w);
1081      memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x402000, 0x402001, 0, 0, realtec_402000_w);
1082      memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x404000, 0x404001, 0, 0, realtec_404000_w);
910      static unsigned char lionk2sig[] = { 0x26, 0x79, 0x00, 0xff, 0x00, 0xf4};
911
912      if (!allendianmemcmp(&ROM[0x03c2+relocate],&lionk2sig[0],sizeof(lionk2sig)))
913      {
914         memory_install_write16_handler(machine, 0,ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, lion2_prot1_w );
915         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, lion2_prot1_r );
916         memory_install_write16_handler(machine, 0,ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, lion2_prot2_w );
917         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, lion2_prot2_r );
918      }
1083919   }
1084920
1085   if (is_kof98)
921   if (genesis_last_loaded_image_length == 0x100000)
1086922   {
1087      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x480000, 0x480001, 0, 0, g_kof98_aa_r );
1088      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4800e0, 0x4800e1, 0, 0, g_kof98_aa_r );
1089      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4824a0, 0x4824a1, 0, 0, g_kof98_aa_r );
1090      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x488880, 0x488881, 0, 0, g_kof98_aa_r );
923      static unsigned char bugslsig[] = { 0x20, 0x12, 0x13, 0xc0, 0x00, 0xff};
1091924
1092      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4a8820, 0x4a8821, 0, 0, g_kof98_0a_r );
1093      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4f8820, 0x4f8821, 0, 0, g_kof98_00_r );
925      if (!allendianmemcmp(&ROM[0xee0d0+relocate],&bugslsig[0],sizeof(bugslsig)))
926      {
927         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, bugl_extra_r);
928      }
1094929   }
1095930
1096   if (is_elfwor)
931   if (genesis_last_loaded_image_length == 0x100000 && !allendianmemcmp((char *)&ROM[0x0172+relocate], "GAME : ELF WOR", 14))
1097932   {
1098933   /*
1099934   Elf Wor (Unl) - return (0x55 @ 0x400000 OR 0xc9 @ 0x400004) AND (0x0f @ 0x400002 OR 0x18 @ 0x400006). It is probably best to add handlers for all 4 addresses.
r2438r2439
1103938      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, elfwor_0x400002_r );
1104939      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, elfwor_0x400006_r );
1105940   }
941   if (genesis_last_loaded_image_length == 0x200000)
942   {
943      static unsigned char rx3sig[] = { 0x66, 0x00, 0x00, 0x0e, 0x30, 0x3c};
944      if (!allendianmemcmp(&ROM[0xc8b90+relocate],&rx3sig[0],sizeof(rx3sig)))
945      {
946         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, rx3_extra_r);
947      }
948   }
949   if (genesis_last_loaded_image_length == 0x100000)
950   {
951      static unsigned char sbubsig[] = { 0x0c, 0x39, 0x00, 0x55, 0x00, 0x40}; //    cmpi.b  #$55,($400000).l
952      if (!allendianmemcmp(&ROM[0x123e4+relocate],&sbubsig[0],sizeof(sbubsig)))
953      {
954         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, sbub_extra1_r);
955         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, sbub_extra2_r);
956      }
957   }
958   if (genesis_last_loaded_image_length == 0x200000)
959   {
960      static unsigned char kof98sig[] = { 0x9b, 0xfc, 0x00, 0x00, 0x4a, 0x00};
961      if (!allendianmemcmp(&ROM[0x56ae2+relocate],&kof98sig[0],sizeof(kof98sig)))
962      {
963         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x480000, 0x480001, 0, 0, g_kof98_aa_r );
964         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4800e0, 0x4800e1, 0, 0, g_kof98_aa_r );
965         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4824a0, 0x4824a1, 0, 0, g_kof98_aa_r );
966         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x488880, 0x488881, 0, 0, g_kof98_aa_r );
1106967
1107   if (is_lionk2)
968         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4a8820, 0x4a8821, 0, 0, g_kof98_0a_r );
969         memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4f8820, 0x4f8821, 0, 0, g_kof98_00_r );
970      }
971   }
972   if (genesis_last_loaded_image_length == 0x80000)
1108973   {
1109      memory_install_write16_handler(machine, 0,ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, lion2_prot1_w );
1110      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, lion2_prot1_r );
1111      memory_install_write16_handler(machine, 0,ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, lion2_prot2_w );
1112      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, lion2_prot2_r );
974      if (!allendianmemcmp((char *)&ROM[0x7e30e + relocate],"SEGA",4) ||
975          !allendianmemcmp((char *)&ROM[0x7e100 + relocate],"SEGA",4) ||
976          !allendianmemcmp((char *)&ROM[0x7e1e6 + relocate],"SEGA",4))  { // Whac a Critter/mallet legend, Defend the Earth, Funnyworld/ballonboy
977            realtek_old_bank_addr = -1;
978            /* Realtec mapper!*/
979            memcpy(&ROM[0x400000],&ROM[relocate],0x80000);
980            for (mirroraddr = 0; mirroraddr < 0x400000;mirroraddr+=0x2000) {
981               memcpy(ROM+mirroraddr, ROM +  relocate + 0x7e000, 0x002000); /* copy last 8kb across the whole rom region */
982            }
983
984            memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, realtec_400000_w);
985            memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x402000, 0x402001, 0, 0, realtec_402000_w);
986            memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x404000, 0x404001, 0, 0, realtec_404000_w);
987         }
1113988   }
989   // detect 'Super 19 in 1'
990   if (genesis_last_loaded_image_length == 0x400000)
991   {
992      static unsigned char s19in1sig[] = { 0x13, 0xc0, 0x00, 0xa1, 0x30, 0x38};
1114993
1115   if (is_rx3)
994      if (!allendianmemcmp(&ROM[0x1e700+relocate],&s19in1sig[0],sizeof(s19in1sig))) // super19in1
995      {
996         memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x400000); // allow hard reset to menu
997         memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13039, 0, 0, s19in1_bank);
998      }
999
1000   }
1001   // detect 'Super 15 in 1'
1002   if (genesis_last_loaded_image_length == 0x200000)
11161003   {
1117      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, rx3_extra_r);
1004      static unsigned char s15in1sig[] = { 0x22, 0x3c, 0x00, 0xa1, 0x30, 0x00};
1005
1006      if (!allendianmemcmp(&ROM[0x17bb2+relocate],&s15in1sig[0],sizeof(s15in1sig))) // super15in1
1007      {
1008         memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x200000); // allow hard reset to menu
1009         memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13039, 0, 0, s19in1_bank);
1010      }
11181011   }
11191012
1120   if (is_bugsl)
1013        /* check if cart has battery save */
1014   genesis_sram_len = 0;
1015   genesis_sram = NULL;
1016   if (ROM[0x1b1] == 'R' && ROM[0x1b0] == 'A')
11211017   {
1122      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, bugl_extra_r);
1018      genesis_sram_start = (ROM[0x1b5] << 24 | ROM[0x1b4] << 16 | ROM[0x1b7] << 8 | ROM[0x1b6]);
1019      genesis_sram_len = (ROM[0x1b9] << 24 | ROM[0x1b8] << 16 | ROM[0x1bb] << 8 | ROM[0x1ba]);
11231020   }
11241021
1125   if (is_sbub)
1022   if (genesis_sram_start != genesis_sram_len)
11261023   {
1127      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, sbub_extra1_r);
1128      memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, sbub_extra2_r);
1129}
1024                if (genesis_sram_start & 1)
1025                        genesis_sram_start -= 1;
1026                if (!(genesis_sram_len & 1))
1027                        genesis_sram_len += 1;
1028      genesis_sram_len -= (genesis_sram_start - 1);
1029      genesis_sram = auto_malloc (genesis_sram_len);
1030      memset(genesis_sram, 0, genesis_sram_len);
1031      image_battery_load(image_from_devtype_and_index(IO_CARTSLOT,0), genesis_sram, genesis_sram_len);
11301032
1131   /* install NOP handler for TMSS */
1132   memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA14000, 0xA14003, 0, 0, genesis_TMSS_bank_w);
1033                if (genesis_last_loaded_image_length - 0x200 < genesis_sram_start)
1034      {
1035                        genesis_sram_active = 1;
1036      }
11331037
1134}
1038        memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, genesis_sram_start & 0x3fffff, (genesis_sram_start + genesis_sram_len - 1) & 0x3fffff, 0, 0, genesis_sram_read);
1039        memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, genesis_sram_start & 0x3fffff, (genesis_sram_start + genesis_sram_len - 1) & 0x3fffff, 0, 0, genesis_sram_write);
1040        memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa130f0, 0xa130f1, 0, 0, genesis_sram_toggle);
1041   }
11351042
1136static DRIVER_INIT( genusa )
1137{
1138   DRIVER_INIT_CALL(gencommon);
1139   DRIVER_INIT_CALL(megadriv);
1140}
11411043
1142static DRIVER_INIT( geneur )
1143{
1144   DRIVER_INIT_CALL(gencommon);
1145   DRIVER_INIT_CALL(megadrie);
1044   /* install NOP handler for TMSS */
1045   memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA14000, 0xA14003, 0, 0, genesis_TMSS_bank_w);
11461046}
11471047
1148static DRIVER_INIT( genjpn )
1149{
1150   DRIVER_INIT_CALL(gencommon);
1151   DRIVER_INIT_CALL(megadrij);
1152}
11531048
11541049/***************************************************************************
11551050
r2438r2439
11571052
11581053***************************************************************************/
11591054
1160/*    YEAR  NAME      PARENT    COMPAT  MACHINE    INPUT     INIT   CONFIG   COMPANY   FULLNAME */
1161CONS( 1989, genesis,  0,      0,   megadriv,  megadri6, genusa,   genesis, "Sega",   "Genesis (USA, NTSC)", 0)
1162CONS( 1993, gensvp,   genesis,   0,   megdsvp,   megdsvp, megadsvp,   genesis, "Sega",   "Genesis (USA, NTSC, w/SVP)", 0)
1163CONS( 1990, megadriv, genesis,   0,   megadriv,  megadri6, geneur,   genesis, "Sega",   "Mega Drive (Europe, PAL)", 0)
1164CONS( 1988, megadrij, genesis,   0,   megadriv,  megadri6, genjpn,   genesis, "Sega",   "Mega Drive (Japan, NTSC)", 0)
1055/*    YEAR  NAME      PARENT    COMPAT  MACHINE    INPUT     INIT        CONFIG   COMPANY   FULLNAME */
1056CONS( 1989, genesis,  0,      0,      megadriv,  megadri6, genusa,   genesis, "Sega",   "Genesis (USA, NTSC)", 0)
1057CONS( 1993, gensvp,   genesis,   0,      megdsvp,   megdsvp,  megadsvp,   genesis, "Sega",   "Genesis (USA, NTSC, w/SVP)", 0)
1058CONS( 1990, megadriv, genesis,   0,      megadriv,  megadri6, geneur,   genesis, "Sega",   "Mega Drive (Europe, PAL)", 0)
1059CONS( 1988, megadrij, genesis,   0,      megadriv,  megadri6, genjpn,   genesis, "Sega",   "Mega Drive (Japan, NTSC)", 0)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team