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 (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"go6502/core6502"
|
||||
"os"
|
||||
"time"
|
||||
@ -87,20 +88,34 @@ func (a *Apple2) SetKeyboardProvider(kb KeyboardProvider) {
|
||||
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
|
||||
func (a *Apple2) SendCommand(command int) {
|
||||
a.commandChannel <- command
|
||||
}
|
||||
|
||||
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
|
||||
func (a *Apple2) Run(log bool) {
|
||||
// Start the processor
|
||||
a.cpu.Reset()
|
||||
startTime := time.Now()
|
||||
referenceTime := time.Now()
|
||||
for {
|
||||
// Run a 6502 step
|
||||
a.cpu.ExecuteInstruction(log)
|
||||
@ -118,9 +133,14 @@ func (a *Apple2) Run(log bool) {
|
||||
|
||||
if a.cycleDurationNs != 0 {
|
||||
// Wait until next 6502 step has to run
|
||||
clockDuration := time.Since(startTime)
|
||||
simulatedDurationNs := time.Duration(float64(a.cpu.GetCycles()) * a.cycleDurationNs)
|
||||
waitDuration := simulatedDurationNs - clockDuration
|
||||
clockDuration := time.Since(referenceTime)
|
||||
simulatedDuration := time.Duration(float64(a.cpu.GetCycles()) * a.cycleDurationNs)
|
||||
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 {
|
||||
time.Sleep(waitDuration)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ func SDLRun(a *apple2.Apple2) {
|
||||
defer renderer.Destroy()
|
||||
window.SetTitle("Apple2")
|
||||
|
||||
kp := newSDLKeyBoard()
|
||||
kp := newSDLKeyBoard(a)
|
||||
a.SetKeyboardProvider(&kp)
|
||||
go a.Run(false)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package apple2sdl
|
||||
|
||||
import (
|
||||
"go6502/apple2"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
@ -8,11 +9,13 @@ import (
|
||||
|
||||
type sdlKeyboard struct {
|
||||
keyChannel chan uint8
|
||||
a *apple2.Apple2
|
||||
}
|
||||
|
||||
func newSDLKeyBoard() sdlKeyboard {
|
||||
func newSDLKeyBoard(a *apple2.Apple2) sdlKeyboard {
|
||||
var k sdlKeyboard
|
||||
k.keyChannel = make(chan uint8, 100)
|
||||
k.a = a
|
||||
return k
|
||||
}
|
||||
|
||||
@ -84,6 +87,10 @@ func (k *sdlKeyboard) putKey(keyEvent *sdl.KeyboardEvent) {
|
||||
result = 31
|
||||
case sdl.K_DOWN:
|
||||
result = 10
|
||||
|
||||
// Control of the emulator
|
||||
case sdl.K_F5:
|
||||
k.a.SendCommand(apple2.CommandToggleSpeed)
|
||||
}
|
||||
|
||||
// Missing values 91 to 95. Usually control for [\]^_
|
||||
|
Loading…
Reference in New Issue
Block a user