delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/03/18/23:30:05

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: any help with com port routines, please?
Date: 19 Mar 2002 04:20:37 GMT
Organization: Cornell University
Lines: 318
Sender: asu1 AT cornell DOT invalid (on pool-141-149-209-94.syr.east.verizon.net)
Message-ID: <Xns91D5ED750A415asu1cornelledu@132.236.56.8>
References: <embb9ugb5e4hvkg7puugclhucgi69to7ca AT 4ax DOT com>
NNTP-Posting-Host: pool-141-149-209-94.syr.east.verizon.net
X-Trace: news01.cit.cornell.edu 1016511637 8090 141.149.209.94 (19 Mar 2002 04:20:37 GMT)
X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu
NNTP-Posting-Date: 19 Mar 2002 04:20:37 GMT
User-Agent: Xnews/L5
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Dr Green <drgreen27_no AT spam_hotmail DOT com> wrote in 
news:embb9ugb5e4hvkg7puugclhucgi69to7ca AT 4ax DOT com:

> Hello all.   I've also posted this to the msdos.programmer newsgroup,
> with no response.  I was just hoping someone here might recognize some
> of this code and be able to help me out.  Thanx!

I really do not know much about these matters but I'll make a few comments. 
Maybe they'll help.

<snip>

> /*********************Update Scoreboard*****************************/
> void UpdateScoreBoard(void)
>    {
>     unsigned val, ads;

if this was compiled using a 16-bit compiler, these are meant to be 16-bit 
values. with djgpp, change the declaration to unsigned short. 

> 
>      /* each digit is it's own item */
> 
>         val = ( ClockMin / 10 ) % 10;
> 
>      /* i'm assuming this is some address in the memory on the
> scoreboard chip, but who knows... */
> 
>         ads = 0 + 0xC100;
> 
>         if(val==0)
>              val=15;
> 
>         dbpoke(ads,1,val);
>         val = ClockMin % 10;
>         ads = 1 + 0xC100;
> 
>         if(val==0)
>              val=15;
> 
>         dbpoke(ads,1,val);
> 
> /* etc... */
> }
> 
> 
> /*
>      write "count" words from "buffer" to address "address" in the
>      remote data base over the rs232 bus.  returns "0" if no error
>      else "1".  does a read after write verify.
> */
> 
> int dbpoke(unsigned address, unsigned count, unsigned buffer[])
>    {
>    unsigned tbuff[64];
>    int i, j;
> 
> 
>      flush(port);
> 
>    for(j=0; j<1; ++j)
>        {
>        for(i=0; i<count; ++i)
>            sendblk(0x00, HB(address + 2*i), LB(address + 2*i),
> buffer[i]);
>        }
> 
>    return(1);
>    }

this function looks a little wild to me. first, i do not understand the 
need for the outer loop. second, it always returns 1 which, according to 
the comment, signifies an error value. i am stumped.

> 
> /*********rs232drv.c********/
> 
> #define  DBASE          0x06          /* =60,000 */
> #define  IBLKDLY       -4          /* hunderdths secs   */
> 
> 
> void sendblk(int db1, int db2, int db3, int db4)
>    {
>    if (db1 == 0xff)
>        {
>           flush(port);
>              rs232_out(port, 0xf0);
>              rs232_out(port, DBASE);
>           rs232_out(port, db2);
>           rs232_out(port, db3);
>              rs232_out(port, db4);
>         rs232_out(port, 0xf0^DBASE^db2^db3^db4);
>        }

I am assuming the XORing provides a checksum value to the board. the value 
of db1 selects functionality. i just don't know what that functionality is 
:)

also, port is a global variable. presumably, it being set according to some 
command line option. see below ...

> 
>      if (db1 == 0x00)
>        {
>              rs232_out(port, 0x0f);
>         rs232_out(port, DBASE);
>           rs232_out(port, db2);
>           rs232_out(port, db3);
>             rs232_out(port, 1);
>           rs232_out(port, HB(db4));
>           rs232_out(port, LB(db4));
>             rs232_out(port, 0x0f^DBASE^db2^db3^1^HB(db4)^LB(db4));
>        }
> 
> /*   Delay(IBLKDLY);*/
>    }
> 
> /*
>      RS232 write
> */
> 
> int rs232_out(int port, char data)

you want to change this to unsigned short for the port again because of the 
16-bit versus 32-bit difference. assuming the macros or constants such as 
COM1, LSR1 etc ... are defined properly elsewhere, this function should 
compile with djgpp.

