Esempio n. 1
0
        public ColecoVision(CoreComm comm, GameInfo game, byte[] rom, object SyncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            MemoryCallbacks = new MemoryCallbackSystem();
            CoreComm        = comm;
            _syncSettings   = (ColecoSyncSettings)SyncSettings ?? new ColecoSyncSettings();
            bool skipbios = this._syncSettings.SkipBiosIntro;

            Cpu                 = new Z80A();
            Cpu.ReadMemory      = ReadMemory;
            Cpu.WriteMemory     = WriteMemory;
            Cpu.ReadHardware    = ReadPort;
            Cpu.WriteHardware   = WritePort;
            Cpu.MemoryCallbacks = MemoryCallbacks;

            VDP = new TMS9918A(Cpu);
            (ServiceProvider as BasicServiceProvider).Register <IVideoProvider>(VDP);
            PSG = new SN76489();

            // TODO: hack to allow bios-less operation would be nice, no idea if its feasible
            BiosRom = CoreComm.CoreFileProvider.GetFirmware("Coleco", "Bios", true, "Coleco BIOS file is required.");

            // gamedb can overwrite the syncsettings; this is ok
            if (game["NoSkip"])
            {
                skipbios = false;
            }
            LoadRom(rom, skipbios);
            this.game = game;
            SetupMemoryDomains();
            (ServiceProvider as BasicServiceProvider).Register <IDisassemblable>(new Disassembler());
        }
Esempio n. 2
0
        public override string Disassemble(MemoryDomain m, uint addr, out int length)
        {
            var ret = Z80A.Disassemble((ushort)addr, a => m.PeekByte(a), out var tmp);

            length = tmp;
            return(ret);
        }
Esempio n. 3
0
        public ColecoVision(CoreComm comm, GameInfo game, byte[] rom, object SyncSettings)
        {
            CoreComm          = comm;
            this.SyncSettings = (ColecoSyncSettings)SyncSettings ?? new ColecoSyncSettings();
            bool skipbios = this.SyncSettings.SkipBiosIntro;

            Cpu               = new Z80A();
            Cpu.ReadMemory    = ReadMemory;
            Cpu.WriteMemory   = WriteMemory;
            Cpu.ReadHardware  = ReadPort;
            Cpu.WriteHardware = WritePort;

            VDP = new TMS9918A(Cpu);
            PSG = new SN76489();

            // TODO: hack to allow bios-less operation would be nice, no idea if its feasible
            string biosPath = CoreComm.CoreFileProvider.GetFirmwarePath("Coleco", "Bios", true, "Coleco BIOS file is required.");

            BiosRom = File.ReadAllBytes(biosPath);

            // gamedb can overwrite the syncsettings; this is ok
            if (game["NoSkip"])
            {
                skipbios = false;
            }
            LoadRom(rom, skipbios);
            this.game = game;
            SetupMemoryDomains();
        }
Esempio n. 4
0
        /// <summary>
        /// Main constructor
        /// </summary>
        /// <param name="spectrum"></param>
        /// <param name="cpu"></param>
        public ZX48(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List <byte[]> files, List <JoystickType> joysticks)
        {
            Spectrum = spectrum;
            CPU      = cpu;

            CPUMon = new CPUMonitor(this);

            //ULADevice = new ULA48(this);
            ULADevice = new Screen48(this);

            BuzzerDevice = new Beeper(this);
            BuzzerDevice.Init(44100, ULADevice.FrameLength);

            TapeBuzzer = new Beeper(this);
            TapeBuzzer.Init(44100, ULADevice.FrameLength);

            KeyboardDevice = new StandardKeyboard(this);

            InitJoysticks(joysticks);

            TapeDevice = new DatacorderDevice(spectrum.SyncSettings.AutoLoadTape);
            TapeDevice.Init(this);

            InitializeMedia(files);
        }
Esempio n. 5
0
        private void MakeTrace(long _cycleCount)
        {
            int[] regs = new int[12];
            LibEmu83.TI83_GetRegs(Context, regs);
            ushort PC = (ushort)regs[10];

            string disasm    = Z80A.Disassemble(PC, addr => LibEmu83.TI83_ReadMemory(Context, addr), out int bytes_read);
            string byte_code = null;

            for (ushort i = 0; i < bytes_read; i++)
            {
                byte_code += $"{LibEmu83.TI83_ReadMemory(Context, (ushort)(PC + i)):X2}";
                if (i < (bytes_read - 1))
                {
                    byte_code += " ";
                }
            }

            Tracer.Put(new(
                           disassembly:
                           $"{PC:X4}: {byte_code,-12} {disasm,-26}",
                           registerInfo:
                           $"AF:{regs[0]:X4} BC:{regs[1]:X4} DE:{regs[2]:X4} HL:{regs[3]:X4} IX:{regs[8]:X4} IY:{regs[9]:X4} SP:{regs[11]:X4} Cy:{_cycleCount}"
                           ));
        }
Esempio n. 6
0
        /// <summary>
        /// Main constructor
        /// </summary>
        public ZX128(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List <byte[]> files, List <JoystickType> joysticks)
        {
            Spectrum = spectrum;
            CPU      = cpu;

            CPUMon = new CPUMonitor(this)
            {
                machineType = MachineType.ZXSpectrum128
            };

            ROMPaged       = 0;
            SHADOWPaged    = false;
            RAMPaged       = 0;
            PagingDisabled = false;

            ULADevice = new Screen128(this);

            BuzzerDevice = new OneBitBeeper(44100, ULADevice.FrameLength, 50, "SystemBuzzer");

            TapeBuzzer = new OneBitBeeper(44100, ULADevice.FrameLength, 50, "TapeBuzzer");

            AYDevice = new AY38912(this);
            AYDevice.Init(44100, ULADevice.FrameLength);

            KeyboardDevice = new StandardKeyboard(this);

            InitJoysticks(joysticks);

            TapeDevice = new DatacorderDevice(spectrum.SyncSettings.AutoLoadTape);
            TapeDevice.Init(this);

            InitializeMedia(files);
        }
Esempio n. 7
0
        /// <summary>
        /// Main constructor
        /// </summary>
        /// <param name="spectrum"></param>
        /// <param name="cpu"></param>
        public ZX128(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List <byte[]> files, List <JoystickType> joysticks)
        {
            Spectrum = spectrum;
            CPU      = cpu;

            ROMPaged       = 0;
            SHADOWPaged    = false;
            RAMPaged       = 0;
            PagingDisabled = false;

            ULADevice = new ULA128(this);

            BuzzerDevice = new Buzzer(this);
            BuzzerDevice.Init(44100, ULADevice.FrameLength);

            TapeBuzzer = new Buzzer(this);
            TapeBuzzer.Init(44100, ULADevice.FrameLength);

            AYDevice = new AYChip(this);
            AYDevice.Init(44100, ULADevice.FrameLength);

            KeyboardDevice = new StandardKeyboard(this);

            InitJoysticks(joysticks);

            TapeDevice = new DatacorderDevice(spectrum.SyncSettings.AutoLoadTape);
            TapeDevice.Init(this);

            InitializeMedia(files);
        }
        /// <summary>
        /// Main constructor
        /// </summary>
        public CPC464(AmstradCPC cpc, Z80A cpu, List <byte[]> files, bool autoTape, AmstradCPC.BorderType borderType)
        {
            CPC = cpc;
            CPU = cpu;

            FrameLength = 79872;

            CRCT = new CRCT_6845(CRCT_6845.CRCTType.MC6845, this);
            //CRT = new CRTDevice(this);
            GateArray = new AmstradGateArray(this, AmstradGateArray.GateArrayType.Amstrad40007);
            PPI       = new PPI_8255(this);

            TapeBuzzer = new Beeper(this);
            TapeBuzzer.Init(44100, FrameLength);

            //AYDevice = new PSG(this, PSG.ay38910_type_t.AY38910_TYPE_8912, GateArray.PSGClockSpeed, 882 * 50);
            AYDevice = new AY38912(this);
            AYDevice.Init(44100, FrameLength);

            KeyboardDevice = new StandardKeyboard(this);

            TapeDevice = new DatacorderDevice(autoTape);
            TapeDevice.Init(this);

            InitializeMedia(files);
        }
Esempio n. 9
0
        public ColecoVision(CoreComm comm, GameInfo game, byte[] rom,
                            ColecoSettings settings,
                            ColecoSyncSettings syncSettings)
        {
            var ser = new BasicServiceProvider(this);

            ServiceProvider = ser;
            _syncSettings   = (ColecoSyncSettings)syncSettings ?? new ColecoSyncSettings();
            bool skipBios = _syncSettings.SkipBiosIntro;

            _cpu = new Z80A
            {
                FetchMemory     = ReadMemory,
                ReadMemory      = ReadMemory,
                WriteMemory     = WriteMemory,
                ReadHardware    = ReadPort,
                WriteHardware   = WritePort,
                MemoryCallbacks = MemoryCallbacks
            };

            PSG       = new SN76489col();
            SGM_sound = new AY_3_8910_SGM();
            _blip.SetRates(3579545, 44100);

            ControllerDeck = new ColecoVisionControllerDeck(_syncSettings.Port1, _syncSettings.Port2);

            _vdp = new TMS9918A(_cpu);
            ser.Register <IVideoProvider>(_vdp);
            ser.Register <IStatable>(new StateSerializer(SyncState));

            // TODO: hack to allow bios-less operation would be nice, no idea if its feasible
            _biosRom = comm.CoreFileProvider.GetFirmware("Coleco", "Bios", true, "Coleco BIOS file is required.");

            // gamedb can overwrite the SyncSettings; this is ok
            if (game["NoSkip"])
            {
                skipBios = false;
            }

            use_SGM = _syncSettings.UseSGM;

            if (use_SGM)
            {
                Console.WriteLine("Using the Super Game Module");
            }

            LoadRom(rom, skipBios);
            SetupMemoryDomains();

            _tracer.Header = _cpu.TraceHeader;
            ser.Register <IDisassemblable>(_cpu);
            ser.Register <ITraceable>(_tracer);
        }
Esempio n. 10
0
 public VDP(SMS sms, Z80A cpu, VdpMode mode, DisplayType displayType)
 {
     Sms       = sms;
     Cpu       = cpu;
     this.mode = mode;
     if (mode == VdpMode.SMS)
     {
         CRAM = new byte[32];
     }
     if (mode == VdpMode.GameGear)
     {
         CRAM = new byte[64];
     }
     DisplayType   = displayType;
     NameTableBase = CalcNameTableBase();
 }
Esempio n. 11
0
        public ColecoVision(CoreComm comm, GameInfo game, byte[] rom, object SyncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            MemoryCallbacks = new MemoryCallbackSystem();
            CoreComm        = comm;
            _syncSettings   = (ColecoSyncSettings)SyncSettings ?? new ColecoSyncSettings();
            bool skipbios = _syncSettings.SkipBiosIntro;

            Cpu = new Z80A
            {
                ReadMemory      = ReadMemory,
                WriteMemory     = WriteMemory,
                ReadHardware    = ReadPort,
                WriteHardware   = WritePort,
                MemoryCallbacks = MemoryCallbacks
            };

            PSG            = new SN76489();
            _fakeSyncSound = new FakeSyncSound(PSG, 735);
            (ServiceProvider as BasicServiceProvider).Register <ISoundProvider>(_fakeSyncSound);

            ControllerDeck = new ColecoVisionControllerDeck(_syncSettings.Port1, _syncSettings.Port2);

            VDP = new TMS9918A(Cpu);
            (ServiceProvider as BasicServiceProvider).Register <IVideoProvider>(VDP);

            // TODO: hack to allow bios-less operation would be nice, no idea if its feasible
            BiosRom = CoreComm.CoreFileProvider.GetFirmware("Coleco", "Bios", true, "Coleco BIOS file is required.");

            // gamedb can overwrite the syncsettings; this is ok
            if (game["NoSkip"])
            {
                skipbios = false;
            }

            LoadRom(rom, skipbios);
            _game = game;
            SetupMemoryDomains();

            Tracer.Header = Cpu.TraceHeader;
            var serviceProvider = ServiceProvider as BasicServiceProvider;

            serviceProvider.Register <IDisassemblable>(new Disassembler());
            serviceProvider.Register <ITraceable>(Tracer);
        }
