Esempio n. 1
0
        private void MakeTrace(IntPtr _s)
        {
            int[] s = new int[14];
            System.Runtime.InteropServices.Marshal.Copy(_s, s, 0, 14);

            Tracer.Put(new TraceInfo
            {
                Disassembly =
                    LR35902.Disassemble(
                        (ushort)s[1],
                        addr => LibGambatte.gambatte_cpuread(GambatteState, addr),
                        _settings.RgbdsSyntax,
                        out _).PadRight(36),
                RegisterInfo =
                    string.Format(
                        "A:{3:x2} B:{4:x2} C:{5:x2} D:{6:x2} E:{7:x2} F:{8:x2} H:{9:x2} L:{10:x2} LY:{13:x2} SP:{2:x2} {11} Cy:{0}",
                        s[0],
                        s[1] & 0xffff,
                        s[2] & 0xffff,
                        s[3] & 0xff,
                        s[4] & 0xff,
                        s[5] & 0xff,
                        s[6] & 0xff,
                        s[7] & 0xff,
                        s[8] & 0xff,
                        s[9] & 0xff,
                        s[10] & 0xff,
                        s[11] != 0 ? "skip" : "",
                        s[12] & 0xff,
                        s[13] & 0xff)
            });
        }
Esempio n. 2
0
        public override string Disassemble(MemoryDomain m, uint addr, out int length)
        {
            ushort tmp;
            string ret = LR35902.Disassemble((ushort)addr, a => m.PeekByte(a), out tmp);

            length = tmp;
            return(ret);
        }
Esempio n. 3
0
                    public CPU( )
                    {
                        m_gb_core = new LR35902();

                        m_gb_core.BindCyclesStep(CyclesStep);

                        m_userCyclesRate = kCyclesPerFrame;
                        m_cyclesElapsed  = 0;
                    }
Esempio n. 4
0
        private void MakeTrace(IntPtr _s)
        {
            int[] s = new int[14];
            System.Runtime.InteropServices.Marshal.Copy(_s, s, 0, 14);
            ushort PC = (ushort)s[1];

            Tracer.Put(new(
                           disassembly: LR35902.Disassemble(
                               PC,
                               addr => {
                if (addr == PC)
                {
                    //opcode
                    return((byte)((s[12] >> 16) & 0xFF));
                }
                else
                {
                    if (addr == ((PC + 1) & 0xFFFF))
                    {
                        //high operand
                        return((byte)((s[12] >> 8) & 0xFF));
                    }
                    else
                    {
                        //low operand
                        return((byte)(s[12] & 0xFF));
                    }
                }
            },
                               _settings.RgbdsSyntax,
                               out _).PadRight(36),
                           registerInfo: string.Format(
                               "A:{3:x2} F:{8:x2} B:{4:x2} C:{5:x2} D:{6:x2} E:{7:x2} H:{9:x2} L:{10:x2} LY:{13:x2} SP:{2:x2} {11} Cy:{0}",
                               (ulong)s[0] + _cycleCount,
                               s[1] & 0xffff,
                               s[2] & 0xffff,
                               s[3] & 0xff,
                               s[4] & 0xff,
                               s[5] & 0xff,
                               s[6] & 0xff,
                               s[7] & 0xff,
                               s[8] & 0xff,
                               s[9] & 0xff,
                               s[10] & 0xff,
                               s[11] != 0 ? "prefetched" : "",
                               s[12] & 0xffffff,
                               s[13] & 0xff)));
        }
Esempio n. 5
0
        public GBHawk(CoreComm comm, GameInfo game, byte[] rom, /*string gameDbFn,*/ object settings, object syncSettings)
        {
            var ser = new BasicServiceProvider(this);

            cpu = new LR35902
            {
                ReadMemory      = ReadMemory,
                WriteMemory     = WriteMemory,
                PeekMemory      = PeekMemory,
                DummyReadMemory = ReadMemory,
                OnExecFetch     = ExecFetch
            };
            ppu        = new PPU();
            timer      = new Timer();
            audio      = new Audio();
            serialport = new SerialPort();

            CoreComm = comm;

            _settings       = (GBSettings)settings ?? new GBSettings();
            _syncSettings   = (GBSyncSettings)syncSettings ?? new GBSyncSettings();
            _controllerDeck = new GBHawkControllerDeck(_syncSettings.Port1);

            byte[] Bios = comm.CoreFileProvider.GetFirmware("GB", "World", false, "BIOS Not Found, Cannot Load");

            if (Bios == null)
            {
                throw new MissingFirmwareException("Missing Gamboy Bios");
            }

            _bios = Bios;

            Buffer.BlockCopy(rom, 0x100, header, 0, 0x50);

            string hash_md5 = null;

            hash_md5 = "md5:" + rom.HashMD5(0, rom.Length);
            Console.WriteLine(hash_md5);

            _rom = rom;
            Setup_Mapper();

            _frameHz = 60;

            timer.Core      = this;
            audio.Core      = this;
            ppu.Core        = this;
            serialport.Core = this;

            ser.Register <IVideoProvider>(this);
            ser.Register <ISoundProvider>(audio);
            ServiceProvider = ser;

            _settings     = (GBSettings)settings ?? new GBSettings();
            _syncSettings = (GBSyncSettings)syncSettings ?? new GBSyncSettings();

            _tracer = new TraceBuffer {
                Header = cpu.TraceHeader
            };
            ser.Register <ITraceable>(_tracer);

            SetupMemoryDomains();
            HardReset();

            iptr0 = Marshal.AllocHGlobal(CHR_RAM.Length + BG_map_1.Length + BG_map_2.Length + 1);
            iptr1 = Marshal.AllocHGlobal(OAM.Length + 1);
            iptr2 = Marshal.AllocHGlobal(color_palette.Length * 2 * 8 + 1);
            iptr3 = Marshal.AllocHGlobal(color_palette.Length * 8 + 1);

            _scanlineCallback = null;
        }
