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 because 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 added a PAUSE routine. Instead of using the build in version, I wrote my own routine. I did this for a few reasons. The first being the ZX81’s built in routine is bugged. The second being the machine code was going to run faster than the BASIC version and I needed a bit of delay. This allowed me to slow things down.

Lastly 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 from earlier versions I've used. This one waits for the user to release the key if you are breaking from it. This prevents the program from exiting too early. This prevents the ZX81 from reading 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. My 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 it was a colossal waste of time. There are only 21 values needed. 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 then created a small table with those values.

Moving to precomputed values meant I could dump much of what I had done with the variables, using a normal assembly loop instead. This tightened up the code significantly. I could use the loop variable to calculate what position to pull. I did have a slight setback, 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 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