Giter Club home page Giter Club logo

nes's Introduction

Pyntendo

pip install pyntendo

A Nintendo Entertainment System (NES) emulator written in Python and Cython.

  • All core components are implemented, including audio, and the most important mappers.
  • Performant (runs at 60fps on modern machines)
  • Fully headless operation is supported
    • NumPy-based input/output
    • Very limited external dependencies (really just NumPy)
    • See Headless Demo for a minimal example
  • Pure Python/Cython, fully compatible with CPython (>3.6)

Although most games I have tested seem to run without issues, there are still some open issues that would improve performance and accuracy and probably make some hard to emulate games work or work better.

  • Several popular(ish) mappers are not implemented (along with lots of less popular ones)
  • Some fine timing is not quite right, which might cause issues in some sensitive games
  • This is not a cycle-accurate emulator, so sub-instruction level timing is not correctly emulated, and some parts of other systems are not emulated in a cycle-correct way
  • See my devnotes for known issues and planned work

I would like to give huge thanks and kudos to everyone who contributed to the amazing NESDev Wiki and all the other fantastic sources (most listed in the code), tests and forums for NES emulator development and 6502 progamming. Without these resources it would have been impossible to develop this emulator.

Usage

Basic usage:

from nes import NES
nes = NES("my_rom.nes")
nes.run()

Full set of options:

from nes import NES, SYNC_AUDIO, SYNC_NONE, SYNC_PYGAME, SYNC_VSYNC

nes = NES(rom_file,                  # the rom file to load
          screen_scale=3,            # factor by which to scale the screen (NES screen is 256x240 pixels with overscan)
          log_file=None,             # file to log to (logging is largely turned off by default and is exceptionally slow for high-volume parts of the system)
          log_level=None,            # level of logging (logging is largely turned off by default)
          opengl=False,              # use opengl for screen rendering
          sync_mode=SYNC_AUDIO,      # audio / video sync mode  (one of SYNC_AUDIO, SYNC_NONE, SYNC_PYGAME, SYNC_VSYNC; see below)
          verbose=True,              # whether to print out cartridge info at startup
          show_nametables=False,     # shows the nametables alongside the main screen (for debug, not compatible with opengl=True)
          vertical_overscan=False,   # show the top and bottom 8 pixels (not usually visible on CRT TVs)
          horizontal_overscan=False, # show the left and right 8 pixels (often not visible on CRT TVs)
          palette_file=None,         # supply a palette file to use; None gives default
          headless=False,            # runs the nes in headless mode without the pygame screen being started
          )

Sync mode controls how the framerate is controlled and synced to screen/audio. The available modes are as follows:

SYNC_NONE = 0  # no sync: runs very fast, unplayable, music is choppy
SYNC_AUDIO = 1  # sync to audio: rate is perfect, can glitch sometimes, screen tearing can be bad
SYNC_PYGAME = 2  # sync to pygame's clock, adaptive audio: generally reliable, some screen tearing
SYNC_VSYNC = 3  # sync to external vsync, adaptive audio: requires ~60Hz vsync, no tearing

Pure python version:

(This is purely for interest and comparison to the Cython version. It is very slow, has no APU, is not up to date, has some (more) bugs than the cython version and has not been developed for a while.):

from nes.pycore.system import NES as pyNES
pynes = pyNES("my_rom.nes")
pynes.run()

Screenshots

Here are some screenshots of the emulator in action: Super Mario Brothers, Donkey Kong, MegaMan

Controls

Default keymap is:

Up, Left, Down, Right: W, A, S, D
Select, Start:  G, H
A, B: P, L

OSD/Volume controls:

Turn off OSD:  1
Start CPU logging (very slow): 2
Volume Down/Up: -, =
Mute: 0

Dependencies

Depends on the following libraries for key functionality:

  • numpy (optional?)
    • headless operation
    • (possibly also required by pygame surfarray, used in rendering)
  • pygame (optional)
    • timing
    • rendering
    • input
    • (without pygame, only headless operation is possible)
  • pyaudio (optional)
    • audio playing
    • sync to audio
  • pyopengl (optional)
    • OpenGL rendering
    • (not essential; can use SDL rendering via pygame)

License

Distributed under the MIT License (see here)

nes's People

Contributors

jameskmurphy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nes's Issues

ERROR: Could not build wheels for nes-py, which is required to install pyproject.toml-based projects

pip install nes-py
Collecting nes-py
  Downloading nes_py-8.2.1.tar.gz (77 kB)
     ---------------------------------------- 77.7/77.7 kB 613.0 kB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Collecting gym>=0.17.2 (from nes-py)
  Downloading gym-0.26.2.tar.gz (721 kB)
     ---------------------------------------- 721.7/721.7 kB 827.3 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy>=1.18.5 in e:\python311-venv\lib\site-packages (from nes-py) (1.25.0)
Collecting pyglet<=1.5.21,>=1.4.0 (from nes-py)
  Downloading pyglet-1.5.21-py3-none-any.whl.metadata (7.6 kB)
Requirement already satisfied: tqdm>=4.48.2 in e:\python311-venv\lib\site-packages (from nes-py) (4.66.1)
Collecting cloudpickle>=1.2.0 (from gym>=0.17.2->nes-py)
  Downloading cloudpickle-3.0.0-py3-none-any.whl.metadata (7.0 kB)
Collecting gym-notices>=0.0.4 (from gym>=0.17.2->nes-py)
  Downloading gym_notices-0.0.8-py3-none-any.whl.metadata (1.0 kB)
Requirement already satisfied: colorama in e:\python311-venv\lib\site-packages (from tqdm>=4.48.2->nes-py) (0.4.6)
Downloading pyglet-1.5.21-py3-none-any.whl (1.1 MB)
   ---------------------------------------- 1.1/1.1 MB 800.4 kB/s eta 0:00:00
Downloading cloudpickle-3.0.0-py3-none-any.whl (20 kB)
Downloading gym_notices-0.0.8-py3-none-any.whl (3.0 kB)
Building wheels for collected packages: nes-py, gym
  Building wheel for nes-py (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [28 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-311
      creating build\lib.win-amd64-cpython-311\nes_py
      copying nes_py\nes_env.py -> build\lib.win-amd64-cpython-311\nes_py
      copying nes_py\_image_viewer.py -> build\lib.win-amd64-cpython-311\nes_py
      copying nes_py\_rom.py -> build\lib.win-amd64-cpython-311\nes_py
      copying nes_py\__init__.py -> build\lib.win-amd64-cpython-311\nes_py
      creating build\lib.win-amd64-cpython-311\nes_py\app
      copying nes_py\app\cli.py -> build\lib.win-amd64-cpython-311\nes_py\app
      copying nes_py\app\play_human.py -> build\lib.win-amd64-cpython-311\nes_py\app
      copying nes_py\app\play_random.py -> build\lib.win-amd64-cpython-311\nes_py\app
      copying nes_py\app\__init__.py -> build\lib.win-amd64-cpython-311\nes_py\app
      creating build\lib.win-amd64-cpython-311\nes_py\wrappers
      copying nes_py\wrappers\joypad_space.py -> build\lib.win-amd64-cpython-311\nes_py\wrappers
      copying nes_py\wrappers\__init__.py -> build\lib.win-amd64-cpython-311\nes_py\wrappers
      running build_ext
      building 'nes_py.lib_nes_env' extension
      creating build\temp.win-amd64-cpython-311
      creating build\temp.win-amd64-cpython-311\Release
      creating build\temp.win-amd64-cpython-311\Release\nes_py
      creating build\temp.win-amd64-cpython-311\Release\nes_py\nes
      creating build\temp.win-amd64-cpython-311\Release\nes_py\nes\src
      creating build\temp.win-amd64-cpython-311\Release\nes_py\nes\src\mappers
      cl.exe /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Ines_py/nes/include -IE:\Python311-venv\include -IE:\Python311\include -IE:\Python311\Include /EHsc /Tpnes_py/nes/src/mappers\mapper_CNROM.cpp /Fobuild\temp.win-amd64-cpython-311\Release\nes_py/nes/src/mappers\mapper_CNROM.obj -std=c++1y -pipe -O3
      error: command 'cl.exe' failed: None
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for nes-py
  Running setup.py clean for nes-py
  Building wheel for gym (pyproject.toml) ... done
  Created wheel for gym: filename=gym-0.26.2-py3-none-any.whl size=827637 sha256=4bd5ea8e44a83ff271acbca77ab5ff7b8bd0bcd02a9d8b2065ef66a3c9b9ce5b
  Stored in directory: c:\users\ManPython\appdata\local\pip\cache\wheels\1c\77\9e\9af5470201a0b0543937933ee99ba884cd237d2faefe8f4d37
Successfully built gym
Failed to build nes-py
ERROR: Could not build wheels for nes-py, which is required to install pyproject.toml-based projects

Building wheel for pyntendo (pyproject.toml) did not run successfully.

>pip install pyntendo
Collecting pyntendo
  Using cached pyntendo-0.0.8.tar.gz (1.1 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyntendo
  Building wheel for pyntendo (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for pyntendo (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [33 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-311
      creating build\lib.win-amd64-cpython-311\nes
      copying nes\instructions.py -> build\lib.win-amd64-cpython-311\nes
      copying nes\meta.py -> build\lib.win-amd64-cpython-311\nes
      copying nes\peripherals.py -> build\lib.win-amd64-cpython-311\nes
      copying nes\rom.py -> build\lib.win-amd64-cpython-311\nes
      copying nes\tests.py -> build\lib.win-amd64-cpython-311\nes
      copying nes\utils.py -> build\lib.win-amd64-cpython-311\nes
      copying nes\__init__.py -> build\lib.win-amd64-cpython-311\nes
      creating build\lib.win-amd64-cpython-311\tests
      copying tests\__init__.py -> build\lib.win-amd64-cpython-311\tests
      creating build\lib.win-amd64-cpython-311\nes\cycore
      copying nes\cycore\__init__.py -> build\lib.win-amd64-cpython-311\nes\cycore
      creating build\lib.win-amd64-cpython-311\nes\pycore
      copying nes\pycore\bitwise.py -> build\lib.win-amd64-cpython-311\nes\pycore
      copying nes\pycore\carts.py -> build\lib.win-amd64-cpython-311\nes\pycore
      copying nes\pycore\memory.py -> build\lib.win-amd64-cpython-311\nes\pycore
      copying nes\pycore\mos6502.py -> build\lib.win-amd64-cpython-311\nes\pycore
      copying nes\pycore\ppu.py -> build\lib.win-amd64-cpython-311\nes\pycore
      copying nes\pycore\system.py -> build\lib.win-amd64-cpython-311\nes\pycore
      copying nes\pycore\__init__.py -> build\lib.win-amd64-cpython-311\nes\pycore
      running build_ext
      building 'nes.cycore.apu' extension
      creating build\temp.win-amd64-cpython-311
      creating build\temp.win-amd64-cpython-311\Release
      creating build\temp.win-amd64-cpython-311\Release\nes
      creating build\temp.win-amd64-cpython-311\Release\nes\cycore
      cl.exe /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IE:\Python311-venv\include -IE:\ \Python311\include -IE:\Python311\Include /Tcnes/cycore\apu.c /Fobuild\temp.win-amd64-cpython-311\Release\nes/cycore\apu.obj
      error: command 'cl.exe' failed: None
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyntendo
Failed to build pyntendo
ERROR: Could not build wheels for pyntendo, which is required to install pyproject.toml-based projects

Add dependencies to install instructions

After installing just using pip install pyntendo then trying to run a game a few times, I realized you also need

  • cython
  • pygame
  • numpy

Please could you either add those as dependencies to setup.py or include it in the README :-)

p.s. I had great fun playing mario

ImportError: cannot import name 'SYNC_AUDIO' from 'nes'

Error:

pygame 2.4.0 (SDL 2.26.4, Python 3.11.3)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "E:\Pyntendo\main.pyw", line 1, in <module>
    from nes import NES, SYNC_AUDIO, SYNC_NONE, SYNC_PYGAME, SYNC_VSYNC
ImportError: cannot import name 'SYNC_AUDIO' from 'nes' (E:\Python311-venv\Lib\site-packages\nes\__init__.py)

Code:

from nes import NES, SYNC_AUDIO, SYNC_NONE, SYNC_PYGAME, SYNC_VSYNC

SYNC_NONE = 0  # no sync: runs very fast, unplayable, music is choppy
SYNC_AUDIO = 1  # sync to audio: rate is perfect, can glitch sometimes, screen tearing can be bad
SYNC_PYGAME = 2  # sync to pygame's clock, adaptive audio: generally reliable, some screen tearing
SYNC_VSYNC = 3  # sync to external vsync, adaptive audio: requires ~60Hz vsync, no tearing

nes = NES(rom_file,                  # the rom file to load
          screen_scale=3,            # factor by which to scale the screen (NES screen is 256x240 pixels with overscan)
          log_file=None,             # file to log to (logging is largely turned off by default and is exceptionally slow for high-volume parts of the system)
          log_level=None,            # level of logging (logging is largely turned off by default)
          opengl=False,              # use opengl for screen rendering
          sync_mode=SYNC_AUDIO,      # audio / video sync mode  (one of SYNC_AUDIO, SYNC_NONE, SYNC_PYGAME, SYNC_VSYNC; see below)
          verbose=True,              # whether to print out cartridge info at startup
          show_nametables=False,     # shows the nametables alongside the main screen (for debug, not compatible with opengl=True)
          vertical_overscan=False,   # show the top and bottom 8 pixels (not usually visible on CRT TVs)
          horizontal_overscan=False, # show the left and right 8 pixels (often not visible on CRT TVs)
          palette_file=None,         # supply a palette file to use; None gives default
          headless=False,            # runs the nes in headless mode without the pygame screen being started
          )



nes = NES("2.nes")
nes.run()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.