User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sat Sep 03, 2016 5:09 pm

As many of you will know, I have recently ported my x86 (IA-32) version of BBC BASIC to Linux, Mac OS-X and Android by means of the SDL (Simple DirectMedia Layer) cross-platform library. To achieve this I have written, in C, an almost complete emulation of the BBC VDU drivers ('oswrch'), including MODE 7, and an emulation of the BBC star commands ('oscli') albeit that they are more closely based on those in BBC BASIC for Windows rather than Acorn's MOS or RISC OS.

To all intents and purposes the only major component of this cross-platform version of BBC BASIC which is CPU-specific is the interpreter itself! This raises an intriguing possibility: if I could link my SDL-based OS emulation to Sophie's ARM BASIC I could quite easily create a version which would run on the RPi, and indeed on other ARM platforms supported by SDL 2.0 such as Android.

Unfortunately, creating a linkable and relocatable version of ARM BASIC is not straightforward. There are two principal stumbling blocks: BASIC makes its calls into the OS via SWIs, which would have to be changed to conventional BL subroutine calls, and BASIC's RAM workspace is at a fixed memory address which would have to be made relocatable (in most, if not all, cases the workspace is accessed by register-relative addressing so this isn't as challenging as it might at first seem, and a modern assembler may be able to do much of the work).

My difficulty is that I'm not an ARM programmer so this adaptation to make BASIC linkable and relocatable isn't something I can do myself. Some preliminary work has already been done by David Boddie, which can be found at Github here (don't be misled by the name, there's nothing Android-specific); it uses as its starting point Jonathan Harston's enhanced BBC BASIC Plus.

My question is: would anybody be interested in collaborating with me on this project? If we can take forward David Boddie's work to create a linkable and relocatable version of ARM BASIC, the only remaining task will be to write some glue code (either in C or ARM assembler) to interface my existing SDL-based framework with the ABI that BASIC expects to see for its input-output etc. The end result would be a highly functional, fast, GUI version of BBC BASIC for the RPi with features that (for example) Brandy can't provide such as the embedded ARM assembler.

Richard.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sat Sep 03, 2016 6:56 pm

Sounds interesting. Very much so.

Though I can only imagine the work needed to simulate all the SWI Calls, especialy the WIMP calls that a vast amount of BBC BACIS V code uses on RISC OS. Then there is the issue of inline assembler, which would have to be significantly changed for many RISC OS programs, unless you automaticaly replace any references to SWI with branches to the equilivent simulated calls in your interpreter.

I have to many projects in progress at this time. Though I do look forward to seeing the results, as I have yet to find an equaly capable, equaly fast purely interpreted BASIC anywhere.

And BBC BASIC V is on the RPi, if you use RISC OS, so no CPU issues (like the 26 bit R15 effective addressing, and integrated flags of older ARM CPU's).
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sat Sep 03, 2016 8:23 pm

DavidS wrote:I can only imagine the work needed to simulate all the SWI Calls, especialy the WIMP calls that a vast amount of BBC BACIS V code uses on RISC OS.
That is not at all the objective: this will be an implementation of the BBC BASIC programming language, not a RISC OS emulator! As I mentioned in my original post only VDU and OSCLI are emulated (to a degree), so the compatibility with RISC OS won't be any greater than it is in BBC BASIC for Windows or BBC BASIC for Mac OS! But from my perspective that's not a disadvantage, it's what I've been used to for the last 30 years or so since I developed BBC BASIC (Z80)!

Richard.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sat Sep 03, 2016 8:34 pm

RichardRussell wrote:
DavidS wrote:I can only imagine the work needed to simulate all the SWI Calls, especialy the WIMP calls that a vast amount of BBC BACIS V code uses on RISC OS.
That is not at all the objective: this will be an implementation of the BBC BASIC programming language, not a RISC OS emulator! As I mentioned in my original post only VDU and OSCLI are emulated (to a degree), so the compatibility with RISC OS won't be any greater than it is in BBC BASIC for Windows or BBC BASIC for Mac OS! But from my perspective that's not a disadvantage, it's what I've been used to for the last 30 years or so since I developed BBC BASIC (Z80)!

Richard.
Ah ok. I was just thinking about what people may attempt with the actual ARM BASIC (BBC BASIC V). I still look forward to seeing the results, as it will help promote the use of Assembly, even on Linux ARM.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
scruss
Posts: 2471
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Mon Sep 05, 2016 1:00 am

RichardRussell wrote:My question is: would anybody be interested in collaborating with me on this project?
I can't provide anything more than a long-distance "Yay!". I also didn't know that you'd made BBC BASIC for x86, either!
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Pyjamarama
Posts: 12
Joined: Sun Oct 02, 2016 5:51 am

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 6:03 am

I would love that! I want to introduce my children in BASIC and the BBC Basic would be ideal!!

User avatar
DougieLawson
Posts: 36097
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 10:57 am

Pyjamarama wrote:I would love that! I want to introduce my children in BASIC and the BBC Basic would be ideal!!
Why?

BASIC is one of the least structured programming languages in the history of the planet. Everything from COBOL to PL/I through C/C++ leads to better programming practices. Python (even with its quirky syntax rules) has much better structure (although it's missing the evaluate/case/select language element).

If you insist on using BASIC rather than python for teaching, then look at Gordon Henderson's RTB or the FUZE variant of it. That, at least, has gained some structure from the awful spaghetti code BASICs we had back in the 1980s. https://www.fuze.co.uk/get-fuze-basic.html
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Heater
Posts: 13269
Joined: Tue Jul 17, 2012 3:02 pm

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 11:31 am

I'm with Dougie on this one.

Why?

Do your children a favor and start them off with something a bit more mainstream.

I won't argue the merits of this language or that, but there is a lot to be said for using a language that has a huge user community.

Python for example. Not my favorite but a nice easy starter language. If your children learn Python then they can play with the other kids :)

BASIC is OK if you are into software archeology or have a retro fetish.

Pyjamarama
Posts: 12
Joined: Sun Oct 02, 2016 5:51 am

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 5:11 pm

:) I agree. But even for retrospective reason I would love to see a BBC Basic blinking at my Pi

Anyway, my plan is to teach them some fundamentals (lile lopps, screen plotting etc) using BASIC...maybe a retro version.

After that I can move to FuzeBasic for a bit more structured things.

After that we can talk real business with something like C++

jahboater
Posts: 4674
Joined: Wed Feb 04, 2015 6:38 pm

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 5:15 pm

DougieLawson wrote:
Pyjamarama wrote:I would love that! I want to introduce my children in BASIC and the BBC Basic would be ideal!!
Why?

BASIC is one of the least structured programming languages in the history of the planet. Everything from COBOL to PL/I through C/C++ leads to better programming practices. Python (even with its quirky syntax rules) has much better structure (although it's missing the evaluate/case/select language element).
+1
It is precisely the last language I would use for teaching.

Heater
Posts: 13269
Joined: Tue Jul 17, 2012 3:02 pm

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 5:27 pm

Pyjamarama,
After that we can talk real business with something like C++
Some would consider that child abuse. :)

Except of course in the limited way that C++ is exposed to Arduino users.

I'm totally into the idea of starting with fundamentals, sequence, selection and iteration. You'll need some variables and plotting stuff on the screen helps enormously. As does lighting a LED or wiggling a servo.

Python can do all that. And, as I said, allow your children to play with all the other kids on the block.

Pyjamarama
Posts: 12
Joined: Sun Oct 02, 2016 5:51 am

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 5:59 pm

Hahahahahaha!!

Anyway...isn't it a pitty an ARM based computer not to have a BBC Basic version?

Heater wrote:Pyjamarama,
After that we can talk real business with something like C++
Some would consider that child abuse. :)

Except of course in the limited way that C++ is exposed to Arduino users.

I'm totally into the idea of starting with fundamentals, sequence, selection and iteration. You'll need some variables and plotting stuff on the screen helps enormously. As does lighting a LED or wiggling a servo.

Python can do all that. And, as I said, allow your children to play with all the other kids on the block.

Heater
Posts: 13269
Joined: Tue Jul 17, 2012 3:02 pm

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 6:06 pm

Pyjamarama,

...isn't it a pity an ARM based computer not to have a BBC Basic version?

No. Last I heard BBC BASIC was for the 6502 based BBC Computer.

Pyjamarama
Posts: 12
Joined: Sun Oct 02, 2016 5:51 am

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 6:11 pm

Didn't Archie run a BBC Basic version?

User avatar
scruss
Posts: 2471
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 6:22 pm

Pyjamarama wrote:Didn't Archie run a BBC Basic version?
Yes, it did, and you can still run it under Risc OS.

