Creating A C# Nes Emulator...in Windows forms?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Creating A C# Nes Emulator...in Windows forms?
by on (#57304)
It's been a while since I've posted, as I've sidetracked into other interests, but that being sidetracking itself, I am here to ask about my question.

I want to make clear that this is NO request for anyone to make anything, but rather, a question for help, as to how in the world can I create a C# NES emulator in Windows Forms. The problem lies in the fact that I am not sure how I am supposed to draw the games screen onto the form. I assume with the PictureBox control. Sounds good, until i try to draw an image using Image.FromStream. It does not work for me AT ALL (I'm testing it with random data), and I'm thinking it's because that it only accepts data fed to it in bitmap format. Well, I'm talking about the NES, and that it not bitmap format!

So yes, I am feeling stuck. It's like I'm checking for all my ingredients before I cook, and it turns out that there is no dough for the pizza. I have tried using XNA, and I can't figure out how to keep the screen refreshed, so I am forgetting that, and since I am fluent with no other language or environment other than Visual Studio. I am asking for whatever help I can get for figuring how I can render the game onto the screen...using Windows Forms, provided it's possible.

Woo, sorry for the lengthy post. But anyways, please give some input for solutions!

Thanks!

by on (#57305)
Read about LockBits.

Then sit back and wonder why C# is so slow.

by on (#57309)
If you have something that outputs pixels in real time, you're supposed to be writing it in pixel shader language.

Things like this and the lack of a counterpart to Allegro's AUDIOSTREAM in XNA make me think Microsoft doesn't intend C# for emulators. There is even a thread on the XNA board that speculates that Microsoft did this on purpose so that people don't end up making emulators for Xbox 360 XNA that run infringing copies of copyrighted games designed for discontinued video game consoles.

by on (#57313)
Indeed...this is starting to make me think I'm going to have to break down and look for a different implementation, unfortunately. I did a little test with GetPixel, and I realized that it is not very friendly at all. I think I understand why there is a lack of C# emulators...lol.

by on (#57316)
there was a person who wrote this C# NES emulator utilizing shaders, it's pretty wicked you can check it out.
http://code.google.com/p/fishbulbnes/

by on (#57333)
That one appears to require Windows Vista or 7 to run.

by on (#57382)
Check out My Nes

http://sourceforge.net/projects/mynes/

by on (#57388)
Hey thanks. I happened to see that link to My Nes on sourceforge yesterday. It is an awesome resource for my needs. Now, the thing isn't perfect, so what I did was copy "most" of it's code, as I rewrote a few things here and there, and I am going to try and do improvements on it, like see where it has innacurracies and maybe base it on a new C# emulator I can make with it, which I will probably reuse it's video renderer since it is very hard to render anything effeciently in C#. I may do a tell all in the future with any developments I make with editing the emulator.

Appropriate credits shall be made, of course, provided I make changes to it.

by on (#64352)
Sorry to dig up an old thread, but I wanted to mention that you can embed a directx window into your windows form. Then you can just draw directly to a Texture2D. That is what I'm doing with my emulator. And though some examples mention it, it is not necessary to use multiple threads to accomplish this.

Here is just one example: http://gosub.com/OpenSource/DirectXCont ... ontrol.htm

You can find a few others if you google a bit for them.

I hope this information might be somewhat helpful if anyone is doing a search later on.