Showing posts with label BBC BASIC. Show all posts
Showing posts with label BBC BASIC. Show all posts

Search for the most precious substance in the universe


Who thought it was unobtainium?

Riemannian is a text-based space adventure game written in BASIC. I am not certain of its origins but it was converted to BBC BASIC by Janny Looyenga (and I think it was released as either a Beebug, or an Acorn User magazine disk).

I have just spent my afternoon converting it to run on the Raspberry Pi under RISC OS and subsequently on the PC under BBC BASIC for Windows.

In Riemannian, you control a spacecraft, which teleports randomly around a text-based Teletext universe. You have three resources that need to be managed: oxygen, fuel and provisions. Your quest requires you to mine as much of the elusive riemannian ore before your resources run out and you are unceremoniously dumped back to the BASIC prompt.

On your journey, you will encounter aliens, both friend and foe. Some will wish to sell you commodities, whilst others try to blow you away with their laser guns and robot slaves. There are also some other special encounters, but I wouldn't want to spoil your fun of encountering these yourself.

This world is very notable for the Uslian tree ant and its inhabitants' exceptional loathing of sit coms

I have covered how to convert BBC microcomputer programs to RISC OS BASIC programs in another post.

The main problem I had to overcome is the fact that, in Riemannian, much of the gameplay is time-based. You have to press the right key at just the right time to zap an alien or mine the planetoids. Upon inspection of the code, two facts became obvious. Firstly, the code was a horrible mess of spaghetti (probably indicating that it originated on a less elegant 8-bit machine to the BBC micro) and second, much of the timing revolved around how many loops the computer could perform whilst waiting for your input. As my target machine, the Raspberry Pi, is a much faster machine, I had to alter these timing loops so the original gameplay was restored. I think I have managed whilst also making the game a little more forgiving than the original.

From a time when mining was much more about guesswork (just like modern Fracking).

+1 Geek Experience Point awarded to by Janny Looyenga for the original BBC BASIC conversion.

I am going to assume that due to its age, Riemannian is currently in the public domain. So you can download a copy from my OneDrive. If you are the owner of Riemannian, and it is your sole source of income, then I am really sorry and I will remove this link as soon as you get in touch.

I've provided four versions:

  • A RISC OS BASIC file
  • A plain text file containing all the code
  • A BBC BASIC for Windows file
  • A Windows executable file (it is totally NOT a virus, but if you are in doubt run it in a sandbox such as Virtual Box rather than trusting a strange blogger on the Internet).

If you enjoyed this post, then that is it, you have reached the very bottom of the Web, but you might like some other conversions of ancient BASIC programs, such as this one, or this one, but especially this one.

That's it for today. I will be back later for more geeky stuff - stay tuned!

More groovy patterns for Raspberry Pi

Following on from the last post about groovy patterns for Raspberry Pi, I present my latest program, another random walk.

It is a random walk similar to last time, however with this one there are three degrees of freedom (rather than horizontal and vertical) and rather than a line, the object displayed in a coloured 3D box.
This code is for BASIC V running under RISCOS on the Raspberry Pi. Copy the code, or download directly.

The code:

   10 REM Blocks
   20 REM T Street
   30 REM 2017-05-21
   40 :
   50 MODE 19
   52 delay = 0
   55 colcyc = 0
   60 angle1 = RAD(45): angle2 = RAD(20)
   70 size = 16
   72 LIMIT = 50
   73 DENSITY = 40
   80 xo=500:yo=500
   90 x = xo: y=yo
  100 dir = RND(5)
  110 PROCsetdir
  112 lc = 0
  114 dc = 0
  120 REPEAT
  140   PROCbox(x,y,size,angle1,angle2)
  141   t=TIME:REPEAT UNTIL TIME>t+delay
  150   x = x + dx: y = y + dy
  151   lc = lc + 1
  160   IF RND(6) = 1 THEN PROCchangeDir
  170   IF x<0 OR x>1000 OR y<0 OR y>1000 OR lc>LIMIT THEN
  180     x=xo:y=yo
  181     colcyc = colcyc+2: IF colcyc > 127 colcyc = 0
  182     lc = 0
  183     dc = dc + 1
  190   ENDIF
  191   IF dc>DENSITY THEN
  192     dc = 0:CLS:x=xo:y=yo:lc = 0
  193   ENDIF
  200 UNTIL FALSE
  210 END
  220 :
  230 DEFPROCbox(x,y,s,ar,au)
  240 REM draws a box at coords x,y
  250 REM where the coords are the lower left corner
  260 REM and s is the size of box
  270 REM and ar and au are angles
  280 MOVE x,y
  290 LOCAL up, right
  300 up = s*SIN(au)
  310 right = s*COS(ar)
  320 REM front side
  330 GCOL 2+colcyc
  340 MOVE x,y+s
  350 PLOT 85,x+s,y
  360 MOVE x+s, y:MOVE x, y+s
  370 PLOT 85, x+s, y+s
  380 REM right hand side
  390 GCOL 1+colcyc
  400 MOVE x+s+right, y+up: MOVE x+s, y+s
  410 PLOT 85, x+s, y
  420 MOVE x+s+right, y+up: MOVE x+s, y+s
  430 PLOT 85, x+s+right, y+s+up
  440 REM top
  450 GCOL 1+colcyc
  460 MOVE x+right, y+s+up: MOVE x+s, y+s
  470 PLOT 85, x, y+s
  480 MOVE x+right, y+s+up: MOVE x+s, y+s
  490 PLOT 85, x+s+right, y+s+up
  491 GCOL 0
  492 MOVEx,y:DRAW x+s,y:DRAW x+s,y+s:DRAWx,y+s:DRAW x,y
  500 ENDPROC
  510 :
  520 DEFPROCsetdir
  530 CASE dir OF
  540   WHEN 1
  550   dx = 0: dy = size
  560   WHEN 2
  570   dx = size: dy = 0
  580   WHEN 3
  590   dx = 0: dy = -size
  600   WHEN 4
  610   dx = -size: dy = 0
  620   WHEN 5
  630   dx = -(size*COS(angle2)): dy = -(size*SIN(angle2))
  635   WHEN6
  636   dx = (size*COS(angle2)): dy = (size*SIN(angle2))
  640 ENDCASE
  650 ENDPROC
  660 :
  670 DEFPROCchangeDir
  680 dir=RND(6)
  690 PROCsetdir
  700 ENDPROC
  710 :


