mirror of
https://github.com/ivanizag/izapple2.git
synced 2024-12-22 09:30:19 +00:00
F5 to toggle fast/slow mode
This commit is contained in:
parent
78ff401ff0
commit
f2c935305b
@ -2,6 +2,7 @@ package apple2
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"go6502/core6502"
|
"go6502/core6502"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@ -87,20 +88,34 @@ func (a *Apple2) SetKeyboardProvider(kb KeyboardProvider) {
|
|||||||
a.io.setKeyboardProvider(kb)
|
a.io.setKeyboardProvider(kb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
// CommandToggleSpeed toggles cpu speed between full speed and actual Apple II speed
|
||||||
|
CommandToggleSpeed = iota + 1
|
||||||
|
)
|
||||||
|
|
||||||
// SendCommand enqueues a command to the emulator thread
|
// SendCommand enqueues a command to the emulator thread
|
||||||
func (a *Apple2) SendCommand(command int) {
|
func (a *Apple2) SendCommand(command int) {
|
||||||
a.commandChannel <- command
|
a.commandChannel <- command
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Apple2) executeCommand(command int) {
|
func (a *Apple2) executeCommand(command int) {
|
||||||
//TODO
|
switch command {
|
||||||
|
case CommandToggleSpeed:
|
||||||
|
if a.cycleDurationNs == 0 {
|
||||||
|
fmt.Println("Slow")
|
||||||
|
a.cycleDurationNs = 1000.0 / CpuClockMhz
|
||||||
|
} else {
|
||||||
|
fmt.Println("Fast")
|
||||||
|
a.cycleDurationNs = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the Apple2 emulation
|
// Run starts the Apple2 emulation
|
||||||
func (a *Apple2) Run(log bool) {
|
func (a *Apple2) Run(log bool) {
|
||||||
// Start the processor
|
// Start the processor
|
||||||
a.cpu.Reset()
|
a.cpu.Reset()
|
||||||
startTime := time.Now()
|
referenceTime := time.Now()
|
||||||
for {
|
for {
|
||||||
// Run a 6502 step
|
// Run a 6502 step
|
||||||
a.cpu.ExecuteInstruction(log)
|
a.cpu.ExecuteInstruction(log)
|
||||||
@ -118,9 +133,14 @@ func (a *Apple2) Run(log bool) {
|
|||||||
|
|
||||||
if a.cycleDurationNs != 0 {
|
if a.cycleDurationNs != 0 {
|
||||||
// Wait until next 6502 step has to run
|
// Wait until next 6502 step has to run
|
||||||
clockDuration := time.Since(startTime)
|
clockDuration := time.Since(referenceTime)
|
||||||
simulatedDurationNs := time.Duration(float64(a.cpu.GetCycles()) * a.cycleDurationNs)
|
simulatedDuration := time.Duration(float64(a.cpu.GetCycles()) * a.cycleDurationNs)
|
||||||
waitDuration := simulatedDurationNs - clockDuration
|
waitDuration := simulatedDuration - clockDuration
|
||||||
|
if waitDuration > 1*time.Second {
|
||||||
|
// We have to wait too long. Let's fast forward
|
||||||
|
referenceTime = referenceTime.Add(-waitDuration)
|
||||||
|
waitDuration = 0
|
||||||
|
}
|
||||||
if waitDuration > 0 {
|
if waitDuration > 0 {
|
||||||
time.Sleep(waitDuration)
|
time.Sleep(waitDuration)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func SDLRun(a *apple2.Apple2) {
|
|||||||
defer renderer.Destroy()
|
defer renderer.Destroy()
|
||||||
window.SetTitle("Apple2")
|
window.SetTitle("Apple2")
|
||||||
|
|
||||||
kp := newSDLKeyBoard()
|
kp := newSDLKeyBoard(a)
|
||||||
a.SetKeyboardProvider(&kp)
|
a.SetKeyboardProvider(&kp)
|
||||||
go a.Run(false)
|
go a.Run(false)
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package apple2sdl
|
package apple2sdl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go6502/apple2"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
@ -8,11 +9,13 @@ import (
|
|||||||
|
|
||||||
type sdlKeyboard struct {
|
type sdlKeyboard struct {
|
||||||
keyChannel chan uint8
|
keyChannel chan uint8
|
||||||
|
a *apple2.Apple2
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSDLKeyBoard() sdlKeyboard {
|
func newSDLKeyBoard(a *apple2.Apple2) sdlKeyboard {
|
||||||
var k sdlKeyboard
|
var k sdlKeyboard
|
||||||
k.keyChannel = make(chan uint8, 100)
|
k.keyChannel = make(chan uint8, 100)
|
||||||
|
k.a = a
|
||||||
return k
|
return k
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +87,10 @@ func (k *sdlKeyboard) putKey(keyEvent *sdl.KeyboardEvent) {
|
|||||||
result = 31
|
result = 31
|
||||||
case sdl.K_DOWN:
|
case sdl.K_DOWN:
|
||||||
result = 10
|
result = 10
|
||||||
|
|
||||||
|
// Control of the emulator
|
||||||
|
case sdl.K_F5:
|
||||||
|
k.a.SendCommand(apple2.CommandToggleSpeed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Missing values 91 to 95. Usually control for [\]^_
|
// Missing values 91 to 95. Usually control for [\]^_
|
||||||
|
Loading…
Reference in New Issue
Block a user