BBC BASIC on the Raspberry Pi Pico

for discussion of bbc basic for windows/sdl, brandy and more
Post Reply
User avatar
Richard Russell
Posts: 2625
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

BBC BASIC on the Raspberry Pi Pico

Post by Richard Russell »

Over at the Raspberry Pi forum Eric Olsen is working on a port of my BBC BASIC interpreter (with all the 'modern' extensions, like structures and 64-bit integers) to the Raspberry Pi Pico, a $5 computer! This would be, at least initially, a 'console mode' implementation, requiring an external terminal for user I/O.

He has already had considerable success, but is encountering some problems working within the constraints of having only about 256K of RAM in total. Although that sounds generous for BBC BASIC, I have not had to worry about limited memory availability on modern platforms so my code is not optimised for that (for example the string accumulator is currently 64K just because that's a convenient amount).

So he and I are working on ways to reduce the memory footprint, one of which is to reduce the size of the string accumulator. I have also proposed the following approach to memory management, maximising the flexibility of how the limited RAM is divided between the various competing demands, largely by the BASIC programmer tuning the value of HIMEM to suit the particular program:

memory_layout_pico.png

This is very much in keeping with the BBC BASIC 'philosophy' of giving the programmer low-level control of memory allocation. It's not yet clear whether it will be possible to cajole the Pico's kernel to allow this arrangement (which involves the CPU stack being within our malloc'ed block).
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
User avatar
jgharston
Posts: 4575
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: BBC BASIC on the Raspberry Pi Pico

Post by jgharston »

Ooo, looking good.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.36
(C) Copyright J.G.Harston 1989,2005-2020
>_
dp11
Posts: 1357
Joined: Sun Aug 12, 2012 9:47 pm
Contact:

Re: BBC BASIC on the Raspberry Pi Pico

Post by dp11 »

I'm afraid I don't understand the term 'string accumulator ', could you explain a bit more?
User avatar
Richard Russell
Posts: 2625
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC on the Raspberry Pi Pico

Post by Richard Russell »

dp11 wrote:
Sun Aug 22, 2021 9:12 am
I'm afraid I don't understand the term 'string accumulator ', could you explain a bit more?
It's a temporary holding buffer for a string, principally for use during expression evaluation. Consider a simple statement such as:

Code: Select all

a$ = a$ + b$
The typical way this will be executed by an interpreter is as follows:
  1. Copy the string a$ to the string accumulator.
  2. Concatenate b$ onto the contents of the string accumulator.
  3. Replace a$ with the contents of the string accumulator.
Simplistically, the string accumulator must be large enough to contain the longest possible string (255 bytes in the case of Acorn BASICs). Of course this isn't feasible in the case of my BASICs, which have no (practical) limit on string length, so in my case the accumulator is there purely for performance reasons: strings short enough to fit (the majority) can be handled efficiently via the string accumulator, longer strings must be evicted to the heap, which takes time.

The name arises by analogy with the accumulator register which performs a similar function in numeric calculations.
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
User avatar
Richard Russell
Posts: 2625
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC on the Raspberry Pi Pico

Post by Richard Russell »

For additional reference, according to MDFS the string accumulator of Sophie's original 6502 BBC BASIC is at &0600 to &06FF. It's also used to contain the parameter block built by the CALL statement.

When it's not at a fixed address there is typically a way to discover where it is. For example in BBC BASIC for Windows and 32-bit editions of BBC BASIC for SDL 2.0 its address can be found as !332 and in 64-bit editions its address can be found as ]332:

Code: Select all

      a$ = "Hello "
      b$ = "world!"
      L% = LEN(a$ + b$ + CHR$&D)
      PRINT $!332
which prints:

Code: Select all

Hello world!
showing how the string accumulator holds the concatenated string temporarily for its length to be measured, even though it's not actually stored in a variable.
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
User avatar
Richard Russell
Posts: 2625
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC on the Raspberry Pi Pico

Post by Richard Russell »

BBC BASIC for the Raspberry Pi Pico is now at a stage where it can be experimented with. It's very much a work-in-progress (for example there isn't yet a Thumb2 assembler) but it can run programs and control the GPIO. Installation instructions can be found here.

There are a number of demo programs supplied, including one (gpio.bbc) to blink the LED:

Code: Select all

 `gpio_put` = SYS("gpio_put")
 led_pin = 25
 SYS "gpio_init", led_pin
 SYS "gpio_set_dir", led_pin, 1
 REPEAT
   SYS `gpio_put`, led_pin, 1
   WAIT 25
   SYS `gpio_put`, led_pin, 0
   WAIT 25
 UNTIL FALSE
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
User avatar
BigEd
Posts: 4522
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: BBC BASIC on the Raspberry Pi Pico

Post by BigEd »

An interesting development thread, and a fine milestone!
elk1984
Posts: 52
Joined: Mon Mar 01, 2021 9:54 pm
Contact:

Re: BBC BASIC on the Raspberry Pi Pico

Post by elk1984 »

That's very cool. A chance to use some of the Picos I have lying around with a decent BASIC :D
Post Reply

Return to “modern implementations of classic programming languages”