Skip to content

Instantly share code, notes, and snippets.

@scottferg
Created September 13, 2013 00:52
Show Gist options
  • Save scottferg/6545730 to your computer and use it in GitHub Desktop.
Save scottferg/6545730 to your computer and use it in GitHub Desktop.

Revisions

  1. scottferg created this gist Sep 13, 2013.
    56 changes: 56 additions & 0 deletions minimal_nes_main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    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
    }