-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtraceBuilder.go
136 lines (124 loc) · 3.49 KB
/
traceBuilder.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package izapple2
import (
"fmt"
"strings"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)
type executionTracer interface {
connect(a *Apple2)
inspect()
}
type traceBuilder struct {
name string
description string
executionTracer executionTracer
connectFunc func(a *Apple2)
}
var traceFactory map[string]*traceBuilder
func getTracerFactory() map[string]*traceBuilder {
if traceFactory != nil {
return traceFactory
}
tracerFactory := make(map[string]*traceBuilder)
tracerFactory["mos"] = &traceBuilder{
name: "mos",
description: "Trace MOS calls with Applecorn skipping terminal IO",
executionTracer: newTraceApplecorn(true),
}
tracerFactory["mosfull"] = &traceBuilder{
name: "mosfull",
description: "Trace MOS calls with Applecorn",
executionTracer: newTraceApplecorn(false),
}
tracerFactory["mli"] = &traceBuilder{
name: "mli",
description: "Trace ProDOS MLI calls",
executionTracer: newTraceProDOS(),
}
tracerFactory["ucsd"] = &traceBuilder{
name: "ucsd",
description: "Trace UCSD system calls",
executionTracer: newTracePascal(),
}
tracerFactory["cpu"] = &traceBuilder{
name: "cpu",
description: "Trace CPU execution",
connectFunc: func(a *Apple2) {
a.cpuTrace = true
a.cpu.SetTrace(true)
},
}
tracerFactory["ss"] = &traceBuilder{
name: "ss",
description: "Trace sotfswiches calls",
connectFunc: func(a *Apple2) { a.io.setTrace(true) },
}
tracerFactory["ssreg"] = &traceBuilder{
name: "ssreg",
description: "Trace sotfswiches registrations",
connectFunc: func(a *Apple2) { a.io.setTraceRegistrations(true) },
}
tracerFactory["panicss"] = &traceBuilder{
name: "panicss",
description: "Panic on unimplemented softswitches",
connectFunc: func(a *Apple2) { a.io.setPanicNotImplemented(true) },
}
tracerFactory["cpm65"] = &traceBuilder{
name: "cpm65",
description: "Trace CPM65 BDOS calls skipping terminal IO",
executionTracer: newTraceCpm65(true),
}
tracerFactory["cpm65full"] = &traceBuilder{
name: "cpm65full",
description: "Trace CPM65 BDOS calls",
executionTracer: newTraceCpm65(false),
}
tracerFactory["cpm"] = &traceBuilder{
name: "cpm",
description: "Trace CPM BDOS calls skipping terminal IO",
executionTracer: newTraceCpm(true),
}
tracerFactory["cpm"] = &traceBuilder{
name: "cpm",
description: "Trace CPM BDOS calls",
executionTracer: newTraceCpm(false),
}
tracerFactory["rom"] = &traceBuilder{
name: "rom",
description: "Trace monitor ROM calls",
executionTracer: newTraceMonitor(),
}
return tracerFactory
}
func availableTracers() []string {
names := maps.Keys(getTracerFactory())
slices.Sort(names)
return names
}
func setupTracers(a *Apple2, paramString string) error {
tracerFactory := getTracerFactory()
tracerNames := splitConfigurationString(paramString, ',')
for _, tracer := range tracerNames {
tracer = strings.ToLower(strings.TrimSpace(tracer))
if tracer == "none" {
continue
}
builder, ok := tracerFactory[tracer]
if !ok {
return fmt.Errorf("unknown tracer %s", tracer)
}
if builder.connectFunc != nil {
builder.connectFunc(a)
}
if builder.executionTracer != nil {
a.addTracer(builder.executionTracer)
}
fmt.Printf("Tracer %s enabled\n", builder.name)
}
return nil
}
func (a *Apple2) addTracer(tracer executionTracer) {
tracer.connect(a)
a.tracers = append(a.tracers, tracer)
}