-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (51 loc) · 1.29 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
package main
import (
"time"
"github.com/alexflint/go-arg"
)
// Adjust these according to your game preferences
var SCALING = 15
var FPS = 60
var speed = 10
type args struct {
ROMPATH string `arg:"positional" help:"Path to CHIP8 ROM file."`
SCALING int `default:"15" arg:"-s" help:"Pixel scaling. Adjusts size of display."`
FPS int `default:"60" arg:"-f" help:"FPS to run display at."`
CPUspeed int `default:"10" arg:"-c" help:"Speed of CPU relative to FPS."`
}
// Return version info
func (args) Version() string {
return "chip8 v0.1.0"
}
// Timing vars
var startTime time.Time
var now time.Time
var then time.Time
var elapsed time.Duration
var fpsInterval time.Duration
func main() {
// Use prefs in args
var args args
arg.MustParse(&args)
var ROMPATH = args.ROMPATH
SCALING = args.SCALING
FPS = args.FPS
speed = args.CPUspeed
// Decide how often we render a frame
fpsInterval = time.Duration(time.Millisecond * 1000.0 / time.Duration(FPS))
then = time.Now()
startTime = then
// Load the chip8 font and ROM into memory
loadSprites()
loadROM(ROMPATH)
// Start display and take one step forward (render one frame)
startDisplay()
step()
}
func step() {
elapsed = time.Since(then)
// Wait till it's time to render a frame
if elapsed > fpsInterval {
cycle()
}
}