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

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
NesHackR
Posts: 18
Joined: Tue Jan 05, 2010 4:24 pm

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

Post by NesHackR » Sat Feb 27, 2010 4:14 pm

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!

User avatar
Dwedit
Posts: 4435
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit » Sat Feb 27, 2010 4:15 pm

Read about LockBits.

Then sit back and wonder why C# is so slow.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

tepples
Posts: 22361
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sat Feb 27, 2010 5:13 pm

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.

NesHackR
Posts: 18
Joined: Tue Jan 05, 2010 4:24 pm

Post by NesHackR » Sat Feb 27, 2010 6:01 pm

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.

qeed
Posts: 61
Joined: Tue Jun 17, 2008 11:51 am

Post by qeed » Sat Feb 27, 2010 6:25 pm

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/

User avatar
Dwedit
Posts: 4435
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit » Sun Feb 28, 2010 3:50 am

That one appears to require Windows Vista or 7 to run.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
James
Posts: 429
Joined: Sat Jan 22, 2005 8:51 am
Location: Chicago, IL
Contact:

Post by James » Mon Mar 01, 2010 12:34 pm


NesHackR
Posts: 18
Joined: Tue Jan 05, 2010 4:24 pm

Post by NesHackR » Mon Mar 01, 2010 3:44 pm

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.

User avatar
tineras
Posts: 53
Joined: Mon Jul 05, 2010 7:59 am

Post by tineras » Fri Jul 16, 2010 2:33 pm

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.

Post Reply