home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!zephyr.ens.tek.com!master!saab!billr
- From: billr@saab.tek.com (Bill Randle)
- Newsgroups: comp.sources.games
- Subject: v12i097: rogue - a rogue 5.3 clone, Patch3
- Message-ID: <1764@masterCNA.TEK.COM>
- Date: 13 Sep 91 18:38:07 GMT
- Sender: news@masterCNA.TEK.COM
- Lines: 1500
- Approved: billr@saab.CNA.TEK.COM
-
- Submitted-by: seaotter@ATHENA.MIT.EDU
- Posting-number: Volume 12, Issue 97
- Archive-name: rogue/Patch3
- Patch-To: rogue: Volume 1, Issue 11-16
-
-
- [[Here are the changes necessary to adapt Tim Stoehr's rogue clone to VMS.
- It consists of a new machdep.c, a Makefile for VMS and a .com file that
- emulates it, a package of terminal functions wrapped into vmsterm.c and
- vmsterm.h, and a small patchfile. I have refrained from adding new com-
- mands or fiddling with the code unnecessarily: I might do that later.
-
- --Mike Zraly]]
-
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: BUGS3 Make.com Makefile.vms Patches03 README.VMS machdep.c
- # vmsterm.c vmsterm.h
- # Wrapped by seaotter@e40-008-10 on Fri Aug 23 23:47:03 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'BUGS3' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'BUGS3'\"
- else
- echo shar: Extracting \"'BUGS3'\" \(972 characters\)
- sed "s/^X//" >'BUGS3' <<'END_OF_FILE'
- XHere is yet another list for fixes for Tim Stoehr's rogue clone.
- XI was not able to contact Tim at his Tektronix email address, so
- XI added these myself. This introduces a diversion from the rogue
- Xclone distributed by Berkeley but I don't really see them as being
- Xinterested in VMS compatability.
- X Mike Zraly
- X mzraly@ldbvax.dnet.lotus.com
- X or c/o seaotter@athena.mit.edu
- X ----------------------------------------------------
- X
- X 1.) Add VMS compatability through changes to machdep.c (add
- X appropriate code), the introduction of one small #define
- X to rogue.h, and a package of VMS keyboard i/o functions
- X I developed (vmsterm.c and vmsterm.h). I also added a
- X Makefile for VMS suitable for use with the VMS Make program
- X (available via anonymous FTP from vmsd.oac.uci.edu or
- X pomona.claremont.edu)
- X
- X 2.) Replace comment within comment in machdep.c (circa line 41)
- X with [* ... *] instead of /* ... */
- X
- X 3.) Change patchlevel.h
- X
- X 4.) Change version message in play.c
- X
- X
- END_OF_FILE
- if test 972 -ne `wc -c <'BUGS3'`; then
- echo shar: \"'BUGS3'\" unpacked with wrong size!
- fi
- # end of 'BUGS3'
- fi
- if test -f 'Make.com' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Make.com'\"
- else
- echo shar: Extracting \"'Make.com'\" \(846 characters\)
- sed "s/^X//" >'Make.com' <<'END_OF_FILE'
- X$ On Control_Y Then Goto The_Exit
- X$ On Error Then Goto The_Exit
- X$ cc curses
- X$ cc hit
- X$ cc init
- X$ cc inventory
- X$ cc level
- X$ cc machdep
- X$ cc main
- X$ cc message
- X$ cc monster
- X$ cc move
- X$ cc object
- X$ cc pack
- X$ cc play
- X$ cc random
- X$ cc ring
- X$ cc room
- X$ cc save
- X$ cc score
- X$ cc spec_hit
- X$ cc throw
- X$ cc trap
- X$ cc use
- X$ cc zap
- X$ cc vmsterm
- X$ open/write foo rtl.opt
- X$ write foo "SYS$LIBRARY:VAXCRTLG/SHARE"
- X$ close foo
- X$ link /exe=rogue curses.obj, hit.obj, init.obj,-
- X inventory.obj, level.obj, machdep.obj,-
- X main.obj, message.obj, monster.obj,-
- X move.obj, object.obj, pack.obj,-
- X play.obj, random.obj, ring.obj,-
- X room.obj, save.obj, score.obj,-
- X spec_hit.obj, throw.obj, trap.obj,-
- X use.obj, zap.obj, vmsterm.obj, rtl.opt/opt
- X$ rogue :== $'f$env("default")'rogue.exe
- X$The_Exit:
- X$ Save_Status = $STATUS
- X$ exit Save_Status
- END_OF_FILE
- if test 846 -ne `wc -c <'Make.com'`; then
- echo shar: \"'Make.com'\" unpacked with wrong size!
- fi
- # end of 'Make.com'
- fi
- if test -f 'Makefile.vms' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile.vms'\"
- else
- echo shar: Extracting \"'Makefile.vms'\" \(934 characters\)
- sed "s/^X//" >'Makefile.vms' <<'END_OF_FILE'
- X#
- X# VMS makefile for rogue
- X#
- X
- XROGUE_OBJS = curses.obj, hit.obj, init.obj, \
- X inventory.obj, level.obj, machdep.obj, \
- X main.obj, message.obj, monster.obj, \
- X move.obj, object.obj, pack.obj, \
- X play.obj, random.obj, ring.obj, \
- X room.obj, save.obj, score.obj, \
- X spec_hit.obj, throw.obj, trap.obj, \
- X use.obj, zap.obj, vmsterm.obj
- X
- XCC = cc
- X
- XCFLAGS =
- X
- Xrogue: $(ROGUE_OBJS) rtl.opt
- X link /exe=rogue $(ROGUE_OBJS), rtl.opt/opt
- X rogue :== $'f$env("default")'rogue.exe
- X
- Xrtl.opt:
- X open/write foo rtl.opt
- X write foo "SYS$LIBRARY:VAXCRTLG/SHARE"
- X close foo
- X
- X*.obj: *.c rogue.h
- X $(CC) $(CFLAGS) $*
- X
- Xallclean: clean
- X msg = f$env("MESSAGE")
- X set mess /nofac/noid/nosev/notext
- X delete/nolog rogue.exe;*
- X set mess 'msg'
- X
- Xclean:
- X msg = f$env("MESSAGE")
- X set mess /nofac/noid/nosev/notext
- X purge/nolog
- X delete/nolog *.lis;*
- X delete/nolog *.obj;*
- X delete/nolog rogue.scores;*
- X delete/nolog rogue.save;*
- X delete/nolog rtl.opt;*
- X set mess 'msg'
- END_OF_FILE
- if test 934 -ne `wc -c <'Makefile.vms'`; then
- echo shar: \"'Makefile.vms'\" unpacked with wrong size!
- fi
- # end of 'Makefile.vms'
- fi
- if test -f 'Patches03' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Patches03'\"
- else
- echo shar: Extracting \"'Patches03'\" \(1307 characters\)
- sed "s/^X//" >'Patches03' <<'END_OF_FILE'
- X*** patchlevel.h.orig Wed Aug 14 06:29:16 1991
- X--- patchlevel.h Wed Aug 21 11:57:22 1991
- X***************
- X*** 1 ****
- X! #define PATCHLEVEL 2
- X--- 1 ----
- X! #define PATCHLEVEL 3
- X*** play.c.orig Wed Aug 14 06:26:18 1991
- X--- play.c Wed Aug 21 11:58:38 1991
- X***************
- X*** 1,4 ****
- X--- 1,8 ----
- X /*
- X+ * This code was adapted for VMS by Mike Zraly
- X+ */
- X+
- X+ /*
- X * play.c
- X *
- X * This source herein may be modified and/or distributed by anybody who
- X***************
- X*** 154,160 ****
- X throw();
- X break;
- X case 'v':
- X! message("rogue-clone: Version II. (Tim Stoehr was here), tektronix!zeus!tims", 0);
- X break;
- X case 'Q':
- X quit(0);
- X--- 158,164 ----
- X throw();
- X break;
- X case 'v':
- X! message("rogue-clone: Version II+VMS (M Zraly was here), mzraly@ldbvax.dnet.lotus.com", 0);
- X break;
- X case 'Q':
- X quit(0);
- X*** rogue.h.orig Wed Aug 14 06:55:39 1991
- X--- rogue.h Wed Aug 21 11:57:26 1991
- X***************
- X*** 1,4 ****
- X--- 1,8 ----
- X /*
- X+ * This code was adapted for VMS by Mike Zraly
- X+ */
- X+
- X+ /*
- X * object.h
- X *
- X * This source herein may be modified and/or distributed by anybody who
- X***************
- X*** 9,14 ****
- X--- 13,22 ----
- X * gain or profit.
- X *
- X */
- X+
- X+ #ifdef VMS
- X+ #define getchar() tt_getc()
- X+ #endif /* VMS */
- X
- X #define boolean char
- X
- END_OF_FILE
- if test 1307 -ne `wc -c <'Patches03'`; then
- echo shar: \"'Patches03'\" unpacked with wrong size!
- fi
- # end of 'Patches03'
- fi
- if test -f 'README.VMS' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README.VMS'\"
- else
- echo shar: Extracting \"'README.VMS'\" \(1433 characters\)
- sed "s/^X//" >'README.VMS' <<'END_OF_FILE'
- XHere is how to get rogue running on VMS:
- X
- X1) unpack these sources -- if you have them in vms_share format,
- X concatenate the different files in correct order into somefile.com,
- X then type @somefile; if you have them in cshar format, you will
- X either have to extract them on a UNIX system and then send them
- X to your VMS system somehow, or manually unpack the files with
- X your favorite editor. (Ugh!)
- X
- X2) once you have all the files in one source directory, type
- X
- X @make
- X
- X to compile and link everything together. Alternatively you
- X could use the VMS make program available from either of the
- X following anonymous FTP sites:
- X
- X SITE: pomona.claremont.edu
- X IP-#: 134.173.4.160
- X DIR: [.utilities.make]
- X FILES: *.*
- X
- X SITE: vmsd.oac.uci.edu
- X IP-#: 128.200.15.2
- X DIR: /
- X FILES: make_src.*
- X
- X [Makefile.vms was generated by this make program]
- X
- X Install it at your site and type
- X
- X rename Makefile.vms Makefile
- X make
- X
- X Either way, you may now play rogue by typing
- X
- X rogue
- X
- X but if you want to do it every session, you should put the
- X following into your LOGIN.COM:
- X
- X $ rogue :== $DISK:[DIRECTORY]rogue.exe
- X
- X for example I might have
- X
- X $ rogue :== $DISK$USER26:[MZRALY.ROGUE]
- X
- X If you have any questions, try typing
- X
- X help :=
- X
- X--
- X
- X
- XMike Zraly ``Times are bad. Children no longer
- Xmzraly@ldbvax.dnet.lotus.com obey their parents, and everyone is
- Xor c/o seaotter@athena.mit.edu writing a book.'' -- Cicero
- END_OF_FILE
- if test 1433 -ne `wc -c <'README.VMS'`; then
- echo shar: \"'README.VMS'\" unpacked with wrong size!
- fi
- # end of 'README.VMS'
- fi
- if test -f 'machdep.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'machdep.c'\"
- else
- echo shar: Extracting \"'machdep.c'\" \(17495 characters\)
- sed "s/^X//" >'machdep.c' <<'END_OF_FILE'
- X/*
- X * This code was adapted for VMS by Mike Zraly
- X */
- X
- X/*
- X * machdep.c
- X *
- X * This source herein may be modified and/or distributed by anybody who
- X * so desires, with the following restrictions:
- X * 1.) No portion of this notice shall be removed.
- X * 2.) Credit shall not be taken for the creation of this source.
- X * 3.) This code is not to be traded, sold, or used for personal
- X * gain or profit.
- X *
- X */
- X
- X/* Included in this file are all system dependent routines. Extensive use
- X * of #ifdef's will be used to compile the appropriate code on each system:
- X *
- X * UNIX: all UNIX systems.
- X * UNIX_BSD4_2: UNIX BSD 4.2 and later, UTEK, (4.1 BSD too?)
- X * UNIX_SYSV: UNIX system V
- X * UNIX_V7: UNIX version 7
- X * VMS: all VMS systems.
- X *
- X * All UNIX code should be included between the single "#ifdef UNIX" at the
- X * top of this file, and the "#endif UNIX" at the bottom.
- X *
- X * To change a routine to include a new UNIX system, simply #ifdef the
- X * existing routine, as in the following example:
- X *
- X * To make a routine compatible with UNIX system V, change the first
- X * function to the second:
- X *
- X * md_function()
- X * {
- X * code;
- X * }
- X *
- X * md_function()
- X * {
- X * #ifdef UNIX_SYSV
- X * sysVcode;
- X * #else
- X * code;
- X * #endif [* UNIX_SYSV *]
- X * }
- X *
- X * Appropriate variations of this are of course acceptible.
- X * The use of "#elseif" is discouraged because of non-portability.
- X * If the correct #define doesn't exist, "UNIX_SYSV" in this case, make it up
- X * and insert it in the list at the top of the file. Alter the CFLAGS
- X * in you Makefile appropriately.
- X *
- X */
- X
- X#include <stdio.h>
- X
- X#ifdef UNIX
- X#include <sys/types.h>
- X#include <sys/file.h>
- X#include <sys/stat.h>
- X#endif /* UNIX */
- X
- X#ifdef VMS
- X#include <types.h>
- X#include <file.h>
- X#include <stat.h>
- X#endif /* VMS */
- X
- X#ifdef UNIX_SYSV
- X#include <time.h>
- X#include <termio.h>
- X#endif /* UNIX_SYSV */
- X
- X#ifdef UNIX_BSD4_2
- X#include <sys/time.h>
- X#include <sgtty.h>
- X#endif /* UNIX_BSD4_2 */
- X
- X#ifdef VMS
- X#include <time.h>
- X#endif /* VMS */
- X
- X#include <signal.h>
- X#include "rogue.h"
- X
- X/* md_slurp:
- X *
- X * This routine throws away all keyboard input that has not
- X * yet been read. It is used to get rid of input that the user may have
- X * typed-ahead.
- X *
- X * This function is not necessary, so it may be stubbed. The might cause
- X * message-line output to flash by because the game has continued to read
- X * input without waiting for the user to read the message. Not such a
- X * big deal.
- X */
- X
- Xmd_slurp()
- X{
- X#ifdef UNIX
- X long ln = 0;
- X
- X#ifdef UNIX_BSD4_2
- X ioctl(0, FIONREAD, &ln);
- X#endif /* UNIX_BSD4_2 */
- X#ifdef UNIX_SYSV
- X ioctl(0, TCFLSH, &ln);
- X ln = 0;
- X#endif /* UNIX_SYSV */
- X
- X ln += stdin->_cnt;
- X
- X for (; ln > 0; ln--) {
- X (void) getchar();
- X }
- X#endif /* UNIX */
- X#ifdef VMS
- X tt_flush();
- X#endif /* VMS */
- X}
- X
- X/* md_control_keyboard():
- X *
- X * This routine is much like md_cbreak_no_echo_nonl() below. It sets up the
- X * keyboard for appropriate input. Specifically, it prevents the tty driver
- X * from stealing characters. For example, ^Y is needed as a command
- X * character, but the tty driver intercepts it for another purpose. Any
- X * such behavior should be stopped. This routine could be avoided if
- X * we used RAW mode instead of CBREAK. But RAW mode does not allow the
- X * generation of keyboard signals, which the program uses.
- X *
- X * The parameter 'mode' when true, indicates that the keyboard should
- X * be set up to play rogue. When false, it should be restored if
- X * necessary.
- X *
- X * This routine is not strictly necessary and may be stubbed. This may
- X * cause certain command characters to be unavailable.
- X */
- X
- Xmd_control_keybord(mode)
- Xboolean mode;
- X{
- X#ifdef UNIX
- X static boolean called_before = 0;
- X#ifdef UNIX_BSD4_2
- X static struct ltchars ltc_orig;
- X static struct tchars tc_orig;
- X struct ltchars ltc_temp;
- X struct tchars tc_temp;
- X#endif /* UNIX_BSD4_2 */
- X#ifdef UNIX_SYSV
- X static struct termio _oldtty;
- X struct termio _tty;
- X#endif /* UNIX_SYSV */
- X
- X if (!called_before) {
- X called_before = 1;
- X#ifdef UNIX_BSD4_2
- X ioctl(0, TIOCGETC, &tc_orig);
- X ioctl(0, TIOCGLTC, <c_orig);
- X#endif /* UNIX_BSD4_2 */
- X#ifdef UNIX_SYSV
- X ioctl(0, TCGETA, &_oldtty);
- X#endif /* UNIX_SYSV */
- X }
- X#ifdef UNIX_BSD4_2
- X ltc_temp = ltc_orig;
- X tc_temp = tc_orig;
- X#endif /* UNIX_BSD4_2 */
- X#ifdef UNIX_SYSV
- X _tty = _oldtty;
- X#endif /* UNIX_SYSV */
- X
- X if (!mode) {
- X#ifdef UNIX_BSD4_2
- X ltc_temp.t_suspc = ltc_temp.t_dsuspc = -1;
- X ltc_temp.t_rprntc = ltc_temp.t_flushc = -1;
- X ltc_temp.t_werasc = ltc_temp.t_lnextc = -1;
- X tc_temp.t_startc = tc_temp.t_stopc = -1;
- X#endif /* UNIX_BSD4_2 */
- X#ifdef UNIX_SYSV
- X _tty.c_cc[VSWTCH] = CNSWTCH;
- X#endif /* UNIX_SYSV */
- X }
- X#ifdef UNIX_BSD4_2
- X ioctl(0, TIOCSETC, &tc_temp);
- X ioctl(0, TIOCSLTC, <c_temp);
- X#endif /* UNIX_BSD4_2 */
- X#ifdef UNIX_SYSV
- X ioctl(0, TCSETA, &_tty);
- X#endif /* UNIX_SYSV */
- X#endif /* UNIX */
- X#ifdef VMS
- X if (mode)
- X tt_init();
- X else
- X tt_fini();
- X#endif /* VMS */
- X}
- X
- X/* md_heed_signals():
- X *
- X * This routine tells the program to call particular routines when
- X * certain interrupts/events occur:
- X *
- X * SIGINT: call onintr() to interrupt fight with monster or long rest.
- X * SIGQUIT: call byebye() to check for game termination.
- X * SIGHUP: call error_save() to save game when terminal hangs up.
- X *
- X * On VMS, SIGINT and SIGQUIT correspond to ^C and ^Y.
- X *
- X * This routine is not strictly necessary and can be stubbed. This will
- X * mean that the game cannot be interrupted properly with keyboard
- X * input, this is not usually critical.
- X */
- X
- Xmd_heed_signals()
- X{
- X signal(SIGINT, onintr);
- X signal(SIGQUIT, byebye);
- X signal(SIGHUP, error_save);
- X}
- X
- X/* md_ignore_signals():
- X *
- X * This routine tells the program to completely ignore the events mentioned
- X * in md_heed_signals() above. The event handlers will later be turned on
- X * by a future call to md_heed_signals(), so md_heed_signals() and
- X * md_ignore_signals() need to work together.
- X *
- X * This function should be implemented or the user risks interrupting
- X * critical sections of code, which could cause score file, or saved-game
- X * file, corruption.
- X */
- X
- Xmd_ignore_signals()
- X{
- X signal(SIGQUIT, SIG_IGN);
- X signal(SIGINT, SIG_IGN);
- X signal(SIGHUP, SIG_IGN);
- X}
- X
- X/* md_get_file_id():
- X *
- X * This function returns an integer that uniquely identifies the specified
- X * file. It need not check for the file's existence. In UNIX, the inode
- X * number is used.
- X *
- X * This function need not be implemented. To stub the routine, just make
- X * it return 0. This will make the game less able to prevent users from
- X * modifying saved-game files. This is probably no big deal.
- X */
- X
- Xint
- Xmd_get_file_id(fname)
- Xchar *fname;
- X{
- X#ifdef UNIX
- X struct stat sbuf;
- X
- X if (stat(fname, &sbuf)) {
- X return(-1);
- X }
- X return((int) sbuf.st_ino);
- X#endif /* UNIX */
- X#ifdef VMS
- X return((int) 0);
- X#endif /* VMS */
- X}
- X
- X/* md_link_count():
- X *
- X * This routine returns the number of hard links to the specified file.
- X *
- X * This function is not strictly necessary. On systems without hard links
- X * this routine can be stubbed by just returning 1.
- X */
- X
- Xint
- Xmd_link_count(fname)
- Xchar *fname;
- X{
- X#ifdef UNIX
- X struct stat sbuf;
- X
- X stat(fname, &sbuf);
- X return((int) sbuf.st_nlink);
- X#endif /* UNIX */
- X#ifdef VMS
- X return((int) 1);
- X#endif /* VMS */
- X}
- X
- X/* md_gct(): (Get Current Time)
- X *
- X * This function returns the current year, month(1-12), day(1-31), hour(0-23),
- X * minute(0-59), and second(0-59). This is used for identifying the time
- X * at which a game is saved.
- X *
- X * This function is not strictly necessary. It can be stubbed by returing
- X * zeros instead of the correct year, month, etc. If your operating
- X * system doesn't provide all of the time units requested here, then you
- X * can provide only those that it does, and return zeros for the others.
- X * If you cannot provide good time values, then users may be able to copy
- X * saved-game files and play them.
- X */
- X
- Xmd_gct(rt_buf)
- Xstruct rogue_time *rt_buf;
- X{
- X struct tm *t, *localtime();
- X time_t seconds = 0;
- X
- X time(&seconds);
- X t = localtime(&seconds);
- X
- X rt_buf->year = t->tm_year;
- X rt_buf->month = t->tm_mon + 1;
- X rt_buf->day = t->tm_mday;
- X rt_buf->hour = t->tm_hour;
- X rt_buf->minute = t->tm_min;
- X rt_buf->second = t->tm_sec;
- X}
- X
- X/* md_gfmt: (Get File Modification Time)
- X *
- X * This routine returns a file's date of last modification in the same format
- X * as md_gct() above.
- X *
- X * This function is not strictly necessary. It is used to see if saved-game
- X * files have been modified since they were saved. If you have stubbed the
- X * routine md_gct() above by returning constant values, then you may do
- X * exactly the same here.
- X * Or if md_gct() is implemented correctly, but your system does not provide
- X * file modification dates, you may return some date far in the past so
- X * that the program will never know that a saved-game file being modified.
- X * You may also do this if you wish to be able to restore games from
- X * saved-games that have been modified.
- X */
- X
- Xmd_gfmt(fname, rt_buf)
- Xchar *fname;
- Xstruct rogue_time *rt_buf;
- X{
- X struct stat sbuf;
- X time_t seconds;
- X struct tm *t;
- X
- X stat(fname, &sbuf);
- X seconds = (time_t) sbuf.st_mtime;
- X t = localtime(&seconds);
- X
- X rt_buf->year = t->tm_year;
- X rt_buf->month = t->tm_mon + 1;
- X rt_buf->day = t->tm_mday;
- X rt_buf->hour = t->tm_hour;
- X rt_buf->minute = t->tm_min;
- X rt_buf->second = t->tm_sec;
- X}
- X
- X/* md_df: (Delete File)
- X *
- X * This function deletes the specified file, and returns true (1) if the
- X * operation was successful. This is used to delete saved-game files
- X * after restoring games from them.
- X *
- X * Again, this function is not strictly necessary, and can be stubbed
- X * by simply returning 1. In this case, saved-game files will not be
- X * deleted and can be replayed.
- X */
- X
- Xboolean
- Xmd_df(fname)
- Xchar *fname;
- X{
- X#ifdef VMS
- X#define unlink delete
- X#endif /* VMS */
- X
- X if (unlink(fname)) {
- X return(0);
- X }
- X return(1);
- X}
- X
- X/* md_gln: (Get login name)
- X *
- X * This routine returns the login name of the user. This string is
- X * used mainly for identifying users in score files.
- X *
- X * A dummy string may be returned if you are unable to implement this
- X * function, but then the score file would only have one name in it.
- X */
- X
- Xchar *
- Xmd_gln()
- X{
- X#ifdef UNIX
- X char *getlogin();
- X char *t;
- X
- X t = getlogin();
- X return(t);
- X#endif /* UNIX */
- X#ifdef VMS
- X return((char *)getenv("USER"));
- X#endif /* VMS */
- X}
- X
- X/* md_sleep:
- X *
- X * This routine causes the game to pause for the specified number of
- X * seconds.
- X *
- X * This routine is not necessary at all, and can be stubbed with no ill
- X * effects.
- X */
- X
- Xmd_sleep(nsecs)
- Xint nsecs;
- X{
- X (void) sleep(nsecs);
- X}
- X
- X/* md_getenv()
- X *
- X * This routine gets certain values from the user's environment. These
- X * values are strings, and each string is identified by a name. The names
- X * of the values needed, and their use, is as follows:
- X *
- X * TERMCAP
- X * The name of the users's termcap file, NOT the termcap entries
- X * themselves. This is used ONLY if the program is compiled with
- X * CURSES defined (-DCURSES). Even in this case, the program need
- X * not find a string for TERMCAP. If it does not, it will use the
- X * default termcap file as returned by md_gdtcf();
- X * TERM
- X * The name of the users's terminal. This is used ONLY if the program
- X * is compiled with CURSES defined (-DCURSES). In this case, the string
- X * value for TERM must be found, or the routines in curses.c cannot
- X * function, and the program will quit.
- X * ROGUEOPTS
- X * A string containing the various game options. This need not be
- X * defined.
- X * HOME
- X * The user's home directory. This is only used when the user specifies
- X * '~' as the first character of a saved-game file. This string need
- X * not be defined.
- X *
- X * If your system does not provide a means of searching for these values,
- X * you will have to do it yourself. None of the values above really need
- X * to be defined except TERM when the program is compiled with CURSES
- X * defined. In this case, as a bare minimum, you can check the 'name'
- X * parameter, and if it is "TERM" find the terminal name and return that,
- X * else return zero. If the program is not compiled with CURSES, you can
- X * get by with simply always returning zero. Returning zero indicates
- X * that their is no defined value for the given string.
- X */
- X
- Xchar *
- Xmd_getenv(name)
- Xchar *name;
- X{
- X#ifdef UNIX
- X char *value;
- X char *getenv();
- X
- X value = getenv(name);
- X
- X return(value);
- X#endif /* UNIX */
- X#ifdef VMS
- X return((char *)getenv(name));
- X#endif /* VMS */
- X}
- X
- X/* md_malloc()
- X *
- X * This routine allocates, and returns a pointer to, the specified number
- X * of bytes. This routines absolutely MUST be implemented for your
- X * particular system or the program will not run at all. Return zero
- X * when no more memory can be allocated.
- X */
- X
- Xchar *
- Xmd_malloc(n)
- Xint n;
- X{
- X char *malloc();
- X char *t;
- X
- X t = malloc(n);
- X return(t);
- X}
- X
- X/* md_gseed() (Get Seed)
- X *
- X * This function returns a seed for the random number generator (RNG). This
- X * seed causes the RNG to begin generating numbers at some point in it's
- X * sequence. Without a random seed, the RNG will generate the same set
- X * of numbers, and every game will start out exactly the same way. A good
- X * number to use is the process id, given by getpid() on most UNIX systems.
- X *
- X * You need to find some single random integer, such as:
- X * process id.
- X * current time (minutes + seconds) returned from md_gct(), if implemented.
- X *
- X * It will not help to return "get_rand()" or "rand()" or the return value of
- X * any pseudo-RNG. If you don't have a random number, you can just return 1,
- X * but this means your games will ALWAYS start the same way, and will play
- X * exactly the same way given the same input.
- X */
- X
- Xmd_gseed()
- X{
- X return((time((time_t *)0) & ~((int)0)) + getpid());
- X}
- X
- X/* md_exit():
- X *
- X * This function causes the program to discontinue execution and exit.
- X * This function must be implemented or the program will continue to
- X * hang when it should quit.
- X */
- X
- Xmd_exit(status)
- Xint status;
- X{
- X exit(status);
- X}
- X
- X/* If you have a viable curses/termlib library, then use it and don't bother
- X * implementing the routines below. And don't compile with -DCURSES.
- X */
- X
- X#ifdef CURSES
- X
- X/* md_cbreak_no_echo_nonl:
- X *
- X * This routine sets up some terminal characteristics. The tty-driver
- X * must be told to:
- X * 1.) Not echo input.
- X * 2.) Transmit input characters immediately upon typing. (cbreak mode)
- X * 3.) Move the cursor down one line, without changing column, and
- X * without generating a carriage-return, when it
- X * sees a line-feed. This is only necessary if line-feed is ever
- X * used in the termcap 'do' (cursor down) entry, in which case,
- X * your system should must have a way of accomplishing this.
- X *
- X * When the parameter 'on' is true, the terminal is set up as specified
- X * above. When this parameter is false, the terminal is restored to the
- X * original state.
- X *
- X * Raw mode should not to be used. Keyboard signals/events/interrupts should
- X * be sent, although they are not strictly necessary. See notes in
- X * md_heed_signals().
- X *
- X * This function must be implemented for rogue to run properly if the
- X * program is compiled with CURSES defined to use the enclosed curses
- X * emulation package. If you are not using this, then this routine is
- X * totally unnecessary.
- X *
- X * Notice that information is saved between calls. This is used to
- X * restore the terminal to an initial saved state.
- X *
- X */
- X
- Xmd_cbreak_no_echo_nonl(on)
- Xboolean on;
- X{
- X#ifdef UNIX
- X#ifdef UNIX_BSD4_2
- X static struct sgttyb tty_buf;
- X static int tsave_flags;
- X
- X if (on) {
- X ioctl(0, TIOCGETP, &tty_buf);
- X tsave_flags = tty_buf.sg_flags;
- X tty_buf.sg_flags |= CBREAK;
- X tty_buf.sg_flags &= ~(ECHO | CRMOD); /* CRMOD: see note 3 above */
- X ioctl(0, TIOCSETP, &tty_buf);
- X } else {
- X tty_buf.sg_flags = tsave_flags;
- X ioctl(0, TIOCSETP, &tty_buf);
- X }
- X#endif /* UNIX_BSD4_2 */
- X#ifdef UNIX_SYSV
- X struct termio tty_buf;
- X static struct termio tty_save;
- X
- X if (on) {
- X ioctl(0, TCGETA, &tty_buf);
- X tty_save = tty_buf;
- X tty_buf.c_lflag &= ~(ICANON | ECHO);
- X tty_buf.c_oflag &= ~ONLCR;
- X tty_buf.c_cc[4] = 1; /* MIN */
- X tty_buf.c_cc[5] = 2; /* TIME */
- X ioctl(0, TCSETAF, &tty_buf);
- X } else {
- X ioctl(0, TCSETAF, &tty_save);
- X }
- X#endif /* UNIX_SYSV */
- X#endif /* UNIX */
- X#ifdef VMS
- X if (on)
- X tt_init();
- X else
- X tt_fini();
- X#endif /* VMS */
- X}
- X
- X/* md_gdtcf(): (Get Default Termcap File)
- X *
- X * This function is called ONLY when the program is compiled with CURSES
- X * defined. If you use your system's curses/termlib library, this function
- X * won't be called. On most UNIX systems, "/etc/termcap" suffices.
- X *
- X * If their is no such termcap file, then return 0, but in that case, you
- X * must have a TERMCAP file returned from md_getenv("TERMCAP"). The latter
- X * will override the value returned from md_gdtcf(). If the program is
- X * compiled with CURSES defined, and md_gdtcf() returns 0, and
- X * md_getenv("TERMCAP") returns 0, the program will have no terminal
- X * capability information and will quit.
- X */
- X
- Xchar *
- Xmd_gdtcf()
- X{
- X#ifdef UNIX
- X return("/etc/termcap");
- X#endif /* UNIX */
- X#ifdef VMS
- X return(getenv("TERMCAP"));
- X#endif /* VMS */
- X}
- X
- X/* md_tstp():
- X *
- X * This function puts the game to sleep and returns to the shell. This
- X * only applies to UNIX 4.2 and 4.3. For other systems, the routine should
- X * be provided as a do-nothing routine. md_tstp() will only be referenced
- X * in the code when compiled with CURSES defined.
- X *
- X */
- X
- Xmd_tstp()
- X{
- X#ifdef UNIX_BSD4_2
- X kill(0, SIGTSTP);
- X#endif /* UNIX_BSD4_2 */
- X}
- X
- X#endif /* CURSES */
- END_OF_FILE
- if test 17495 -ne `wc -c <'machdep.c'`; then
- echo shar: \"'machdep.c'\" unpacked with wrong size!
- fi
- # end of 'machdep.c'
- fi
- if test -f 'vmsterm.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vmsterm.c'\"
- else
- echo shar: Extracting \"'vmsterm.c'\" \(5996 characters\)
- sed "s/^X//" >'vmsterm.c' <<'END_OF_FILE'
- X#ifdef VMS
- X
- X
- X/*
- X * VMSTERM.C
- X *
- X * Copyright (c) 1991 by Michael S Zraly.
- X *
- X * Some of the details in this code were derived from code
- X * for the games larn, copyright 1986 by Noah Morgan (as
- X * adapted by Kevin Routley), and nethack, copyright 1985
- X * by the Stichting Mathematisch centrum, Amsterdam.
- X *
- X * Permission is granted to distribute and modify this source
- X * Permission is granted to distribute and modify this source
- X * freely, provided that no charge is made for doing so and
- X * that this comment remains untouched.
- X *
- X * Last Modified: 21 August 1991
- X */
- X
- X
- X#include <descrip.h>
- X#include "vmsterm.h"
- X
- X
- X#define TT_BUFSIZ 80
- X
- X
- X/*
- X * I/o func codes passed to SYS$QIO() or SYS$QIOW():
- X */
- X#define TT_NOPURGE (IO$_READLBLK|IO$M_NOFILTR|IO$M_TIMED|IO$M_NOECHO)
- X#define TT_PURGE ((TT_NOPURGE)|(IO$M_PURGE))
- X
- X
- X/*
- X * Default terminal characteristics
- X */
- X#define TT_TTDEFS (TT$M_MECHTAB|TT$M_MECHFORM|TT$M_NOECHO)
- X#define TT_TT2DEFS (TT2$M_PASTHRU)
- X
- X
- X/*
- X * Macro functions to get and
- X * set terminal characteristics
- X */
- X#define tt_getmode(iosb_s,ttbuf) \
- X ( ((SYS$QIOW(0, tt_chan(), IO$_SENSEMODE, &(iosb_s), \
- X (void(*)())0, 0, &(ttbuf), sizeof(ttbuf), 0, 0, 0, 0) \
- X & SS$_NORMAL) == 0) ? TT_FAILURE : TT_SUCCESS )
- X
- X#define tt_setmode(iosb_s,ttbuf) \
- X ( ((SYS$QIOW(0, tt_chan(), IO$_SETMODE, &(iosb_s), \
- X (void(*)())0, 0, &(ttbuf), sizeof(ttbuf), 0, 0, 0, 0) \
- X & SS$_NORMAL) == 0) ? TT_FAILURE : TT_SUCCESS )
- X
- X
- X/*
- X * Private (static) variables
- X */
- Xstatic int _io_on = 0; /* between tt_init & tt_fini */
- Xstatic int _io_pu = 0; /* purge typeahead on next read */
- Xstatic int _iochan = 0; /* channel for i/o */
- Xstatic IOSB_S _iosb;
- Xstatic TTBUF _ttbuf_old;
- Xstatic TTBUF _ttbuf_new;
- X
- X
- X/*
- X - (static) tt_getchannel :
- X */
- Xstatic int tt_getchannel ()
- X{
- X struct dsc$descriptor_s iodsc;
- X
- X if (_iochan > 0)
- X return TT_SUCCESS; /* already assigned channel */
- X
- X iodsc.dsc$w_length = sizeof("TT:")-1;
- X iodsc.dsc$b_dtype = DSC$K_DTYPE_T;
- X iodsc.dsc$b_class = DSC$K_CLASS_S;
- X iodsc.dsc$a_pointer = "TT:";
- X
- X if ((SYS$ASSIGN (&iodsc, &_iochan, 0, 0) & SS$_NORMAL) == 0)
- X return TT_FAILURE;
- X
- X return TT_SUCCESS;
- X}
- X
- X
- X/*
- X - (static) tt_freechannel :
- X */
- Xstatic int tt_freechannel ()
- X{
- X int status;
- X
- X if (_iochan == 0)
- X return TT_SUCCESS; /* channel not assigned */
- X
- X status = SYS$DASSGN (_iochan);
- X
- X _iochan = 0;
- X
- X if ((status & SS$_NORMAL) == 0)
- X return TT_FAILURE;
- X
- X return TT_SUCCESS;
- X}
- X
- X
- X/*
- X - (static) vms_read :
- X */
- Xstatic int vms_read (char *buffer, int size, int timeout)
- X{
- X int code;
- X int status;
- X IOSB_R iostab;
- X static int tt_terms[2] = { 0, 0 };
- X
- X if (_io_pu == 1)
- X code = TT_PURGE;
- X else
- X code = TT_NOPURGE;
- X
- X _io_pu = 0;
- X
- X status = SYS$QIOW (0, _iochan, code,
- X &iostab, (void(*)())0, 0,
- X buffer, size, timeout, tt_terms, 0, 0);
- X
- X if (status == SS$_TIMEOUT)
- X return TT_TIMEOUT;
- X
- X if (status != SS$_NORMAL)
- X return TT_ERROR;
- X
- X if ((status = iostab.term_offset + iostab.term_size) > 0)
- X return status;
- X
- X return TT_TIMEOUT;
- X}
- X
- X
- X/*
- X - tt_chan :
- X */
- Xint tt_chan ()
- X{
- X if (_iochan == 0)
- X (void) tt_getchannel();
- X
- X return _iochan;
- X}
- X
- X
- X/*
- X - tt_init :
- X */
- Xint tt_init ()
- X{
- X if (_io_on == 1)
- X return TT_SUCCESS;
- X
- X if (tt_getchannel() == TT_FAILURE)
- X return TT_FAILURE;
- X
- X if (tt_getmode(_iosb, _ttbuf_old) == TT_FAILURE)
- X return TT_FAILURE;
- X
- X if (tt_getmode(_iosb, _ttbuf_new) == TT_FAILURE)
- X return TT_FAILURE;
- X
- X _ttbuf_new.ttchar |= TT_TTDEFS;
- X _ttbuf_new.tt2char |= TT_TT2DEFS;
- X
- X if (tt_setmode(_iosb, _ttbuf_new) == TT_FAILURE) {
- X (void) tt_fini ();
- X return TT_FAILURE;
- X }
- X
- X if (atexit(tt_fini) != 0) {
- X (void) tt_fini ();
- X return TT_FAILURE;
- X }
- X
- X _io_on = 1;
- X return TT_SUCCESS;
- X}
- X
- X
- X/*
- X - tt_getc :
- X */
- Xint tt_getc ()
- X{
- X int incount;
- X static char buffer[TT_BUFSIZ];
- X static char *bufptr = buffer;
- X static char *bufend = buffer;
- X
- X /*
- X * If io not initialized, do so.
- X */
- X
- X if (_io_on == 0)
- X if (tt_init() == TT_FAILURE)
- X return TT_ERROR;
- X
- X /*
- X * First call to vms_read reads any leftover
- X * characters from operating system's read
- X * buffer -- it should return TIMEOUT. Then
- X * call again and again until a character
- X * is successfully read.
- X */
- X
- X if (bufptr >= bufend) {
- X bufptr = bufend = buffer;
- X incount = vms_read (buffer, TT_BUFSIZ, 0);
- X while (incount < TT_SUCCESS)
- X incount = vms_read (buffer, 1, 2);
- X bufend = &buffer[incount];
- X }
- X
- X /*
- X * If escape was read, call vms_read with
- X * timeout 0 to read all characters in the
- X * escape sequence.
- X */
- X
- X if (*bufptr == '\033') {
- X char junk[80];
- X
- X (void) vms_read(junk, 80, 0);
- X bufptr = bufend = buffer;
- X
- X return '\033';
- X }
- X
- X *bufend = '\0';
- X
- X return (*bufptr++ & 0177);
- X}
- X
- X
- X/*
- X - tt_flush :
- X */
- Xvoid tt_flush ()
- X{
- X /*
- X * Alternatively we could call vms_read with 0 timeout
- X * until no more characters are available, i.e.
- X *
- X * char ch;
- X *
- X * while (vms_read(&ch, 1, 0) > TT_FAILURE)
- X * ;
- X *
- X * Hopefully the final vms_read() will return TT_TIMEOUT
- X */
- X _io_pu = 1;
- X return;
- X}
- X
- X
- X/*
- X - tt_fini :
- X */
- Xvoid tt_fini ()
- X{
- X if (_io_on == 0)
- X return;
- X
- X (void) tt_setmode (_iosb, _ttbuf_old);
- X
- X /*
- X * De-assign io channel.
- X */
- X
- X (void) tt_freechannel ();
- X
- X _io_on = 0;
- X return;
- X}
- X
- X
- X/*
- X - tt_speed :
- X */
- Xint tt_speed ()
- X{
- X if (_io_on == 0)
- X if (tt_init() == TT_FAILURE)
- X return TT_ERROR;
- X
- X if (_iosb.ospeed < BAUD_MIN || _iosb.ospeed > BAUD_MAX)
- X return TT_FAILURE;
- X else
- X return _iosb.ospeed;
- X}
- X
- X
- X/*
- X - tt_cols :
- X */
- Xint tt_cols ()
- X{
- X if (_io_on == 0)
- X if (tt_init() == TT_FAILURE)
- X return TT_ERROR;
- X
- X if (_ttbuf_new.cols > 0)
- X return _ttbuf_new.cols;
- X
- X return TT_ERROR;
- X}
- X
- X
- X/*
- X - tt_rows :
- X */
- Xint tt_rows ()
- X{
- X if (_io_on == 0)
- X if (tt_init() == TT_FAILURE)
- X return TT_ERROR;
- X
- X if (_ttbuf_new.rows > 0)
- X return _ttbuf_new.rows;
- X
- X return TT_ERROR;
- X}
- X
- X
- X/*
- X - tt_shell :
- X */
- Xvoid tt_shell ()
- X{
- X long status;
- X struct dsc$descriptor_s dsc;
- X
- X dsc.dsc$w_length = sizeof("")-1;
- X dsc.dsc$b_dtype = DSC$K_DTYPE_T;
- X dsc.dsc$b_class = DSC$K_CLASS_S;
- X dsc.dsc$a_pointer = "";
- X
- X (void) LIB$SPAWN (&dsc, 0, 0, 0, 0, 0, &status, 0, 0, 0, 0, 0);
- X
- X return;
- X}
- X#endif /* VMS */
- END_OF_FILE
- if test 5996 -ne `wc -c <'vmsterm.c'`; then
- echo shar: \"'vmsterm.c'\" unpacked with wrong size!
- fi
- # end of 'vmsterm.c'
- fi
- if test -f 'vmsterm.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vmsterm.h'\"
- else
- echo shar: Extracting \"'vmsterm.h'\" \(3313 characters\)
- sed "s/^X//" >'vmsterm.h' <<'END_OF_FILE'
- X#ifndef __VMSTERM_LOADED
- X#define __VMSTERM_LOADED 1
- X#ifdef VMS
- X
- X
- X/*
- X * VMSTERM.H
- X *
- X * Copyright (c) 1991 by Michael S Zraly.
- X *
- X * Some of the details in this code were derived from code
- X * for the games larn, copyright 1986 by Noah Morgan (as
- X * adapted by Kevin Routley), and nethack, copyright 1985
- X * by the Stichting Mathematisch centrum, Amsterdam.
- X *
- X * Permission is granted to distribute and modify this source
- X * freely, provided that no charge is made for doing so and
- X * that this comment remains untouched.
- X *
- X * Last Modified: 21 August 1991
- X */
- X
- X
- X#include <iodef.h>
- X#include <ssdef.h>
- X#include <ttdef.h>
- X#include <tt2def.h>
- X
- X
- X/*
- X * Return codes:
- X */
- X#define TT_SUCCESS 1
- X#define TT_FAILURE 0
- X#define TT_ERROR (-1)
- X#define TT_TIMEOUT (-2)
- X
- X
- X/*
- X * These speed codes are for compatability with BSD UNIX
- X */
- X#define B0 (-1) /* no VMS equivalent */
- X#define B50 TT$C_BAUD_50
- X#define B75 TT$C_BAUD_75
- X#define B110 TT$C_BAUD_110
- X#define B134 TT$C_BAUD_134
- X#define B150 TT$C_BAUD_150
- X#define B200 B150 /* no VMS equivalent */
- X#define B300 TT$C_BAUD_300
- X#define B600 TT$C_BAUD_600
- X#define B1200 TT$C_BAUD_1200
- X#define B1800 TT$C_BAUD_1800
- X#define B2000 TT$C_BAUD_2000 /* no BSD equivalent */
- X#define B2400 TT$C_BAUD_2400
- X#define B3600 TT$C_BAUD_3600 /* no BSD equivalent */
- X#define B4800 TT$C_BAUD_4800
- X#define B7200 TT$C_BAUD_7200 /* no BSD equivalent */
- X#define B9600 TT$C_BAUD_9600
- X#define B19200 TT$C_BAUD_19200 /* no BSD equivalent */
- X#define B38400 TT$C_BAUD_38400 /* no BSD equivalent */
- X#define EXTA B50 /* no VMS equivalent */
- X#define EXTB B50 /* no VMS equivalent */
- X
- X#define BAUD_MIN B50
- X#define BAUD_MAX B38400
- X
- X
- X/*
- X * This is the i/o status block structure returned from
- X * an IO$_READxBLK call to SYS$QIO() or SYS$QIOW().
- X */
- Xtypedef struct {
- X unsigned status : 16;
- X unsigned term_offset : 16;
- X unsigned terminator : 16;
- X unsigned term_size : 16;
- X} IOSB_R;
- X
- X
- X/*
- X * This is the i/o status block structure returned from
- X * an IO$_SENSEMODE or IO$_SETMODE call to SYS$QIO() or
- X * SYS$QIOW().
- X */
- Xtypedef struct {
- X unsigned status : 16;
- X unsigned ospeed : 8;
- X unsigned ispeed : 8;
- X unsigned cr_fill : 8;
- X unsigned lf_fill : 8;
- X unsigned parity : 8;
- X unsigned unused : 8;
- X} IOSB_S;
- X
- X
- X/*
- X * This is the structure describing terminal characteristics
- X * passed as the P1 argument in an IO$_SENSEMODE or IO$_SET-
- X * MODE call to SYS$QIO() or SYS$QIOW().
- X */
- Xtypedef struct {
- X unsigned class : 8;
- X unsigned type : 8;
- X unsigned cols : 16;
- X unsigned ttchar : 24; /* see <ttdef.h> */
- X unsigned rows : 8;
- X unsigned tt2char : 32; /* see <tt2def.h> */
- X} TTBUF;
- X
- X
- X/*
- X * Macro functions to get and
- X * set terminal characteristics
- X */
- X#define tt_getmode(iosb_s,ttbuf) \
- X ( ((SYS$QIOW(0, tt_chan(), IO$_SENSEMODE, &(iosb_s), \
- X (void(*)())0, 0, &(ttbuf), sizeof(ttbuf), 0, 0, 0, 0) \
- X & SS$_NORMAL) == 0) ? TT_FAILURE : TT_SUCCESS )
- X
- X#define tt_setmode(iosb_s,ttbuf) \
- X ( ((SYS$QIOW(0, tt_chan(), IO$_SETMODE, &(iosb_s), \
- X (void(*)())0, 0, &(ttbuf), sizeof(ttbuf), 0, 0, 0, 0) \
- X & SS$_NORMAL) == 0) ? TT_FAILURE : TT_SUCCESS )
- X
- X
- X/*
- X * Prototypes:
- X */
- Xint tt_chan();
- Xint tt_init();
- Xint tt_getc();
- Xvoid tt_flush();
- Xvoid tt_fini();
- Xint tt_speed();
- Xint tt_cols();
- Xint tt_rows();
- Xvoid tt_shell();
- X
- X
- X#endif /* VMS */
- X#endif /* __VMSTERM_LOADED */
- END_OF_FILE
- if test 3313 -ne `wc -c <'vmsterm.h'`; then
- echo shar: \"'vmsterm.h'\" unpacked with wrong size!
- fi
- # end of 'vmsterm.h'
- fi
- echo shar: End of shell archive.
- exit 0
-