-
Notifications
You must be signed in to change notification settings - Fork 0
/
GopherBoy.go
79 lines (60 loc) · 1.35 KB
/
GopherBoy.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
package main
import (
"image"
"image/draw"
"os"
"github.com/kevinbrolly/GopherBoy/gameboy"
"github.com/veandco/go-sdl2/sdl"
)
func main() {
window := NewSDL2Window("Gameboy", 640, 576)
gameboy := gameboy.NewGameboy(window)
rom := os.Args[1]
gameboy.LoadCartridge(rom)
gameboy.Run()
}
type SDL2Window struct {
Name string
Width int
Height int
window *sdl.Window
}
func NewSDL2Window(name string, width, height int) *SDL2Window {
w := &SDL2Window{
Name: name,
Width: width,
Height: height,
}
if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
panic(err)
}
var err error
w.window, err = sdl.CreateWindow(w.Name, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
int32(w.Width), int32(w.Height), sdl.WINDOW_ALLOW_HIGHDPI)
if err != nil {
panic(err)
}
_, err = sdl.CreateRenderer(w.window, -1, 0)
if err != nil {
panic(err)
}
return w
}
func (w *SDL2Window) Quit() {
w.window.Destroy()
sdl.Quit()
}
func (w *SDL2Window) DrawFrame(buffer *image.RGBA) {
renderer, err := w.window.GetRenderer()
if err != nil {
panic(err)
}
surface, err := sdl.CreateRGBSurface(0, 160, 144, 32, 0, 0, 0, 0)
draw.Draw(surface, surface.Bounds(), buffer, image.Point{}, draw.Src)
texture,err := renderer.CreateTextureFromSurface(surface);
if err != nil {
panic(err)
}
renderer.Copy(texture, nil, nil);
renderer.Present();
}