Interactive teletext techniques
Tony Rudkin offers some Basic routines to give accessing Ceefax
that personal touch
READERS who took advantage of The Micro User's special offer
and bought the teletext system will be well aware of the tremendous
amount of free information transmitted by the four TV stations.
The simple use of the *TELETEXT command converts the computer
into a teletext terminal allowing pages from any channel to be
viewed and stored, giving easy access to information on TV programmes,
travel, weather, news and so on.
Although it is simple to view the teletext pages, it is less
easy to extract information from them, The data format used is
quite complex, with a 40 character line of text being transmitted
as 42 eight bit bytes.
The first two bytes contain information which does not appear
on the screen. The remaining 40 bytes are in a form which is suitable
for direct display only when interpreted by the teletext video
circuit in a BBC B or Master.
With care this same data can be converted into a form which
can be used in Basic programs. There it can do such potentially
useful things as keeping a record of share prices, listing currency
exchange rates and providing a real-time clock for the computer.
You can even automatically store data for later use in applications
such as your own carousel-type show.
Most people who have bought the teletext system recently will
also have bought the Advanced Teletext System (ATS) rom. This
allows much simpler access to the free software transmitted by
BBC2 and provides more powerful facilities when used in Basic
programs than the standard teletext rom.
Serious teletext users are recommended to upgrade to the ATS
rom at the earliest possible opportunity. This is especially applicable
to computers which are not fitted with shadow memory, as the standard
teletext rom consumes over 5k of the memory compared with a mere
256 bytes for the ATS one.
For the purposes of this article either rom may be used, and
where there are different commands both are indicated in the program
listings.
The techniques described have been chosen for their simplicity
so you can experiment with the teletext facilities.
The teletext roms have limited facilities for operation within
Basic programs, and a typical example is given in Program I. This
simply selects the teletext mode, the TV channel to be accessed
and the page number of interest.
10 REM Sample Teletext Program
20 REM For Advanced Tele text System rom
30 REM (C) Micro User
40 REM For standard Tele text ROM replace
50 REM *TTXON in line 90 with *TELESOFT
60 REM and *TTXOFF in li ne 140 with *ADFS, *DISC or *TAPE 70
:
80 MODE 7
90 *TTXON
100 *BBC1
110 *PAGE 171
120 *TRANSFER 6000
130 *DISPLAY 6000
140 *TTXOFF
Program I: Reading a teletext page
Then a sequence of commands transfers data from this page to
the computer memory (starting at address &6000), displays
the page on the screen and finally disables the teletext rom.
In many ways this process emulates the terminal mode offered
by the teletext rom. But since it is written in Basic it allows
much more flexibility, and can easily automate the capture and
display of regularly-accessed pages.
It is worth noting that the *PAGE command which selects the
page of interest can be extended further to specify which sub-page
within the chosen page is accessed. For example, *PAGE 1300002
would select sub-page 2 of page 130.
Having captured a teletext page in memory, further work is required
to make the information useful. This simply means that the special
teletext control codes need to be removed and the data converted
to printable Ascii characters.
This is done by a Basic procedure (PROCConvert) which examines
each active data byte and takes action depending on its value.
If the byte value is greater than 128 it is reduced by 128 and
if less than 32 the byte is replaced with a space character (32).
The procedure, shown in Program lla and IIb, requires the start
value of the memory area to be transferred, and is called with
a Basic line such as:
60 PROCConvert(&6000)
to indicate that the page data to be converted is located in
the memory from address &6000 onwards.
1000 DEF PROCConvert(Addre ss%)
1010 FOR Row%=0 TO 23
1020 FOR Column%=0 TO 39
1030 Pointer%=Address%+Row %*40+Column%
1040 Byte%=?Pointer%
1050 Byte%=Byte%AND&7F
1060 IF Byte%<32 THEN Byte %=32
1070 ?Pointer%=Byte%
1080 NEXT Column%
1090 NEXT Row%
1100 ENDPROC
1110 :
2000 DEF PROCGetText(Addre ss%,Row%)
2010 Text$=""
2020 IF Row%>23 OR Row%<0 THEN ENDPROC
2030 Pointer%,=Address%,+Row %*40
2040 Pointer%?40=13
2050 Text$=$(Pointer%+1)
2060 ENDPROC
Program lla: Converting text, TFS rom
1000 DEF PROCConvert(Addre ss%)
1010 fOR Row%=0 TO 23
1020 FOR Column%=2 TO 41
1030 Pointer%=Address%+Row %*42+Column%
1040 Byte%=?Pointer%
1050 IF Byte%>=128 THEN By te%=Byte%-128
1060 IF Byte%<32 THEN Byte %=32
1070 ?Pointer%=Byte%
1080 NEXT Column%
1090 NEXT Row%
1100 ENDPROC
1110 :
2000 DEF PROCGetText(Addre ss%,Row%)
2010 Text$="":I%=0
2020 REPEAT
2030 Pointer%=Address%+1+I %*42
2040 I%= I%+1
2050 UNTIL ?Pointer%=Row% OR I%=24
2060 IF I%<24 Pointer%?41= 13:Text$=$(Pointer%+2)
2070 ENDPROC
Program IIb: Convening text, TFS rom
The address value passed in the procedure call must agree with
the address value which follows the *TRANSFER command.
The procedure takes a few seconds to complete the conversion
and creates an area of memory containing information which can
easily be transferred into a Basic program using the second procedure
given in Program II.
This Basic procedure identifies the start of the required row
of text and then transfers the text on that line to a Basic string
variable called Text$.
The required row number is passed to the procedure with the
start address by enclosing the address value and row number in
brackets after the procedure name. So a program sequence of the
form:
70 PROCGetText(&6000,6)
80 PRINT Text$
would search from address &6000 for row 6 and extract the
text information ready for it to be printed to the screen in line
80.
For the ATS rom the procedure PROC-Gettext simplifies its search
for row numbers by looking only at those memory locations that
actually contain row number information.
These locations occur every 42 bytes and once a match is found
the 40 characters of text can be extracted.
It should be noted that the teletext signal convention does
not require all rows of text to be transmitted and any row which
is not found is assumed to be blank.
For the standard teletext rom the data is stored without the
additional two bytes and the position of the start of the line
of text is calculated directly from the row number.
When using PROCGettext you should remember that the 24 teletext
rows are numbered from 0 to 23, and any attempt to request text
from rows outside this range will also result in a blank line
being returned.
Having now created a simple method of extracting text information
from teletext data we are in a position to use these techniques
in a practical way.
A typical example might be the extraction of a news item transmitted
on BBC1 Ceefax page 102.
If we ignore the header information appearing at the top of
the page, the real text is contained in rows 5 to 23. This can
be extracted and sent to a printer with a very simple program
of the form shown in Program III.
10 REM Sample Teletext Program
20 REM by Tony Rudkin
30 REM (c) Micro User
40 REM For standard tele text rom replace
50 REM *TTXON in line 90 with *TELESOFT
60 REM and *TTXOFF in line 200 with *ADFS, *DISC or *TAPE
70 REM Add lines 1000 on , from Program IIa or lIb
80 MODE 7
90 *TTXON
100 *BBC1
110 *PAGE 102
120 *TRANSFER 6000
130 PROCConvert(&6000)
140 VDU 2:REM Printer On
150 FOR R%=5 TO 23
160 PROCGetText(&6000,R%)
170 PRINT Text$
180 NEXT R%
190 VDU 3:REM Printer Off
200 *TTXOFF 210 END
Program III: Printing a news page
Owners of the Master series computers will have probably discovered
the advantages of having a real time clock which they can use
in their programs where time or date information is needed.
With a few additional lines of Basic, owners of BBC B Micros
can also have access to an extremely accurate real-time clock
using data recovered from teletext pages.
The techniques described earlier take a few seconds to extract
text information once the teletext page has been transferred into
memory, and this delay introduces an error which some users would
consider to be unacceptable.
To overcome this problem, a dedicated routine is given in Program
IV which extracts the time and date information in a much faster
way - typically seconds. PROCCIockDate gets the time and date
information and puts it into two Basic variables called Clock$
and Date$. These can then be displayed on the screen or transferred
to a printer or file.
10 REM Clock for Standar d Teletext rom
20 REM by Tony Rudkin
30 REM (c) Micro User
40 MODE7
50 PROCTimeDate
60 PRINT"Time is "Clock$
70 PRINT"Date is "Date$
80 END
90 :
3000 DEF PROCTimeDate
3010 *TELESOFT
3020 *BBC1
3030 *PAGE 100
3040 TRANSFER 7800
3050 FOR I%=&7814 TO &7827
3060 ?I%=?I% AND &7F
3070 NEXT I%
3080 ?&7828=13:?&7825=58
3090 A$=$&7814 3100 Clock$=RIGHT$(A$,8)
3110 Date$=LEFT$(A$,10)
3120 *DISC
3130 ENDPROC
Program IVa: Clock for TFS rom
10 REM Clock for ATS rom
20 REM by Tony Rudkin
30 REM (c) Micro User
40 MODE7
50 PROCTimeDate
60 PRINT'Time is "Clock$
70 PRINT"Date is "Date$
80 END
90 :
3000 DEF PROCTimeDate
3010 *TTXON
3020 *BBC1
3030 *PAGE 100
3040 *TRANSFER 7800
3050 FOR I%=&7816 TO &7829
3060 ?I%=?I% AND &7F
3070 NEXT I%
3080 ?&782A=13:?&7827=58
3090 A$=$&7816
3100 Clock$=RIGHT$(A$,8)
3110 Date$=LEFT$(A$,10)
3120 *TTXOFF
3130 ENDPROC
Program IVb: Clock for ATS rom
Master owners can also use the procedure as a very effective
way of updating their real-time clocks by simply adding a line
of the form:
25 TIME$=Clock$
This will reset the internal clock time in line with the teletext
information and can be a useful routine for updating the clock
whenever we change from Greenwich Mean Time (winter time) to summer
time, as well as for taking out the odd few seconds of error which
creep in over the weeks.
The techniques given here are just an introduction to what can
be achieved by using simple teletext rom commands within Basic,
and will allow you to develop personalised routines to access
Ceefax and Oracle pages.
Even greater flexibility and speed can be achieved using more
complex command forms, but the time savings thus gained are unlikely
to be very important for most programs.