-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (40 loc) · 810 Bytes
/
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
package main
import (
"embed"
"image"
"log"
"emu/constants"
"emu/emu"
"emu/renderer"
)
//go:embed assets/*
var assets embed.FS
func main() {
c := emu.CPU{}
c.Init()
f, err := assets.Open("assets/roms/PONG2")
if err != nil {
log.Fatalln(err)
}
if err := c.LoadROM(f); err != nil {
log.Fatalln(err)
}
ren := renderer.New()
renderer.SetKeypressFunc(func(key constants.Key) {
c.Keypad[key.ToChip8()] = 1
})
renderer.SetKeyReleaseFunc(func(key constants.Key) {
c.Keypad[key.ToChip8()] = 0
})
renderer.SetImgFunc(func() image.Image {
c.Cycle()
img := image.NewGray(image.Rect(0, 0, constants.VideoWidth, constants.VideoHeight))
for i, _ := range c.Video {
img.Pix[i] = c.Video[i]
}
return img
})
if err := ren.Start(640, 320); err != nil {
log.Fatalln(err)
}
}