BBC BASIC on Raspberry Pi

Recently I wrote about setting up RISC OS Pi for Raspberry Pi. One of the good things about RISCO OS is that it has a built in BASIC interpreter which is backwards compatible (mostly) with your BBC micro computer BASIC.

One way of running BBC software on your Raspberry Pi is to use an emulator, however it is also possible to run 'beeb' BASIC programs from your pinboard or command line, as this blog post will attempt to show.

RISC OS pinboard showing native BASIC apps and a stormy day in Scarborough.

Whether you choose to run the emulator, or run BASIC as native programs, your first port of call will be some BBC disc images. You might choose to download your BASIC disc images from the internet, or you may already have them on your vintage beeb machine. This post will cover both situations.

  • First load your disc image into your BBC emulator on your PC. I will be using the excellent BeebEm emulator for Windows.  To do this select: File > Load Disc 0 and find the disc image in your file explorer. The disc image will now be loaded into a virtual drive in your emulator. To see the files, type *cat in the BASIC command line.
Load your disc image into your emulator.
  • Export the BASIC programs that you want from the disc image. BeebEm provides you with the option of exporting a file from your disc image onto you PC. Save this onto a USB flash drive.  To do this select: Edit > Export Files from Disc > Disc 0

Export the BASIC files from the disk image onto a USB device.
  • Rename the file that has been exported. You don't want the DFS directory information showing. For example, change $.file to file only.
  • Plug the USB device into your Raspberry Pi. RISC OS should see the USB device which will allow you to copy the file and save it wherever it makes sense on your machine.
You should see the USB drive appear on your icon bar.
  • At this point you will probably have to change the file type to 'BASIC' rather than 'Text'. To do this, press the middle 'menu' mouse button and choose the appropriate option from the menu.
  • Your BASIC program will be ready to run directly from your pinboard.
To run from the command line, you will need a couple of extra steps.

  • First select the filing system for your USB drive. This is likely to be the command *fat32fs

  • Then mount the disk with *mount 0 or *mount 1 depending on the number of USB devices you have. To get a directory listing try *dir :0 followed by *cat and hopefully you will see your file. This can be executed with CH."filename" or edited with LOAD"filename" and LIST or RUN.

If in doubt, RISC OS provides documentation with the *help command. To return to the main filing system type *SFDS

Data Centre

If you have BASIC programs on floppy disc on a vintage beeb machine, you can also get your code running on RISC OS using the brilliant Data Centre from RetroClinic.

The documentation that comes with your data center explains fully how to transfer disc images from floppies or Compact Flash cards onto your PC.

In my case, I am transferring files stored on compact flash drive under ADFS to virtual RAM drives under DFS. These can then be exported onto the USB stick.  Once you have the disc images you can follow the instructions on getting them running on your Raspberry Pi from above.

Compatibility

Although you will find that most of your BBC micro, Electron or Master BASIC programs will run on your RISC OS Pi or RISC OS pico machine, there may be some minor compatibility problems.

Most notably is that you are going to find that your programs run fast. Very fast! This might not be a problem, in fact it might be very welcome if your program involves a lot of graphics. It could be a problem if you wish to play a game but don't have the reflexes of a Jedi.

With a program that I wrote myself for the BBC Master I notice that the different keyboard layout of the BBC machine and a modern USB keyboard caused an issue. This was because my program uses the key combination SHIFT + '3' to reset a timer. On the BBC machines this combination of keys produces the octothorpe character '#' whereas on my IEEE keyboard, this combination produces the '£' character. This was a minor problem which was overcome by a quick patch of the code.

