-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (58 loc) · 1.17 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
package main
import (
"bufio"
"os"
"strconv"
core "github.com/DigNZ/goinvaders/core"
"github.com/DigNZ/goinvaders/system"
)
func RetrieveROM(filename string) ([]byte, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
stats, statsErr := file.Stat()
if statsErr != nil {
return nil, statsErr
}
var size int64 = stats.Size()
bytes := make([]byte, size)
bufr := bufio.NewReader(file)
_, err = bufr.Read(bytes)
return bytes, err
}
func main() {
if len(os.Args) < 2 {
panic("Invalid use")
}
filename := os.Args[1]
buffer, err := RetrieveROM(filename)
if err != nil {
panic("Cannot load file")
}
var filesize uint16 = uint16(len(buffer))
var pc uint16 = 0
if len(os.Args) > 2 && os.Args[2] == "dasm" {
for {
if pc >= filesize {
break
}
pc += core.Disassemble8080Op(buffer, pc)
}
} else {
m := core.Machine{}
m.Init("rom/audio")
if len(os.Args) > 2 {
addr, err := strconv.ParseInt(os.Args[2], 16, 16)
if err != nil {
panic(err)
}
m.Cpu.InitWithDataAt(buffer, int(addr))
} else {
m.Cpu.InitWithData(buffer)
}
system := system.System{Machine: &m}
system.Start()
}
}