支持Windows,Mac,Linux NES模拟器内核源码来自 https://github.com/colinvella/EmuNes 他这边的源码功能很完善了的,支持视频录制,手柄,金手指等等。现在移植到cpf来实现跨平台测试,不过这边的移植测试里并没有把所有功能移植完整。
移植这个,主要就是图形绘制和音频播放适配。
需要开启代码优化才能有足够的帧数,否则会很卡。
绘制和控制的代码主要在 NesVideoPanel 类里
将游戏画面绘制出来
protected override void OnRender(DrawingContext dc) { base.OnRender(dc); if (bitmapBuffer != null) { dc.DrawImage(bitmapBuffer.Bitmap, new Rect(new Point(), ActualSize), new Rect(0, 0, bitmapBuffer.Bitmap.Width, bitmapBuffer.Bitmap.Height)); if (gameState == GameState.Paused) { var size = ActualSize; dc.DrawImage(FilterPause, new Rect(new Point(), ActualSize), new Rect(0, 0, FilterPause.Width, FilterPause.Height)); var textSize = dc.DrawingFactory.MeasureString("暂停", new Font(FontFamily, 36, FontStyles.Italic)); var outlineThickness = size.Height / 120; textSize.Width += outlineThickness; textSize.Height += outlineThickness; float textX = (size.Width - textSize.Width) / 2; float textY = (size.Height - textSize.Height) / 2; using (PathGeometry graphicsPath = new PathGeometry(new Font(this.FontFamily, 36, FontStyles.Italic), "暂停")) using (SolidColorBrush outlinePen = new SolidColorBrush(Color.Black)) using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(new GradientStop[] { new GradientStop(Color.White, 0), new GradientStop(Color.LightSkyBlue, 1) }, new Point(), new Point(0, textSize.Height), Matrix.Identity)) { var m = Matrix.Identity; m.Translate(textX, textY); graphicsPath.Transform(m); dc.DrawPath(outlinePen, new Stroke(outlineThickness) { LineJoin = LineJoins.Round }, graphicsPath); dc.FillPath(linearGradientBrush, graphicsPath); } } } }
键盘操作
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (e.Key == Keys.Tab) { e.Handled = true; } keyboardState[e.Key] = true; } protected override void OnKeyUp(KeyEventArgs e) { base.OnKeyUp(e); keyboardState[e.Key] = false; }
声音播放采用SDL2,支持跨平台播放声音,在 ApuAudioProvider 类里实现
源码里带sdl2的64位dll,如果发布到其他平台需要对应平台安装SDL2才行。
默认支持直接打开zip文件读取nes,不过Net4版的不能读取zip
感兴趣的可以下载研究,需要VS2019。需要cpf设计器的话,请看 CPF入门教程
签名:<-CPF C# 跨平台桌面UI框架,支持Windows,Mac,Linux,包括XP,国产麒麟Linux等等->
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构