Machine Code Graphics Loop

See all articles from T-S Horizons n14

A super color graphics program, with some ideas on writing in MC.

Some time ago, I wrote a graphics program called Graphics Loop, which appeared in Sync. (Jul/Aug 82, page 14). Eventually I wrote a machine code version. When I got my TS 2068, I tried to write a similar program using color graphics. The TS 2068 uses a different method of keeping track of the screen display, and the machine code for it was quite long, although I did get a program which worked. A short time ago I found an easier way, with a surprisingly short program. It creates excellent color graphics, and the variations possible are endless. What I did was take a fairly simple program which I found in Howard Sams Timex Sinclair 2068 Intermediate/Advanced Guide and added a few ideas of my own. The original program simply poked the whole screen with a number such as 51, resulting in a screenful of black and white lines. By varying the number between 0 and 255, you can get many variation, but always black and white lines, and one will soon tire of it. The program first loads WL with the starting D file address, 16384. (17,1,64). Following this the BC register is loaded with the total D file count, 6143. Next the instruction LDIR (Load, increase and return) causes a move by HL to the second address, and so on, till the screen is filled.

I had discovered previously that if a program runs over the last d file address, and spills into the Attribute file, any number poked into that file will produce colors on the screen, depending on the number.

So why not extend the total number of addresses so that The Att file is also filled by the program? This will result in automatic Paper and Ink selection for the whole screen. To do this, merely change BC to 1,0,27 instead of I,255,23. That is 256*27, or 6922 addresses. (it takes 3*256, or 768 addresses to fill the Att file). And lo, the entire screen is filled with color. Mostly solid colors, though, and not very exciting, as yet.

Now comes the second idea. What if you added 2 addresses to the DE register. (17,2,64). Will the system crash? It will not, and you have added a step feature to your loop. The system does not erase even if you step more than a single line, more than 32 addresses. So now you have what is basically my original graphics loop program if you can find some way of continually changing the number poked, and also changing the step.

When I first got this to work, I got some good graphics, but found that they always started out with a black screen, and it took several screenfuls before the colors got decent. I then saw that I could start the program with the paper and ink color I wanted, by selecting the starting numbers. (See the Attribute Byte Format, page 252 in the TS manual). Whatever paper color is initially selected, it remains that way for some time, allowing for many variations in color and brightness. You can also alter the range of steps, and will find an endless variety of designs possible. Keep the numbers used less than 128, if the Flash-ing bothers you. If not, use numbers to 255. My program represents only one of the many starting combinations and steps possible.

Here is one version of my program. One could also start by using inputs for starting A and B and then use random numbers to replace lines 70 and 75. Use INT numbers as the computer will not accept decimals.

  5 REM MC GRAPHICS LOOP
6 REM B BUSH DEC 84
10 CLEAR 64999: BORDER 1
15 LET A=54: LET B=1
20 RESTORE 50
25 FOR J=1 TO 14
30 READ Q: POKE 64999+J,Q
35 NEXT J
50 DATA 33,0,64,54,A,17,B,64,1,0,27,237,176,201
60 RANDOMIZE USR 65000
70 LET A=A-1
75 LET B=B+1
80 IF A<-255 THEN LET A=54
90 IF B>32 THEN LET B=1
100 PAUSE 100: GO TO 20

There you have it. What an incredibly short machine code program for all that it does! Try different starting Attributes for A by picking numbers 0 to 255 at random, or select the paper and ink values from the chart. (Page 252 TS 2068 Manual). You probably will want to use a pocket calculator unless you are adept at mental arithmetic.

Needed next is a Basic program to constantly change the variables and then run the machine code over again. My program also uses a slightly different program to poke the machine code into memory. It allows you to always keep track of how many bytes of Machine code are in the Data statement, by checking the J loop. (The ending number always represents the number of bytes.) This can be a help when writing and rewriting the code.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.