Category : Files from Magazines
Archive   : CUJ9209.ZIP
Filename : 1009044A

 
Output of file : 1009044A contained in archive : CUJ9209.ZIP
/*** LISTING 2 ***/
/*** ***/
/*** set.c ***/
/*** **************************************** ***/
/*** SET SERIAL PARAMETERS ***/
/*** **************************************** ***/
#include "serial.h"

int portbase;

int SetSerial (int ComPort,long Baud,int Parity,
int DataBits,int StopBits)
{
if (SetPort(ComPort))
{
return (-1);
}

if (SetBaud(Baud))
{
return (-1);
}

if (SetOthers(Parity,DataBits,StopBits))
{
return (-1);
}

return (0);
}

/*** **************************************** ***/
/*** SET THE PORT VALUE TO CORRECT COM PORT ***/
/*** **************************************** ***/

int SetPort (int ComPort)
{
switch (ComPort)
{
case COM1: portbase = COM1BASE;
break;

case COM2: portbase = COM2BASE;
break;

case COM3: portbase = COM3BASE;
break;

case COM4: portbase = COM4BASE;
break;

default: return (-1);
}
return (0);
}

/*** **************************************** ***/
/*** SET THE BAUD RATE - DLAB MUST BE SET ON.***/
/*** **************************************** ***/
int SetBaud (long Baud)
{
char Current_Value;
int divisor;

if ((Baud <= 0) || (Baud > 115200L))
{
return (-1);
}

else
{
divisor = (int)(115200L/Baud);
}

/*** READ CURRENT VALUES IN LINE CONTROL REG ***/

Current_Value = inp(portbase + LCR);

/*** OR CURRENT VALUE WITH 0x80 TO SET DLAB ***/

outp(portbase + LCR,(Current_Value | DLAB));

/*** OUTPUT BAUD DIVISOR TO LOW BYTE ***/

outp(portbase + DLL,(divisor & 0x00FF));

/*** OUTPUT BAUD DIVISOR TO HIGH BYTE ***/

outp(portbase + DLH,((divisor >> 8) & 0x00FF));

/*** TURN DLAB OFF BY SENDING CURRENT VALUE ***/

outp(portbase + LCR,Current_Value);

return (0);
}

/*** **************************************** ***/
/*** SET PARITY, DATA BITS, AND STOPBITS ***/
/*** **************************************** ***/
int SetOthers (int Parity,int DataBits,int StopBits)
{
int setting;

if ((DataBits < 5) || (DataBits > 8))
{
return (-1);
}

if ((StopBits != 1 && StopBits != 2))
{
return (-1);
}

if ((Parity != NO_PARITY) && (Parity != ODD_PARITY)
&& (Parity != EVEN_PARITY))
{
return (-1);
}

setting = DataBits - 5;
setting |= ((StopBits == 1) ? 0x00 : 0x04);
setting |= Parity;

outp(portbase + LCR,setting);

return (0);
}



  3 Responses to “Category : Files from Magazines
Archive   : CUJ9209.ZIP
Filename : 1009044A

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/