Wednesday, November 25, 2015

Modern micro with RISC OS Pico

RISC OS Pico is a stripped down distribution of RISC OS which turns Raspberry Pi into a modern micro computer. It was created by RISC OS Open Limited to celebrate 50 years of Basic programming language. Imagine a classic BBC Micro manufactured today: the same black and white text console, the same fun and easy to learn programming language, but much cheaper, with much faster CPU and more RAM, with super fast flash storage, capable of fitting into your pocket. This is what Raspberry Pi with RISC OS Pico is.

Pico boots within a few seconds, straight into console Basic interpreter, just like all classic and modern micros. Yes, you heard it right. Micro computers didn't die with the demise of Atari XL/XE, BBC, C64 and Spectrum. There are many modern incarnations, like Micromite Companion, Fignition (using Forth instead of Basic, just like renowned Jupiter ACE), Grant Searle's Multicomp and other homebrew projects. RISC OS Pico has additional advantage, though. Because its shell is BBC Basic VI, it is natively capable of running programs written in BBC Basic. When I was a child I found it very exciting to type in a program printed in a computer magazine and watch it run. Now you can do the same with your kids to teach them programming. You can google around for some ready to use BBC Basic listings or check out the online book and create something yourself. Basic is very easy to learn and great for understanding how the computer works. It lacks many concepts found in other high level languages, like objects, interfaces, first class functions and other stuff, but they have been created for professional programmers, and they don't show you the way the computers really work. For the CPU any program is just a list of instructions (keywords in Basic) located at subsequent memory addresses (line numbers), and the program counter goes over that list one by one, changes the flow when a condition is met (IF...THEN...ENDIF), repeats some instructions in a loop (REPEAT, WHILE) jumps into a subroutine located at different address (GOSUB line-number), then returns from it (RETURN), or jumps to some other place in a program (GOTO line-number). Even threads, when run on a single CPU core, are executed sequentially, it's just very fast switching between them which creates an illusion of parallel processing. This is why people who can program in Basic are able to learn assembly language much quicker than those who come from other languages. Don't be afraid of Basic teaching you "bad habits". Languages are not good or bad, it's programmers that are.

To start using RISC OS Pico you need a distribution which is suitable for your version of Raspberry Pi. If you have model A or B you can use an official ROOL version, otherwise you should download an alternative version, which has been upgraded to work with Raspberry Pi B+ and Raspberry Pi 2. The file is just 4MB and the only thing you need to do is to unpack it to a blank, FAT formatted SD card. You can also buy a ready to use SD card.

When you put the RISC OS Pico on the card and turn the power on, you should see the following prompt on your screen:
RISC OS 192MB
ARM1176JZF-8 Processor
Piccolo Systems SDFS
ARM BBC BASIC VI (C) Acorn 1989
Starting with 97040636 bytes free
>_
The memory size and processor type can be different, depending on the Raspberry Pi model used with Pico. If you see nothing but a blank screen, add the following line to CONFIG.TXT:
hdmi_safe=1
It should solve the video output problem.

Your new BBC Micro is now ready to use, but if you don't have a UK keyboard, you may notice that some keys are mapped differently. To fix his just type in:
*keyboard usa
and press Enter. If you don't use a standard QWERTY layout, replace "usa" with proper country name ("france", "germany", etc). Notice that the aforementioned keyword starts with "*". It's so called "star command", and it's an operating system command called inside Basic - just like DOS command in Atari or Commodore Basics. There are more commands you can use, for example "*cat" lists the contents of a directory, and "*quit" quits from Basic (to go back just type in "basic" and press Enter). Star commands are written in lowercase, unlike Basic keywords, which must be uppercase. You can find star commands reference here.

To load a program from the SD card use the Basic keyword LOAD, for example to load SimonSays program located in Examples folder use the following:
LOAD "Examples.SimonSays"
To list a program use LIST. Press Scroll Lock key during listing to pause screen scrolling, or use "LIST 10,50" to show only lines from 10 to 50.

When you type your own program you can number the lines yourself or use AUTO keyword to let Basic do it for you. To turn off this feature just press Esc. It's a good practice to leave a bit of space between subsequent line numbers (use 10,20,30 instead of 1,2,3) in case you need to put some code between existing lines. But don't worry if you get lost in numbering - just use RENUMBER.

To replace a program line with new code just enter it using the same line number, and to delete it use only the number with no instructions to follow, for example to remove line 10:
10 PRINT "Hello"
type in:
10
and press Enter. Editing lines is also very easy. List the program, press up arrow and find the line you want to modify on the screen, than keep pressing End key. The contents of the line gets copied to the prompt, so you can edit it and then confirm changes with Enter.

When your program is ready you can SAVE it with:
SAVE "filename"
and then execute it with RUN. You can break it at any moment with Esc key. If by any chance the program stops responding, you can restart the Pico pressing CTRL and Break keys simultaneously.

Programs written in BBC Basic are very fast. Even when 8-bit computers dominated the world, BBC Basic was considered the fastest and most mature. I wondered if it's still true, so I created an implementation of the sieve of Eratosthenes in Basic (available here) and Python (available here) using exactly the same algorithm, and run them both on my Raspberry Pi B+. The results are as follows:

InterpreterOperating systemExecution time
BBC Basic VIRISC OS Pico7.84 seconds
BBC Basic VIRISC OS 5.214.59 seconds
Python 2.7.2RISC OS 5.2125.68 seconds
Python 2.7.9Raspbian Jessie17 seconds

To try the BBC Basic version with RISC OS Pico, just put the file "sieve" in the root folder of the Pico SD card, fire up the Pi and do:
LOAD "sieve"
RUN

1 comment:

Anonymous said...

I have an A3010, if you want basic programs to go faster use *RMFASTER BASIC