func main() { filename := "" options := &nes.Options{} flag.StringVar(&options.Region, "region", "NTSC", "system region to emulate: NTSC | PAL") flag.BoolVar(&options.CPUDecode, "cpu-decode", false, "decode CPU instructions") flag.StringVar(&options.Recorder, "recorder", "", "recorder to use: none | jpeg | gif") flag.StringVar(&options.AudioRecorder, "audio-recorder", "", "recorder to use: none | wav") flag.StringVar(&options.CPUProfile, "cpu-profile", "", "write CPU profile to file") flag.StringVar(&options.MemProfile, "mem-profile", "", "write memory profile to file") flag.StringVar(&options.HTTPAddress, "http", "", "HTTP service address (e.g., ':6060')") flag.StringVar(&options.Listen, "listen", "", "Listen at address as master (e.g., ':8080')") flag.StringVar(&options.Connect, "connect", "", "Connect to address as slave, <rom-file> will be ignored (e.g., 'localhost:8080')") flag.Parse() filename, err := homedir.Expand("~/.nintengorc") if err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) } else { if _, err = os.Stat(filename); !os.IsNotExist(err) { if err = LoadConfig(options, filename); err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) } } } if len(flag.Args()) != 1 { if len(options.Connect) == 0 { fmt.Fprintf(os.Stderr, "usage: <rom-file>\n") return } } else { filename = flag.Arg(0) } nes, err := nes.NewNES(filename, options) if err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) return } if options.HTTPAddress != "" { neserv := http.NewNEServer(nes, options.HTTPAddress) fmt.Println(options.HTTPAddress) go neserv.Run() } err = nes.Run() if err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) } }
func main() { options := &nes.Options{ Region: "NTSC", } document := js.Global.Get("document") inputElem := document.Call("createElement", "input") inputElem.Call("setAttribute", "type", "file") document.Get("body").Call("appendChild", inputElem) filec := make(chan *js.Object, 1) inputElem.Set("onchange", func(event *js.Object) { filec <- inputElem.Get("files").Index(0) }) file := <-filec gamename := file.Get("name").String() reader := js.Global.Get("FileReader").New() bufc := make(chan []byte, 1) reader.Set("onloadend", func(event *js.Object) { bufc <- js.Global.Get("Uint8Array").New(reader.Get("result")).Interface().([]byte) }) reader.Call("readAsArrayBuffer", file) buf := <-bufc br := bytes.NewReader(buf) nes, err := nes.NewNESFromReader(gamename, br, options) if err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) return } inputElem.Call("remove") go nes.Run() }