BEGINNER'S LINE GOING
TO TOWN PROJECT - Pt. II
by Geoff Corry
TO TOWN PROJECT - Pt. II
by Geoff Corry
Now that summer's almost over, we can think about what we are going to do in Atari computing. Maybe join a user's group. But where? In the Greater Vancouver area you can call 942-6115 or in the Lower Fraser Valley, call 530-1793 in Langley. Irwin Electronics toll free Atari support line in Toronto, has a new number; 800-268-1732, replacing the old 268-1784. They will give you a list over the phone of user groups in your area of Canada. In the U.S., call Atari at 1-800-538-8543 or (408) 942-6827, to find out if there is a group in your area. We are responding to a letter, see last issue, requesting an up-to-date list of user groups. I am going to ask for your help on this one: if you belong to a group, either in the U.S. or Canada, please have your representative drop a line to ROM, Box 252, Maple Ridge, B.C.,Canada, V2X 7G 1, or phone (604) 462-9128 or 462-9177, giving the name of the group, where and when you meet, and a contact phone number for other's to reach you. User's groups are a great way for Atarians to meet, to exchange ideas or help solve problems in games, programming, or hardware, and what other's think of new products that are available.
Back to the Project. In Issue 6 of ROM, (I goofed off in the last issue), we were talking about memory. Talking about goofs, there were some small ones in my last article. First, the 2 lines at the bottom of column 1 on page 13, should be under the Memory Map in column 2. On page 14, the list at the top of column 2 came down with a severe case of wraparound. Suffice to say, the smaller numbers refer to the 16K Atari with tape drive. The Display Lists on page 15 got a little silly at the end. Knock off the 0's at the end of each list, and on the second list, move the 6 next to the 15 to make 156. I must remind you that these D/L's were only valid for the GR.0 display, the mode you were in when running MEMADDR. Changing the D/L is done automatically when you change the Graphic mode, or it can be modified by poking new values into the D/L within a program. Bob did this in last issue's Page Flipping article, and so shall we in this month's topic.
To Scroll or not to Scroll, That is the Question.
With apologies to the Bard of Stratford, this question comes up when considering the design of a program. Scrolling uses up a lot of memory, but gives you the advantage of seeing a larger layout or picture without the loss of detail. Programs such as Visicalc for business, word processors, graphic art programs, and some games use this technique. Graphic adventure games, such as Gateway to Apshai or Questron, partly owe their success to the scrolling feature. It is all there, and by using the arrow keys or joystick, you can move anywhere in the layout or picture. Also an element of surprise can be added with this feature (maybe in Visicalc too).
Graphic 0 displays 40 columns by 24 lines for a full screen of 40X24 or 960 possible character positions. The screen memory has to be the same size to accommodate the internal character code for each position. To scroll 4 screens across as well as 4 screens down, will require 16X960 or 15K of screen memory. To have these screens available without reloading is possible only with lots of memory. The higher graphic modes are even more demanding, 4200 bytes 8138 bytes per screen for GR.7 and GR.8 respectively. These last totals include the larger display lists required with these modes. All is not lost however, the memory requirements can be shortened by only scrolling part of the screen. Seven Cities of Gold, Flag Capture, and Ultima 3 all use this option. Another way to beat the memory block is to load in sections of the display as required; Questron, for one, uses this method.
To produce a colorful and pleasing display, we should not consider Basic modes 1 to 6, which give a blocky or less colorful display. The G.T.I.A. modes 9-11 which require as much screen memory as Gr.8, may be considered, but we will leave that to another article.
So you see, a game design and graphic requirements depend on how much memory is available. Those of you with 16K machines have already looked around the stores, but only so many packages,`32K or 48K required' will be printed. Now you know why. The way to still have a good looking game that works with 16K, involves compromises. Partial loading of hi-res. screens means a wait for that 8K of memory to be replaced. Speed of play drops and interest wains if you are sitting there, waiting, especially with a tape drive. Some adventure games and the educational series from Dorsett are on tape and load as you go and you don't notice the delay.
Let's hear from you who are limited by 16K of memory and a 410 or 1010 Program Recorder, and if there is enough response, we will devote a separate column to adapt the Going To Town Project to your capabilities. Send your replies to the address in the first paragraph. Those of you with disk drives have probably upgraded your machines, as a 16K unit with DOS only has 7.5K of free memory. We request that you send your replies in time for the next issue, so speak out!
In my last article, I described the Graphic 0 display list. This list contains all the instructions that the ANTIC chip in your computer requires to process the screen memory data into a pseudo television camera signal suitable for your T.V. or monitor. By altering the D/L, we can get ANTIC to start looking for it's data in various parts of memory. Bob Cockroft's article on page flipping uses the same idea, except he jumps a full screen each time by getting ANTIC to look at a different display list heading the desired picture data. This way he can switch graphic modes for each display. With scrolling, we will be staying in the same mode, but looking at adjacent areas of screen memory, which has been predesigned to be larger than a screenfull. Before we go on let's have a closer look at the display list.
The display list is a work schedule for ANTIC that is loaded into the computer memory when you turn it on. It is the same list that we saw in the last article, producing a blue GR.0 screen. If Basic is installed, we get the characters for `READY' loaded into the bottom of screen memory and relayed by ANTIC to your T.V. at the top left. If you don't have Basic in, DUP.SYS will put the DOS menu into screen memory and on to your T.V. Without either, you will get `MEMO PAD' put into screen memory by the Operating System. Now look at Table 1 for a byte by byte run down of the GR.0 display list.
Now that you have looked at this table, you can see that ANTIC has a fair job to do. But you ain't seen nothing yet, folks, wait till you see a GR7 or GR8 display list. The ANTIC chip lives up to it's name. It does this list 60 times a second, and keeps it up until you change graphic mode, POKE 559,0 to give it a rest, or turn off the computer.
Now this has been pretty heavy going, but if you want more on display lists, see Mapping The Atari, by Ian Chadwick (COMPUTE! Books), Appen.8 on page 171, or Chapter 2 of Advanced Programming Techniques for Your ATARI by Linda Schreiber (TAB Books). Tricky Tutorial # I by Santa Cruz Software is an excellent disk for learning about D/L's. Oh, see Issue 2 of ROM for more on DL 's.
Let's take a break and type in listing #1, a joystick reader using some logic statements to control the value of two variables, X and Y, with the stick position.
TABLE I GR.0 DISPLAY LIST
10 POSITION 2,2:? "READING THE JOYSTICK USING LOGIC"
20 POSITION 4,4:? "THESE TAKE THE FORM OF:-"
30 POSITION 6,6:? "100 ST=STICK(0)"
40 POSITION 6,7:? "110 X=X+(ST=7)-(ST=11)"
50 POSITION 6,8:? "120 Y=Y+(ST=13-(ST=14)"
100 ST=STICK(0):POKE 752,1
130 POSITION 15,10:? "ST=";PEEK(6 32);" "
140 POSITION 10,12:? "X=";X;" "
150 POSITION 20,12:? "Y=";Y;" "
200 GOTO 100
Line 10 may get some of you wondering what the bent arrow means, and how do you type it in. This symbol clears the screen when you run the program, and you type it in by hitting the ESC key and then hold down the CTRL key and hit CLEAR. Some programs will list this symbol as the right brace (wiggely bracket), because most printers will interpret this control code that way. You have probably typed in lines similar to lines 110 and 120 and wondered what's going on here. In this case, the part in brackets is tested for `true' or `false'. If true, then a 1 is substituted, if false then a 0 replaces the bracket sandwtch. In line 100, the ST = STICK(0) is Basic's way of ST = PEEK(632), looking at the number that is in the stick register for each position of the stick. I have done it that way in line 130 to show the values. When the stick is at rest, a 15 is in the register. Move the stick to the right and a 7 now appears. In line 110 this puts a 1 in place of the first bracket sandwich because ST = 7. ST is not 11 so the second sandwich is 0. Boy, all this is making me hungry. Now X= + 1-0. Move the stick to the left and line 110 becomes X = + 0-1, because ST is now 11. This way of writing logic statements is a bit more elegant than:- 110 IF ST = 7 THEN X = X + 1 :IF ST= 11 THEN X = X-1 Line 120 does the same thing to variable Y. A 13 in the register increases the value, and a 14 decreases the value of Y. If we were in a flying saucer looking down at Earth, when we go forward, we expect to see the terrain scroll down. Easy! Just substitute the two register numbers or change the signs like this:
Y = Y + (ST = 14)-(ST = 13) or
Y = Y-(ST =13) + (ST = 14) which does the same thing.
Now if we want to control something on the screen, we can't let it fall of the edge, otherwise we get good old ERROR 141 (cursor out of range), so lets add four more lines to our little logic demo:
180 POSITION X, Y:? "[CTRL-T]"
190 FOR W=1 TO 50:NEXT W
Here the logic statements prevent X from being less than + 1 or greater than 38. Y can only range from 1 to 22. Here the meat in the bracket sandwiches has been changed to develled egg. No, sorry about that. We have used the `(' and `)' symbols instead of the equal sign. The procedure is similar though, if X in line 160 is less than 1, then the first logic sandwich becomes 1 and X is increased by 1, fighting the attempt of the stick moved to the left and line 110 to make X smaller. Likewise with the stick moved to the right and line 110 making X larger, when it gets above 38, logic sandwich #2 becomes 1, multiplies it with -1 to make sure X never gets bigger than 38. Line 170 keeps Y between 1 and 22 in the same manner. A less elegant way of writing line 160 would be:
160 IF X<1 THEN X=1:IF X>38 THEN X=38
Now those for who are having trouble with line 180; this line is intended to put the ball character wherever the values of X and Y take it. Use the same method as in line 10. Don't type [CTRL T], but hold the CTRL key down and hit T. This technique will come in useful, when we move a character across the screen and we want the screen to scroll when we get near the boundaries. Line 190 is a delay loop that slows the ball down a bit; try different values from 10 to 100 and see what happens. Do you know why some of the printing gets wiped out by the ball, and some doesn't? Line 200 will give you the clue.
Let's get back to scrolling. We have spent quite a bit of time on the Display List because modifying it is how you create the scrolling effect. Look at Table 1 again. In the middle you will see bytes 4 and 5. These bytes point to the start of screen memory, which for GR.0 mode, starts at memory location 15424 or 40000, depending how much memory you have. In that location is the character for the top left of the screen. The first 40 memory locations store all the characters for the first line. Next is stor ed the 40 characters for line 2, and on down to the end of line 24. Here comes the important bit! By changing byte 4, we can get ANTIC to start picking up memory anywhere along the memory list. The `2' in byte 3 and bytes 6 to 28 tell ANTIC to display 24 GR.0 lines from where we tell it to start. If our number exceeds 255 in byte 4, we have to carry 1 into byte 5 and subtract 256 from byte 4. conversely, if we reduce byte 4 below 0, we have to subtract 1 from byte 5 and add 256 to byte 4. This is the same o Id game you have been playing for years, except you did it when numbers exceeded or fell below 100. While you are thinking about that, type in listing 2, and we will show you what we mean:-
50 TRAP 40000:TRAP 50
100 HORZ=PDL4+(ST=11)-(ST=7):IF HORZ<>PDL4 THEN 120
110 VERT=PDL4+40*(ST=14)-40*(ST=13):IF VERT<>PDL4 THEN 160
140 POKE DL4,HORZ
150 FOR W=1 TO 50:NEXT W:GOTO 80
180 POKE DL4,VERT
190 FOR W=1 TO 50:NEXT W:GOTO 80
Lets explain what is going on here. Line 40 starts off with a LIST statement. That is a cute way to fill up the screen without having to go to all the trouble of typing in a lot of display code. It's not original, I got the idea from the Tricky Tutorial #2 on Scrolling, an excellent disk to delve into these mysteries. It sure helped me to write this piece. Line 50 also was lifted; without this line you will suddenly get error statements and everything stops. Line 60 finds the start of the D/L in your mac hine and sets variable DL to that number. Ah ha! Line 70 sets up DL4 and DL5 as the location of the 4'th and 5'th bytes. Line 80 sets another variable, PDL4, as the value found when peeking at byte 4. Remember ST in our first listing? Same thing in line 90. Line 100 looks sort of familiar also, except here we are comparing the value in byte 4 with the changed value by wiggling the stick left or right. Line 110 does the same thing but vertically. Hold on, there is something different here. Remember how we s aid screen memory is stored. All 40 bytes for line 1, followed by 40 bytes for line 2, and so on down to line 24. So if we want to look straight up or down (in GR.0), we have to jump back or forth 40 memory locations. Line 110 sets up variable VERT in increments of 40, depending on whether the stick is pushed up or down. Lines 120 and 130 modify bytes 4 and 5 in the display list depending on the value of HORIZ set in line 100. There's that funny math again. Line 140 actually modifies the D/L to move the sc reen left or right in steps of 1 character. This type of movement is known as coarse scrolling as opposed to fine scrolling. When I saved it I called it `D:COARSE` because I knew I would not be misunderstood. I will leave what you call it up to you. The movement is jerky, but we can put up with that with text and some character graphic displays. Questron gets along real fine with this. (A tribute to the midwestern states). Line 150 a short delay loop and then send you back to line 80 to read the stick agai n. Lines 160 to 190 do the same thing in the vertical direction, notice the end of line 110 sent you down there when it detected vertical stick movement.
O.K. Run the program, and hold the stick (plugged into the first jack) to the right. You will see your listing (courtesy of line 40) move in that direction off the screen. The listing will start to appear coming in from the left, but starting at line 50. That's lines 120 and 130 working away, but by this time DL4 has increased by 40, so ANTIC thinks that is the start of screen direction, you will eventually go past the starting point, and line 40 will start to appear one line down from it's original posit ion. Keep scrolling left and a strange looking line starts to appear. That's our display list in disguise. The bytes in Table 1 have been converted to characters. For instance, 112 is the internal code for lower case `p', so you see three of these. I will leave you to sort out the other numbers following the sequence in Table 1.
Moving the stick up or down will bring lines 150 to 180 into play. You will notice that you can only move up or down 6 lines. That is because we only change byte 4, and 40 into 256 allows only 6 moves. I am now going to throw you a curve, with two extra lines to modify the display list to convert the graphic mode. Basic mode 2 is the same as ANTIC mode 7. This trick I borrowed from Linda Schreiber's book listed earlier. Add these two lines:
75 POKE DL+3,PEEK(DL+3)+5
That changes the 2 in the third byte to a 7, which puts the top line in GR. 2 mode. Now lets changes bytes 6 to 28:
85 FOR X=6 TO 28:POKE DL+X,7:NEXT X
BEFORE you run this, SAVE it. Because it is guaranteed to lock up if you scroll too far, and you don't want to type this all in again. The reason that this will cause problems, is that the D/L is not completely set up for GR. 2 mode. We will go into the fine points of various DL modes in our next article. Oh! Before I go, look at Kyle Peacock's series on scrolling in A.N.A.L.O.G. COMPUTING, Issues 13 to 16. And as Kyle says, `See you in the funny papers'.