Giter VIP home page Giter VIP logo

nes's Introduction

Summary

This is an NES emulator written in Go.

Screenshots

Screenshots

Title Screens

http://www.michaelfogleman.com/static/nes/

Dependencies

github.com/go-gl/gl/v2.1/gl
github.com/go-gl/glfw/v3.1/glfw
github.com/gordonklaus/portaudio

The portaudio-go dependency requires PortAudio on your system:

To build portaudio-go, you must first have the PortAudio development headers and libraries installed. Some systems provide a package for this; e.g., on Ubuntu you would want to run apt-get install portaudio19-dev. On other systems you might have to install from source.

On Mac, you can use homebrew:

brew install portaudio

Installation

The go get command will automatically fetch the dependencies listed above, compile the binary and place it in your $GOPATH/bin directory.

go get github.com/fogleman/nes

Usage

nes [rom_file|rom_directory]
  1. If no arguments are specified, the program will look for rom files in the current working directory.

  2. If a directory is specified, the program will look for rom files in that directory.

  3. If a file is specified, the program will run that rom.

For 1 & 2, the program will display a menu screen to select which rom to play. The thumbnails are downloaded from an online database keyed by the md5 sum of the rom file.

Menu Screenshot

Controls

Joysticks are supported, although the button mapping is currently hard-coded. Keyboard controls are indicated below.

Nintendo Emulator
Up, Down, Left, Right Arrow Keys
Start Enter
Select Right Shift
A Z
B X
A (Turbo) A
B (Turbo) S
Reset R

Mappers

The following mappers have been implemented:

  • NROM (0)
  • MMC1 (1)
  • UNROM (2)
  • CNROM (3)
  • MMC3 (4)
  • AOROM (7)

These mappers cover about 85% of all NES games. I hope to implement more mappers soon. To see what games should work, consult this list:

NES Mapper List

Known Issues

  • there are some minor issues with PPU timing, but most games work OK anyway
  • the APU emulation isn't quite perfect, but not far off

Documentation

Interested in writing your own emulator? Curious about the NES internals? Here are some good resources:

nes's People

Contributors

alanoliveira avatar caixiangyue avatar d1y avatar fogleman avatar kgabis avatar mattkanwisher avatar mtojek avatar ncoish avatar odidev avatar tianzerl avatar zhaostu 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  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

nes's Issues

Update ‘go-gl/glfw’ to v3.2 or above

Hi Team,

I am working on the project ‘mvn-golang’, to add support for the Linux/ARM64 platform.

The build fails on the Linux/ARM64 machine, because of the ‘folgeman/nes’ dependency used. ‘folgeman/nes’ uses ‘glfw’ version 3.1. This version does not support the Linux/ARM64 platform, and hence ‘mvn-golang’ fails to build for ARM64.

Can you please update the ‘glfw’ version to v3.2 or above, as higher versions of glfw are passing for the Linux/ARM64 platform. It will help ‘folgeman/nes’ to work on both LINUX AMD64 and ARM64 platforms.

If required, I will raise the PR with updates.

Instal failed

OS:mint 20.2

pkg-config --cflags -- portaudio-2.0

Package portaudio-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `portaudio-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'portaudio-2.0' found
pkg-config: exit status 1

github.com/go-gl/glfw/v3.2/glfw

/usr/bin/ld: 找不到 -lXxf86vm
collect2: error: ld returned 1 exit status

github.com/go-gl/glfw/v3.2/glfw

In file included from /data/SourceCode/Go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/c_glfw_linbsd.go:24:
/data/SourceCode/Go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/glfw/src/linux_joystick.c: In function ‘_glfwInitJoysticksLinux’:
/data/SourceCode/Go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/glfw/src/linux_joystick.c:224:42: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 9 [-Wformat-truncation=]
224 | snprintf(path, sizeof(path), "%s/%s", dirname, entry->d_name);
| ^~~~~~~
In file included from /usr/include/stdio.h:867,
from /usr/include/X11/Xcursor/Xcursor.h:26,
from /data/SourceCode/Go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/glfw/src/x11_platform.h:39,
from /data/SourceCode/Go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/glfw/src/internal.h:169,
from /data/SourceCode/Go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/glfw/src/x11_init.c:28,
from /data/SourceCode/Go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/c_glfw_linbsd.go:19:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: ‘__builtin___snprintf_chk’ output between 12 and 267 bytes into a destination of size 20
67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Failed when using "go get"

Go Version: go version go1.11.2 darwin/amd64
OS: MacOS 10.12.6

When I run go get github.com/fogleman/nes, it failed. And here is the output:

go: finding github.com/fogleman/nes latest
go: downloading github.com/fogleman/nes v0.0.0-20180222220412-5a21a6273289
go: finding github.com/gordonklaus/portaudio latest
go: finding github.com/go-gl/glfw/v3.1/glfw latest
go: finding github.com/go-gl/gl/v2.1/gl latest
go: downloading github.com/gordonklaus/portaudio v0.0.0-20180817120803-00e7307ccd93
go: finding github.com/go-gl/gl latest
go: downloading github.com/go-gl/gl v0.0.0-20181026044259-55b76b7df9d2
go: finding github.com/go-gl/glfw latest
go: downloading github.com/go-gl/glfw v0.0.0-20181213070059-819e8ce5125f
# pkg-config --cflags  -- portaudio-2.0
Package portaudio-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `portaudio-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'portaudio-2.0' found
pkg-config: exit status 1

APU Problems

I have noticed you have the exact same problem I do in my emulator, which is that during the Zelda title screen, the pulse waves cut out too quickly; there is a bit of a gap that should not be there. Just thought I'd point it out in case you can figure out the root cause before I do; I suspect we may have used the same docs to write our APUs, and maybe there is a problem in the documentation. I have determined that in my emu, the pulse length counter hits 0 too quickly, but not sure why.

Broken link

Hi,

First of all, great job and you are a wonderful inspiration for every programmer :)

6502 CPU Reference link is broken

Error on install

I run the following:
go get github.com/fogleman/nes

And get the following output:
# pkg-config --cflags portaudio-2.0
Package portaudio-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `portaudio-2.0.pc' to the PKG_CONFIG_PATH environment variable
No package 'portaudio-2.0' found
pkg-config: exit status 1

How to reset the loaded rom?

Hi I know this is just an awesome pet project, but I have a strage problem I played a game which crashed the music plays but their are there only an background color but now other spirites like the charecter and level objects or the game menu.. Is there any trick to solve this?

Module path should be "github.com/fogleman/nes", not "nes"

Background

Module path is inconsistent with go import path.
GO111MODULE=on, run go get github.com/fogleman/nes:

$ go get: github.com/fogleman/[email protected]: parsing go.mod:
        module declares its path as: nes
                but was required as: github.com/fogleman/nes

Solution

Fix the module path:

Rename the module path to "github.com/fogleman/nes".
https://github.com/fogleman/nes/blob/master/go.mod#L1

module github.com/fogleman/nes
go 1.14
require (
	…
) 

Can't install on Ubuntu 15.10

My Ubuntu system had upgraded to Ubuntu 15.10, when ran command "go get github.com/fogleman/nes", go-gl can't compile.
@ubuntu:~$ go get github.com/fogleman/nes

github.com/go-gl/glfw/v3.1/glfw

In file included from GoProject/src/github.com/go-gl/glfw/v3.1/glfw/context.go:4:0:
glfw/include/GLFW/glfw3.h:153:21: fatal error: GL/gl.h: No such file or directory
compilation terminated.

github.com/go-gl/gl/v2.1/gl

GoProject/src/github.com/go-gl/gl/v2.1/gl/procaddr.go:52:21: fatal error: GL/glx.h: No such file or directory
compilation terminated.

error with go get github.com/fogleman/nes

When I try to install the emulator I'm getting this output:

"# github.com/go-gl/glfw/v3.1/glfw
/usr/bin/ld: no se puede encontrar -lXi
collect2: error: ld returned 1 exit status"

When I look in $GOPATH/bin, nes is not installed.

Thank you.

Zero Page Indexed

case modeZeroPageX:
    address = uint16(cpu.Read(cpu.PC+1) + cpu.X)

case modeZeroPageY:
    address = uint16(cpu.Read(cpu.PC+1) + cpu.Y)

I have yet to run or play with your code, Golang isn't exactly my domain. However, this doesn't appear to account for wrapping and always being on the zero page. Lets say 0xFF is in cpu.PC+1 and cpu.X is 3. The address returned would be 0x0102 not 0x0002. Same goes for Y.

I'm writing my own 6502 at the moment so please feel free to call me nuts since your emulator seems to work from the screenshots.

From: Emulator 101

Zero-Page Indexed

This works just like absolute indexed, but the target address is limited to the first 0xFF bytes.

The target address will wrap around and will always be in the zero page. If the instruction is LDA $C0,X, and X is $60, then the target address will be $20. $C0+$60 = $120, but the carry is discarded in the calculation of the target address.

[Newb Question] Go-gl can't find headers

Alright, so admittedly this might be a stupid question, but I normally use a windows environment for development and have only recently started using Linux, mostly because it's damn hard to contribute to anything open source when you're running windows. Some of these configuration problems can be a bit baffling, so excuse the newbness.

Following the directions, I installed portaudio without any issue. But when I ran go get github.com/fogleman/nes I get this error:

# github.com/go-gl/gl/v2.1/gl
gocode/src/github.com/go-gl/gl/v2.1/gl/procaddr.go:52:21: fatal error: GL/glx.h: No such file or directory
  #include <GL/glx.h>
                     ^
compilation terminated.
# github.com/go-gl/glfw/v3.1/glfw
In file included from gocode/src/github.com/go-gl/glfw/v3.1/glfw/context.go:4:0: glfw/include/GLFW/glfw3.h:153:21: fatal error: GL/gl.h: No such file or directory
   #include <GL/gl.h>
                     ^
compilation terminated.

It's pretty obvious what's happening here: go-gl can't find the OpenGL headers. Why, I'm not quite sure. Does something in my system need to be pointing to the header files, or is this an actual bug? I'm running Xubuntu 14, if that's relevant.

APU Triangle Channel Problem

In game F1, the triangle channel will send out some high-frequency waveform, especially after the game is pause. When the triangle channel is forced to mute, it disappears.

No audio.

Can't enjoy the old school Mario music..

Segmentation fault

Running "go get github.com/fogleman/nes" gives the following, concise output:
Segmentation fault

No bin folder is created under my GOPATH.

I'm running Linux Mint.

portaudio-go was moved to github

After I run go get github.com/fogleman/nes the terminal gives me messages as follow:
package code.google.com/p/portaudio-go/portaudio: Get https://code.google.com/p/portaudio-go/source/checkout?repo=: dial tcp 224.0.0.1:443: connect: address family not supported by protocol family

So I use my browser to https://code.google.com/p/portaudio-go/ and found it was redirected to https://github.com/gordonklaus/portaudio. Then I modify the source code at every place the "coode.google" appear and compiled the program successfully.

Hope you fix this little issue.

Thx for sharing this awesome program.

How to solve it?

pkg-config --cflags -- portaudio-2.0

pkg-config: exec: "pkg-config": executable file not found in $PATH

CJK fonts support

panic: runtime error: index out of range

goroutine 1 [running, locked to thread]:
github.com/fogleman/nes/nes.(_Mapper3).Read(0xc208104000, 0xc208101000, 0x4b58172)
/Users/Blask/.go/src/github.com/fogleman/nes/nes/mapper3.go:24 +0x6d
github.com/fogleman/nes/nes.(_ppuMemory).Read(0xc20802c078, 0xc208281000, 0xc208283976)
/Users/Blask/.go/src/github.com/fogleman/nes/nes/memory.go:84 +0x6e
github.com/fogleman/nes/nes.(_PPU).fetchLowTileByte(0xc2082c6000)
/Users/Blask/.go/src/github.com/fogleman/nes/nes/ppu.go:376 +0x80
github.com/fogleman/nes/nes.(_PPU).Step(0xc2082c6000)
/Users/Blask/.go/src/github.com/fogleman/nes/nes/ppu.go:598 +0x374
github.com/fogleman/nes/nes.(_Console).Step(0xc2080f2000, 0x2)
/Users/Blask/.go/src/github.com/fogleman/nes/nes/console.go:48 +0x66
github.com/fogleman/nes/nes.(_Console).StepSeconds(0xc2080f2000, 0x3f9118ef3a350400)
/Users/Blask/.go/src/github.com/fogleman/nes/nes/console.go:69 +0x4d
github.com/fogleman/nes/ui.(_GameView).Update(0xc20802e410, 0x40239eb0b3919264, 0x3f9118ef3a350400)
/Users/Blask/.go/src/github.com/fogleman/nes/ui/gameview.go:68 +0x125
github.com/fogleman/nes/ui.(_Director).Step(0xc20802a280)
/Users/Blask/.go/src/github.com/fogleman/nes/ui/director.go:53 +0x76
github.com/fogleman/nes/ui.(_Director).Run(0xc20802a280)
/Users/Blask/.go/src/github.com/fogleman/nes/ui/director.go:69 +0x43
github.com/fogleman/nes/ui.(_Director).Start(0xc20802a280, 0xc20802a180, 0x3, 0x4)
/Users/Blask/.go/src/github.com/fogleman/nes/ui/director.go:64 +0xbf
github.com/fogleman/nes/ui.Run(0xc20802a180, 0x3, 0x4)
/Users/Blask/.go/src/github.com/fogleman/nes/ui/run.go:62 +0x5a4
main.main()
/Users/Blask/.go/src/github.com/fogleman/nes/main.go:19 +0x138

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/Cellar/go/1.4.2/libexec/src/runtime/asm_amd64.s:2232 +0x1

goroutine 18 [syscall, locked to thread]:
runtime.goexit()
/usr/local/Cellar/go/1.4.2/libexec/src/runtime/asm_amd64.s:2232 +0x1

after I change the rom filename to english letter only, it works

Need help decoding an error message

$ go get github.com/fogleman/nes
$ nes
2015/03/23 16:38:28 Usage: go run main.go rom_file.nes
$ nes ~/Downloads/Tetris.nes
2015/03/23 16:40:16 unsupported mapper: 65
$

I am ambivalent about the usage message, it works for one developer situation but not for the full compiled one, which perhaps should be the norm?

Sadly I have no idea what mapper 65 is :-(

invalid import path?

been trying to get this set up and going. I'm rather new to all this. anyway I run into this when I use the command.

go get github.com/fogleman/nes

go: github.com/fogleman/nes: invalid github.com import path "github.com/fogleman"

like I said I'm rather new and probably doing something completely wrong.

USB Support for Controller

Hi,

I wonder if it would be difficult to add USB Controller Support for an USB SNES Gamepad so I could run this on my Raspberry Pi and have an sort of Go based NES Classic MINI alternative..

Go 1.6 runtime error

Hello Michael,

I am really impressed with your implementation of nes emulator, so much so that I'm trying to implement my own (Swift + Metal). Was playing with your implementation, however after the update to go 1.6 I am no longer able to due to runtime error.

The problem exists for go version go1.6.2 darwin/amd64 and here is the stack trace.

panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running, locked to thread]:
panic(0x44e4660, 0xc820111a30)
    /usr/local/opt/go/libexec/src/runtime/panic.go:481 +0x3e6
github.com/gordonklaus/portaudio._cgoCheckPointer1(0x43ed9a0, 0xc820096080, 0x0, 0x0, 0x0, 0x43ccde0)
    ??:0 +0x4d
github.com/gordonklaus/portaudio.OpenStream(0x0, 0x0, 0x0, 0xc82006a360, 0x2, 0xd5d4a5, 0x40e5888000000000, 0x0, 0x0, 0xc820111a00, ...)
    /Users/pawel/go/src/github.com/gordonklaus/portaudio/portaudio.go:504 +0x3d1
github.com/fogleman/nes/ui.(*Audio).Start(0xc8200c9340, 0x0, 0x0)
    /Users/pawel/go/src/github.com/fogleman/nes/ui/audio.go:24 +0x192
github.com/fogleman/nes/ui.Run(0xc820111980, 0x1, 0x1)
    /Users/pawel/go/src/github.com/fogleman/nes/ui/run.go:33 +0xce
main.main()
    /Users/pawel/go/src/github.com/fogleman/nes/main.go:19 +0x13d

Kind regards,
Pawel

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.