Ejemplo n.º 1
0
        public override void PostFrameCallback()
        {
            uint frame = Mem.ReadU32(AddrGlobal.NonLagFrameCount);

            if ((frame <= _prevF) && !Emu.IsLagged())
            {
                Emu.SetIsLagged(true);
                Emu.SetLagCount(Emu.LagCount() + 1);
            }
            uint mode = Mem.ReadByte(AddrGlobal.GameMode);

            _levelTime = Mem.ReadU16(AddrGlobal.LevelFrameCount);
            ResetStatusLine();
            StatusText($"Frames: {Mem.ReadU32(AddrGlobal.FrameCount),7} Nonlag: {frame,7} Level: {_levelTime,6} GameMode: {mode:X2}");
            switch (mode)
            {
            case 0x20:
            case 0x28:
            case 0xAC:
                Update2DTickers();
                if (_mapDumpState != 0)
                {
                    PostProcessMapDump();
                }
                DrawTurnSignal();
                break;

            case 0xF6:
                Update3DTickers();
                break;
            }
            Joy.Set("C", null, 1);
            Joy.Set("Start", null, 1);
            Gui.DrawFinish();
        }
Ejemplo n.º 2
0
        public void Emu_lives_in_down_under_and_is_flightless()
        {
            //Arrange and Act
            Emu emu = new Emu();

            //Assert
            Assert.Equal("The great down under", emu.Home());
            Assert.Equal("I might flap my wings, but I'll never fly", emu.Movement());
        }
Ejemplo n.º 3
0
        private void SetEmu(TextBox currentTextBox, Emu emu)
        {
            SetEmuInner(CentimetersText, emu.ToCm().Value);
            SetEmuInner(EmuText, emu.Value);
            SetEmuInner(PixelText, emu.ToPixel().Value);
            SetEmuInner(PoundText, emu.ToPixel().ToPound().Value);
            SetEmuInner(InchText, emu.ToInch().Value);
            SetEmuInner(HalfPointText, emu.ToPt().ToHalfPoint().Value);
            SetEmuInner(PointText, emu.ToPt().Value);

            void SetEmuInner(TextBox textBox, double value)
            {
                SetTextInner(textBox, value.ToString());
            }

            void SetTextInner(TextBox textBox, string text)
            {
                if (!ReferenceEquals(textBox, currentTextBox))
                {
                    textBox.Text = text;
                }
            }
        }
Ejemplo n.º 4
0
        public List<Game> GetGames(Emu emulator)
        {
            List<Game> games = new List<Game>();

            //Create a JSON serializer to read/write the game data json files.
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            //Get all ROM files within the specified directory
            var RomFiles = Directory.GetFiles(Path.Combine(emulator.Location, emulator.RomLocation), emulator.SearchPattern);

            //Go through each rom within the rom directory
            foreach (var rom in RomFiles)
            {
                //Find the data for the rom within the data directory
                string infoJsonPath = Path.Combine("Games", "Data", Path.GetFileNameWithoutExtension(rom), "data.json");

                //If the data doesn't exist, we need to look it up through MAME
                if (!File.Exists(infoJsonPath))
                {
                    //Create the directory for the game data to be held in
                    if (!Directory.Exists(Path.GetDirectoryName(infoJsonPath)))
                        Directory.CreateDirectory(Path.GetDirectoryName(infoJsonPath));

                    //Create a new Game object to hold all the game data
                    Game romGame = new Game();

                    //The data directory is located where we specified it
                    romGame.DataDirectory = Path.GetDirectoryName(infoJsonPath);
                    romGame.Location = rom;

                    //Create a new mame process with the argument -listfull {rom} to get the rom name
                    var proc = new Process
                    {
                        StartInfo = new ProcessStartInfo
                        {
                            FileName = Path.Combine(emulator.Location, emulator.LaunchExecutable),
                            Arguments = $"-listfull {Path.GetFileNameWithoutExtension(rom)}",
                            UseShellExecute = false,
                            RedirectStandardOutput = true,
                            CreateNoWindow = true
                        }
                    };
                    proc.Start();

                    //Read the console output from MAME
                    while (!proc.StandardOutput.EndOfStream)
                    {
                        //Read the input from the console
                        string output = proc.StandardOutput.ReadLine();
                        //Check if the string has a "
                        int gameLoc = output.IndexOf("\"");

                        //If it doesn't, it's the header and we don't care about this line
                        if (gameLoc == -1)
                            continue;

                        //Get the game name that's within the quotes
                        string gameName = output.Substring(gameLoc + 1, output.Length - gameLoc - 2);
                        Log.Write("Adding information for game \"" + gameName + "\"");

                        //Assign the game name to the game
                        romGame.Name = gameName;
                    }

                    //Get the game data from GameDB
                    romGame = GameDBScraper.UpdateGameData(romGame);

                    //Write the game data to the data directory
                    File.WriteAllText(infoJsonPath, serializer.Serialize(romGame));
                }

                Game game = serializer.Deserialize<Game>(File.ReadAllText(infoJsonPath));

                //Add the game to the game list
                if (!game.Skip)
                    games.Add(game);
            }

            return games;
        }
