diff --git a/apple2.go b/apple2.go index 43a3505..fc6705d 100644 --- a/apple2.go +++ b/apple2.go @@ -25,6 +25,7 @@ type Apple2 struct { isColor bool fastMode bool fastRequestsCounter int + profile bool showSpeed bool } @@ -91,6 +92,15 @@ func (a *Apple2) Run() { } } +func (a *Apple2) setProfiling(value bool) { + a.profile = value +} + +// IsProfiling returns true when profiling +func (a *Apple2) IsProfiling() bool { + return a.profile +} + const ( // CommandToggleSpeed toggles cpu speed between full speed and actual Apple II speed CommandToggleSpeed = iota + 1 diff --git a/apple2main.go b/apple2main.go index 77c8b8c..667788a 100644 --- a/apple2main.go +++ b/apple2main.go @@ -97,6 +97,10 @@ func MainApple() *Apple2 { "model", "2enh", "set base model. Models available 2plus, 2e, 2enh, base64a") + profile := flag.Bool( + "profile", + false, + "generate profile trace to analyse with pprof") flag.Parse() if *wozImage != "" { @@ -170,6 +174,7 @@ func MainApple() *Apple2 { a.cpu.SetTrace(*traceCPU) a.io.setTrace(*traceSS) a.io.setPanicNotImplemented(*panicSS) + a.setProfiling(*profile) // Load ROM if not loaded already if *romFile != "" { diff --git a/apple2sdl/main.go b/apple2sdl/main.go index 447d865..c64d60b 100644 --- a/apple2sdl/main.go +++ b/apple2sdl/main.go @@ -1,7 +1,6 @@ package main import ( - "flag" "unsafe" "github.com/ivanizag/apple2" @@ -10,18 +9,13 @@ import ( ) func main() { - prof := flag.Bool( - "profile", - false, - "generate profile trace to analyse with pprof") - flag.Parse() - if *prof { + a := apple2.MainApple() + if a.IsProfiling() { // See the log with: // go tool pprof --pdf ~/go/bin/apple2sdl /tmp/profile329536248/cpu.pprof > profile.pdf defer profile.Start().Stop() } - a := apple2.MainApple() if a != nil { SDLRun(a) }