Another problem was that some BBC BASIC programs do not have well-defined exit strategies. Oftentimes the way out of the program is to reset the machine with the 'BREAK' key. Under RISC OS this may cause programs to hang forever requiring a full reboot of the machine.  In most cases you either need to put up with this, or write an exit strategy.

One way of doing this would be to program the 'ESC' key to act like the 'BREAK' key. Just add the following BASIC line into the start of your program:

  ON ERROR IF ERR = 17 OSCLI("DESKTOP")

If you have enjoyed this post then you might want to read other posts about the Raspberry Pi, or about the BBC micro systems, or just something at random from this blog.



Spider webs by natural selection

I recently discovered this awesome BBC BASIC program for simulating spider webs through natural selection. It was written by Matthew Tizard for the BBC Acorn User magazine October 1992.

Natural selection left running on a BBC Master 128 for a couple of days.

The program generates nine 'spider webs'. The fittest spider web is the web that catches the most 'flies'.  This web is then chosen to go into the next generation.

Natural selection running on BeebEm with 6502 Second processor showing nine generations with 'flies' turned off.


I found that the program is best run with your second processor turned on (for hopefully obvious reasons). In fact I found that you get approximately three times improvement in speed, with one generation taking about twenty seconds to generate, draw and test on screen.

You can easily switch on your second processor using BeebEm as shown above.

Another version of the program allows you to control evolution by choosing which web you wish to survive into the next generation. In this way you can select for characteristics that you like, not necessarily the ones that will catch the most flies.

Assuming that the program is in the public domain I have put the files onto a BBC disk image which you can download from the link below.
BBC Disk Image

You will need to load the disk image into your emulator program, or directly into your microcomputer using the datacenter, MMC unit or otherwise copy it onto a floppy disk.

There is a readme file which can be loaded with *type T.readme

The programs can be executed with CHAIN "ArtAuto" OR CHAIN "ArtLife".  Press <ESCAPE> and type LIST to see the program code.


+1 Geek Experience point for Matthew Tizard

#geek #bbcmicro #naturalselection #spiderwebs

RISC OS Pico

I was delighted to discover recently of the existence of RISC OS pico for the Raspberry Pi.

RISC OS Pico is a stripped-down version of RISC OS for Raspberry Pi. Essentially they have stripped out the graphical user interface from the operating system leaving a Raspberry Pi that boots directly into BBC BASIC VI.

Raspberry Pi booting into RISC OS Pico, showing BASIC prompt and more RAM than you could possibly ever fill.

RISC OS is an operating system designed in Cambridge, England by Acorn. First released in 1987, its origins can be traced back to the original team that developed the ARM microprocessor. Anyone who remembers the Acorn Archimedes range of computers will be familiar with RISC OS. For a 30 year-old OS, it really was ahead of its time. RISC OS in now owned by Castle Technology Ltd. You can find my adventures with RISC OS lurking on this blog.

RISC OS Pico boots very quickly (about eight seconds on my Raspberry Pi 2 between pressing SHIFT+BREAK and getting the BASIC prompt) as shown in this video (running on an early model Pi):



Installation is very easy. You simply extract the ZIP archive onto an SD card with FAT format.  The hardest part is finding an SD card that can be formatted in FAT format (not FAT-32).

Once loaded you have a computer that boots directly to BASIC, leaving you with a rather silly amount of RAM available for your programs - thousands of times more memory than available on the original BBC microcomputers, and of course a much faster processor.  BBC BASIC VI is rather more advanced that BASIC IV on the BBC Master, with greater graphics capability and some extra commands such as WHILE...ENDWHILE and CASE...ENDCASE structures.

The distribution comes with some example programs and a guide to writing BASIC programs for RISC OS.  There is no other documentation supplied (unless I am looking in all the wrong places) so you will have to figure stuff out for yourself.

Setting the time is achieved through the BASIC command:

TIME$ = "16 Sep 2016.18.51.00"

Or whatever the current time is for you, although you will be disappointed if you do not have an on-board battery backup, which sadly the Pi does not yet have (the clock resets to 1970 when you power down).

Retrieving the time is achieved through either printing this variable, or the operating system call:

OSCLI("TIME")

Other nice features I have discovered so far:

There is a BASIC editor program that beats the BBC Master.  Simply type 'EDIT'.  Options are selected using the function keys:

f1 - OS command
f2 - LOAD program
f3 - SAVE program
f4 - Search and edit
f5 - Search and replace
f7 - Search

A full list of function key definitions can be achieved with CTRL + f5.

There is also a full set of documentation for each of the BASIC commands.  Simply type:

HELP <command>

Well, that's it for now, because that is all I have learned so far.  I am going to continue to play with Pico, possibly try and get some BBC Master programs to run on it, so be sure to come back soon for more...

...if you are still awake, then you might like to read some more posts about the BBC Computers or RISC computers, or you might just want to play a browser-based adventure game.

#BBCBASIC #RISCOS #Pico #RaspberryPi





Label

World Karma Game