Ejemplo n.º 1
0
		void Init(GameInfo game, byte[] rom)
		{
			Controller = NullController.GetNullController();
			Cpu = new HuC6280(CoreComm);
			VCE = new VCE();
			VDC1 = new VDC(this, Cpu, VCE);
			PSG = new HuC6280PSG();
			SCSI = new ScsiCDBus(this, disc);

			Cpu.Logger = (s) => CoreComm.Tracer.Put(s);

			if (TurboGrafx)
			{
				Ram = new byte[0x2000];
				Cpu.ReadMemory21 = ReadMemory;
				Cpu.WriteMemory21 = WriteMemory;
				Cpu.WriteVDC = VDC1.WriteVDC;
				soundProvider = PSG;
				CDAudio = new CDAudio(null, 0);
			}

			else if (SuperGrafx)
			{
				VDC2 = new VDC(this, Cpu, VCE);
				VPC = new VPC(this, VDC1, VDC2, VCE, Cpu);
				Ram = new byte[0x8000];
				Cpu.ReadMemory21 = ReadMemorySGX;
				Cpu.WriteMemory21 = WriteMemorySGX;
				Cpu.WriteVDC = VDC1.WriteVDC;
				soundProvider = PSG;
				CDAudio = new CDAudio(null, 0);
			}

			else if (TurboCD)
			{
				Ram = new byte[0x2000];
				CDRam = new byte[0x10000];
				ADPCM = new ADPCM(this, SCSI);
				Cpu.ReadMemory21 = ReadMemoryCD;
				Cpu.WriteMemory21 = WriteMemoryCD;
				Cpu.WriteVDC = VDC1.WriteVDC;
				CDAudio = new CDAudio(disc);
				SetCDAudioCallback();
				PSG.MaxVolume = short.MaxValue * 3 / 4;
				SoundMixer = new SoundMixer(PSG, CDAudio, ADPCM);
				SoundSynchronizer = new MetaspuSoundProvider(ESynchMethod.ESynchMethod_V);
				soundProvider = SoundSynchronizer;
				Cpu.ThinkAction = (cycles) => { SCSI.Think(); ADPCM.Think(cycles); };
			}

			if (rom.Length == 0x60000)
			{
				// 384k roms require special loading code. Why ;_;
				// In memory, 384k roms look like [1st 256k][Then full 384k]
				RomData = new byte[0xA0000];
				var origRom = rom;
				for (int i = 0; i < 0x40000; i++)
					RomData[i] = origRom[i];
				for (int i = 0; i < 0x60000; i++)
					RomData[i + 0x40000] = origRom[i];
				RomLength = RomData.Length;
			}
			else if (rom.Length > 1024 * 1024)
			{
				// If the rom is bigger than 1 megabyte, switch to Street Fighter 2 mapper
				Cpu.ReadMemory21 = ReadMemorySF2;
				Cpu.WriteMemory21 = WriteMemorySF2;
				RomData = rom;
				RomLength = RomData.Length;
				// user request: current value of the SF2MapperLatch on the tracelogger
				Cpu.Logger = (s) => CoreComm.Tracer.Put(string.Format("{0:X1}:{1}", SF2MapperLatch, s));
			}
			else
			{
				// normal rom.
				RomData = rom;
				RomLength = RomData.Length;
			}

			if (game["BRAM"] || Type == NecSystemType.TurboCD)
			{
				BramEnabled = true;
				BRAM = new byte[2048];

				// pre-format BRAM. damn are we helpful.
				BRAM[0] = 0x48; BRAM[1] = 0x55; BRAM[2] = 0x42; BRAM[3] = 0x4D;
				BRAM[4] = 0x00; BRAM[5] = 0x88; BRAM[6] = 0x10; BRAM[7] = 0x80;
			}

			if (game["SuperSysCard"])
				SuperRam = new byte[0x30000];

			if (game["ArcadeCard"])
			{
				ArcadeRam = new byte[0x200000];
				ArcadeCard = true;
				ArcadeCardRewindHack = _settings.ArcadeCardRewindHack;
				for (int i = 0; i < 4; i++)
					ArcadePage[i] = new ArcadeCardPage();
			}

			if (game["PopulousSRAM"])
			{
				PopulousRAM = new byte[0x8000];
				Cpu.ReadMemory21 = ReadMemoryPopulous;
				Cpu.WriteMemory21 = WriteMemoryPopulous;
			}

			// the gamedb can force sprite limit on, ignoring settings
			if (game["ForceSpriteLimit"] || game.NotInDatabase)
				ForceSpriteLimit = true;

			if (game["CdVol"])
				CDAudio.MaxVolume = int.Parse(game.OptionValue("CdVol"));
			if (game["PsgVol"])
				PSG.MaxVolume = int.Parse(game.OptionValue("PsgVol"));
			if (game["AdpcmVol"])
				ADPCM.MaxVolume = int.Parse(game.OptionValue("AdpcmVol"));
			// the gamedb can also force equalizevolumes on
			if (TurboCD && (_settings.EqualizeVolume || game["EqualizeVolumes"] || game.NotInDatabase))
				SoundMixer.EqualizeVolumes();

			// Ok, yes, HBlankPeriod's only purpose is game-specific hax.
			// 1) At least they're not coded directly into the emulator, but instead data-driven.
			// 2) The games which have custom HBlankPeriods work without it, the override only
			//    serves to clean up minor gfx anomalies.
			// 3) There's no point in haxing the timing with incorrect values in an attempt to avoid this.
			//    The proper fix is cycle-accurate/bus-accurate timing. That isn't coming to the C# 
			//    version of this core. Let's just acknolwedge that the timing is imperfect and fix
			//    it in the least intrusive and most honest way we can.

			if (game["HBlankPeriod"])
				VDC1.HBlankCycles = game.GetIntValue("HBlankPeriod");

			// This is also a hack. Proper multi-res/TV emulation will be a native-code core feature.

			if (game["MultiResHack"])
				VDC1.MultiResHack = game.GetIntValue("MultiResHack");

			Cpu.ResetPC();
			SetupMemoryDomains();
		}
