Esempio n. 1
0
        private void HardReset()
        {
            _cart = Cart.Create(_rom, _gameInfo.CartType);
            ILogger logger = new ConsoleLogger();

            HSC7800 hsc7800 = null;

            if (_hsbios != null)
            {
                hsc7800 = new HSC7800(_hsbios, _hsram);
            }

            Bios7800 bios7800 = new Bios7800(_bios);

            _theMachine = MachineBase.Create(
                _gameInfo.MachineType,
                _cart,
                bios7800,
                hsc7800,
                _gameInfo.LController,
                _gameInfo.RController,
                logger);

            _theMachine.Reset();
            _theMachine.InputState.InputPollCallback = InputCallbacks.Call;

            ControlAdapter       = new Atari7800Control(_theMachine);
            ControllerDefinition = ControlAdapter.ControlType;

            _avProvider.ConnectToMachine(_theMachine, _gameInfo);

            SetupMemoryDomains(hsc7800);
        }
Esempio n. 2
0
        private void HardReset()
        {
            cart = Cart.Create(rom, GameInfo.CartType);
            ILogger logger = new ConsoleLogger();

            HSC7800 hsc7800 = null;

            if (hsbios != null)
            {
                hsc7800 = new HSC7800(hsbios, hsram);
            }

            Bios7800 bios7800 = new Bios7800(bios);

            theMachine = MachineBase.Create
                             (GameInfo.MachineType,
                             cart,
                             bios7800,
                             hsc7800,
                             GameInfo.LController,
                             GameInfo.RController,
                             logger);

            theMachine.Reset();
            theMachine.InputState.InputPollCallback = InputCallbacks.Call;

            ControlAdapter       = new Atari7800Control(theMachine);
            ControllerDefinition = ControlAdapter.ControlType;

            _avProvider.ConnectToMachine(theMachine, GameInfo);

            // to sync exactly with audio as this emulator creates and times it, the frame rate should be exactly 60:1 or 50:1
            CoreComm.VsyncNum = theMachine.FrameHZ;
            CoreComm.VsyncDen = 1;

            SetupMemoryDomains(hsc7800);
        }
