-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
72 lines (57 loc) · 1.43 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
66
67
68
69
70
71
72
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/snes-emu/gose/render"
"github.com/snes-emu/gose/log"
"github.com/snes-emu/gose/config"
"github.com/snes-emu/gose/core"
"github.com/snes-emu/gose/debugger"
"go.uber.org/zap"
)
// VERSION set at compile time
var VERSION string
func main() {
config.Init()
log.Init()
log.Info("starting gose", zap.String("version", VERSION))
if len(flag.Args()) == 0 {
fmt.Fprintln(os.Stderr, "Please provide a rom file to open")
os.Exit(1)
}
if config.ImagePath() != "" {
renderer := render.NewImageRenderer(core.WIDTH, core.HEIGHT, config.ImagePath())
emu := core.New(renderer, true)
emu.ReadROM(flag.Arg(0))
emu.Start()
emu.StepAndWait(config.NCycles())
emu.Stop()
renderer.Stop() // TODO: move into emu.Stop()
} else {
renderer, err := render.NewRenderer(int(core.WIDTH), int(core.HEIGHT))
if err != nil {
log.Fatal("failed to init renderer", zap.Error(err))
}
emu := core.New(renderer, config.DebugServer())
emu.ReadROM(flag.Arg(0))
if config.DebugServer() {
log.Info("starting the debugger")
db := debugger.New(emu, fmt.Sprintf("localhost:%d", config.DebugPort()))
db.Start()
}
emu.Start()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
emu.Stop()
log.Info("emulation stopped")
os.Exit(0)
}()
//should be run on the main thread
renderer.Run()
}
}