I have coded a very simple text scroller that uses most of the concepts explained on this article. I hope this program will be of help to those willing to dust off their knowledge on assembly language.
The program will start by just typing RUN, as I have included a simple BASIC program that calls the machine language code (please see the source).
I tried to code that program in the simpler way that I could, so I didn’t use interrupts. I also tried to mimic a bit this basic program to make things clearer. So, like on that program, the x-coarse scrolling is performed by reading and printing to the screen an entire line of text each time. The coarse scrolling happens because the first character of text to be read keeps being changed.
I also added an Y motion, so that the text moves up and down on the screen while it is also scrolling from right to left. I set up Y movement limits. When the text “hits” one of those limits, it reverts its Y movement. A simple flag on a RAM location is used to decide whether the text should be moved up or down. The EOR instruction is used to flip this flag when Y movement reverting is needed. Exclusive OR is actually used to flip bits (bits previously to zero are set to one, and bits previously to 1 are set to 0). Depending on the value of the flag, some parts of the code are executed, and others are skipped.
When the text line must be moved up or down, the previous line must be deleted. This is accomplished by the subroutine “delete_row”.
Timing is accomplished by using bit 7 of register $d011. Code that modifies characters on the screen must be executed while the raster is out of the viewable area. Please also note that we must wait at some point that the raster is on the viewable area of the screen. That may seem strange, but this is required for the timing. After we have executed the code to modify information on the screen when the raster is on the non-viewable area, then we have to make sure that the raster goes back to the viewable area of the screen before executing the remaining code. Otherwise, the program would go just too fast.
The program makes extensive use of self-modifying code, which I have always found very handy.