Reading BBC Basic files on Linux

discuss general risc os software applications and utilities
Related forum: adventures


Post Reply
darkcity
Posts: 3
Joined: Wed Mar 25, 2020 11:57 am
Contact:

Reading BBC Basic files on Linux

Post by darkcity » Wed Apr 29, 2020 12:28 pm

I've been looking at some of Jan Vibes graphic BBC Basic programs and thinking of converting a few to python. The problem I have is that the BBC Basic files are tokenised so the keywords are just unrecognised characters in the Linux text editor. I could probably work them out, but I wonder if there is a tool that does it? I could install http://www.bbcbasic.co.uk/bbcsdl/ but that could be overkill. :mrgreen:

User avatar
davidb
Posts: 2863
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Reading BBC Basic files on Linux

Post by davidb » Wed Apr 29, 2020 12:49 pm

This search might be useful. ;)

One of the programs referenced is BASIC Tokeniser/Detokeniser, which should be adaptable to what you want.

I think there's also a Perl program somewhere. Maybe the author will speak up and let you know where to get it from.

User avatar
BigEd
Posts: 3422
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Reading BBC Basic files on Linux

Post by BigEd » Wed Apr 29, 2020 12:52 pm


darkcity
Posts: 3
Joined: Wed Mar 25, 2020 11:57 am
Contact:

Re: Reading BBC Basic files on Linux

Post by darkcity » Wed Apr 29, 2020 1:45 pm

Great, thanks for the magic words. I'm going to try mmb utils first :D

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Reading BBC Basic files on Linux

Post by Richard Russell » Wed Apr 29, 2020 2:20 pm

darkcity wrote:
Wed Apr 29, 2020 12:28 pm
I could install http://www.bbcbasic.co.uk/bbcsdl/ but that could be overkill.
Why overkill? It's a lightweight application (once you eliminate the many megabytes worth of example programs included) and free. It will load both varieties of tokenised BBC BASIC program (Acorn's and mine) and allow you to re-save them as a plain-text file, or be copied to the clipboard.

User avatar
scruss
Posts: 275
Joined: Sun Jul 01, 2018 4:12 pm
Location: Toronto
Contact:

Re: Reading BBC Basic files on Linux

Post by scruss » Wed Apr 29, 2020 2:35 pm

Soruk's Matrix Brandy BASIC can read, save and run many of these programs directly under Linux too. Here's Jan's "smoulder" (from BAS08)
jan_vibe-BAS08_Smoulder.jpg
Smoulder, by Jan Vibe, on Matrix Brandy BASIC on Linux
The hardest part of getting these going was fixing the $&#^$!@ file permissions in the archive: all were 000, so you couldn't read any of the files or folders without fixing them.

User avatar
jgharston
Posts: 4118
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Reading BBC Basic files on Linux

Post by jgharston » Wed Apr 29, 2020 4:02 pm

And the BasConv library ripped from the innards of the RISC OS !BasConv application will convert between different format BASIC program files.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.32
(C) Copyright J.G.Harston 1989,2005-2020
>_

User avatar
scruss
Posts: 275
Joined: Sun Jul 01, 2018 4:12 pm
Location: Toronto
Contact:

Re: Reading BBC Basic files on Linux

Post by scruss » Wed Apr 29, 2020 5:22 pm

Didn't have much luck running BasConv on either BBCSDL or Matrix Brandy:
  • BBCSDL couldn't find the source file specified in the current directory;
  • Matrix Brandy gives Address is out of range at line 430 in PROCBasConvInit.
I might be missing some Acorn assumptions with file names: I'm just typing the name itself, no additional sigils.

User avatar
jgharston
Posts: 4118
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Reading BBC Basic files on Linux

Post by jgharston » Thu Apr 30, 2020 1:21 am

scruss wrote:
Wed Apr 29, 2020 5:22 pm
Didn't have much luck running BasConv on either BBCSDL or Matrix Brandy:
  • BBCSDL couldn't find the source file specified in the current directory;
  • Matrix Brandy gives Address is out of range at line 430 in PROCBasConvInit.
I might be missing some Acorn assumptions with file names: I'm just typing the name itself, no additional sigils.
Odd, as I wrote and tested it on BBC BASIC for SDL. As for filenames, as with any program, you use whatever filename convention is being used by the system you are running the program on. I've just done a quick test:
Image2.gif

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.32
(C) Copyright J.G.Harston 1989,2005-2020
>_

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Reading BBC Basic files on Linux

Post by Richard Russell » Thu Apr 30, 2020 1:22 am

scruss wrote:
Wed Apr 29, 2020 5:22 pm
I might be missing some Acorn assumptions with file names: I'm just typing the name itself, no additional sigils.
BBCSDL wil be assuming a default extension of '.bbc', if the file you are converting has no extension add a trailing dot when you enter its name.
Matrix Brandy gives Address is out of range at line 430 in PROCBasConvInit.
This will be because you are running it on a 64-bit system and it is trying to assign a 64-bit memory address to the 32-bit variable line%.

