Last year, when I was trying to figure out how to convert an IBM program to Sinclair BASIC for my 2068, I wrote a letter to Alan Pywell to ask him how to he would convert the following IBM line…
ON RO GOSUB 1100, 1140, 1200, 1350…(etc.)
I thought I had found a fairly good solution. I believe I used IF statements (IF RO=1 THEN GOTO 1100, etc.) but Alan Pywell had a much better way of doing it. Actually a couple better ways. The rest of this article is from his letter…
ON RO GOSUB 1100, 1140, 1200…etc.
This is basically a “caculated Gosub,” since the computer has to calculate the destination. The good news is “our” computers also do calculated Gosubs–the only (slight) difference is that the destination numbers must be equally spaced (a way round this follows shortly!). I will write as if your knowlede is zero–forgive me if I state the obvious occasionally as this is better than leaving out a snippet of vital info! “Our” calculated destinations also differ from those on lesser computers because we can tell the Spectrum or QL what the calculation is to be. Lesser BASICS “expect” a line number and complain if they don’t get one. “Our” machines don’t “expect” anything–they always call a “full-expression evaluator” to sort out the destination. Thus GOSUB 1000-(10*XY)+A/B is a legitimate command. Incidently, it is this full expression evaluator that helps to make Sinclair BASICS relatively slow. Another legitimate command is GOSUB 5000+RO. Thus:-
100 GOSUB 5000 + RO
110 ---
120 --- etc.
5001 PRINT "This is Room 1: RETURN
5002 PRINT "This is Room 2: RETURN
etc.
There is the problem that the line numbers you quoted are not evenly spaced. If you cannot juggle the line numbers so that PRINT lines are evenly spaced then you need to read youR line numbers from DATA statements. We now make use of the full expression evaluator to calculate a line number for RESTORE.
100 RESTORE 6000+RO
110 READ X
120 GOSUB X: REM X=5000 or 5050 or 5110, etc., etc. depending on
value of RO
5000 PRINT "Room Number 1" : RETURN
5050 " " " 2" : "
5110 " " " 3" : "
6000 DATA 5000 : REM READ LINE NUMBERS TO GOSUB TO
6001 DATA 5050 (copy these numbers from the original
6002 DATA 5110 ON RO GOSUB)
Reading the line numbers as above is somewhat cumbersome really (ask a purist!!) but it greatly simplifies translation from other BASICS, and it works! Of course, if you’re writing a program from scratch, just ensure that your GOSUB destinations are evenly spaced. They don’t have to separated by 1, as above, you could separate them by say 10, or 100.
GOSUB 5000 + 10 * RO (5010, 5020, 5030, etc.)
GOSUB 5000 + 100 * RO (5100, 5200, 5300, etc.)
Having said all that, when writing an adventure game from scratch, don’t use a PRINT line for every room — you’ll have the purists howling for your blood! This is the method I used to use on the Spectrum. Somewhere in the start-up routine, DIM a string array to the number of rooms by the length of each room description, i.e. DIM R$(19,32) would allow for 19 rooms each with one line of text. DIM R$(19,64) would allow for two lines of text. PRINTING a room description requires a mere one line:
100 PRINT R$ (RO, 1 TO) <-- this looks strange but it works!
So, how to put the descriptions into R$? Put them into DATA statements than READ them is the obvious answer. But on the Spectrum I was always short of RAM space, so why store the text twice? (Once in R$, once in DATA statements.)
I used to enter the description in direct mode (i.e., omit line number) as I needed them. For example, say I’ve written the adventure to ROOM 10. Now I want to “do” ROOM 11. I would type LET R$(11)= “This is ROOM 11” — with no line numbers. To test, type PRINT R$(11, 1 TO). (The “1 TO” may not be necessary on the Spectrum, I can’t remember.)
When you save a Spectrum prog the variables are saved also. BUT — don’t use RUN or NEW! Use GOTO 1 or whatever, or your variables, including room descriptions, will be wiped out. If you’re not short of RAM space, use DATA satements, as in the following method, which I use on the QL.
100 RESTORE 28000 + RO
110 READ room_desc$ : PRINT room_desc$
28001 DATA "This is Room One"
28002 DATA "This is Room Two"
etc.
You can also use this method for object descriptions. It is very easy to implement long and short descriptions — let me know if you want more info.
Alan Pywell’s address is — [address omitted] — England {copied by R. Blizzard}