Esempio n. 12
0
File: VDP.cs Progetto: gocha/BizHawk
        public VDP(SMS sms, Z80A cpu, VdpMode mode, DisplayType displayType, bool region_compat)
        {
            Sms       = sms;
            Cpu       = cpu;
            this.mode = mode;
            if (mode == VdpMode.SMS)
            {
                CRAM = new byte[32];
            }
            if (mode == VdpMode.GameGear)
            {
                CRAM = new byte[64];
            }
            DisplayType = displayType;
            if (mode == VdpMode.SMS)
            {
                JPN_Compat = region_compat;
            }
            NameTableBase = CalcNameTableBase();

            lock_tile_start = mode == VdpMode.SMS ? 24 : 25;
        }
Esempio n. 13
0
        public SMS(CoreComm comm, GameInfo game, byte[] rom, object settings, object syncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            Settings        = (SMSSettings)settings ?? new SMSSettings();
            SyncSettings    = (SMSSyncSettings)syncSettings ?? new SMSSyncSettings();
            CoreComm        = comm;
            MemoryCallbacks = new MemoryCallbackSystem();

            IsGameGear = game.System == "GG";
            IsSG1000   = game.System == "SG";
            RomData    = rom;
            Tracer     = new TraceBuffer();
            (ServiceProvider as BasicServiceProvider).Register <ITraceable>(Tracer);
            if (RomData.Length % BankSize != 0)
            {
                Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
            }
            RomBanks = (byte)(RomData.Length / BankSize);

            Region = DetermineDisplayType(SyncSettings.DisplayType, game.Region);
            if (game["PAL"] && Region != DisplayType.PAL)
            {
                Region = DisplayType.PAL;
                CoreComm.Notify("Display was forced to PAL mode for game compatibility.");
            }
            if (IsGameGear)
            {
                Region = DisplayType.NTSC;                 // all game gears run at 60hz/NTSC mode
            }
            CoreComm.VsyncNum = Region == DisplayType.NTSC ? 60 : 50;
            CoreComm.VsyncDen = 1;

            RegionStr = SyncSettings.ConsoleRegion;
            if (RegionStr == "Auto")
            {
                RegionStr = DetermineRegion(game.Region);
            }

            if (game["Japan"] && RegionStr != "Japan")
            {
                RegionStr = "Japan";
                CoreComm.Notify("Region was forced to Japan for game compatibility.");
            }

            if ((game.NotInDatabase || game["FM"]) && SyncSettings.EnableFM && !IsGameGear)
            {
                HasYM2413 = true;
            }

            if (Controller == null)
            {
                Controller = NullController.GetNullController();
            }

            Cpu                 = new Z80A();
            Cpu.RegisterSP      = 0xDFF0;
            Cpu.ReadHardware    = ReadPort;
            Cpu.WriteHardware   = WritePort;
            Cpu.MemoryCallbacks = MemoryCallbacks;

            Vdp = new VDP(this, Cpu, IsGameGear ? VdpMode.GameGear : VdpMode.SMS, Region);
            (ServiceProvider as BasicServiceProvider).Register <IVideoProvider>(Vdp);
            PSG        = new SN76489();
            YM2413     = new YM2413();
            SoundMixer = new SoundMixer(YM2413, PSG);
            if (HasYM2413 && game["WhenFMDisablePSG"])
            {
                SoundMixer.DisableSource(PSG);
            }
            ActiveSoundProvider = HasYM2413 ? (ISoundProvider)SoundMixer : PSG;

            SystemRam = new byte[0x2000];

            if (game["CMMapper"])
            {
                InitCodeMastersMapper();
            }
            else if (game["CMMapperWithRam"])
            {
                InitCodeMastersMapperRam();
            }
            else if (game["ExtRam"])
            {
                InitExt2kMapper(int.Parse(game.OptionValue("ExtRam")));
            }
            else if (game["KoreaMapper"])
            {
                InitKoreaMapper();
            }
            else if (game["MSXMapper"])
            {
                InitMSXMapper();
            }
            else if (game["NemesisMapper"])
            {
                InitNemesisMapper();
            }
            else if (game["TerebiOekaki"])
            {
                InitTerebiOekaki();
            }
            else
            {
                InitSegaMapper();
            }

            if (Settings.ForceStereoSeparation && !IsGameGear)
            {
                if (game["StereoByte"])
                {
                    ForceStereoByte = byte.Parse(game.OptionValue("StereoByte"));
                }
                PSG.StereoPanning = ForceStereoByte;
            }

            if (SyncSettings.AllowOverlock && game["OverclockSafe"])
            {
                Vdp.IPeriod = 512;
            }

            if (Settings.SpriteLimit)
            {
                Vdp.SpriteLimit = true;
            }

            if (game["3D"])
            {
                IsGame3D = true;
            }

            if (game["BIOS"])
            {
                Port3E = 0xF7;                 // Disable cartridge, enable BIOS rom
                InitBiosMapper();
            }
            else if (game.System == "SMS")
            {
                BiosRom = comm.CoreFileProvider.GetFirmware("SMS", RegionStr, false);
                if (BiosRom != null && (game["RequireBios"] || SyncSettings.UseBIOS))
                {
                    Port3E = 0xF7;
                }

                if (BiosRom == null && game["RequireBios"])
                {
                    throw new MissingFirmwareException("BIOS image not available. This game requires BIOS to function.");
                }
                if (SyncSettings.UseBIOS && BiosRom == null)
                {
                    CoreComm.Notify("BIOS was selected, but rom image not available. BIOS not enabled.");
                }
            }

            if (game["SRAM"])
            {
                SaveRAM = new byte[int.Parse(game.OptionValue("SRAM"))];
            }
            else if (game.NotInDatabase)
            {
                SaveRAM = new byte[0x8000];
            }

            SetupMemoryDomains();

            //this manages the linkage between the cpu and mapper callbacks so it needs running before bootup is complete
            ((ICodeDataLogger)this).SetCDL(null);

            (ServiceProvider as BasicServiceProvider).Register <IDisassemblable>(new Disassembler());
        }
