-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (49 loc) · 1.22 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"log"
"os"
"github.com/i82orbom/nesgo/pkg/audio/portaudio"
"github.com/i82orbom/nesgo/pkg/gui/glfw"
"github.com/i82orbom/nesgo/pkg/nes"
"github.com/i82orbom/nesgo/pkg/nesgo"
)
func main() {
var (
romPath string
err error
cart *nes.Cartridge
)
if romPath, err = romFromFlags(); err != nil {
log.Fatalf(err.Error())
}
if cart, err = nes.NewCartridge(romPath); err != nil {
log.Fatalf(err.Error())
}
console := nes.NewConsole()
console.InsertCartridge(cart)
console.Reset() // Reset signal to start emulating
window, err := glfw.NewGameWindow(console.TextureProvider())
if err != nil {
log.Fatalf("Could not create gamewindow: %s", err.Error())
}
audio, err := portaudio.NewDevice(console.AudioSource())
if err != nil {
log.Fatalf("Could not initialize audio: %s", err.Error())
}
defer audio.Close()
emulator := nesgo.NewEmulator(window, console)
window.SetKeyCallback(emulator.KeyCallback)
defer window.Destroy()
for !window.ShouldClose() {
emulator.Step()
window.Draw()
}
}
// Returns the path to the rom
func romFromFlags() (string, error) {
if len(os.Args) == 1 {
return "", fmt.Errorf("a path to a rom has to be specified")
}
return os.Args[1], nil
}