Esempio n. 3
0
        void HardReset()
        {
            cart = Cart.Create(rom, GameInfo.CartType);
            ILogger logger = new ConsoleLogger();

            HSC7800 hsc7800 = null;

            if (hsbios != null)
            {
                hsc7800 = new HSC7800(hsbios, hsram);
            }

            Bios7800 bios7800 = new Bios7800(bios);

            theMachine = MachineBase.Create
                             (GameInfo.MachineType,
                             cart,
                             bios7800,
                             hsc7800,
                             GameInfo.LController,
                             GameInfo.RController,
                             logger);

            theMachine.Reset();
            theMachine.InputState.InputPollCallback = CoreComm.InputCallback.Call;

            ControlAdapter       = new Atari7800Control(theMachine);
            ControllerDefinition = ControlAdapter.ControlType;

            avProvider.ConnectToMachine(theMachine, GameInfo);
            // to sync exactly with audio as this emulator creates and times it, the frame rate should be exactly 60:1 or 50:1
            CoreComm.VsyncNum = theMachine.FrameHZ;
            CoreComm.VsyncDen = 1;

            // reset memory domains
            if (_MemoryDomains == null)
            {
                _MemoryDomains = new List <MemoryDomain>();
                if (theMachine is Machine7800)
                {
                    _MemoryDomains.Add(new MemoryDomain(
                                           "RAM1", 0x800, MemoryDomain.Endian.Unknown,
                                           delegate(int addr)
                    {
                        if (addr < 0 || addr >= 0x800)
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        return(((Machine7800)theMachine).RAM1[(ushort)addr]);
                    },
                                           delegate(int addr, byte val)
                    {
                        if (addr < 0 || addr >= 0x800)
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        ((Machine7800)theMachine).RAM1[(ushort)addr] = val;
                    }));
                    _MemoryDomains.Add(new MemoryDomain(
                                           "RAM2", 0x800, MemoryDomain.Endian.Unknown,
                                           delegate(int addr)
                    {
                        if (addr < 0 || addr >= 0x800)
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        return(((Machine7800)theMachine).RAM2[(ushort)addr]);
                    },
                                           delegate(int addr, byte val)
                    {
                        if (addr < 0 || addr >= 0x800)
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        ((Machine7800)theMachine).RAM2[(ushort)addr] = val;
                    }));
                    _MemoryDomains.Add(new MemoryDomain(
                                           "BIOS ROM", bios.Length, MemoryDomain.Endian.Unknown,
                                           delegate(int addr)
                    {
                        return(bios[addr]);
                    },
                                           delegate(int addr, byte val)
                    {
                    }));
                    if (hsc7800 != null)
                    {
                        _MemoryDomains.Add(new MemoryDomain(
                                               "HSC ROM", hsbios.Length, MemoryDomain.Endian.Unknown,
                                               delegate(int addr)
                        {
                            return(hsbios[addr]);
                        },
                                               delegate(int addr, byte val)
                        {
                        }));
                        _MemoryDomains.Add(new MemoryDomain(
                                               "HSC RAM", hsram.Length, MemoryDomain.Endian.Unknown,
                                               delegate(int addr)
                        {
                            return(hsram[addr]);
                        },
                                               delegate(int addr, byte val)
                        {
                            hsram[addr] = val;
                        }));
                    }
                    _MemoryDomains.Add(new MemoryDomain(
                                           "System Bus", 65536, MemoryDomain.Endian.Unknown,
                                           delegate(int addr)
                    {
                        if (addr < 0 || addr >= 0x10000)
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        return(theMachine.Mem[(ushort)addr]);
                    },
                                           delegate(int addr, byte val)
                    {
                        if (addr < 0 || addr >= 0x10000)
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        theMachine.Mem[(ushort)addr] = val;
                    }));
                }
                else                 // todo 2600?
                {
                }
                MemoryDomains = new MemoryDomainList(_MemoryDomains);
            }
        }
        public static MachineStateInfo Create(ImportedGameProgramInfo importedGameProgramInfo, bool use7800Bios = false, bool use7800Hsc = false)
        {
            if (importedGameProgramInfo.StorageKeySet.Count == 0)
            {
                throw new ArgumentException("importedGameProgramInfo.StorageKeySet", nameof(importedGameProgramInfo));
            }

            var romBytes = importedGameProgramInfo.StorageKeySet
                           .Select(sk => DatastoreService.GetRomBytes(sk))
                           .FirstOrDefault(b => b.Length > 0) ?? Array.Empty <byte>();

            if (romBytes.Length == 0)
            {
                Error("MachineFactory.Create: No ROM bytes");
                return(MachineStateInfo.Default);
            }

            romBytes = RomBytesService.RemoveA78HeaderIfNecessary(romBytes);

            var gameProgramInfo = importedGameProgramInfo.GameProgramInfo;

            if (gameProgramInfo.CartType == CartType.Unknown)
            {
                var inferredCartType = RomBytesService.InferCartTypeFromSize(gameProgramInfo.MachineType, romBytes.Length);
                if (inferredCartType != gameProgramInfo.CartType)
                {
                    gameProgramInfo = gameProgramInfo with {
                        CartType = inferredCartType
                    };
                }
            }

            if (gameProgramInfo.MachineType != MachineType.A7800NTSC &&
                gameProgramInfo.MachineType != MachineType.A7800PAL)
            {
                use7800Bios = use7800Hsc = false;
            }

            var bios7800 = use7800Bios ? GetBios7800(gameProgramInfo) : Bios7800.Default;
            var hsc7800  = use7800Hsc ? GetHSC7800() : HSC7800.Default;

            Cart cart;

            try
            {
                cart = Cart.Create(romBytes, gameProgramInfo.CartType);
            }
            catch (Emu7800Exception ex)
            {
                Error("MachineFactory.Create: Unable to create Cart: " + ex.Message);
                return(MachineStateInfo.Default);
            }

            MachineBase machine;

            try
            {
                machine = MachineBase.Create(gameProgramInfo.MachineType, cart, bios7800, hsc7800,
                                             gameProgramInfo.LController, gameProgramInfo.RController, NullLogger.Default);
            }
            catch (Emu7800Exception ex)
            {
                Error("MachineFactory.Create: Unable to create Machine: " + ex.Message);
                return(MachineStateInfo.Default);
            }

            return(new()
            {
                FramesPerSecond = machine.FrameHZ,
                CurrentPlayerNo = 1,
                GameProgramInfo = gameProgramInfo,
                Machine = machine
            });
        }