Esempio n. 14
0
File: SMS.cs Progetto: m35/BizHawk
        public SMS(CoreComm comm, GameInfo game, byte[] rom, object settings, object syncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            Settings        = (SmsSettings)settings ?? new SmsSettings();
            SyncSettings    = (SmsSyncSettings)syncSettings ?? new SmsSyncSettings();
            CoreComm        = comm;
            MemoryCallbacks = new MemoryCallbackSystem(new[] { "System Bus" });

            IsGameGear   = game.System == "GG";
            IsGameGear_C = game.System == "GG";
            IsSG1000     = game.System == "SG";
            RomData      = rom;

            if (RomData.Length % BankSize != 0)
            {
                Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
            }

            RomBanks = (byte)(RomData.Length / BankSize);

            Region = DetermineDisplayType(SyncSettings.DisplayType, game.Region);
            if (game["PAL"] && Region != DisplayType.PAL)
            {
                Region = DisplayType.PAL;
                CoreComm.Notify("Display was forced to PAL mode for game compatibility.");
            }

            if (IsGameGear)
            {
                Region = DisplayType.NTSC;                 // all game gears run at 60hz/NTSC mode
            }

            _region = SyncSettings.ConsoleRegion;
            if (_region == SmsSyncSettings.Regions.Auto)
            {
                _region = DetermineRegion(game.Region);
            }

            if (game["Japan"] && _region != SmsSyncSettings.Regions.Japan)
            {
                _region = SmsSyncSettings.Regions.Japan;
                CoreComm.Notify("Region was forced to Japan for game compatibility.");
            }

            if (game["Korea"] && _region != SmsSyncSettings.Regions.Korea)
            {
                _region = SmsSyncSettings.Regions.Korea;
                CoreComm.Notify("Region was forced to Korea for game compatibility.");
            }

            if ((game.NotInDatabase || game["FM"]) && SyncSettings.EnableFm && !IsGameGear)
            {
                HasYM2413 = true;
            }

            Cpu = new Z80A()
            {
                ReadHardware    = ReadPort,
                WriteHardware   = WritePort,
                FetchMemory     = FetchMemory,
                ReadMemory      = ReadMemory,
                WriteMemory     = WriteMemory,
                MemoryCallbacks = MemoryCallbacks,
                OnExecFetch     = OnExecMemory
            };

            if (game["GG_in_SMS"])
            {
                // skip setting the BIOS because this is a game gear game that puts the system
                // in SMS compatibility mode (it will fail the check sum if played on an actual SMS though.)
                IsGameGear   = false;
                IsGameGear_C = true;
                game.System  = "GG";
                Console.WriteLine("Using SMS Compatibility mode for Game Gear System");
            }

            Vdp = new VDP(this, Cpu, IsGameGear ? VdpMode.GameGear : VdpMode.SMS, Region);
            (ServiceProvider as BasicServiceProvider).Register <IVideoProvider>(Vdp);
            PSG    = new SN76489sms();
            YM2413 = new YM2413();
            //SoundMixer = new SoundMixer(YM2413, PSG);
            if (HasYM2413 && game["WhenFMDisablePSG"])
            {
                disablePSG = true;
            }

            blip_L.SetRates(3579545, 44100);
            blip_R.SetRates(3579545, 44100);

            (ServiceProvider as BasicServiceProvider).Register <ISoundProvider>(this);

            SystemRam = new byte[0x2000];

            if (game["CMMapper"])
            {
                InitCodeMastersMapper();
            }
            else if (game["CMMapperWithRam"])
            {
                InitCodeMastersMapperRam();
            }
            else if (game["ExtRam"])
            {
                InitExt2kMapper(int.Parse(game.OptionValue("ExtRam")));
            }
            else if (game["KoreaMapper"])
            {
                InitKoreaMapper();
            }
            else if (game["MSXMapper"])
            {
                InitMSXMapper();
            }
            else if (game["NemesisMapper"])
            {
                InitNemesisMapper();
            }
            else if (game["TerebiOekaki"])
            {
                InitTerebiOekaki();
            }
            else if (game["EEPROM"])
            {
                InitEEPROMMapper();
            }
            else
            {
                InitSegaMapper();
            }

            if (Settings.ForceStereoSeparation && !IsGameGear)
            {
                if (game["StereoByte"])
                {
                    ForceStereoByte = byte.Parse(game.OptionValue("StereoByte"));
                }

                PSG.Set_Panning(ForceStereoByte);
            }

            if (SyncSettings.AllowOverClock && game["OverclockSafe"])
            {
                Vdp.IPeriod = 512;
            }

            if (Settings.SpriteLimit)
            {
                Vdp.SpriteLimit = true;
            }

            if (game["3D"])
            {
                IsGame3D = true;
            }

            if (game["BIOS"])
            {
                Port3E = 0xF7;                 // Disable cartridge, enable BIOS rom
                InitBiosMapper();
            }
            else if (game.System == "SMS" && !game["GG_in_SMS"])
            {
                BiosRom = comm.CoreFileProvider.GetFirmware("SMS", _region.ToString(), false);

                if (BiosRom == null)
                {
                    throw new MissingFirmwareException("No BIOS found");
                }

                if (!game["RequireBios"] && !SyncSettings.UseBios)
                {
                    // we are skipping the BIOS
                    // but only if it won't break the game
                }
                else
                {
                    Port3E = 0xF7;
                }
            }

            if (game["SRAM"])
            {
                SaveRAM = new byte[int.Parse(game.OptionValue("SRAM"))];
                Console.WriteLine(SaveRAM.Length);
            }
            else if (game.NotInDatabase)
            {
                SaveRAM = new byte[0x8000];
            }

            SetupMemoryDomains();

            //this manages the linkage between the cpu and mapper callbacks so it needs running before bootup is complete
            ((ICodeDataLogger)this).SetCDL(null);

            InputCallbacks = new InputCallbackSystem();

            Tracer = new TraceBuffer {
                Header = Cpu.TraceHeader
            };

            var serviceProvider = ServiceProvider as BasicServiceProvider;

            serviceProvider.Register <ITraceable>(Tracer);
            serviceProvider.Register <IDisassemblable>(Cpu);
            Vdp.ProcessOverscan();

            Cpu.ReadMemory  = ReadMemory;
            Cpu.WriteMemory = WriteMemory;

            // Z80 SP initialization
            // stops a few SMS and GG games from crashing
            Cpu.Regs[Cpu.SPl] = 0xF0;
            Cpu.Regs[Cpu.SPh] = 0xDF;
        }