Ejemplo n.º 5
0
        public PeRunner(PeRunnerOptions opt)
        {
            _nextStart = opt.StartAddress;
            Initialize(_nextStart);
            using (this.EnterExit())
            {
                // load any predefined exports
                _psx = new Psx(this);
                _exports.Add("libpsxscl.so", BizExvoker.GetExvoker(_psx, CallingConventionAdapters.Waterbox));
                _emu = new Emu(this);
                _exports.Add("libemuhost.so", BizExvoker.GetExvoker(_emu, CallingConventionAdapters.Waterbox));
                _syscalls = new Syscalls(this);
                _exports.Add("__syscalls", BizExvoker.GetExvoker(_syscalls, CallingConventionAdapters.Waterbox));

                // load and connect all modules, starting with the executable
                var todoModules = new Queue <string>();
                todoModules.Enqueue(opt.Filename);

                while (todoModules.Count > 0)
                {
                    var moduleName = todoModules.Dequeue();
                    if (!_exports.ContainsKey(moduleName))
                    {
                        var    path   = Path.Combine(opt.Path, moduleName);
                        var    gzpath = path + ".gz";
                        byte[] data;
                        if (File.Exists(gzpath))
                        {
                            using (var fs = new FileStream(gzpath, FileMode.Open, FileAccess.Read))
                            {
                                data = Util.DecompressGzipFile(fs);
                            }
                        }
                        else
                        {
                            data = File.ReadAllBytes(path);
                        }

                        var module = new PeWrapper(moduleName, data, _nextStart);
                        ComputeNextStart(module.Size);
                        AddMemoryBlock(module.Memory, moduleName);
                        _savestateComponents.Add(module);
                        _disposeList.Add(module);

                        _exports.Add(moduleName, module);
                        _modules.Add(module);
                        foreach (var name in module.ImportsByModule.Keys)
                        {
                            todoModules.Enqueue(name);
                        }
                    }
                }

                _libcpatch          = new LibcPatch(this);
                _exports["libc.so"] = new PatchImportResolver(_exports["libc.so"], BizExvoker.GetExvoker(_libcpatch, CallingConventionAdapters.Waterbox));

                ConnectAllImports();

                // load all heaps
                _heap          = CreateHeapHelper(opt.SbrkHeapSizeKB, "brk-heap", true);
                _sealedheap    = CreateHeapHelper(opt.SealedHeapSizeKB, "sealed-heap", true);
                _invisibleheap = CreateHeapHelper(opt.InvisibleHeapSizeKB, "invisible-heap", false);
                _plainheap     = CreateHeapHelper(opt.PlainHeapSizeKB, "plain-heap", true);

                if (opt.MmapHeapSizeKB != 0)
                {
                    _mmapheap = new MapHeap(_nextStart, opt.MmapHeapSizeKB * 1024, "mmap-heap");
                    _mmapheap.Memory.Activate();
                    ComputeNextStart(opt.MmapHeapSizeKB * 1024);
                    AddMemoryBlock(_mmapheap.Memory, "mmap-heap");
                    _savestateComponents.Add(_mmapheap);
                    _disposeList.Add(_mmapheap);
                }

                _syscalls.Init();

                Console.WriteLine("About to enter unmanaged code");
                if (!OSTailoredCode.IsUnixHost && !System.Diagnostics.Debugger.IsAttached && Win32Imports.IsDebuggerPresent())
                {
                    // this means that GDB or another unconventional debugger is attached.
                    // if that's the case, and it's observing this core, it probably wants a break
                    System.Diagnostics.Debugger.Break();
                }

                // run unmanaged init code
                var libcEnter = _exports["libc.so"].GetProcAddrOrThrow("__libc_entry_routine");
                var psxInit   = _exports["libpsxscl.so"].GetProcAddrOrThrow("__psx_init");

                var del = (LibcEntryRoutineD)CallingConventionAdapters.Waterbox.GetDelegateForFunctionPointer(libcEnter, typeof(LibcEntryRoutineD));
                // the current mmglue code doesn't use the main pointer at all, and this just returns
                del(IntPtr.Zero, psxInit, 0);

                foreach (var m in _modules)
                {
                    m.RunGlobalCtors();
                }

                /*try
                 * {
                 *      _modules[0].RunExeEntry();
                 *      //throw new InvalidOperationException("main() returned!");
                 * }
                 * catch //(EndOfMainException)
                 * {
                 * }
                 * _modules[0].RunGlobalCtors();
                 * foreach (var m in _modules.Skip(1))
                 * {
                 *      if (!m.RunDllEntry())
                 *              throw new InvalidOperationException("DllMain() returned false");
                 *      m.RunGlobalCtors();
                 * }*/
            }
        }
