"XMODEM Transfers in BASIC" (from Vol. 2 No. 5 A Tandy 1000 owner with a modem faces a real "Catch-22"situation. Joseph Heller coined the phrase "Catch-22" inhis magnificent novel of the same name. In that novel, aWorld War II bombadier named Yossarian thought he had comeup with the perfect scheme for getting out of combat duty.He reasoned that anyone who voluntarily participated inthose death-defying, hazardous bombing runs over enemyterritory must be insane. As a result, he applied for adischarge by reason of insanity. But, there was a catch!As the company doctor explained, regulation #22 (orCatch-22) specified that anyone who feared for his life andtried to find an excuse to get out of combat must beperfectly sane. Only an insane person would WANT to riskhis life with every new mission. Thus, the only peopleeligible for a discharge were the ones who wanted tocontinue flying! How does this apply to Tandy 1000 owners with modems? Well,as you know, there are literally hundreds (possibly eventhousands) of excellent public domain and shareware programswritten for MS-DOS computers like the Grandy. (Public domainprograms are usually offered free-of-charge to thecommunity; authors of shareware programs ask for a voluntarydonation, usually in the range of $5 to $50.) Many of theseprograms can be downloaded (or copied) from national andlocal computer bulletin board services (or BBS's). There isprobably at least one local BBS in your city or metropolitanarea; national services like Compuserve, Genie, and Delphican be accessed from almost anywhere. All of our Grandy'scame with DeskMate; you would think that the RECEIVEfunction in DeskMate's TELECOM terminal software packagecould be used to download some of that marvelous publicdomain software. But no, TELECOM is only equipped to handlesimple text, document, and word processing files. It willnot transfer files with a COM, EXE, or ARC extension -- andmost of the best programs have those very extensions! So what is a computer user to do? The best solution is toacquire a really sophisticated terminal program that willhandle advanced transfer techniques. (A terminal program isone that links your keyboard and monitor through the modemand the telephone lines with the distant computer system.Some of the more popular titles that fit into that categoryare QMODEM, PROCOMM, and PC-TALK. Once you have one ofthose packages, there is no limit to the number of programsyou can download. Catch-22! All of those programs are COM,EXE, and ARC files. You cannot download them with DeskMate.Do you see the dilemma? You cannot download the programsyou want from local and national BBS's because you do nothave a program which can transfer COM/EXE/ARC files; theBBS's all have programs that will transfer those files, butthey are all COM/EXE/ARC files that you cannot copy. The BASIC listing shown at the end of this column is a verysimple terminal program called SIMON. (Simple ... SIMON ...get it?) Although it is very crude compared to fancyprograms like DeskMate, it does have one redeeming feature-- it WILL transfer all kinds of programs, including thosepesky COM, EXE, and ARC files. Since it is in BASIC, allyou have to do is type it in and start to enjoy the world oftelecomputing. We will go into more specific details on how to download afile from a BBS in a moment, but now it might be interestingto talk about how files are transferred in general. Thenational and local BBS's use a variety of techniques forfile transfer, but the most widely used technique isprobably the one called XMODEM. As you know, all computerprograms and files are nothing more than series of numbers.Each byte in a computer file contains one number -- aninteger between 0 and 255. Each of those numbers serves aspecific purpose; some numbers are operation codes whichtell the computer to do something -- like perform anarithmetic operation, move a number from one memory locationto another, and so on. Other numbers are used to storeinstructions and other screen messages; they use the ASCIIcode numbers found in the back of your BASIC manual. Thus, when you ask the BBS computer to transmit a copy of aspecific program down the phone line, you are asking it torelay the series of numbers which make up that program. Thesimplest method (and the one used by DeskMate) is for theBBS computer to start sending the numbers one-by-one whileyour computer records them as they come down the line.Unfortunately, that technique does not always work. Eventhe best telephone lines are subject to momentary bits ofstatic and noise. That static can cause the numberstransmitted to become garbled; the copy you receive on yourend may not be exactly the same as the one on the other endof the line. And if even one byte in a file is wrong, itmay not work as it should. Ward Christensen developed the XMODEM technique of filetransfer over five years ago to solve this problem. Hissolution was to transmit the file in 128-byte sections. Atthe end of each 128-byte transfer, both the BBS and yourcomputer stop and "compare notes" to make sure that all 128bytes transferred in the previous block were correct. Ifthere was an error, then the same 128 bytes are transmittedagain (and again and again until they come through OK).When that block has been successfully transmitted, then thenext 128 bytes are sent, and so on, until the whole file istransferred. That description of XMODEM is conceptually correct, althoughas you might expect, in reality it is a bit morecomplicated. For the record, here are the actual stepsinvolved in XMODEM transfer: 1. Once you have requested an XMODEM file transfer, the BBScomputer waits for your computer to send the number 21 tosignal its readiness. 2. Once the value of 21 has been received, the BBS computerbegins to transmit the first block of data. The blockactually begins with the number 1, followed by the blocknumber counter (starting with 1, and incrementing with eachsuccessful block transferred), 255 minus the block number,the next 128 bytes of program data, and a checksum value(more on that in a moment). 3. After transferring that block, the BBS computer waitswhile your computer makes two checks. First, your computercompares the block number received with the block number itexpected to receive. If that number does not match, or ifthe calculated value of 255 minus the block number does notmatch the received value, then your computer transmits thenumber 21 to signal a problem and the entire block isrepeated. 4. Your computer also uses the checksum value to verify theaccuracy of the 128 bytes of program data received. Yourcomputer calculates the sum of all 128 data values received.The resulting sum is divided by 256, and the remainder ofthat division is compared with the checksum value. If theremainder does not match, then your computer transmits thenumber 21 and the block is repeated. 5. If there are no problems with that data block, then yourcomputer transmits the number 6, and the BBS computer beginsto transfer the next block of data. 6. This continues until there is no more data to send. Atthe end of the transfer, the BBS computer sends the number4, and your computer acknowledges the end-of-transmissionsignal with the number 6. An XMODEM transfer can be cancelled at any time bytransmitting the number 24. Notice that the checksumtechnique used in step #4 above is not foolproof; it ispossible that two or more of the numbers in the 128 bytegroup might be garbled, but the checksum could still becorrect. Nevertheless, the odds of such a coincidencehappening are very low; XMODEM transfers are reported to begreater than 99% reliable. Now that you know all about XMODEM, how does the SIMONprogram at the end of this article work? Lines 140 through160 perform some housekeeping chores: clearing the screen,setting the screen colors, setting up a 23-line viewingwindow, and placing a message on the bottom line of thescreen (in subroutine 520). Lines 200 through 320 open up communications with your modemthrough a serial port. Some of you have 300 baud modems,others have 1200 baud modems. Some use COM port #1, othersuse #2. All of those choices are taken into account inlines 210 through 240. Notice that all of the OPENstatements in lines 270 through 300 use similarspecifications: they begin with either COM1 or COM2,followed by a baud rate (300 or 1200), no parity, with 8data bits and 1 stop bit. Normally, the computer waits forabout one second to receive two key signals from the modem-- one called "Clear to Send", and another called "Data SetReady". If neither signal is received in that time, a"Device Timeout" Error is produced. The CS and DS optionsin the OPEN statements tell the computer not to botherchecking for those two key signals; that gives you more thanjust one second to make contact with the BBS. Lines 360 through 400 link your computer's keyboard andmonitor with the BBS computer. Line 360 checks to see ifyou have typed anything; if so, it is transmitted using thePRINT #1 statement. In line 370, EOF(1) is used to see ifthe BBS has transmitted any characters back to you; EOF(1)is true if there are characters waiting, false if there arenone. The characters received are placed in string variableB$ and displayed in line 400. Line 390 checks for the ASCIIvalue 8; most BBS's use this value as a "backspace", but ourGrandy computers display it as a square graphic symbol. TheASCII value of 8 is replaced with ASCII value 29 to move thecursor one space to the left. Subroutines 440 and 520 perform some useful functions -- toset up function keys F1 and F10, and to present a message onthe bottom line of the screen, respectively. Subroutine 590is the workhorse routine that receives an XMODEM filetransmission. Line 590 asks you what file name you willgive to the data which is about to arrive. A file by thatname is opened in line 660. Lines 680-690 correspond tostep #1 outlined above. Lines 730-750 perform step #2,while lines 790-800 perform step #3. The checksumarithmetic of step #4 is performed in lines 810-820. If allis OK, the block is stored in line 860, and step #5 isperformed in line 880. When the "end-of-transmission"signal is received, the file is closed in line 920. Line990 is called when function key F10 is pressed; it breaksoff the connection with your modem and returns you toBASIC's OK message. And now for the most important question -- how do I useSIMON to download some of those mouth-watering public domainand shareware programs from the bulletin board services?Unfortunately, I cannot give you specific instructions sinceeach BBS is operated slightly differently. But here aresome general tips. First, locate some phone numbers for BBSsystems you would like to call. There are a few listedelsewhere in this magazine. Your local computer club orusers group might have a list. The closest Radio Shackmight know of a few. Other magazines publish listsregularly; "Computer Shopper" magazine has a ratherextensive list, although it is not always up-to-date. Once you have decided on a number to call, type BASIC SIMONfrom the DOS A> prompt to run the terminal program. Makethe proper COM port and baud rate menu selection for yourcomputer and modem. The next step depends entirely on whattype of modem you have. If you have an older styleacoustical or direct-connect modem like I do, then yousimply dial the phone number of the BBS and wait for thehigh pitched tone. Once you hear the tone, you switch yourmodem on (or place the handset in the "Mickey Mouse" ears ifit is an acoustical modem). Press ENTER a few times to makecontact with the BBS. If you have a Hayes-compatible automatic-dialing modem, thenthings are somewhat easier. If you are calling a local BBSwith the number 555-1234, then you would type "ATDT5551234"and press ENTER. The letters "AT" get the modem'sattention, and the letters "DT" mean to dial the numberwhich follows in touch tone style. One you press ENTER, youshould hear the modem come to life and rapidly dial thenumber you specified. If all goes well, you will see themessage "CONNECT" on screen. You too might need to pressENTER a few times to make contact. A large number of you probably have the Tandy 300 BaudInternal Modem card installed. Although I have neverpersonally used this modem, I did locate some referencematerial in an old issue of ONE THOUSAND (Volume I, Number8, August, 1986, pp. 15-16). To call that same BBS at555-1234, you must type "*C*MGFDT5551234X" and press ENTER.The symbols "*C" get the modem's attention, the symbols"*MG" set the modem to manual connect, and the symbols "FDT"ask the modem to dial the number which follows Fast Dial inTouch tone format. The * is similar to the AT command ofthe Hayes and compatible modems. It is the attentionsignal. The X tells the modem to eXecute te dialingsequence and presto, the modem goes to work! Owners of other types of modems will have to consult theirequipment's reference manuals for further details. Once youhave connected with the BBS, follow the directions whichwill appear on your screen. If this is your first time tocall that BBS, you will probably have to apply forpermission to access the library of public domain software.You may have to wait several days before receiving thatpermission. Once you have permission to download programs, simply followthe directions provided by the BBS on your screen. You willhave to tell the BBS the name of the program you want tocopy. You will also have to select the technique used fortransfer -- select XMODEM, of course. Eventually, the BBSwill print a message saying something on the order of "Readyto Download PROGRAM.ARC" -- and then nothing further willhappen. At that point (and not a moment before), press F1to initiate SIMON's XMODEM receive subroutine. Enter a filename (I always use a file name equal to the BBS libraryname, but you do not have to do so), then sit back and watchas the file is transferred. Once the transmission iscomplete, your Grandy will beep to get your attention andthe BBS menu will probably re-appear. If it does not, pressENTER a few times to get its attention. When you arethrough, sign off the BBS using the proper commands. Neverjust "drop carrier" as it is not only rude, but alsodestructive on occasion. Once you have receivedconfirmation that you are indeed disconnected, press F10 toclose the line to the modem. Somewhere in each BBS's library of programs, you willprobably find a program called ARC.EXE. It may have somenumbers included in the title (ARC51.EXE, for example), butit is probably the same program. This should be the firstprogram you download (unless, of course, you have alreadyobtained the ARC program from some other source). ARC is autility program that compresses programs and makes themsmaller. That means shorter transfer times for you sinceeach byte transferred takes some finite amount of time. ARCcan also restore the programs to their full original size;they will not run in their compressed format, so you needARC to make the programs operational. If you need help inusing ARC, just type the program name from the DOS A>prompt. Your second download with SIMON should be a full featuredterminal program like QMODEM, PROCOMM, PC-TALK, or somethingsimilar. It will probably arrive in ARC format, so you willhave to de-archive it before using it. All of thoseprograms support not only XMODEM but also a variety of evenmore advanced transfer techniques, including YMODEM,TELELINK, KERMIT, and others. Once you have a super-duperterminal program like the ones mentioned above, you canretire SIMON to your scrap heap of obsolete programs. Many of you already have advanced terminal programs, andwill not find much useful in SIMON. Nevertheless, I hopeyou have learned a little more about XMODEM, and perhapsgained some new respect for BASIC. I look forward tohearing from you, with questions and suggestions for futurecolumns. Write to me in care of ONE THOUSAND magazine. Seeyou next month!