Esempio n. 15
0
        public ZXSpectrum(CoreComm comm, IEnumerable <byte[]> files, List <GameInfo> game, object settings, object syncSettings)
        {
            var ser = new BasicServiceProvider(this);

            ServiceProvider = ser;
            InputCallbacks  = new InputCallbackSystem();
            MemoryCallbacks = new MemoryCallbackSystem(new[] { "System Bus" });

            CoreComm = comm;

            _gameInfo = game;

            _cpu = new Z80A();

            _tracer = new TraceBuffer {
                Header = _cpu.TraceHeader
            };

            //_file = file;
            _files = files?.ToList() ?? new List <byte[]>();

            if (settings == null)
            {
                settings = new ZXSpectrumSettings();
            }
            if (syncSettings == null)
            {
                syncSettings = new ZXSpectrumSyncSettings();
            }

            PutSyncSettings((ZXSpectrumSyncSettings)syncSettings ?? new ZXSpectrumSyncSettings());
            PutSettings((ZXSpectrumSettings)settings ?? new ZXSpectrumSettings());

            List <JoystickType> joysticks = new List <JoystickType>();

            joysticks.Add(((ZXSpectrumSyncSettings)syncSettings as ZXSpectrumSyncSettings).JoystickType1);
            joysticks.Add(((ZXSpectrumSyncSettings)syncSettings as ZXSpectrumSyncSettings).JoystickType2);
            joysticks.Add(((ZXSpectrumSyncSettings)syncSettings as ZXSpectrumSyncSettings).JoystickType3);

            deterministicEmulation = ((ZXSpectrumSyncSettings)syncSettings as ZXSpectrumSyncSettings).DeterministicEmulation;

            switch (SyncSettings.MachineType)
            {
            case MachineType.ZXSpectrum16:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum16, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.ZXSpectrum48:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum48, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.ZXSpectrum128:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum128, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.ZXSpectrum128Plus2:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum128Plus2, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.ZXSpectrum128Plus2a:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum128Plus2a, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.ZXSpectrum128Plus3:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum128Plus3, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            default:
                throw new InvalidOperationException("Machine not yet emulated");
            }

            _cpu.MemoryCallbacks = MemoryCallbacks;

            HardReset = _machine.HardReset;
            SoftReset = _machine.SoftReset;

            _cpu.FetchMemory   = _machine.ReadMemory;
            _cpu.ReadMemory    = _machine.ReadMemory;
            _cpu.WriteMemory   = _machine.WriteMemory;
            _cpu.ReadHardware  = _machine.ReadPort;
            _cpu.WriteHardware = _machine.WritePort;
            _cpu.FetchDB       = _machine.PushBus;

            ser.Register <ITraceable>(_tracer);
            ser.Register <IDisassemblable>(_cpu);
            ser.Register <IVideoProvider>(_machine.ULADevice);

            // initialize sound mixer and attach the various ISoundProvider devices
            SoundMixer = new SoundProviderMixer((int)(32767 / 10), (ISoundProvider)_machine.BuzzerDevice);
            SoundMixer.AddSource((ISoundProvider)_machine.TapeBuzzer);
            if (_machine.AYDevice != null)
            {
                SoundMixer.AddSource(_machine.AYDevice);
            }

            // set audio device settings
            if (_machine.AYDevice != null && _machine.AYDevice.GetType() == typeof(AYChip))
            {
                ((AYChip)_machine.AYDevice as AYChip).PanningConfiguration = ((ZXSpectrumSettings)settings as ZXSpectrumSettings).AYPanConfig;
                _machine.AYDevice.Volume = ((ZXSpectrumSettings)settings as ZXSpectrumSettings).AYVolume;
            }

            if (_machine.BuzzerDevice != null)
            {
                ((Buzzer)_machine.BuzzerDevice as Buzzer).Volume = ((ZXSpectrumSettings)settings as ZXSpectrumSettings).EarVolume;
            }

            if (_machine.TapeBuzzer != null)
            {
                ((Buzzer)_machine.TapeBuzzer as Buzzer).Volume = ((ZXSpectrumSettings)settings as ZXSpectrumSettings).TapeVolume;
            }

            ser.Register <ISoundProvider>(SoundMixer);


            HardReset();
            SetupMemoryDomains();
        }
