¢(While some of the following is old¢that to some of you, there is a¢possibility that you may have¢forgotten some basics¢--- PUN INTENDED---)¢Reprinted from M.A.G.I.C.'s EXCELLENT¢Newsletter, September 1990.¢ Ye OLDE EDITORS¢ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-¢¢ ¢ Atari BASIC Programming Helps¢By Hawke, Sysop of the Nine Hells¢Information Exchange of Philadelphia,¢(215) 785-2625¢¢As a whole, standard Atari BASIC is¢not the best programming medium in¢existence. One of the major problems¢stems from the fact that it was¢created too many years ago. Be that¢as it may, new programmers are being¢subjected to it now, unnecessarily,¢and must deal with a user unfriendly¢language. Inspired by a set of PASCAL¢notes, I venture to write these helps,¢so that BASIC programmers can learn¢from my experience, as well as the¢Phoenix, with whom I have consulted¢about this text. Any questions or¢comments are welcomed. Contact myself¢or Phoenix through the above Bulletin¢Board number.¢¢The following sections deal with¢POKE's, PEEK's, small machine language¢routines, some program listings, BASIC¢tricks, and other such nonsense.¢¢ROUTINE ONE: (Three Lower case H's),¢(INVERSE asterisk), (Capital L),¢(Capital V), (INVERSE Lower case D)¢¢ROUTINE TWO: (Lower case H), (INVERSE¢Quote), (Control P), (SPACE), (Upper¢case V), (INVERSE lower case D),¢(INVERSE control A), (INVERSE capital¢T), (INVERSE close parenthesis),¢(Control ,), (INVERSE control E),¢(INVERSE capital U), (Control .)¢¢(Ed. note: When typing in the above¢routines, DON'T type in the commas.)¢¢Section One: Machine Language¢Routines¢¢Many BASIC programmers are fearful of¢using machine language subroutines in¢their programs. I know this to be¢true, because I was one of them. I¢have since gotten over that fear,¢after collaboratively writing the¢P-Net 4.5 BBS system with the Phoenix,¢and have converted a few others.¢¢If you have ever used Character Fonts,¢made with any number of font editor¢programs (Envision, SuperFont, etc.),¢you know that they can be used to¢create fancy text, graphics, or maps.¢The problem with them is that one must¢enter in 1,024 bytes, poke them into a¢page of memory, and then change the¢register holding the address of the¢ROM set to the new set. To do all¢this takes a bit of time to do. The¢following machine language subroutine¢loads in a character set and adjusts¢the register in seconds.¢¢1 POKE 881,0:OPEN¢#3,4,128,"D:SET.DAT": POKE 884,0:POKE¢885,112:POKE 888,0: POKE 889,4:POKE¢882,7¢2 AA=USR(ADR("ROUTINE ONE"),48):CLOSE¢#3:POKE 54277,4:POKE 756,112¢¢* SET.DAT would be the font.¢¢* Poking 885,112 tells the machine¢which page of memory the redefined¢character set will be stored in (since¢a character set MUST start at the¢beginning of a page).¢¢* To return to the ROM set, simply¢POKE 756,224. To go back to the¢redefined font, POKE 756,112.¢¢¢The next machine routine deals with¢speedy Disk I/O. Atari BASIC¢programmers know that using the INPUT¢and GET commands with disk files is¢SLOW, especially when using large¢amounts of data. The following¢machine language subroutine solves¢this problem by allowing you to read¢an entire file into a string,¢virtually, in seconds. This can be¢useful when printing out text files or¢editting machine language programs (by¢string search, etc.).¢¢ 900 CLOSE #1:OPEN¢#1,4,0,"D1:filename.ext"¢1000 CE=INT(MEM/256):POKE 857,CE:POKE¢856,MEM-256*CE:¢BUF$(MEM)=" ":BOF=C1¢1010 POKE 853,INT(ADR(BUF$)/256):POKE¢852,¢ADR(BUF$)-PEEK(853)*256¢1020 DUM$="ROUTINE TWO":POKE 850,7:IF¢USR(ADR(DUM$))=136¢THEN BOF=C0¢1030¢X=PEEK(856)+256*PEEK(857):BUF$=BUF$(1,¢):RETURN¢¢* MEM is the amount of characters that¢BUF$ is dimensioned to hold.¢¢* In line 1000, the routine divides up¢that number into two numbers with a¢formula (16-bit conversion). This¢tells the subroutine the maximum¢length the string can hold. It then¢sets the last character in BUF$ equal¢to a character, thus, it defines BUF$¢as being full.¢¢* Line 1010 divides the address¢(starting location) of BUF$ by the¢same 16-bit conversion, and stores it¢for the subroutine, so that it knows¢where to start putting the incoming¢data.¢¢* Line 1020 executes the machine¢routine, and reads in the data,¢checking for an End Of File (EOF)¢error; #136. If such an error is met,¢the variable BOF is set to zero.¢¢* Line 1030 retrieves the number of¢bytes long the routine loaded, and¢tells BUF$ that it is X number of¢characters long.¢¢* If BOF=0, the user may account for¢the EOF and jump back to the routine¢after clearing BUF$.¢¢* By using this routine, one can copy¢files through BASIC. Simply, after¢reading in a file, print the string to¢disk.¢¢10 CLOSE #1:OPEN¢#1,8,0,"D1:destinat.ion":PRINT¢#1;BUF$:CLOSE #1¢¢¢The last machine language routine is a¢clock. The Atari has a built in clock¢and doesn't even use it. It follows¢the electrical current in the U.S.,¢which flows at 60Mhz. The following¢routine, written by the Phoenix, sets¢up a clock, using page 6 memory (1536)¢to store the data, and operates during¢each VBI (Vertical Blank Interrupt).¢You merely have to supply the current¢hour, minutes, seconds, and 60ths of a¢second. You can retrieve the current¢time by merely using PEEK commands.¢The only stricture is that if you use¢a graphics command (eg. GRAPHICS 0)¢you must re-initialize the clock.¢¢32700 FOR A=1 TO 105:READ B:POKE¢1535+A,B:NEXT A¢32705 ? "Enter Military Time as¢Hours,Minutes,Seconds,60ths": INPUT¢H,M,S,SS¢32710 X=USR(1611,H,M,S,SS)¢32720 DATA¢238,115,6,173,115,6,201,60,240,3,76,95¢228,169¢32730 DATA¢0,141,115,6,238,114,6,173,114,6,201,60¢240,3,76,¢95,228,169,0,141¢32740 DATA¢114,6,238,113,6,173,113,6,201,60,240,3¢76,95,228,¢169,0,141,113,6¢32750 DATA¢238,112,6,173,112,6,201,24,240,3,76,95¢228,169,0,¢141,112,6,76,95¢32751 DATA¢228,104,104,104,141,112,6,104,104,141,¢13,6,104,¢104,141,114,6,104,104,141¢32752 DATA¢115,6,169,6,170,160,0,76,92,228,0¢¢* The PEEK locations for the time¢are:¢¢ Hours - 1648¢ Minutes - 1649¢ Seconds - 1650¢ 60ths - 1651¢¢* The program first pokes the machine¢language subroutine into page 6¢memory, and then prompts you to enter¢the time.¢¢* It then GOSUBS the machine¢subroutine, sending with it the values¢of the current time, and then starts¢the clock.¢¢* After a GRAPHICS command, just PEEK¢in the values of the correct time into¢H, M, S, and SS, and reintialize the¢clock.¢¢¢Section Two: BASIC Tricks¢¢Since Atari BASIC hasn't many special¢features, one must compensate by¢"tricking" the system. These "tricks"¢are actually ways around BASIC that¢speed up processing, format output,¢etc.¢¢The first trick deals with filling a¢string with one character. To fill a¢string with 1,000 spaces, one would¢usually do this:¢¢ 10 DIM L$(1000)¢ 20 FOR A=1 TO 1000¢ 30 L$(A,A)=" "¢ 40 NEXT A¢¢This method, though fine programming,¢is SLOW. The trick around it is a¢quirk in the BASIC; well, not actually¢a "quirk", but a hidden back door.¢The line below is the aforementioned¢routines equivalent.¢¢10 DIM L$(1000):L$=" ":L$(1000)="¢":L$(2)=L$¢¢Not only is this routine shorter, but¢it's almost instantaneous, depending¢on the size of the string. I find a¢one second wait for strings in the¢xx,xxx digit range, but I think that¢it's worth the wait.¢¢Side Note: If you DIMension a string¢at 1000, and aren't filling the ENTIRE¢string with one character, say 500¢from a 1,000 character string, and use¢the formula [L$=" ":L$(500)="¢":L$(2)=L$], it will fill it with 501¢spaces. To clear this up, all you¢need do, is put "L$=L$(1,500))" after¢setting it. This is true, even when¢filling 998 of the 1,000 characters.¢¢¢The next "trick" deals with the INPUT¢statement. Anyone who has programmed¢using the INPUT statement knows that¢it puts a "?" on the screen to signify¢an input request. This can be¢bothersome to some, especially me,¢when they want to make prompts look¢nice. That "?" just looks outta¢place, and sometimes is included in¢the returned variable.¢¢There are two solutions. One is to¢write your own "Get-Line" routine,¢using an open keyboard buffer, getting¢keypresses, adjusting for backspaces¢and control characters, and using up¢memory, OR...¢¢Use the following Input command that¢is totally the equivalent of your¢regular INPUT.¢¢ INPUT #16,variable¢¢That's right! An input through¢standard Atari BASIC without the¢dreaded "?". It works exactly like¢the standard INPUT command. Sure, you¢could open a channel to the editor¢(E:) yourself, but this method¢requires no additional open buffers.¢¢¢Ever want to intialize a disk from¢BASIC? No, I don't mean just format¢it, I mean put DOS on it too. Well, I¢have good news and bad news. The GOOD¢news is that you can, the bad news is¢that that's ALL you can put on it;¢DOS, no DUP. In fact, the writing of¢DOS to the disk is as fast as writing¢from DOS itself!¢¢ OPEN¢#1,8,0,"D1:DOS.SYS":CLOSE #1¢¢Yes, that's it! All DOS's except¢SpartaDOS and TOPDOS will work, even¢the OSA+ DOS's. You have just written¢DOS to your disk from BASIC.¢¢¢Did you ever want to Re-Boot (Warm¢Boot) the computer from BASIC without¢hitting System Reset? Try this:¢¢ X=USR(58487)¢¢This will "Warm Boot" the computer,¢but unlike the RESET key, it is the¢equivalent of turning the machine OFF¢and ON again; so you might call it an¢artificial COLD boot. You may hold¢down OPTION as this boot takes place¢to disengage BASIC. Its Hexadecimal¢number is E477. You can do it from a¢DOS as well.¢¢¢Section Three: PEEK's and POKE's¢¢Did the speed of Atari BASIC¢processing ever bug you? Well,¢there's a way to increase data¢processing 33%. It will increase¢problem solving speed, data¢processing, and graphic plotting.¢¢ POKE 559,0¢¢This POKE will shut down ANTIC, thus¢shutting of the screen, so that¢processing speed is increased. To¢turn it back on, use POKE 559,34.¢¢¢To find out what version of Atari¢BASIC you have in your computer, you¢simply:¢¢ PRINT PEEK(43234)¢¢A number 32 or less is revision A.¢The value 64 or less is revision B;¢built into most XL's. And a number¢greater than 64 is revision C; the¢current version built into the XE¢line. Though I have an old 800XL, for¢some reason I have revision C built¢in; a blessing.¢¢¢Here are some keyboard POKE's to play¢with:¢¢ * 755,004 - Turns character set¢Upside-Down, and disables Inverse¢video.¢¢ * 755,008 - Right-Side up¢character set WITHOUT Inverse video.¢¢ * 755,013 - Upside-Down¢characters WITH Inverse video.¢¢ * 755,010 - Right-Side up¢character set with Inverse video¢ (Normal mode).¢¢¢Special recognition to XLent software¢and David Castell for creating the¢fine word processor used to create¢this text. BRAVO.¢¢Please send me comments concerning¢these notes. A positive response¢might warrant a Part Two.¢¢ ¢Hawke¢¢----------------¢¢I downloaded this article from the¢Pandora BBS (614) 471-9209 on¢10/22/89. It looks like it came from¢the Nine Hells Information Exchange of¢Philadelphia (PA) BBS, (215) 785-2625.¢ I thought it might be good for those¢still programming in Atari BASIC. I¢hadn't seem most of the tips before¢except the one on getting rid of the¢question mark. I'll bet others¢haven't either. I hope you find this¢article helpful. - Grant -¢ ¢