-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
117 lines (106 loc) · 2.09 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
package main
import (
"io/ioutil"
"log"
"time"
termbox "github.com/nsf/termbox-go"
"github.com/scottrangerio/go-chip8/cpu"
)
func main() {
cpu := cpu.NewCPU()
rom, err := ioutil.ReadFile("./roms/pong.rom")
if err != nil {
log.Fatal(err)
}
cpu.LoadRom(rom)
done := make(chan struct{})
q := make(chan termbox.Event)
go func() {
for {
select {
case <-done:
return
default:
q <- termbox.PollEvent()
}
}
}()
kb := make(map[byte]bool)
go func() {
for {
select {
case <-done:
return
default:
if e := <-q; e.Type == termbox.EventKey {
if e.Key == termbox.KeyEsc {
done <- struct{}{}
}
switch e.Ch {
case 'w':
kb[0x1] = !kb[0x1]
go func() {
time.Sleep(150 * time.Millisecond)
kb[0x1] = !kb[0x1]
}()
case 's':
kb[0x4] = !kb[0x4]
go func() {
time.Sleep(150 * time.Millisecond)
kb[0x4] = !kb[0x4]
}()
case 'u':
kb[0xC] = !kb[0xC]
go func() {
time.Sleep(150 * time.Millisecond)
kb[0xC] = !kb[0xC]
}()
case 'j':
kb[0xD] = !kb[0xD]
go func() {
time.Sleep(150 * time.Millisecond)
kb[0xD] = !kb[0xD]
}()
// case '1':
// kb[0x1] = !kb[0x1]
// go func() {
// time.Sleep(150 * time.Millisecond)
// kb[0x1] = !kb[0x1]
// }()
// case '2':
// case '3':
// case '4':
// kb[0xC] = !kb[0xC]
// go func() {
// time.Sleep(150 * time.Millisecond)
// kb[0xC] = !kb[0xC]
// }()
// case 'q':
// kb[0x4] = !kb[0x4]
// go func() {
// time.Sleep(150 * time.Millisecond)
// kb[0x4] = !kb[0x4]
// }()
// case 'w':
// case 'e':
// case 'r':
// kb[0xD] = !kb[0xD]
// go func() {
// time.Sleep(150 * time.Millisecond)
// kb[0xD] = !kb[0xD]
// }()
// case 'a':
// case 's':
// case 'd':
// case 'f':
// case 'z':
// case 'x':
// case 'c':
// case 'v':
}
}
}
}
}()
cpu.Run(done, kb)
}