agnes - single C header NES emulation library

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
kgabis
Posts: 6
Joined: Wed Mar 20, 2019 9:55 am
Location: Warsaw, Poland

agnes - single C header NES emulation library

Post by kgabis » Thu Mar 21, 2019 12:23 pm

Hi all!

I want to present you agnes. Agnes is a NES emulation library available as a single C header. It's very easy to use and should be trivially embeddable. Also, it could be useful as a reference for other people writing NES emulators.

Current status: it supports 4 mappers (NROM, UxROM, MMC1 and MMC3), but it's possible that some games might not work correctly (as always). Also, there is no sound due to lack of APU emulation. And performance could be better (there's a lot of space for performance optimizations in PPU rendering).

You can find it here: https://github.com/kgabis/agnes

I'd like to thank all people on this forum and NesDev wiki, it would be impossible to write a NES emulator without all the knowledge found here.

User avatar
rainwarrior
Posts: 7717
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: agnes - single C header NES emulation library

Post by rainwarrior » Thu Mar 21, 2019 12:46 pm

Cool!

User avatar
slembcke
Posts: 171
Joined: Fri Nov 24, 2017 2:40 pm
Location: Minnesota

Re: agnes - single C header NES emulation library

Post by slembcke » Fri Mar 22, 2019 7:54 am

Hah! Nice. I'm tempted to incorporate this into one of my random hobby projects just... because.

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

Re: agnes - single C header NES emulation library

Post by tepples » Fri Mar 22, 2019 7:56 am

Would you prefer that I make feature requests in this topic, in GitHub Issues, or somewhere else?

User avatar
kgabis
Posts: 6
Joined: Wed Mar 20, 2019 9:55 am
Location: Warsaw, Poland

Re: agnes - single C header NES emulation library

Post by kgabis » Fri Mar 22, 2019 8:59 am

tepples wrote:Would you prefer that I make feature requests in this topic, in GitHub Issues, or somewhere else?
I think that github issues is the best place for it :)

User avatar
Kasumi
Posts: 1292
Joined: Wed Apr 02, 2008 2:09 pm

Re: agnes - single C header NES emulation library

Post by Kasumi » Fri Mar 22, 2019 4:38 pm

This is slick! I implemented it in no time and no trouble. I may include it in my NES graphics tool until such time as I get crazy enough to attempt my own emulator. :lol:

The only thing I see that's "wrong" is no output for emphasis bits, but it's not a large complaint or anything.

User avatar
kgabis
Posts: 6
Joined: Wed Mar 20, 2019 9:55 am
Location: Warsaw, Poland

Re: agnes - single C header NES emulation library

Post by kgabis » Wed Apr 03, 2019 6:29 am

Recently I've been working on exposing nametables and sprites through the API. You can see it in action here: https://twitter.com/KrzysztofGabis/stat ... 1925894146
Attachments
Zrzut ekranu 2019-04-03 o 15.28.59.png

User avatar
kgabis
Posts: 6
Joined: Wed Mar 20, 2019 9:55 am
Location: Warsaw, Poland

Re: agnes - single C header NES emulation library

Post by kgabis » Fri Apr 05, 2019 5:19 am

More work on emulator debugging:
* Showing visible area on per-scanline basis
* Displaying contents of RAM (bottom)
* Displaying contents of PPU memory (right)

I hoped that writing a "speculative" emulator that draws whole screen and then redraws portions of it when scroll/banks change would be much easier but at this point I'm leaning towards ignoring optimizations (for now) and concentrating on APU emulation. It's the last bit that's really missing from making my emulator complete (by my definition of complete ;)).

Anyway, here's a short video:
https://twitter.com/KrzysztofGabis/stat ... 9092816896
Attachments
smb.png

User avatar
Zepper
Formerly Fx3
Posts: 3192
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: agnes - single C header NES emulation library

Post by Zepper » Sat Apr 06, 2019 11:11 am

One word: awesome.

User avatar
kgabis
Posts: 6
Joined: Wed Mar 20, 2019 9:55 am
Location: Warsaw, Poland

Re: agnes - single C header NES emulation library

Post by kgabis » Sat Feb 08, 2020 3:38 pm

Not sure if anyone will find it interesting, but I haven't heard of any emulator doing this. Recently I've been playing with frame interpolation to make NES games play more smoothly on high refresh rate displays (120, 240hz). The idea is to emulate 2 frames at once and then interpolate scroll and sprite positions in between. The downside is that you need to render screen and sprites separately and it's quite hard to do in a non-glitchy way (especially with games changing bank mid-screen). So far interpolating scroll positions has been quite successful but interpolating sprite positions is quite tricky and I'm not sure it can be achieved because the same "game object" can end up being two different sprites on two consecutive frames. Anyway, I've tested it with SMB at 120hz and it plays noticeably smoother. You can see the results running at 50% speed here (interpolated frames are on the right):

https://www.youtube.com/watch?v=bH4RBxaj9QY

Not sure if I'll spend more time on this, but seeing that more and more people have high refresh rate screens I think this might be an interesting direction.

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

Re: agnes - single C header NES emulation library

Post by Dwedit » Sat Feb 08, 2020 9:17 pm

If raster effects are causing problems, you need a different way to think about whole-screen rendering.

After a frame runs, you can collect information for each scanline: (possibly sample this information at the middle of each scanline)

* X Scroll
* Y Scroll
* PPU Control
* PPU Mask
* 8 selected CHR banks

(you don't necessarily need to store every scanline separately, just indicating when it changes is enough)

From there, you can do a not-pixel-accurate, but somewhat accurate reconstruction of the whole screen. It would be good enough for most games other than Marble Madness or Punch Out.

Then divide the screen into scrolling regions. For example, detect the status bar, and the main game screen separately. Then you can have much better results for motion interpolation.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
kgabis
Posts: 6
Joined: Wed Mar 20, 2019 9:55 am
Location: Warsaw, Poland

Re: agnes - single C header NES emulation library

Post by kgabis » Sun Feb 09, 2020 1:56 am

That's what I'm doing with scroll positions right now, I'm storing them per scanline. Otherwise the status bar in SMB wouldn't work correctly.

Post Reply