Adding pause capability.

This commit is contained in:
Rob Greene 2020-03-13 21:29:12 -05:00 committed by Iván Izaguirre
parent e57a4b21e6
commit da7bb3ebf7
3 changed files with 29 additions and 1 deletions

View File

@ -27,6 +27,7 @@ type Apple2 struct {
fastRequestsCounter int
profile bool
showSpeed bool
paused bool
}
const (
@ -48,7 +49,13 @@ func (a *Apple2) Run() {
for {
// 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
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) {
a.profile = value
}
@ -122,6 +134,8 @@ const (
CommandKill
// CommandReset executes a 6502 reset
CommandReset
// CommandPauseUnpauseEmulator allows the Pause button to freeze the emulator for a coffee break
CommandPauseUnpauseEmulator
)
// SendCommand enqueues a command to the emulator thread
@ -164,6 +178,8 @@ func (a *Apple2) executeCommand(command int) {
a.cpu.SetTrace(!a.cpu.GetTrace())
case CommandReset:
a.cpu.Reset()
case CommandPauseUnpauseEmulator:
a.paused = !a.paused
}
}

View File

@ -47,6 +47,7 @@ func SDLRun(a *apple2.Apple2) {
go a.Run()
paused := false
running := true
for running {
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)
if img != nil {
surface, err := sdl.CreateRGBSurfaceFrom(unsafe.Pointer(&img.Pix[0]),

View File

@ -123,6 +123,8 @@ func (k *sdlKeyboard) putKey(keyEvent *sdl.KeyboardEvent) {
} else {
fmt.Println("Saving snapshot")
}
case sdl.K_PAUSE:
k.a.SendCommand(apple2.CommandPauseUnpauseEmulator)
}
// Missing values 91 to 95. Usually control for [\]^_