Esempio n. 16
0
        public AmstradCPC(CoreLoadParameters <AmstradCPCSettings, AmstradCPCSyncSettings> lp)
        {
            var ser = new BasicServiceProvider(this);

            ServiceProvider = ser;
            CoreComm        = lp.Comm;
            _gameInfo       = lp.Roms.Select(r => r.Game).ToList();
            _cpu            = new Z80A();
            _tracer         = new TraceBuffer {
                Header = _cpu.TraceHeader
            };
            _files = lp.Roms.Select(r => r.RomData).ToList();

            var settings     = lp.Settings ?? new AmstradCPCSettings();
            var syncSettings = lp.SyncSettings ?? new AmstradCPCSyncSettings();

            PutSyncSettings((AmstradCPCSyncSettings)syncSettings);
            PutSettings((AmstradCPCSettings)settings);

            DeterministicEmulation = ((AmstradCPCSyncSettings)syncSettings).DeterministicEmulation;

            switch (SyncSettings.MachineType)
            {
            case MachineType.CPC464:
                ControllerDefinition = AmstradCPCControllerDefinition;
                Init(MachineType.CPC464, _files, ((AmstradCPCSyncSettings)syncSettings).AutoStartStopTape,
                     ((AmstradCPCSyncSettings)syncSettings).BorderType);
                break;

            case MachineType.CPC6128:
                ControllerDefinition = AmstradCPCControllerDefinition;
                Init(MachineType.CPC6128, _files, ((AmstradCPCSyncSettings)syncSettings).AutoStartStopTape, ((AmstradCPCSyncSettings)syncSettings).BorderType);
                break;

            default:
                throw new InvalidOperationException("Machine not yet emulated");
            }

            _cpu.MemoryCallbacks = MemoryCallbacks;

            HardReset = _machine.HardReset;
            SoftReset = _machine.SoftReset;

            _cpu.FetchMemory    = _machine.ReadMemory;
            _cpu.ReadMemory     = _machine.ReadMemory;
            _cpu.WriteMemory    = _machine.WriteMemory;
            _cpu.ReadHardware   = _machine.ReadPort;
            _cpu.WriteHardware  = _machine.WritePort;
            _cpu.FetchDB        = _machine.PushBus;
            _cpu.IRQACKCallback = _machine.GateArray.IORQA;
            //_cpu.OnExecFetch = _machine.CPUMon.OnExecFetch;

            ser.Register <ITraceable>(_tracer);
            ser.Register <IDisassemblable>(_cpu);
            ser.Register <IVideoProvider>(_machine.GateArray);
            ser.Register <IStatable>(new StateSerializer(SyncState));

            // initialize sound mixer and attach the various ISoundProvider devices
            SoundMixer = new SoundProviderMixer((int)(32767 / 10), "Tape Audio", (ISoundProvider)_machine.TapeBuzzer);
            if (_machine.AYDevice != null)
            {
                SoundMixer.AddSource(_machine.AYDevice, "AY-3-3912");
            }

            // set audio device settings
            if (_machine.AYDevice != null && _machine.AYDevice.GetType() == typeof(AY38912))
            {
                ((AY38912)_machine.AYDevice).PanningConfiguration = ((AmstradCPCSettings)settings).AYPanConfig;
                _machine.AYDevice.Volume = ((AmstradCPCSettings)settings).AYVolume;
            }

            if (_machine.TapeBuzzer != null)
            {
                ((Beeper)_machine.TapeBuzzer).Volume = ((AmstradCPCSettings)settings).TapeVolume;
            }

            ser.Register <ISoundProvider>(SoundMixer);

            HardReset();
            SetupMemoryDomains();
        }
