Previous 15994 Revisions Next

r5807 Saturday 19th September, 2009 at 21:13:20 UTC by MooglyGuy
Porting over Harmony's and Fabio's changes from MAME, adds ST010 and SPC7110 support. SPC7110 emulation lacks RTC support.
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mess]mess.mak
[src/mess/machine]snescart.c

src/mame/machine/snes.c
r5806r5807
66
77  R. Belmont
88  Anthony Kruize
9  Harmony
910  Based on the original code by Lee Hammerton (aka Savoury Snax)
1011  Thanks to Anomie for invaluable technical information.
1112  Thanks to byuu for invaluable technical information.
r5806r5807
3839static UINT16 hblank_offset;
3940UINT16 snes_htmult;   /* in 512 wide, we run HTOTAL double and halve it on latching */
4041UINT8 snes_has_addon_chip;
42UINT32 snes_rom_size;
4143
4244// full graphic variables
4345static UINT16 vram_fgr_high, vram_fgr_increment, vram_fgr_count, vram_fgr_mask, vram_fgr_shift, vram_read_buffer;
r5806r5807
6466#include "machine/snescx4.c"
6567#include "machine/snesrtc.c"
6668#include "machine/snessdd1.c"
69#include "machine/snes7110.c"
70#include "machine/snesst10.c"
6771
6872/*************************************
6973
r5806r5807
379383         offset += 0x4300;
380384      }
381385   }
386   else if(snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC)
387   {
388      UINT16 limit = (snes_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f;
389      if(offset >= 0x4800 && offset < limit)
390      {
391         return spc7110_mmio_read(space->machine, offset);
392      }
393   }
382394
383395   /* offset is from 0x000000 */
384396   switch( offset )
r5806r5807
750762         offset += 0x4300;
751763      }
752764   }
765   else if(snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC)
766   {
767      UINT16 limit = (snes_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f;
768      if(offset >= 0x4800 && offset < limit)
769      {
770         spc7110_mmio_write(space->machine, (UINT32)offset, data);
771         return;
772      }
773   }
753774
754775   /* offset is from 0x000000 */
755776   switch( offset )
r5806r5807
14701491         value = (address < 0x7000) ? DSP1_getDr() : DSP1_getSr();
14711492      else if (snes_has_addon_chip == HAS_CX4)
14721493         value = CX4_read(address - 0x6000);
1494      else if (snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC)
1495      {
1496         value = snes_ram[0x306000 + (offset & 0x1fff)];
1497      }
14731498      else
14741499      {
14751500         logerror( "snes_r_bank1: Unmapped external chip read: %04x\n", address );
r5806r5807
15041529         value = obc1_read (space, offset);
15051530      else if (snes_has_addon_chip == HAS_DSP2)
15061531         value = (address < 0x7000) ? DSP2_read() : 0x00;
1532      else if (snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC)
1533      {
1534         value = snes_ram[0x306000 + (offset & 0x1fff)];
1535      }
15071536      else if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0))
15081537      {
15091538         int mask = ((snes_cart.sram * 1024) - 1);            /* Limit SRAM size to what's actually present */
r5806r5807
15651594   {
15661595      value = snes_ram[0x600000 + offset];
15671596   }
1597   else if (snes_has_addon_chip == HAS_ST010 && offset >= 0x80000 && address < 0x1000)
1598   {
1599      value = st010_read(address);
1600   }
15681601   else if (snes_cart.mode & 5)                     /* Mode 20 & 22 */
15691602   {
15701603      if (address >= 0x8000)
r5806r5807
16271660         logerror( "snes_r_bank6 hit in Super FX mode, please fix me\n" );
16281661      else if (snes_cart.mode != SNES_MODE_25)
16291662         value = memory_read_byte(space, offset);
1663      else if (snes_has_addon_chip == HAS_CX4)
1664      {
1665         //printf( "R: CX4 hit from 0x800000\n" );
1666      }
16301667      else                     /* Mode 25 has SRAM not mirrored from lower banks */
16311668      {
16321669         if (address < 0x6000)
r5806r5807
16721709   {
16731710      logerror( "snes_r_bank7 hit in Super FX mode, please fix me\n" );
16741711   }
1712   else if (snes_has_addon_chip == HAS_ST010 && offset >= 0x280000 && offset < 0x300000 && address < 0x1000)
1713   {
1714      value = st010_read(address);
1715   }
16751716   else if (snes_cart.mode & 5)            /* Mode 20 & 22 */
16761717   {
16771718      if (address < 0x8000)
r5806r5807
17091750         DSP1_setDr(data);
17101751      else if (snes_has_addon_chip == HAS_CX4)
17111752         CX4_write(space->machine, address - 0x6000, data);
1753      else if (snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC)
1754      {
1755         snes_ram[0x306000 + (offset & 0x1fff)] = data;
1756      }
17121757      else
17131758         logerror( "snes_w_bank1: Attempt to write to reserved address: %x = %02x\n", offset, data );
17141759   }
r5806r5807
17371782         obc1_write(space, offset, data);
17381783      else if (snes_has_addon_chip == HAS_DSP2)
17391784         DSP2_write(data);
1785      else if (snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC)
1786      {
1787         snes_ram[0x306000 + (offset & 0x1fff)] = data;
1788      }
17401789      else if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0))
17411790      {
17421791         int mask = ((snes_cart.sram * 1024) - 1);         /* Limit SRAM size to what's actually present */
r5806r5807
17671816
17681817   if (snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL)
17691818   {
1770      //printf( "Writing %02x to %08x\n", data, 0x600000 + offset );
17711819      snes_ram[0x600000 + offset] = data;
17721820   }
1821   else if (snes_has_addon_chip == HAS_ST010 && offset >= 0x80000 && address < 0x1000)
1822   {
1823      st010_write(address, data);
1824   }
17731825   else if (snes_cart.mode & 5)               /* Mode 20 & 22 */
17741826   {
17751827      if (address >= 0x8000)
r5806r5807
18301882      {
18311883         logerror( "snes_w_bank6 hit (RAM) in Super FX mode, please fix me\n" );
18321884      }
1885      else if(snes_has_addon_chip == HAS_CX4)
1886      {
1887         //printf( "R: CX4 hit from 0x800000\n" );
1888      }
18331889      if (snes_cart.mode != SNES_MODE_25)
18341890      {
18351891         if (offset < 0x300000)
r5806r5807
18871943         logerror( "snes_w_bank7 hit (RAM) in Super FX mode, please fix me\n" );
18881944      }
18891945   }
1946   else if (snes_has_addon_chip == HAS_ST010 && offset >= 0x280000 && offset < 0x300000 && address < 0x1000)
1947   {
1948      st010_write(address, data);
1949   }
18901950   else if (snes_cart.mode & 5)            /* Mode 20 & 22 */
18911951   {
18921952      if (address < 0x8000)
r5806r5807
19932053         InitDSP4();
19942054         break;
19952055
2056      case HAS_RTC:
2057         srtc_reset(machine);
2058         break;
2059
2060      case HAS_SDD1:
2061         sdd1_reset(machine);
2062         break;
2063
19962064      case HAS_OBC1:
19972065         obc1_init();
19982066         break;
19992067
2068      case HAS_ST010:
2069         st010_reset();
2070         break;
2071
20002072      default:
20012073         break;
20022074   }
r5806r5807
20592131   snes_ram[WRDIVH] = 0xff;
20602132
20612133   sdd1_init(machine);
2134   spc7110_init(machine);
2135   st010_init(machine);
20622136}
20632137
20642138MACHINE_RESET( snes )
r5806r5807
20812155   snes_htmult = 1;
20822156   snes_ppu.interlace = 1;
20832157   snes_ppu.obj_interlace = 1;
2084
2085   srtc_reset(machine);
2086   sdd1_reset(machine);
20872158}
20882159
20892160
r5806r5807
20952166   UINT8  *rom;
20962167
20972168   rom = memory_region(machine, "user3");
2098   snes_ram = auto_alloc_array(machine, UINT8, 0x1000000);
2099   memset(snes_ram, 0, 0x1000000);
2169   snes_ram = auto_alloc_array(machine, UINT8, 0x1400000);
2170   memset(snes_ram, 0, 0x1400000);
21002171
21012172   /* all NSS games seem to use MODE 20 */
21022173   snes_cart.mode = SNES_MODE_20;
r5806r5807
21612232   UINT8  *rom;
21622233
21632234   rom = memory_region(machine, "user3");
2164   snes_ram = auto_alloc_array(machine, UINT8, 0x1000000);
2165   memset(snes_ram, 0, 0x1000000);
2235   snes_ram = auto_alloc_array(machine, UINT8, 0x1400000);
2236   memset(snes_ram, 0, 0x1400000);
21662237
21672238   snes_cart.mode = SNES_MODE_21;
21682239   snes_cart.sram_max = 0x40000;
src/mame/includes/snes.h
r5806r5807
5151#define SNES_CGRAM_SIZE      0x202   /* 256 16-bit colours + 1 tacked on 16-bit colour for fixed colour */
5252#define SNES_OAM_SIZE      0x440   /* 1088 bytes of Object Attribute Memory */
5353#define SNES_SPCRAM_SIZE   0x10000   /* 64kb of spc700 ram */
54#define SNES_EXROM_START   0x1000000
5455#define FIXED_COLOUR      256      /* Position in cgram for fixed colour */
5556/* Definitions for PPU Memory-Mapped registers */
5657#define INIDISP         0x2100
r5806r5807
410411WRITE_LINE_DEVICE_HANDLER( snes_extern_irq_w );
411412
412413extern UINT8 snes_has_addon_chip;
414extern UINT32 snes_rom_size;
413415extern UINT16 snes_htmult;
414416
415417extern void snes_gdma( const address_space *space, UINT8 channels );
src/mess/machine/snescart.c
r5806r5807
351351   snes_ram = memory_region(machine, "maincpu");
352352   memset( snes_ram, 0, 0x1000000 );
353353
354   snes_rom_size = image_length(image);
355
354356   /* Check for a header (512 bytes) */
355357   offset = 512;
356358   image_fread(image, header, 512);
r5806r5807
359361      /* Found an SWC identifier */
360362      logerror("Found header(SWC) - Skipped\n");
361363   }
362   else if ((header[0] | (header[1] << 8)) == (((image_length(image) - 512) / 1024) / 8))
364   else if ((header[0] | (header[1] << 8)) == (((snes_rom_size - 512) / 1024) / 8))
363365   {
364366      /* Some headers have the rom size at the start, if this matches with the
365367         * actual rom size, we probably have a header */
366368      logerror("Found header(size) - Skipped\n");
367369   }
368   else if ((image_length(image) % 0x8000) == 512)
370   else if ((snes_rom_size % 0x8000) == 512)
369371   {
370372      /* As a last check we'll see if there's exactly 512 bytes extra to this
371373         * image. */
r5806r5807
379381      image_fseek(image, offset, SEEK_SET);
380382   }
381383
384   snes_rom_size -= offset;
385
382386   /* We need to take a sample to test what mode we need to be in (the
383387   sample has to be quite large to cope with large carts in ExHiRom) */
384388   image_fread(image, temp_buffer, 0x40ffff);
r5806r5807
395399
396400   if ((valid_mode20 >= valid_mode21) && (valid_mode20 >= valid_mode25))
397401   {
398      if ((temp_buffer[0x007fd5] == 0x32) || ((image_length(image) - offset) > 0x401000))
402      if ((temp_buffer[0x007fd5] == 0x32) || ((snes_rom_size - offset) > 0x401000))
399403         snes_cart.mode = SNES_MODE_22;   // ExLoRom
400404      else
401405         snes_cart.mode = SNES_MODE_20;   // LoRom
r5806r5807
416420
417421   /* Loading data */
418422   ROM = memory_region(image->machine, "cart");
419   length = image_fread(image, ROM, image_length(image) - offset);
423   length = image_fread(image, ROM, snes_rom_size - offset);
420424
421425   /* FIXME: Insert crc check here */
422426
423427   /* How many blocks of data are available to be loaded? */
424   total_blocks = ((image_length(image) - offset) / (snes_cart.mode & 0x05 ? 0x8000 : 0x10000));
428   total_blocks = ((snes_rom_size - offset) / (snes_cart.mode & 0x05 ? 0x8000 : 0x10000));
425429   read_blocks = 0;
426430
427431   /* Loading all the data blocks from cart, we only partially cover banks 0x00 to 0x7f. Therefore, we
r5806r5807
499503         {
500504            /* Loading data */
501505            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &ROM[0x400000 + read_blocks * 0x10000], 0x10000);
506            memcpy(&snes_ram[0x1000000 + read_blocks * 0x10000], &snes_ram[0x400000 + read_blocks * 0x10000], 0x10000);
502507            /* Mirroring */
503508            memcpy(&snes_ram[0x8000 + read_blocks * 0x10000], &snes_ram[0x408000 + read_blocks * 0x10000], 0x8000);
504509            read_blocks++;
r5806r5807
652657         case 0x34:
653658         case 0x35:
654659            if (snes_r_bank1(space, 0x00ffd5) == 0x23)
655            {   
660            {
656661               snes_has_addon_chip = HAS_SA1;
657662               supported_type = 0;
658663            }
r5806r5807
661666         case 0x43:
662667         case 0x45:
663668            if (snes_r_bank1(space, 0x00ffd5) == 0x32)
669            {
664670               snes_has_addon_chip = HAS_SDD1;
671            }
665672            break;
666673
667674         case 0x55:
668675            if (snes_r_bank1(space, 0x00ffd5) == 0x35)
669            {   
676            {
670677               snes_has_addon_chip = HAS_RTC;
671678               supported_type = 0;
672679            }
r5806r5807
690697            else if (snes_r_bank1(space, 0x00ffd5) == 0x3a)
691698            {
692699               snes_has_addon_chip = HAS_SPC7110;
693               supported_type = 0;
694700            }
695701            break;
696702
r5806r5807
705711            else
706712            {
707713               snes_has_addon_chip = HAS_ST010;
708               supported_type = 0;
709714            }
710715            break;
711716
r5806r5807
760765      logerror( "===========\n\n" );
761766      logerror( "\tTotal blocks:  %d (%dmb)\n", total_blocks, total_blocks / (snes_cart.mode & 5 ? 32 : 16) );
762767      logerror( "\tROM bank size: %s (LoROM: %d , HiROM: %d, ExHiROM: %d)\n",
763                        (snes_cart.mode == SNES_MODE_20) ? "LoROM" :
768                        (snes_cart.mode == SNES_MODE_20) ? "LoROM" :
764769                        (snes_cart.mode == SNES_MODE_21) ? "HiROM" :
765770                        (snes_cart.mode == SNES_MODE_22) ? "ExLoROM" : "ExHiROM",
766771                              valid_mode20, valid_mode21, valid_mode25);
src/mess/mess.mak
r5806r5807
14981498   $(MESS_DRIVERS)/ptcsol.o   \
14991499   $(MESS_DRIVERS)/p8k.o      \
15001500
1501
1502
15011503#-------------------------------------------------
1504# miscellaneous dependencies
1505#-------------------------------------------------
1506
1507$(MAME_MACHINE)/snes.o:    $(MAMESRC)/machine/snesdsp1.c \
1508            $(MAMESRC)/machine/snesdsp2.c \
1509            $(MAMESRC)/machine/snesobc1.c \
1510            $(MAMESRC)/machine/snesrtc.c \
1511            $(MAMESRC)/machine/snessdd1.c \
1512            $(MAMESRC)/machine/snescx4.c \
1513            $(MAMESRC)/machine/snes7110.c \
1514            $(MAMESRC)/machine/snesst10.c
1515
1516$(MESS_VIDEO)/gba.o:       $(MESSSRC)/video/gbamode0.c \
1517            $(MESSSRC)/video/gbamode1.c \
1518            $(MESSSRC)/video/gbamode2.c \
1519            $(MESSSRC)/video/gbam345.c
1520
1521#-------------------------------------------------
15021522# layout dependencies
15031523#-------------------------------------------------
15041524

Previous 15994 Revisions Next


© 1998-2018 The MESS Team