Show current speed in Mhz with Ctrl-F5
This commit is contained in:
parent
862b087d4e
commit
4d6b02e4d6
24
apple2.go
24
apple2.go
|
@ -27,11 +27,12 @@ type Apple2 struct {
|
||||||
fastMode bool
|
fastMode bool
|
||||||
fastRequestsCounter int
|
fastRequestsCounter int
|
||||||
profile bool
|
profile bool
|
||||||
|
showSpeed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// CpuClockMhz is the actual Apple II clock speed
|
// CPUClockMhz is the actual Apple II clock speed
|
||||||
CpuClockMhz = 14.318 / 14
|
CPUClockMhz = 14.318 / 14
|
||||||
cpuClockEuroMhz = 14.238 / 14
|
cpuClockEuroMhz = 14.238 / 14
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,6 +49,8 @@ func (a *Apple2) Run() {
|
||||||
// Start the processor
|
// Start the processor
|
||||||
a.cpu.Reset()
|
a.cpu.Reset()
|
||||||
referenceTime := time.Now()
|
referenceTime := time.Now()
|
||||||
|
speedReferenceTime := referenceTime
|
||||||
|
speedReferenceCycles := uint64(0)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Run a 6502 step
|
// Run a 6502 step
|
||||||
|
@ -81,6 +84,17 @@ func (a *Apple2) Run() {
|
||||||
time.Sleep(waitDuration)
|
time.Sleep(waitDuration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.showSpeed && a.cpu.GetCycles()-speedReferenceCycles > 1000000 {
|
||||||
|
// Calculate speed in MHz every million cycles
|
||||||
|
newTime := time.Now()
|
||||||
|
newCycles := a.cpu.GetCycles()
|
||||||
|
elapsedCycles := float64(newCycles - speedReferenceCycles)
|
||||||
|
freq := 1000.0 * elapsedCycles / float64(newTime.Sub(speedReferenceTime).Nanoseconds())
|
||||||
|
fmt.Printf("Freq: %f Mhz\n", freq)
|
||||||
|
speedReferenceTime = newTime
|
||||||
|
speedReferenceCycles = newCycles
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +105,8 @@ func (a *Apple2) setProfile(value bool) {
|
||||||
const (
|
const (
|
||||||
// CommandToggleSpeed toggles cpu speed between full speed and actual Apple II speed
|
// CommandToggleSpeed toggles cpu speed between full speed and actual Apple II speed
|
||||||
CommandToggleSpeed = iota + 1
|
CommandToggleSpeed = iota + 1
|
||||||
|
// CommandShowSpeed toggles printinf the current freq in Mhz
|
||||||
|
CommandShowSpeed
|
||||||
// CommandToggleColor toggles between NTSC color TV and Green phospor monitor
|
// CommandToggleColor toggles between NTSC color TV and Green phospor monitor
|
||||||
CommandToggleColor
|
CommandToggleColor
|
||||||
// CommandSaveState stores the state to file
|
// CommandSaveState stores the state to file
|
||||||
|
@ -117,11 +133,13 @@ func (a *Apple2) executeCommand(command int) {
|
||||||
case CommandToggleSpeed:
|
case CommandToggleSpeed:
|
||||||
if a.cycleDurationNs == 0 {
|
if a.cycleDurationNs == 0 {
|
||||||
fmt.Println("Slow")
|
fmt.Println("Slow")
|
||||||
a.cycleDurationNs = 1000.0 / CpuClockMhz
|
a.cycleDurationNs = 1000.0 / CPUClockMhz
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Fast")
|
fmt.Println("Fast")
|
||||||
a.cycleDurationNs = 0
|
a.cycleDurationNs = 0
|
||||||
}
|
}
|
||||||
|
case CommandShowSpeed:
|
||||||
|
a.showSpeed = !a.showSpeed
|
||||||
case CommandToggleColor:
|
case CommandToggleColor:
|
||||||
a.isColor = !a.isColor
|
a.isColor = !a.isColor
|
||||||
case CommandSaveState:
|
case CommandSaveState:
|
||||||
|
|
|
@ -23,7 +23,6 @@ func newApple2e() *Apple2 {
|
||||||
a.Name = "Apple IIe"
|
a.Name = "Apple IIe"
|
||||||
a.mmu = newMemoryManager(&a)
|
a.mmu = newMemoryManager(&a)
|
||||||
a.cpu = core6502.NewNMOS6502(a.mmu)
|
a.cpu = core6502.NewNMOS6502(a.mmu)
|
||||||
//a.cpu = core6502.NewCMOS65c02(a.mmu)
|
|
||||||
a.io = newIoC0Page(&a)
|
a.io = newIoC0Page(&a)
|
||||||
a.mmu.InitRAMalt()
|
a.mmu.InitRAMalt()
|
||||||
addApple2SoftSwitches(a.io)
|
addApple2SoftSwitches(a.io)
|
||||||
|
|
|
@ -35,7 +35,7 @@ func MainApple() *Apple2 {
|
||||||
"slot for the hard drive if present. -1 for none.")
|
"slot for the hard drive if present. -1 for none.")
|
||||||
cpuClock := flag.Float64(
|
cpuClock := flag.Float64(
|
||||||
"mhz",
|
"mhz",
|
||||||
CpuClockMhz,
|
CPUClockMhz,
|
||||||
"cpu speed in Mhz, use 0 for full speed. Use F5 to toggle.")
|
"cpu speed in Mhz, use 0 for full speed. Use F5 to toggle.")
|
||||||
charRomFile := flag.String(
|
charRomFile := flag.String(
|
||||||
"charRom",
|
"charRom",
|
||||||
|
|
|
@ -93,7 +93,11 @@ func (k *sdlKeyboard) putKey(keyEvent *sdl.KeyboardEvent) {
|
||||||
|
|
||||||
// Control of the emulator
|
// Control of the emulator
|
||||||
case sdl.K_F5:
|
case sdl.K_F5:
|
||||||
k.a.SendCommand(apple2.CommandToggleSpeed)
|
if ctrl {
|
||||||
|
k.a.SendCommand(apple2.CommandShowSpeed)
|
||||||
|
} else {
|
||||||
|
k.a.SendCommand(apple2.CommandToggleSpeed)
|
||||||
|
}
|
||||||
case sdl.K_F6:
|
case sdl.K_F6:
|
||||||
k.a.SendCommand(apple2.CommandToggleColor)
|
k.a.SendCommand(apple2.CommandToggleColor)
|
||||||
case sdl.K_F7:
|
case sdl.K_F7:
|
||||||
|
|
|
@ -18,7 +18,7 @@ const (
|
||||||
samplingHz = 48000
|
samplingHz = 48000
|
||||||
bufferSize = 10000
|
bufferSize = 10000
|
||||||
// bufferSize/samplingHz will be the max delay of the sound
|
// bufferSize/samplingHz will be the max delay of the sound
|
||||||
sampleDurationCycles = 1000000 * apple2.CpuClockMhz / samplingHz
|
sampleDurationCycles = 1000000 * apple2.CPUClockMhz / samplingHz
|
||||||
// each sample on the sound stream is 21.31 cpu cycles approx
|
// each sample on the sound stream is 21.31 cpu cycles approx
|
||||||
maxOutOfSyncMs = 2000
|
maxOutOfSyncMs = 2000
|
||||||
decayLevel = 128
|
decayLevel = 128
|
||||||
|
@ -83,7 +83,7 @@ func SpeakerCallback(userdata unsafe.Pointer, stream *C.Uint8, length C.int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that we are not too long behind
|
// Verify that we are not too long behind
|
||||||
var maxOutOfSyncCyclesFloat = 1000 * apple2.CpuClockMhz * maxOutOfSyncMs
|
var maxOutOfSyncCyclesFloat = 1000 * apple2.CPUClockMhz * maxOutOfSyncMs
|
||||||
var maxOutOfSyncCycles = uint64(maxOutOfSyncCyclesFloat)
|
var maxOutOfSyncCycles = uint64(maxOutOfSyncCyclesFloat)
|
||||||
for _, pc := range s.pendingClicks {
|
for _, pc := range s.pendingClicks {
|
||||||
if pc-s.lastCycle > maxOutOfSyncCycles {
|
if pc-s.lastCycle > maxOutOfSyncCycles {
|
||||||
|
|
|
@ -40,8 +40,7 @@ func addApple2ESoftSwitches(io *ioC0Page) {
|
||||||
}, "BSRREADRAM")
|
}, "BSRREADRAM")
|
||||||
|
|
||||||
// TOOD:
|
// TOOD:
|
||||||
// AKD read on 0x10
|
// VBL or VERTBLANK read on 0x19
|
||||||
// VBL read on 0x19
|
|
||||||
|
|
||||||
//io.softSwitchesData[ioFlagAltChar] = ssOn // Not sure about this.
|
//io.softSwitchesData[ioFlagAltChar] = ssOn // Not sure about this.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue