Вопрос

How can I find the position of the electron gun (i.e. actively changing pixel/scanline) on the ZX Spectrum?

Different Spectrum models have slightly different timings.

If this is not possible, is there a way of waiting for some form of vertical sync event? (i.e. at the top of the bottom of the screen.)

Это было полезно?

Решение 2

There is a 3 byte frame counter at address 23672.

23672 FRAMES 
3 byte (least significant first), frame counter. Incremented every 20ms.

I'm making the assumption that this is incremented by the 50Hz interrupt. So I'll just poll it in a loop until the least significant byte changes.

Другие советы

The only reliable sync event that you have is the 50Hz interrupt generated at the start of the vertical blank period of the screen refresh.

Basically, you have two options. Vast majority of people would simply wait from the interrupt to the start of the screen. The necessary amount of waiting is different for different models and clones. Most programs relying on such precise timings would only support one or two models. The most advanced programs would try to identify a partucular clone/model and adjust the timings accordingly, but no-one has ever created a truly portable program based on such an approach, due to the complexity of the task and the lack of sufficiently detailed documentation on many models.

The second option is to use the port #FF. It is not a real port, but reading from it returns the value of the byte that ULA is currently fetching from the screen (or 255). Hence, it is possible to symchronize on the interrupt and then poll the port #FF until it returns value different from 255 (assuming your screen contains something different). However, be warned that several common models of Spectrum, e.g. +2A and +3, do not have this behaviour, so once again, this is not an option if you are interested in a good coverage of supported models.

It was a long time ago, but I recall there was a memory refresh counter that updated for each scan line. If you set it to 0 at vblank it will contain the current scanline.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top