diff --git a/Chip8.Sharp/Chip8.Sharp.sln b/Chip8.Sharp/Chip8.Sharp.sln index 307c1bd..5628834 100644 --- a/Chip8.Sharp/Chip8.Sharp.sln +++ b/Chip8.Sharp/Chip8.Sharp.sln @@ -6,15 +6,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chip8.Core", "Chip8.Core\Ch EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{05D2CF24-E03F-4D32-906B-641573A16429}" ProjectSection(SolutionItems) = preProject - CHIP-8 Keyboard Mapping.md = CHIP-8 Keyboard Mapping.md - CHIP-8 OpCodes.md = CHIP-8 OpCodes.md - CHIP-8 Specs.md = CHIP-8 Specs.md - run-tests = run-tests ..\nunit3-xslt\html-report.xslt = ..\nunit3-xslt\html-report.xslt ..\nunit3-xslt\html-summary.xslt = ..\nunit3-xslt\html-summary.xslt + ..\nunit3-xslt\README.md = ..\nunit3-xslt\README.md + run-tests = run-tests + ..\nunit3-xslt\text-profile.xslt = ..\nunit3-xslt\text-profile.xslt ..\nunit3-xslt\text-report.xslt = ..\nunit3-xslt\text-report.xslt ..\nunit3-xslt\text-summary.xslt = ..\nunit3-xslt\text-summary.xslt - ..\nunit3-xslt\text-profile.xslt = ..\nunit3-xslt\text-profile.xslt EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chip8.Tests", "Chip8.Tests\Chip8.Tests.csproj", "{ACF18D83-5BD5-4AA9-B794-711E069719B5}" @@ -25,7 +23,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chip8.WindowsForms", "Chip8 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chip8.WPF", "Chip8.WPF\Chip8.WPF.csproj", "{415A9C97-30EA-49D5-AA8E-B50D472D18CD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chip8.SDL", "Chip8.SDL\Chip8.SDL.csproj", "{A4862065-B576-49B3-89DC-A501AA17B905}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chip8.SDL", "Chip8.SDL\Chip8.SDL.csproj", "{A4862065-B576-49B3-89DC-A501AA17B905}" EndProject Global GlobalSection(Performance) = preSolution @@ -65,6 +63,7 @@ Global {ACF18D83-5BD5-4AA9-B794-711E069719B5}.Release|x86.ActiveCfg = Debug|Any CPU {ACF18D83-5BD5-4AA9-B794-711E069719B5}.Release|x86.Build.0 = Debug|Any CPU {CB188B88-CBFF-4D27-B5B2-335D7029C322}.Debug|Any CPU.ActiveCfg = Debug|x86 + {CB188B88-CBFF-4D27-B5B2-335D7029C322}.Debug|Any CPU.Build.0 = Debug|x86 {CB188B88-CBFF-4D27-B5B2-335D7029C322}.Debug|x64.ActiveCfg = Debug|x64 {CB188B88-CBFF-4D27-B5B2-335D7029C322}.Debug|x64.Build.0 = Debug|x64 {CB188B88-CBFF-4D27-B5B2-335D7029C322}.Debug|x86.ActiveCfg = Debug|x86 @@ -73,7 +72,6 @@ Global {CB188B88-CBFF-4D27-B5B2-335D7029C322}.Release|x64.ActiveCfg = Debug|x64 {CB188B88-CBFF-4D27-B5B2-335D7029C322}.Release|x64.Build.0 = Debug|x64 {CB188B88-CBFF-4D27-B5B2-335D7029C322}.Release|x86.ActiveCfg = Debug|x64 - {CB188B88-CBFF-4D27-B5B2-335D7029C322}.Debug|Any CPU.Build.0 = Debug|x86 {AB9198E1-E2E9-4B1F-9FC3-8B7F32C986F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AB9198E1-E2E9-4B1F-9FC3-8B7F32C986F6}.Debug|Any CPU.Build.0 = Debug|Any CPU {AB9198E1-E2E9-4B1F-9FC3-8B7F32C986F6}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -117,4 +115,7 @@ Global GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {85F0FA54-6A6D-4D08-86A4-5BC480BF3DED} EndGlobalSection + GlobalSection(Performance) = preSolution + HasPerformanceSessions = true + EndGlobalSection EndGlobal diff --git a/Chip8.Sharp/Chip8.WPF/MainWindow.xaml b/Chip8.Sharp/Chip8.WPF/MainWindow.xaml index 85c17de..2a72bf9 100644 --- a/Chip8.Sharp/Chip8.WPF/MainWindow.xaml +++ b/Chip8.Sharp/Chip8.WPF/MainWindow.xaml @@ -9,5 +9,6 @@ + diff --git a/Chip8.Sharp/Chip8.WPF/MainWindow.xaml.cs b/Chip8.Sharp/Chip8.WPF/MainWindow.xaml.cs index b275265..eb590ee 100644 --- a/Chip8.Sharp/Chip8.WPF/MainWindow.xaml.cs +++ b/Chip8.Sharp/Chip8.WPF/MainWindow.xaml.cs @@ -34,6 +34,10 @@ public partial class MainWindow : Window readonly TimeSpan targetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 1000); TimeSpan lastTime; + // frame rate handling + private DateTime frameDateTime; + private double averageDeltaTime; + private static readonly Color ambar = Color.FromArgb(0xFF, 0xFF, 0xB0, 0x00); private static readonly Color lightAmbar = Color.FromArgb(0xFF, 0xFF, 0xCC, 0x00); private static readonly Color green1 = Color.FromArgb(0xFF, 0x33, 0xFF, 0x00); @@ -392,6 +396,14 @@ void OnDraw(byte[] graphics) { Draw(graphics); imgScreen.InvalidateVisual(); + + // frame rate + DateTime currentDateTime = DateTime.Now; + double currentDeltaTime = (currentDateTime - frameDateTime).TotalSeconds; + frameDateTime = currentDateTime; + averageDeltaTime = averageDeltaTime * 0.9 + currentDeltaTime * 0.1; + int frameRate = (int)(1.0 / averageDeltaTime); + frameRateStatusLabel.Content = frameRate + " FPS"; }); } diff --git a/Chip8.Sharp/Chip8.WindowsForms/MainForm.Designer.cs b/Chip8.Sharp/Chip8.WindowsForms/MainForm.Designer.cs index 20b9275..5beafa3 100644 --- a/Chip8.Sharp/Chip8.WindowsForms/MainForm.Designer.cs +++ b/Chip8.Sharp/Chip8.WindowsForms/MainForm.Designer.cs @@ -30,6 +30,7 @@ private void InitializeComponent() { this.cbPrograms = new System.Windows.Forms.ComboBox(); this.pbScreen = new Chip8.WindowsForms.PictureBoxWithInterpolationMode(); + this.frameRateStatusLabel = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.pbScreen)).BeginInit(); this.SuspendLayout(); // @@ -39,8 +40,9 @@ private void InitializeComponent() this.cbPrograms.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbPrograms.FormattingEnabled = true; this.cbPrograms.Location = new System.Drawing.Point(0, 0); + this.cbPrograms.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.cbPrograms.Name = "cbPrograms"; - this.cbPrograms.Size = new System.Drawing.Size(640, 21); + this.cbPrograms.Size = new System.Drawing.Size(1280, 33); this.cbPrograms.TabIndex = 1; this.cbPrograms.TabStop = false; this.cbPrograms.SelectedIndexChanged += new System.EventHandler(this.cbPrograms_SelectedIndexChanged); @@ -51,21 +53,34 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.pbScreen.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; - this.pbScreen.Location = new System.Drawing.Point(0, 27); + this.pbScreen.Location = new System.Drawing.Point(0, 52); + this.pbScreen.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.pbScreen.Name = "pbScreen"; - this.pbScreen.Size = new System.Drawing.Size(640, 480); + this.pbScreen.Size = new System.Drawing.Size(1280, 923); this.pbScreen.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pbScreen.TabIndex = 0; this.pbScreen.TabStop = false; // + // frameRateStatusLabel + // + this.frameRateStatusLabel.AutoSize = true; + this.frameRateStatusLabel.ForeColor = System.Drawing.Color.Red; + this.frameRateStatusLabel.Location = new System.Drawing.Point(12, 63); + this.frameRateStatusLabel.Name = "frameRateStatusLabel"; + this.frameRateStatusLabel.Size = new System.Drawing.Size(71, 25); + this.frameRateStatusLabel.TabIndex = 2; + this.frameRateStatusLabel.Text = "0 FPS"; + // // MainForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(640, 508); + this.ClientSize = new System.Drawing.Size(1280, 977); + this.Controls.Add(this.frameRateStatusLabel); this.Controls.Add(this.cbPrograms); this.Controls.Add(this.pbScreen); this.KeyPreview = true; + this.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "MainForm"; @@ -75,6 +90,7 @@ private void InitializeComponent() this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pbScreen)).EndInit(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -82,6 +98,7 @@ private void InitializeComponent() private PictureBoxWithInterpolationMode pbScreen; private System.Windows.Forms.ComboBox cbPrograms; + private System.Windows.Forms.Label frameRateStatusLabel; } } diff --git a/Chip8.Sharp/Chip8.WindowsForms/MainForm.cs b/Chip8.Sharp/Chip8.WindowsForms/MainForm.cs index c98d63f..8ca3813 100644 --- a/Chip8.Sharp/Chip8.WindowsForms/MainForm.cs +++ b/Chip8.Sharp/Chip8.WindowsForms/MainForm.cs @@ -31,6 +31,10 @@ public partial class MainForm : Form readonly TimeSpan targetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 1000); TimeSpan lastTime; + // frame rate + private DateTime frameDateTime; + private double averageDeltaTime; + private static readonly Color ambar = Color.FromArgb(0xFF, 0xFF, 0xB0, 0x00); private static readonly Color lightAmbar = Color.FromArgb(0xFF, 0xFF, 0xCC, 0x00); private static readonly Color green1 = Color.FromArgb(0xFF, 0x33, 0xFF, 0x00); @@ -387,12 +391,28 @@ void OnDraw(byte[] graphics) { Draw(graphics); pbScreen.Refresh(); + + // frame rate + DateTime currentDateTime = DateTime.Now; + double currentDeltaTime = (currentDateTime - frameDateTime).TotalSeconds; + frameDateTime = currentDateTime; + averageDeltaTime = averageDeltaTime * 0.9 + currentDeltaTime * 0.1; + int frameRate = (int)(1.0 / averageDeltaTime); + frameRateStatusLabel.Text = frameRate + " FPS"; })); } else { Draw(graphics); pbScreen.Refresh(); + + // frame rate + DateTime currentDateTime = DateTime.Now; + double currentDeltaTime = (currentDateTime - frameDateTime).TotalSeconds; + frameDateTime = currentDateTime; + averageDeltaTime = averageDeltaTime * 0.9 + currentDeltaTime * 0.1; + int frameRate = (int)(1.0 / averageDeltaTime); + frameRateStatusLabel.Text = frameRate + " FPS"; } } @@ -403,18 +423,15 @@ void Draw(byte[] graphics) unsafe { - byte* pointer = (byte*)bits.Scan0; + int* pointer = (int*)bits.Scan0; - foreach (byte pixel in graphics) + for (int i = 0; i < graphics.Length; i++) { + byte pixel = graphics[i]; var color = (pixel > 0) ? appleIIcGreen : Color.Black; - pointer[0] = color.B; - pointer[1] = color.G; - pointer[2] = color.R; - pointer[3] = 255; // Alpha - - pointer += 4; // 4 bytes per pixel + *pointer = color.ToArgb(); + pointer++; // 4 bytes (1 int) per pixel } } diff --git a/SDL2-CS b/SDL2-CS index 110bf1c..ac10a99 160000 --- a/SDL2-CS +++ b/SDL2-CS @@ -1 +1 @@ -Subproject commit 110bf1c50b19b4e739c7fd2afb0d306becc8fbed +Subproject commit ac10a992b365b1ecf5ea4cec52d4a9e89f5059a1