Serial port BASIC commands

discussion of beeb/electron applications, languages, utils and educational s/w
Post Reply
courseddent
Posts: 43
Joined: Tue Feb 26, 2019 10:16 pm
Contact:

Serial port BASIC commands

Post by courseddent » Mon Oct 14, 2019 6:46 pm

I'm interested in controlling vintage analogue synths using my BBC Master. At the moment the slightly convoluted route is to get the BBC to output bytes over the serial port, which I'll convert to MIDI externally.

My plan was to write a simple step sequencer in BASIC which will output these bytes. So my question is what BBC BASIC commands I use to output data specifically to the serial port? I've been looking through an old User Guide, particularly the "Using printers" section, but haven't found it massively illuminating for the simple task of just sending a few bytes to the serial port occasionally from a BASIC prorgam.

I understand that this approach may not work out well in the end, but wanted to have a go at it before I start solder MIDI interfaces together.

Also, any tips on other ways to do this would be great, perhaps using Pascal or C?

Thanks!

User avatar
jgharston
Posts: 3798
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Serial port BASIC commands

Post by jgharston » Mon Oct 14, 2019 9:18 pm

courseddent wrote:
Mon Oct 14, 2019 6:46 pm
I'm interested in controlling vintage analogue synths using my BBC Master. At the moment the slightly convoluted route is to get the BBC to output bytes over the serial port, which I'll convert to MIDI externally.
Sounds like that would be a lot easier with a MIDI interface.
courseddent wrote:
Mon Oct 14, 2019 6:46 pm
My plan was to write a simple step sequencer in BASIC which will output these bytes. So my question is what BBC BASIC commands I use to output data specifically to the serial port? I've been looking through an old User Guide, particularly the "Using printers" section, but haven't found it massively illuminating for the simple task of just sending a few bytes to the serial port occasionally from a BASIC prorgam.
BASIC doesn't know anything about serial (or any other) ports. The operating system deals with them.

You can select the serial port as the input stream and then just read from the input stream just as you would normally read from the input stream. Similarly, you can select the serial port as one of the output streams and then write to the output stream just as you would normally write to the output stream.

*FX2,1 enables and selects serial input. Input can only come from one source at a time.
*FX3,3 sends output to the serial port. Output can go to multiple destinations.
ADVAL(-2) will tell you if there are any bytes in the serial input buffer.
ADVAL(-3) will tell you if there is any space in the serial output buffer.

An example bare-bones serial terminal program is:

Code: Select all

ON ERROR OSCLI "FX2":OSCLI "FX3":REPORT:PRINT:END
*FX229,1
*FX2,2
REPEAT
IF ADVAL(-1):OSCLI "FX3,3":VDU GET:*FX3
IF ADVAL(-2):OSCLI "FX2,1":VDU GET:*FX2,2
UNTIL FALSE
A crude way to send a single byte to the serial port is:
DEFPROCserout(A%):OSCLI"FX3,3":VDU A%:OSCLI "FX3":ENDPROC

A crude way to read a single byte from the serial port is:
DEFFNserin:OSCLI"FX2,2":IF ADVAL(-1)=0 THEN =-1
OSCLI "FX2,1":A%=GET:OSCLI "FX2,2":=A%
It returns -1 if nothing is waiting or the the waiting byte if one is waiting.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

johnkenyon
Posts: 224
Joined: Wed Jul 20, 2011 2:21 pm
Location: Coventry
Contact:

Re: Serial port BASIC commands

Post by johnkenyon » Tue Oct 15, 2019 8:34 am

Use a separate MIDI port.
If you don't:
1) You will have to modify the clock to the 6850 (Midi uses 31250 baud, so you'll need a 31250 x whatever multiplier Hz clock)
That will stop you from using the serial port "normally", and will also break the tape interface

2) You will have to mess around with the input and output levels - you can do this externally, but given that fiddling with the clock will break the serial interface anyway...

If I were to do DIY with MIDI, I would either build a board to connect a 6850 with a fixed clock and the required receiver/transmitter gubbins to the 1MHz bus, or to connect to the internal modem connector on the master (would definitely have to use a 68B50).

Coeus
Posts: 1416
Joined: Mon Jul 25, 2016 11:05 am
Contact:

Re: Serial port BASIC commands

Post by Coeus » Wed Oct 16, 2019 1:03 pm

