Linux MS DOS discussions
 help / color / mirror / Atom feed
From: Mark Rejhon <marky@marky.com>
To: Randy Thelen <rthelen@madscientistroom.org>
Cc: marky@magmacom.com, ag115@freenet.carleton.ca,
	linux-msdos@vger.kernel.org
Subject: Re: I have a patch for dosemu-1.0.2.1 to enhance rs232 "break" support
Date: Fri, 23 Aug 2002 12:04:31 -0400	[thread overview]
Message-ID: <3D665D0F.ECAD81E5@marky.com> (raw)
In-Reply-To: 20020823021342.K43474@tesla.madscientistroom.org

Hi!

Thanks, but I stopped working on DOSEMU years ago -- so I'm going to 
forward this to the Linux-MSDOS mailing list:
linux-msdos@vger.kernel.org

Glad you're enjoying the software!


Randy Thelen wrote:
> 
> Hi Mark!
> 
> My name is Randy Thelen and I've hacked on src/base/serial/ser_ports.c
> for dosemu-1.0.2.1.  I've added support for programs that create break
> sequences on the COM ports.
> 
> In my particular case, I've been trying to run Parallax's stamp2
> program (see http://www.parallaxinc.com/ ) for the Basic Stamp2.
> The stamp2 programmer sends breaks across the rs232 line to get
> the attention of the Basic Stamp.  I trouble shot the problem to
> a few simple changes, and I include those here for you to review
> and possibly apply to other changes being considered for a rev
> of dosemu.
> 
> DosEmu is a great program and I've used it for about a year and half.
> I love it!  This is the best way I know to express my gratitude!
> 
> -- Randy Thelen


diff -urN dosemu-1.0.2.1/src/base/serial/ser_ports.c
dosemu-1.0.2.2/src/base/serial/ser_ports.c
--- dosemu-1.0.2.1/src/base/serial/ser_ports.c  2001-03-11 05:27:25.000000000
-0800
+++ dosemu-1.0.2.2/src/base/serial/ser_ports.c  2002-08-23 09:34:22.000000000
-0700
@@ -33,6 +33,7 @@
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <ctype.h>
 
 #include "config.h"
 #include "emu.h"
@@ -534,6 +535,34 @@
 }
 
 
+/*
+ * This function updates the msr and mcr with respect to the hardware.
+ * It is necessary because the hardware can change state out from under
+ * neath us, and some DOS code will sit and spin looking at registers
+ * that are alterable from a remote host.
+ */
+static void
+get_update(int num)
+{
+  int control;
+
+  ioctl(com[num].fd, TIOCMGET, &control);
+
+  if (control & TIOCM_RTS) com[num].MCR |=  UART_MCR_RTS;
+  else                     com[num].MCR &= ~UART_MCR_RTS;
+  if (control & TIOCM_DTR) com[num].MCR |=  UART_MCR_DTR;
+  else                     com[num].MCR &= ~UART_MCR_DTR;
+  if (control & TIOCM_CAR) com[num].MSR |=  UART_MSR_DCD;
+  else                     com[num].MSR &= ~UART_MSR_DCD;
+  if (control & TIOCM_RNG) com[num].MSR |=  UART_MSR_RI;
+  else                     com[num].MSR &= ~UART_MSR_RI;
+  if (control & TIOCM_DSR) com[num].MSR |=  UART_MSR_DSR;
+  else                     com[num].MSR &= ~UART_MSR_DSR;
+  if (control & TIOCM_CTS) com[num].MSR |=  UART_MSR_CTS;
+  else                     com[num].MSR &= ~UART_MSR_CTS;
+}
+
+
 /* This function returns the value in the MSR (Modem Status Register)
  * and does the expected UART operation whenever the MSR is read.
  * [num = port]
@@ -543,6 +572,8 @@
 {
   int val;
 
+  get_update(num);
+
   val = com[num].MSR;                          /* Save old MSR value */
   com[num].MSR &= UART_MSR_STAT;               /* Clear delta bits */
   com[num].int_condition &= ~MS_INTR;          /* MSI condition satisfied */
@@ -568,6 +599,8 @@
 {
   static int val;
 
+  if ((com[num].LSR & 1) == 0) sleep(1);
+
   val = com[num].LSR;                  /* Save old LSR value */
   com[num].int_condition &= ~LS_INTR;  /* RLSI int condition satisfied */
   com[num].LSR &= ~UART_LSR_ERR;       /* Clear error bits */
@@ -764,6 +797,10 @@
 static void
 put_lcr(int num, int val)
 {
+  int changed;
+  int control;
+  changed = com[num].LCR ^ val;                /* Bitmask of changed bits */
+
   com[num].LCR = val;                  /* Set new LCR value */
   if (val & UART_LCR_DLAB) {           /* Is Baudrate Divisor Latch set? */
     s_printf("SER%d: LCR = 0x%x, DLAB high.\n", num, val);
@@ -779,6 +816,16 @@
     com[num].DLAB = 0;                 /* Baudrate Divisor Latch flag */
     ser_termios(num);                  /* Sets new line settings */
   }
+
+  /* Set or Clear Break on serial device only if Break state changed */
+  if (changed & UART_LCR_SBC) {
+    if(s1_printf) s_printf("SER%d: LCR: SBC -> %d\n",num,(val &
UART_LCR_SBC));
+    control = 0;  /* UNUSED for TIOCSBRK and TIOCCBRK */
+    if (val & UART_LCR_SBC)
+      ioctl(com[num].fd, TIOCSBRK, &control);
+    else
+      ioctl(com[num].fd, TIOCCBRK, &control);
+  }
 }
 
 
@@ -831,7 +878,7 @@
     com[num].int_enab = (val & UART_MCR_OUT2);
 
     /* Force RTS & DTR reinitialization if the loopback state has changed */
-    if (UART_MCR_LOOP) changed |= UART_MCR_RTS | UART_MCR_DTR;
+    if (changed & UART_MCR_LOOP) changed |= UART_MCR_RTS | UART_MCR_DTR;
 
     /* Update DTR setting on serial device only if DTR state changed */
     if (changed & UART_MCR_DTR) {
@@ -977,6 +1024,7 @@
     break;
 
   case UART_MCR:       /* Read from Modem Control Register */
+    get_update(num);
     val = com[num].MCR;
     if(s2_printf) s_printf("SER%d: Read MCR = 0x%x\n",num,val);
     break;

       reply	other threads:[~2002-08-23 16:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20020823021342.K43474@tesla.madscientistroom.org>
2002-08-23 16:04 ` Mark Rejhon [this message]
2002-08-23 21:58 I have a patch for dosemu-1.0.2.1 to enhance rs232 "break" support Stas Sergeev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3D665D0F.ECAD81E5@marky.com \
    --to=marky@marky.com \
    --cc=ag115@freenet.carleton.ca \
    --cc=linux-msdos@vger.kernel.org \
    --cc=marky@magmacom.com \
    --cc=rthelen@madscientistroom.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox