-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
76 lines (64 loc) · 1.44 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
// Copyright 2018 Brett Vickers. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"github.com/beevik/go6502/asm"
"github.com/beevik/go6502/host"
)
var (
assemble string
)
func init() {
flag.StringVar(&assemble, "a", "", "assemble file")
flag.CommandLine.Usage = func() {
fmt.Println("Usage: go6502 [script] ..\nOptions:")
flag.PrintDefaults()
}
}
func main() {
flag.Parse()
// Initiate assembly from the command line if requested.
if assemble != "" {
err := asm.AssembleFile(assemble, 0, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to assemble (%v).\n", err)
}
os.Exit(0)
}
// Create the host
h := host.New()
defer h.Cleanup()
// Run commands contained in command-line files.
args := flag.Args()
if len(args) > 0 {
for _, filename := range args {
file, err := os.Open(filename)
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
os.Exit(1)
}
ioState := h.EnableProcessedMode(file, os.Stdout)
h.RunCommands(false)
h.RestoreIoState(ioState)
file.Close()
}
}
// Break on Ctrl-C.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go handleInterrupt(h, c)
// Interactively run commands entered by the user.
h.EnableRawMode()
h.RunCommands(true)
}
func handleInterrupt(h *host.Host, c chan os.Signal) {
for {
<-c
h.Break()
}
}