jonah
Posts: 1
Joined: Thu Feb 06, 2014 11:18 pm

BBC BASIC sound programming / interfacing with SN76489?

Fri Feb 07, 2014 12:00 am

sorry if this is the wrong place, there are a lot of sub forums, i'm not sure about the overlap.

i was wondering if BBC BASIC written on the Raspberry Pi is compatible with the BBC micro? Could i write code and then run it?

if yes, could i interface with the SN76489 (the main sound chip in the BBC micro) from the Raspberry Pi itself?

if yes to that :) does the "language" of BBC BASIC allow it to work with more than 1 SN76489? If not what would i have to do program assembly macros?

i'm a musician more than a programmer, i can work with arduinos, but i don't find them very "fun". i've done some Atari BASIC programming for their 8bit computers and (although their BASIC is slow) i really like working with BASIC. it's similar to how i think of musical ideas and i find that being able to write messy "bad" code works really well for thinking on your feet. it becomes a basically realtime experience once you have enough code. you can always go back to figure out what you did later and clean it up. :lol: and those old sound chips and their square waves usually sound pretty good run through some filters / EQ. :D

i've read that BBC BASIC has some nice built in commands for working with audio and it's reasonably fast. it would be fantastic to be able to work with it without sourcing "vintage" hardware. the computers themselves mostly still run fine, but peripherals and connectivity to the outside/modern world seems to be a real time and money sink.

thanks for any insight. :)

Steve Drain
Posts: 105
Joined: Tue Oct 30, 2012 2:08 pm
Location: Exeter UK

Re: BBC BASIC sound programming / interfacing with SN76489?

Fri Feb 07, 2014 11:46 am

The version of BBC BASIC for RISC OS on the Pi is ultimately derived from the version on the BBC Micro, so at an elementary level programs can be mutually compatible. However, the sound systems are completely different and despite some superficial likenesses you cannot run programs written for one on the other.

There is no SN76489 chip in the Pi or other RISC OS machines, but there are BBC Micro emulators that emulate that chip and can run original BASIC sound programs. If you are a skilled at ARM assembly, one of the sound chip emulators can be programmed independently, but that is not for the faint hearted.

You can also program the RISC OS sound system in BASIC to produce most of the effects of the SN76489, but that would be rather ignoring the hugely more flexible system that you have in front of you.

I am not personally very experienced with RISC OS sound programming, but if you want to see what is possible you should run the !Maestro application (click the 'Apps' icon on the Iconbar) which is written in BBC BASIC.

For more help you should visit the ROOL forums:

http://www.riscosopen.org/forum

theom
Posts: 73
Joined: Wed Jun 13, 2012 2:53 pm

Re: BBC BASIC sound programming / interfacing with SN76489?

Mon Mar 10, 2014 6:10 pm

If you want to emulate an SN76489 in all its gory details, ZeriBeep should do the trick.
(note that's in a PackDir archive - I think the read-only SparkFS on the Pi can open it)

It works natively in RISC OS, but I don't know if anyone has tested it on a Pi.

fladda
Posts: 18
Joined: Fri Jan 04, 2013 1:46 pm

Re: BBC BASIC sound programming / interfacing with SN76489?

Tue Mar 11, 2014 2:00 pm

I just downloaded ZeriBeeb from John K's website. However, the version of !SparkFS on my RC12? RPi (1.43 dated 16-Sep-12) does not appear to be able to unpack this file. I tried various things including setting the file type to &6E8 (i.e. a PackDir file). The good news is that ZeriBeeb is shown as a 26/32-bit application so there's a moderate chance that this module? might work on the Rpi with native RISC OS :-). I could unpack this on my RISC PC at home.

PackDir on John K's site is only 26 bit so will not work on the RPi natively.

As an aside...

I never cease to be amazed by the amount of useful utilites still out there for RISC OS, and the fact that they now are just a download away. In the old days or yore, getting hold of such RISC OS utilities was a challenge... although that when you finally got them they usually ran, as we then didn't have the current 26/32bit barrier for RISC OS software.

Incidentally I purchased a copy of !SparkFS from David Pilling when it was released around 1989? for the princely sum of GBP 5.00. At the time the floppy disc came with a lifetime free upgrade service if you posted it back to David for upgrading. Unfortunately, I think that I skipped ALL my old acorn floppy discs a couple of years ago, just before the RPi was launched, as I then thought that after the recent RISC OS 'wars', that RISC OS would just continue its long decline into the history books. Who's have thought that many of the old RISC OS stalwarts who'd abandoned RISC OS during the last 5-10 years (like me) would have come back into the fold again. To think that I just skipped most of my old RISC OS stuff a few years ago, including my original 1987 A310, 440, A5000*4!, A7000 and loads of other bits :-( Luckily I kept my Risc PC :-)

Funny old world...

Ralph

dr_d_gee
Posts: 84
Joined: Fri Jan 04, 2013 1:30 pm

Re: BBC BASIC sound programming / interfacing with SN76489?

Tue Mar 11, 2014 2:55 pm

Looking at the website, it seems that ZeriBeep is used by Michael Foot's BeebIt emulator. You can certainly download and install that on a Pi, so presumably ZeriBeep comes with it.

Additionally some of the other tools available on the website let the emulator access files on the "host" i.e. the Pi itself. So you could write the code on the Pi with an editor like StrongED and run the software via the emulator.

fladda
Posts: 18
Joined: Fri Jan 04, 2013 1:46 pm

Re: BBC BASIC sound programming / interfacing with SN76489?

Tue Mar 11, 2014 5:08 pm

Just downloaded the BeebIt emulator, and there is indeed a RISC OS 32-bit relocatable module called "ZBeep" version 1.3.1 written by John K. This does appear to be the BBC sound emulation package.

There are three SWIs (software calls) that could be called from BASIC on the RPi under RISC OS.

Ralph

User avatar
Shawty
Posts: 59
Joined: Fri Nov 16, 2012 1:22 am
Location: North East UK
Contact: Website

Re: BBC BASIC sound programming / interfacing with SN76489?

Tue Sep 09, 2014 5:49 pm

Programming the SN76489 is not all that difficult to be honest (I was one of the original hackers on the BBC Model B that figured out it was possible to make it play sampled sounds, something 'TYB' became famous for, with their mixmania disks)

What many folks fail to realize however is that the SN76489 was only one of a family of many similar sound generation chips.

The most popular of these chips (and the one that's got most info available for it) was the 'AY-3-8912'. This chip actually had 3 audio outputs one for each of the 3 tone channels on it with the noise channel being mixed onto one of the existing tone channels in real time.

In fact, the only real main difference between the 2 chips was a) The SN76489 doesn't have an 8 bit I/O port like the AY series does, B) All audio output was on one pin, but there was an audio input that could be mixed through, Enabling sound generators to be chained together, or in the case of the BBC Model B this was used for the Speech Upgrade kit that added hardware speech capabilities to the machine.

ON the actual BBC Model B all reads/writes to and from the SN76489 where performed over the System 6522 (Otherwise known as Sheila) available from address 0xFE40 to 0xFE4F, in order to get data into the SN76489 chip you had to set data direction register A on the system 6522 to 0xFF so that all the lines where outputs, the data direction register was at 0xFE43.

Once you'd done this, you then had to output the byte you wanted to write to the SN76489 to the write data register on the System 6522 by writing it to memory address 0xFE41

Once you'd loaded the register (Known as the 'Slow Databus') you then had to use output register B on the System 6522 (This is where all the control and interrupt lines where) and set the SN76489 write line low for 8 micro seconds, then bring it high again, the output register B on the System 6522 was at 0xFE40

All of this had to be repeated for each byte of data you wanted to send to the SN76489, well all except setting the Data Direction register A to 0xFF to set all the lines as outputs.

Once you understood this however, and managed to get your data into the SN76489 , programming it was really easy.

To work out the frequency you wanted to send to it you used the following maths:

4000000/32 * (a 10 bit binary number representing the frequency you wanted) - If memory serves I think Middle C was round about 440.

Once you had your frequency you sent it to the SN76489 in the following format:

BIT: 7 6 5 4 3 2 1 0
1 R2 R1 R0 F3 F2 F1 F0

BIT: 7 6 5 4 3 2 1 0
0 x F9 F8 F7 F6 F5 F4

Sorry for the crappy ASCII graphics I never was much good at Text Art :-)

R0, R1 and R2 where the register number on the SN76489 that you wanted to program and F0 through F9 where the 10 bit frequency you worked out previously.

Bit 7 MUST be set to 1 for the first byte and 0 for the second, and bit 6 on the second byte was effectively ignored.

To set the noise source you had to send a byte to the SN76489 in the following format:

BIT: 7 6 5 4 3 2 1 0
1 R2 R1 R0 x FB NF1 NF0

As with setting the frequency, Bit 7 must be 1 and bits 6,5 and 4 where the register number, bit 3 was ignored and bit's 2,1 and 0 set the noise output parameters.

Lastly to change the volume level you used the following byte:

BIT: 7 6 5 4 3 2 1 0
1 R2 R1 R0 A3 A2 A1 A0

Just like the rest Bit 7 was 1, 6,5 & 4 where the register with A4 through A0 being the volume level.

The actual values used where:

Volume levels
-------------
A3 A2 A1 A0 Volume
0 0 0 0 15 (Max)
0 0 0 1 14
0 0 1 0 13
0 0 1 1 12
0 1 0 0 11
0 1 0 1 10
0 1 1 0 9
0 1 1 1 8
1 0 0 0 7
1 0 0 1 6
1 0 1 0 5
1 0 1 1 4
1 1 0 0 3
1 1 0 1 2
1 1 1 0 1
1 1 1 1 0 (Off)

Noise type
----------
FB Noise type
0 Periodic noise
1 White noise

Noise Frequency
---------------
NF1 NF0 Frequency
0 0 Low
0 1 Medium
1 0 High
1 1 Frequency currently assigned to channel 1

Register Number
---------------
R2 R1 R0 Frequency
0 0 0 Channel 3 Frequency
0 0 1 Channel 3 Volume
0 1 0 Channel 2 Frequency
0 1 1 Channel 2 Volume
1 0 0 Channel 1 Frequency
1 0 1 Channel 1 Volume
1 1 0 Noise Control
1 1 1 Noise Volume

So thats the hardware :-) and since your running on a Pi with a good amount of I/O availability it shouldn't be very difficult to source one of these chips and hook it up to a Pi to using a breadboard or similar, the fun part is going to be getting the OS using it.
(cont)
still crazy (Even since the days of my BBC Model B) BEST and only way to be ;-)

IM: @shawty_ds on twitter
if you remember the Acorn and BBC days then I was "!Shawty! of DSPD" (Author of the BBC B Sound Tracker suite, and the Dreamscape demo)

User avatar
Shawty
Posts: 59
Joined: Fri Nov 16, 2012 1:22 am
Location: North East UK
Contact: Website

Re: BBC BASIC sound programming / interfacing with SN76489?

Tue Sep 09, 2014 5:49 pm

(cont)

Now I'll say right now, Iv'e heard of this RiscOS pico thing but I've not used it yet, I am however a veteran of the original RiscOS (3.11 onwards - heck I even remember Arthur it's predecessor!!)

The one thing that Acorn got absolutley right with RiscOS was the way the designed it.

In the BBC OS (Which the original BBC Basic II was supplied with) all of the basic sound commands where provided using operating system calls, OSWORD 7 to be exact.

In fact a great many of the things that BBC basic did where passed directly through to the underlying operating system using OSBYTE and OSWORD calls.

Beacuse of the way OSWORD worked (and the design of the BBC's OS) each call was vectored, so it was amazingly easy to intercept calls to the underlying OS and redirect them elsewhere (I recall seeing Johnathan G Harston once demonstrating a MIDI interface he'd built and plugged into the BBC Model B that faithfully played EVERYTHING sent using a BBC Sound command on an external midi keyboard)

This redirection meant that you could intercept the "SOUND x,x,x,x" command in BBC Basic and make sure it never got to the actual SN76489 chip, or you could extend it, send it out on the User 6522 chip and have a second sound chip available externally, you could do just about anything very easy.

When Acorn developed RiscOS they maintained this mentality and made the underlying RiscOS not only modular (Using Relocatable Modules) but they also implemented a RiscOS version of EVERY SINGLE OSBYTE and OSWORD call that the original BBC understood.

This made life porting BBC B software to the Archimedies range extremely easy, and this included porting BBC Basic.

The main difference on the Archimedies range was that the OSWORD 7 calls for producing sound where re-directed through a RiscOS specific operating system extension that knew how to interface to the new hardwares sound system.

The good news is that not only did Acorn port accross all the relevent OSBYTE and OSWORD hooks, they also ported accross the various OSxxxxx calls used to intercept OSBYTE and OSWORD vectors, which means that even today as long as RiscOS remains faithful and still includes these various compatability calls under the hood, it would not be at all difficult to create a relocatable module which you then softload in !boot.

Said Relocatable Module could then intercept OSWORD 7 tus also intercepting the BBC Basic sound command.

Your relocatable module could then via the R-Pi's extensive I/O capabilities interface directly to an external SN76489 chip, thus providing your RiscOS driven R-Pi with genuine and authentic BBC Model B sound.

Shawty
still crazy (Even since the days of my BBC Model B) BEST and only way to be ;-)

IM: @shawty_ds on twitter
if you remember the Acorn and BBC days then I was "!Shawty! of DSPD" (Author of the BBC B Sound Tracker suite, and the Dreamscape demo)

Return to “RISCOS”