   10REM > telstar
   20:
   30REM This is a basic Viewdata/Videotex client written in BBC BASIC. but
   40REM using some Matrix Brandy extensions. For instance, the networking
   50REM interface is a local extension, as is the screen memory access and
   60REM the *WinTitle command.
   70:
   80VER$="Viewdata client version 20231022"
   90:
  100IF INKEY(-256) <> &4D THEN PRINT "This program works on Matrix Brandy for RISC OS or SDL only.":END
  110SYS"Brandy_Platform" TO ,,,sdl%,,leg%
  120IF sdl% = 0 AND ((leg% AND &F0) <> &A0) THEN PRINT "This program works on Matrix Brandy for RISC OS or SDL only.":END
  130:
  140SYS"OS_Byte",229,1: SYS "OS_Byte",4,1
  150OSCLI"Key1|_":OSCLI"KEY2"+CHR$(130):OSCLI"KEY3"+CHR$(131)
  160ON ERROR GOTO 580
  170MODE 7:OFF: VDU23,16,1|23,18,1|
  180reveal%=0:scan%=0:width%=1:black%=0:ost%=0
  190borked%=0:telnet%=1:extended%=0:cur%=0
  200allowfs%=1:DIM scr%% 1000
  210REM Variables for downloading
  220screen%=0
  230download%=0
  240X%=OPENUP(FNwelcome):VDU28,0,23,39,0,31
  250S$=MID$(S$,1+INSTR(S$,":"))
  260PROCstatusbar(CHR$132+"* "+S$)
  270OSCLI"WinTitle Matrix Network Viewdata/Teletext Client: Connected"
  280REM Send Telnet init data if required
  290IF telnet%=1 THEN BPUT#X%,&FF,&FD,&03 ELSE VDU23,18,1,2|:BPUT#X%,13
  300REPEAT
  310M%=BGET#X%: IF M%=-2 THEN GOTO 570
  320IF M% = -1 AND TIME > ost%+5 THEN PROCstatusxfer(0)
  330IF M% = -1 THEN PROCdhscan
  340IF M% >= 0 THEN PROCvdu(M%):PROCstatusxfer(1): GOTO570
  350SYS "OS_Byte",21,0:I%=INKEY(20):IF I%=-1 THEN scan%=1:PROCdhscan: GOTO 570
  360PROCstatusxfer(2)
  370IF I%=163 THEN I%=96: GOTO 560
  380IF I%=35 OR I%=13 THEN I%=95:GOTO560
  390IF I%>=32 AND I%<=126THENGOTO560
  400IF I%=127 THEN I%=8:GOTO460
  410IF I%=4 THEN GOTO 580
  420IF I%=6 THEN PROCtogglescreen: GOTO 310
  430IF I%=18 THEN PROCreveal: GOTO 310
  440IF I%=2 THEN PROCtoggleblack: GOTO 310
  450IF I%=24 THEN GOTO 610
  460IF I%=8 AND borked%=1 THEN VDU8,32:GOTO560
  470IF I%>=136 AND I%<=139 THEN I%-=128
  480IF I%=31THENPROChelp:GOTO310
  490IF I%=130THENI%=FNcontrolcode:GOTO560
  500IF I%=131 THEN I%=35: GOTO 560
  510IF I%=159ORI%=203THENBPUT#X%,42:BPUT#X%,48:I%=48:GOTO560
  520IF I%=158ORI%=202THENBPUT#X%,42:BPUT#X%,48:I%=57:GOTO560
  530IF I%=172ORI%=236THENBPUT#X%,42:I%=95:GOTO560
  540IF I%=175ORI%=239THENBPUT#X%,42:BPUT#X%,48:I%=95:GOTO560
  550IF I%=171ORI%=233THENBPUT#X%,42:BPUT#X%,57:BPUT#X%,48:I%=95
  560IF I% > 0 THEN BPUT#X%,I%
  570UNTIL M%=-2
  580CLOSE#X%
  590PROCstatusbar(CHR$129+"Disconnected  "+CHR$156): OSCLI"WinTitle Matrix Network Viewdata/Teletext Client: Disconnected"
  600VDU26:PRINTTAB(18,24)CHR$(128+RND(7));"Press any key...";: A=GET:RUN
  610CLOSE#X%:PRINT TAB(0,24);: ON: OSCLI"FX229":END
  620:
  630DEFPROCvdu(M%)
  640IF M% >= 32 THEN PROCactvdu: ENDPROC
  650CASE M% OF
  660WHEN 27: REPEAT N%=BGET#X%: UNTIL N%<>-1: N%=(N% MOD 32)+128: VDU N%: PROCcheckdh: ENDPROC
  670WHEN 8: IF POS=0 AND VPOS=0 THEN VDU31,39,23 ELSE VDU 8
  680WHEN 9: IF POS=39 AND VPOS=23 THEN VDU30 ELSE VDU9
  690WHEN 10: IF VPOS<23 THEN VDU10 ELSE VDU 31,POS,0
  700WHEN 11: IF VPOS > 0 THEN VDU11 ELSE VDU31,POS,23
  710WHEN 12, 13, 30: VDU M%
  720WHEN 17: ON:cur%=1
  730WHEN 20: OFF:cur%=0
  740ENDCASE
  750IF VPOS=24 THEN VDU31,POS,0
  760ENDPROC
  770:
  780DEFPROCcheckdh
  790IFN%=141THENscan%=1
  800ENDPROC
  810:
  820DEFPROCactvdu
  830VDU (M% OR 128):IF VPOS=24 OR (VPOS=23 AND POS=40) THEN VDU30
  840ENDPROC
  850:
  860DEFPROCdhscan
  870OFF:IFscan%=0ENDPROC
  880FOR N%=0 TO 22: FOR P%=0 TO 39
  890IF GET(P%,N%) = 141 THEN PROCcopyline: N%+=1
  900NEXT P%, N%
  910scan%=0:IF cur%=1 THEN ON
  920ENDPROC
  930:
  940DEFPROCcopyline
  950IF N% > 22 THEN ENDPROC
  960x%=POS:y%=VPOS
  970VDU31,0,N%+1
  980FOR P%=0 TO 39: VDU GET(P%,N%): NEXT
  990VDU31,x%,y%
 1000ENDPROC
 1010:
 1020DEFPROCreveal
 1030reveal% EOR=1
 1040VDU23,18,2,reveal%|
 1050ENDPROC
 1060:
 1070DEFPROCtoggleblack
 1080black% EOR=1
 1090VDU23,18,3,black%|
 1100ENDPROC
 1110:
 1120DEFPROCtogglescreen
 1130IF allowfs%=0THENENDPROC
 1140OSCLI"Fullscreen"
 1150SYS"OS_Byte",42 TO ,fs%
 1160IF fs% AND 8 THEN MOUSE OFF ELSE MOUSE ON
 1170ENDPROC
 1180:
 1190DEFPROCstatusbar(status$)
 1200IFsdl%=0 THEN ENDPROC
 1210$&7FC0=STRING$(40," ")
 1220status$=CHR$157+LEFT$(status$, 37)
 1230$&7FC0=status$: ?(&7FC0+LENstatus$)=32
 1240ENDPROC
 1250:
 1260DEFPROCstatusxfer(st%)
 1270IFsdl%=0 THEN ENDPROC
 1280CASE st% OF
 1290WHEN 1:?&7FC2=ASC"["
 1300WHEN 2:?&7FC2=ASC"]"
 1310OTHERWISE: ?&7FC2=32
 1320ENDCASE
 1330ost%=TIME
 1340ENDPROC
 1350:
 1360DEFFNcustom
 1370CLS
 1380PRINT "  ";CHR$(132);CHR$(157);CHR$(135);CHR$(141);"Matrix Network Viewdata Client ";CHR$(156)
 1390PRINT "  ";CHR$(132);CHR$(157);CHR$(135);CHR$(141);"Matrix Network Viewdata Client ";CHR$(156)
 1400PRINT:PRINT CHR$(130);"Please enter the Viewdata server"
 1410PRINT CHR$(130);"in the form";CHR$(134);"server:port";CHR$(130);"or";CHR$(134)"ipaddr:port"
 1420PRINT CHR$(130);"or press";CHR$(134);"Enter";CHR$(130);"to return":PRINT
 1430ON:PRINT CHR$(131);:INPUT">"server$:OFF
 1440="ip0:"+server$
 1450
 1460DEFFNwelcome
 1470PROCwelcomescreen
 1480borked%=0: REPEAT A%=GET: UNTIL (A% >= 48 AND A% <= 57) OR A%=6 OR A%=24 OR A%=84 OR A%=116
 1490IF A% = 24 OR A% = 48 THEN PRINT:ON:OSCLI"FX229":END
 1500IF A% = 6 THEN PROCtogglescreen: GOTO 1480
 1510IF A% = 49 THEN borked%=1: S$ = "ip0:glasstty.com:6502"
 1520IF A% = 50 THEN borked%=1: S$ = "ip0:glasstty.com:6503"
 1530IF A% = 51 THEN borked%=1: S$ = "ip0:glasstty.com:6504"
 1540IF A% = 52 THEN S$ = "ip0:fish.ccl4.org:23"
 1550IF A% = 53 THEN S$ = "ip0:nx.nxtel.org:23280"
 1560IF A% = 54 THEN S$ = "ip0:teletext.matrixnetwork.co.uk:6502"
 1570IF A% = 55 THEN S$ = "ip0:teletext.matrixnetwork.co.uk:48065"
 1580IF A% = 56 THEN GOTO 1480
 1590IF A% = 57 THEN S$ = FNcustom: IF S$="ip0:" THEN GOTO 1470
 1600IF A% = 84 OR A% = 116 THEN telnet%=telnet% EOR 1: GOTO 1470
 1610CLS
 1620=S$
 1630:
 1640DEFPROCwelcomescreen:CLS:VDU26
 1650OSCLI"WinTitle Matrix Network Viewdata/Teletext Client"
 1660PRINT "  ";CHR$(132);CHR$(157);CHR$(135);CHR$(141);"Matrix Network Viewdata Client ";CHR$(156)
 1670PRINT "  ";CHR$(132);CHR$(157);CHR$(135);CHR$(141);"Matrix Network Viewdata Client ";CHR$(156)
 1680PRINT
 1690PRINT CHR$(131);"1 - Telstar";CHR$(133);"(CURRER)"
 1700PRINT CHR$(131);"2 - Telstar";CHR$(133);"(ELLIS)"
 1710PRINT CHR$(131);"3 - Telstar";CHR$(133);"(ACTON)"
 1720PRINT CHR$(131);"4 - Tetrachloromethane";CHR$(133);"(CCl4)"
 1730PRINT CHR$(131);"5 - NXtel"
 1740PRINT CHR$(131);"6 - TEEFAX";CHR$(133);"and Matrix Teletext"
 1750PRINT CHR$(131);"7 - CEEFAX";CHR$(133);"(NMS - teletext)"
 1760PRINT
 1770PRINT CHR$(131);"9 -";CHR$(130);"Custom address"
 1780PRINT CHR$(129);"0 - Exit"
 1790
 1800PRINT CHR$(131);"T - Toggle Telnet codes -";
 1810IF telnet%=1 THEN PRINT CHR$(130);"ON" ELSE PRINT CHR$(129);"OFF"
 1820PRINT TAB(0,15)CHR$(134);"While the session is running:"
 1830IF allowfs%=1 THEN PRINT CHR$(134);" Press CTRL-F to toggle Full Screen":
 1840PRINT CHR$(134);" Press CTRL-R to toggle Reveal"
 1850PRINT CHR$(134);" Press CTRL-B to toggle Black"
 1860PRINT CHR$(134);" Press CTRL-X to exit immediately"
 1870PRINT CHR$(134);" Press CTRL-D to disconnect":PRINT
 1880PRINT CHR$(130);" F1 or CTRL-/ for help & other keys"
 1890PRINT TAB(4,23)CHR$(129);"Please make your selection..."
 1900PRINT CHR$(132);CHR$(157);CHR$(135);VER$;
 1910ENDPROC
 1920:
 1930DEFPROChelp
 1940x%=POS:y%=VPOS:VDU26:PROCstorescreen:CLS
 1950PRINT "  ";CHR$(132);CHR$(157);CHR$(135);CHR$(141);"Matrix Network Viewdata Client ";CHR$(156)
 1960PRINT "  ";CHR$(132);CHR$(157);CHR$(135);CHR$(141);"Matrix Network Viewdata Client ";CHR$(156)
 1970PRINT
 1980PRINT CHR$(134);"Special keys available:":PRINT
 1990IF allowfs%=1 THEN PRINT CHR$(134);" Press";CHR$(131);"CTRL-F";CHR$(134);"to toggle Full Screen":
 2000PRINT CHR$(134);" Press";CHR$(131);"CTRL-R";CHR$(134);"to toggle Reveal":
 2010PRINT CHR$(134);" Press";CHR$(131);"CTRL-B";CHR$(134);"to toggle Black";CHR$(133);"*"
 2020PRINT CHR$(134);" Press";CHR$(131);"CTRL-X";CHR$(134);"to exit immediately"
 2030PRINT CHR$(134);" Press";CHR$(131);"CTRL-D";CHR$(134);"to disconnect": PRINT
 2040PRINT
 2050PRINT CHR$(131);" CTRL-[";CHR$(134);"Select previous frame";CHR$(129);"(*#)"
 2060PRINT CHR$(131);" CTRL-^";CHR$(134);"Select main index frame";CHR$(129);"(*0#)"
 2070PRINT CHR$(131);" PgUp";CHR$(134);" redraw current frame";CHR$(129);"(*00)"
 2080PRINT CHR$(131);" PgDn";CHR$(134);" Request updated frame";CHR$(129);"(*09)"
 2090PRINT CHR$(131);" CTRL-END";CHR$(134);"Request disconnect";CHR$(129);"(*90#)"
 2100PRINT
 2110PRINT CHR$(130);" F2: Send teletext control code":PRINT
 2120PRINT CHR$(133);"*";CHR$(134);"This also switches the Hold Character"
 2130PRINT CHR$(134);"behaviour between that of the";CHR$(131);"SAA5050";CHR$(134);"/"
 2140PRINT CHR$(131);"BBC Micro";CHR$(134);"and later Teletext/Videotex"
 2150PRINT CHR$(134);"specifications."
 2160IFGET
 2170PROCrestorescreen
 2180VDU28,0,23,39,0,31,x%,y%
 2190ENDPROC
 2200:
 2210DEFFNcontrolcode
 2220x%=POS:y%=VPOS:VDU26:PROCstorescreen:CLS
 2230VDU23,18,3,1|
 2240PRINT "  ";CHR$(132);CHR$(157);CHR$(135);CHR$(141);"Matrix Network Viewdata Client ";CHR$(156)
 2250PRINT "  ";CHR$(132);CHR$(157);CHR$(135);CHR$(141);"Matrix Network Viewdata Client ";CHR$(156)
 2260PRINT
 2270PRINT CHR$(141);CHR$(134);SPC(10);"Control codes:"
 2280PRINT CHR$(141);CHR$(134);SPC(10);"Control codes:"
 2290PRINT " @:(text black)     P:(graphics black)"
 2300PRINT CHR$(129);"A: text red        Q: graphics red"
 2310PRINT CHR$(130);"B: text green      R: graphics green"
 2320PRINT CHR$(131);"C: text yellow     S: graphics yellow"
 2330PRINT CHR$(132);"D: text blue       T: graphics blue"
 2340PRINT CHR$(133);"E: text magenta    U: graphics magenta"
 2350PRINT CHR$(134);"F: text cyan       V: graphics cyan"
 2360PRINT CHR$(135);"G: text white      W: graphics white"
 2370PRINT CHR$(136);"H: Flash On";CHR$(137);"       X: Conceal"
 2380PRINT CHR$(137);"I: Flash Off       Y: Contiguous gfx"
 2390PRINT " J: &8A (End Box)   Z: Separated gfx"
 2400PRINT " K: &8B (Start Box)";CHR$&9B;"[: &9B (Esc/Switch)"
 2410PRINT " L: Dbl Height Off ";CHR$&9B;"|: Black background"
 2420PRINT " M: Dbl Height On  ";CHR$&9B;"]: Set bg colour"
 2430PRINT " N: &8E (dbl width)";CHR$&9B;"^: Hold graphics"
 2440PRINT " O: &8F (dbl size) ";CHR$&9B;"#: Release graphics"
 2450PRINT
 2460PRINT CHR$(134);"Note: Codes &8A, &8B, &8E, &8F and &9B"
 2470PRINT CHR$(134);"have no effect in this client."
 2480t%=GET
 2490SYS6,25,16
 2500PROCrestorescreen
 2510VDU28,0,23,39,0,31,x%,y%,23,18,3,0|
 2520=(t% AND 31)+128
 2530:
 2540DEFPROCstorescreen
 2550FOR p%=0 TO 999
 2560p%?scr%%=GET(p% MOD 40,p% DIV 40)
 2570NEXT
 2580ENDPROC
 2590:
 2600DEFPROCrestorescreen
 2610VDU30: FOR p%=0 TO 999: VDU (p%?scr%%) OR &80: NEXT
 2620ENDPROC