(Heater - BBC BASIC for RISC OS is, without wanting to put words in his mouth, DavidS's ideal of a load-and-go development environment.)
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Heater
Posts: 13269
Joined: Tue Jul 17, 2012 3:02 pm

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 6:32 pm

I was pretty sure that there was a BBC BASIC for the Acorn Archimedes.

I'm also sure that no non-trivial BBC BASIC Program from a BBC Computer would run on the Archimedes version of BBC BASIC. Correct me if I am wrong.

Also, pretty much no one had an Archimedes machine.

I did lust after one at the time but it was far too expensive to justify for me.

User avatar
bensimmo
Posts: 4172
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 7:13 pm

Just fire up Beebdroid on your android tablet/phone, then if you can get past Repton and chickie egg and Frak and Twin Kingdom Valley and ...
Or buy a cheap old pc and fire up some other emulator if you want to do some basic basic with the kids.
We did that, he enjoyed the simplicity of it.
Then moved up in the world with Scratch ;-)


Still, I'd install it and run it.

User avatar
ukscone
Forum Moderator
Forum Moderator
Posts: 4145
Joined: Fri Jul 29, 2011 2:51 pm
Contact: Website

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 7:15 pm

Heater wrote: Also, pretty much no one had an Archimedes machine.
i knew only one person with an Archimedes, at least they claimed to have one but I never actually saw it

User avatar
bensimmo
Posts: 4172
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 7:40 pm

ukscone wrote:
Heater wrote: Also, pretty much no one had an Archimedes machine.
i knew only one person with an Archimedes, at least they claimed to have one but I never actually saw it
I had one at home for a while well a BBC A3000, probably with a Nimbus too, but that's something different.
Either way the Masters where used more often.
Wonder if we'll get a Pi Master and a Pi Master Compact and Pi 3000?

Anyway I'm nosying around the BBC basic website now :oops:

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 8:47 pm

Aaah BASIC :-)

FWIW: I owned an Archimedes computer. I liked it. I upgraded it with a 20MB drive too. I also had a BBC Micro before that (which got stolen )-; I used BBC B's and Masters at the place I was working at the time (University research stuff by then and used them for my work). I think the last thing I did with my Arc was to play Lemmings on it...

I do sometimes wonder if we've lost the plot though - what are we teaching - problem solving or a particular programming language. I sometimes thing we're giving people solutions to problems that don't exist...

I am of the view that it doesn't really matter what language you start on - it's the teacher and approach to problem solving that's more important than the language itself. you pick the language to best suit the task in-hand.

Of-course I was daft enough to write a BASIC interpreter, so it's also possible I am biased. RTB is written in C.

Right now - alongside some (paid-for) automation projects I'm working on, I'm also updating RTB. It's now faster than before with a few more features. I'll release a new one soon. I had an idea that it might be fast enough to write an old-style (think wolfenstein 3d) 3D type game in. And it almost is - I'm getting 25-30 fps for a simple raycaster at 320x240 pixel resolution on a Pi v2 - same as the original which was written in C and x86 ASM... (I get over 150 fps on my desktop fwiw - not had a chance to try it in a Pi v3 yet)

I guess, after what I said above, you might ask if BASIC is the right language for a 3D renderer - almost probably not, but I like a challenge...

Now what if I made the renderer part of RTB - it's only a few 100 lines of C after all... Would anyone pick it up and use RTB as the 'front-end' to code the map, puzzles, traps and tricks in???

-Gordon

Ps. for you RTB enthusiasts out there, I'm re-doing some demos, etc., but please do play with: https://unicorn.drogon.net/mj-fractal.rtb if you want to waste some time...
--
Gordons projects: https://projects.drogon.net/

User avatar
rpdom
Posts: 15170
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Sun Oct 02, 2016 9:21 pm

I had an Archimedes. One of the early ones. It originally ran "Arthur" before RISC OS, and BBC Basic was available for both. I upgraded mine to an ARM3 chip, faster MEMC1 chip, 4MB RAM, 105MB disk and had a "podule" with a composite video input.

It was expensive, but I got a discount at the time as I needed it for work. I had to port our code from the BBC to the Archimedes and also the RM Nimbus and PC (Using the BBC BASIC on that too). Porting the BASIC part of the code (95% of it) was relatively easy. Porting the stuff written in assembler for the 6502 was a bit harder but I managed it. I made it so the same BASIC code ran on all three platforms, with a few tests for platform type, and the assembled stuff had the same names and entry points on each platform.

