Adding pause capability.
This commit is contained in:
parent
e57a4b21e6
commit
da7bb3ebf7
18
apple2.go
18
apple2.go
|
@ -27,6 +27,7 @@ type Apple2 struct {
|
||||||
fastRequestsCounter int
|
fastRequestsCounter int
|
||||||
profile bool
|
profile bool
|
||||||
showSpeed bool
|
showSpeed bool
|
||||||
|
paused bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -48,7 +49,13 @@ func (a *Apple2) Run() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Run a 6502 step
|
// Run a 6502 step
|
||||||
a.cpu.ExecuteInstruction()
|
if !a.paused {
|
||||||
|
a.cpu.ExecuteInstruction()
|
||||||
|
} else {
|
||||||
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
referenceTime = time.Now()
|
||||||
|
speedReferenceTime = referenceTime
|
||||||
|
}
|
||||||
|
|
||||||
// Execute meta commands
|
// Execute meta commands
|
||||||
commandsPending := true
|
commandsPending := true
|
||||||
|
@ -92,6 +99,11 @@ func (a *Apple2) Run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPaused returns true when emulator is paused
|
||||||
|
func (a *Apple2) IsPaused() bool {
|
||||||
|
return a.paused
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Apple2) setProfiling(value bool) {
|
func (a *Apple2) setProfiling(value bool) {
|
||||||
a.profile = value
|
a.profile = value
|
||||||
}
|
}
|
||||||
|
@ -122,6 +134,8 @@ const (
|
||||||
CommandKill
|
CommandKill
|
||||||
// CommandReset executes a 6502 reset
|
// CommandReset executes a 6502 reset
|
||||||
CommandReset
|
CommandReset
|
||||||
|
// CommandPauseUnpauseEmulator allows the Pause button to freeze the emulator for a coffee break
|
||||||
|
CommandPauseUnpauseEmulator
|
||||||
)
|
)
|
||||||
|
|
||||||
// SendCommand enqueues a command to the emulator thread
|
// SendCommand enqueues a command to the emulator thread
|
||||||
|
@ -164,6 +178,8 @@ func (a *Apple2) executeCommand(command int) {
|
||||||
a.cpu.SetTrace(!a.cpu.GetTrace())
|
a.cpu.SetTrace(!a.cpu.GetTrace())
|
||||||
case CommandReset:
|
case CommandReset:
|
||||||
a.cpu.Reset()
|
a.cpu.Reset()
|
||||||
|
case CommandPauseUnpauseEmulator:
|
||||||
|
a.paused = !a.paused
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ func SDLRun(a *apple2.Apple2) {
|
||||||
|
|
||||||
go a.Run()
|
go a.Run()
|
||||||
|
|
||||||
|
paused := false
|
||||||
running := true
|
running := true
|
||||||
for running {
|
for running {
|
||||||
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
|
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
|
||||||
|
@ -66,6 +67,15 @@ func SDLRun(a *apple2.Apple2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if paused != a.IsPaused() {
|
||||||
|
if a.IsPaused() {
|
||||||
|
window.SetTitle(a.Name + " - PAUSED!")
|
||||||
|
} else {
|
||||||
|
window.SetTitle(a.Name)
|
||||||
|
}
|
||||||
|
paused = a.IsPaused()
|
||||||
|
}
|
||||||
|
|
||||||
img := apple2.Snapshot(a)
|
img := apple2.Snapshot(a)
|
||||||
if img != nil {
|
if img != nil {
|
||||||
surface, err := sdl.CreateRGBSurfaceFrom(unsafe.Pointer(&img.Pix[0]),
|
surface, err := sdl.CreateRGBSurfaceFrom(unsafe.Pointer(&img.Pix[0]),
|
||||||
|
|
|
@ -123,6 +123,8 @@ func (k *sdlKeyboard) putKey(keyEvent *sdl.KeyboardEvent) {
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Saving snapshot")
|
fmt.Println("Saving snapshot")
|
||||||
}
|
}
|
||||||
|
case sdl.K_PAUSE:
|
||||||
|
k.a.SendCommand(apple2.CommandPauseUnpauseEmulator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Missing values 91 to 95. Usually control for [\]^_
|
// Missing values 91 to 95. Usually control for [\]^_
|
||||||
|
|
Loading…
Reference in New Issue