Skip to content

Commit

Permalink
cpu: remove obsolete trace code
Browse files Browse the repository at this point in the history
  • Loading branch information
cornelk committed Jan 20, 2024
1 parent 5837990 commit 18b122f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
7 changes: 5 additions & 2 deletions pkg/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cpu

import (
"io"
"os"
"sync"

"github.com/retroenv/nesgoemu/pkg/bus"
Expand Down Expand Up @@ -44,7 +45,6 @@ type CPU struct {
tracing TracingMode
tracingTarget io.Writer
TraceStep TraceStep
lastFunction string
}

// New creates a new CPU.
Expand All @@ -66,8 +66,11 @@ func New(bus *bus.Bus, nmiHandler, irqHandler *func()) *CPU {
return c
}

// SetTracing sets the CPU tracing options.
// SetTracing sets the CPU tracing options, if target is nil it will default to os.Stdout.
func (c *CPU) SetTracing(mode TracingMode, target io.Writer) {
if target == nil {
target = os.Stdout
}
c.tracing = mode
c.tracingTarget = target
}
Expand Down
17 changes: 6 additions & 11 deletions pkg/cpu/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ import (

// execute branch jump if the branching op result is true.
func (c *CPU) branch(branchTo bool, param any) {
// disable trace while calling the go mode branch code
// TODO refactor to avoid this
trace := c.tracing
c.tracing = NoTracing

if branchTo {
addr := param.(Absolute)

c.PC = uint16(addr)
c.cycles++
if !branchTo {
return
}

c.tracing = trace
addr := param.(Absolute)

c.PC = uint16(addr)
c.cycles++
}

// hasAccumulatorParam returns whether the passed or missing parameter
Expand Down
17 changes: 2 additions & 15 deletions pkg/cpu/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package cpu

import (
"fmt"
"reflect"
"runtime"
"strings"

. "github.com/retroenv/retrogolib/addressing"
Expand All @@ -14,7 +12,7 @@ import (
// TracingMode defines a tracing mode.
type TracingMode int

// tracing modes, either disabled, in Go mode or emulator mode.
// tracing modes, either disabled or in emulator mode.
const (
NoTracing TracingMode = iota
EmulatorTracing
Expand Down Expand Up @@ -52,11 +50,7 @@ func (t TraceStep) print(cpu *CPU) {
s := fmt.Sprintf("%04X %s %s %s %s%-31s A:%02X X:%02X Y:%02X P:%02X SP:%02X CYC:%d\n",
t.PC, opcodes[0], opcodes[1], opcodes[2], unofficial, t.Instruction,
cpu.A, cpu.X, cpu.Y, cpu.GetFlags(), cpu.SP, cpu.cycles)
if cpu.tracingTarget != nil {
_, _ = fmt.Fprint(cpu.tracingTarget, s)
} else {
fmt.Print(s)
}
_, _ = fmt.Fprint(cpu.tracingTarget, s)
}

// Trace logs the trace information of the passed instruction and its parameters.
Expand All @@ -72,13 +66,6 @@ func (c *CPU) trace(instruction *cpu.Instruction, params ...any) {
c.TraceStep.print(c)
}

// SetResetHandlerTraceInfo sets info about the reset handler function for Go mode execution.
func (c *CPU) SetResetHandlerTraceInfo(resetHandlerParam func()) {
p := reflect.ValueOf(resetHandlerParam).Pointer()
funcDetails := runtime.FuncForPC(p)
c.lastFunction = funcDetails.Name()
}

func shouldOutputMemoryContent(address uint16) bool {
switch {
case address < 0x0800:
Expand Down

0 comments on commit 18b122f

Please sign in to comment.