⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ulib14.c

📁 大量的汇编程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------------*/
/*       u l i b 1 4 . c                                              */
/*                                                                    */
/*       Serial port communications driver for ARTICOMM INT14         */
/*       driver                                                       */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*    Copyright (c) Richard H. Lamb 1985-1987                         */
/*                                                                    */
/*    Changes Copyright 1992 by Mark W. Schumann                      */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
/*    Wonderworks.                                                    */
/*                                                                    */
/*    All rights reserved except those explicitly granted by the      */
/*    UUPC/extended license agreement.                                */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*       This suite needs some tuning, but the Wonderworks lacks      */
/*       the time and more importantly the software to do so.         */
/*       Specific problems:                                           */
/*                                                                    */
/*          The INT14 interface is not checked to be ARTICOMM, and    */
/*          thus the extensions to the generic INT14 functions may    */
/*          fail with no warning to the user.                         */
/*                                                                    */
/*          Non-ARTICOMM programs are not supported.                  */
/*                                                                    */
/*          No error is returned if a write times out                 */
/*                                                                    */
/*          Input data is discarded if a read times out, which        */
/*          will confuse the 'g' packet input processor.              */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*                          RCS Information                           */
/*--------------------------------------------------------------------*/

/*
 *    $Id: ulib14.c 1.3 1993/10/03 22:09:09 ahd Exp $
 *
 *    $Log: ulib14.c $
 * Revision 1.3  1993/10/03  22:09:09  ahd
 * Use unsigned long to display speed
 *
 * Revision 1.2  1993/05/30  15:25:50  ahd
 * Multiple driver support
 *
 *
 *   30 Nov 92 - Adapt for use with INT14 drivers.
 *               Currently this is guaranteed to work only with
 *               Artisoft's ARTICOMM driver, but porting to others
 *               should be minor.  Mods by Mark W. Schumann
 *               <mark@whizbang.wariat.org>
 */

/*--------------------------------------------------------------------*/
/*                        System include files                        */
/*--------------------------------------------------------------------*/

#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include <dos.h>    /* Declares union REGS and int86(). */

/*--------------------------------------------------------------------*/
/*                    UUPC/extended include files                     */
/*--------------------------------------------------------------------*/

#include "lib.h"
#include "hlib.h"
#include "ulib.h"
#include "comm.h"          // Modem status bits
#include "ssleep.h"
#include "catcher.h"

#include "fossil.h"        // Various INT14 definitions
#include "commlib.h"       // Trace functions, etc.

/*--------------------------------------------------------------------*/
/*                        Internal prototypes                         */
/*--------------------------------------------------------------------*/

static void modemControl( char mask, boolean on);
static void ShowModem( void );
static unsigned char bps_table(int);

/*--------------------------------------------------------------------*/
/*                          Global variables                          */
/*--------------------------------------------------------------------*/

static BPS currentBPS;
static char currentDirect;
static boolean carrierDetect;

currentfile();
static boolean hangupNeeded = TRUE;


/*--------------------------------------------------------------------*/
/*    b p s _ t a b l e                                               */
/*                                                                    */
/*    Look up the INT14 baud rate value corresponding to (bps).       */
/*--------------------------------------------------------------------*/

static unsigned char bps_table (int bps)
{

   static int tab[] = {110, 150, 300, 600, 1200, 2400, 4800, 9600, -1};
   unsigned char i;

   for (i = 0; tab[i] > 0; i++)
   {
      if (tab[i] == bps)
         return i;
   }

   return 255;

} /* bps_table */

/*--------------------------------------------------------------------*/
/*    i o p e n l i n e                                               */
/*                                                                    */
/*    Open the serial port for I/O                                    */
/*--------------------------------------------------------------------*/

int iopenline(char *name, BPS bps, const boolean direct)
{

   if (portActive)              /* Was the port already active?      */
      closeline();               /* Yes --> Shutdown it before open  */

   printmsg(15, "openline: %s, %lu", name, bps);

   currentDirect = (char) (direct ? 'D' : 'M');

   if (sscanf(name, "COM%d", &portNum) != 1)
   {
      printmsg(0,"Communications port must be format COMx, was %s",
                name);
      panic();
   }

   norecovery = FALSE;     // Flag we need a graceful shutdown after
                           // Cntl-BREAK

/*--------------------------------------------------------------------*/
/*       With the INT14 setup, we don't worry about the lock file     */
/*       since our modem sharing software is supposed to deal with    */
/*       resource contention.                                         */
/*--------------------------------------------------------------------*/

   portNum--;              /* Change ordinal number to offset       */
   SIOSpeed( bps );        /* Open the port and set the speed       */
   flowcontrol( FALSE );   /* Enable hardware flow control          */

   ssleep(2);              /* Wait two seconds as required by V.24  */
   carrierDetect = FALSE;  /* No modem connected yet                */

   traceStart( name );

   portActive = TRUE;     /* record status for error handler */

   return 0;               // Return success to caller

} /* iopenline */


/*--------------------------------------------------------------------*/
/*    i s r e a d                                                     */
/*                                                                    */
/*    Read from the serial port                                       */
/*                                                                    */
/*    Non-blocking read essential to "g" protocol.  See               */
/*    "dcpgpkt.c" for description.  This all changes in a             */
/*    multi-tasking system.  Requests for I/O should get queued       */
/*    and an event flag given.  Then the requesting process (e.g.     */
/*    gmachine()) waits for the event flag to fire processing         */
/*    either a read or a write.  Could be implemented on VAX/VMS      */
/*    or DG but not MS-DOS.                                           */
/*--------------------------------------------------------------------*/

unsigned int isread(char *buffer, unsigned int wanted, unsigned int timeout)
{

   union REGS regs;          /* Scratch area for interrupt calls. */

   /* With INT14, don't bother with a counter; just set a timeout    */
   /*  value with INT14/AX=8009.  This is Artisoft-specific.         */

   int count = 0;

   ShowModem();                  // Report modem status

/*--------------------------------------------------------------------*/
/*             Now actually try to read a buffer of data              */
/*--------------------------------------------------------------------*/

   regs.x.ax = 0x8009;            /* Set timeouts */
   regs.x.bx = timeout * 91 / 5;  /* Send timeout in ticks */
   regs.x.cx = timeout * 91 / 5;  /* Receive timeout in ticks */
   regs.x.dx = portNum;           /* Port number */
   int86 (FS_INTERRUPT, &regs, &regs);

   for ( count = 0; count < (int) wanted; count++ )
   {
      unsigned short result = FossilCntl( FS_RECV1, 0);

      if (result & 0x8000)          // Did read time out?
      {
         printmsg (20, "Timeout in sread().");
         traceData( buffer, count + 1, FALSE );
         return count;
      }

      buffer[count] = (char) (result & 0x00ff);
   }

   traceData( buffer, count + 1, FALSE );
   return count + 1;

} /* isread */

/*--------------------------------------------------------------------*/
/*    i s w r i t e                                                   */
/*                                                                    */
/*    Write to the serial port                                        */
/*--------------------------------------------------------------------*/

int iswrite(char *data, unsigned int len)
{
   unsigned int i;

   ShowModem();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -