NewVCS() expects environment.Label on instantiation

this helps force the environment.Label to be set to something meaningful
This commit is contained in:
JetSetIlly 2024-04-30 18:33:13 +01:00
parent a196b21a93
commit 96ad0797b4
15 changed files with 43 additions and 29 deletions

View file

@ -56,7 +56,7 @@ type Comparison struct {
driver driver
}
const comparisonEnv = environment.Label("comparison")
const comparisonLabel = environment.Label("comparison")
// NewComparison is the preferred method of initialisation for the Comparison type.
func NewComparison(driverVCS *hardware.VCS) (*Comparison, error) {
@ -79,11 +79,10 @@ func NewComparison(driverVCS *hardware.VCS) (*Comparison, error) {
tv.SetFPSCap(true)
// create a new VCS emulation
cmp.VCS, err = hardware.NewVCS(tv, cmp, driverVCS.Env.Prefs)
cmp.VCS, err = hardware.NewVCS(comparisonLabel, tv, cmp, driverVCS.Env.Prefs)
if err != nil {
return nil, fmt.Errorf("comparison: %w", err)
}
cmp.VCS.Env.Label = comparisonEnv
cmp.img = image.NewRGBA(image.Rect(0, 0, specification.ClksScanline, specification.AbsoluteMaxScanlines))
cmp.diffImg = image.NewRGBA(image.Rect(0, 0, specification.ClksScanline, specification.AbsoluteMaxScanlines))

View file

@ -354,11 +354,10 @@ func NewDebugger(opts CommandLineOptions, create CreateUserInterface) (*Debugger
}
// create a new VCS instance
dbg.vcs, err = hardware.NewVCS(tv, dbg, nil)
dbg.vcs, err = hardware.NewVCS(environment.MainEmulation, tv, dbg, nil)
if err != nil {
return nil, fmt.Errorf("debugger: %w", err)
}
dbg.vcs.Env.Label = environment.MainEmulation
// create userinput/controllers handler
dbg.controllers = userinput.NewControllers(dbg.vcs.Input)

View file

@ -22,6 +22,7 @@ import (
"github.com/jetsetilly/gopher2600/cartridgeloader"
"github.com/jetsetilly/gopher2600/disassembly/symbols"
"github.com/jetsetilly/gopher2600/environment"
"github.com/jetsetilly/gopher2600/hardware"
"github.com/jetsetilly/gopher2600/hardware/cpu"
"github.com/jetsetilly/gopher2600/hardware/cpu/execution"
@ -77,6 +78,8 @@ func NewDisassembly(vcs *hardware.VCS) (*Disassembly, *symbols.Symbols, error) {
return dsm, &dsm.Sym, nil
}
const disassemblyLabel = environment.Label("disassembly")
// FromCartridge initialises a new partial emulation and returns a disassembly
// from the supplied cartridge filename. Useful for one-shot disassemblies,
// like the gopher2600 "disasm" mode.
@ -88,7 +91,7 @@ func FromCartridge(cartload cartridgeloader.Loader) (*Disassembly, error) {
return nil, fmt.Errorf("disassembly: %w", err)
}
vcs, err := hardware.NewVCS(tv, nil, nil)
vcs, err := hardware.NewVCS(disassemblyLabel, tv, nil, nil)
if err != nil {
return nil, fmt.Errorf("disassembly: %w", err)
}

View file

@ -25,6 +25,9 @@ import (
// Label is used to name the environment
type Label string
// MainEmulation is the label used for the main emulation
const MainEmulation = Label("main")
// Television interface exposing a minimum amount of the real television
// implementation
type Television interface {
@ -57,8 +60,9 @@ type Environment struct {
//
// The Notify and Preferences can be nil. If prefs is nil then a new instance of
// the system wide preferences will be created.
func NewEnvironment(tv Television, notify notifications.Notify, prefs *preferences.Preferences) (*Environment, error) {
func NewEnvironment(label Label, tv Television, notify notifications.Notify, prefs *preferences.Preferences) (*Environment, error) {
env := &Environment{
Label: label,
TV: tv,
Notifications: notify,
Prefs: prefs,
@ -91,9 +95,6 @@ func (env *Environment) Normalise() {
env.Prefs.PlusROM.SetDefaults()
}
// MainEmulation is the label used for the main emulation
const MainEmulation = Label("main")
// IsEmulation checks the emulation label and returns true if it matches
func (env *Environment) IsEmulation(label Label) bool {
return env.Label == label

View file

@ -78,11 +78,14 @@ type VCS struct {
// NewVCS creates a new VCS and everything associated with the hardware. It is
// used for all aspects of emulation: debugging sessions, and regular play.
//
// The Label argument indicates which environment the emulation will be
// happening in. This affects how log entries are handled, amonst other things
//
// The Television argument should not be nil. The Notify and Preferences
// argument may be nil if required.
func NewVCS(tv *television.Television, notify notifications.Notify, prefs *preferences.Preferences) (*VCS, error) {
func NewVCS(label environment.Label, tv *television.Television, notify notifications.Notify, prefs *preferences.Preferences) (*VCS, error) {
// set up environment
env, err := environment.NewEnvironment(tv, notify, prefs)
env, err := environment.NewEnvironment(label, tv, notify, prefs)
if err != nil {
return nil, err
}

View file

@ -23,6 +23,7 @@ import (
"github.com/jetsetilly/gopher2600/cartridgeloader"
"github.com/jetsetilly/gopher2600/debugger/govern"
"github.com/jetsetilly/gopher2600/environment"
"github.com/jetsetilly/gopher2600/hardware"
"github.com/jetsetilly/gopher2600/hardware/television"
"github.com/jetsetilly/gopher2600/setup"
@ -49,7 +50,7 @@ func Check(output io.Writer, profile Profile, cartload cartridgeloader.Loader, s
tv.SetFPSCap(!uncapped)
// create vcs
vcs, err := hardware.NewVCS(tv, nil, nil)
vcs, err := hardware.NewVCS(environment.MainEmulation, tv, nil, nil)
if err != nil {
return fmt.Errorf("performance: %w", err)
}

View file

@ -31,6 +31,8 @@ type Emulation struct {
vcs *hardware.VCS
}
const previewLabel = environment.Label("preview")
// NewEmulation is the preferred method of initialisation for the Emulation type
func NewEmulation(prefs *preferences.Preferences) (*Emulation, error) {
em := &Emulation{}
@ -43,11 +45,10 @@ func NewEmulation(prefs *preferences.Preferences) (*Emulation, error) {
tv.SetFPSCap(false)
// create a new VCS emulation
em.vcs, err = hardware.NewVCS(tv, nil, prefs)
em.vcs, err = hardware.NewVCS(previewLabel, tv, nil, prefs)
if err != nil {
return nil, fmt.Errorf("preview: %w", err)
}
em.vcs.Env.Label = environment.Label("preview")
return em, nil
}

View file

@ -26,6 +26,7 @@ import (
"github.com/jetsetilly/gopher2600/cartridgeloader"
"github.com/jetsetilly/gopher2600/database"
"github.com/jetsetilly/gopher2600/debugger/govern"
"github.com/jetsetilly/gopher2600/environment"
"github.com/jetsetilly/gopher2600/hardware"
"github.com/jetsetilly/gopher2600/hardware/television"
"github.com/jetsetilly/gopher2600/logger"
@ -136,7 +137,7 @@ func (reg *LogRegression) regress(newRegression bool, output io.Writer, msg stri
tv.SetFPSCap(false)
// create VCS and attach cartridge
vcs, err := hardware.NewVCS(tv, nil, nil)
vcs, err := hardware.NewVCS(environment.MainEmulation, tv, nil, nil)
if err != nil {
return false, "", fmt.Errorf("log: %w", err)
}

View file

@ -28,6 +28,7 @@ import (
"github.com/jetsetilly/gopher2600/database"
"github.com/jetsetilly/gopher2600/debugger/govern"
"github.com/jetsetilly/gopher2600/digest"
"github.com/jetsetilly/gopher2600/environment"
"github.com/jetsetilly/gopher2600/hardware"
"github.com/jetsetilly/gopher2600/hardware/riot/ports"
"github.com/jetsetilly/gopher2600/hardware/television"
@ -123,7 +124,7 @@ func (reg *PlaybackRegression) regress(newRegression bool, output io.Writer, msg
return false, "", fmt.Errorf("playback: %w", err)
}
vcs, err := hardware.NewVCS(tv, nil, nil)
vcs, err := hardware.NewVCS(environment.MainEmulation, tv, nil, nil)
if err != nil {
return false, "", fmt.Errorf("playback: %w", err)
}

View file

@ -28,6 +28,7 @@ import (
"github.com/jetsetilly/gopher2600/database"
"github.com/jetsetilly/gopher2600/debugger/govern"
"github.com/jetsetilly/gopher2600/digest"
"github.com/jetsetilly/gopher2600/environment"
"github.com/jetsetilly/gopher2600/hardware"
"github.com/jetsetilly/gopher2600/hardware/television"
"github.com/jetsetilly/gopher2600/setup"
@ -196,7 +197,7 @@ func (reg *VideoRegression) regress(newRegression bool, output io.Writer, msg st
}
// create VCS and attach cartridge
vcs, err := hardware.NewVCS(tv, nil, nil)
vcs, err := hardware.NewVCS(environment.MainEmulation, tv, nil, nil)
if err != nil {
return false, "", fmt.Errorf("video: %w", err)
}

View file

@ -18,12 +18,15 @@ package rewind
import (
"fmt"
"github.com/jetsetilly/gopher2600/environment"
"github.com/jetsetilly/gopher2600/hardware"
"github.com/jetsetilly/gopher2600/hardware/memory/memorymap"
"github.com/jetsetilly/gopher2600/hardware/television"
"github.com/jetsetilly/gopher2600/hardware/television/coords"
)
const searchLabel = environment.Label("search")
// SearchMemoryWrite runs an emulation between two states looking for the
// instance when the address is written to with the value (valueMask is applied
// to mask specific bits)
@ -51,7 +54,7 @@ func (r *Rewind) SearchMemoryWrite(tgt *State, addr uint16, value uint8, valueMa
}
_ = searchTV.SetFPSCap(false)
searchVCS, err := hardware.NewVCS(searchTV, nil, nil)
searchVCS, err := hardware.NewVCS(searchLabel, searchTV, nil, nil)
if err != nil {
return nil, fmt.Errorf("rewind: search: %w", err)
}
@ -115,7 +118,7 @@ func (r *Rewind) SearchRegisterWrite(tgt *State, reg rune, value uint8, valueMas
}
_ = searchTV.SetFPSCap(false)
searchVCS, err := hardware.NewVCS(searchTV, nil, nil)
searchVCS, err := hardware.NewVCS(searchLabel, searchTV, nil, nil)
if err != nil {
return nil, fmt.Errorf("rewind: search: %w", err)
}

View file

@ -66,6 +66,8 @@ type Anim struct {
monitorInputDelay int
}
var animLabel = environment.Label("thumbnail_anim")
// NewAnim is the preferred method of initialisation for the Anim type
func NewAnim(prefs *preferences.Preferences) (*Anim, error) {
thmb := &Anim{
@ -91,11 +93,10 @@ func NewAnim(prefs *preferences.Preferences) (*Anim, error) {
tv.SetFPSCap(true)
// create a new VCS emulation
thmb.vcs, err = hardware.NewVCS(tv, thmb, prefs)
thmb.vcs, err = hardware.NewVCS(animLabel, tv, thmb, prefs)
if err != nil {
return nil, fmt.Errorf("thumbnailer: %w", err)
}
thmb.vcs.Env.Label = environment.Label("thumbnail_anim")
thmb.img = image.NewRGBA(image.Rect(0, 0, specification.ClksScanline, specification.AbsoluteMaxScanlines))
thmb.Reset()

View file

@ -51,6 +51,8 @@ type Image struct {
Render chan *image.RGBA
}
var imageLabel = environment.Label("image")
// NewImage is the preferred method of initialisation for the Image type
func NewImage(prefs *preferences.Preferences) (*Image, error) {
thmb := &Image{
@ -75,11 +77,10 @@ func NewImage(prefs *preferences.Preferences) (*Image, error) {
tv.SetFPSCap(false)
// create a new VCS emulation
thmb.vcs, err = hardware.NewVCS(tv, nil, prefs)
thmb.vcs, err = hardware.NewVCS(imageLabel, tv, nil, prefs)
if err != nil {
return nil, fmt.Errorf("thumbnailer: %w", err)
}
thmb.vcs.Env.Label = environment.Label("thumbnail")
thmb.img = image.NewRGBA(image.Rect(0, 0, specification.ClksScanline, specification.AbsoluteMaxScanlines))
thmb.Reset()

View file

@ -26,6 +26,8 @@ import (
"github.com/jetsetilly/gopher2600/rewind"
)
const replayLabel = environment.Label("tracker_replay")
// create replay emulation if it has not been created already
func (tr *Tracker) createReplayEmulation(mixer television.AudioMixer) error {
if tr.replayEmulation != nil {
@ -38,18 +40,15 @@ func (tr *Tracker) createReplayEmulation(mixer television.AudioMixer) error {
}
tv.AddAudioMixer(mixer)
tr.replayEmulation, err = hardware.NewVCS(tv, nil, nil)
tr.replayEmulation, err = hardware.NewVCS(replayLabel, tv, nil, nil)
if err != nil {
return fmt.Errorf("tracker: create replay emulation: %w", err)
}
tr.replayEmulation.Env.Label = replayEnv
tr.replayEmulation.TIA.Audio.SetTracker(tr)
return nil
}
const replayEnv = environment.Label("tracker_replay")
// Replay audio from start to end indexes
//
// The onEnd argument is a function to run when the replay has concluded

View file

@ -165,7 +165,7 @@ func (tr *Tracker) AudioTick(env audio.TrackerEnvironment, channel int, reg audi
}
// add entry to list of entries only if we're not in the tracker emulation
if !env.IsEmulation(replayEnv) {
if !env.IsEmulation(replayLabel) {
if tr.emulation.State() != govern.Rewinding {
// find splice point in tracker
splice := len(tr.crit.Entries) - 1