Here is another scrolling routine with BASIC V2. Two patterns are scrolled at the same time. Programmable characters and multicolor mode have been used.
You can download the program here.
Here is the program in action:
The program contains some tricks for speed optimization.
On line 0 (not seen on the picture) a GOTO 6 instruction is used to temporary skip the scrolling routine. On the following lines, programmable characters are defined and the chessboards are printed on the screen. On line 15, program jumps to line 1. At this point, the scrolling is performed.
The scrolling routine is on the first lines of the program so that it runs fast. In fact, the code at the end of a BASIC program runs slower than the code at the beginning on the program. This trick was quite common with Sinclair BASIC for instance, where subroutines were put at the beginning of the program instead than at the end of it. That way some speed could be gained.
Note the trick dealing with the variable S. S is defined on line 14.
On the screen we have two chessboards. The one on the left makes use of hi-res characters, while the one on the right makes use of multicolor characters. So, bytes on the chessboard to the left can be either 0 or 255, while bytes on the chessboard to the right can be either 85 or 170.
Theoretically, we would have to make two swaps on line 2. One swap for multicolor bytes, and one swap for hi-res bytes. But, this would take too much time. Variable S is used so that only swapping the values of variables F and E is enough. A good look at line 1 will make things clear.
NOTE: line 0 should not be used on BASIC V2 programs, as it cannot be listed alone. But still, keeping line numbers low helps for speed.