I used to run MSDOS software under the PC emulator (Autoroute, CorelDraw and some other stuff under GEM).

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Mon Oct 03, 2016 2:10 am

DougieLawson wrote:
Pyjamarama wrote:I would love that! I want to introduce my children in BASIC and the BBC Basic would be ideal!!
Why?

BASIC is one of the least structured programming languages in the history of the planet. Everything from COBOL to PL/I through C/C++ leads to better programming practices. Python (even with its quirky syntax rules) has much better structure (although it's missing the evaluate/case/select language element).

If you insist on using BASIC rather than python for teaching, then look at Gordon Henderson's RTB or the FUZE variant of it. That, at least, has gained some structure from the awful spaghetti code BASICs we had back in the 1980s. https://www.fuze.co.uk/get-fuze-basic.html
Have you used ARM BASIC (also known as BBC BASIC V)? It is a structured programming language.

I have never seen an ARM BASIC program that uses anything like GOTO/GOSUB, no no. Parameterized procedures and functions are the standard way to block code in ARM BASIC.

ARM Basic is 100 times better than 99% of other BASIC implementations, even on modern systems.

So do not talk about spaghetti code where it does NOT apply.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Mon Oct 03, 2016 2:20 am

scruss wrote:
Pyjamarama wrote:Didn't Archie run a BBC Basic version?
Yes, it did, and you can still run it under Risc OS.

(Heater - BBC BASIC for RISC OS is, without wanting to put words in his mouth, DavidS's ideal of a load-and-go development environment.)
:)
Heater wrote:I was pretty sure that there was a BBC BASIC for the Acorn Archimedes.

I'm also sure that no non-trivial BBC BASIC Program from a BBC Computer would run on the Archimedes version of BBC BASIC. Correct me if I am wrong.

Also, pretty much no one had an Archimedes machine.

I did lust after one at the time but it was far too expensive to justify for me.
Actually most BBC BASIC programs from the 6502 BBC computers would indeed run (remember the Original Archimedes was a BBC Computer as well, although ARM Based).

The VDU system calls are still there, and most of the Pre-ARM ones are unchanged, same goes for OS-Byte calls.

In fact there have been more than a few 6502 emulators for running older 6502 MOS operating system programs from the 6502 BBC Computer time, and these were done by simply passing any system calls and VDU calls on to RISC OS, so only the CPU needed emulating to run even machine language programs.

I am in america and I had an Archimedes (probably still do in a closet).
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Mon Oct 03, 2016 2:34 am

As to the complaints about the presence of GOTO in ARM BASIC:
Those that complain about the GOTO command must not like C, C++, B, BCPL, etc, etc.

Though more on point, in ARM BASIC it is as common to see GOTO used as it is to see goto in C, both languages have the said command, though it is rarely used.

GOTO has one good use, as it is implemented in BASIC, that use is teaching kids how looping structures work, as a program can be written simulating the function of any loop using GOTO. Ok the same could be done in C, though not as cleanly. This is a good thing as it helps show a bit of what is going on behind the scenes with loops, before the kid is ready to learn Assembly Language (needed for all programmers sooner or later, you can not have a compiler without a back-end, and assembly is a good way of that, with only direct machine language being better).

And BBC BASIC V (ARM BASIC) is as structured as C, ARM BASIC even has pointers, which is very important.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Heater
Posts: 13269
Joined: Tue Jul 17, 2012 3:02 pm

Re: Porting ARM BASIC to the Raspberry Pi via SDL 2.0

Mon Oct 03, 2016 9:04 am

DavidS,
And BBC BASIC V (ARM BASIC) is as structured as C, ARM BASIC even has pointers, which is very important.
So it's not really BASIC at all.

BASIC has line numbers. It has GOTO, GOSUB/RETURN. LET, FOR/NEXT etc. BASIC uses floating point numbers. It allowed defining actual named functions with DEF. Where a "function" is a single expression that can fit on one line.

In fact it looked like what's described in it's manual: See attachment.

Modern so called "BASIC"s with the structured programming constructs etc are not BASIC. They are reincarnations of Algol

Edit: Hmmm...the BASIC manual is too big to attach. It's here: http://www.cs.bris.ac.uk/~dave/basic.pdf

Return to “Other programming languages”