Skip to content

Commit 44c98ea

Browse files
committed
adding utilities
1 parent c151e71 commit 44c98ea

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

util/roms.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"log"
7+
"os"
8+
"path"
9+
"strings"
10+
11+
"github.com/fogleman/nes/nes"
12+
)
13+
14+
func testRom(path string) (err error) {
15+
defer func() {
16+
if r := recover(); r != nil {
17+
err = r.(error)
18+
}
19+
}()
20+
console, err := nes.NewConsole(path)
21+
if err != nil {
22+
return err
23+
}
24+
console.StepSeconds(3)
25+
return nil
26+
}
27+
28+
func main() {
29+
args := os.Args[1:]
30+
if len(args) != 1 {
31+
log.Fatalln("Usage: go run util/roms.go roms_directory")
32+
}
33+
dir := args[0]
34+
infos, err := ioutil.ReadDir(dir)
35+
if err != nil {
36+
panic(err)
37+
}
38+
for _, info := range infos {
39+
name := info.Name()
40+
if !strings.HasSuffix(name, ".nes") {
41+
continue
42+
}
43+
name = path.Join(dir, name)
44+
err := testRom(name)
45+
if err == nil {
46+
fmt.Println("OK ", name)
47+
} else {
48+
fmt.Println("FAIL", name)
49+
fmt.Println(err)
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)