-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
58 lines (49 loc) · 1.02 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
package main
import (
"flag"
"log"
"os"
"github.com/hadialqattan/lc3-vm-golang/vm"
termbox "github.com/nsf/termbox-go"
)
func main() {
// init text-based user interface
err := termbox.Init()
if err != nil {
panic(err)
}
defer termbox.Close()
// get the program file path
progPath := getProgramPath()
// init the CPU
log.Println("Booting the LC3-VM")
termbox.Flush()
cpu := vm.NewCPU()
// load the program file
log.Printf("Loading the program: %s", progPath)
cpu.LoadProgramImage(progPath)
// start the input loop
go cpu.KBinputLoop()
// start processing
err = cpu.Run()
if err != nil {
log.Printf("%s", err)
}
log.Println("Terminated!")
}
func getProgramPath() string {
flag.Parse()
args := flag.Args()
if len(args) < 1 {
log.Printf("A program file must be specified")
return ""
}
if info, err := os.Stat(args[0]); err != nil {
log.Printf("No program file found")
return ""
} else if info.IsDir() {
log.Printf("A program should be a file not a directory")
return ""
}
return args[0]
}