[comp.sys.amiga.tech] Setting the serial port baudrate from Basic

e85rw@efd.lth.se (Ricard Wolf) (12/07/90)

Hi Amiga fans!

I friend of mine is wrting som compositional software for his Amiga, to
drive synthesizers via MIDI. He has got a small hardware box converting
the RS-232 signal levels to the current loop type interface required by 
MIDI. 

The problem is, he will be writing the code in BASIC, and he can not
set the serial port baud rate to the required 31.25Kbaud requeired by
the MIDI protocol. The only possible baud rates seem to be the 
cannonical 1200,2400,4800 etc. Obviously the serial port can be set
to non-standard baud rates, since it has been done in various sequencer
programs available for the Amiga. The question is, is it possible to do
in a BASIC environment? And in that case, HOW??? Any hints would be
appreciated, even short segments of assembler/machine code...

Of course BASIC is quite slow compared to MIDI, but he is only interested
in driving synthesizers via MIDI out, so even if the serial port is unbufferd
on receiving data, it should be possible to write at a reasonable speed.

Email would be nice (I don't really feel like wading through tons
of Amiga info (I don't actually use one myself (no rotten eggs, please))),
but I guess this would have a wide enough appeal to be posted.

-- 
Ricard Wolf

+--------------------------+-------------------------------------+
| Ricard Wolf              | Lund Institute of Technology        |
| email: e85rw@efd.lth.se  | If you can't buy 'em - build 'em !! |
+--------------------------+-------------------------------------+

dtiberio@csserv1.ic.sunysb.edu (David Tiberio) (12/08/90)

Are you using AmigaBASIC? If so, try a compiler such as Blitz or GFA.

to open the serial port:

open "COM1:19200,n,8,1" as #1

COM1 is the serial port
19200 is the highest baud I have ever used (for my modem)
n is "no parity", your choices may differ
8 is 8 data bits (you can use 7 too
1 is 1 stop bit (you can use 0,1,2)

then INPUT#1 or PRINT#1 to exchange data.

If you want to talk more about BASIC, please contact me. I use HiSoft BASIC
for many of my programs.

fillmore@emrcan.BITNET (12/28/90)

Somebody asked a while ago how to set the serial port baud rate to MIDI speed
from an AmigaBasic program.  Here is a code fragment from a program I wrote
when I first got my Amiga:

   OPEN "com1:9600,n,8,1" as 1
   adr1 = &HDFF
   adr2 = &H32
   adr = adr2 + adr1*4096
   POKEW adr,(1000000!/(.2794*31250))

This opens the serial port as usual, but then pokes the hardware to switch to
MIDI speed.

Input can be read as follows:

   WHILE LOC(1)<>0
     b$ = INPUT$(1,1)
     { process byte b$ }
   WEND

Output can be sent by:

   PRINT #1,b$;

Keep in mind that the speed will not be very accurate from Basic because
of the slow interpreter speed, garbage collection, etc.
It works well enough to write a MIDI patch librarian, MIDI hex dump, etc.

________________________
Bob Fillmore, Systems Software & Communications     BITNET:  FILLMORE@EMRCAN
  Computer Services Centre,                         BIX:     bfillmore
  Energy, Mines, & Resources Canada                 Voice:   (613) 992-2832
  588 Booth St., Ottawa, Ontario, Canada  K1A 0E4   FAX:     (613) 996-2953