Esempio n. 17
0
        public ZXSpectrum(CoreComm comm, IEnumerable <byte[]> files, List <GameInfo> game, object settings, object syncSettings, bool?deterministic)
        {
            var ser = new BasicServiceProvider(this);

            ServiceProvider = ser;
            CoreComm        = comm;

            _gameInfo = game;

            _cpu = new Z80A();

            _tracer = new TraceBuffer {
                Header = _cpu.TraceHeader
            };

            _files = files?.ToList() ?? new List <byte[]>();

            if (settings == null)
            {
                settings = new ZXSpectrumSettings();
            }

            if (syncSettings == null)
            {
                syncSettings = new ZXSpectrumSyncSettings();
            }

            PutSyncSettings((ZXSpectrumSyncSettings)syncSettings);
            PutSettings((ZXSpectrumSettings)settings);

            var joysticks = new List <JoystickType>
            {
                ((ZXSpectrumSyncSettings)syncSettings).JoystickType1,
                ((ZXSpectrumSyncSettings)syncSettings).JoystickType2,
                ((ZXSpectrumSyncSettings)syncSettings).JoystickType3
            };

            DeterministicEmulation = ((ZXSpectrumSyncSettings)syncSettings).DeterministicEmulation;

            if (deterministic != null && deterministic == true)
            {
                if (!DeterministicEmulation)
                {
                    CoreComm.Notify("Forcing Deterministic Emulation");
                }

                DeterministicEmulation = deterministic.Value;
            }

            MachineType = SyncSettings.MachineType;

            switch (MachineType)
            {
            case MachineType.ZXSpectrum16:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum16, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.ZXSpectrum48:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum48, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.ZXSpectrum128:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum128, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.ZXSpectrum128Plus2:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum128Plus2, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.ZXSpectrum128Plus2a:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum128Plus2a, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.ZXSpectrum128Plus3:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.ZXSpectrum128Plus3, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            case MachineType.Pentagon128:
                ControllerDefinition = ZXSpectrumControllerDefinition;
                Init(MachineType.Pentagon128, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files, joysticks);
                break;

            default:
                throw new InvalidOperationException("Machine not yet emulated");
            }

            _cpu.MemoryCallbacks = MemoryCallbacks;

            HardReset = _machine.HardReset;
            SoftReset = _machine.SoftReset;

            _cpu.FetchMemory   = _machine.ReadMemory;
            _cpu.ReadMemory    = _machine.ReadMemory;
            _cpu.WriteMemory   = _machine.WriteMemory;
            _cpu.ReadHardware  = _machine.ReadPort;
            _cpu.WriteHardware = _machine.WritePort;
            _cpu.FetchDB       = _machine.PushBus;
            _cpu.OnExecFetch   = _machine.CPUMon.OnExecFetch;

            ser.Register <ITraceable>(_tracer);
            ser.Register <IDisassemblable>(_cpu);
            ser.Register <IVideoProvider>(_machine.ULADevice);

            // initialize sound mixer and attach the various ISoundProvider devices
            SoundMixer = new SyncSoundMixer(targetSampleCount: 882);
            SoundMixer.PinSource(_machine.BuzzerDevice, "System Beeper", (int)(32767 / 10));
            SoundMixer.PinSource(_machine.TapeBuzzer, "Tape Audio", (int)(32767 / 10));
            if (_machine.AYDevice != null)
            {
                SoundMixer.PinSource(_machine.AYDevice, "AY-3-3912");
            }

            // set audio device settings
            if (_machine.AYDevice != null && _machine.AYDevice.GetType() == typeof(AY38912))
            {
                ((AY38912)_machine.AYDevice).PanningConfiguration = ((ZXSpectrumSettings)settings).AYPanConfig;
                _machine.AYDevice.Volume = ((ZXSpectrumSettings)settings).AYVolume;
            }

            if (_machine.BuzzerDevice != null)
            {
                _machine.BuzzerDevice.Volume = ((ZXSpectrumSettings)settings).EarVolume;
            }

            if (_machine.TapeBuzzer != null)
            {
                _machine.TapeBuzzer.Volume = ((ZXSpectrumSettings)settings).TapeVolume;
            }

            DCFilter dc = new DCFilter(SoundMixer, 512);

            ser.Register <ISoundProvider>(dc);
            ser.Register <IStatable>(new StateSerializer(SyncState));
            HardReset();
            SetupMemoryDomains();
        }
Esempio n. 18
0
        public SMS(CoreComm comm, GameInfo game, byte[] rom, object settings, object syncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            Settings        = (SMSSettings)settings ?? new SMSSettings();
            SyncSettings    = (SMSSyncSettings)syncSettings ?? new SMSSyncSettings();
            CoreComm        = comm;
            MemoryCallbacks = new MemoryCallbackSystem(new[] { "System Bus" });

            IsGameGear = game.System == "GG";
            IsSG1000   = game.System == "SG";
            RomData    = rom;

            if (RomData.Length % BankSize != 0)
            {
                Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
            }

            RomBanks = (byte)(RomData.Length / BankSize);

            Region = DetermineDisplayType(SyncSettings.DisplayType, game.Region);
            if (game["PAL"] && Region != DisplayType.PAL)
            {
                Region = DisplayType.PAL;
                CoreComm.Notify("Display was forced to PAL mode for game compatibility.");
            }

            if (IsGameGear)
            {
                Region = DisplayType.NTSC;                 // all game gears run at 60hz/NTSC mode
            }

            RegionStr = SyncSettings.ConsoleRegion;
            if (RegionStr == "Auto")
            {
                RegionStr = DetermineRegion(game.Region);
            }

            if (game["Japan"] && RegionStr != "Japan")
            {
                RegionStr = "Japan";
                CoreComm.Notify("Region was forced to Japan for game compatibility.");
            }

            if ((game.NotInDatabase || game["FM"]) && SyncSettings.EnableFM && !IsGameGear)
            {
                HasYM2413 = true;
            }

            Cpu = new Z80A()
            {
                ReadHardware    = ReadPort,
                WriteHardware   = WritePort,
                FetchMemory     = FetchMemory,
                ReadMemory      = ReadMemory,
                WriteMemory     = WriteMemory,
                MemoryCallbacks = MemoryCallbacks,
                OnExecFetch     = OnExecMemory
            };

            Vdp = new VDP(this, Cpu, IsGameGear ? VdpMode.GameGear : VdpMode.SMS, Region);
            (ServiceProvider as BasicServiceProvider).Register <IVideoProvider>(Vdp);
            PSG        = new SN76489();
            YM2413     = new YM2413();
            SoundMixer = new SoundMixer(YM2413, PSG);
            if (HasYM2413 && game["WhenFMDisablePSG"])
            {
                SoundMixer.DisableSource(PSG);
            }

            ActiveSoundProvider = HasYM2413 ? (IAsyncSoundProvider)SoundMixer : PSG;
            _fakeSyncSound      = new FakeSyncSound(ActiveSoundProvider, 735);
            (ServiceProvider as BasicServiceProvider).Register <ISoundProvider>(_fakeSyncSound);

            SystemRam = new byte[0x2000];

            if (game["CMMapper"])
            {
                InitCodeMastersMapper();
            }
            else if (game["CMMapperWithRam"])
            {
                InitCodeMastersMapperRam();
            }
            else if (game["ExtRam"])
            {
                InitExt2kMapper(int.Parse(game.OptionValue("ExtRam")));
            }
            else if (game["KoreaMapper"])
            {
                InitKoreaMapper();
            }
            else if (game["MSXMapper"])
            {
                InitMSXMapper();
            }
            else if (game["NemesisMapper"])
            {
                InitNemesisMapper();
            }
            else if (game["TerebiOekaki"])
            {
                InitTerebiOekaki();
            }
            else if (game["EEPROM"])
            {
                InitEEPROMMapper();
            }
            else
            {
                InitSegaMapper();
            }

            if (Settings.ForceStereoSeparation && !IsGameGear)
            {
                if (game["StereoByte"])
                {
                    ForceStereoByte = byte.Parse(game.OptionValue("StereoByte"));
                }

                PSG.StereoPanning = ForceStereoByte;
            }

            if (SyncSettings.AllowOverlock && game["OverclockSafe"])
            {
                Vdp.IPeriod = 512;
            }

            if (Settings.SpriteLimit)
            {
                Vdp.SpriteLimit = true;
            }

            if (game["3D"])
            {
                IsGame3D = true;
            }

            if (game["BIOS"])
            {
                Port3E = 0xF7;                 // Disable cartridge, enable BIOS rom
                InitBiosMapper();
            }
            else if (game.System == "SMS")
            {
                BiosRom = comm.CoreFileProvider.GetFirmware("SMS", RegionStr, false);

                if (BiosRom == null)
                {
                    throw new MissingFirmwareException("No BIOS found");
                }
                else if (!game["RequireBios"] && !SyncSettings.UseBIOS)
                {
                    // we are skipping the BIOS
                    // but only if it won't break the game
                }
                else
                {
                    Port3E = 0xF7;
                }
            }

            if (game["SRAM"])
            {
                SaveRAM = new byte[int.Parse(game.OptionValue("SRAM"))];
                Console.WriteLine(SaveRAM.Length);
            }
            else if (game.NotInDatabase)
            {
                SaveRAM = new byte[0x8000];
            }

            SetupMemoryDomains();

            //this manages the linkage between the cpu and mapper callbacks so it needs running before bootup is complete
            ((ICodeDataLogger)this).SetCDL(null);

            InputCallbacks = new InputCallbackSystem();

            Tracer = new TraceBuffer {
                Header = Cpu.TraceHeader
            };

            var serviceProvider = ServiceProvider as BasicServiceProvider;

            serviceProvider.Register <ITraceable>(Tracer);
            serviceProvider.Register <IDisassemblable>(Cpu);
            Vdp.ProcessOverscan();

            Cpu.ReadMemory  = ReadMemory;
            Cpu.WriteMemory = WriteMemory;
        }
Esempio n. 19
0
 /// <summary>
 /// Main constructor
 /// </summary>
 /// <param name="spectrum"></param>
 /// <param name="cpu"></param>
 public ZX128Plus2(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List <byte[]> files, List <JoystickType> joysticks)
     : base(spectrum, cpu, borderType, files, joysticks)
 {
 }
 public CPUMonitor(SpectrumBase machine)
 {
     _machine = machine;
     _cpu     = _machine.CPU;
 }
Esempio n. 21
0
        public Genesis(CoreComm comm, GameInfo game, byte[] rom)
        {
            ServiceProvider = new BasicServiceProvider(this);
            CoreComm        = comm;
            MainCPU         = new MC68000();
            SoundCPU        = new Z80A();
            YM2612          = new YM2612()
            {
                MaxVolume = 23405
            };
            PSG = new SN76489()
            {
                MaxVolume = 4681
            };
            VDP = new GenVDP();
            VDP.DmaReadFrom68000 = ReadWord;
            (ServiceProvider as BasicServiceProvider).Register <IVideoProvider>(VDP);
            SoundMixer = new SoundMixer(YM2612, PSG);

            MainCPU.ReadByte    = ReadByte;
            MainCPU.ReadWord    = ReadWord;
            MainCPU.ReadLong    = ReadLong;
            MainCPU.WriteByte   = WriteByte;
            MainCPU.WriteWord   = WriteWord;
            MainCPU.WriteLong   = WriteLong;
            MainCPU.IrqCallback = InterruptCallback;

            // ---------------------- musashi -----------------------
#if MUSASHI
            _vdp    = vdpcallback;
            read8   = Read8;
            read16  = Read16;
            read32  = Read32;
            write8  = Write8;
            write16 = Write16;
            write32 = Write32;

            Musashi.RegisterVdpCallback(Marshal.GetFunctionPointerForDelegate(_vdp));
            Musashi.RegisterRead8(Marshal.GetFunctionPointerForDelegate(read8));
            Musashi.RegisterRead16(Marshal.GetFunctionPointerForDelegate(read16));
            Musashi.RegisterRead32(Marshal.GetFunctionPointerForDelegate(read32));
            Musashi.RegisterWrite8(Marshal.GetFunctionPointerForDelegate(write8));
            Musashi.RegisterWrite16(Marshal.GetFunctionPointerForDelegate(write16));
            Musashi.RegisterWrite32(Marshal.GetFunctionPointerForDelegate(write32));
#endif
            // ---------------------- musashi -----------------------

            SoundCPU.ReadMemory    = ReadMemoryZ80;
            SoundCPU.WriteMemory   = WriteMemoryZ80;
            SoundCPU.WriteHardware = (a, v) => { Console.WriteLine("Z80: Attempt I/O Write {0:X2}:{1:X2}", a, v); };
            SoundCPU.ReadHardware  = x => 0xFF;
            SoundCPU.IRQCallback   = () => SoundCPU.Interrupt = false;
            Z80Reset = true;
            RomData  = new byte[0x400000];
            for (int i = 0; i < rom.Length; i++)
            {
                RomData[i] = rom[i];
            }

            SetupMemoryDomains();
#if MUSASHI
            Musashi.Init();
            Musashi.Reset();
            VDP.GetPC = () => Musashi.PC;
#else
            MainCPU.Reset();
            VDP.GetPC = () => MainCPU.PC;
#endif
            InitializeCartHardware(game);
        }
Esempio n. 22
0
 public TMS9918A(Z80A cpu)
 {
     Cpu = cpu;
 }
Esempio n. 23
0
 public TMS9918A(Z80A cpu)
 {
     this.Cpu = cpu;
 }