Thursday, July 17, 2014

Serial Flow Control RTS in QBasic

Flow control is pretty important everywhere in life, and serial communications are no exception.




"Speed it up a little!"


Since my jx-80 simulator in Qbasic is slow and so is my old-school win98 laptop, it can't keep up with 9600 bps data. So I had to struggle to find a way to do it. I got a clue from the online help that had a little example of setting DTR with the INP function.

PRINT "set dtr"
x% = INP(&H3FC)
OUT &H3FC, (x% OR 1)

Well I tried this and it didn't work quite right, seeming to drop characters and get confused.

So I searched some more and came across a really nice book called "Interfacing the IBM-PC to Medical Equipment: The Art of Serial Communication" on Google Books.



On page 73 it has a nice diagram of the Modem Control Register and shows bit 0 is DTR and bit 1 is RTS. So I set and cleared the RTS and it worked great! My logic is to clear RTS when the buffer gets above 5000 bytes and set RTS when the buffer drops below 4000 bytes.

PRINT "set rts"
x% = INP(&H3FC)
OUT &H3FC, (x% OR 2)

PRINT "clear rts"
x% = INP(&H3FC)
OUT &H3FC, (x% AND (255-2))


Without the flow control, the buffer happily goes up to 65535 and overflows. Before this, I put some code in to watch the buffer when it hits 55000 and to stop drawing to the screen to speed it back up. But I think proper flow control is much better.

I think it really would not have been difficult to add commands to handle setting and clearing the RTS and DTR bits in QBASIC.



here you can see the clearing of RTS when we cross 5000 bytes and also the setting of RTS when we drop below 4000 bytes.



The picture finishes normally! The buffer display on the bottom line reads zero.

I see that on ebay they want an arm and a leg for the book. It's a good book, I'm not sure I'd pay $100-200 for it.





Anyway the latest version of my QBasic epson simulator (Epson91.BAS)



No comments:

Post a Comment