Classic Computer Magazine Archive ANTIC VOL. 6, NO. 5 / SEPTEMBER 1987


Tech Tips

By Carl Evans


In coming months, many of the short programs featured on these Tech Tips pages will be adapted from Atari BASIC: Faster and Better by AntIc Contributing Editor Carl Evans. This excellent collection of powerful BASIC subroutines unfortunatelg is no longer in print, but we will be publishing the best of it in future issues.

All the Tech Tips this month are by Evans. BUT. . . Antic still welcomes good short programs sent in by readers for Tech Tips or I/O letters. And we'll still continue to publish the best Tech Tips we find in all the users group newsletters.-- ANTIC ED

MEMORY BLOCK POINTER

Many different methods are used to reserve a block of memory so that it is protected front modification by BASIC or the operating system. Carl Evans believes that the safest way to do this is to LOAD a small BASIC program that changes the pointers to the bottom of memory and RUN it just before running your main program.

19930 REM RESERVE.LST-PROTECTS A BLOCK OF MEMORY
19931 REM SIZE=NUMBER OF BYTES TO RESERVE
19932 ADDRESS=256*PEEK(744)+PEEK(743)+SIZE
19933 MM = INT(ADRESS/256):LL = ADDRESS-256 * MM
19935 POKE 128,LL:POKE 129,MM:REM MOVE LOMEM UP
19936 POKE 8,0:REM RESET WARM START FLAG
19937 X = USR(40960):REM RESTART BASIC

HEX-TO-DECIMAL CONVERSION

In many cases it's much more efficient to work with hexadecimal (hex) notation than decimal. In fact, it's almost mandatory if you expect to do much machine language programming. Use the following routine to convert any two-place or four-place (one-byte or two-byte) hex number into decimal by storing your hex number in HEXNUMBER$ and using a GOSUB to HEXDEC.LST. The routine will return the proper decimal number in DECNUMBER.

20100 REM HEXDEC.LST--CONVERT HEX NUMBERS TO DECIMAL
20101 DIM HEXDEC$(23),HEXNUMBER$(4)
20102 INPUT HEXNUMBER$
20103 HEXDEC$="ABCDEFGHIJ *****"KLMNOP"
20104 REM THIS IS THE MAIN ENTRY POINT
20105 DECNUMBER=0:HEX=LEN(HEXNUMBER$):FOR X=1 TO HEX
20106 DECNUMBER=16*DECNUMBER+ASC(HEXDEC$(ASC(HEXNUMBER$(X))-47))-65:NEXT X
20107 PRINT DECNUMBER:GOTO 20102

The above routine is particularly useful if your BASIC progrom requires you to INPUT hex numbers. Just make the input variable a string and store the input in HEXNUMBER$ before calling the HEXDEC routine.

VARIABLE LISTER

This short program displays a list of all the variables in your BASIC program. This lets you count the total amount of variables you have, as well as checking any of the names.

19990 REM VSHORT.LST
19991 POKE 204,PEEK(130):POKE 205,PEEK(131)
19992 IF PEEK(204)=PEEK(132) AND PEEK(205)=PEEK(133) THEN STOP
19993 PRINT CHR$(PEEK(PEEK(204) +256*PEEK(205)));
19994 IF PEEK(PEEK(204)+256*PEEK(205))>127 THEN PRINT
19995 IF PEEK(204)=255 THEN POKE 204,0:POKE 205,PEEK(205)+1:GOTO 19992
19996 POKE 204,PEEK(204)+1:GOTO 19992

DECIMAL-TO-HEX CONVERSION

This routine takes a decimal number (stored in DECNUMBER) and converts it to a hex number (stored in HEXNUMBER$). The variable BYTES specifies the size of the hex number as either one or two bytes.

20110 REM DECHEX.LST--CONVERT DECIMAL NUMBERS TO HEX
20111 DIM DECHEX$(16)
20112 DECHEX$ ="0123456789ABCDEF"
20113 INPUT DECNUMBER
20114 KHEX=4096:Z4=4:PRINT "$";:IF BYTES=1 THEN KHEX = 16:Z4 = 2
20115 FOR I=1 TO Z4:J =INT(DECNUMBER/KHEX):PRINT DECHEX$(J + 1, J + 1);
20116 DECNUMBER= DECNUMBER-KHEX*J:KHEX= KHEX/16:NEXT I:PRINT:IF BYTES=1 THEN BYTES=2:Z4=4
20117 GOTO 20113

If you have a Tech Tip that you would like to share with other readers send it along to Antic Tech Tips, 544 Second Street, San Francisco, CA 94107. You might get your name in print. We always welcome very short programs that demonstrate the Atari's powers, simple hardware modifications, or useful macros for popular software.