-
Notifications
You must be signed in to change notification settings - Fork 232
/
main.go
129 lines (114 loc) · 2.85 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"bufio"
"encoding/json"
"flag"
"github.com/HFO4/gbc-in-cloud/driver"
"github.com/HFO4/gbc-in-cloud/fyne"
"github.com/HFO4/gbc-in-cloud/gb"
"github.com/HFO4/gbc-in-cloud/static"
"github.com/HFO4/gbc-in-cloud/stream"
"log"
"os"
)
var (
h bool
GUIMode bool
FyneMode bool
StreamServerMode bool
StaticServerMode bool
ConfigPath string
ListenPort int
ROMPath string
SoundOn bool
FPS int
Debug bool
)
func init() {
flag.BoolVar(&h, "h", false, "This help")
flag.BoolVar(&GUIMode, "g", true, "Play specific game in GUI mode")
flag.BoolVar(&FyneMode, "G", false, "Play specific game in Fyne GUI mode")
flag.BoolVar(&StreamServerMode, "s", false, "Start a cloud-gaming server")
flag.BoolVar(&StaticServerMode, "S", false, "Start a static image cloud-gaming server")
flag.BoolVar(&SoundOn, "m", true, "Turn on sound in GUI mode")
flag.BoolVar(&Debug, "d", false, "Use Debugger in GUI mode")
flag.IntVar(&ListenPort, "p", 1989, "Set the `port` for the cloud-gaming server")
flag.IntVar(&FPS, "f", 60, "Set the `FPS` in GUI mode")
flag.StringVar(&ConfigPath, "c", "", "Set the game option list `config` file path")
flag.StringVar(&ROMPath, "r", "", "Set `ROM` file path to be played in GUI mode")
}
func startGUI(screen driver.DisplayDriver, control driver.ControllerDriver) {
core := new(gb.Core)
core.FPS = FPS
core.Clock = 4194304
core.Debug = Debug
core.DisplayDriver = screen
core.Controller = control
core.DrawSignal = make(chan bool)
core.SpeedMultiple = 0
core.ToggleSound = SoundOn
core.Init(ROMPath)
go core.Run()
screen.Run(core.DrawSignal, func() {
core.SaveRAM()
})
}
func runStaticServer() {
server := static.StaticServer{
Port: ListenPort,
GamePath: ROMPath,
}
server.Run()
}
func runServer() {
if ConfigPath == "" {
log.Fatal("[Error] Game list not specified")
}
// Read config file
configFile, err := os.Open(ConfigPath)
defer configFile.Close()
if err != nil {
log.Fatal("[Error] Failed to read game list config file,", err)
}
stats, statsErr := configFile.Stat()
if statsErr != nil {
log.Fatal(statsErr)
}
var size = stats.Size()
gameListStr := make([]byte, size)
bufReader := bufio.NewReader(configFile)
_, err = bufReader.Read(gameListStr)
streamServer := new(stream.StreamServer)
streamServer.Port = ListenPort
var gameList []stream.GameInfo
err = json.Unmarshal(gameListStr, &gameList)
if err != nil {
log.Fatal("Unable to decode game list config file.")
}
streamServer.GameList = gameList
streamServer.Run()
}
func main() {
flag.Parse()
if h {
flag.Usage()
return
}
if StreamServerMode {
runServer()
return
}
if StaticServerMode {
runStaticServer()
return
}
if FyneMode {
driver := new(fyne.LCD)
startGUI(driver, driver)
return
} else if GUIMode {
driver := new(driver.LCD)
startGUI(driver, driver)
return
}
}