Dale’s Atari 800 Games › Stan Ockers

Time Trial

By Stan Ockers, in the ACE newsletter of December 1981.

Play Time Trial

Stan’s write-up

How about two programs running at the same time? As an example of this I submit a program I call ‘Time Trial’. A machine language program moves the roadway while a basic program creates sounds, checks collisions etc. The machine language program runs during the time that the electron beam in the TV tube is returning from bottom to the top of the screen, the so-called ‘vertical blank’ period. Basic is normally interrupted during this time for the operating system to do certain updating chores. There is also plenty of time for our scrolling program. It is a perfect time for updating anything to do with the screen because the screen is blanked at this time and the updating won’t cause flickering.

The key to scrolling is the display list and in particular the LMS instruction (Load Memory Scan). The display list is a set of instructions for ANTIC, the special video microprocessor which controls the screen. The display list for GR. 18 is given in table 1. The LMS instruction points to the area in memory where screen data resides. The instructions following are single byte because they just continue picking up data where the last line left off.

The revised display list appears in table 2. Each line of characters in the scrolled region has its own LMS instruction. This allows using portions of the same data for many lines (the starting position is displaced). A display list similar to table 1 with scrolling activated could be used but the data would have to be a continuous chunk of memory. 512 roadway lines would require 512 x 20 = 10,240 bytes of data. A lot more variation and detail would be available but that’s a lot of memory (and a lot of typing)!

