百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

NET-NES

> 编程语言
开源

NET-NES 是一个 NES 模拟器,使用 C# 编写。

323 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

NET-NES 是一个 NES 模拟器,使用 C# 编写。

NET-NES

NET-NES, a NES emulator, written in C#.

NET-NES is a NES emulator, capable of running some of the best games for the NES. To start off, after making my Gameboy emulator, CODE-DMG, I wanted to create the next step up. As I thought to myself, "It only made sense to create a NES emulator!" It felt such a natural pairing making a Gameboy emulator, and now NET-NES, a NES emulator. The NES to me is a very fascinating console. The NES not only made a impact in gaming history, but also in electronics, which captivated me. Not to mention how the NES is home to some of the best and well known games! So why not take on the challenge and emulate it, it would be perfect! Now, some quick history and background information. The NES, (Nintendo Entertainment System), launched first in Japan as the FamiCom (Family Computer) in 1983, later coming into North America in 1985. At this point in North America, the Video Game Crash of 1983 was hitting North America hard, with home console gaming market being in shambles. However, Nintendo in 1985 decided to launch their console in North America, change the name to NES, advertise it as a "toy", and boom! That was able to bring life back into the gaming industry in North America! Pretty cool history if I say so myself. Now into the hardware itself, the NES houses a 8-bit CPU, a Ricoh 2A03, which runs at around 1.79 Mhz. This CPU is pretty much a clone of the MOS 6502, but with the decimal mode removed, and a APU added. The PPU, the Ricoh 2C02, runs around 3 times faster then the CPU, and is reponsible for display graphics on a frame of 256x240 with palletes being able to pick from 64 colours. When it comes to memory, there is 2 KB of RAM, and 2 KB of VRAM with a 16-bit address bus. NES cartridges can also contain a mapper chip to support larger ROMs, larger graphics data, and more RAM. Coming back to this project, this was really fun to work on! Now you may have a few questions like, "Ok, so why the name NET-NES?" Well I made it using C# and Dotnet, so I thought it's pretty unique and fun to say! Now you may ask, "Cool, but why C# and Raylib again? Why not C/C++, or even Java?" C# has been was wonderful to use and something I keep coming back to, and the community is great. As for Raylib, I just keep finding it fun! :)

Getting Started

Want to use it, and mess around? Here's how you can get started!

Download

  1. Download it from here, or on the releases page. (win-x64, win-x86, osx-x64, osx-arm64, linux-x64)
  2. Unzip the folder
  3. Launch the executable
    • On MacOS, there might be a pop up saying "Apple could not verify", this is normal. Simply right click on the app, then open, then open again. You also go to System Settings, then security, then allow. You only need to do this once during the first time.
    • You may also need to enable execute permission on "Unix-like Oses"
    • If you want to use the terminal: Point your terminal to the application and run, Windows: NET-NES --nes , Unix-like Oses ./NET-NES --nes
  4. You are ready to go!

Controls

  • (A) = X
  • (B) = Z
  • [START] = [ENTER]
  • [SELECT] = [RSHIFT]
  • D-Pad = ArrowKeys

Note: Pressing [SPACE] Bar toggles the top menu bar.

Usage

Simply launching the executable will show the basic GUI. Going File -> Open ROM will bring up a file launcher to select your ROM. Help -> Manual will show all the basic instructions on how to use, and what to know. More information in the Compatibility section.

Flags

NET-NES flags when using terminal. Note: these flags can be passed in any order, and in any combination.

  • --nes : Starts up the emulator given a rom file
  • --json : Runs a CPU test for a instruction given a JSON file in test/v1
  • -s , --scale : Scale window size by factor (2 is default)
  • -f, --fps: Enables FPS counter (off is default)
  • -rl, --raylib-log: Enables Raylib logs (off is default)
  • -d, --debug: Enables debug mode (off is default)
  • -a, --about: Shows about
  • -v, --version: Shows version number
  • -h, --help: Shows help screen

Screenshots

Showcase of running games

Demo Gameplay

Compatibility

Passes nestest CPU instruction tests

Most NES cartridges came with a mapper chip to support larger size of ROM and graphics data, as well as bulit in RAM on the cartridges. Mapper 0 (NROM) is most simple, and should work. Mapper 1, Mapper 2, and Mapper 4 all have been implemented and they work, but they should be consider experimental.

Most games I tried out works. Some games may have some graphical glitches, or might just freeze. This is because even though I have emulated the base NES system, the emulation itself is not fully accurate. This because the PPU emulation I did runs by scanline timing, and not by dot by dot, meaning there is some timing inaccuracy that can effect a few games. More infomation in the Program Architecture section. However, most games should run fine, here is list of games I tested:

…

Compile

Want to tinker around, modify, make your own, learn a bit about emulation development, or contribute? Here's how you can get started with the code and compile.

To get started, you need to have dontnet install. For reference, I used dotnet 6.0

  1. Download dotnet: https://dotnet.microsoft.com/en-us/
  2. Clone this repository, and point your terminal to the root directory of the repository
  3. Run dotnet run to compile, and it should run right after! You also do dotnet run -- --nes if want to load up a rom at startup!