As well as project designs for a MIDI interface there was a commercial one, the M2000, as part of the Hybrid music system.

Thinking of which, the Hybrid software can act as a MIDI sequencer too.

User avatar
jgharston
Posts: 3798
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Serial port BASIC commands

Post by jgharston » Wed Oct 16, 2019 2:17 pm

Coeus wrote:
Wed Oct 16, 2019 1:03 pm
As well as project designs for a MIDI interface there was a commercial one, the M2000, as part of the Hybrid music system.
There were serveral, of which the Hybrid M2000 and the ElectroMusicResearch system are the ones I've been able to reverse engineer. As with the EPE, ETI and JGH self-build ones, they all use a (/two) 6850s and all but the M2000 are at the same address. You can use the *MIDI driver that allows you to use SOUND commands to talk to MIDI devices without having to play with the hardware (add an extra parameter to *MIDI to drive the M2000).

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

courseddent
Posts: 43
Joined: Tue Feb 26, 2019 10:16 pm
Contact:

Re: Serial port BASIC commands

Post by courseddent » Wed Oct 16, 2019 11:00 pm

jgharston wrote:
Mon Oct 14, 2019 9:18 pm
A crude way to send a single byte to the serial port is:
DEFPROCserout(A%):OSCLI"FX3,3":VDU A%:OSCLI "FX3":ENDPROC
That's exactly what I was after, thank you so much.

My overall longer term plan was to build one of the reverse engineered MIDI interfaces, however it will take me quite a while to design and etch boards to build one of these. If anyone has any tips on this, or even a source for them, they would be very much appreciated!

My plan in the meantime was to output bytes at say 9600 baud on the serial port, then convert these bytes to MIDI using an Arduino. It's a horrible hack, and it's possible that the timing will be so bad that it won't work at all, but I was keen to get something up and running and this way it would take more like an hour or so, versus a couple of days for me to design and solder the MIDI board.

User avatar
Elminster
Posts: 3979
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: Serial port BASIC commands

Post by Elminster » Thu Oct 17, 2019 8:30 am

There are a few Midi kit remakes (although not on serial port). Have you checked the hardware list in my signature below.

E.g.
jasonl has done the whole music x000 series

https://github.com/jlbeebprojects/music4xxx-AtMega
viewtopic.php?f=3&t=16895
Last edited by Elminster on Thu Oct 17, 2019 11:32 am, edited 1 time in total.

User avatar
1024MAK
Posts: 9603
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Serial port BASIC commands

Post by 1024MAK » Thu Oct 17, 2019 11:31 am

courseddent wrote:
Wed Oct 16, 2019 11:00 pm
My plan in the meantime was to output bytes at say 9600 baud on the serial port, then convert these bytes to MIDI using an Arduino.
Ahh, back in the old days, it was possible to wire up two UARTs (the type that did not need a microprocessor to set them up) back to back with a little glue logic to do speed / data rate conversion. But the type of UART required has been obsolete and out of production for a very long time...

Mark

User avatar
jgharston
Posts: 3798
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Serial port BASIC commands

Post by jgharston » Thu Oct 17, 2019 1:16 pm

courseddent wrote:
Wed Oct 16, 2019 11:00 pm
My overall longer term plan was to build one of the reverse engineered MIDI interfaces, however it will take me quite a while to design and etch boards to build one of these. If anyone has any tips on this,
Use stripboard.
Image
wiring diagram
or even a source for them, they would be very much appreciated!
Watch the bay of fleas.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

courseddent
Posts: 43
Joined: Tue Feb 26, 2019 10:16 pm
Contact:

Re: Serial port BASIC commands

Post by courseddent » Thu Oct 17, 2019 10:02 pm

Elminster wrote:
Thu Oct 17, 2019 8:30 am
There are a few Midi kit remakes (although not on serial port). Have you checked the hardware list in my signature below.

E.g.
jasonl has done the whole music x000 series

https://github.com/jlbeebprojects/music4xxx-AtMega
viewtopic.php?f=3&t=16895
Ah ha! Now that's what I'm after! I'm going to get the 2000 one made up. I wonder if I should make a few if people want them since I'll need to buy multiple components.

As far as I can see this should work well with the *MIDI redirection thing here:

http://mdfs.net/Software/MIDI/Redirect/MIDI.txt

Is that right?

courseddent
Posts: 43
Joined: Tue Feb 26, 2019 10:16 pm
Contact:

Re: Serial port BASIC commands

Post by courseddent » Fri Oct 18, 2019 10:09 am

One other question - I'm unsure which 6850 chip would be suitable. There's loads listed on ebay:

MC6850
MC6850P
MC6850S
MC6850L
F6850P

Maybe there all the same an the first letters are the manufacturer and last letter is package type? Also there seems to be some newly manufactured ones from China as well - would it be worth going for these?

johnkenyon
Posts: 224
Joined: Wed Jul 20, 2011 2:21 pm
Location: Coventry
Contact:

Re: Serial port BASIC commands

Post by johnkenyon » Fri Oct 18, 2019 12:40 pm

courseddent wrote:
Fri Oct 18, 2019 10:09 am
One other question - I'm unsure which 6850 chip would be suitable. There's loads listed on ebay:

MC6850
MC6850P
MC6850S
MC6850L
F6850P

Maybe there all the same an the first letters are the manufacturer and last letter is package type? Also there seems to be some newly manufactured ones from China as well - would it be worth going for these?
As far as the part numbers are concerned, I think you have it right.

You might be better off posting a request in viewforum.php?f=9 which might yield a known working device that won't take a month to arrive...

User avatar
1024MAK
Posts: 9603
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Serial port BASIC commands

Post by 1024MAK » Fri Oct 18, 2019 1:42 pm

MC is a prefix used by Motorola
The suffix often includes a letter to indicate the type of package, but can also identify other features. Lead or lead free pins, improved version, speed rating, etc.
The two most common suffixes for a DIL / DIP plastic package are N and P, but it varies between different manufacturers.

Often the data sheet, or the data book will give details.

Be careful of ‘new’ chips from China or sold on eBay and other sites that allow third part sellers to trade. These are often just old chips (‘pulls’) that have had the markings on the top erased, new markings put on, the pins cleaned up and then sold as ‘new’.

The problem is, that although a lot of these work, the markings may no longer reflect the chip contained inside. So for example, a 2MHz NMOS 6502 may be remarked as a 4MHz CMOS 65C02...

And in some cases, the chips may not work at all, or only partially work.

If you want to see if a chip is in production, and it’s one of the big semiconductor companies, visit their web site. Most list details included if they are obsolete, not recommended for new designs, in production, etc, etc...

Motorola sold their semiconductor business, so there will be no new Motorola chips...

Mark

User avatar
1024MAK
Posts: 9603
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Serial port BASIC commands

Post by 1024MAK » Fri Oct 18, 2019 1:49 pm

A PDF of the datasheet for the MC6850 is here.

Mark

courseddent
Posts: 43
Joined: Tue Feb 26, 2019 10:16 pm
Contact:

Re: Serial port BASIC commands

Post by courseddent » Fri Oct 18, 2019 1:52 pm

1024MAK wrote:
Fri Oct 18, 2019 1:42 pm
Be careful of ‘new’ chips from China or sold on eBay and other sites that allow third part sellers to trade. These are often just old chips (‘pulls’) that have had the markings on the top erased, new markings put on, the pins cleaned up and then sold as ‘new’.
Mark
Ah that's great to know, I suspected it would be worth avoiding 'new' ones. And thanks for passing on the datasheet - all much clearer now!

courseddent
Posts: 43
Joined: Tue Feb 26, 2019 10:16 pm
Contact:

Re: Serial port BASIC commands

Post by courseddent » Fri Oct 18, 2019 1:54 pm

johnkenyon wrote:
Fri Oct 18, 2019 12:40 pm
You might be better off posting a request in viewforum.php?f=9 which might yield a known working device that won't take a month to arrive...
Thanks - hadn't even noticed that there was a wanted section - have posted in there. Absolutely - could save me a lot of waiting!

User avatar
jgharston
Posts: 3798
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Serial port BASIC commands

Post by jgharston » Fri Oct 18, 2019 6:14 pm

courseddent wrote:
Thu Oct 17, 2019 10:02 pm
As far as I can see this should work well with the *MIDI redirection thing here:
http://mdfs.net/Software/MIDI/Redirect/MIDI.txt
Is that right?
Yes, it will do. Depending on if the addressing is fully decoded or not you may need to use *MIDI &FC08 or customise to set the default address with the instructions in the Technical Notes section.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

Post Reply