-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
90 lines (85 loc) · 1.57 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
package main
import (
"github.com/Oicho/GO-Chip8/chip8"
"github.com/Oicho/GO-Chip8/myLogger"
termbox "github.com/nsf/termbox-go"
"fmt"
"os"
"strings"
"time"
)
func main() {
if len(os.Args) == 1 {
fmt.Println("Usage: program filepath")
return
}
myLogger.Init(true)
var mem = chip8.Memory{}
mem.Init()
err := termbox.Init()
var romPath string
var pause bool
if (len(os.Args) == 3) {
pause = true
romPath = os.Args[2]
} else {
pause = false
romPath = os.Args[1]
}
mem.LoadRom(romPath)
if err != nil {
panic(err)
}
defer termbox.Close()
eventQueue := make(chan termbox.Event)
go func() {
for {
eventQueue <- termbox.PollEvent()
}
}()
termbox.Flush()
loop:
for {
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
select {
case ev := <-eventQueue:
if ev.Type == termbox.EventKey && ev.Key == termbox.KeyEsc {
break loop
}
if ev.Type == termbox.EventKey && ev.Key == termbox.KeySpace {
pause = !pause
}
if ev.Type == termbox.EventKey {
str := string(ev.Ch)
if str >= "A" {
str = strings.ToLower(str)
}
switch str {
case "s":
mem.PrintMemoryValues()
mem.Iterate()
termbox.Flush()
break
case "a":
myLogger.InfoPrint("Reloading/pausing emulator")
mem = chip8.Memory{}
mem.Init()
mem.LoadRom(romPath)
pause = true
termbox.Flush()
break
case "q":
myLogger.InfoPrint("Dump")
break
}
}
default:
if !pause {
mem.PrintMemoryValues()
mem.Iterate()
termbox.Flush()
time.Sleep(10 * time.Millisecond)
}
}
}
}