Action! › and› BBS Express! PRO› Tutorial›› by› Thomas M. Johnson ››› Available from ›› Villa Video's Bargain Cellar › (414) 265-5149 › ExpressNet Node X11 ››Action! is copyright of ACS, OSS, ICD.›BBS Express! PRO is copyright Orion›Micro Systems.› ›This tutorial is copyright Thomas M.›Johnson.››This tutorial can be distributed under›the following conditions:› 1) It is free.› 2) All of the above› information is intact.››--------------------------------------››Well, I guess its time to talk about›files. Now, when I say files, I mean›both files and devices. The only›Atari device that uses files is the›disk drive. But when it comes down›to using files and devices, things›are done the same.››Your Atari has a few devices built in›to it when you turn it on.››E: - input and output› - This is the standard Atari editor› that is used. When you do a› PrintE() or other simple output,› this is the device it goes to.› Also, when you do a InputB()› this is the device it comes from.› It is the screen and the keyboard› combined.››C: - input and output› - This is the cassette player.››P: - output only› - This was originally meant to› stand for parallel but Atarians› now know it as printer. It makes› sense that it is for output only,› right?››S: - output only › - This is the screen. This is the› device that is opened by the› Atari when you do a Graphics› command. (We'll cover Graphics› later in the tutorial.)››K: - input only › - The keyboard. When you input› information from the keyboard,› nothing is echoed on the screen.››There are 2 more devices that we call›standard, even though they aren't ›built in to you computer. They have›to be loaded in before you can use›them.››D: - input and output› - Your disk drive. DOS must be› loaded before you can use it.› Also, a filename must be supplied› when you first open this device.››R: - input and output› - The RS232 port on the 850 or› P:R: Connection. This is› used by modems that need the › interface.››There is also 1 custom device that›is "famous" enough to merit me›mentioning it here.››T: - input and output› - This is your 1030 or XM301 modem.››OK, those are the devices. How do you›use them? Good thing you asked. The›first thing you must do before you›can use a device, is open it.››Open(1,"K:",4,0)››The number "1" is the device number.›After you open a device, from the then›on you refer to it by its device›number.››The "K:" is what device you want to›open. It is a string and must either›be in "quotes" or a CHAR ARRAY›variable.››The next number is the command. Use›this chart to find out which command›to use.››Input Only - 4›Output Only - 8›Input and output - 12›Append to end› of file - 9›Disk drive› directory - 6››Since a K: device can only do input,›the number "4" is an easy choice.››Just because a device can do input›and output DOES NOT mean you should›choose the number 12. If you want›to output to a disk file use 8.›The reason the command number 12 is›there is in a situation like this:››If you want to change the 5th BYTE›in a file, you read the first 4›and then over write the 5th.››The last number "0" is required and›there must always be a "0" there.››If you know BASIC, you will see there›is a little difference between the ›order Action! uses and the order›BASIC uses.››In BASIC it is like this:››OPEN #1,4,0,"K:"››The arguments mean the same things,›just a different order.››To output to a file, you use the›standard Atari Print PROCs except›you put a D (for device) at the›end in the proper place. For example,›if you want to print a string with›a carriage return on the end›to a device, you'd use:››PrintDE(2,"Hi there")››The number "2" is the device number›you assigned it in the Open(). This›can be done to any device that can›do output and the statement will be›exactly the same.››Here are the output PROCs. ››PrintD - string›PrintDE - string with CR›PrintBD - BYTE›PrintBDE - BYTE with CR›PrintCD - CARD›PrintCDE - CARD with CR›PrintID - INT›PrintIDE - INT with CR››The input statements are close to the›normal input FUNCs as well.››b=InputBD(1)››Input a byte from device number 1.››Here are the input FUNCs.››InputBD - BYTE›InputCD - CARD›InputID - INT››And for strings:›InputSD(3,name)››This get a string from device number›3 and places it in name.››There are 3 more statements you can›use with devices.››c=GetD(1) - get a single character› from device number 1››PutD(1,c) - put a single character› on device 1.›PutDE(1,c) - same but CR after››InputMD(3,name,20) - Get a string from› device number 1› and only 20› characters long.››When you are done with a device, you›must always close it.››Close(4) - close device number 4.››There are a few things that are ›different when you use D:››The first is you must supply a›filename. It can be 8 characters›long with a 3 character extension.››Open(3,"D:MYFILE.DAT",8,0)››If you use a DOS that has›subdirectories, they can be included›in the device string as well.››If you use Open a disk file with›a command number of 8, it will›create a new file if it does not›already exist or erase the old file›if it does.››When you Open a disk file with›command number 4, it always starts›reading at the beginning.››It is a good idea to get in the habit›of close a device number before›you open it just to make sure it is›ok to use. If you try to open a ›device number when it is already›open, you program will bomb.››The device numbers that you are ›allowed to use are 1 though 7.››Lastly, every time you compile an›Action! program, a BYTE ARRAY is›automaticly declared for you. The›ARRAY is called "EOF". EOF holds›either a 0 or a 1 so it can be used›in a IF, WHILE or UNTIL statement.››When using disk or cassette files,›you cannot try to read past the end›of the file. If you do try, the›program will crash.››So you have 2 choices, either you›have to save the number of entries›in that file and use a FOR loop›to read in exactly that number of›entries. Or use EOF.››EOF holds a 1 if you are at the end›of file and 0 otherwise. For›example:››EOF(2)››If device number 2 is at the end of›the file, then this will be a 1. The›best way to use EOF is in a WHILE›loop because a WHILE loop checks›before the loop is run the first›time.›››PROC read()›› BYTE character›› Close(1)› Open(1,"D1:ATUTOR.001",4,0)› WHILE EOF(1)=0 › DO› character=GetD(1)› Put(character)› OD› Close(1)›RETURN››This PROC prints ATUTOR.001 on the›screen character by character. The›file ATUTOR.001 must be on the disk in›disk drive #1 for this program to ›work. Also, you may have noticed that›I didn't call it main() this time.›Remember, you don't have to call›it main().››This type of PROC might be good if›you wrote a game and this will print›the instruction file to the screen›for the user.››You may also have noticed that reading›character by character is not the most›efficient way to do this. A better›way would have been to read the whole›line in with a InputSD() and echo›it with a PrintE(). But to so this ›the last line must end with a CR›before the end of file. If you KNOW›that it does, you can use the next›PROC instead. But, if you are›unsure, you don't want to make›assumptions. (By the way, ATUTOR.001›does have a CR before the end of file›so it is OK to use this PROC)››PROC better_read()›› BYTE ARRAY line(50)›› Close(1)› Open(1,"D1:ATUTOR.001",4,0)› WHILE EOF(1)=0 › DO› InputSD(1,line)› PrintE(line)› OD› Close(1)›RETURN››