Difference between revisions of "CPU Speed control"

From SpecNext official Wiki
Jump to: navigation, search
m
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
''Acceleration'', or ''Turbo mode'', allows the Next to run at faster clock speeds than a standard Spectrum.
+
Next CPU speed is configured by {{NextRegNo|$07}}. User can use NMI menu, or NMI+8 ("F8" on PS/2 keyboard) to further change/toggle current CPU speed. NextBASIC programmers can select CPU speed by "RUN AT x" command.
  
Acceleration is enabled via {{NextRegNo|$06}} and configured via {{NextRegNo|$07}}, or via a user control. There are four potential settings:
+
The standard Spectrum does run the Z80 CPU at 3.5 MHz, Next can be reconfigured to run at 7, 14 and 28 MHz (x2, x4, x8 of standard speed).
  
* Turbo off, or turbo on and $07 set to #00: 3.5 Mhz (standard clock).
+
Enabling the expansion bus (edge connector at the back of the board) will limit the speed to 3.5MHz, to keep signals' timing compatible with classic peripherals (in future it may become possible to enable expansion bus while using higher CPU speed, if Next-compatible peripheral is connected, details to be disclosed upon completion of the feature).
* Turbo on, $07 set to #01: 7 Mhz (x2). (Standard for [[Reference machines|Pentagon]]).
+
 
* Turbo on, $07 set to #10: 14 Mhz. (x4)
+
The running SW may disable NMI and F8 keys, making impossible to change the CPU speed for the user, this is available for Next SW to make sure it will run at designed CPU speed all the time.
* Turbo on, $07 set to #11: 28 Mhz. (x8) Some features, such as [[Layer 2]] drawing, are disabled at this speed.
+
 
 +
The CPU speed will literally speed up the CPU, giving it twice/four/eight times as many timing signals per second, shortening the duration of single machine cycle that many times. So simple Z80 instruction like for example `nop` will still take four cycles, but its duration in seconds will be halved in 7MHz mode. The video signal and maskable-interrupts are driven by video signal timings, which are not modified by CPU speed, the interrupts in VGA0 50Hz mode still happen 50 times per second (but instead of roughly 70 thousand machine cycles per one frame the SW will have x2/x4/x8 machine cycles available for instructions execution).
 +
 
 +
Running SW at CPU speeds it was not originally designed can produce different results, from:
 +
* more smooth and responsive gameplay (for example Stunt Car Racer) when the gameplay ticks at interrupt speed and only graphics rendering is accelerated
 +
* full game including gameplay being accelerated (probably to the unplayable level)
 +
* garbled screen rendering in games which require precise timing to display multi-color effects (Old Tower)
 +
* crash/reset of the SW if it is even more sensitive to the precise machine timing (this could happen also when the machine timing subtly differs from original, like HDMI 50Hz mode not being identical to original VGA0 50Hz timing, but so sensitive software should be very rare)
 +
 
 +
The 28 MHz mode currently induces extra wait state to every memory read, so instruction like `nop` will take five machine cycles instead of four and `ld a,(hl)` will take nine machine cycles instead of seven, making the effective speed of Next about 21-24 MHz in 28 MHz mode. This may be further improved in future Next cores, making the Next SW to run even slightly faster.
 +
 
 +
The "real world" exact speed is further affected by selected {{NextRegNo|$11}}, which does "pitch" the machine as whole, ie. the SW itself is not aware of being sped up by some percent having the same relative timings (amount of machine cycles between two interrupts), but external outputs like sounds, serial communication and video signal is slightly sped up. This is important for Next SW doing serial communication and it should be incorporated into calculating the UART pre-scalar value to get correct baud rate from external point of view, also sampled-music players may want to adjust their playback rate to avoid the "pitch" in other than VGA0 mode.

Latest revision as of 07:29, 21 September 2020

Next CPU speed is configured by CPU Speed Register ($07). User can use NMI menu, or NMI+8 ("F8" on PS/2 keyboard) to further change/toggle current CPU speed. NextBASIC programmers can select CPU speed by "RUN AT x" command.

The standard Spectrum does run the Z80 CPU at 3.5 MHz, Next can be reconfigured to run at 7, 14 and 28 MHz (x2, x4, x8 of standard speed).

Enabling the expansion bus (edge connector at the back of the board) will limit the speed to 3.5MHz, to keep signals' timing compatible with classic peripherals (in future it may become possible to enable expansion bus while using higher CPU speed, if Next-compatible peripheral is connected, details to be disclosed upon completion of the feature).

The running SW may disable NMI and F8 keys, making impossible to change the CPU speed for the user, this is available for Next SW to make sure it will run at designed CPU speed all the time.

The CPU speed will literally speed up the CPU, giving it twice/four/eight times as many timing signals per second, shortening the duration of single machine cycle that many times. So simple Z80 instruction like for example `nop` will still take four cycles, but its duration in seconds will be halved in 7MHz mode. The video signal and maskable-interrupts are driven by video signal timings, which are not modified by CPU speed, the interrupts in VGA0 50Hz mode still happen 50 times per second (but instead of roughly 70 thousand machine cycles per one frame the SW will have x2/x4/x8 machine cycles available for instructions execution).

Running SW at CPU speeds it was not originally designed can produce different results, from:

  • more smooth and responsive gameplay (for example Stunt Car Racer) when the gameplay ticks at interrupt speed and only graphics rendering is accelerated
  • full game including gameplay being accelerated (probably to the unplayable level)
  • garbled screen rendering in games which require precise timing to display multi-color effects (Old Tower)
  • crash/reset of the SW if it is even more sensitive to the precise machine timing (this could happen also when the machine timing subtly differs from original, like HDMI 50Hz mode not being identical to original VGA0 50Hz timing, but so sensitive software should be very rare)

The 28 MHz mode currently induces extra wait state to every memory read, so instruction like `nop` will take five machine cycles instead of four and `ld a,(hl)` will take nine machine cycles instead of seven, making the effective speed of Next about 21-24 MHz in 28 MHz mode. This may be further improved in future Next cores, making the Next SW to run even slightly faster.

The "real world" exact speed is further affected by selected Video Timing Register ($11), which does "pitch" the machine as whole, ie. the SW itself is not aware of being sped up by some percent having the same relative timings (amount of machine cycles between two interrupts), but external outputs like sounds, serial communication and video signal is slightly sped up. This is important for Next SW doing serial communication and it should be incorporated into calculating the UART pre-scalar value to get correct baud rate from external point of view, also sampled-music players may want to adjust their playback rate to avoid the "pitch" in other than VGA0 mode.