[comp.sources.games.bugs] here are pm patches for SysV

eric@snark.uu.net (Eric S. Raymond) (08/10/89)

(I am posting this because neither address I have for pm's developer seem to be
any good. Breaker for Peter Constantinidis Jr. -- got yer ears on?)

Here is a collection of diffs that gets pm version 2 more or less working on
AT&T UNIX version at or later than SVr3.2. The crucial 3.2 addition is the new
FIORDCHK ioctl(), which is equivalent to BSD's FIONREAD. These diffs preserve
all the BSD code, which is enabled by setting OS_VERS to BSD??? and
uncommenting the flsbuf.[co] instances in OBJS and SRCS[12].

I say `more or less' working because without a millisecond timer there's no
way to do slow(), so it has to be a no-op. The monsters thus start off as
mean as they will get, and the game has a ragged feel.

There is also a bug somewhere in the move-processing code. If I try to
start the pac-man moving in any direction but the right, he freezes and
no movement commands are ever accepted. I don't think this was due to my
mods, are there any pm experts who can tell me whether this is a known bug?

*** Makefile-orig	Wed Aug  9 00:38:22 1989
--- Makefile	Wed Aug  9 01:05:27 1989
***************
*** 21,33 ****
  #	sources broken into two parts for easy 2 part source distributions
  #
  HDRS	=	pm.h
! OBJS	=	config.o flsbuf.o init.o make_moves.o\
! 		misc.o monsters.o msg.o pm.o random.o\
! 		rip.o score.o screen.o timing.o warning.o
! SRCS1	=	config.c flsbuf.c init.c make_moves.c\
! 		misc.c monsters.c msg.c
  SRCS2	=	pm.c random.c rip.c score.c screen.c timing.c warning.c
! SRCS	=	$(SRCS1) $(SRCS2)
  #
  # Configuration section
  #
--- 21,31 ----
  #	sources broken into two parts for easy 2 part source distributions
  #
  HDRS	=	pm.h
! OBJS	=	config.o init.o make_moves.o misc.o monsters.o msg.o \
! 		pm.o random.o rip.o score.o screen.o timing.o warning.o
! SRCS1	=	config.c init.c make_moves.c misc.c monsters.c msg.c
  SRCS2	=	pm.c random.c rip.c score.c screen.c timing.c warning.c
! SRCS	=	$(SRCS1) $(SRCS2) # flsbuf.c
  #
  # Configuration section
  #
***************
*** 63,73 ****
  
  install:	pm pm_roll pm_user clean
  
! $(PMLIB):	$(OBJS)
  		ar rv $@ $?
! 		ranlib $@
  clean:
! 		rm -f $(OBJS) pm.a
  
  pm:		tester
  		-mv pm pm.old; mv tester pm
--- 61,71 ----
  
  install:	pm pm_roll pm_user clean
  
! $(PMLIB):	$(OBJS) # flsbuf.o
  		ar rv $@ $?
! 		-ranlib $@
  clean:
! 		rm -f $(OBJS) pm.a # flsbuf.o
  
  pm:		tester
  		-mv pm pm.old; mv tester pm
***************
*** 76,82 ****
  
  $(OBJS):	$(HDRS)
  
! tags:		$(HDRS) $(SRCS)
  		ctags -u $?
  		sort tags -o tags
  
--- 74,80 ----
  
  $(OBJS):	$(HDRS)
  
! tags:		$(HDRS) $(SRCS) flsbuf.c
  		ctags -u $?
  		sort tags -o tags
  
***************
*** 86,104 ****
  pm_user:
  		> $(PM_USER)
  
! Print:		$(HDRS) $(SRCS)
  		pr -l60 -w132 $? | lpr -d "-tpm"
  		-touch Print
  
  P_all:
! 		pr -l60 -w132 Tags $(HDRS) $(SRCS) | lpr -mc -d "-tpm"
  		-touch Print
  
  lint:
  		lint $(LINTARGS) $(SRCS) -lcurses
  
  wc:
! 		wc $(HDRS) $(SRCS)
  
  #
  # To make a binary-only export
--- 84,102 ----
  pm_user:
  		> $(PM_USER)
  
! Print:		$(HDRS) $(SRCS) flsbuf.c
  		pr -l60 -w132 $? | lpr -d "-tpm"
  		-touch Print
  
  P_all:
! 		pr -l60 -w132 Tags $(HDRS) $(SRCS) flsbuf.c | lpr -mc -d "-tpm"
  		-touch Print
  
  lint:
  		lint $(LINTARGS) $(SRCS) -lcurses
  
  wc:
! 		wc $(HDRS) $(SRCS) flsbuf.c
  
  #
  # To make a binary-only export
*** init.c-orig	Tue Aug  8 23:10:48 1989
--- init.c	Wed Aug  9 02:07:10 1989
***************
*** 6,12 ****
--- 6,14 ----
  #include "pm.h"
  
  coord	pm_pos;
+ #ifdef BSD
  struct	timeb	_tp;		/* used for timing			*/
+ #endif /* BSD */
  long	thescore = 0L,		/* player's score			*/
  	hi_score = 0L, 		/* high score so far			*/
  	move_cntr = 0L,		/* # of moves made by player		*/
***************
*** 16,22 ****
--- 18,26 ----
  	ch = ' ',		/* current move of pm			*/
  	oldch = '\0',		/* old (temporary) move			*/
  	newch = '\0',		/* new move (future)			*/
+ #ifdef BSD
  	baud = '\0',		/* output baud rate of terminal		*/
+ #endif /* BSD */
  	*argv0,			/* argv[0]				*/
  	*mesg;			/* pointer to last message		*/
  int	timeit = FALSE,		/* printing loop/move counter?		*/
***************
*** 55,66 ****
--- 59,72 ----
  {
  	130, 130, 120, 115, 110, 100, 95, 85, 75, 70, 65, 55, 45
  };
+ #ifdef BSD
  int	bauds[] =
  {
  /* 0  1  2   3   4   5   6   7   8     9    10    11    12    13     14   15*/
  /* 0 50 75 110 134 150 200 300 600  1200  1800  2400  4800  9600   EXTA EXTB*/
     0, 0, 0,  0,  0,  0,  0,  0,  0, 1200, 1800, 2400, 4800, 9600, 19200,   0
  };
+ #endif /* BSD */
  
  /*
  ** init() -	perform necessary intializations
***************
*** 79,90 ****
  			argv0);
  #endif
  	hi_score = get_hi_scr();
! 	if (initscr() == ERR)
  	{
  		fprintf(stderr, "initscr() error\n");
  		perror(argv0);
  		exit(1);
  	}
  	if (!baud)	/* if baud, then we are trying to simulate another */
  	{
  		if (!bauds[_tty.sg_ospeed])
--- 85,97 ----
  			argv0);
  #endif
  	hi_score = get_hi_scr();
! 	if (initscr() == ERRWIN)
  	{
  		fprintf(stderr, "initscr() error\n");
  		perror(argv0);
  		exit(1);
  	}
+ #ifdef BSD
  	if (!baud)	/* if baud, then we are trying to simulate another */
  	{
  		if (!bauds[_tty.sg_ospeed])
***************
*** 95,100 ****
--- 102,108 ----
  		}
  		baud = _tty.sg_ospeed;
  	}
+ #endif /* BSD */
  	trap(0);
  	h = &ghosts[0];
  	g = &ghosts[1];
*** make_moves.c-o	Tue Aug  8 22:58:37 1989
--- make_moves.c	Wed Aug  9 00:52:18 1989
***************
*** 152,159 ****
  		return(FALSE);
  	return(l > 0 ? TRUE : FALSE);
  #else
  	return(1);
! #endif
  }
  
  /*
--- 152,163 ----
  		return(FALSE);
  	return(l > 0 ? TRUE : FALSE);
  #else
+ #ifdef FIORDCHK
+ 	return(ioctl(0, FIORDCHK, (char *)NULL));
+ #else
  	return(1);
! #endif /* FIORDCHK */
! #endif /* !FIONREAD */
  }
  
  /*
***************
*** 315,321 ****
  			*/
  			if (is_wiz) /* wizard is an exception! */
  				return(trash(getchar()), ERROR);
! 			_puts(CL);
  			move(LINES - 1, 0);
  			draw();
  			printf("[Hit return when ready] ");
--- 319,325 ----
  			*/
  			if (is_wiz) /* wizard is an exception! */
  				return(trash(getchar()), ERROR);
! 			clear();
  			move(LINES - 1, 0);
  			draw();
  			printf("[Hit return when ready] ");
***************
*** 402,408 ****
  	};
  	reg	char	**s = cmds;
  
! 	_puts(CL);
  	while (*s)
  		printf("%s\n", *s++);
  	trash(getchar());
--- 406,412 ----
  	};
  	reg	char	**s = cmds;
  
! 	clear(); refresh();
  	while (*s)
  		printf("%s\n", *s++);
  	trash(getchar());
***************
*** 416,422 ****
  void	status ()
  {
  	alarm(0);
! 	_puts(CL);
  	move(0, 0);
  	printf("        Diagnostics\n\n");
  	printf("Fruit:             %c\n", fr_ch);
--- 420,426 ----
  void	status ()
  {
  	alarm(0);
! 	clear(); refresh();
  	move(0, 0);
  	printf("        Diagnostics\n\n");
  	printf("Fruit:             %c\n", fr_ch);
***************
*** 434,440 ****
--- 438,448 ----
  	printf("Score:             %ld\n", thescore);
  	printf("Pos.:              (%d, %d)\n", pm_pos.x, pm_pos.y);
  	printf("Tunn.:             %s\n",TF(pm_tunn));
+ #ifdef BSDCURSES
  	printf("Baud:              %d\n", bauds[baud]);
+ #else
+ 	printf("Baud:              %d\n", baudrate());
+ #endif /* !BSDCURSES */
  	printf("Screen dimension   %d x %d\n", LINES, COLS);
  	printf("High score:        %ld\n", hi_score);
  	printf("Max's:             %d,%d\n", stdscr->_maxy, stdscr->_maxx);
*** monsters.c-ori	Tue Aug  8 23:00:37 1989
--- monsters.c	Tue Aug  8 23:03:42 1989
***************
*** 183,189 ****
  	m = wh_mons(name);
  	if (m == NULL)
  		msg("No such monster: %s", punctrl(name));
! 	_puts(CL);
  	fprintf(stderr, "Name:          %c\n", m->mo_name);
  	fprintf(stderr, "Place:         (%d,%d)\n", m->mo_pos.x, m->mo_pos.y);
  	fprintf(stderr, "Inch:          %c\n", m->mo_inch);
--- 183,189 ----
  	m = wh_mons(name);
  	if (m == NULL)
  		msg("No such monster: %s", punctrl(name));
! 	clear(); refresh();
  	fprintf(stderr, "Name:          %c\n", m->mo_name);
  	fprintf(stderr, "Place:         (%d,%d)\n", m->mo_pos.x, m->mo_pos.y);
  	fprintf(stderr, "Inch:          %c\n", m->mo_inch);
*** pm.c-orig	Wed Aug  9 00:53:34 1989
--- pm.c	Wed Aug  9 00:54:32 1989
***************
*** 22,30 ****
--- 22,32 ----
  			case 's':
  				check_scrs();
  				exit(0);
+ #ifdef BSDCURSES
  			case 'B':
  				baud = to_baud(++*argv);
  				break;
+ #endif /* BSDCURSES */
  			default:
  				usage();
  		}
*** pm.h-orig	Tue Aug  8 22:51:25 1989
--- pm.h	Wed Aug  9 02:06:21 1989
***************
*** 10,17 ****
  #define	PATTERNS		/* let there be patterns!!!		*/
  #define	FASTER			/* let the monsters move fast (monsters.c) */
  #define	MAX_UPDATE		/* more refreshes			*/
! #ifdef	BSD42|BSD43|BSD29
  #	define	BAD_OVERLAY	/* bug in curses (overlay.c)		*/
  #endif
  #define	MYTIMER			/* quite reliable			*/
  
--- 10,18 ----
  #define	PATTERNS		/* let there be patterns!!!		*/
  #define	FASTER			/* let the monsters move fast (monsters.c) */
  #define	MAX_UPDATE		/* more refreshes			*/
! #if defined(BSD42) || defined(BSD43) || defined(BSD29)
  #	define	BAD_OVERLAY	/* bug in curses (overlay.c)		*/
+ #	define	BSDCURSES	/* no delay_output() function		*/
  #endif
  #define	MYTIMER			/* quite reliable			*/
  
***************
*** 22,28 ****
  #include <ctype.h>
  #include <sys/types.h>
  #include <sys/timeb.h>
! #ifdef	BSD42|BSD43
  #	include <sys/time.h>
  #else
  #	include <time.h>
--- 23,29 ----
  #include <ctype.h>
  #include <sys/types.h>
  #include <sys/timeb.h>
! #if defined(BSD42) || defined(BSD43)
  #	include <sys/time.h>
  #else
  #	include <time.h>
***************
*** 248,264 ****
  #define	randomize(i)	seed = i
  #define	flush()		raw(),noraw()
  #define	m_erase(mon)	mvaddch(mon.mo_pos.y, mon.mo_pos.x, mon.mo_inch)
  #define	draw()		ftime(&_tp), refresh(), delay()
  
  extern	coord	pm_pos;
- extern	struct	timeb	_tp;
  extern	int	pm_tunn, pm_extunn, d_left, e_left, level, fr_val,
  		fruit_val[], pms_left, pm_bonus, pm_eaten, pm_run,
  		mons_eaten, mons_val[], eat_times[], timer, was_wiz, is_wiz,
! 		timeit, quiet, fast, uid, seed, bauds[], wizard_uid;
  extern	char	*argv0, fruit[], fruit_eaten[], fr_ch, ch, oldch,
! 		newch, moves[], *mesg, **environ, *pm_user, *pm_roll,
! 		baud;
  #ifdef	LINT
  extern	char	_trash_;
  #endif
--- 249,274 ----
  #define	randomize(i)	seed = i
  #define	flush()		raw(),noraw()
  #define	m_erase(mon)	mvaddch(mon.mo_pos.y, mon.mo_pos.x, mon.mo_inch)
+ #ifdef BSDCURSES
  #define	draw()		ftime(&_tp), refresh(), delay()
+ extern	struct	timeb	_tp;
+ #else
+ #define draw()		refresh(), delay()
+ #endif
  
  extern	coord	pm_pos;
  extern	int	pm_tunn, pm_extunn, d_left, e_left, level, fr_val,
  		fruit_val[], pms_left, pm_bonus, pm_eaten, pm_run,
  		mons_eaten, mons_val[], eat_times[], timer, was_wiz, is_wiz,
! 		timeit, quiet, fast, uid, seed, wizard_uid;
! #ifdef BSDCURSES
! extern	int	bauds[];
! #endif /* BSDCURSES */
  extern	char	*argv0, fruit[], fruit_eaten[], fr_ch, ch, oldch,
! 		newch, moves[], *mesg, **environ, *pm_user, *pm_roll;
! #ifdef BSDCURSES
! extern	char	baud;
! #endif /* BSDCURSES */
  #ifdef	LINT
  extern	char	_trash_;
  #endif
***************
*** 268,273 ****
--- 278,289 ----
  extern	char	_putchar(), *crypt(), *strcpy();
  extern	int	getuid();
  extern	off_t	lseek();
+ 
+ #ifdef BSDCURSES
+ #define ERRWIN	ERR
+ #else
+ #define ERRWIN	(WINDOW *)NULL
+ #endif /* BSDCURSES */
  
  /*
  ** local functions
*** rip.c-orig	Tue Aug  8 23:00:55 1989
--- rip.c	Tue Aug  8 23:02:50 1989
***************
*** 14,20 ****
  {
  	echo();
  	nocrmode();
! 	_puts(CL);
  	tombstone(thescore, mon);
  	printf("[Press return to continue]");
  	getchar();
--- 14,20 ----
  {
  	echo();
  	nocrmode();
! 	clear(); refresh();
  	tombstone(thescore, mon);
  	printf("[Press return to continue]");
  	getchar();
*** screen.c-orig	Wed Aug  9 01:00:24 1989
--- screen.c	Wed Aug  9 02:06:53 1989
***************
*** 249,255 ****
  	{
  		reg	char	**str = _board;
  
! 		if ((tmp = newwin(0, 0, 0, 0)) == ERR)
  		{
  			move(0, 0);
  			printw("barriers(): newwin() error");
--- 249,255 ----
  	{
  		reg	char	**str = _board;
  
! 		if ((tmp = newwin(0, 0, 0, 0)) == ERRWIN)
  		{
  			move(0, 0);
  			printw("barriers(): newwin() error");
*** timing.c-orig	Tue Aug  8 23:01:50 1989
--- timing.c	Wed Aug  9 01:37:22 1989
***************
*** 21,26 ****
--- 21,27 ----
  */
  void	delay ()
  {
+ #ifdef BSDCURSES
  	unss	mlen, u;	/* how long it took to print */
  	auto	struct	timeb	tp;
  
***************
*** 29,39 ****
--- 30,51 ----
  	if ((u = PAWS(chcnt)) >= mlen)
  		msleep(u - mlen);
  	chcnt = 0l;
+ #else
+ 	/*
+ 	 * Delay is used to make sure we don't get ahead of the screen.
+ 	 * So OK, we can use a wait-for-queue and avoid all the mess
+ 	 * with character counting.
+ 	 */
+ 	ioctl(1, TCSBRK, 1);	/* don't send a break */
+ #endif /* BSDCURSES */
  }
  
  /*
  ** msleep()	- sleep the specified number of milliseconds
  */
+ #ifndef BSDCURSES
+ void msleep(u)	{delay_output(u);}
+ #else
  void	msleep (u)
  reg	unss	u;
  {
***************
*** 79,84 ****
--- 91,97 ----
  	return(0);
  }
  #endif
+ #endif /* BSDCURSES */
  
  static	int	rates[] =	/* these were `tuned' after much playing */
  {
***************
*** 106,111 ****
--- 119,125 ----
  void	slow (flag)
  reg	int	flag;
  {
+ #ifdef BSDCURSES
  	reg	int	ms;
  	static	struct	timeb	tp;
  	auto	struct	timeb	tp2;
***************
*** 130,135 ****
--- 144,150 ----
  			msleep(rates[level] - ms);
  	}
  	ftime(&tp);
+ #endif /* BSDCURSES */
  }
  
  /*
***************
*** 140,146 ****
  {
  	auto	char	buf[BUFSIZ];
  
! 	_puts(CL);
  	echo();
  	nocrmode();
  	printf("old delay: %d, new delay: ", rates[level]);
--- 155,161 ----
  {
  	auto	char	buf[BUFSIZ];
  
! 	clear(); refresh();
  	echo();
  	nocrmode();
  	printf("old delay: %d, new delay: ", rates[level]);
***************
*** 154,159 ****
--- 169,175 ----
  	redraw();
  }
  
+ #ifdef BSD_CURSES
  /*
  ** to_baud()	- convert the given string to an appropriate baud define
  */
***************
*** 174,176 ****
--- 190,193 ----
  			return((char) i);
  	return('\0');
  }
+ #endif /* BSDCURSES */
--
      Eric S. Raymond = eric@snark.uu.net    (mad mastermind of TMN-Netnews)