-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·80 lines (64 loc) · 1.84 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
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"os"
"runtime/debug"
"github.com/alexflint/go-arg"
)
var Commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return ""
}()
type args struct {
Rom string `arg:"positional,required" help:"Path to the ROM file"`
Screenshot string `arg:"required,--img" help:"path of in-game screenshot" placeholder:"<SCREENSHOT>"`
Output string `arg:"--output" help:"output file" default:"out.png" placeholder:"<FILE>"`
}
func (args) Description() string {
return "GBGraphics - extract graphics from Gameboy ROM using a screenshot"
}
func (args) Version() string {
return "Version (git commit):" + Commit
}
func main() {
var userInput args
arg.MustParse(&userInput)
outputFilename := userInput.Output
screenshot := userInput.Screenshot
path := userInput.Rom
if path == "" {
fmt.Println("No ROM specified!")
os.Exit(1)
}
romBytes, errReadFile := os.ReadFile(path)
if errReadFile != nil {
fmt.Println(errReadFile)
os.Exit(1)
}
// loop from 0 to 7
var locations [][]string
for i := 0; i < 8; i++ {
locations = append(locations, getTiles(screenshot, romBytes, i))
}
// Create a slice of all the addresses
var allAddresses []string
for _, location := range locations {
allAddresses = append(allAddresses, location...)
}
uniqueAddresses := removeDuplicateString(allAddresses)
for i, address := range uniqueAddresses {
// for every address, get the tile and save it to disk
//tile := romBytes[convertHexToInt32(address) : convertHexToInt32(address)+16]
//fmt.Printf("Address: %s, Tile: %v\n", address, hex.EncodeToString(tile))
if err := processTile(i, address, outputFilename, romBytes, rangeLength, width, bitDepth); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
}