Return Key Mode

article by Les Ellingham, program by John Poynter

 

Issue 8

Mar/Apr 84

Next Article >>

<< Prev Article

 

 

 

Would you believe that a home computer could write its own programs or automatically add to a program you have written? Ask any other computer owner if this is possible and they will probably tell you it is not, but you bought the best and one of the many unique features of the Atari is what is termed the 'Return Key Mode' or 'Forced Read Mode'. This facility allows you to write a program that can automatically add to itself or delete parts of the original program.

John Poynter's program accompanying this article shows a practical demonstration of this feature by providing a Data file that will automatically extend itself as more data is input, but before looking at the program let's see what this 'Return Key Mode' is.

Only one memory location is involved and we must POKE this to achieve the desired result. The location is 842 which is part of the Input/Output Control Block (IOCB) zero which is normally used for the screen editor. The content of this location is usually 12 which will cause input to be read from the keyboard and written to the screen. If however we POKE this location with 13 the IOCB will then read from the screen and will treat the screen as an input device just the same as the keyboard. What happens in effect is that the computer automatically 'presses' the RETURN key for you and enters all the information displayed on the screen.

Only three simple steps are required to use this facility

1. POSITION the cursor at the top of the data you wish to enter.
2. POKE location 842,13.
3. Reset location 842 and CONTinue the program.

ADDING LINES

 

Let's look first at Example 1 to see how simple it is to use the Return Key Mode. Type in the program, LIST it out and then RUN it. Amazing isn't it? Line 10 simply clears the screen and line 100 prints out the lines you are going to enter - note the POSITION statement which we will come to later. Line 110 prints CONT at the bottom of the screen so that when the Return Key Mode is activated, it will execute this command and continue the program. Line 120 positions the cursor at the top of the screen ready for the Return Key Mode which is activated by the POKE in line 130. Line 130 also STOPs the program which is essential for the Return Key Mode to operate. Line 140 resets location 842 to accept normal input from the keyboard and line 150 is a simple delay loop before line 160 clears the screen and LISTs out your revised program.

10 ? CHR$(125)
100 POSITION 2,4:FOR I=20 TO 90 STEP 10:? I;" REM NEW LINES HERE":NEXT I
110 POSITION 2,22:? "CONT"
120 POSITION 2,0
130 POKE 842,13:STOP

140 POKE 842,12
150 FOR W=1 TO 200:NEXT W

160 ? CHR$(125):LIST

The routine is short and simple but there are one or two ground rules which must be followed. The cursor must be placed above the lines you wish to enter but you must also allow sufficient space for the message STOPPED AT LINE xxx which will be printed after the STOP command. If for instance your lines were printed at position 2,0, the STOPPED message would overwrite them giving an error. This is why line 100 commences with POSITION 2,4. Secondly the CONT command must follow the lines you wish to enter but does not need to follow immediately. I have placed the CONT command near the bottom of the screen to allow a varied number of lines to be inserted. There is a limit to the number of lines which can be entered at one time as they must appear on the screen between the STOP message and the CONT command but of course there is no reason why the routine cannot be called a number of times.

DELETING LINES

 

So how do we delete part of the program? Simple, we just list out the line numbers just as we would in direct editing. RUN example 1 and then change line 100 to

100 POSITION 2,4:FOR I=20 TO 90 STEP 10:? I:NEXT I

RUN it again and your newly added lines are gone.

THE SECRET METHOD

One drawback of the example given is that you can see the lines being listed out and it looks untidy and will look rather strange in the middle of a program. The simple way to disguise this is to set the colour of the text to the same colour as the background prior to executing the program. Add lines 95 and 155 and RUN it again.

95 SETCOLOR 1,9,4
155 SETCOLOR 1,9,10


There. If you did not know how it worked, you would probably think nothing had happened but it has and you have learned a very powerful new programming tool.

Now take a look at John Poynter's Data File program. The program is a simple record-keeping file that can be used for all manner of records from addresses to recipes to collections. The only options are to enter or read data or save the program. You cannot delete or edit entries but it achieves what it set out to do which was to find a way to accept Data input without breaking into the program. There are several additions which could be made - why not try them? How about a routine to delete entries, or a way to accept commas in data entry or to format the screen so that only one record at a time is shown to prevent the scrolling.

You have the basic framework and the Return Key Mode allows you to develop some very sophisticated and powerful Data Flies. If you come up with any improvements to the program, send them in for others to share.


AtariLister - requires Java

top