pico-zxspectrum icon indicating copy to clipboard operation
pico-zxspectrum copied to clipboard

60 Hz refresh rate

Open fruit-bat opened this issue 1 year ago • 1 comments

** Raised on behalf of https://github.com/javavi **

There are a number of issues that I am currently working on and need your advice.

  • 60Hz interrupt rate is not native to ZX Spectrum which has a 50Hz interrupt rate Because of this, the music is distorted, plays faster, a number of games crash. I've experimented with different approaches to convert interrupts to 50Hz. Music, gameplay restored to normal, but interrupts are out of sync with frame rate. Created a border buffer to display the border correctly but the border effects are jittery, maybe there is no clear stability in the execution time of processor command cycles. A more correct approach for negotiation is a frame buffer into which the input process writes to line emulation frequency of 50Hz, and the output process at VGA 60Hz. This approach is used by the authors of emulators for MURMULATOR and gives a good result.

fruit-bat avatar Jun 04 '23 18:06 fruit-bat

Apologies for the late reply. I've had similar issues with my Pico ZX81 emulator (https://github.com/ikjordan/picozx81) The approach I took was:

  • To run with a 50Hz system interrupt, but keep the display refresh at 60Hz.
  • I use triple memory buffers for the display (easier on memory in black and white!). With double buffering there were rare cases of the emulator code zeroing the swapped buffer whilst it was still to be processed in the scanline buffers
  • When the ZX81 emulator code has generated a full display the buffer is immediately used by the VGA or DVI scanline routines. This ensures minimal lag, but can result in some tearing if the display is rapidly scrolling.
  • I use an AY emulator that stores timestamped AY register changes triggered during the frame and then uses those changes to create a sound frame when the display is swapped into the scanline. This is my attempt to keep sound and display in sync, and also to avoid jitter in the sound due to variations in compute time for the Z80 and ULA emulators.
  • The 50Hz interrupt was derived from the PWM or I2S sound interrupt rate

Incidentally, many thanks to @fruit-bat for inspiring me to start the ZX81 emulator, and for the usb hub code :-)

ikjordan avatar Jul 23 '23 12:07 ikjordan