In lines 150-195 a new character set is constructed to get just two new characters. The whole character set is moved down into RAM. Doing this in Basic takes over 20 seconds so I’ve written a machine language routine to do it (stored in M$), Calling is by A=USR(ADR(M$), ADDR, ADDR2) for moving 1K from ADDR1 to ADDR2 (decimal #’s). The machine language routine takes less than a couple of seconds. RAMTOP is moved down 5 pages to make room for the character set. (Basic thinks RAM stops 5 pages lower). The extra page is because Basic will actually alter a few bytes beyond RAMTOP if they exist (normally they don’t),

After creating the new display list and poking in data for the roadway, our vertical blank routine is poked into page 6. The routine communicates with Basic through a set of locations listed in table 3. The routine does a number of things. The number indicating how much of a character is scrolled changes from 16 down to 0 (1552 and also hex D405 in the OS).

It is then reset to 16, each LMS pointer is shifted down into the next LMS pointer (moving all lines down screen), and the LMS pointer for the top line is set by refering to the next roadway data byte. If the byte is 255, the pointer is set by returning back to the beginning of the roadway data. Notice that is necessary to use machine language to insert or remove our VBI routine. In Basic an interrupt could occur between changing the low and high bytes of a pointer resulting in a disasterous jump. The OS provides a routine at $E45C to solve this problem,

How rapidly scrolling takes place would normally be determined by the byte at 1546 (COUNT) which resets a counter (CNTDN) at 1547. This turned out to be much too slow so a one was placed in COUNT and some scrolling takes place everytime through (1/60 th sec.) To go even faster, some positions between 16 and 0 are skipped. The number of positions skipped is found by shifting the byte at 1548 right until a 0 bit is found. The number in 1548 then controls the speed (poked in at line 560 in the Basic program).

The car is a PM graphics player set up in lines 400-430. The seven additional pages down from RAMTOP puts the start of PM area on a 1K boundary as it must be. Even though horizontal movement requires only a poke of one location, it proved to be slow and jerky in Basic. The solution was to put this function into the vertical blank routine where it is updated every 60th of a second. I am becoming increasingly discouraged with player missile movement in Basic.

The point of the program is to move the car around the track of 5 laps as fast as possible. The fire button (joystick PLYR 1) is the accelerator, down to speed up, up to slow down, Going off track will slow you down in a hurry. The program could be easily changed to have you going through a field of meteors with a spaceship or whatever,

—Stan Ockers

The start of Stan Ockers' Time Trial article in ACE Volume 1
As printed: page 8 of the December 1981 issue.

The program

The listing, “TIME TRIAL by Stan Ockers”, is on pages 9, 10, 12 of the issue. The game page runs it line by line in an emulated Atari 800, just as typed in.

Where this copy came from: Typed-in copy from Atarimania (Time_Trial.zip), proofread against the December 1981 issue in ACE Volume 1 (pages 139-143). The program matched, but the copy had dropped Stan's comments (about 35 REM lines, starting with his note that all of them can be deleted); they are restored from the scan.

Show the listing
5 REM **********************
10 REM **    TIME TRIAL    **
20 REM ** S. OCKERS  11/81 **
30 REM **********************
40 REM ** ALL REMS CAN BE DELETED **
100 DIM M$(32),S$(8),P$(8),T(5):OPEN #1,4,0,"K:"
150 REM ** NEW CHARACTER SET **
155 REM ** ML routine for moving 1K **
160 FOR I=1 TO 32:READ A:M$(I)=CHR$(A):NEXT I
170 DATA 104,104,133,204,104,133,203,104,133,206,104,133,205,162,4,160,0,177,203,145,205,136,208,249,230,204
175 DATA 230,206,202,208,240,96
177 REM ** Lower RAMTOP and move character set **
180 POKE 106,PEEK(106)-5:GRAPHICS O:CS=(PEEK(106)+1)*256:A=USR(ADR(M$),57344,CS)
185 REM ** Change a couple of characters ($ and %) **
190 FOR I=CS+32 TO CS+47:READ A:POKE I,A:NEXT I
195 DATA 36,109,73,146,146,73,109,36,36,182,146,73,73,146,182,36
200 REM ** NEW DISPLAY LIST **
210 GRAPHICS 18:DL=PEEK(560)+256*PEEK(561):A=PEEK(DL+4)+256*PEEK(DL+5):A=A+22:B=INT(A/256):C=A-B*256
220 POKE DL+4,C:POKE 88,C:POKE DL+5,B:POKE 89,B:POKE DL+6,6:POKE DL+7,6
230 FOR I=17 TO 19:POKE DL+I+21,PEEK(DL+I):NEXT I
240 FOR I=DL+8 TO DL+35 STEP 3:POKE I,103:POKE I+1,146:POKE I+2,6:NEXT I:POKE DL+35,71
245 POKE 756,CS/256:POKE 708,200:POSITION 4,0:? #6;"INITIALIZING"
250 REM ** DATA FOR ROADWAY **
252 REM ** Try making your own **
255 RESTORE 265
260 RW=(PEEK(106)-10)*256:FOR I=RW TO RW+512:READ A:A=A+141:POKE I,A:NEXT I
265 DATA 25,5,5,5,5,5,5,5,5,5,4,4,4,4,3,3,3,3,2,2,2,2,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
267 DATA 1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8
270 DATA 8,8,8,8,9,9,9,9,10,10,10,10,9,9,9,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,9,9,9,8,8,8,7,7,7,6,6,6,5
275 DATA 5,6,6,7,7,8,8,9,9,8,8,8,8,8,7,7,7,7,7,6,6,6,6,6,5,5,5,5,4,4,4,4,3,3,2,2,1,1,0,0,1,1,2,2,3,3,4,4,5
277 DATA 5,6,6,7,7,8,8,9,9,8,7,6,5,4,3,2,1,0,0,0,1,2,3,4,5,6,7,8,9,9,9,9,9,9,9,8,7,6,5,4,3,2,1,1,1,0,0,0,0
280 DATA 0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9
282 DATA 8,8,8,7,7,7,6,6,5,5,4,4,3,3,2,2,1,2,1,1,2,2,1,1,1,3,3,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1,1,1,1,1,1,1,1
285 DATA 2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,7,7,7,7,7,7,8,8,8,8,7,7,6,6,5
287 DATA 5,5,5,6,6,6,7,8,9,8,7,6,5,5,5,5,5,4,3,2,1,1,1,2,3,4,5,6,7,8,9,9,8,7,6,5,4,3,2,1,2,3,4,5,6,7,8,9,8
288 DATA 7,7,6,6,5,5,4,4,3,3,2,2,1,1,2,2,3,3,3,4,4,4,5,5,5,6,6,7,7,8,8,9,9,8,8,8,8,7,7,7,6,6,6,5,5,5,5,5,5
290 DATA 5,5,5,4,3,2,1,2,3,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,114
300 REM ** PAGE SIX POKES **
310 RESTORE 315:FOR I=1536 TO 1731:READ A:POKE I,A:NEXT I
314 REM ** Change VBI vector **
315 DATA 104,160,17,162,6,169,7,76,92,228
316 REM ** Init. data for VBI routine **
317 DATA 1,1,0,0,0,0,0
318 REM ** VERT BLANK ROUTINE ** Determine scroll value **
319 DATA 206,11,6,208,94,173,10,6,141,11,6
320 DATA 173,12,6,206,16,6,74,176,250,173,16,6,141,5,212,16,71
321 REM ** Move lines down **
322 DATA 169,16,141,16,6,173,48,2,133,203
325 DATA 56,233,3,133,205,173,49,2,133,204,133,206,160,37,177,205,145,203,136,177,205,145,203,136,136
330 DATA 192,10,208,241
331 REM ** Add a new line **
332 DATA 230,207,208,2,230,208,162,0,161,207,201,255,208,15,173,14,6,133,207
333 DATA 173,15,6,133,208,161,207,238,13,6,136,145,203
335 DATA 173,0,211,72,41,8,208,2,230,209,104,41,4,208,2,198,209,165,209,141,0,208,76,98,228
338 REM ** Screen roadway data **
340 DATA 4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4
342 REM ** Remove our VBI routine **
343 DATA 104,160,98,162,228,169,7,76,92,228
344 REM ** POS. AT BEG. OF RW DATA **
345 POKE 1550,0:POKE 1551,RW/256:POKE 207,0:POKE 208,RW/256
350 REM ** ROADWAY WIDTH **
358 POSITION 0,0:? #6;"                    "
360 POSITION 0,1:? #6;"ROAD WIDTH (1)NARROW TO (3) WIDE        ":GET #1,A:W=A-48:IF W<1 OR W>3 THEN 360
370 FOR I=1690-W TO 1693+W:POKE I,0:NEXT I:FOR I=1710-W TO 1713+W:POKE I,222:NEXT I
400 REM ** PM GRAPHICS **
410 A=PEEK(106)-7:POKE 54279,A:PM=256*A:POKE 559,46:POKE 53277,3:X=120:POKE 53248,X:POKE 209,X:POKE 53256,1
415 RESTORE 430
420 FOR I=PM+512 TO PM+640:POKE I,0:NEXT I:POKE 704,56:Y=90:FOR I=PM+512+Y TO PM+528+Y:READ A:POKE I,A:NEXT I
430 DATA 153,153,255,153,153,24,24,60,36,36,36,36,165,165,231,189,153
440 FOR I=1 TO 8:READ A:P$(I,I)=CHR$(A):NEXT I
450 DATA 106,96,85,76,63,51,40,22
490 POSITION 0,1:? #6;"PRESS FIRE BUTTON   WHEN READY TO START"
492 IF STRIG(0)=1 THEN 492
495 A=USR(1536)
500 REM
502 POSITION 0,1:? #6;"TOTAL       LAP   ":POSITION 0,2:? #6;" AVG. SPEED AVG. LAP"
504 REM ** RESET CLOCK - INIT. VAR. **
505 Z=0:POKE 18,Z:POKE 19,Z:POKE 20,Z:LAP=0:T(0)=0:DIST=220000:DIS=12
507 REM ** SPEED BYTES STRING **
510 RESTORE 520:FOR I=1 TO 8:READ A:S$(I)=CHR$(A):NEXT I:N=1:TT=30
520 DATA 0,1,3,7,15,31,63,127
522 REM ** CK TRIGGER - CLEAR COLL. REG. **
525 T=STRIG(0):POKE 53278,0
530 REM ** TT IS ACCELERATOR RESPONSE COUNTER **
531 TT=TT-1:IF TT>0 THEN 560
532 TT=30
533 IF T=1 AND N=1 THEN 560
536 IF T=0 AND N=8 THEN 560
540 IF T=1 THEN N=N-1:IF N=0 THEN N=8
550 IF T=0 THEN N=N+1:IF N=9 THEN N=1
560 POKE 1548,ASC(S$(N,N))
570 L=PEEK(1549):IF L>LAP THEN GOSUB 2010
572 IF L=5 THEN 610
573 REM ** COLLISION DETECTION **
575 IF PEEK(53252)=1 THEN GOSUB 1010
577 REM ** PRINT SPEED - MOTOR SOUND **
580 POSITION 7,0:? #6;20*N;" "
582 IF DIS=12 THEN DIS=2:GOTO 584
583 IF DIS=2 THEN DIS=12
584 SOUND 0,ASC(P$(N,N)),DIS,7+N
590 GOTO 525
600 REM ** FINISH ROUTINE **
610 SOUND 0,0,0,0:A=USR(1722)
620 POSITION 0,0:? #6;"AVG. = ";INT(TS);"           "
630 IF TS>RA THEN RA=TS
640 POSITION 0,1:? #6;"RECORD = ";INT(RA);"         "
650 POSITION O,2:? #6;"Again? Press Trigger"
655 IF STRIG(0)=0 THEN 655
660 IF STRIG(0)=1 THEN 660
670 GOTO 310
1000 REM ** COLLISION SUBROUTINE **
1010 FOR I=0 TO 3:SOUND I,50+20*I,2*I+2,12:NEXT I
1020 FOR I=N TO 1 STEP -1
1030 N=I:POKE 1548,ASC(S$(N,N)):POKE 712,N*16+8:POKE 704,N*16+10:FOR J=1 TO 10:NEXT J:NEXT I
1090 POKE 704,56:POKE 712,0:FOR I=0 TO 3:SOUND I,0,0,0:NEXT I:RETURN 
2000 REM ** NEW LAP SUBROUTINE **
2005 REM ** Ck. clock for lap time - calc. speed **
2010 LAP=L:T(LAP)=PEEK(20)+256*PEEK(19)+256*256*PEEK(18):SP=DIST/(T(LAP)-T(LAP-1))
2020 POSITION 12,0:? #6;INT(SP);"   ":TS=DIST*LAP/(T(LAP)-T(0)):POSITION 1,0:? #6;INT(TS);" "
2025 POSITION 18,0:? #6;LAP
2030 RETURN 

Play Time Trial