Emulation and sync behaviour of a CRT monitor
Posted: Sat Nov 23, 2019 6:39 pm
Thoughts over how emulation may be improved regarding how it catches sync, what it may display when the signal is incorrect. CUzeBox currently mostly either draws a solid image or nothing at all. In some regards to try to remedy what Stephane (rv6502) mentioned, giving some difficulty designing video modes (that is if the emulator doesn't pick it up, you get a blank screen with no reasonable sync indicators either, making it difficult to figure out what is even wrong).
For this, some insight is necessary on how a CRT operates. I never checked that myself down to the electronic, just making some assumptions by common sense. Please correct if wrong.
What I believe is that the CRT mostly runs at its own pace (60Hz NTSC), when it receives signal, synchronizing its operation to the signal.
The emulator I think already behaves by these principles, the hsync condition causing it a horizontal retrace (advances to next line), and the vsync one a vertical retrace.
However two things are definitely not wholly correct:
For this, some insight is necessary on how a CRT operates. I never checked that myself down to the electronic, just making some assumptions by common sense. Please correct if wrong.
What I believe is that the CRT mostly runs at its own pace (60Hz NTSC), when it receives signal, synchronizing its operation to the signal.
- HSync pulses: Triggers a horizontal retrace (deflects beam to the left), probably simply as long as the sync is active.
- VSync pulse: When it matches, probably triggers a mechanism to do the vertical retrace (deflects beam to the top).
- Otherwise beams runs at a steady pace towards the right (~55 usec across the monitor), and at a steady pace towards the bottom (~14ms from top to bottom).
The emulator I think already behaves by these principles, the hsync condition causing it a horizontal retrace (advances to next line), and the vsync one a vertical retrace.
However two things are definitely not wholly correct:
- The emulator establishes 60Hz by the vertical rate provided by the game. This obviously isn't anything anywhere near the truth, it is fine when the game behaves right producing sync, otherwise not. But as the emulator's architecture is now, due to the audio / video syncing constraint (notably video to the host where the emulator is running, if host is set up to use a 60Hz display), I don't think this is possible to change. Or maybe it could cause the emulator abandoning this precise sync with the host if the timing of the game is off.
- Capturing the VSync pulse is quite crude, and so it often misses for signals which actual TVs may still be able to pick up. This might be possible to be improved (I just didn't find too high need for this as even figuring out cycle counts for a video mode with trial-and-error would rarely cause this to be a problem, at least I didn't find it so with my designs).