Recently, Garth asked:
Quote:
I have never seen a BBC Micro, but I hear nothing but good about its BASIC.
A while back Ed gave a good description of the old Beeb;
http://forum.6502.org/viewtopic.php?f=3&t=3482&p=40799&hilit=bbc+micro#p40799 so no point repeating it really, but a picture:
Attachment:
BBCMicro.jpg [ 282.39 KiB | Viewed 15723 times ]
They keyboard layout is a little unusual by todays standards, but in 1981 everyone was still making it up as they went.. One thing Ed didn't mention in his good write-up was the arrow keys and the copy button - essentially, you used the arrow keys to move a 2nd cursor round the screen, then they copy key would copy the character under the cursor into they keyboard input buffer, so more like the Apple II (Esc commands, then forward arrow) than the Commodore PET, etc. style of editing. It worked well enough.
There were a few variants - a cut-down version called the Electron and ending with the BBC Master which had 128KB of RAM and space for an internal 2md processor as well as an external one. (Note the fore-runner to the BBC Micro was called the Acorn Atom and the working name for the BBC Micro was the Proton before it took on the name of the BBC Micro)
As for the BASIC:
I think it's fair to say that the boffins at Acorn HQ had a good, solid comp-sci background and having seen the 6502 "competition" (ie. the various MS Basics for the most part), so with 16MB of ROM space and a built-in operating system (another 12KB) they made a good job.
Integers are 32-bit and pure integer expressions are evaluated as integers without a conversion to floating point. Floating point numbers are 40-bits wide and highly optimised. To the point that my 'benchmark' text-mode Mandelbrot (using floating point only) is a shade under twice the speed in BBC Basic than a MS Basic for the same clock speed.
There are no peek/poke commands as such, however you can store data in RAM and read it from RAM using byte and word indirection operators. To read a byte at location $42 (Acorn use & for hox. notation in BBC Basic, so &42)
Code:
var = ?&42
var here would be floating point, the usual % suffix to indicate integers, so var%.
To read a word (4 bytes), you would use the ! operator (often called 'pling' although I never got past calling it an 'eek' mark)
These can work with an offset, so
Code:
var% = X%?4
would fetch the byte in memory location addressed by X% plus 4. Assignment is: X%!4 = var%[/code]
The question now is how to allocate RAM for poking your data into and the DIM statement allows you to use the DIM'd variable as an address in the indirection operators
Code:
DIM C% 100
C%!4 = &123456AB
Single letter integer variables from @% through Z% are stored in fixed memory locations, so are extra fast.
Variables can be any number of characters long and all characters are significant. Upper and lower case are distinct.
Loops - the usual FOR loop, but also REPEAT .... UNTIL condition (spread over multiple lines)
Functions and Procedures are named and can be written over multiple lines. They can take parameters, can have have local variables and be called recursively.
A recursive string reversal example:
Code:
100 PRINT FN_REV ("Gordon Henderson")
110 END
120 DEF FN_REV(S$)
130 IF LEN(S$) = 1 THEN =S$
140 =RIGHT$(S$,1) + FN_REV(LEFT$(S$,LEN(S$)-1))
Note that I used an underscore character to start the name - one quirk is that there can't be a space between the function name and the DEF FN instruction. Not everyone did it that way though, some used lower case and some just got on with capitals...
There is also a built-in 2-pass assembler... However you have to manage the 2 passes yourself using a FOR loop. Here is an example from the book:
Code:
10 REM DOUBLE HEIGHT IN TELETEXT
20 WIDTH 36: MODE 7
30 VDU 28,0,23,39,0
40 write=!&20E AND &FFFF
50 DIM PROG 100
60 FOR PASS = 0 TO 1
70 P%= PROG
80 [
90 OPT PASS*3
100 CMP#&D : BNE noter
110 PHA :JSR write
120 LDA#&8D : JSR write
140 LDA#&08 : JSR write
150 LDA#&8D : JSR write
160 PLA : RTS
170 .noter CMP #&20 : BCS legal
180 JMP write
190 .legal PHA : JSR write
200 LDA #$0B : JSR write
210 LDA #&08 : JSR write
220 PLA : PHA : JSR write
230 LDA #&0A : JSR write
240 PLA : RTS
250 ]
260 NEXT PASS
270 !&20E=!&20E AND &FFFF0000 OR PROG
280 END
Without going into what that's doing in too much depth, the
FOR loop is the 2 passes and the
OPT instruction signals the assembler what to do - so
OPT 0 on the first pass and
OPT 3 on the 2nd pass (
OPT 0 means ignore errors, needed as we don't have the forward references at that point, and
OPT 3 means report the errors) P% tells the assembler where to put the assembled code, so the code is stored in the array created in the
DIM PROG instruction. Assembly code is placed inside the
[ ] section. Note labels starting with a dot and multiple assembly statement per line using the colon. Macros, while not part of the assembler can be trivial added with procedures - it's still interpreting BASIC as well as running the assembler, so you can make it call a procedure to output more code.
That's mostly the main differences from a 'classic' MS style Basic. The Operating System specific stuff relates mostly the the graphics and sound, but there was on-board analog input (for joysticks, etc.) the OS provided hooks to the filing systems (tape, disk, network) and most other IO - You were not supposed to poke the screen memory, but use the built in's instead - and if you obeyed the rules then your code would work in a 2nd processor (initially a 3Mhz 6502 with much more RAM) without change. (The latest 2nd processor is an ARM based one that will give you a ~300Mhz emulated 6502...)
(And speaking of the ARM, the BBC Micro was used to help develop and test the ISA and the first ARM processor was implemented as a 2nd processor to a BBC Micro - the A in ARM is Acorn)
The key thing is that the BASIC itself is de-coupled from the underlying operating system. The OS manages the screen, keyboard, hardware, etc. leaving the language ROM (Basic in this case) to do what it does best - this enabled development of many other language ROMs (Forth, Comal, Pascal, Lisp, Logo, etc.) leaving more space for the language to do its thing with the OS providing a common interface). Note also - A language ROM could be wordprocessor, spreadsheet, database and so on. The ROMs all occupied the same physical space: &8000 through &BFFF with the OS providing the means to switch between them. (The ROMs were also filing systems and other utilities like graphics extensions and again the OS managed this transparently to the application, so a BASIC program could open a file and it didn't need to know if the file was stored on tape, local disk or network disk.
As for BBC Basic being used in a home-brew system... It's possible and I've done it, although it did require me to write my own version of the Acorn MOS (Machine Operating System) to support the system calls that BASIC needs (the up-shot of this is that I'm able to run some other BBC ROMs too). The OS interface is very well documented and dis-assembled and back-annotated.
The original sources appear to have been lost, along with the copyright holder(s). There is a somewhat convoluted trace of ownership that (as far as I know) ended with a US bank which was destroyed in the twin towers disaster. Does that mean you can use it in a commercial project? Who knows. I'd not like to say, but to my knowledge, no-one has reared their head up to claim copyright.
Note that there are other BBC Basics - The most notable one is RT Russels BBC Basic for Windows. I think RTR wrote the original BBC Basic port to the Z80 2nd processor (which ran CP/M) then went on to develop a commercial version to run under Windows. Today, it's been open sourced and runs under Linux platforms including the Raspberry Pi.
I did a demo of BBC Basic vs. MS. Basic (Actually EhBASIC) on my Ruby board some time back - originally to demonstrate it to some of the Commander X16 people but they go all huffy and pulled it from their facebook pages, however it's on youtube channel here:
https://www.youtube.com/watch?v=ci_70naIg_Q and has the Mandelbrot demo timed.
Hope this helps explain it a little.
Cheers,
-Gordon