From 989b2fac2425487462a69747691c813c35e2a9bb Mon Sep 17 00:00:00 2001 From: andys Date: Thu, 2 Nov 2023 22:02:03 +0000 Subject: [PATCH] Add ability to load ROM from command line --- chip8.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/chip8.go b/chip8.go index 47b4ec0..c9e3768 100644 --- a/chip8.go +++ b/chip8.go @@ -2,10 +2,20 @@ package main import ( "chip8" + "flag" "io/ioutil" + "os" ) func main() { + var romFile = flag.String("rom", "", "The filename of the Chip8 ROM you want to execute") + flag.Parse() + + if *romFile == "" { + println("Please specify a ROM to load") + os.Exit(1) + } + chip8Display := Chip8Display{} defer chip8Display.shutdown() chip8Display.startUp() @@ -14,7 +24,7 @@ func main() { vm := chip8.NewVM(&chip8Display, random) - dat, _ := ioutil.ReadFile("test_opcode.ch8") + dat, _ := ioutil.ReadFile(*romFile) //check(err) vm.Load(dat)