Ejemplo n.º 6
0
Archivo: VBA.cs Proyecto: snowl/Arcadia
        /// <summary>
        /// Gets all games for Visual Boy Advanced
        /// </summary>
        /// <param name="emulator">The data for the VBA emu</param>
        /// <returns>A list of games for VBA</returns>
        public List<Game> GetGames(Emu emulator)
        {
            List<Game> games = new List<Game>();

            //Create a JSON serializer to read/write the game data json files.
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            //Get all ROM files within the specified directory
            var RomFiles = Directory.GetFiles(Path.Combine(emulator.Location, emulator.RomLocation), emulator.SearchPattern);

            //Go through each rom within the rom directory
            foreach (var rom in RomFiles)
            {
                string gameTitle = "";
                string gameCode = "";

                //Open up each ROM to be read
                using (BinaryReader reader = new BinaryReader(File.Open(rom, FileMode.Open)))
                {
                    if (Path.GetExtension(rom) == ".gba")
                    {
                        //Skip to position 0xA0
                        reader.ReadBytes(0xA0);

                        //Read the Game Title (0xA0 - 0xAB)
                        gameTitle = Encoding.ASCII.GetString(reader.ReadBytes(12)).Replace("\0", "").Replace(" ", "");
                        //Read the Game Code (0xAC - 0xAF)
                        gameCode = Encoding.ASCII.GetString(reader.ReadBytes(4));
                    }
                    else if (Path.GetExtension(rom) == ".gbc")
                    {
                        reader.ReadBytes(0x134);

                        gameTitle = Encoding.ASCII.GetString(reader.ReadBytes(11)).Replace("\0", "").Replace(" ", "");
                        gameCode = Encoding.ASCII.GetString(reader.ReadBytes(4));
                    }
                }

                //Create the gameName for the directory
                string gameName = gameTitle + "-" + gameCode;

                //Find the data for the rom within the data directory
                string infoJsonPath = Path.Combine("Games", "Data", gameName, "data.json");

                //If the data doesn't exist, we need to look it up online
                if (!File.Exists(infoJsonPath))
                {
                    //Create the directory for the game data to be held in
                    if (!Directory.Exists(Path.GetDirectoryName(infoJsonPath)))
                        Directory.CreateDirectory(Path.GetDirectoryName(infoJsonPath));

                    //Create a new Game object to hold all the game data
                    Game romGame = new Game();

                    //The data directory is located where we specified it
                    romGame.DataDirectory = Path.GetDirectoryName(infoJsonPath);
                    romGame.Location = rom;

                    //Get the name of the rom through Nintendo Age
                    romGame.Name = NintendoAgeScraper.IdentifyGameByGameCode(NintendoAgeConsole.GameboyAdvance, gameCode);

                    Log.Write("Adding information for game \"" + romGame.Name + "\"");

                    //Get the game data from GameDB
                    romGame = GameDBScraper.UpdateGameData(romGame);

                    //Write the game data to the data directory
                    File.WriteAllText(infoJsonPath, serializer.Serialize(romGame));
                }

                Game game = serializer.Deserialize<Game>(File.ReadAllText(infoJsonPath));

                //Add the game to the game list
                if (!game.Skip)
                    games.Add(game);
            }

            return games;
        }
Ejemplo n.º 7
0
        private void PostProcessMapDump()
        {
            PlayerObj player;

            ReadPlayerObj(Addr2D.PlayerObj, out player);
            Mem.WriteS16(Addr2D.PlayerObj + 0x42, 7);  // Hide HP meter
            Mem.WriteS16(Addr2D.PlayerObj + 0x44, 56); // Hide air meter
            Point playerPos = GetScreenLoc(player.Mid);

            if ((playerPos.X < -64) || (playerPos.X > 384) || (playerPos.Y < -64) || (playerPos.Y > 288))
            {
                Mem.WriteByte(Addr2D.PlayerObj + 0x9C, 0xC); // set player invincibility
                Mem.WriteS16(0xFFA7CA, 1);                   // set flag that flashes invincible sprites invisible
            }
            else
            {
                Mem.WriteByte(Addr2D.PlayerObj + 0x9C, 0x0); // clear player invincibiility
                Mem.WriteS16(0xFFA7CA, 0);                   // clear flag that flashes invincible sprites invisible
            }
            int levelWidth  = Mem.ReadS16(Addr2D.LevelWidth);
            int levelHeight = Mem.ReadS16(Addr2D.LevelHeight);
            var levelID     = Mem.ReadByte(AddrGlobal.LevelID);

            GPGX.GPGXSettings s;
            switch (_mapDumpState)
            {
            case 1:
                s          = Emu.GetSettings() as GPGX.GPGXSettings;
                s.DrawBGA  = false;
                s.DrawBGB  = false;
                s.DrawBGW  = false;
                s.DrawObj  = false;
                s.Backdrop = true;
                Emu.PutSettings(s);
                if ((_camX == _destX) && (_camY == _destY))
                {
                    if ((_prevX != _camX) || (_prevY != _camY))
                    {
                        if (_destX == 0)
                        {
                            if (_rowStateGuid != string.Empty)
                            {
                                MemSS.DeleteState(_rowStateGuid);
                            }
                            _rowStateGuid = MemSS.SaveCoreStateToMemory();
                        }
                        _snapPast = 1;
                    }
                    else
                    {
                        _snapPast--;
                    }
                    if (_snapPast == 0)
                    {
                        ClientApi.Screenshot($"{MapDumpFolder}{levelID}\\{_destY}_{_destX}_top.png");
                        if (_destX >= levelWidth - 320)
                        {
                            if (_destY < levelHeight - 224)
                            {
                                if (_rowStateGuid != string.Empty)
                                {
                                    MemSS.LoadCoreStateFromMemory(_rowStateGuid);
                                }
                                _destX = 0;
                                _destY = Math.Min(_destY + 111, levelHeight - 224);
                            }
                        }
                        else
                        {
                            _destX = Math.Min(_destX + 159, levelWidth - 320);
                        }
                        if ((_prevX == _destX) && (_prevY == _destY))
                        {
                            ClientApi.SetGameExtraPadding(levelWidth - 320, levelHeight - 224, 0, 0);
                            _mapDumpState++;
                        }
                    }
                }
                Mem.WriteS16(Addr2D.CamXDest, _destX);
                Mem.WriteS16(Addr2D.CamYDest, _destY);
                break;

            case 2:
                if (_rowStateGuid != String.Empty)
                {
                    MemSS.DeleteState(_rowStateGuid);
                }
                _rowStateGuid = String.Empty;
                ClientApi.SetGameExtraPadding(levelWidth - 320, levelHeight - 224, 0, 0);
                s          = Emu.GetSettings() as GPGX.GPGXSettings;
                s.DrawBGA  = false;
                s.DrawBGB  = false;
                s.DrawBGW  = false;
                s.DrawObj  = false;
                s.Backdrop = true;
                Emu.PutSettings(s);

                var a = Gui.GetAttributes();
                a.SetColorKey(Color.FromArgb(0, 0x11, 0x22, 0x33), Color.FromArgb(0, 0x11, 0x22, 0x33));
                Gui.SetAttributes(a);
                Gui.ToggleCompositingMode();

                Gui.DrawImageRegion($"{MapDumpFolder}{levelID}\\{levelHeight - 224}_{levelWidth - 320}_top.png", 2, 2, 318, 222, (levelWidth - 318), (levelHeight - 222), 318, 222);
                for (int x = ((levelWidth - 320) / 159) * 159; x >= 0; x -= 159)
                {
                    var dx = (x == 0) ? 0 : 2;
                    Gui.DrawImageRegion($"{MapDumpFolder}{levelID}\\{levelHeight - 224}_{x}_top.png", dx, 2, 320 - dx, 222, x + dx, (levelHeight - 222), 320 - dx, 222);
                }
                for (int y = ((levelHeight - 224) / 111) * 111; y >= 0; y -= 111)
                {
                    var dy = (y == 0) ? 0 : 2;
                    Gui.DrawImageRegion($"{MapDumpFolder}{levelID}\\{y}_{levelWidth - 320}_top.png", 2, dy, 318, 224 - 2, levelWidth - 318, y + dy, 318, 224 - dy);
                    for (int x = ((levelWidth - 320) / 159) * 159; x >= 0; x -= 159)
                    {
                        var dx = (x == 0) ? 0 : 2;
                        Gui.DrawImageRegion($"{MapDumpFolder}{levelID}\\{y}_{x}_top.png", dx, dy, 320 - dx, 224 - dy, x + dx, y + dy, 320 - dx, 224 - dy);
                    }
                }
                Gui.ToggleCompositingMode();
                Gui.SetAttributes(new System.Drawing.Imaging.ImageAttributes());
                Gui.DrawFinish();
                _mapDumpState++;
                break;

            case 4:
                s          = Emu.GetSettings() as GPGX.GPGXSettings;
                s.DrawBGA  = (levelID != 29);
                s.DrawBGB  = (levelID == 7);
                s.DrawBGW  = true;
                s.DrawObj  = true;
                s.Backdrop = false;
                Emu.PutSettings(s);
                if ((_camX == _destX) && (_camY == _destY))
                {
                    if ((_prevX != _camX) || (_prevY != _camY))
                    {
                        if (_destX == 0)
                        {
                            if (_rowStateGuid != string.Empty)
                            {
                                MemSS.DeleteState(_rowStateGuid);
                            }
                            _rowStateGuid = MemSS.SaveCoreStateToMemory();
                        }
                        _snapPast = 1;
                    }
                    else
                    {
                        _snapPast--;
                    }
                    if (_snapPast == 0)
                    {
                        ClientApi.Screenshot($"{MapDumpFolder}{levelID}\\{_destY}_{_destX}_bottom.png");
                        if (_destX >= levelWidth - 320)
                        {
                            if (_destY < levelHeight - 224)
                            {
                                if (_rowStateGuid != string.Empty)
                                {
                                    MemSS.LoadCoreStateFromMemory(_rowStateGuid);
                                }
                                _destX = 0;
                                _destY = Math.Min(_destY + 111, levelHeight - 224);
                            }
                        }
                        else
                        {
                            _destX = Math.Min(_destX + 159, levelWidth - 320);
                        }
                        if ((_prevX == _destX) && (_prevY == _destY))
                        {
                            ClientApi.SetGameExtraPadding(levelWidth - 320, levelHeight - 224, 0, 0);
                            _mapDumpState++;
                        }
                    }
                }
                Mem.WriteS16(Addr2D.CamXDest, _destX);
                Mem.WriteS16(Addr2D.CamYDest, _destY);
                break;

            case 5:
                if (_rowStateGuid != String.Empty)
                {
                    MemSS.DeleteState(_rowStateGuid);
                }
                _rowStateGuid = String.Empty;
                s             = Emu.GetSettings() as GPGX.GPGXSettings;
                s.DrawBGA     = (levelID != 29);
                s.DrawBGB     = (levelID == 7);
                s.DrawBGW     = true;
                s.DrawObj     = true;
                s.Backdrop    = false;
                Emu.PutSettings(s);
                Gui.DrawImageRegion($"{MapDumpFolder}{levelID}\\{levelHeight - 224}_{levelWidth - 320}_bottom.png", 2, 2, 318, 222, (levelWidth - 318), (levelHeight - 222), 318, 222);
                for (int x = ((levelWidth - 320) / 159) * 159; x >= 0; x -= 159)
                {
                    var dx = (x == 0) ? 0 : 2;
                    Gui.DrawImageRegion($"{MapDumpFolder}{levelID}\\{levelHeight - 224}_{x}_bottom.png", dx, 2, 320 - dx, 222, x + dx, (levelHeight - 222), 320 - dx, 222);
                }
                for (int y = ((levelHeight - 224) / 111) * 111; y >= 0; y -= 111)
                {
                    var dy = (y == 0) ? 0 : 2;
                    Gui.DrawImageRegion($"{MapDumpFolder}{levelID}\\{y}_{levelWidth - 320}_bottom.png", 2, dy, 318, 224 - 2, levelWidth - 318, y + dy, 318, 224 - dy);
                    for (int x = ((levelWidth - 320) / 159) * 159; x >= 0; x -= 159)
                    {
                        var dx = (x == 0) ? 0 : 2;
                        Gui.DrawImageRegion($"{MapDumpFolder}{levelID}\\{y}_{x}_bottom.png", dx, dy, 320 - dx, 224 - dy, x + dx, y + dy, 320 - dx, 224 - dy);
                    }
                }
                Gui.DrawFinish();
                _mapDumpState++;
                break;
            }
            _prevX = _camX;
            _prevY = _camY;
        }
Ejemplo n.º 8
0
 public static Pt ToPt(this Emu emu)
 {
     return(new Pt(emu.Value / 12700));
 }
Ejemplo n.º 9
0
 public static Pixel ToPixel(this Emu emu)
 {
     return(new Pixel(emu.Value / 914400 * DefaultDpi));
 }
Ejemplo n.º 10
0
 public static Mm ToMm(this Emu emu)
 {
     return(new Mm(emu.Value / 36000));
 }
Ejemplo n.º 11
0
 public static Dxa ToDxa(this Emu emu)
 {
     return(new Dxa(emu.Value / 635));
 }
Ejemplo n.º 12
0
 public static Cm ToCm(this Emu emu)
 {
     return(new Cm(emu.Value / 360000));
 }
Ejemplo n.º 13
0
 public static Inch ToInch(this Emu emu)
 {
     return(new Inch(emu.Value / 914400));
 }