Ejemplo n.º 2
0
        void Init(GameInfo game, byte[] rom)
        {
            Controller = NullController.GetNullController();
            Cpu        = new HuC6280(MemoryCallbacks);
            VCE        = new VCE();
            VDC1       = new VDC(this, Cpu, VCE);
            PSG        = new HuC6280PSG();
            SCSI       = new ScsiCDBus(this, disc);

            Cpu.Logger = (s) => Tracer.Put(s);

            if (TurboGrafx)
            {
                Ram = new byte[0x2000];
                Cpu.ReadMemory21  = ReadMemory;
                Cpu.WriteMemory21 = WriteMemory;
                Cpu.WriteVDC      = VDC1.WriteVDC;
                soundProvider     = PSG;
                CDAudio           = new CDAudio(null, 0);
            }

            else if (SuperGrafx)
            {
                VDC2              = new VDC(this, Cpu, VCE);
                VPC               = new VPC(this, VDC1, VDC2, VCE, Cpu);
                Ram               = new byte[0x8000];
                Cpu.ReadMemory21  = ReadMemorySGX;
                Cpu.WriteMemory21 = WriteMemorySGX;
                Cpu.WriteVDC      = VDC1.WriteVDC;
                soundProvider     = PSG;
                CDAudio           = new CDAudio(null, 0);
            }

            else if (TurboCD)
            {
                Ram               = new byte[0x2000];
                CDRam             = new byte[0x10000];
                ADPCM             = new ADPCM(this, SCSI);
                Cpu.ReadMemory21  = ReadMemoryCD;
                Cpu.WriteMemory21 = WriteMemoryCD;
                Cpu.WriteVDC      = VDC1.WriteVDC;
                CDAudio           = new CDAudio(disc);
                SetCDAudioCallback();
                PSG.MaxVolume     = short.MaxValue * 3 / 4;
                SoundMixer        = new SoundMixer(PSG, CDAudio, ADPCM);
                SoundSynchronizer = new MetaspuSoundProvider(ESynchMethod.ESynchMethod_V);
                soundProvider     = SoundSynchronizer;
                Cpu.ThinkAction   = (cycles) => { SCSI.Think(); ADPCM.Think(cycles); };
            }

            if (rom.Length == 0x60000)
            {
                // 384k roms require special loading code. Why ;_;
                // In memory, 384k roms look like [1st 256k][Then full 384k]
                RomData = new byte[0xA0000];
                var origRom = rom;
                for (int i = 0; i < 0x40000; i++)
                {
                    RomData[i] = origRom[i];
                }
                for (int i = 0; i < 0x60000; i++)
                {
                    RomData[i + 0x40000] = origRom[i];
                }
                RomLength = RomData.Length;
            }
            else if (rom.Length > 1024 * 1024)
            {
                // If the rom is bigger than 1 megabyte, switch to Street Fighter 2 mapper
                Cpu.ReadMemory21  = ReadMemorySF2;
                Cpu.WriteMemory21 = WriteMemorySF2;
                RomData           = rom;
                RomLength         = RomData.Length;
                // user request: current value of the SF2MapperLatch on the tracelogger
                Cpu.Logger = (s) => Tracer.Put(new TraceInfo
                {
                    Disassembly  = string.Format("{0:X1}:{1}", SF2MapperLatch, s),
                    RegisterInfo = ""
                });
            }
            else
            {
                // normal rom.
                RomData   = rom;
                RomLength = RomData.Length;
            }

            if (game["BRAM"] || Type == NecSystemType.TurboCD)
            {
                BramEnabled = true;
                BRAM        = new byte[2048];

                // pre-format BRAM. damn are we helpful.
                BRAM[0] = 0x48; BRAM[1] = 0x55; BRAM[2] = 0x42; BRAM[3] = 0x4D;
                BRAM[4] = 0x00; BRAM[5] = 0x88; BRAM[6] = 0x10; BRAM[7] = 0x80;
            }

            if (game["SuperSysCard"])
            {
                SuperRam = new byte[0x30000];
            }

            if (game["ArcadeCard"])
            {
                ArcadeRam            = new byte[0x200000];
                ArcadeCard           = true;
                ArcadeCardRewindHack = _settings.ArcadeCardRewindHack;
                for (int i = 0; i < 4; i++)
                {
                    ArcadePage[i] = new ArcadeCardPage();
                }
            }

            if (game["PopulousSRAM"])
            {
                PopulousRAM       = new byte[0x8000];
                Cpu.ReadMemory21  = ReadMemoryPopulous;
                Cpu.WriteMemory21 = WriteMemoryPopulous;
            }

            // the gamedb can force sprite limit on, ignoring settings
            if (game["ForceSpriteLimit"] || game.NotInDatabase)
            {
                ForceSpriteLimit = true;
            }

            if (game["CdVol"])
            {
                CDAudio.MaxVolume = int.Parse(game.OptionValue("CdVol"));
            }
            if (game["PsgVol"])
            {
                PSG.MaxVolume = int.Parse(game.OptionValue("PsgVol"));
            }
            if (game["AdpcmVol"])
            {
                ADPCM.MaxVolume = int.Parse(game.OptionValue("AdpcmVol"));
            }
            // the gamedb can also force equalizevolumes on
            if (TurboCD && (_settings.EqualizeVolume || game["EqualizeVolumes"] || game.NotInDatabase))
            {
                SoundMixer.EqualizeVolumes();
            }

            // Ok, yes, HBlankPeriod's only purpose is game-specific hax.
            // 1) At least they're not coded directly into the emulator, but instead data-driven.
            // 2) The games which have custom HBlankPeriods work without it, the override only
            //    serves to clean up minor gfx anomalies.
            // 3) There's no point in haxing the timing with incorrect values in an attempt to avoid this.
            //    The proper fix is cycle-accurate/bus-accurate timing. That isn't coming to the C#
            //    version of this core. Let's just acknolwedge that the timing is imperfect and fix
            //    it in the least intrusive and most honest way we can.

            if (game["HBlankPeriod"])
            {
                VDC1.HBlankCycles = game.GetIntValue("HBlankPeriod");
            }

            // This is also a hack. Proper multi-res/TV emulation will be a native-code core feature.

            if (game["MultiResHack"])
            {
                VDC1.MultiResHack = game.GetIntValue("MultiResHack");
            }

            Cpu.ResetPC();

            Tracer = new TraceBuffer {
                Header = Cpu.TraceHeader
            };
            var ser = new BasicServiceProvider(this);

            ServiceProvider = ser;
            ser.Register <ITraceable>(Tracer);
            ser.Register <IDisassemblable>(Cpu);
            ser.Register <IVideoProvider>((IVideoProvider)VPC ?? VDC1);
            SetupMemoryDomains();
        }