Esempio n. 6
0
        public GBHawk(CoreComm comm, GameInfo game, byte[] rom, /*string gameDbFn,*/ object settings, object syncSettings)
        {
            var ser = new BasicServiceProvider(this);

            cpu = new LR35902
            {
                ReadMemory      = ReadMemory,
                WriteMemory     = WriteMemory,
                PeekMemory      = PeekMemory,
                DummyReadMemory = ReadMemory,
                OnExecFetch     = ExecFetch,
                SpeedFunc       = SpeedFunc,
            };

            timer      = new Timer();
            audio      = new Audio();
            serialport = new SerialPort();

            CoreComm = comm;

            _settings       = (GBSettings)settings ?? new GBSettings();
            _syncSettings   = (GBSyncSettings)syncSettings ?? new GBSyncSettings();
            _controllerDeck = new GBHawkControllerDeck(_syncSettings.Port1);

            byte[] Bios = null;

            // Load up a BIOS and initialize the correct PPU
            if (_syncSettings.ConsoleMode == GBSyncSettings.ConsoleModeType.Auto)
            {
                if (game.System == "GB")
                {
                    Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");
                    ppu  = new GB_PPU();
                }
                else
                {
                    Bios   = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
                    ppu    = new GBC_PPU();
                    is_GBC = true;
                }
            }
            else if (_syncSettings.ConsoleMode == GBSyncSettings.ConsoleModeType.GB)
            {
                Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");
                ppu  = new GB_PPU();
            }
            else
            {
                Bios   = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
                ppu    = new GBC_PPU();
                is_GBC = true;
            }

            if (Bios == null)
            {
                throw new MissingFirmwareException("Missing Gamboy Bios");
            }

            _bios = Bios;

            // Here we modify the BIOS if GBA mode is set (credit to ExtraTricky)
            if (is_GBC && _syncSettings.GBACGB)
            {
                for (int i = 0; i < 13; i++)
                {
                    _bios[i + 0xF3] = (byte)((GBA_override[i] + _bios[i + 0xF3]) & 0xFF);
                }
            }

            // CPU needs to know about GBC status too
            cpu.is_GBC = is_GBC;

            Buffer.BlockCopy(rom, 0x100, header, 0, 0x50);

            string hash_md5 = null;

            hash_md5 = "md5:" + rom.HashMD5(0, rom.Length);
            Console.WriteLine(hash_md5);

            _rom = rom;
            Setup_Mapper();

            _frameHz = 60;

            timer.Core      = this;
            audio.Core      = this;
            ppu.Core        = this;
            serialport.Core = this;

            ser.Register <IVideoProvider>(this);
            ser.Register <ISoundProvider>(audio);
            ServiceProvider = ser;

            _settings     = (GBSettings)settings ?? new GBSettings();
            _syncSettings = (GBSyncSettings)syncSettings ?? new GBSyncSettings();

            _tracer = new TraceBuffer {
                Header = cpu.TraceHeader
            };
            ser.Register <ITraceable>(_tracer);

            SetupMemoryDomains();
            HardReset();

            iptr0 = Marshal.AllocHGlobal(VRAM.Length + 1);
            iptr1 = Marshal.AllocHGlobal(OAM.Length + 1);
            iptr2 = Marshal.AllocHGlobal(color_palette.Length * 8 * 8 + 1);
            iptr3 = Marshal.AllocHGlobal(color_palette.Length * 8 * 8 + 1);

            _scanlineCallback = null;
        }
