10
20
30 :
40 DIM ctrl% 31,mem% 1023:X%=ctrl%:Y%=X%DIV256:in%=0:out%=0
50 ON ERROR REPORT:PROCCloseAll:PRINT:END
60 PRINT "Create PROC to display teletext page"
70 INPUT "Input file: "in$
80 size%=1024:in%=OPENIN(FNfname(in$)):IF in%:size%=EXT#in%
90 PRINT "Frame number (1";
100 IF size%>1024:PRINT "-";(size%+1023)DIV1024;") "; ELSE PRINT") ";
110 INPUT ""ptr%:IF ptr%<1:ptr%=1
120 INPUT "Procedure name: "proc$:IF proc$="":proc$="page"
130 INPUT "Start line number: "line%:IF line%=0:line%=1000
140 INPUT "Line step: "step%:IF step%=0:step%=10
150 INPUT "Output file: "out$
160 INPUT "(T)ext or (B)asic: "type$
170 IF INSTR("Bb",LEFT$(type$,1)):type$="B" ELSE type$="T"
180 :
190 IF in%=0:PRINT"File '"in$"' not found":END
200 ptr%=(ptr%-1)*1024:IF ptr%+1>size%:PRINT"Frame past end of file":PROCCloseAll:END
210 out%=OPENOUT(FNfname(out$)):IF out%=0:PRINT"Can't save '"out$"'":PROCCloseAll:END
220 FOR A%=0 TO 1023 STEP 4:mem%!A%=0:NEXT
230 PROCgbpb(3,in%,mem%,1024,ptr%):CLOSE#in%:in%=0
240 rows%=FNttx_rows(mem%)
250 IF type$="B":BPUT#out%,13
260 text$=FNtkn(CHR$&DD+CHR$&F2+proc$+":"+CHR$&DB,"DEFPROC"+proc$+":CLS")
270 IF rows%=25 OR rows%=23:text$=text$+FNtkn(":"+CHR$&EF,":VDU")
280 IF rows%=25:text$=text$+"31,39,24,"+STR$mem%?999+",32,30,11"
290 IF rows%=23:text$=text$+"10"
300 PROCoutput:FOR row%=0 TO rows%-1
310 PRINT CHR$13;line%;:ptr%=mem%+row%*40:text$=""""
320 FOR col%=ptr% TO ptr%+39+(row%=24)
330 A%=?col% AND 127:IF A%<32 OR A%=127:A%=A% OR &80
340 A$=CHR$A%:A$=MID$("`#_"+A$,INSTR("#_`"+A$,A$),1)
350 text$=text$+A$:IF A%=34:text$=text$+A$
360 NEXT col%
370 IF RIGHT$(text$,1)=" ":REPEATtext$=LEFT$(text$,LENtext$-1):UNTILRIGHT$(text$,1)<>" "
380 text$=text$+CHR$34:IF text$="""""":text$=""
390 IF text$<>"":IF A%<>32 OR row%=24:text$=text$+";"
400 text$=FNtkn(CHR$&F1,"PRINT")+text$
410 IF row%=rows%-1:text$=text$+FNtkn(CHR$&BD,"CHR$")+"30;"
420 PROCoutput:NEXT row%:PRINT CHR$13;SPC6;CHR$13;
430 text$=FNtkn(CHR$&E1,"ENDPROC")
440 PROCoutput:IF type$="B":BPUT#out%,255
450 CLOSE#out%:out%=0:ON ERROR END
460 OSCLI "SetType "+out$+" "+FNtkn("FFB","FFF")
470 END
480 :
490 DEFFNtkn(B$,T$):IF type$="B":=B$ ELSE =T$
500 :
510 DEFPROCoutput
520 IF type$="B":PROCout(out%,CHR$(line%DIV256)+CHR$(line%)+CHR$(4+LENtext$))
530 PROCout(out%,text$+CHR$13)
540 line%=line%+step%
550 ENDPROC
560 :
570 DEFPROCout(o%,A$):IF A$="":ENDPROC
580 FOR A%=1 TO LENA$:BPUT#o%,ASCMID$(A$,A%,1):NEXT:ENDPROC
590 :
600 DEFPROCCloseAll
610 A%=out%:out%=0:IFA%:CLOSE#A%
620 A%=in%:in%=0:IFA%:CLOSE#A%
630 ENDPROC
640 :
650 DEFFNfname(A$):=A$+LEFT$(".",?(TOP-3)=0)
660 DEFPROCgbpb(A%,chn%,addr%,num%,ptr%)
670 ?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:IFPAGE<&FFFFF:CALL&FFD1:ENDPROC
680 IFA%=1ORA%=3:PTR#?X%=X%!9
690 REPEAT:IFA%=1ORA%=2:BPUT#?X%,?X%!1 ELSE IFA%=3ORA%=4:?X%!1=BGET#?X%
700 X%!1=X%!1+1:X%!5=X%!5-1:UNTIL(EOF#?X% AND A%>2)OR X%!5<1:ENDPROC
710 :
720 DEFFNttx_rows(D%):A%=919:REPEATA%=A%+1:UNTILA%>999ORD%?A%<32:=A%DIV40