Exemplo n.º 1
0
 private void RefreshBreakpoints()
 {
     //lock (emulatorLock)
     {
         SnesDebugApi.SetBreakpoints(_breakpoints.ToArray(), (UInt32)_breakpoints.Count);
     }
 }
Exemplo n.º 2
0
        private void HandleNotification(NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case ConsoleNotificationType.GameLoaded:
                if (!SnesApi.IsPaused())
                {
                    RefreshBreakpoints();
                }
                GameLoaded();
                if (OnRun != null)
                {
                    OnRun();
                }
                if (OnStatusChange != null)
                {
                    OnStatusChange(EmulatorStatus.Playing);
                }
                EmitDebugData();
                break;

            case ConsoleNotificationType.CodeBreak:
                var source = (SnesBreakSource)(byte)e.Parameter.ToInt64();
                //if (source == SnesBreakSource.Breakpoint && OnBreak != null)
                if (OnBreak != null)
                {
                    var state   = SnesDebugApi.GetState();
                    var address = SnesDebugApi.GetAbsoluteAddress(new AddressInfo
                    {
                        Address = (state.Cpu.K << 16) | state.Cpu.PC,
                        Type    = SnesMemoryType.CpuMemory
                    });
                    OnBreak(address.Address);
                }
                if (OnStatusChange != null)
                {
                    OnStatusChange(EmulatorStatus.Paused);
                }
                EmitDebugData();
                break;

            case ConsoleNotificationType.PpuFrameDone:
                CountFrame();
                break;
            }

            if (e.NotificationType == ConsoleNotificationType.PpuFrameDone)
            {
                return;
            }
            if (e.NotificationType == ConsoleNotificationType.EventViewerRefresh)
            {
                return;
            }

            var status = string.Format("Emulator: {0}", e.NotificationType.ToString());

            _logHandler(new LogData(status, LogType.Normal));
        }
Exemplo n.º 3
0
 public void Pause()
 {
     if (!IsRunning())
     {
         return;
     }
     SnesDebugApi.Step(CpuType.Cpu, 1);
 }
Exemplo n.º 4
0
        private void GetTileMapData()
        {
            _tilemapOptions.Layer     = (byte)_state.TileMaps.GetPage;
            _state.TileMaps.MapWidth  = GetMapWidth();
            _state.TileMaps.MapHeight = GetMapHeight();
            SnesDebugApi.GetTilemap(_tilemapOptions, _state.SnesState.Ppu, _state.Memory.PpuData, _state.Memory.CgRam, _state.TileMaps.PixelData[0]);

            _state.TileMaps.ViewportHeight = _state.SnesState.Ppu.OverscanMode ? 239 : 224;
            _state.TileMaps.ScrollX        = (_state.SnesState.Ppu.BgMode == 7 ? (int)_state.SnesState.Ppu.Mode7.HScroll : _state.SnesState.Ppu.Layers[_tilemapOptions.Layer].HScroll) % _state.TileMaps.MapWidth;
            _state.TileMaps.ScrollY        = (_state.SnesState.Ppu.BgMode == 7 ? (int)_state.SnesState.Ppu.Mode7.VScroll : _state.SnesState.Ppu.Layers[_tilemapOptions.Layer].VScroll) % _state.TileMaps.MapHeight;
        }
Exemplo n.º 5
0
        private void PushTileMapData()
        {
            _state.Memory.CgRam   = SnesDebugApi.GetMemoryState(SnesMemoryType.CGRam);
            _state.Memory.PpuData = SnesDebugApi.GetMemoryState(SnesMemoryType.VideoRam);
            _state.SnesState      = _state.SnesState = SnesDebugApi.GetState();

            GetTileMapData();
            if (OnRegisterUpdate != null)
            {
                OnRegisterUpdate(_state);
            }
        }
Exemplo n.º 6
0
        private void GetCharacterData()
        {
            _tileViewOptions.Format   = (TileFormat)_state.CharacterData.ColorMode;
            _tileViewOptions.Width    = 16;
            _tileViewOptions.PageSize = 0x10000;
            var source  = SnesDebugApi.GetMemoryState(SnesMemoryType.VideoRam);
            var address = 0;
            var size    = Math.Min(source.Length - address, _tileViewOptions.PageSize);

            Array.Copy(source, address, _tileSource, 0, size);
            _state.CharacterData.Width  = 128;
            _state.CharacterData.Height = GetChrHeight(_tileViewOptions, _state.CharacterData.ColorMode);
            SnesDebugApi.GetTileView(_tileViewOptions, _tileSource, _tileSource.Length, _state.Memory.CgRam, _state.CharacterData.PixelData[0]);
        }
Exemplo n.º 7
0
        protected override void EmitDebugData()
        {
            if (OnRegisterUpdate == null)
            {
                return;
            }

            _state.SnesState      = SnesDebugApi.GetState();
            _state.Memory.PpuData = SnesDebugApi.GetMemoryState(SnesMemoryType.VideoRam);
            _state.Memory.OamData = SnesDebugApi.GetMemoryState(SnesMemoryType.SpriteRam);
            _state.Memory.CgRam   = SnesDebugApi.GetMemoryState(SnesMemoryType.CGRam);
            _state.Memory.CpuData = SnesDebugApi.GetMemoryState(SnesMemoryType.CpuMemory);
            _state.Memory.X       = _state.SnesState.Cpu.X & (_state.SnesState.Cpu.PS.HasFlag(ProcFlags.IndexMode8) ? 0xFF : 0xFFFF);
            _state.Memory.Y       = _state.SnesState.Cpu.Y & (_state.SnesState.Cpu.PS.HasFlag(ProcFlags.IndexMode8) ? 0xFF : 0xFFFF);
            SnesDebugApi.GetSpritePreview(_spriteOptions, _state.SnesState.Ppu, _state.Memory.PpuData, _state.Memory.OamData, _state.Memory.CgRam, _state.Sprites.PixelData);
            _state.Sprites.Details = Sprite.GetSnesSprites(_state.Memory.OamData, _state.SnesState.Ppu.OamMode);

            GetCharacterData();
            GetTileMapData();

            OnRegisterUpdate(_state);
        }
Exemplo n.º 8
0
 public void StepOver()
 {
     SnesDebugApi.Step(CpuType.Cpu, 1, StepType.StepOver);
 }
Exemplo n.º 9
0
 public void StepInto()
 {
     SnesDebugApi.Step(CpuType.Cpu, 1, StepType.Step);
 }
Exemplo n.º 10
0
 public static byte[] GetMemoryState(SnesMemoryType type)
 {
     byte[] buffer = new byte[DebugApi.GetMemorySize(type)];
     DebugApi.GetMemoryStateWrapper(type, buffer);
     return(buffer);
 }
Exemplo n.º 11
0
 public static byte[] GetEventViewerOutput(UInt32 scanlineCount, EventViewerDisplayOptions options)
 {
     byte[] buffer = new byte[340 * 2 * scanlineCount * 2 * 4];
     DebugApi.GetEventViewerOutputWrapper(buffer, options);
     return(buffer);
 }
Exemplo n.º 12
0
 public void SetPpuMemory(int offset, byte value)
 {
     SnesDebugApi.SetMemoryValue(SnesMemoryType.VideoRam, (uint)offset, value);
 }
Exemplo n.º 13
0
 public void SetOamMemory(int offset, byte value)
 {
     SnesDebugApi.SetMemoryValue(SnesMemoryType.SpriteRam, (uint)offset, value);
 }
Exemplo n.º 14
0
 public static byte[] GetEventViewerOutput(EventViewerDisplayOptions options)
 {
     byte[] buffer = new byte[340 * 2 * 262 * 2 * 4];
     DebugApi.GetEventViewerOutputWrapper(buffer, options);
     return(buffer);
 }
Exemplo n.º 15
0
 public void SetCpuMemory(int offset, byte value)
 {
     // TODO: Is emulator running?
     SnesDebugApi.SetMemoryValue(SnesMemoryType.CpuMemory, (uint)offset, value);
 }
Exemplo n.º 16
0
 public static AddressCounters[] GetMemoryAccessCounts(UInt32 offset, UInt32 length, SnesMemoryType type)
 {
     AddressCounters[] counts = new AddressCounters[length];
     DebugApi.GetMemoryAccessCountsWrapper(offset, length, type, counts);
     return(counts);
 }
Exemplo n.º 17
0
 public static UInt64[] GetMemoryAccessStamps(UInt32 offset, UInt32 length, SnesMemoryType type, MemoryOperationType operationType)
 {
     UInt64[] stamps = new UInt64[length];
     DebugApi.GetMemoryAccessStampsWrapper(offset, length, type, operationType, stamps);
     return(stamps);
 }
Exemplo n.º 18
0
 public void StepOut()
 {
     SnesDebugApi.Step(CpuType.Cpu, 1, StepType.StepOut);
 }
Exemplo n.º 19
0
 public static UInt32[] GetMemoryAccessCounts(UInt32 offset, UInt32 length, SnesMemoryType type, MemoryOperationType operationType)
 {
     UInt32[] counts = new UInt32[length];
     DebugApi.GetMemoryAccessCountsWrapper(offset, length, type, operationType, counts);
     return(counts);
 }
Exemplo n.º 20
0
 public static string GetScriptLog(Int32 scriptId)
 {
     return(Utf8Marshaler.PtrToStringUtf8(DebugApi.GetScriptLogWrapper(scriptId)).Replace("\n", Environment.NewLine));
 }
Exemplo n.º 21
0
 public static string GetExecutionTrace(UInt32 lineCount)
 {
     return(Utf8Marshaler.PtrToStringUtf8(DebugApi.GetExecutionTraceWrapper(lineCount)));
 }
Exemplo n.º 22
0
 public static byte[] GetCdlData(UInt32 offset, UInt32 length, SnesMemoryType memType)
 {
     byte[] cdlData = new byte[length];
     DebugApi.GetCdlDataWrapper(offset, length, memType, cdlData);
     return(cdlData);
 }
Exemplo n.º 23
0
 public void InitDebugger()
 {
     //var debuggerAlreadyRunning = SnesDebugApi.DebugIsDebuggerRunning();
     SnesDebugApi.InitializeDebugger();
 }
Exemplo n.º 24
0
 public static string GetLog()
 {
     return(Utf8Marshaler.PtrToStringUtf8(DebugApi.GetDebuggerLogWrapper()).Replace("\n", Environment.NewLine));
 }