-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (50 loc) · 1.75 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
59
package main
import (
"flag"
"fmt"
"os"
gones "github.com/tiagolobocastro/gones/lib"
"github.com/tiagolobocastro/gones/lib/speakers"
)
const defaultAudioLibrary = speakers.Beep
func validateINesPath(romPath string) error {
stat, err := os.Stat(romPath)
if err != nil {
return fmt.Errorf("iNes Rom file path (\"%v\") does not exist or is not valid", romPath)
} else if stat.IsDir() {
return fmt.Errorf("iNes Rom file path (\"%v\") points to a directory", romPath)
}
return nil
}
func main() {
romPath := ""
positionalArgs := 0
if len(os.Args) > 1 && os.Args[1][0] != '-' {
romPath = os.Args[1]
positionalArgs++
}
flag.StringVar(&romPath, "rom", romPath, "path to the iNes Rom file to run")
audioLib := flag.String("audio", defaultAudioLibrary, "beep, portaudio or nil")
logAudio := flag.Bool("logaudio", false, "log audio sampling average every second (debug only)")
verbose := flag.Bool("verbose", false, "verbose logs (debug only)")
freeRun := flag.Bool("freerun", false, "run as fast as possible with double buffered sync (debug only)")
spriteLimit := flag.Bool("spritelimit", false, "limit number of sprites per scanline to 8 (true to the NES)")
if err := flag.CommandLine.Parse(os.Args[positionalArgs+1:]); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Failed to parse the commandline parameters, err=%v\n", err)
return
}
if err := validateINesPath(romPath); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Rom image path is not valid? err=%v\n", err)
return
}
fmt.Printf("Starting GoNes with iNes Rom file: %s\n", romPath)
nes := gones.NewNES(
gones.CartPath(romPath),
gones.Verbose(*verbose),
gones.FreeRun(*freeRun),
gones.AudioLibrary(*audioLib),
gones.AudioLogging(*logAudio),
gones.SpriteLimit(*spriteLimit),
)
nes.Run()
}