BBC BASIC on the Raspberry Pi Pico

for discussion of bbc basic for windows/sdl, brandy and more
Post Reply
Deleted User 9295

BBC BASIC on the Raspberry Pi Pico

Post by Deleted User 9295 »

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).
User avatar
jgharston
Posts: 5319
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.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
dp11
Posts: 1757
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?
Deleted User 9295

Re: BBC BASIC on the Raspberry Pi Pico

Post by Deleted User 9295 »

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.
Deleted User 9295

Re: BBC BASIC on the Raspberry Pi Pico

Post by Deleted User 9295 »

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.
Deleted User 9295

Re: BBC BASIC on the Raspberry Pi Pico

Post by Deleted User 9295 »

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
User avatar
BigEd
Posts: 6261
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!
User avatar
elk1984
Posts: 162
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”