Esempio n. 7
0
        public GBHawk(CoreComm comm, GameInfo game, byte[] rom, /*string gameDbFn,*/ GBSettings settings, GBSyncSettings syncSettings)
        {
            var ser = new BasicServiceProvider(this);

            cpu = new LR35902
            {
                ReadMemory      = ReadMemory,
                WriteMemory     = WriteMemory,
                PeekMemory      = PeekMemory,
                DummyReadMemory = ReadMemory,
                OnExecFetch     = ExecFetch,
                SpeedFunc       = SpeedFunc,
                GetButtons      = GetButtons,
                GetIntRegs      = GetIntRegs,
                SetIntRegs      = SetIntRegs
            };

            timer      = new Timer();
            audio      = new Audio();
            serialport = new SerialPort();

            _settings     = (GBSettings)settings ?? new GBSettings();
            _syncSettings = (GBSyncSettings)syncSettings ?? new GBSyncSettings();

            byte[] Bios = null;

            // Load up a BIOS and initialize the correct PPU
            if (_syncSettings.ConsoleMode == GBSyncSettings.ConsoleModeType.Auto)
            {
                if (game.System == "GB")
                {
                    Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");
                    ppu  = new GB_PPU();
                }
                else
                {
                    Bios   = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
                    ppu    = new GBC_PPU();
                    is_GBC = true;
                }
            }
            else if (_syncSettings.ConsoleMode == GBSyncSettings.ConsoleModeType.GB)
            {
                Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");
                ppu  = new GB_PPU();
            }
            else
            {
                Bios   = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
                ppu    = new GBC_PPU();
                is_GBC = true;
            }

            if (Bios == null)
            {
                throw new MissingFirmwareException("Missing Gamboy Bios");
            }

            _bios = Bios;

            // set up IR register to off state
            if (is_GBC)
            {
                IR_mask = 0; IR_reg = 0x3E; IR_receive = 2; IR_self = 2; IR_signal = 2;
            }

            // Here we modify the BIOS if GBA mode is set (credit to ExtraTricky)
            if (is_GBC && _syncSettings.GBACGB)
            {
                for (int i = 0; i < 13; i++)
                {
                    _bios[i + 0xF3] = (byte)((GBA_override[i] + _bios[i + 0xF3]) & 0xFF);
                }
                IR_mask = 2;
            }

            // CPU needs to know about GBC status too
            cpu.is_GBC = is_GBC;

            Buffer.BlockCopy(rom, 0x100, header, 0, 0x50);

            if (is_GBC && ((header[0x43] != 0x80) && (header[0x43] != 0xC0)))
            {
                ppu = new GBC_GB_PPU();
            }

            Console.WriteLine("MD5: " + rom.HashMD5(0, rom.Length));
            Console.WriteLine("SHA1: " + rom.HashSHA1(0, rom.Length));
            _rom = rom;
            string mppr = Setup_Mapper();

            if (cart_RAM != null)
            {
                cart_RAM_vbls = new byte[cart_RAM.Length];
            }

            if (mppr == "MBC7")
            {
                _controllerDeck = new GBHawkControllerDeck(_syncSettings.Port1);
            }
            else
            {
                _controllerDeck = new GBHawkControllerDeck(GBHawkControllerDeck.DefaultControllerName);
            }

            timer.Core      = this;
            audio.Core      = this;
            ppu.Core        = this;
            serialport.Core = this;

            ser.Register <IVideoProvider>(this);
            ser.Register <ISoundProvider>(audio);
            ServiceProvider = ser;

            _settings     = (GBSettings)settings ?? new GBSettings();
            _syncSettings = (GBSyncSettings)syncSettings ?? new GBSyncSettings();

            _tracer = new TraceBuffer {
                Header = cpu.TraceHeader
            };
            ser.Register <ITraceable>(_tracer);
            ser.Register <IStatable>(new StateSerializer(SyncState));
            SetupMemoryDomains();
            cpu.SetCallbacks(ReadMemory, PeekMemory, PeekMemory, WriteMemory);
            HardReset();

            iptr0 = Marshal.AllocHGlobal(VRAM.Length + 1);
            iptr1 = Marshal.AllocHGlobal(OAM.Length + 1);
            iptr2 = Marshal.AllocHGlobal(ppu.color_palette.Length * 8 * 8 + 1);
            iptr3 = Marshal.AllocHGlobal(ppu.color_palette.Length * 8 * 8 + 1);

            _scanlineCallback = null;

            /*
             * for (int i = 0; i < ZP_RAM.Length; i++)
             * {
             *      ZP_RAM[i] = 0xFF;
             * }
             *
             * for (int i = 0; i < RAM.Length; i++)
             * {
             *      RAM[i] = 0xFF;
             * }
             */
        }