Page 1 of 1

Closing an RS-232 channel

Posted: Mon Jun 30, 2014 12:59 pm
by srowe
I've recently been rediscovering the various subtle ways of RS-232 connections (like using >=128 for the LFN to get CRLF at the end of a line). One thing I'm still struggling with is checking the transmit queue is empty before closing the channel. The Programmer's Reference Guide says
Care should be taken to ensure all data is transmitted before closing the channel. A way to check this from BASIC is:

100 IF ST=0 AND (PEEK(37151) AND 64)=1 GOTO 100
110 CLOSE lf
I tried this but 37151 never seemed to have the 64 bit set, so the close happened prematurely.

Is there a recommended way to check for an empty transmit queue?

Re: Closing an RS-232 channel

Posted: Mon Jun 30, 2014 2:34 pm
by Mike
Hmm ...

at first it looks like an obvious typo in the PRM. If one masks out 64 from an integer value, the result can only be 0 or 64, therefore this comparison always fails. OTOH, in register 37151, neither bit 0 (value: 1) nor bit 6 (value: 64) are related to RS232. :?

...

Ah! We had this discussed some time ago here: 'Userport Serial programming nonsense'.

...

I dug a bit in the KERNAL. There are two byte pointers into the RS232 transmit buffer, $029D ("one after byte just sent") and $029E ("next free place"). When these two are equal, the KERNAL disables the NMI timer for output instead of transferring the next byte into the byte output buffer. Thus you might try:

Code: Select all

100 IFPEEK(669)<>PEEK(670)THEN100
to check for an empty transmit buffer.

Greetings,

Michael

Re: Closing an RS-232 channel

Posted: Mon Jun 30, 2014 2:59 pm
by srowe
Ah, thanks. That's the sort of test I expected. I'll update my ROM dump program to use this.