[pspplayer commit] r601 - in trunk: Noxa.Emulation.Psp.Cpu.R4000Ultra Noxa.Emulation.Psp.Player/Debugger/Tools

1 view
Skip to first unread message

codesite...@google.com

unread,
Mar 29, 2008, 10:10:03 PM3/29/08
to psppla...@googlegroups.com
Author: ben.vanik
Date: Sat Mar 29 19:09:53 2008
New Revision: 601

Modified:
trunk/Noxa.Emulation.Psp.Cpu.R4000Ultra/R4000Hook.cpp
trunk/Noxa.Emulation.Psp.Player/Debugger/Tools/RegistersControl.cs

Log:
Basic register editing - click to edit - if you add '.d' to the end of
the value, it'll be interpreted as a base-10 number

Modified: trunk/Noxa.Emulation.Psp.Cpu.R4000Ultra/R4000Hook.cpp
==============================================================================
--- trunk/Noxa.Emulation.Psp.Cpu.R4000Ultra/R4000Hook.cpp (original)
+++ trunk/Noxa.Emulation.Psp.Cpu.R4000Ultra/R4000Hook.cpp Sat Mar 29
19:09:53 2008
@@ -211,7 +211,12 @@
{
case RegisterSet::Gpr:
Debug::Assert( ( T::typeid == uint::typeid ) || ( T::typeid ==
int::typeid ) );
- return ( T )( uint )_cpuCtx->Registers[ ordinal ];
+ if( ordinal == 32 )
+ return ( T )( uint )_cpuCtx->LO;
+ else if( ordinal == 33 )
+ return ( T )( uint )_cpuCtx->HI;
+ else
+ return ( T )( uint )_cpuCtx->Registers[ ordinal ];
case RegisterSet::Fpu:
Debug::Assert( T::typeid == float::typeid );
return ( T )_cpuCtx->Cp1Registers[ ordinal ];
@@ -229,7 +234,12 @@
{
case RegisterSet::Gpr:
Debug::Assert( ( T::typeid == uint::typeid ) || ( T::typeid ==
int::typeid ) );
- _cpuCtx->Registers[ ordinal ] = ( uint )value;
+ if( ordinal == 32 )
+ _cpuCtx->LO = ( uint )value;
+ else if( ordinal == 33 )
+ _cpuCtx->HI = ( uint )value;
+ else
+ _cpuCtx->Registers[ ordinal ] = ( uint )value;
break;
case RegisterSet::Fpu:
Debug::Assert( T::typeid == float::typeid );

Modified: trunk/Noxa.Emulation.Psp.Player/Debugger/Tools/RegistersControl.cs
==============================================================================
--- trunk/Noxa.Emulation.Psp.Player/Debugger/Tools/RegistersControl.cs (original)
+++ trunk/Noxa.Emulation.Psp.Player/Debugger/Tools/RegistersControl.cs
Sat Mar 29 19:09:53 2008
@@ -9,10 +9,13 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Globalization;
+using System.Media;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using Noxa.Emulation.Psp.Debugging.DebugModel;
+using Noxa.Emulation.Psp.Debugging.Hooks;
using Noxa.Emulation.Psp.Player.Debugger.Model;

namespace Noxa.Emulation.Psp.Player.Debugger.Tools
@@ -32,6 +35,7 @@
this.SetStyle( ControlStyles.OptimizedDoubleBuffer, true );

this.SetupGraphics();
+ this.SetupEditing();
}

public void Setup( InprocDebugger debugger )
@@ -39,6 +43,184 @@
_debugger = debugger;
}

+ enum RegisterType
+ {
+ General,
+ Fpu,
+ Vfpu,
+ }
+
+ #region Editing
+
+ private TextBox _editBox;
+ private bool _isEditing;
+ private RegisterType _editType;
+ private int _editOrdinal;
+
+ private void SetupEditing()
+ {
+ _editBox = new TextBox();
+ _editBox.Font = _font;
+ _editBox.Height = _lineHeight + 2;
+ _editBox.Visible = false;
+ _editBox.KeyDown += new KeyEventHandler( _editBox_KeyDown );
+ _editBox.LostFocus += new EventHandler( _editBox_LostFocus );
+ this.Controls.Add( _editBox );
+ }
+
+ protected override void OnMouseUp( MouseEventArgs e )
+ {
+ base.OnMouseUp( e );
+
+ if( e.X < 2 + _labelWidth )
+ return;
+
+ // Determine line and such
+ RegisterType type = RegisterType.General;
+ int line = ( e.Y - 2 ) / _lineHeight;
+
+ // Ignore PC
+ if( line == 0 )
+ return;
+
+ this.EditRegister( type, line );
+ }
+
+ private void EditRegister( RegisterType type, int ordinal )
+ {
+ if( _isEditing == true )
+ this.SaveEdit();
+ _isEditing = true;
+ _editType = type;
+ _editOrdinal = ordinal;
+
+ // Determine top
+ int line = 1; // PC
+ switch( type )
+ {
+ case RegisterType.General:
+ line += ordinal - 1; // no $0
+ break;
+ case RegisterType.Fpu:
+ line += 2 + ordinal;
+ break;
+ case RegisterType.Vfpu:
+ line += ordinal; // TODO
+ break;
+ }
+
+ _editBox.Left = 2 + _labelWidth - 3;
+ _editBox.Top = _lineHeight * line - 1;
+ _editBox.Width = this.ClientRectangle.Width - _editBox.Left;
+ _editBox.Text = this.GetRegisterValue( type, ordinal );
+ _editBox.Visible = true;
+ _editBox.Focus();
+ _editBox.SelectAll();
+ }
+
+ private void SaveEdit()
+ {
+ if( _isEditing == false )
+ return;
+ string value = _editBox.Text;
+ bool result = this.SetRegisterValue( _editType, _editOrdinal, value );
+ if( result == false )
+ {
+ SystemSounds.Exclamation.Play();
+ }
+ _isEditing = false;
+ _editBox.Visible = false;
+ this.Invalidate();
+ }
+
+ private void CancelEdit()
+ {
+ _isEditing = false;
+ _editBox.Visible = false;
+ this.Invalidate();
+ }
+
+ private void _editBox_KeyDown( object sender, KeyEventArgs e )
+ {
+ switch( e.KeyCode )
+ {
+ case Keys.Escape:
+ e.Handled = true;
+ this.CancelEdit();
+ break;
+ case Keys.Enter:
+ e.Handled = true;
+ this.SaveEdit();
+ break;
+ }
+ }
+
+ private void _editBox_LostFocus( object sender, EventArgs e )
+ {
+ this.SaveEdit();
+ }
+
+ private string GetRegisterValue( RegisterType type, int ordinal )
+ {
+ switch( type )
+ {
+ default:
+ case RegisterType.General:
+ return _debugger.DebugHost.CpuHook.GetRegister<uint>(
RegisterSet.Gpr, ordinal ).ToString( "X8" );
+ case RegisterType.Fpu:
+ return _debugger.DebugHost.CpuHook.GetRegister<float>(
RegisterSet.Fpu, ordinal ).ToString();
+ case RegisterType.Vfpu:
+ return _debugger.DebugHost.CpuHook.GetRegister<float>(
RegisterSet.Vfpu, ordinal ).ToString();
+ }
+ }
+
+ private bool SetRegisterValue( RegisterType type, int ordinal,
string value )
+ {
+ switch( type )
+ {
+ default:
+ case RegisterType.General:
+ {
+ uint uintValue;
+ if( value.EndsWith( ".d" ) == true )
+ {
+ if( value.Length == 2 )
+ return false;
+ value = value.Substring( 0, value.Length - 2 );
+ int intValue;
+ if( int.TryParse( value, out intValue ) == false )
+ return false;
+ uintValue = ( uint )intValue;
+ }
+ else
+ {
+ if( uint.TryParse( value, NumberStyles.HexNumber,
CultureInfo.InvariantCulture, out uintValue ) == false )
+ return false;
+ }
+ _debugger.DebugHost.CpuHook.SetRegister<uint>( RegisterSet.Gpr,
ordinal, uintValue );
+ return true;
+ }
+ case RegisterType.Fpu:
+ {
+ float floatValue;
+ if( float.TryParse( value, out floatValue ) == false )
+ return false;
+ _debugger.DebugHost.CpuHook.SetRegister<float>( RegisterSet.Fpu,
ordinal, floatValue );
+ return true;
+ }
+ case RegisterType.Vfpu:
+ {
+ float floatValue;
+ if( float.TryParse( value, out floatValue ) == false )
+ return false;
+ _debugger.DebugHost.CpuHook.SetRegister<float>(
RegisterSet.Vfpu, ordinal, floatValue );
+ return true;
+ }
+ }
+ }
+
+ #endregion
+
#region Painting

internal Font _font = new Font( "Courier New", 8.0f,
FontStyle.Regular );
@@ -144,10 +326,10 @@
e.Graphics.DrawString( state.ProgramCounter.ToString( "X8" ),
_font, valueBrush, x + _labelWidth + 3, y, _stringFormat );
y += _lineHeight;

- DrawMode mode = DrawMode.General;
+ RegisterType mode = RegisterType.General;
switch( mode )
{
- case DrawMode.General:
+ case RegisterType.General:
{
RegisterBank bank = RegisterBanks.General;
for( int n = 1; n < 32; n++ )
@@ -175,7 +357,7 @@
y += _lineHeight;
}
break;
- case DrawMode.Fpu:
+ case RegisterType.Fpu:
{
// Control register
e.Graphics.DrawString( "fcr", _font, labelBrush, x, y,
_stringFormat );
@@ -204,16 +386,9 @@
}
}
break;
- case DrawMode.Vfpu:
+ case RegisterType.Vfpu:
break;
}
- }
-
- enum DrawMode
- {
- General,
- Fpu,
- Vfpu,
}

#endregion

Reply all
Reply to author
Forward
0 new messages