*FX8,1 | 75 baud |
*FX8,2 | 150 baud |
*FX8,3 | 300 baud |
*FX8,4 | 1200 baud |
Parallel
*FX5,1 | (necessary only if serial port previously selected) |
*FX6,0 | enable line feeds (if required) |
CTRL-B or VDU 2 | turn on |
LIST | |
CTRL-C or VDU 3 | turn off |
*FX5,2 | select serial port |
*FX3,n | n=1, 2, 3 or 4 according to baud rate |
*FX6,0 | enable line feeds (if required) |
CTRL-B or VDU 2 | turn on |
LIST | |
CTRL-C or VDU 3 | turn off |
*FX5,4 | select Econet |
*FX6,0 | enable line feeds (if required) |
CTRL-B or VDU 2 | turn on |
LIST | |
CTRL-C or VDU 3 | turn off |
X=ADVAL(-4) IF X=64-N THEN PRINT CHR$(3);"NO PRINTER CONNECTED": GOTO...
If the free space is not greater than 64-N, then nothing has been transmitted and preventive action can be taken.
*NET
In an Econet system up to 254 BBC microcomputers can be connected together. Each microcomputer connected to the network has a station identity which is a number between 1 and 254. This number is set by a switch inside the computer case. No two computers on a network can have the same station identity. The diagram of the network shows that, in addition to the user stations, there are usually two special purpose computers: the file server.
Which together with a disc drive provides storage for the network and a printer server, which together with a printer, is available for program listings and output of data. A network may have more than one file server or printer server.
The printer server can be used as a normal station except when it is accessed by another user on the network to print a file. The printer server Heeds an additional special ROM containing the printer software. The Iletwork computers assume that the file server has a default identity of 254 and that the printer server has the default address (station identity) of 235. The computer (or computers) that acts as a file server is dedicated to that purpose and runs a special program supplied on a floppy disc. Two versions of the file server software have been released and are in widespread use. These are referred to as level 1 and level 2.
Key
Computers that have the Econet system installed will usually be arranged to default to the Econet filing system on switch-on and after a <BREAK>. It is possible to cause a <BREAK> or switch-on to select another filing system even though the Econet system is installed, as follows
<CTRL-D>+<BREAK> selects DFS (Disc Filing System)
<CTRL-T>+<BREAK> selects CFS (Cassette Filing System)
<CTRL-N>+<BREAK> selects NFS (Network Filing System)
Assuming that the file server has been started by the system manager, and the network is in operation, then each user station can access the Econet filing system.
After a switch-on with the network selected, a computer fitted with the Econet will respond thus
BBC Computer 32K Econet station nnn BASIC >
where nnn is the station identity. The other filing systems can be selected in the usual way by *DISC or *TAPE without loss of program or data. Thus programs may be transferred between different filing systems.
*I AM nnn
where nnn is the station identity of the file server selected. As the default station number is 254 it is not necessary to select this after switch-on.
On level 1 the file server has a list of valid users identified by a single letter from A to Z, which is also the name of their directory on the file server. The station identity is paired with the user nameldirectory so that each station can only have access to one directory. The directories for different stations can all be different or some can have common directories. Thus a station cannot have more than one directory assigned to it, but a directory can have several stations assigned to it. The allocation of directories to stations is set up by the system manager whenever he starts the system up. This means that the users must normally use the same machine each time, in order to have access to their own files.
The level 1 file server software can be run on a Model B microcomputer With any type of disc drive and Econet interface. It does not require the 6502 Second processor, which is needed by level 2 file servers. The level I file Server is a BASIC program which uses the DFS filing system. This limits the total number of files available to the Econet system users to a maximum of about 120 on each file server and that only if a twin double-sided disc drive is being used.
In addition to the individual directories indicated by a letter, allocated to each network station, there is a library directory, &, which is available to all users on the network. The library cannot be written to while the system is running but since the file server discs are in normal disc filing system format they can be written to whilst the file server is operating as an ordinary DFS machine. The network computers automatically select the & directory on drive 0 as the library. The & directory can only be accessed on drive 0; it can not be accessed on any other drive. Thus the library must be on drive 0. The library directory & is intended for the system utility programs which are used by all users, and for demonstration programs for the whole class to use. One of the advantages of the level 1 Econet system is that the discs can be prepared on an ordinary DFS machine, unlike level 2.
Another advantage of the Econet system is that it can provide a printer server. This means that a whole group of users can access a common printer. An Econet network can, however , have a printer server without having a file server.
The range of commands available on the level 1 Econet system is restricted and these are listed in Table L.1. The absence of data file handling commands is a severe limitation to the use of level 1. Another restriction is that, as the system is run by a file server without a second processor, the maximum length of file that can be transferred across the network is also limited. The latter restriction can be overcome by saving blocks of memory with *SA VE and using *LOAD to reassemble a file which would otherwise be too large.
Table L.1 Level 1 Econet system commands.
Command | Argument | Explanation |
SAVE | "XYZ3789" | Save a BASIC program in file XYZ3789 |
LOAD | "XYZ3789" | Load the BASIC program XYZ3789 |
*CAT | Catalogue the files of a particular user | |
*DELETE | <fsp> | Delete a specified file. |
*DRIVE n | Select the disc drive surface in use (n=0 to 3). | |
*ACCESS | <fsp> L | Lock (L) or unlock ( ) a file. |
Locked files cannot be deleted or overwritten | ||
*I AM | nnn | Select file server by stated identity. |
*SAVE <fsp> | start finish | Save an area of memory on disc giving |
*SAVE <fsp> | start+length | start address and finish address or length |
*LOAD | <fsp> | Load file into memory. |
*RUN | Execute a machine code program | |
*INFO | <fsp> | Displays information about a file |
*<fsp> | Execute a machine code program as a command | |
*/ | <fsp> | Allows <fsp> to take reserved names such as CAT so that you can write your own utilities. |
*PS | nnn | Select station nnn as print server |
*FX 5,4 | Special *FX call to select Econet printer. Use CTRL-B and CTRL-C in the usual way to start and finish printing. |
*DRIVE n
where n=0, 1, 2 or 3, and subsequent LOAD or SAVE commands will refer to the selected drive. Alternatively, you can SAVE or LOAD from a different drive without changing the selected drive by preceding the filename with :n where n is the drive number.
The commands in Table L. 1 form part of the Econet software and are always available to the network user. A second group of commands or utilities would normally be made available to the user at the discretion of the system manager and these are given in Table L.2. A utility is a separate program that can be used in the same way as a command. The utility programs are stored in the & directory and are *RUN by the *<filename> command which will search the selected library if a file of the given name is not in the user's directory. The system manager can choose which utilities are available to the users by the range of program files he provides.
Table L.2 Level 1 network utilities.
Command | Argument | Explanation |
*PROT | Protect station from remote control. | |
*REMOTE | nnn | Take remote control of station nnn. |
*VIEW | nnn | Take copy of VDU from station nnn. |
*NOTIFY | nnn | Send message to nnn. |
*UNPROT | Unprotect station. | |
*FS | nnn | Change file server to station nnn. |
*ROFF | Remote off. |
Table L.3 Additional Level I error messages.
Message | Explanation |
Directory full | The number of files each user may store is restricted at the start-up of the system. You cannot exceed this limit. |
File not found | The Econet system only looks on the selected drive for a requested file. |
Insufficient access | The file server does not recognize you as a user station. The identity of the computer is not in the list given. |
Not listening | Your command has not been accepted by the file server or print server. |
Too much data | This arises when the file length limit is exceeded. |
Line jammed | Information permanently present on the network. |
No clock | The network clock signal is not reaching the station. |
No reply | The file server is not responding to your command. |
*I AM nnn USER3 PASS
where nnn is the file server station selected. if other than the default station 254, USER3 is the name of the user, and PASS is the password for this user.
Unlike level I, a user of the level 2 Econet system can use any of the stations on the network. It is not necessary to associate user names with the station identity as in level 1. The user name can consist of up to ten characters which must start with a letter. The password can be up to six characters long. The first time a user logs on to the system, the password will usually be blank.
If a user who is not known to the system tries to log on, the error message 'User not known' will be displayed. The system manager is responsible for creating new users, and for creating a user root directory for them. A user who does not have a directory can log on, but will not have any storage space allocated, and will only be able to read and use files on public access. At logon a user will normally have his own root directory as his selected directory. Extra security of passwords is provided in later versions of the Econet ROM in which the following sequence is permitted and will not reveal the password on the monitor screen
*I AM USER3
<RETURN>
PASS
<RETURN>
In this case the second line will not be shown on the monitor screen. Use of the wrong password by a valid user will produce the error message 'Wrong password'. The user will not be logged on by the system and he must try again. At the end of a session at a station on the Econet the command
*BYE
logs off the user. The *BYE command is issued automatically during a logon so that only one user can be logged on at a station at one time. Until a user has logged into the network the only Econet file server command accepted is *I AM <user> <password>. The manager sets the number of stations that are to be served by a file server, and if an attempt is made to log on to a file server which has its full complement of users, the message 'Too many users' is sent.
The network stations on the Econet may include stations with DFS and disc drives. The range of standard DFS commands available on the Econet to non-DFS machines is nearly as extensive as those available on DFS machines. The commands on the DFS and Econet filing system (NFS) are as nearly compatible as possible. The DFS commands with no equivalent are *BACKUP, *BUILD, *COMPACT, *COPY, *DESTROY, *DRIVE, *DUMP, *ENABLE, *LIST and *TYPE, but a system can have library utilities to provide some of these facilities, for example *BUILD, *DUMP and *TYPE. (See, for instance, Networking with the BBC Microcomputer by R G Napier, published by Prentice-i-iall International.)
The commands that are different or modified are * ACCESS, *CAT, *DIR and *INFO. In addition to the DFS commands and those discussed for level 1, level 2 has the following additional commands available
*BYE *CDIR *DISCS *EX *LIB *PASS *SDISC
Table L.4 gives a summary of these commands and the modified DFS commands.
Table L.4 Level 2 Econet system commands
Command | Argument | Explanation |
*BYE | Logs the user off | |
*CDIR | <dir name> | Creates a directory. |
*DISCS | Displays the names of the discs currently in use. | |
*EX | <dir name> | Gives extensive information about files in directory <dir name> |
*I AM | nnn <name> | The logon command to station nnn by user <name>. |
*INFO | <fsp> | Gives information about a file. It cannot be used with wildcards as in the DFS. |
*LIB | <dir name> | Selects <dir name> as the library directory. |
*PASS | "" <pass> | Sets user password to <pass>. |
*PASS | <old> <new> | Changes user password from <old> to <new>. |
*PS | <nnn> | Selects the printer server to be a station other than the default station 235. It is assumed the selected station is suitably equipped. |
*SDISC | <disc name> | Changes the disc available to the user. |
The majority of the modified commands that differ from their DFS counterparts can, in general be used as though there were no difference. The * ACCESS command is the most changed command due to the wider range of facilities offered by the network environment. The format for this command in the Econet situation is
*ACCESS <fsp> <owner access>/<public access> L
The presence of L indicates that the file is locked, to prevent its deletion. The owner access can be R for read and/or W for write, and the public access may be nil or read R. Thus
*ACCESS SAMPLE R/ L
sets the file in the currently selected directory called SAMPLE for read access by the owner, and at the same time prevents its deletion. Another format might be
*ACCESS MINEONLY RW/ L
or
*ACCESS EVERYONE RW/R L
The default setting of file access on creation of a file is RW/ . The access control is limited to either public access or no public access. There is no way of limiting access to a group of users.
The *PASS command is to enable a user to set a new value for a password. The format is
*PASS <oldpass> <newpass>
or, in the case of the initial setting
*PASS "" <pass>
The quotation marks are used to identify the empty string.
The *DISCS command enables a user to find out which discs the file server has loaded. A file server disc has a name to identify it. A user who needs a disc not currently loaded can then ask the system manager to load it, in place of one of those currently available. The command *SDISC allows a user to select the disc in the other drive for use, thus
*SDISC <name>
The user will need a directory, created by the system manager, on each disc on which he wishes to store programs or data.
The selection of a current library, by use of
*LIB <directory name>
is restricted to the disc selected by *SDISC, and so does not have the power of the similar DFS command. The library must be reselected after using *SDISC. The default library directory selected at logon and on change of disc by use of the command *SDISC is the directory 'Library'. 'Library' contains the system utilities given in Table L.2.
The *DIR command is used to select a directory on the currently selected disc. After a change of disc the user has his root directory as the currently selected directory. If any other is required then the command
*DIR NEWDIR
has to be used to make NEWDIR the currently selected directory. In order to select a directory such as 'Library' or that of another user, it is necessary to ascend to the root directory and then progress to the directory required by the appropriate route. The return to the user's own directory is made by
*DIR
<RETURN>
without specifying the name or root. It will be found that on return to the user's directory by
*DIR $.<username>
that the user only has public access rights. To regain the normal rights of a user logged into their own directory it is necessary to use *DIR alone, logon again or to use the *SDISC command as though to change the selected disc.
A similar restriction and limitation to that for *LIB also applies to *CAT. Only directories on the selected disc can be catalogued and, unlike the DFS, a directory must be created before it is catalogued. A directory is created by
*CDIR <name>
This command can be issued by a user to create a sub-directory. Figure L.2 illustrates the hierarchical structure of the directories.
The format for the catalogue command is
*CAT <name>
If no name is given, the user's currently selected directory is catalogued. If the catalogue of another directory is required, then either that directory must be made the selected directory or the pathname of that directory must be given.
*CAT $.Library
will catalogue the public access files in the directory 'Library' and
*CAT $.USER3.SUB2.SUB2A
will catalogue any files in USER3's sub-directory SUB2A which are on public access to any other user issuing the command.
The files may be referred to by pathnames in which the directory route to - locate a file is given by a list of directory names, separated by the full stop. For example, the library file LSQ could be loaded by the command
LOAD "$.Library.LSQ"
without the need to change the currently selected directory (provided, of Course, that the access control for public read is set). It is generally advisable - to use the pathname, rather than to change directory to use a file in another directory, as it is then no longer necessary to use *DIR <RETURN> to regain owner rights in your own directory. The use of pathnames with files provides a convenient means to refer to files not in the currently selected directory. All the file handling commands can be used with pathnames as a prefix provided that the access sought is allowed. (A useful tip if you are using a prefix frequently is to program it into a function key.)
The *INFO command is less flexible than that available with the DFS as it is no longer possible to use the wildcards * and # to give information about a group of files. It is limited to information about one file only, the first one found to fit the description. In the NFS environment, this command can also give further information about a directory. The level 2 Econet command *EX compensates for the loss of the wildcard facility to some degree, as
*EX <directory name>
is equivalent to issuing a *INFO command for each of the files in the directory named.
The information displayed about files with *EX and *INFO is as follows for each file
NETFILE FFFF1200 FFFF8023 000043 WR/ 14:4:85 000147
where
NETFILE | is the filename |
FFFF1200 | is the reload address |
FFFF8023 | is the execution address |
WR/ | is the access currently set |
000043 | is the file size |
14:4:85 | is the most recent date on which the file was written to |
000147 | is the System Internal Name (SIN) |
! % & = - ~ ^ | @ {£ _ + ; ) ] < > ? /
but not the space character. No distinction is made between upper- and lower-case letters.
The *NOTIFY command can either be used with station identity or with user name. Thus both of the following messages, sent from station 121, are valid
*NOTIFY USER3 It is time for lunch
<RETURN>
*NOTIFY 235 Ptease witch the printer on
<RETURN>
The station at which USER3 is located will 'bleep' and display the message thus
--121: It is time for lunch
The message is not followed by a return so that the receiving user can delete it and continue with his own activity. The message at station 235 is
--121: Please switch printer on
The number prefixing the message gives the station identity of the source of the message.
The range of network utilities available can be controlled by the network manager since he can change the access rights of the users to the files in the directory 'Library', which is the equivalent of the & directory in level 1. The utilities are programs that can be *RUN by the use of the abbreviation *<filename>. The user's own directory is scanned first for the file <filename>. If the file is not found in the owner's directory the 'library directory' is then scanned and if it is found then <filename> is *RUN. The library directory is either that last set by the *LIB command or if no change has been made it will be the directory 'Library' which is the default library directory set by the system during logon using the *I AM command. The system manager may choose to limit the range of utilities available to general users but this does not prevent their use by privileged users. This option has clear applications in class situations where a teacher may not want pupils to have the same access to the computers of other users that he can have.
The additional error messages of the level 2 Econet system are given in Table L.5.
Table L.5 Level 2 Econet error messages.
Message | Explanation |
Bad attribute | *ACCESS has been used with an inappropriate access string. |
Bad password | Whilst using *PASS, the new password is not acceptable. |
Bad string | The file or pathname is too long or, the " symbol has been omitted. |
Broken dir | The directory has been damaged. The system manager is responsible for keeping backup copies. |
Channel | Corrupted memory (RAM) in user station. Log on again. |
Dir. full | The directory on the selected disc is full. |
Message | Explanation |
Dir . not empty | An attempt has been made to delete a non-empty directory. |
Disc changed | A change in file server disc has occured |
Entry locked | It is necessary to use *ACCESS to unlock a file. |
EOF | You have tried to read after the End Of File. |
Insufficient access | You have tried to get access to a file for which you do not have sufficient access rights. |
Insufficient privilege | There are certain commands only available to the system manager. |
Is a dir. | An attempt to make incorrect use of a directory. |
Not found | The file or directory specified is not where you expected. |
Not listening | This can occur if you try to use the printer while it is busy. |
Not logged on | The only command available to a user who is not logged on, is *I AM. |
Not open for update | You are trying to write to a read-only file. |
Outside file | Occurs with OPENIN in BASIC I. An attempt has been made to put the random access pointer past the file end. |
PW file not found | This message may occur at logon if there is no password file on the file server |
Rename across discs | The *RENAME command does not allow a file to be moved between different directories on different discs. |
Too many open files | In general data file access, you have used all the channels available. |
Too many users | The system manager sets the maximum number of users for the file server. |
Types don't match | You have tried to save a file to a directory, or similar. |
User not known | The system manager creates users. |
Message | Explanation |
Who are you? | Reminder that *I AM is the only command for non-logged on users. |
Wrong password | An attempt to log on with an incorrect password. |
R15,9 and W25,0
with track and sector numbers in decimal and separated by a comma because the numbers are collected by a two-variable INPUT command.
A sector is split into two 128-byte display pages, which can be examined using the cursor keys, with or without SHIFT. The program always begins by reading track 0, sector 0 - the first of the two catalogue sectors. Adjacent sectors can be read simply by scrolling the cursor off the top or bottom of the two pages of display. Larger jumps can be made with the R command. A sector can only be written back to disc with the W command, and the program checks first that you really do intend to write a sector.
The current track and sector is displayed at the top of the display, but you can write a sector back to a different place on the disc if you have a reason to do so. Initially the current drive remains in force, and only when you issue a command such as V1 is the drive changed and the value displayed at the top of the screen.
The remaining commands are the same as for MEMZAP.
Sector 0
bytes 0 to 7 | First 8 characters of the disc title |
bytes 8 to 14 | Name of last file on disc (maximum 7 characters) |
byte 15 | File directory letter and lock status |
bytes 16 to 22 | Name of penultimate file |
... | |
... | |
... |
bytes 0 to 3 | Last 4 characters of disc title | |
byte 4 | Number of times the disc has been accessed for writing | |
byte 5 | 8×number of entries in catalogue | |
byte 6 (high nibble) | Startup option set by *OPT 4,n | |
byte 6 (low nibble) | Number of sectors on disc (&190 for 40 | |
and byte 7 | track discs, &320 for 80 track) | |
bytes 8 to 15 | Information on the last file on the disc, as follows | |
bytes 8 and 9 | Load address of file | |
bytes 10 and 11 | Execution address of file (&801F or &8023 for BASIC programs) | |
bytes 12 and 13 | File length in bytes | |
byte 14 | High bits of each number | |
byte 15 | Sector address of start of file (in hex) | |
bytes 16 to 23 | Information on the penultimate file | |
... | ||
... | ||
... |
Sector 0 00 55 74 69 6C 69 74 79 00 UtiLity. 08 4D 45 4D 4F 44 20 20 A4 MEMOD $ 10 44 43 4F 4E 56 20 20 A4 DCONV $ 18 56 45 52 49 46 59 20 A4 VERIFY $ 20 46 4F 52 4D 38 30 20 A4 F0RM80 $ 28 46 4F 52 40 34 30 20 A4 F0RM40 $ 30 21 42 20 20 20 20 20 24 !B $ 38 42 49 4F 52 54 48 4D 57 BIORTHMW 40 50 48 4F 54 4F 20 20 57 PHOTO W 48 50 4F 45 4D 20 20 20 57 POEM W 50 21 42 4F 4F 54 20 20 24 !BOOT $ Sector 1 00 00 00 00 00 06 D8 31 90 .....X1. 08 00 00 00 00 F1 20 01 4C ....q .L 10 00 19 1F 80 C9 01 01 4A ....I..J 18 00 28 00 28 00 02 01 48 .(.(...H 20 00 28 04 28 00 03 01 45 .(.(...E 28 00 28 00 28 00 03 01 42 .(.(...B 30 00 19 1F 80 BA 02 01 3F ....:..? 38 00 19 1F 80 1D 19 01 25 .......% 40 00 19 00 19 00 10 01 15 ........ 48 00 19 1F 80 B1 25 00 EF ....1%.o 50 00 30 00 30 0B 00 00 BB .0.0...;
Figure M.1 DISCZAP display for the BBC utility disc.
(The alternative disaster under Wordwise, obliterating the text in memory by 'loading' a nonexistent file when you meant to save it, can be recovered with MEMZAP, by tracking down the text which will still exist somewhere in memory, and saving it with *SAVE.)
10 INPUT "WHAT IS THE CAPITAL OF FRANCE" ,A$ 15 M=0 20 IF A$="PARIS" THEN GOTO 60 25 M=M+1 27 IF M=2 THEN 80 30 PRINT "WRONG, TRY AGAIN" 40 INPUT A$ 50 GOTO 20 60 PRINT "CORRECT" 70 END 80 PRINT "NO, THE ANSWER IS PARIS" 90 END
10 REM SUM OF THE FIRST N WHOLE NUMBERS 20 INPUT "HOW MANY NUMBERS",N 30 SUM=0 40 FOR J%=1 TO N 50 SUM=SUM+J% 60 NEXT J% 70 PRINT "SUM OF THE FIRST ";N;" WHOLE NUMBERS =";SUM 80 END
10 REM MASTERMIND 20 X=RND(10) 30 PRINT "WHAT NUMBER AM I THINKING OF?"' "(BETWEEN 1 AND 10)" 40 REPEAT 50 INPUT GUESS 60 UNTIL GUESS=X 70 PRINT "CORRECT"
10 REM GUESS THE NUMBER 20 X=RND(1000) 30 PRINT "WHAT NUMBER AM I THINKING OF?"' "(BETWEEN 1 AND 1000)" 35 I=0 40 REPEAT 42 IF I=40 THEN PRINT "GIVE UP! THE ANSWER IS ";X: GOTO 80 45 I=I+1 50 INPUT GUESS 52 IF GUESS>X THEN PRINT "TOO HIGH" 54 IF GUESS<X THEN PRINT "TOO LOW" 60 UNTIL GUESS=X 70 PRINT "CORRECT" 80 PRINT "YOU TOOK ";I;" GUESSES" 90 IF I>10 THEN PRINT "YOU HAVEN'T DISCOVERED THE SYSTEM YET" 100 IF I<=10 THEN PRINT "CONGRATULATIONS" 110 END
*KEY0 LISTO O |M |O |M *KEY1 LISTO 7 |M |N LIST |M
10 REM PRODUCT OF 10 NUMBERS 20 DIM NUM (10) 30 FOR J=1 TO 10 40 READ NUM(J) 50 NEXT J 60 PRODUCT=1 70 FOR J=1 TO 10 80 PRODUCT=PRODUCT*NUM(J) 90 NEXT J 100 PRINT "PRODUCT = ";PRODUCT 110 END 120 DATA 2,5,3,7,1,4,6,9,10,8
10 REM HYPERBOLIC SIN AND COS 20 REPEAT 30 INPUT "VALUE OF X (USE 0 TO FINISH)",X 40 C=FN_hcs(X) 50 S=FN_hsn(X) 60 Y=C*C--S*S: REM SHOULD EQUAL ONE 70 PRINT "COSH(X)="C 80 PRINT "SINH(X)="S 90 PRINT "COSH SQUARED - SINH SQUARED ="Y 95 PRINT 100 UNTIL X=0 105 END 110 DEF FN_hcs(X)=(EXP(X)+EXP(-X))/2 120 DEF FN_hsn(X)=(EXP(X)-EXP(-X))/2
Alternatively, we can print the results in columns
10 REM HYPERBOLIC SIN AND COS 15 @%=&20509: REM @% IS EXPLAINED IN FULL IN CHAPTER 11. THIS IS SETTING THE FORMAT TO 5 DECIMAL PLACES SO THAT THE OUTPUT IS IN NEAT COLUMNS 18 PRINT: PRINT " X COSH SINH TEST=1?" 19 PRINT 20 FOR X=0 TO 2.01 STEP 0.1 30 C=FN_hcs(X) 40 S=FN_hsn(X) 50 Y=C*C-S*S: REM SHOULD EQUAL ONE 60 PRINT ;X,C,S,Y 70 NEXT X 80 END 90 DEF FN_hcs(X)=(EXP(X)+EXP(-X))/2 100 DEF FN_hsn(X)=(EXP(X)-EXP(-X))/2
10 REM FAHRENHEIT/CENTIGRADE CONVERSION 20 INPUT "GIVE A TEMPERATURE IN FAHRENHEIT",TE 30 TC=FN_CENT(TF) 40 PRINT "TEMPERATURE IN CENTIGRADE ="TC 50 INPUT "GIVE A TEMPERATURE IN CENTIGRADE",TC 60 TF=FN_FAHR(TC) 70 PRINT "TEMPERATURE IN FAHRENHEIT="TF 80 END 90 DEF FN_CENT(T) 100 =(T-32)/1.8 110 DEF FN_FAHR(T) 120 =T*1.8+32
110 DEF PR0C_delay(CENTISEC) 160 ENDPROC 190 PROC_delay(RND(150))
Further modifications to eliminate the formal parameter are
110 DEF PROC_delay 150 UNTIL (100+START)<TIME 160 ENDPROC 190 PROC_delay
100 DEF PROC_LOWHIGH 110 REM finds the Largest and smaLLest numbers in array NOS of 10 numbers 120 LOW=NOS(1): HIGH=NOS(1) 130 FOR J=2 TO 10 140 IF NOS(J)>HIGH THEN HIGH=NOS(J) 150 IF NOS(J)<LOW THEN LOW =NOS(J) 160 NEXT J 170 ENDPROC
which can be tested with the following program
10 REM PROGRAM TO TEST PROC_LOWHIGH 20 DIM NOS(10) 25 PRINT "TYPE IN 10 NUMBERS, ONE PER LINE" 30 FOR J=1 TO 10 40 INPUT NOS(J) 50 NEXT J 60 PROC_LOWHIGH 70 PRINT 80 PRINT "LOWEST="LOW 90 PRINT "HIGHEST="HIGH 99 END
100 DEF PROC_PRIME(RANGE) 110 PRIMES(1)=1 120 LOCAL N,X,Y,Z 130 N=1 140 Y=2 150 REPEAT 160 N=N+1 170 PRIMES(N)=Y 180 REPEAT 190 Y=Y+1 200 X=1 210 REPEAT 220 X=X+1 230 Z=INT(Y/X) 240 UNTIL (Z*X=Y OR X*X>Y) 250 UNTIL X*X>Y 260 UNTIL N=RANGE 270 ENDPROC
10 INPUT "No. of prime numbers ",N 20 DIM PRIMES(N) 30 PROC_PRIME(N) 40 SUM=0 50 FOR J=1 TO N 60 SUM=SUM+PRIMES(J) 70 NEXT J 80 PRINT "Sum of first ";N;" primes = ";SUM 90 END
10 REM ON...GOTO DEMONSTRATION 20 REPEA T 30 INPUT "Give the time on a 24 hour cLock" ,ZTIME 40 ON ZTIME G0TO50,50,50,50 ,50,50,50,50,70, 70,70,70,90,90, 90,90,90,110,110,1 10,110,130,130,130 ELSE 150 50 GS$="MORNING" 60 GOTO 140 70 GS$="DAY" 80 GOTO 140 90 GS$="AFTERNOON" 100 GOTO 140 110 GS$="EVENING" 120 GOTO 140 130 GS$="NIGHT" 140 PRINT "GOOD ";GS$ 150 UNTIL TIME>24 160 PRINT "GOODBYE!"
10 X=TIME 20 TS=INT(X/100) 30 TM=INT(TS/60) 40 TH=INT(TM/60) 50 TD=INT(TH/24) 60 PRINT "Time ";TD;" days ";TH;" hours ";TM MOD 60; " minutes. ";TS MOD 60;" second"
10 REM PERPETUAL CALENDAR 20 DIM MON$(12),DAY(12) 30 MODE 0 40 INPUT "For which year do you want a calendar ",YEAR 50 IF YEAR<1800 THEN CLS: PRINT "Remember the year must be post 1800": GOTO 40 60 FOR I=1 TO 12: READ MON$(I),DAY(I): NEXT 70 DAY1=(((YEAR-1800)*365+(YEAR-1800) DIV 4)-(YEAR DIV 100 - YEAR DIV 400 -14)+3) MOD 7 80 IF ((YEAR DIV 4)*4=YEAR) AND ((YEAR DIV 400)*400 <>YEAR) THEN DAY(2)=29: DAY1=(DAY1+6) MOD 7 ELSE DAY(2)=28 100 CLS 110 PRINT TAB(38,0);YEAR 120 FOR J=0 TO 3 125 I=J*3+1: K=J*8+1: L=I 130 PRINT ;TAB(11,K);MON$(I);TAB(36,K);MON$(I+1);TAB(61,K); MON$(I+2) 140 PRINT STRING$(3," Su Mo Tu We Th Fr Sa") 150 REPEAT 160 PROC_DATES(L,J,DAY1) 170 DAY1=(DAY1+DAY(L)) MOD 7 180 L=L+1 190 UNTIL L=I+3 200 NEXT 210 PRINT TAB(0,31); 400 END 500 DEF PROC_DATES(LD,JD,SDAY) 520 DATE=1 530 CDAY=SDAY 540 REPEAT 550 PRINT ;TAB(((LD-1) MOD 3)*25+(CDAY MOD 7)*3+5,JD*8+(CDAY DIV 7) MOD 5 +3);DATE; 560 DATE=DATE+1 570 CDAY=CDAY+1 580 UNTIL DATE-1=DAY(LD) 600 ENDPROC 900 DATA January,31,February,28,March,31,April,30,May,31, June,30,July ,31,August,31,September,30,October,31, November,30,December,31
10 REM PERPETUAL CALENDAR 20 DIM MON$(12),DAY(12),SCRPO$(20,19) 25 FOR I=0 TO 19: FOR J=0 TO 20: SCRPO$(J,I)=" ": NEXT: NEXT 30 MODE 0 40 INPUT "For which year do you want a calendar ",YEAR 50 IF YEAR<1800 THEN CLS: PRINT "Remember the year must be post 1800": GOTO 40 60 FOR I=1 TO 12: READ MON$(I) ,DAY(I): NEXT 70 DAY1=(((YEAR-1800)*365+(YEAR-1800) DIV 4)-(YEAR DIV 100 - YEAR DIV 400 -14)+3) MOD 7 80 IF ((YEAR DIV 4)*4=YEAR) AND ((YEAR DIV 400)*400 <>YEAR) THEN DAY(2)=29: DAY1=(DAY1+6) MOD 7 ELSE DAY(2)=28 100 CLS 110 PRINT TAB(38,0);YEAR 120 FOR J =0 TO 3 125 I=J*3+1: K=J*8+1: L=I 130 PRINT ;TAB(11,K);MON$(I); TAB(36,K);MON$(I+1);TAB(61,K); MON$(I+2) 140 PRINT STRING$(3," Su Mo Tu We Th Fr Sa") 150 REPEAT 160 PROC_DATES(L,J,DAY1) 170 DAY1=(DAY1+DAY(L)) MOD 7 180 L=L+1 190 UNTIL L=I+3 200 NEXT 400 END 500 DEF PROC_DATES(LD,JD,SDAY) 520 DATE= 1 530 CDAY=SDAY 540 REPEAT 545 X=((LD-1) MOD 3)*7+(CDAY MOD 7): Y=JD*5+(CDAY DIV 7) MOD 5 547 IF DATE<10 THEN SCRPO$(X,Y)=" "+STR$(DATE) ELSE SCRPO$(X,Y)=STR$(DATE) 550 PRINT ;TAB(((LD-1) MOD 3)*25+(CDAY MOD 7)*3+5,JD*8+(CDAY DIV 7) MOD 5 +3);DATE; 560 DATE=DATE+1 570 CDAY=CDAY+1 580 UNTIL DATE-1=DAY(LD) 600 ENDPROC 900 DATA January,31,February,28,March,31,April,30,May,31, June,30,July,31,August,31,September,30,October,31, November,30,December,31 2000 PRINT ;TAB(38);YEAR: PRINT 2010 FOR K=0 TO 3: M=K*3+1 2020 PRINT;TAB(11);MON$(M);TAB(36);MON$(M+1);TAB(61);MON$(M+2) 2030 PRINT STRING$(3," Su Ma Tu We Th Fr Sa") 2040 FOR I=0 TO 4: I=K*5+L 2050 FOR J=0 TO 20 2060 IF (J MOD 7)=0 THEN PRINT ;" "; 2070 PRINT ;" ";SCRPO$(J,I); 2080 NEXT 2090 PRINT 2100 NEXT 2110 PRINT 2120 NEXT
10 DIM N(6),M(3) 20 FOR L = 1 TO 20 30 FOR I = 1 TO 6: N(I)=I: NEXT 40 PROC perm (3 ) 50 PRINT ;L;" ";M(1);" ";M(2);" ";M(3) 60 NEXT L 70 END 80 DEF PROC_perm(I) 90 IF I<>1 THEN J=RND(I+3): M(I)=N(J): N(J)=N(I+3): PROC_perm(I-1) ELSE M(I)-N(RND(I+3)) 100 ENDPROC
5 INPUT "Combination of N from R give N and R ",N,R 10 DIM N(R),M(N) 20 FOR L = 1 TO 20 30 FOR I = 1 TO R: N(I)=I: NEXT 40 PROC_perm(N) 50 PRINT ;L; 55 FOR J=1 TO N: PRINT" ";M(J);: NEXT 57 PRINT 60 NEXT L 70 END 80 DEF PROC_perm(I) 90 IF I<>1 THEN J=RND(I+R-N): M(I)=N(J): N(J)=N(I+R-N): PROCperm(I-1) ELSE M(I)=N(RND(I+R-N)) 100 ENDPROC
10 PRINT "INPUT ANY STRING" 20 INPUT A$ 30 L=LEN(A$) 40 B$=LEFT$(A$,INT(L/2)) 50 C$=RIGHT$(A$,L-INT(L/2)) 60 PRINT B$+ " EXTRA " +C$ 70 REM OR PRINT B$; " EXTRA " ;C$ WOULD DO
10 PRINT "INPUT ANY STRING" 20 INPUT A$ 30 FOR J=LEN(A$) TO 1 STEP -1 40 PRINT MID$(A$,J,1); 50 NEXT J 60 PRINT
130 UNTIL J=0 OR (LEN(A$)-LEN(B$))<(L-1)
10 PRINT "INPUT A NUMBER IN FIXED POINT OR EXPONENT FORM" 20 INPUT A$ 30 L=LEN(A$): D=0 40 FOR J = 1 TO L 50 IF MID$(A$,J,1)="E" THEN GOTO 110 60 IF MID$(A$,J,1)="." THEN D=J 70 NEXT J 80 B$=RIGHT$(A$,L+1-1)) 90 B=VAL(B$) 100 IF D>0 THEN PRINT 'B 110 PRINT '"END"
10 PRINT "INPUT ANY CHARACTER" 20 INPUT A$ 30 PRINT "ASCII CODE OF ";A$;" IS ";ASC(A$) 40 PRINT 50 PRINT "INPUT ANY ASCII CODE (33 TO 255)" 60 INPUT A 70 PRINT "THE CHARACTER ";CHR$(A);" HAS ASCII CODE ";A 80 PRINT 90 TIME=0: REPEAT: UNTIL TIME>=300 100 FOR J=33 TO 255 110 PRINT J;" ";CHR$(J) 120 TIME=0: REPEAT: UNTIL TIME>=20 130 NEXT J
25 DIM A$(LEN(A$)) 30 FOR J=1 TO LEN (A$) 40 A$(J)=MID$(A$,J,1) 60 FOR J=LEN(A$) TO 1 STEP -1: PRINT A$(J);: NEXT J 70 PRINT
10 PRINT "TYPE YOUR EXPRESSION AS A FUNCTION" 20 INPUT "OF X: ",EX$ 30 PRINT "TYPE UPPER AND LOWER LIMITS" 40 INPUT "OF X: ",A,B 50 FOR X=A TO B STEP (B-A)/10 60 PRINT X;" ";EVAL(EX$) 70 NEXT X
10 INPUT "TYPE THE AMOUNT IN PENCE: "AMT% 20 PDS%=AMT% DIV 100 30 PENCE%=AMT% MOD 100 40 PRINT "AMOUNT IS £";PDS%;" ";PENCE%;"p"
170 SCORE(PLAYER)=SCORE(PLAYER)-10*(ACE(PLAYER)>0 AND SCORE(PLAYER)<=11)
with a similar line for 260.
70 VDU 29,640;608;
and delete (or replace by zero) X0 and YO from lines 80, 90, 130 and 170. Proceed similarly for the other programs.
30 VDU 28,3,9,16,2
VDU 23,225,8,8,28,42,28,8,8,0
VDU 23,230,248,136,136,136,248,0,0,0 VDU 23,231,248,248,248,248,248,0,0,0 VDU 23,232,32,80,80,136,248,0,0,0 VDU 23,233,32,112,112,248,248,0,0,0 VDU 23,234,112,136,136,136,112,0,0,0 VDU 23,235,112,248,248,248,112,0,0,0
line 20 | should be DIM V(3) |
line 40 | should not be a REM |
line 200 | should not contain a minus sign |
line 220 | closing bracket omitted |
line 230 | should be T, not T$ |
line 230 | missing colon |
line 390 | must return to line 30, not 20 |
10 INPUT "TYPE THE NUMBER OF CARS: ",N 20 CH%=OPENOUT ("CARFILE") 30 FOR J = 1 TO N 40 PRINT "TYPE THE NAME OF THE CAR" 50 INPUT CAR$ 60 PRINT#CH%,CAR$ 70 NEXT J 80 CLOSE#CH%
10 PRINT "LIST OF CARS": PRINT 20 CH%=OPENIN ("CARFILE") 30 REPEAT 40 INPUT#CH%,CAR$ 50 PRINT CAR$ 60 UNTIL EOF#CH% 70 CLOSE#CH%
65 IF LEN(ITNM$)+LEN(TPE$)+9>32 THEN PRINT "YOUR RECORD IS TOO LONG: RE-INPUT": GOTO 40
1015 IF RECNO*32>EXT#CH% THEN PRINT "THAT RECORD NUMBER DOES NOT EXIST": GOTO 1080
1075 PROC_modify(RECNO) 3000 DEF PROC_modify(RECNO) 3010 INPUT "DO YOU WANT TO CHANGE THE QUANTITY (Y/N)",YN$ 3020 IF LEFT$(YN$,1)="N" THEN ENDPROC 3030 INPUT "TYPE THE NEW QUANTITY: "QU% 3040 PTR#CH%=RECNO*32 3050 PRINT#CH%,ITNM$,TPE$,QU% 3060 ENDPROC
10 CH%=OPENIN( "INVENT") 20 C=0 30 REPEA T 40 C=C+1 50 PRINT ;'BGET#CH%;" "; 60 IF C=8*INT(C/8) THEN PRINT 70 UNTIL EOF#CH% 80 CLOSE#CH%
52 L%=LEN(CAR$) 54 IF L%>10 THEN PRINT "NOT MORE THAN 10 CHARACTERS" :GOTO 50 56 CAR$=CAR$+STRING$(10-L%," ")
10 CH%=OPENIN( "CARFILE") 20 PRINT "WHICH CAR DO YOU REQUIRE (1,2,3,...)" 30 INPUT N 40 PTR#CH%=(N-1)*12 50 INPUT#CH%,CAR$ 60 PRINT "CAR ";N;" IS ";CAR$ 70 CLOSE#CH%
*KEY 0 RUN |M *KEY 1 LIST |M *KEY 2 AUTO |M *KEY 3 RENUMBER |M *KEY 4 *RENAME *KEY 5 *DELETE
300 DEF PROC_textprint(L) 310 LOCAL J,K,M 385 M=0 390 REPEAT 395 M=M+1 405 IF T$(M+K)=CHR$(13) THEN J=M 410 UNTIL M>=J-1 460 ENDPROC
Then renumber the resulting procedure to start at 2000 instead of 300. Append the procedure to Example 9.10, and make further changes to the program, as follows
525 DIM T$(3500) 700 760 L=L+1 770 T$(L)=CH$ 780 UNTIL EOF#CH% OR L>=3500 784 IF (OP% AND 4)=4 THEN VDU 2 786 PROC_textprint(L)
A minor problem with this program is that, because it now stores the text as single characters in the string array T$, it is very wasteful of memory. Much larger files could be read if the data was poked directly into memory with the indirection operator instead of into an array. This can be achieved by the following further changes to the program above. As a further refinement, a choice of page widths is offered, to accommodate output to a printer, or use in Mode 0 or Mode 3.
525 BA=&2500 682 PRINT "What page width do you require?" 684 INPUT PGW 770 ?(BA+L)=ASC(CH$) 780 UNTIL EOF#CH% OR L>&5000: REM REDUCE VALUE OF &5000 IF NOT IN MODE 7 782 ?(BA+L+1)=0 784 IF (OP% AND 4)=4 THEN VDU 2 786 PROC_textprint(L,BA) 2000 DEF PROC textprint(L,BA) 2010 LOCAL J,K,M,CH$ 2040 J = PGW+2 2060 J = J-1: CH$=CHR$(?(BA+J+K)) 2070 UNTIL CH$ = " " OR CH$ = CHR$(0) OR (CH$ = "-" AND J<PGW+1) OR J=0 2080 IF J = 0 THEN J = PGW: REM WORD TOO LONG TO FIT 2115 CH$=CHR$(?(BA+M+K)) 2120 PRINT CH$ ; 2130 IF CH$=CHR$(13) THEN J=M 2145 CH$=CHR$(?(BA+J+K)) 2150 IF CH$ <> " " THEN PRINT CH$; 2160 IF J<PGW OR CHR$(?(BA+PGW+K)) = " " OR CHR$(?(BA+PGW+K)) = "" THEN PRINT
10 FOR J=7 TO 0 STEP -1 20 MODE J 30 PRINT "PAGE = ";PAGE 40 PRINT "TOP = ";TOP 50 PRINT "HIMEM = ";HIMEM 60 PRINT "LOMEM = ";LOMEM 70 PRINT "PROGRAM SIZE = ";(TOP-PAGE) 80 PRINT "FREE SPACE = ";(HIMEM-TOP) 90 PRINT "PRESS ANY KEY TO CONTINUE" 100 A$=GET$ 110 NEXT J
10 PRINT "TYPE THE STARTING ADDRESS FOR STRING" 20 INPUT ADDR$ 25 ADDR=EVAL(ADDR$) 30 PRINT "TYPE THE STRING" 40 INPUT A$ 50 FOR J=0 TO LEN(A$)-1 60 ADDR?J=ASC(MID$(A$,J+1,1)) 70 NEXT J 75 J=LEN(A$) 80 ADDR?J=13 90 PRINT "STRING WAS: ";$ADDR
20 A$=GET$
10 MODE 6 20 VDU 23,1,0;0;0;0; 30 *FX 4 , 1 40 ST$="*" 50 CH=20: CV=12 60 PRINT TAB(CH,CV);ST$; 70 REPEAT 80 A=ASC(GET$)-135 90 PRINT TAB(CH,CV);" "; 100 IF A>0 AND A<3 THEN CH=CH+2*A-3 110 IF A>2 AND A<5 THEN CV=CV-2*A+7 120 IF CV>24 THEN CV=24 130 IF CV<0 THEN CV=0 140 IF CH>39 THEN CH=39 150 IF CH<0 THEN CH=0 160 PRINT TAB(CH,CV);ST$; 170 UNTIL A=0
30 PRINT "PRESS THE KEY SPECIFIED" 105 K=64+RND(26) 120 PRINT TAB(15,12);"PRESS THE KEY: ";CHR$(K) 160 UNTIL INKEY(0)=K
70 IF INKEY(-99) THEN PR0C_wait 1030 UNTIL NOT INKEY(-99)
1010 DEF PROC_table 1020 LOCAL J,K 1030 FOR J=1 TO 5 1040 PRINT TAB(7*J-7);HEAD$(J); 1050 NEXT J 1060 PRINT '' 1070 FOR K=1 TO 10 1080 FOR J=1 TO 5 1090 PRINT TAB(7*J-7);A$(K,J); 1100 NEXT J 1110 PRINT 1120 NEXT K 1130 ENDPROC
1000 DEF PROC_clock(HOUR1,SEC1,HOUR2,SEC2) 1010 PRINT TAB(0,7);SPC(16); 1020 PROC_display(HOUR1,MIN1,SEC1) 1030 PRINT SPC(16) 1040 PRINT TAB(0,15) ;SPC(16); 1050 PROC_display(HOUR2,MIN2,SEC2) 1060 PRINT SPC(16) 1070 ENDPROC 2000 DEF PROC_display(HOUR,MIN,SEC) 2010 LOCAL HOUR$,MIN$,SEC$ 2020 HOUR$=STR$(H0UR): IF HOUR<10 THEN HOUR$="0"+H0UR$ 2030 MIN$=STR$(MIN): IF MIN<10 THEN MIN$="0"+MIN$ 2040 SEC$=STR$(SEC): IF SEC<10 THEN SEC$="0"+SEC$ 2050 PRINT HOUR$; ":";MIN$;":";SEC$; 2060 ENDPROC
5 MODE 0 10 FOR J = 1 TO 20 20 I=RND(1000) 30 R1=1E5*RND(1) 40 R2=1E5*RND(1) 50 D1=RND(1) 60 D2=RND(1) 70 PROC_formprint(I,0,5) 80 PROC_formprint(R1,2,10) 90 PROC_formprint(R2,2,10) 100 PROC_formprint(D1,3,7) 110 PROC_formprint(D2,3,7) 120 PRINT 130 NEXT J 140 END
*CAT NEW 10 PRINT 20 INPUT "WHICH PROGRAM DO YOU WANT TO RUN",P$ 30 CHA I N P$ RUN
10 REPEAT 15 CLS 20 PRINT '' 30 PRINT "WHICH MATHEMATICAL OPERATION WOULD YOU LIKE?" 50 PRINT ''"1. RECIPROCAL OF N" 60 PRINT '"2. 10 TO POWER N" 70 PRINT '"3. FACTORIAL OF N" 80 PRINT '"4. PI TO N DECIMAL POINTS" 90 PRINT '"5. N RANDOM NUMBERS" 100 PRINT '"6. END" 120 PRINT '''"TYPE THE NUMBER OF YOUR CHOICE" 125 REPEAT 130 A=VAL(GET$) 135 UNTIL A>0 AND A<7 140 CLS 150 IF A=6 THEN END 160 PRINT "TYPE N: "; 170 N=VAL(GET$) 180 ON A GOSUB 200,300,400,500,600 ELSE END 190 PRINT ''"PRESS ANY KEY TO CONTINUE" :C$=GET$ 195 UNTIL FALSE 200 PRINT '"RECIPROCAL OF ";N;" IS ";1/N 210 RETURN 300 PRINT '"10 ^ ";N;" IS ";10^N 310 RETURN 400 PROD=1 410 FOR J=1 TO N 420 PROD=PROD*J 430 NEXT J 440 PRINT '"FACTORIAL ";N;" IS ";PROD 450 RETURN 500 PW=1 510 FOR J=1 TO N: PW=PW*10: NEXT J 520 P=INT(PI*PW)/PW 530 PRINT '"PI TO ";N;" DECIMAL POINTS IS ";P 540 RETURN 600 PRINT 'N;" RANDOM NUMBERS:"' 610 FOR J=1 TO N: PRINT RND(1): NEXT J 620 RETURN
Lostock Software
13 Cranborne Close
Lostock
Bolton
Lancs BL6 4JG
Please apply directly to Lostock Software, not to Addison-Wesley Publishers Ltd.