User avatar
jgharston
Posts: 4118
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Reading BBC Basic files on Linux

Post by jgharston » Thu Apr 30, 2020 1:26 am

And just tested and the same in BBC BASIC for Windows, and in Brandy Basic, and in PDP BASIC and in 6502 BASIC and in ARM BASIC.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.32
(C) Copyright J.G.Harston 1989,2005-2020
>_

User avatar
scruss
Posts: 275
Joined: Sun Jul 01, 2018 4:12 pm
Location: Toronto
Contact:

Re: Reading BBC Basic files on Linux

Post by scruss » Thu Apr 30, 2020 3:42 am

Richard Russell wrote:
Thu Apr 30, 2020 1:22 am
BBCSDL wil be assuming a default extension of '.bbc', if the file you are converting has no extension add a trailing dot when you enter its name.
That worked. Utterly illogical on Linux, but it works. Thanks.
jgharston wrote:
Thu Apr 30, 2020 1:26 am
And just tested and the same in BBC BASIC for Windows, and in Brandy Basic, and in PDP BASIC and in 6502 BASIC and in ARM BASIC.
Alas it puts out lines with the wrong termination when run under BBCSDL for Linux:

Code: Select all

   10REM > SMOULDER2^M   20^M   30MODE13:OFF^M   40DIM …
Those CRs should be LFs, otherwise it is seen as one line and won't load or display.

darkcity
Posts: 3
Joined: Wed Mar 25, 2020 11:57 am
Contact:

Re: Reading BBC Basic files on Linux

Post by darkcity » Thu Apr 30, 2020 8:40 am

Richard Russell wrote:
Wed Apr 29, 2020 2:20 pm
darkcity wrote:
Wed Apr 29, 2020 12:28 pm
I could install http://www.bbcbasic.co.uk/bbcsdl/ but that could be overkill.
Why overkill? It's a lightweight application (once you eliminate the many megabytes worth of example programs included) and free. It will load both varieties of tokenised BBC BASIC program (Acorn's and mine) and allow you to re-save them as a plain-text file, or be copied to the clipboard.
You may have talked me into it : -)

Soruk
Posts: 799
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Reading BBC Basic files on Linux

Post by Soruk » Wed Jun 17, 2020 2:38 pm

scruss wrote:
Wed Apr 29, 2020 2:35 pm
Soruk's Matrix Brandy BASIC can read, save and run many of these programs directly under Linux too. Here's Jan's "smoulder" (from BAS08)

jan_vibe-BAS08_Smoulder.jpg

The hardest part of getting these going was fixing the $&#^$!@ file permissions in the archive: all were 000, so you couldn't read any of the files or folders without fixing them.
I've just found this thread, and while many of these do run quite well under Matrix Brandy, quite a number don't (those using ECF pattern fills, SYS calls to OS_SpriteOp and the Draw module), and some are highlighting bugs - it's proving a good shakedown on the graphics code!
Matrix Brandy BASIC VI (work in progress)

User avatar
scruss
Posts: 275
Joined: Sun Jul 01, 2018 4:12 pm
Location: Toronto
Contact:

Re: Reading BBC Basic files on Linux

Post by scruss » Thu Jun 18, 2020 2:35 pm

whoops, didn't mean to make more work for you. I may have cherry-picked a demo that seemed to work. Details have never been my strong point

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Reading BBC Basic files on Linux

Post by Richard Russell » Thu Jun 18, 2020 2:51 pm

scruss wrote:
Thu Jun 18, 2020 2:35 pm
I may have cherry-picked a demo that seemed to work.
There are plenty that don't work in BBC BASIC for SDL 2.0, for similar reasons, and others that need a delay adding to run at a sensible speed. But there are hundreds of them in all and I haven't made a concerted effort to work through them (yet!). What they have prompted me to do, however, is to extend my support for loading Acorn-format tokenised programs to recognise the two-byte tokens - at least, those with a direct equivalent in BBCSDL.

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Reading BBC Basic files on Linux

Post by Richard Russell » Thu Jun 18, 2020 3:11 pm

Here's BBCSDL's rendition of smoulder, with the SYS "ColourTrans_SetGCOL" replaced by COLOUR 7,F%>>8,F%>>16,F%>>24:

smoulder_bbcsdl.jpg

Soruk
Posts: 799
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Reading BBC Basic files on Linux

Post by Soruk » Thu Jun 18, 2020 4:07 pm

scruss wrote:
Thu Jun 18, 2020 2:35 pm
whoops, didn't mean to make more work for you. I may have cherry-picked a demo that seemed to work. Details have never been my strong point
Oh no, don't get me wrong. I'm glad to have found these (some I remember from my Acorn User cover discs BITD). And it's given me another source of material to try to identify bugs and fix them. V1.22.6 is shaping up to be a mammoth changeset!
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Reading BBC Basic files on Linux

