• Please review our updated Terms and Rules here

RS232 in BASIC-80 / MBASIC or Turbo Pascal

spiceminer

Experienced Member
Joined
Mar 8, 2014
Messages
198
Location
Europe
Hi everybody!

I am looking for a method to access the RS232 port in MBASIC or Turbo Pascal 2.0 or 3.0 running in CP/M 2.2.

The system is a Royal / Alphatronic PC-8.

Unfortunately, at least in Basic, it seams like there is no possibility to access the RS232 via the OPEN Command (which works only with files on Disk, not Devices).

Access in CP/M using PIP works fine (Here UP1: and UR1: devices)

Best regards
Stephan
 
I'm pretty sure there is a way to make BDOS calls from MBASIC, but it's been so long that I don't recall and don't have any old code. OPEN won't work, as CP/M only accepts files (FCBs), and not device identifiers, for those calls. If I could find a manual for MBASIC I might be able to scan for the feature that makes it possible. Another way is to use INPUT/OUTPUT (?) statements to access the UART directly.
 
Found an MBASIC manual on bitsavers. There are two methods to call outside of BASIC. The USR function is probably a bit too complicated, but the CALL statement looks like it will do what you want. It looks like it should be possible to call directly to 0005H with BC, DE, HL registers set as desired. It's probably going to take some careful studying of the appendix to make it work.
 
Decided to read a little more. Looks like you cannot directly CALL to 0005H, because the arguments are passed by pointer and BDOS expects values. You'll still have to design a stub assembly routine to manipulate the arguments into values in BC and DE, and then POKE that routine into free memory and CALL to that memory. Also, CALL does not return a value - although you might be able to modify the value a variable that was passed in to the CALL statement. CALL and USR sounded quite handy, on paper, but I think they became rather messy in real life.

As I recall, once we got a C compiler we pretty much abandoned BASIC.
 
I need to dig into this a little myself...I've been meaning for a few years now to try using BASIC to bootstrap an XMODEM utility onto my Vector-4 so's I can get some proper software on there...
 
Recently I had been experimenting with PT's extended cassette Basic and MBasic (Microsoft Basic) running in CP/M 2.2 on my SOL-20. Both these Basics appear to have very similar features.

I found it easy to write data to and read the parallel port using OUT and INP in MBASIC. So it should work on the serial port too, but I have not actually tried that yet...

The CALL function is supposed to invoke a machine language routine at a specified address and a RET will bring it back to Basic. Apparently the routine can place a value in H & L. There is also the WAIT statement which waits until a specified value is in the port.

There is a fair amount of detail on OUT, INP, WAIT, CALL etc on pages 6-2 to 6-4 of PT's extended cassette Basic manual. I have been using MBASIC though because its easier to save & load files on disk in CP/M and not be dependent on cassettes.
 
I just had a go at writing to the serial port and receiving data from it from inside MBASIC on my SOL. It might have some use if things are similar on your computer.

I linked the SOL to a modern computer running Teraterm and established communication at 1200 Baud.

Simply by writing to the port (address 249 in this computer) using OUT 249,99 the ACSII value was transmitted received by Teraterm as "c" which is 63h. Also typing a letter in Teraterm, like a C, and using Y = INP(249) and Print Y gave 99 (= 63 hex for c). So two way communication works.

In addition using OUT 248,8 and OUT 248,16 toggles the RTS output from the Sol off and on. Obviously in some data backwards and forwards handling program this would also have to be used along with the CTS input on the SOL and the RTS & CTS on the modem or "other computer/device". Apparently the DSR input is not used on the SOL and it transmits if ready or not.

It was not ncessary to reconfigure any register in the SOL's UART IC, it just worked as it was.
 
The Royal AlphaTronic comes equipped with an 8251 USART. It's easily programmed via Turbo Pascal or via assembler. In MBASIC, you can use the OUT and INP() commands to write and read to the ports on the 8251.

Information on programming the serial port on the AlphaTronic can be found here: https://gopherproxy.meulie.net/goph...ive/walnut-creek-cd-simtel/CPM/IMP/I2RY-1.ASM - you'll need to sift through it to pick out the bits you need and I suspect a datasheet on the 8251 will help with programming info.

g.
 
There are a few tricks to the initializing the 8251. Hopefully the bios initialized it when it was reset. The problem is that some of the information is expected to be sequenced in. If it thinks it is part way in a sequence when it powers up, you need to complete the sequence to get it back into the command state.
Unless you are doing hardware flow control, you only need to worry about two ports. They would be the data port and the status port. You need to check what is in the status port to know when to read incoming data and when the data you wrote got transmitted.
Dwight
 
Back
Top