By way of example, several scripts are provided with WinTTX:
These are examples of the sorts of things that can be achieved with the teletext script language.
The script language itself is fairly simple, tailored to exactly what it has been designed for. Thus, it provides a way to pass messages to the user but there is no provision for, say, drawing on the screen. Such a facility would not be useful in processing teletext frames!
Perhaps the main problem that you will encounter is differences in file naming and paths between the two systems. For example, "<Teletext$Pages>.MyPage" would be an invalid filename under Windows, and likewise "whatever.txt would be invalid under RISC OS (translating to "whatever\txt." in Win/DOS terms).
It is possible to write scripts that work equally on both systems. To do so, you should take advantage of the differences between !Teletext which offers channel presets, and WinTTX that expects a UHF channel. This, requesting the channel preset number under WinTTX will always return "-1", as this code demonstrates:
set A to status(channel) if (A ! -1) goto("riscoscode") ; this stuff is Windows code [...blah blah - WinTTX specific stuff...] go("continue") .riscoscode ; this stuff is RISC OS code [...blah blah - !Teletext specific stuff...] .continue ; everybody meets back here
Of course, if you only have the one platform or if you don't mind writing slightly different scripts for each, you can dispense of this and just write using the facilities relevant to your version of the teletext software you are using.
Where relevant, differences between RISC OS and Windows script commands will be noted. There is also a look-up chart of all commands and which versions of the interpreter they may be found within.
A = 1 * 2 + 5 / 2
Such problems are impossible in the teletext script as it does not support that level of calculation. Instead, you would write:
(note we are using the left-to-right interpretation here)set A to 1 ; A = 1 mul(A, A, 2) ; * 2 add(A, 5) ; + 5 div(A, A, 2) ; / 2
The script file is executed at the beginning, and continues until it reaches a quit() (normal exit), a terminate() (abandon on problem), an error, or reaching the end of the script file.
The primary difference between quit() and terminate() regards the "call stack" - which is described in just a moment. If there is an active call stack when you quit(), you will be warned. If you instead terminate(), there is no such warning. So you should use terminate() when you have to 'just give up'.
Now, you are asking, "what's a call stack?". Well, no language is useful unless it can take jumps. The example above where we determine if the machine is RISC OS or Windows, you see we used the go() command to jump to a label, that is, a line with a name beginning with a '.' character. This is all described in more detail.
Well, we can crank it up a level by jumping to our label using the command call(), and what that does it is pushes our current 'position' in the script into the 'call stack'. We jump to the label, do whatever, and then we'll use the return() command to take the last-saved position off of the call stack and go back there. In this way, simple procedures can be written. You can see an example of this in the weather script - the code to convert celsius to fahrenheit is called is just such a way. Again, this is described in more detail.
INTEGER | FLOAT |
A | Q |
B | R |
C | S |
D | T |
E | U |
F | V |
G | W |
H | X |
I | Y |
J | Z |
K | |
L | |
M | |
N | |
O | |
P |
Speaking of accuracy, all floats are constrained to nine decimal places, so that WinTTX and !Teletext running on standard BBC BASIC V (not the FP version) should give the same results; however if you are making comparisons with floating point values, it is always best to flatten() down to the level of accuracy that is actually required.
(this copies the characters from position 30,17 to 40,17.set A to 30 .reportloop set B to char(A, 17) filewritebyte(B) A++ if (A [ 40) go("reportloop")
Where strings are required as input, such as to the userchoice() command, you can:
message("Please set satellite receiver to \"arte\" (channel FAV:29)")
Note that the use of "\n" and "\"" are suppressed in places where filenames are expected.
Note that the RISC OS script interpreter does not support "\n" and "\"".
One you have retrieved data using getframe() or getframes(), you can use selectframe() or selectframes() to make a cached frame 'current'. Only one frame can be current, but you can switch which is current as you wish, even to the extent of copying from one frame to another byte by byte.
When a frame is 'current', you can read bytes from the frame using set <var> to char(<x>, <y>); and you can write bytes to the frame using setchar().
You can also blank entire lines using omitline() (which has special significance for file output).
When you have made the necessary alterations, you can either write the frame to a file using writeframe() or writeframes(), or you can push the frame back into the cache (replacing the current cached one) using storeframe().
Under RISC OS, on a 40MHz ARM710 processor, the teletext software, when in use, loads the system between 15% and 60% (depending on what it is doing), with an average loading of around twenty-thirty percent. When the script is running, this may go up to around forty percent (again depending on what is happening). Some scripts may take in the order of ten minutes to execute.
The system is designed to be used multitasking, where you start a script and then forget about it for a while.
Please note that the timings were taken on my RiscPC700 with Ran Mokady's !Usage, and is subjective to the other tasks running on your system, and the system itself.
There are currently no timings for system loading under Windows; and such assessment is not terribly relevant for I am using a 450MHz machine running XP. It 'feels' comfortable, doesn't drag the machine down. The Windows process scheduling system means that it often seems to me as if other things are holding up WinTTX, rather than the other way around!