September 03, 2012, 07:21:55 pm
News:
Pages: [1]
Print
Author Topic: "Brandy" BBC BASIC on the OSD  (Read 461 times)
heyrick
Global Moderator
Sr. Member
*****
Posts: 325



View Profile WWW
« on: June 12, 2011, 05:30:08 pm »

Hi, just for fun I have compiled the "brandy" BBC BASIC interpreter for the OSD. Those of you who are British and grew up with the BBC micro (or, better, the Archimedes) will probably be familiar with the sort of BASIC that left everything else standing (yup, even the AppleII pales in comparison to the mighty Beeb).

Anyway, it is too large to attach (some 280KiB raw, 95KiB Zip) so you can download it and some example programs from:

Unzip it, copy it to an SD card or such to get it over to your OSD. When you have done so, enter:
  chmod 755 brandy
to make it executable.

Then, to run it, enter:
  ./brandy <program name>

For example:
  neuros login: root
  Password:


  BusyBox v1.6.1 (2009-05-21 23:20:05 PDT) Built-in shell (ash)
  Enter 'help' for a list of built-in commands.

  ~ $ ./brandy hanoi
  Number of discs? 3
   Move disc 1 from left to right
    Move disc 2 from left to middle
   Move disc 1 from right to middle
     Move disc 3 from left to right
   Move disc 1 from middle to left
    Move disc 2 from middle to right
   Move disc 1 from left to right
  7 steps in 0.02 seconds
  >



Some points:
  • A la RISC OS, you can use "brandy -quit <prog>" or "brandy -load <prog>", etc.
  • Entering "help" does not list commands, duh. For this, I'd refer you to http://www.bbcbasic.co.uk/bbcbasic.html
  • Can't get out? Try QUIT.
  • As it was intended for OSD console use, the features available are VERY simple. Most display-related things (CLS, MODE, VDU, GCOL, etc) do not work.
  • You can get Brandy for Windows, Linux, RISC OS, Amiga, and it's open source if you want it elsewhere.
  • The examples aren't terribly exciting.
  • There is no integration with the OSD. You can't use it to manage scheduled entries, etc. Try using Lua for this.
  • The platform identification, via INKEY(-256), is &F9

BBC BASIC uses an ampersand (&) prefix to hex numbers, and a percent (%) prefix to binary numbers. Printing a number prefixed with a tilde (~) will convert it to hex.
Examples:
  >P. ~&DEAD
        DEAD
  >P. &BEEF
       48879
  >P. ~48879
        BEEF
  >P. %01111011
         123
  >


The first example converts hex to hex. Not so useful. Then we convert hex to denary, and back again, and finally binary to denary (there is no simple way to convert back, it's just there to make it easy to set bitfield flags).


You can call OS functions by prefixing them with a star (*) or programmatically using the OSCLI call.
Example:
  >*ls
  brandy           deupk       sqlite
  dosfsck          hanoi       videoinfo
  >OSCLI("ls -l")
  -rwxr-xr-x    1 root     root       287376 Jun 12 22:07 brandy
  -rwxr-xr-x    1 root     root        12592 Jun 12 00:23 deupk
  -rwxr-xr-x    1 root     root        46620 Jun 12 00:23 dosfsck
  -rwxr-xr-x    1 root     root          461 Jun 12 00:24 hanoi
  drwxr-xr-x    2 root     root         1024 Jun 12 00:24 sqlite
  -rwxr-xr-x    1 root     root         8740 Mar  2 02:10 videoinfo
  >




For those who wish to try out brandy, here's a little program that might be of more use!
REM >bhex
REM
REM Dead simple hex viewer
REM Rick Murray, 2011/06/12
REM Released under EUPL v1.1
REM

DIM buf% 16

OSCLI("ls")
INPUT "Filename";fn$

fp% = OPENIN(fn$)

ln% = EXT#fp%
ln% = (((ln% / 16) + 1) * 16)

here% = 0
head% = 0

WHILE (here% < ln%)

  REM Heading? (every 16 lines)
  IF (head% = 0) THEN
    PRINT '"Address  : 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F :    ASCII data"'
  ENDIF
  head% += 1
  IF (head% > 15) THEN head% = 0

  REM Read data
  FOR p% = 0 TO 15
    IF (NOT EOF#fp%) THEN
      buf%?p% = BGET#fp%
    ELSE
      buf%?p% = 0
    ENDIF
  NEXT

  REM Print offset
  PRINT RIGHT$("00000000" + STR$~(here%), 8) + " : ";

  REM Print hex values
  FOR l% = 0 TO 15
    PRINT RIGHT$("00" + STR$~(buf%?l%), 2) + " ";
  NEXT

  REM Print (filtered) ASCII
  PRINT ": ";
  FOR l% = 0 TO 15
    IF ((buf%?l% < 32) OR (buf%?l% > 126)) THEN buf%?l% = ASC(".")
    PRINT CHR$(buf%?l%);
  NEXT
  PRINT

  here% += 16
ENDWHILE

CLOSE#fp%

END


You can run this with a command like ./brandy -quit bhex and then entering the filename.


Best wishes,

Rick.
Logged
Pages: [1]
Print
Jump to: