コード例 #1
0
ファイル: emulator_test.go プロジェクト: remogatto/gospeccy
func (t *testSuite) Should_support_Z80_format() {
	filename := "testdata/hello.z80"
	snapshot, err := formats.ReadProgram(filename)
	t.Nil(err)

	errChan := make(chan error)
	speccy.CommandChannel <- spectrum.Cmd_Load{ /*informalFileName*/ filename, snapshot, errChan}
	t.Nil(<-errChan)

	t.True(screenEqualTo("testdata/hello_tape_loaded.sna"))
}
コード例 #2
0
ファイル: functions.go プロジェクト: remogatto/gospeccy
func load(path string) {
	var program interface{}
	program, err := formats.ReadProgram(path)
	if err != nil {
		fmt.Fprintf(stdout, "%s\n", err)
		return
	}

	if _, isTAP := program.(*formats.TAP); isTAP {
		romLoaded := make(chan (<-chan bool))
		speccy.CommandChannel <- spectrum.Cmd_Reset{romLoaded}
		<-(<-romLoaded)
	}

	errChan := make(chan error)
	speccy.CommandChannel <- spectrum.Cmd_Load{path, program, errChan}

	err = <-errChan
	if err != nil {
		fmt.Fprintf(stdout, "%s\n", err)
		return
	}
}
コード例 #3
0
func BenchmarkRender(b *testing.B) {
	b.StopTimer()

	initSDL()

	app := spectrum.NewApplication()

	sdlScreen := &SDLScreen{
		screenChannel:   make(chan *spectrum.DisplayData),
		screenSurface:   &SDLSurface{newSurface()},
		unscaledDisplay: newUnscaledDisplay(),
		updatedRectsCh:  make(chan []sdl.Rect),
		app:             app,
	}

	rom, err := spectrum.ReadROM("testdata/48.rom")
	if err != nil {
		panic(err)
	}

	speccy := spectrum.NewSpectrum48k(app, *rom)
	speccy.CommandChannel <- spectrum.Cmd_AddDisplay{sdlScreen}

	snapshot, err := formats.ReadProgram("testdata/fire.z80")
	if err != nil {
		panic(err)
	}

	errChan := make(chan error)
	speccy.CommandChannel <- spectrum.Cmd_LoadSnapshot{"<fire>", snapshot.(formats.Snapshot), errChan}
	err = <-errChan
	if err != nil {
		panic(err)
	}

	// Capture a number of frames sent from 'speccy' to the rendering backends
	const numFrames = 1000
	var frames [numFrames]*spectrum.DisplayData
	{
		go func() {
			for i := 0; i < numFrames; i++ {
				speccy.CommandChannel <- spectrum.Cmd_RenderFrame{nil}
			}
		}()

		for i := 0; i < numFrames; i++ {
			frames[i] = <-sdlScreen.screenChannel
		}
	}

	// The actual benchmark
	{
		b.StartTimer()

		go func() {
			for {
				<-sdlScreen.updatedRectsCh
				sdlScreen.screenSurface.surface.Flip()
			}
		}()

		for i := 0; i < b.N; i++ {
			sdlScreen.render(frames[i%numFrames])
		}

		b.StopTimer()
	}

	app.RequestExit()
	<-app.HasTerminated

	sdl.Quit()
}