-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (42 loc) · 1.09 KB
/
main.go
File metadata and controls
52 lines (42 loc) · 1.09 KB
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
package main
import (
"flag"
"fmt"
"log/slog"
"os"
"path/filepath"
"strings"
"github.com/azraelsec/chip-8/pkg/emulator"
ebiten "github.com/hajimehoshi/ebiten/v2"
)
func main() {
rom := flag.String("rom-path", "", "path to the rom you want to emulate")
cyclesPerUpdate := flag.Int("cycles-per-update", 10, "number of cycles to run per update")
volume := flag.Float64("volume", 0.7, "audio volume (0.0 to 1.0)")
flag.Parse()
if *rom == "" {
slog.Error("-rom-path is required")
os.Exit(1)
}
if *cyclesPerUpdate < 1 {
slog.Error("-cycles-per-update must be greater than 0")
os.Exit(1)
}
if *volume < 0.0 || *volume > 1.0 {
slog.Error("-volume must be between 0.0 and 1.0")
os.Exit(1)
}
romData, err := os.ReadFile(*rom)
if err != nil {
slog.Error(err.Error())
os.Exit(1)
}
romName := strings.TrimSuffix(filepath.Base(*rom), filepath.Ext(*rom))
ebiten.SetWindowSize(640, 320)
ebiten.SetWindowTitle(fmt.Sprintf("Chip8 - %s", romName))
e := emulator.New(romData, *cyclesPerUpdate, *volume)
if err := ebiten.RunGame(e); err != nil {
slog.Error(err.Error())
os.Exit(1)
}
}