MahNES Library Released - Emulator using SDL_Audio now

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

HLorenzi
Posts: 23
Joined: Thu Jun 28, 2012 9:10 pm
Location: São Paulo, Brazil

MahNES Library Released - Emulator using SDL_Audio now

Post by HLorenzi »

> MahNES Library

The library and source code for my emulation engine! Instructions on readme file, and example given. C interface!

https://dl.dropbox.com/u/22954866/MahNESLib.zip

> MahNES Emulator

This is my second attempt at making a NES emulator. I wrote one before, but the code was too much of a mess. Now I'm porting it to organized code using OpenGL and SDL Audio, so I think it's portable across many platforms, but currently it's only on Windows. It can emulate several games at once, and I thought it would be nice to have a little gallery of recent played games on startup, all showing running screens (I'm thinking of showing the user's savestates and old plays through the games, so it's more interesting). Maybe someone did that before?

Basic four-channel APU emulation now, using blargg's blif_buf! Save states (F1, F2, F3 or F4 keys, plus Shift to save). Fast forward (V key).

Currently only supports mappers 0, 1, 2, 4, 7, 9 and 10.

https://dl.dropbox.com/u/22954866/MahNESv03.zip
Last edited by HLorenzi on Sun Jan 13, 2013 6:57 pm, edited 14 times in total.
User avatar
MottZilla
Posts: 2837
Joined: Wed Dec 06, 2006 8:18 pm

Re: MahNES v0.1 - Multiple Simultaneous Emulation

Post by MottZilla »

I think only a couple others did multiple instances of emulation, one like a bunch of TV screens together, another some 3D game room render where you could have multiple games on multiple systems.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: MahNES v0.1 - Multiple Simultaneous Emulation

Post by tepples »

Nemulator's game grid reminded me of the Wii Menu.
zzo38
Posts: 1096
Joined: Mon Feb 07, 2011 12:46 pm

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by zzo38 »

If it is open-source and compatible with C programs and cross-platform, then I might be interested in such thing.
(Free Hero Mesh - FOSS puzzle game engine)
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by Dwedit »

What a misleading filename, OpenAL32.dll is an X64 file. I can't run this on my 32-bit operating system.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
HLorenzi
Posts: 23
Joined: Thu Jun 28, 2012 9:10 pm
Location: São Paulo, Brazil

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by HLorenzi »

zzo38 wrote:If it is open-source and compatible with C programs and cross-platform, then I might be interested in such thing.
Well, C++ programs can work with a C interface, right? Or maybe you need it entirely in C (which is also possible to do)? It is cross-platform because it only uses the C standard library. I'm just wrapping up some things before releasing it.

Open-source is my goal - I mean, it can't harm, can it? I'm not making profit with this anyway. I just don't really know what the guidelines for releasing open-source software are... What license should I choose, how can I still take credit, and all that.
Dwedit wrote:What a misleading filename, OpenAL32.dll is an X64 file. I can't run this on my 32-bit operating system.
OpenAL sucks, I think. It's really unstable (at least with me!), and I can't even tweak some settings without the audio getting all chopped and distorted. I don't know well any other audio playing libraries...
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by tepples »

HLorenzi wrote:It can emulate several games at once, and I thought it would be nice to have a little gallery of recent played games on startup, all showing running screens (I'm thinking of showing the user's savestates and old plays through the games, so it's more interesting). Maybe someone did that before?
Nemulator emulates a couple dozen games simultaneously in a Wii Menu-inspired game chooser, which ended up being Metro even before Microsoft made Metro.

If you want to distribute a library as free software, the choice of license depends on how widely you want the library to be used by non-free software.
  • A strong copyleft means the library can be used only in other free software projects. Use GNU General Public License, version 3 or later, or Sleepycat License.
  • A weak copyleft means the library can be used in proprietary projects, but improvements to the library itself must be made available to the public. Use Mozilla Public License/GNU Lesser General Public License dual-license, as Firefox does.
  • A permissive license means the library can be used in completely proprietary projects. Use Apache License 2, Zlib license, X11 license, FreeBSD license, or GNU Permissive License.
User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by cpow »

HLorenzi wrote:Is there something like that already?
https://gitorious.org/nesicide/nesicide ... r/libs/nes
HLorenzi
Posts: 23
Joined: Thu Jun 28, 2012 9:10 pm
Location: São Paulo, Brazil

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by HLorenzi »

cpow wrote:
HLorenzi wrote:Is there something like that already?
https://gitorious.org/nesicide/nesicide ... r/libs/nes
Well, I'm late to this NES thing, anyway. The project started as a way for me to learn more. I wasn't hoping of being innovative. :P

Maybe I should port my code to pure C? Don't know if that would help its usefulness and "uniqueness"...
User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by cpow »

HLorenzi wrote:
cpow wrote:
HLorenzi wrote:Is there something like that already?
https://gitorious.org/nesicide/nesicide ... r/libs/nes
Well, I'm late to this NES thing, anyway. The project started as a way for me to learn more. I wasn't hoping of being innovative. :P

Maybe I should port my code to pure C? Don't know if that would help its usefulness and "uniqueness"...
Sorry, I wasn't trying to snuff your effort. I was only pointing to the emulator library that I created with similar goals. At present it's only used in two applications--that I know of. Both mine. I didn't use blargg's blip_buffer library...I probably should. But the library interface seems very similar to what you posted.

I probably will catch a lot of noise for this but I don't believe there's any difference whether you choose C or C++. Completely crappy code can be written in either, as can completely concise and correct code.
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by 3gengames »

SDL does sound. I don't know how well, though. Plus it's multi-plat. I tinker with it, it seems okay.

ETA: I would stick with C. I don't want to learn C++ for what reason Linus of Linux has stated, plus it seems like nothing but bloat. Making it objectified might help you, but not others looking at the source.
Last edited by 3gengames on Fri Jan 11, 2013 10:14 pm, edited 1 time in total.
User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by blargg »

I think that a NES emulator library that's portable and has a clean interface is an asset. It's worth the experience making something really clean and easy to use, as that's often lacking. I aimed for too much performance and made the implementation more complex than was maintainable, and it suffered.
HLorenzi wrote:Is there something like that already?
kode54 released the source to nes_emu (which QuickNES is based on). It's also mostly portable (I believe it might do some unaligned 32-bit integer accesses, making it fail on some ARM processors). It makes no OS calls, just standard C library stuff. I can't remember whether it has a C wrapper like my other libraries. I haven't worked on it in years, which is why kode54 has been maintaining it.
Maybe I should port my code to pure C? Don't know if that would help its usefulness and "uniqueness"...
I tried to port something to C and it was so tedious. Until C and C++ compilers aren't bundled, using "light" C++ is so much more maintainable, and you can easily make a C interface wrapper, which is nice for even C++ clients since it insulates them from changes to your classes etc. and makes the shared library interface more stable across versions.
User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by cpow »

blargg wrote:I think that a NES emulator library that's portable and has a clean interface is an asset. It's worth the experience making something really clean and easy to use, as that's often lacking. I aimed for too much performance and made the implementation more complex than was maintainable, and it suffered.
I'm not saying it's perfect...but...
The library I linked has no reliance on any sound or video production libraries. It provides bitmasks for reference so you can pass the controller bits in the right order--but otherwise makes no reference to keyboard, joystick, mouse, or other input technologies. nesSetControllerScreenPosition, for example, could be set from a mouse's position or some other position-aware input device. I admit that the nes_emulator_core.h file could use a lot of clean up...lots of stuff in there that should be elsewhere, but the main gist of the library (with some corrections...some comments were slightly wrong) is:

Code: Select all

// Exported interfaces.
// The following interfaces are to be used by a UI to interact with the emulation
// core and perform the necessary steps to emulate a NES game.  Those steps are:
// 1. Set the NES system mode to MODE_NTSC, MODE_DENDY or MODE_PAL using nesSetSystemMode().
// 2. Provide a 256x256x4-byte chunk of memory to the emulator core for it to
//    render the NES TV surface onto, using nesSetTVOut().
// 3. Clear any emulation state by using nesUnloadROM().
// 4. Pass 16KB PRG-ROM banks in order and 8KB CHR-ROM banks in order to the emulation
//    core by using nesLoadPRGROMBank() and nesLoadCHRROMBank() respectively.  If no
//    CHR-ROM banks are present, do not call nesLoadCHRROMBank().
// 5. If the game has fixed mirroring, tell the emulator core which one it is by
//    using nesSetHorizontalMirroring() or nesSetVerticalMirroring().
// 6. Tell the emulator core you're done passing it ROM data by using
//    nesLoadROM().
// 7. Cause the loaded ROM to be recognized by the emulator core by issuing a
//    reset.  Use the nesResetInitial(mapper) variant to set up the emulator core with the
//    appropriate mapper for the loaded ROM.  Subsequent resets can use the nesReset()
//    variant.
// 8. Run a PPU (video) frame's worth of NES emulation, which generates a full
//    rendered video frame and an appropriate amount of audio data, by using
//    nesRun().  Pass in collected joypad input data.
// 9. If the emulator supports sound output, the number of audio samples available
//    can be retrieved by using nesGetAudioSamplesAvailable().  A pointer to the
//    next buffer of audio samples to play can be retrieved using nesGetAudioSamples().
//    Once retrieved, the number of available audio samples should be reset using
//    nesClearAudioSamplesAvailable.

// Emulation interfaces.
void nesSetSystemMode ( uint32_t mode );
uint32_t nesGetSystemMode ( void );
void nesSetTVOut ( int8_t* tv );
void nesUnloadROM ( void );
void nesLoadPRGROMBank ( uint32_t bank, uint8_t* bankData );
void nesLoadCHRROMBank ( uint32_t bank, uint8_t* bankData );
void nesSetHorizontalMirroring ( void );
void nesSetVerticalMirroring ( void );
void nesSetFourScreen ( void );
void nesLoadROM ( void );
void nesResetInitial ( uint32_t mapper );
void nesReset ( bool soft );
void nesRun ( uint32_t* joypads );
int32_t nesGetAudioSamplesAvailable ( void );
void nesClearAudioSamplesAvailable ( void );
uint8_t* nesGetAudioSamples ( uint16_t samples );
void nesSetControllerType ( int32_t port, int32_t type );
void nesSetControllerScreenPosition ( int32_t port, int32_t px, int32_t py, int32_t wx1, int32_t wy1, int32_t wx2, int32_t wy2 );
void nesSetControllerSpecial ( int32_t port, int32_t special );
bool nesROMIsLoaded ( void );
HLorenzi
Posts: 23
Joined: Thu Jun 28, 2012 9:10 pm
Location: São Paulo, Brazil

Re: MahNES v0.3.6 - Possible Full Portable NES Emulation Lib

Post by HLorenzi »

tepples wrote:If you want to distribute a library as free software, the choice of license depends on how widely you want the library to be used by non-free software.
  • A strong copyleft means the library can be used only in other free software projects. Use GNU General Public License, version 3 or later, or Sleepycat License.
  • A weak copyleft means the library can be used in proprietary projects, but improvements to the library itself must be made available to the public. Use Mozilla Public License/GNU Lesser General Public License dual-license, as Firefox does.
  • A permissive license means the library can be used in completely proprietary projects. Use Apache License 2, Zlib license, X11 license, FreeBSD license, or GNU Permissive License.
Thank you, that was most useful!
User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Re: MahNES Library Released

Post by blargg »

A permissive license encourages voluntary collaboration among developers who use it. The others rely on forced collaboration and have involved terms which must be followed, which turns away some developers who prefer voluntary collaboration and simplicity. Neither will cause collaboration where there's lack of interest or potential; the best way to get people helping is to form a group of people who want to work on the software. The idea is to focus on making the software valuable, rather than on worrying about how others put it to use.
Post Reply