dirkwhoffmann / virtualc64

VirtualC64 is a cycle-accurate C64 emulator for macOS
https://dirkwhoffmann.github.io/virtualc64
Other
356 stars 33 forks source link

Add speed stepper to status bar #807

Closed dirkwhoffmann closed 2 months ago

dirkwhoffmann commented 2 months ago

This is my last planned feature for 5.1...

Background: For a while now, VirtualC64 has supported reducing or increasing the virtual C64's clock frequency. The mode was intended to master challenging games, e.g., by playing a difficult scene with 80% CPU speed. However, the feature was highly impractical because the speed reduction had to be configured via the configurator (red arrow):

Bildschirmfoto 2024-08-31 um 14 00 10

TODO: Allow the user to access the speed adjustment feature via a stepper in the status bar (blue arrow).

dirkwhoffmann commented 2 months ago

This was an easy one (just a few lines of GUI code).

    @IBAction func speedAction(_ sender: NSStepper!) {

        // Round the value to the next number dividable by 5
        var value = Int(round(sender.doubleValue / 5.0)) * 5

        // Make sure the value is in the valid range
        if value < 50 { value = 50 }
        if value > 200 { value = 200 }

        emu?.set(.C64_SPEED_ADJUST, value: value)
    }

    @IBAction func speedResetAction(_ sender:Any!) {

        emu?.set(.C64_SPEED_ADJUST, value: 100)
    }

It seems to work well from a UX point of view. Pressing the small step buttons (blue arrow) increases or decreases the clock frequency by 5. Pressing the level indicator (yellow arrow), which did nothing before, resets the frequency to 100% (aka native speed).

Bildschirmfoto 2024-08-31 um 14 28 32