Skip to content

Instantly share code, notes, and snippets.

@scottferg
Created September 13, 2013 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottferg/6545730 to your computer and use it in GitHub Desktop.
Save scottferg/6545730 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"github.com/scottferg/Fergulator/nes"
"os"
"runtime"
"runtime/pprof"
)
var (
running = true
videoOut Video
audioOut *Audio
cpuprofile = flag.String("cprof", "", "write cpu profile to file")
)
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
fmt.Println(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
} else if false {
runtime.GOMAXPROCS(runtime.NumCPU())
}
videoTick, gamename, err := nes.Init(GetKey)
if err != nil {
fmt.Println(err)
}
videoOut.Init(videoTick, gamename)
audioOut = NewAudio()
defer audioOut.Close()
// Main runloop, in a separate goroutine so that
// the video rendering can happen on this one
go nes.RunSystem()
// This needs to happen on the main thread for OSX
runtime.LockOSThread()
defer videoOut.Close()
videoOut.Render()
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment