A Super Fast Scrolling Demo on the ZX81


A take on an infinite sine wave in z80 assembly.

Totally divergence from working on Gem Quest. I got around to cleaning up my scrolling demo from last month. In doing so, it made me wonder would it would be like to code it in assembly. The answer is both bland and interesting. Let’s discuss why that is.

# Starting from a base.

The actually coding of ZX Scroll was fairly straight forward. I took the original basic and pasted it into one of my assembly templates. From there, I started cranking away at each line. Within an hour or so, I had the base functionality working.

I wrote my own SCROLL and TAB routines since I could print directly into screen memory. I could have used the ZX81’s library, but given that SCROLL has issues, using my own routines was both faster and more reliable.

Although not in my original program, I did add my version of the PAUSE routine. I did this for two reasons. The first being the machine code was going to run much faster than the BASIC version. This allowed me to slow things down a bit.

Second, I could listen for the SPACE key to be pressed if you wanted to break out of the program. Now I did change this routine a bit to only wait for the user to release the key if you are breaking from it. In this instance, I didn’t want to exit the pause earlier or have it wait for the user to release the key. I did want too that on break still. Otherwise, the ZX81 might read the key twice—once to exit, and again at the prompt.

# Getting a bit loopy.

Originally, I coded the loop similar to what I had in the BASIC program. The only difference was using integers instead of decimals for the value of X. The original intent was to replicate the math. I even found some routines to get started. But as I started to dig into it, I realized that was a colossal waste of time. There are only 21 values. At this point, I decided to precompute the values.

To make my life a little easier, I rewrote the original BASIC program to spit out the values instead of printing the tab. This allowed me to use the ZX81 to compute the values I needed in my code. I created a small table with those values.

Moving to precomputed values meant I could dump much of what I had down with the variables, and just use a normal assembly loop. This tightened up the code significantly. This allowed me to also use the loop variable to calculate what position to pull. I did have a slight setback putting mixing up the least and most significant bytes. Once I corrected my mistake, I was pretty much done!

# Moving fast!

Now, this gets me to the actual output of ZX Scroll. Guess what, it is pretty bland. That is, it looks just like the BASIC version. Can you tell the difference?

ZX Scroll, ZX81 screenshot by Steven Reid, 2022ZX Scroll, ZX81 screenshot by Steven Reid, 2022

Yep, looks pretty much the same. Because of the way I compute the position, I’m going through the numbers in reverse. But you can’t tell that from watching the display. For all intents, it is the same program.

But as bland as the output is, the results are much faster. Even with the slight pause I added, the wave blazes across the screen. It looks really neat, making the bland look interesting. I really like the result.

Now, if only I could use this for more than just a demo. Let me know if you have some ideas.



Comments on this article:

No comments so far.

Write a comment:

Type The Letters You See.
[captcha image][captcha image][captcha image][captcha image][captcha image][captcha image]
not case sensitive