dorkhub

6502Emulator

NES模拟器(尽量还原硬件运行逻辑)

tiansongyu
C++536 forksupdated 1 month ago
git clone https://github.com/tiansongyu/6502Emulator.gittiansongyu/6502Emulator

NES 模拟器(Nintendo Entertainment System emulator)

适用于Windows、UNIX、MAC平台的开源NES模拟器,为NES模拟器学习者提供与原NES机器高度相似的运行逻辑展示,源码并没有对运行速度进行优化,这也是为了保证高度还原NES运行机制的妥协。

该项目旨在重现NES游戏机的运行机制,而不注重性能,如果想要学习性能强大的模拟器,可以参照以下模拟器源码,·fceuxjsnes(js)nes(go)SimpleNES等源码,这些模拟器皆具有较好的性能,但整体代码结构并不利于NES模拟器的学习,因为其中做了大量的性能优化,导致模拟器的运行机制与原机器大相径庭,所以本仓库源码更利于理解NES。

控制器按键

Nintendo Emulator
Up, Down, Left, Right W A S D
Start T
Select Y
A K
B J

功能键

function key
save game state F1
load game state F2
reset game Backspace
change palette P

音频后端不可用时(无声模式),额外提供调试键:Space 暂停/继续, C 单步一条 CPU 指令,F 单步一帧。

实现的模块

  • BUS
  • Cartridge(卡带)
  • Mapper(0\1\2\3\4\66)
  • 2A03(apu)
  • 2C02(ppu)
  • 6502(cpu)

编译环境配置

linux环境

安装cmake

# ubuntu
# 安装opengl、alsa
sudo apt install cmake mesa-common-dev libgl1-mesa-dev \
libglu1-mesa-dev alsa-base alsa-utils alsa-source libasound2-dev libpng-dev -y

windows

安装vs2019

编译

linux环境

git clone git@github.com:tiansongyu/6502Emulator.git 
cd 6502Emulator 
mkdir build  
cd build 
cmake  -DCMAKE_BUILD_TYPE=Release .. 
make -j12 
cd 6502/6502Emulator/
./6502Emulator [rom路径]     # 默认 ./rom/smb.nes,可指定其他 .nes 文件

回归测试(headless,无需图形环境)

模拟器核心是独立的静态库(不依赖任何 GUI),tests/nes_headless 就是用它写的回归工具:

cd build/tests
./nes_headless trace    <rom> 8991        # nestest CPU 逐指令跟踪
./nes_headless frames   <rom> 300 [start帧] # 帧哈希(图形回归)
./nes_headless audio    <rom> 5 [start帧]   # 音频指标(直流/点击)
./nes_headless savetest <rom> 200 100 60    # 存档往返一致性

基线与验证方法见 tests/baselines.md

Windows环境

git clone git@github.com:tiansongyu/6502Emulator.git 
cd 6502Emulator 
make_VS2019.bat

可游玩游戏

每个游戏对应一个Mapper,只要实现游戏对应的Mapper,就可以游玩 本模拟器实现的mapper有

  • Mapper0 (NROM)
  • Mapper1 (MMC1)
  • Mapper2 (UxROM)
  • Mapper3 ( CNROM )
  • Mapper4 (MMC3) 最复杂的一种Mapper(IRQ 改为电平触发后,metal max 等游戏的中断问题已修复)
  • Mapper66 (GxROM)

查看如下游戏列表,查看对应的Mapper,可以用来判断是否可游玩

0,1,2,3,4为任天堂自己生产的mapper,已经可以游玩大部分游戏,如想实现其他Mapper ,可以查看Mapper资料,并查看本仓库源码,可以找到实现其他mapper的方法。

参考文档资料

其他开发工具

未实现功能

more like this

asac-fc

asac fc is an rp2040 based flight controller made for FPV drone flying

C50

smb-vanilla-port

A C and C++ decompilation of the NES games "Super Mario Bros" and "Super Mario Bros: The Lost Levels"

C51

croyde-riscv

A barebones 64-bit RISC-V micro-controller class CPU, implementing the I(nteger), M(ul/div), C(ompressed) and K(ryptogr…

SystemVerilog52

search

search projects, people, and tags