Raylib-cs (the C# binding (made by Chris Dill) for Raylib), does not need to be installed, as dotnet will automatically install any dependences from NuGet. For more information on raylib-cs can be found here on Github: https://github.com/chrisdill/raylib-cs. This also applies to Rlimgui-cs and ImGui.NET.

Build

  • For your own platform, framework dependent: dotnet publish
  • For other platform, single file, not framework dependent: dotnet publish -r --self-contained -o bulid/ /p:PublishSingleFile=true
  • For other platform, single file, framework dependent: dotnet publish -r --no-self-contained -o bulid/ /p:PublishSingleFile=true

The reason to have both dotnet dependent or not is the file size. If the user already has dotnet, the lighter file size is the best option. If the user does not have dotnet, it's more convenient to bundle in the dotnet as self contained even if the file size is larger. It's best to put PublishSingleFile for convenience, especially for self contained dotnet as that will have 224 dll files all in the root of the executable.

For more see the dotnet publish documentation: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish, RID: https://learn.microsoft.com/en-us/dotnet/core/rid-catalog, SingleFile: https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md

For MacOS, building requires signing, especially for Apple Silicon. This part is going to be a general note. Dotnet and C# when running and building will automatically sign the binaries with a simple "ad-hoc" (meaning needed or for this) signature. This needs to be done for using and distributing. On other platforms, compiling for Macs would not be signed, since Apple's codesign tool is only on Macs (though others have made open source versions of the tool for cross-platform use). If you have a unsigned binary compiled on a non-Mac platform now on a Mac platform, a simple "ad-hoc" signing will do and can done by codesign -s - . When it comes .app bundles, signing is also required in the same way. You can bulid the .app bundle manually since it's just a directory (Mac build of NET-NES for reference). However, even if the .app bundle is made up with already signed binary, you will have to re-sign the whole .app bundle. This can be done with codesign --force --deep -s - .

Program Architecture

Here's a little information on the program layout!

It can seem a bit complex at first, but it's quite simple. I like to write my code, where it should be easy enough for anyone to understand, no matter their knowledge with emulation, or code! With that in mind, this portion itself is written to be simple, no matter your skill level, so anybody should get the idea of the program works, it's sort of the reason why I write these parts! :)

C# object oriented design allows us to think all the componets of the NES hardware, and make them into classes, which can be used to represent a object. The root of the src contains all the main code. With that, we have the following:

  • CPU.cs: The 8-Bit NES CPU (Ricoh 2A03)
  • PPU.cs: The PPU (Picture Processing Unit) of the NES is responsible for drawing the graphics on screen
  • Bus.cs: Contains the Read() and Write() functions, directing bus for RAM, VRAM, and the cartridge, this also there we can "wire up" some our componets here that rely on memory access
  • Cartridge.cs: Contains memory for PRG and CHR, set's up the cartidge state depending on the iNES header
  • src/mapper: Contains the different memory bank controllers needed, all to make the NES support larger ROMs
    • Mapper0.cs: NROM
    • Mapper1.cs: MMC1
    • Mapper2.cs: UxROM
    • Mapper4.cs: MMC3
  • Input.cs: Handles input for the NES
  • NES.cs: Where we "wire up" all the componets
  • Test.cs: Used for JSON test for the CPU
  • TestBus.cs: A simplified bus for simple memory access for testing
  • TestRunner.cs: Runs the JSON test from Test.cs
  • GUI.cs: A simple GUI to wrap the NES core
  • Helper.cs: Static class to hold global values
  • Program.cs: The entry point of the emulator

This emulator is not meant to be cycle accurate, as the PPU does not run dot by dot, but by scanline.

Each component should stick to it's task. The core of this emulator is written in plain C#, with the only outside library being raylib-cs which is used very minimally. It would be something I may do where I refactor the code to make the core more independent, which should be easy enough to do.

To see how the main loop works, we can look into the NES.cs in the Run() function:

cs
public void Run() {
  int cycles = 0;

  bus.input.UpdateController();

  while (cycles = 341`, it can render a scanline. The `Bus` is what connects the `CPU` and `PPU` to memory, and it's all three components can "talk" to each other using MMIO which are get special places in memory where both componets can read and write depending on use, for example like PPUDATA `$2000` which where VRAM data can we read and write to. Let's look at `CPU.cs` as a example. A constructor is made to set the default state of the componet:
```cs
public CPU(IBus bus) {
     A = X = Y = 0;
     PC = 0x0000;
     SP = 0x0000;
     status = 0;

     this.bus = bus;

     irqRequested = false;
     nmiRequested = false;

     Console.WriteLine("CPU init");
}

Notice how other component can rely on others, and how they need to be passed in. In this case of the CPU, the Bus is passed in, as many insturction need to access to the memory. Each component then had the "main" method they would be invoking. For PPU called Step() as we step every cycle passed in. For the CPU, we have ExecuteInstruction():

cs
private byte Fetch() {
  return bus.Read(PC++);
}

public int ExecuteInstruction() {
  ...
  byte opcode = Fetch();

  switch (opcode) {
  //LDA, LDX, LDY, STA, STX, STY
  case 0xA9: return LDR(ref A, Immediate, 2);
  case 0xA5: return LDR(ref A, ZeroPage, 3);
  case 0xB5: return LDR(ref A, ZeroPageX, 4);
  ...

private int LDR(ref byte r, Func mode, int baseCycles) {
  var addr = mode();
  r = bus.Read(addr.address);
  SetZN(r);

  return baseCycles + addr.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言