-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
66 lines (50 loc) · 1.3 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
package main
import (
"flag"
"log"
"os"
"path"
"sort"
"strconv"
"github.com/thatoddmailbox/gbasm/rom"
"github.com/thatoddmailbox/gbasm/utils"
)
func main() {
log.Println("gbasm")
outputFileName := flag.String("output", "out.gb", "The path and name of the output file.")
flag.Parse()
workingDirectory, err := os.Getwd()
if err != nil {
panic(err)
}
ReadConfigFile(workingDirectory)
rom.ValidateParameters()
rom.Initialize()
// output the actual data
Assembler_ParseFile(path.Join(workingDirectory, "main.s"), 0x150, 32*utils.KiB)
rom.Finalize()
// output the actual file
outputFile, err := os.OpenFile(*outputFileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
panic(err)
}
defer outputFile.Close()
_, err = outputFile.Write(rom.Current.Output[:])
if err != nil {
panic(err)
}
log.Println("Constant listing:")
definitionKeys := make([]string, len(rom.Current.Definitions))
i := 0
for name, _ := range rom.Current.Definitions {
definitionKeys[i] = name
i += 1
}
sort.Strings(definitionKeys)
for _, name := range definitionKeys {
value := rom.Current.Definitions[name]
log.Println(" *", name, value, "0x"+strconv.FormatInt(int64(value), 16))
}
log.Println()
log.Printf("Usage: %d out of %d bytes", rom.Current.UsedByteCount, len(rom.Current.Output))
}