Question about modems

Jim Brain brain at jbrain.com
Thu Nov 14 20:48:09 CST 2019


Well, I am off and running on getting my version of the code up to speed:

https://github.com/go4retro/tcpser

Man, some of this code is rough.  I have learned a lot about writing C 
code in the last decade+.

Anyway, while I work on adding the appropriate functionality into the 
codebase, I find myself ruminating on why there were so many parity 
options in serial communications.

I understand the need for parity per se, given link quality and such.  
But, why the need for Odd, Even, Mark, Space.  Is there some reason why 
different parity options work better in certain situations?

Also, for those wanting to help with some code:

int detect_parity(modem_config *cfg)
{
   int parity, eobits;
   int charA, charT, charCR;


   charA = cfg->pchars[0];
   charT = cfg->pchars[1];
   charCR = cfg->pchars[2];

   parity = (charA & 0x80) >> 7;
   parity |= (charT & 0x80) >> 6;
   parity |= (charCR & 0x80) >> 5;

   eobits = gen_parity(charA & 0x7f);
   eobits |= gen_parity(charT & 0x7f) << 1;
   eobits |= gen_parity(charCR & 0x7f) << 2;

   if (parity == eobits)
     return 2;

   if (parity && (parity ^ eobits) == (parity | eobits))
     return 1;

   return parity & 0x3;
}

#define gen_parity(v) (((((v) * 0x0101010101010101ULL) & 
0x8040201008040201ULL) % 0x1FF) & 1)

Fozztexx (Chris Osborn) authored this little slice of code, and it uses 
the AT<cr> to determine parity of the form:

space == 0
odd == 1
even == 2
mark == 3

I'm trying to sort the code out in my head, which will happen, but takes time.  The issue I see with it is the use of the CR as the third char to check.

Hayes S registers always allows the redefinition of the CR character, via S3.  As such, there's no guarantee line termination = CR, (yes, it's valid for the first AT command, but not after, so if the user does a 8N1 ATS3=15<cr> and then switches to 7E1, the emulator will not handle well.  I agree the likelihood is almost nil someone does this, but tcpser is supposed to be very pedantic on such matters.

Thus, anyone have a way to discern parity using only the 'A' and 'T' ?  I guess I might be able to still use the terminator, since I know what it is ahead of time, but not sure if the above code works on the principle that the 3 ASCII values have unique traits that would not hold true for other values.

Jim




More information about the cctalk mailing list