>   {
>      int rx;
> 
> /*
>      wait for tbe
>      clear DLAB for THR access
>      tramsmit data
> */
> 
>      if (port == COM1)
>        {
>           while (((rx = inportb(LSR1)) & 0x20) == 0)
>                ;
>           outportb(LCR1, inportb(LCR1) & 0x7f);
>           outportb(THR1, data);
>        }
> 
> 
>      if (port == COM2)
>        {
>           while (((rx = inportb(LSR2)) & 0x20) == 0)
>                ;
>           outportb(LCR2, inportb(LCR2) & 0x7f);
>           outportb(THR2, data);
>        }
> 
>      return(rx<<8 | data);
>   }

i know i didn't say much that is useful. here is my best attempt at getting 
something that at least compiles with djgpp.

#include <pc.h>
#include <time.h>

/* not sure if these are correct */

#define COM1 0x03f8
#define COM2 0x02e8

/* i have no idea what these values are supposed to be. presumably there
 * is a header file containing this information
 */
#define LSR1 0
#define LCR1 0
#define THR1 0
#define LSR2 0
#define LCR2 0
#define THR2 0

/* I am assuming HB means high byte, and LB means low byte */
unsigned char HB(unsigned short x)
{
	return (x & 0xff00) >> 8;
}

unsigned char LB(unsigned short x)
{
	return (unsigned char) (x & 0x00ff);
}

unsigned short port = COM1;

/* I assume ClockMin means clock ticks per minute */
unsigned ClockMin = 60*CLOCKS_PER_SEC;

int dbpoke(unsigned short address, 
		unsigned short count, 
		unsigned short buffer[]);
void sendblk(unsigned short db1, 
		unsigned short db2, 
		unsigned short db3, 
		unsigned short db4);
int rs232_out(unsigned short port, unsigned char data);

void UpdateScoreBoard(void)
{
	unsigned short val, ads;
	
	val = ( ClockMin / 10 ) % 10;
	ads = 0 + 0xC100;
	if(val==0)
		val=15;
	dbpoke(ads,1,&val);
	
	val = ClockMin % 10;
	ads = 1 + 0xC100;
	if(val==0)
		val=15;
	dbpoke(ads,1,&val);
	/* etc... */
	return;
}

/*
	write "count" words from "buffer" to address "address" in the
	remote data base over the rs232 bus.  returns "0" if no error
	else "1".  does a read after write verify.
*/

int dbpoke(unsigned short address, 
		unsigned short count, 
		unsigned short *buffer)
{
	unsigned short tbuff[64]; /* what's this for? */
	int i, j;
	
	/* is this necessary? flush(port);*/
	
	for(j=0; j<1; ++j)
	{
		for(i=0; i<count; ++i)
			sendblk(0x00, HB(address + 2*i), LB(address + 2*i), buffer
[i]);
	}
	return(1);
}

/*********rs232drv.c********/

#define  DBASE		0x06		/* =60,000 */
#define  IBLKDLY	  -4		/* hunderdths secs   */

void sendblk(unsigned short db1,
		unsigned short db2,
		unsigned short db3,
		unsigned short db4)
{
	if (db1 == 0xff)
	{
		/* flush(port);*/
		rs232_out(port, 0xf0);
	   	rs232_out(port, DBASE);
		rs232_out(port, db2);
		rs232_out(port, db3);
	   	rs232_out(port, db4);
		rs232_out(port, 0xf0^DBASE^db2^db3^db4);
	}

	if (db1 == 0x00)
	{
		rs232_out(port, 0x0f);
		rs232_out(port, DBASE);
		rs232_out(port, db2);
		rs232_out(port, db3);
  		rs232_out(port, 1);
		rs232_out(port, HB(db4));
		rs232_out(port, LB(db4));
  		rs232_out(port, 0x0f^DBASE^db2^db3^1^HB(db4)^LB(db4));
	}
	/*   Delay(IBLKDLY);*/
	/* it would be a good idea to try to figure out how long this delay 
is
	 * supposed to. according to the comment above, IBLKDLY comes to over
	 * 10 minutes which I find a little too long, but who knows.
	 * you can use djgpp's delay here, but note that it is miliseconds.
	 */
}

/* RS232 write */

int rs232_out(unsigned short port, unsigned char data)
{
	int rx;

/*
	wait for tbe
	clear DLAB for THR access
	tramsmit data
*/

	if (port == COM1)
	  {
		while (((rx = inportb(LSR1)) & 0x20) == 0)
			;
		outportb(LCR1, inportb(LCR1) & 0x7f);
		outportb(THR1, data);
	  }


	if (port == COM2)
	  {
		while (((rx = inportb(LSR2)) & 0x20) == 0)
			;
		outportb(LCR2, inportb(LCR2) & 0x7f);
		outportb(THR2, data);
	  }

	return(rx<<8 | data);
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019