home *** CD-ROM | disk | FTP | other *** search
-
- // Quick Hack in MS C 6.0 to Access Com Port 3
- // OS/2 Device driver will not recognize it.
- // This disregards the OS and goes straight for the Port.
- // (Just Like its usually done in DOS)
- //
- // Mark Lussier
- // December 12, 1990
-
-
- #define INCL_BASE
- #define INCL_COMMON
- #define INCL_NOPM
- #define INCL_DOSPROCESS
- #include <os2.h>
- #include <malloc.h>
- #include <conio.h>
- #include <stdio.h>
- #include <string.h>
-
- #define STK_SIZE 2048
-
- #define COM1 0x03f8
- #define COM2 0x02f8
- #define COM3 0x03e8
- #define COM4 0x02e8
-
- #define BAUD_115200 1
- #define BAUD_57600 2
- #define BAUD_38400 3
- #define BAUD_19200 4
- #define BAUD_9600 6
- #define BAUD_4800 12
- #define BAUD_2400 48
- #define BAUD_1200 96
-
-
- #define PAR_NONE 0x00
- #define PAR_EVEN 0x18
- #define PAR_ODD 0x04
-
- #define DATA7 0x02
- #define DATA8 0x03
-
- #define STOP1 0x00
- #define STOP2 0x04
-
-
-
- ULONG FAR main_sem, FAR ctd_sem;
- USHORT ktcid, ctdid;
- INT ComPort = COM3;
-
-
- VOID FAR WritePort ( CHAR Value )
- {
-
- while ( ! ( inp(ComPort+5) & 0x20 ) );
- outp (ComPort, Value);
-
- }
-
- INT getuserinput( CHAR *prompt, CHAR *text, INT length)
- {
- STRINGINBUF inbuf;
- VioWrtTTY("\r\n\n",3,0);
- VioWrtTTY(prompt,strlen(prompt),0);
- inbuf.cchIn = 0;
- inbuf.cb = length;
- KbdStringIn(text,&inbuf,0,0);
- VioWrtTTY("\r",1,0);
- text[inbuf.cchIn] = '\0'; /* terminate string */
- return 0;
- }
-
- VOID FAR keytocom()
- {
- KBDKEYINFO keyinfo;
- UCHAR charcode, scancode;
- UINT written, ioctlerr;
- CHAR comerr, xname[64], YNresponse[5];
-
- while ( -1 ) /* Do forever: */
- {
- /* Get character from keyboard: */
- KbdCharIn (&keyinfo,0,0);
- charcode = keyinfo.chChar;
- scancode = keyinfo.chScan;
-
- /* Alt-X indicates End-Of-Processing: */
- if (charcode == 0x00 && scancode == 0x2D)
- {
- DosSemRequest(&ctd_sem,-1L);
- getuserinput("Exit to OS/2? ",YNresponse,4);
- DosSemClear(&ctd_sem);
- YNresponse[0] = toupper(YNresponse[0]);
- if (YNresponse[0] == 'Y')
- /* Clear Main semaphore: */
- DosSemClear(&main_sem);
- continue;
- }
- WritePort ( charcode );
- }
- }
-
- VOID FAR comtodsp ()
- {
- CHAR CharReady;
- CHAR Str[2];
- Str[1] = '\0';
- while ( -1 )
- {
- DosSemRequest(&ctd_sem,-1L);
- CharReady = inp(ComPort+5);
-
- if ( CharReady & 0x01 )
- {
- CharReady = inp(ComPort);
- Str[0] = CharReady;
- VioWrtTTY(Str,1,0);
- }
- DosSemClear(&ctd_sem);
- }
- }
- VOID SetBaud ( INT BaudRate, INT Parity, INT Data, INT Stop )
- {
- outp ( ComPort + 3, 0x80 );
- outp ( ComPort , BaudRate );
- outp ( ComPort + 1, 0 );
- outp ( ComPort + 3, Parity | Data | Stop );
- }
- VOID CheckPortAddresses ()
- {
- UCHAR Code;
- INT i;
- static INT StandardAddress[4] = {0x03f8,0x02f8,0x03e8,0x02e8};
-
- printf("\n\n Checking COM PORT 'Standard Addresses' \n\n");
-
- for (i=0; i < 4; i++)
- {
-
- Code = inp(StandardAddress[i]+2);
- Code = ( Code == 0 || Code == 2 || Code == 4 || Code == 6 || Code == 1) ? 1 : 0;
-
- if ( Code )
- printf("Com%d: UART8250 Responding At Address %04x\n",i+1,StandardAddress[i]);
- else
- printf("Com%d: UART8250 is NOT Responding At Address %04x\n",i+1,StandardAddress[i]);
- }
-
- }
-
- main ()
- {
- CHAR FAR * ctdstack, far * ktcstack;
-
- printf(" Com Reality.\n");
- printf("Use Com1-Com4 in OS/2\n");
- printf("By Mark. (c) December 1990 \n\n");
-
- CheckPortAddresses ();
-
- ctdstack = malloc(STK_SIZE);
- ktcstack = malloc(STK_SIZE);
-
- if (ctdstack == NULL || ktcstack == NULL)
- {
- puts ("Unable to allocate stacks");
- exit(2);
- }
-
- SetBaud ( BAUD_2400, PAR_NONE, DATA8, STOP1 );
-
- /* Create receive and display thread: */
- if (DosCreateThread(comtodsp,&ctdid,
- ctdstack+STK_SIZE))
- {
- puts("Can't create COM receive thread");
- exit(1);
- }
-
- /* Set semaphore to block main thread: */
- DosSemSet(&main_sem);
-
- /* Create transmit thread: */
- if (DosCreateThread(keytocom,&ktcid,ktcstack+STK_SIZE))
- {
- puts("Can't create COM transmit thread");
- exit(1);
- }
-
- DosSemWait(&main_sem,-1L);
-
- DosSuspendThread(ktcid);
- DosSuspendThread(ctdid);
-
- }
-
-
-
-
-