Post by Richard Russell » Sat Jun 20, 2020 10:36 am

Having now adapted several of Jan Vibe's programs for BBCSDL/BB4W here are some hints for what needs to be changed (if anything):
  • If the program selects a RISC OS-specific MODE (>7), change it to MODE 8.
  • Change GCOL R,G,B to COLOUR 7,R,G,B (the former variant doesn't convert to a VDU sequence!).
  • Add a delay if the program runs too fast.
Here, for example, is DRAWWOOD after the above modifications:

Code: Select all

   10 REM > DRAWWOOD
   20
   30 MODE8:OFF
   40 REPEAT delay=INKEY(10)
   50   PROCL(RND(2000)-200,RND(1600)-200,RND(2000)-200,RND(1600)-200,RND(64)+32)
   60 UNTIL0
   70
   80 DEFPROCL(X1,Y1,X2,Y2,W)
   90 LOCAL L,T1,T2,XA,YA,XB,YB,XC,YC,XD,YD
  100 L=SQR((X1-X2)^2+(Y1-Y2)^2):IF X1>X2 L=-L
  110 T1=ASN((Y1-Y2)/L):T2=T1+PI:W=W/2
  120 T3=T2+PI:T4=T3+PI
  130 XA=X1+W*SINT3:YA=Y1+W*COST3:XB=X1+W*SINT4:YB=Y1+W*COST4
  140 XC=X2+W*SINT4:YC=Y2+W*COST4:XD=X2+W*SINT3:YD=Y2+W*COST3
  150 T1=RND(255):T2=255-T1
  160 COLOUR7,(254*T1+112*T2)/255,(126*T1+22*T2)/255,0
  170 MOVEXA,YA:MOVEXB,YB:PLOT85,XD,YD:PLOT85,XC,YC
  180 W=INT(SQR((XA-XB)^2+(YA-YB)^2)/2):IF W=0 W=1
  190 FOR L=0 TO W
  200   X1=(XA*L+XB*(W-L))/W:Y1=(YA*L+YB*(W-L))/W
  210   X2=(XD*L+XC*(W-L))/W:Y2=(YD*L+YC*(W-L))/W
  220   PROCBARK(X1,Y1,X2,Y2)
  230 NEXT
  240 ENDPROC
  250
  260 DEFPROCBARK(X1,Y1,X3,Y3)
  270 LOCAL X2,Y2,R,T1,T2
  280 R=RND(1):X2=R*X1+(1-R)*X3:Y2=R*Y1+(1-R)*Y3
  290 PLOT X2,Y2
  300 IF (X2-X1)^2+(Y2-Y1)^2>2000THEN
  310   PROCBARK(X1,Y1,X2,Y2)
  320 ELSE
  330   T1=RND(255):T2=255-T1
  340   COLOUR7,(254*T1+112*T2)/255,(126*T1+22*T2)/255,0
  350   LINE X1,Y1,X2,Y2
  360 ENDIF
  370 IF (X3-X2)^2+(Y3-Y2)^2>2000THEN
  380   PROCBARK(X2,Y2,X3,Y3)
  390 ELSE
  400   T1=RND(255):T2=255-T1
  410   COLOUR7,(254*T1+112*T2)/255,(126*T1+22*T2)/255,0
  420   LINE X2,Y2,X3,Y3
  430 ENDIF
  440 ENDPROC
Of course programs that use sprites, pattern fills, assembler code or some other RISC OS-specific features can't easily be converted.

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Reading BBC Basic files on Linux

Post by Richard Russell » Sat Jun 20, 2020 10:52 am

jgharston wrote:
Wed Apr 29, 2020 4:02 pm
And the BasConv library ripped from the innards of the RISC OS !BasConv application will convert between different format BASIC program files.
The latest release of SDLIDE (which comes with BBC BASIC for SDL 2.0 v1.13a) now automatically converts Acorn's 2-byte tokens to their BB4W/BBCSDL equivalent, so it should no longer be necessary to run BasConv separately. The only significant difference is that in the case of the unsupported keywords (BEATS, TEMPO, VOICES, VOICE, STEREO, OVERLAY, MANDEL) no substitution takes place, so they will appear as CASEERL, CASEERR etc. Unlike BasConv (and BB4W!) BY is handled correctly.

User avatar
jgharston
Posts: 4118
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Reading BBC Basic files on Linux

Post by jgharston » Sun Jun 21, 2020 7:26 pm

Richard Russell wrote:
Sat Jun 20, 2020 10:52 am
The only significant difference is that in the case of the unsupported keywords (BEATS, TEMPO, VOICES, VOICE, STEREO, OVERLAY, MANDEL) no substitution takes place, so they will appear as CASEERL, CASEERR etc. Unlike BasConv (and BB4W!) BY is handled correctly.
That used to work. :( I'll add it to my to-do list.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.32
(C) Copyright J.G.Harston 1989,2005-2020
>_

Post Reply

Return to “32-bit acorn software: other”