-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (59 loc) · 1.23 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
60
61
62
63
64
65
package main
import (
"flag"
"fmt"
"github.com/gerow/blitzle/frontend"
"github.com/gerow/blitzle/gb"
"github.com/veandco/go-sdl2/sdl"
"log"
"os"
"runtime"
"time"
)
var debug = flag.Bool("debug", false, "enable debugging messages, very slow")
var serial = flag.String("serial", "", "file to write serial output to")
func main() {
// XXX(gerow): Hack for issues in go-sdl2
runtime.LockOSThread()
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s ROM_FILE\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
if len(flag.Args()) != 1 {
flag.Usage()
os.Exit(1)
}
fn := flag.Args()[0]
r, err := gb.LoadROMFromFile(fn)
if err != nil {
log.Fatal(err)
}
fmt.Print(r.Info())
sdl.Init(sdl.INIT_EVERYTHING)
sys := gb.NewSys(r)
sys.Debug = *debug
fe, err := frontend.NewFrontend(sys)
if err != nil {
panic(err)
}
defer fe.Close()
// Create a ticker to periodically pump SDL events.
ticker := time.NewTicker(time.Millisecond * 1)
go func() {
for {
<-ticker.C
sdl.PumpEvents()
}
}()
sys.SetVideoSwapper(fe)
if *serial != "" {
serialOut, err := os.Create(*serial)
if err != nil {
panic(err)
}
defer serialOut.Close()
sys.SetSerialSwapper(&frontend.WriterSerialSwapper{serialOut})
}
sys.Run()
}