func LoadRom(jbytes []byte, name string) bool { defer func() { if err := recover(); err != nil { log.Printf("panic: loadRom: %v\n", err) } }() nes.GameName = name rom := jbytes if len(cachePath) > 0 { nes.SaveStateFile = fmt.Sprintf("%s/%s.save", cachePath, nes.GameName) nes.BatteryRamFile = fmt.Sprintf("%s/%s.save", cachePath, nes.GameName) log.Printf("cache path: %s", cachePath) } log.Printf("%v ROM: %v (%v kb)\n", string(rom[:3]), nes.GameName, len(rom)/1024) videoTick, err := nes.Init(rom, nil, GetKey) if err != nil { log.Println(err) return false } video.pixelBuffer = videoTick // Main runloop, in a separate goroutine so that // the video rendering can happen on this one go nes.RunSystem() return true }
func main() { if len(os.Args) < 2 { fmt.Println("Please specify a ROM file") return } flag.Parse() if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { fmt.Println(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } else { runtime.GOMAXPROCS(runtime.NumCPU()) } contents, err := ioutil.ReadFile(os.Args[len(os.Args)-1]) if err != nil { fmt.Println(err.Error()) return } path := strings.Split(os.Args[1], "/") nes.GameName = strings.Split(path[len(path)-1], ".")[0] nes.SaveStateFile = fmt.Sprintf(".%s.state", nes.GameName) nes.BatteryRamFile = fmt.Sprintf(".%s.battery", nes.GameName) log.Println(nes.GameName, nes.SaveStateFile) audioOut = NewAudio() defer audioOut.Close() videoTick, err := nes.Init(contents, audioOut.AppendSample, GetKey) if err != nil { fmt.Println(err) } videoOut.Init(videoTick, nes.GameName) // 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 }
//export Java_com_ferg_afergulator_Engine_loadRom func Java_com_ferg_afergulator_Engine_loadRom(env *C.JNIEnv, clazz C.jclass, jbytes C.jbyteArray, name C.jstring) C.jboolean { defer func() { if err := recover(); err != nil { log.Printf("panic: loadRom: %v\n", err) } }() nes.GameName = GetJavaString(env, name) rom := GetJavaByteArray(env, jbytes) if len(cachePath) > 0 { nes.SaveStateFile = fmt.Sprintf("%s/%s.save", cachePath, nes.GameName) nes.BatteryRamFile = fmt.Sprintf("%s/%s.save", cachePath, nes.GameName) log.Printf("cache path: %s", cachePath) } log.Printf("%v ROM: %v (%v kb)\n", string(rom[:3]), nes.GameName, len(rom)/1024) if audioOut == nil { audioOut = NewAudio() } videoTick, err := nes.Init(rom, audioOut.AppendSample, GetKey) if err != nil { log.Println(err) return C.JNI_FALSE } video.pixelBuffer = videoTick // Main runloop, in a separate goroutine so that // the video rendering can happen on this one go nes.RunSystem() log.Printf("NES SYSTEM RUNNING.......") return C.JNI_TRUE }