Ejemplo n.º 3
0
        private void SyncState(Serializer ser)
        {
            ser.BeginSection("PCEngine");
            Cpu.SyncState(ser);
            VCE.SyncState(ser);
            VDC1.SyncState(ser, 1);
            PSG.SyncState(ser);

            if (SuperGrafx)
            {
                VPC.SyncState(ser);
                VDC2.SyncState(ser, 2);
            }

            if (TurboCD)
            {
                ADPCM.SyncState(ser);
                CDAudio.SyncState(ser);
                SCSI.SyncState(ser);

                ser.Sync("CDRAM", ref CDRam, false);
                if (SuperRam != null)
                {
                    ser.Sync("SuperRAM", ref SuperRam, false);
                }

                if (ArcadeCard)
                {
                    ArcadeCardSyncState(ser);
                }
            }

            ser.Sync("RAM", ref Ram, false);
            ser.Sync("IOBuffer", ref IOBuffer);
            ser.Sync("CdIoPorts", ref CdIoPorts, false);
            ser.Sync("BramLocked", ref BramLocked);

            ser.Sync("Frame", ref frame);
            ser.Sync("Lag", ref _lagCount);
            ser.Sync("IsLag", ref _isLag);
            if (Cpu.ReadMemory21 == ReadMemorySF2)
            {
                ser.Sync("SF2MapperLatch", ref SF2MapperLatch);
            }

            if (PopulousRAM != null)
            {
                ser.Sync("PopulousRAM", ref PopulousRAM, false);
            }

            if (BRAM != null)
            {
                ser.Sync("BRAM", ref BRAM, false);
            }

            ser.EndSection();

            if (ser.IsReader)
            {
                SyncAllByteArrayDomains();
            }
        }
Ejemplo n.º 4
0
        void WriteCD(int addr, byte value)
        {
            if (!TurboCD && !BramEnabled)
            {
                return;                 // flee if no turboCD hooked up
            }
            if (!TurboCD && addr != 0x1FF807)
            {
                return;                 // only bram port available unless full TurobCD mode.
            }
            switch (addr & 0x1FFF)
            {
            case 0x1800:                     // SCSI Drive Control Line
                CdIoPorts[0] = value;
                SCSI.SEL     = true;
                SCSI.Think();
                SCSI.SEL = false;
                SCSI.Think();
                break;

            case 0x1801:                     // CDC Command
                CdIoPorts[1]  = value;
                SCSI.DataBits = value;
                SCSI.Think();
                break;

            case 0x1802:                     // ACK and Interrupt Control
                CdIoPorts[2] = value;
                SCSI.ACK     = ((value & 0x80) != 0);

                SCSI.Think();
                RefreshIRQ2();
                break;

            case 0x1804:                     // CD Reset Command
                CdIoPorts[4] = value;
                SCSI.RST     = ((value & 0x02) != 0);
                SCSI.Think();
                if (SCSI.RST)
                {
                    CdIoPorts[3] &= 0x8F;                             // Clear interrupt control bits
                    RefreshIRQ2();
                }
                break;

            case 0x1805:
            case 0x1806:
                // Latch CDDA data... no action needed for us (because we cheat)
                break;

            case 0x1807:                     // BRAM Unlock
                if (BramEnabled && (value & 0x80) != 0)
                {
                    BramLocked = false;
                }
                break;

            case 0x1808:                     // ADPCM address LSB
                ADPCM.IOAddress &= 0xFF00;
                ADPCM.IOAddress |= value;
                if ((CdIoPorts[0x0D] & 0x10) != 0)
                {
                    Console.WriteLine("doing silly thing");
                }
                break;

            case 0x1809:                     // ADPCM address MSB
                ADPCM.IOAddress &= 0x00FF;
                ADPCM.IOAddress |= (ushort)(value << 8);
                if ((CdIoPorts[0x0D] & 0x10) != 0)
                {
                    Console.WriteLine("doing silly thing");
                }
                break;

            case 0x180A:                     // ADPCM Memory Read/Write Port
                ADPCM.Port180A = value;
                break;

            case 0x180B:                     // ADPCM DMA Control
                ADPCM.Port180B = value;
                break;

            case 0x180D:                     // ADPCM Address Control
                ADPCM.AdpcmControlWrite(value);
                break;

            case 0x180E:                     // ADPCM Playback Rate
                ADPCM.Port180E = value;
                break;

            case 0x180F:                     // Audio Fade Timer
                CdIoPorts[0x0F] = value;
                // TODO ADPCM fades/vol control also.
                switch (value)
                {
                case 0:
                    CDAudio.LogicalVolume = 100;
                    break;

                case 8:
                case 9:
                    if (CDAudio.FadeOutFramesRemaining == 0)
                    {
                        CDAudio.FadeOut(360);                                         // 6 seconds
                    }
                    break;

                case 12:
                case 13:
                    if (CDAudio.FadeOutFramesRemaining == 0)
                    {
                        CDAudio.FadeOut(120);                                         // 2 seconds
                    }
                    break;
                }
                break;

            // Arcade Card ports
            case 0x1AE0:
                ShiftRegister &= ~0xFF;
                ShiftRegister |= value;
                break;

            case 0x1AE1:
                ShiftRegister &= ~0xFF00;
                ShiftRegister |= value << 8;
                break;

            case 0x1AE2:
                ShiftRegister &= ~0xFF0000;
                ShiftRegister |= value << 16;
                break;

            case 0x1AE3:
                ShiftRegister &= 0xFFFFFF;
                ShiftRegister |= value << 24;
                break;

            case 0x1AE4:
                ShiftAmount = (byte)(value & 0x0F);
                if (ShiftAmount != 0)
                {
                    if ((ShiftAmount & 8) != 0)
                    {
                        ShiftRegister >>= 16 - ShiftAmount;
                    }
                    else
                    {
                        ShiftRegister <<= ShiftAmount;
                    }
                }
                break;

            case 0x1AE5:
                RotateAmount = value;
                // rotate not implemented, as no test case exists
                break;

            default:
                if (addr >= 0x1FFA00 && addr < 0x1FFA40)
                {
                    WriteArcadeCard(addr & 0x1FFF, value);
                }
                else
                {
                    Log.Error("CD", "unknown write to {0:X4}:{1:X2} pc={2:X4}", addr, value, Cpu.PC);
                }
                break;
            }
        }