home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource3
/
136_01
/
tz1.c
< prev
next >
Wrap
Text File
|
1979-12-31
|
23KB
|
1,176 lines
/* HEADER: CUG136.20;
TITLE: TZ;
VERSION: 0.29;
DATE: 3/12/1986;
DESCRIPTION: "Twilight Zone Adventure Game (part 1)";
KEYWORDS: game,adventure;
SYSTEM: CP/M,MS-DOS,TOS;
FILENAME: TZ1.C;
AUTHORS: R. Rodman;
COMPILERS: C/80,Aztec,Alcyon;
*/
/* TWILIGHT ZONE GAME
TZ1.C - First half
From 810717 (original assembler version) to 830125 in Z80 assembler.
831025 rr begin conversion to C 0.10
831101 rr dictionary in room file 0.13
831104 rr add terminal file stuff 0.14
850412 rr mods for ibm 0.21
850429 rr for unbuf,use open returns int; for buf,use fopen
returns FILE (Aztec) 0.24
850430 rr try allocating buffer for Aztec 0.25
850521 rr try to fix messed-up message 0.27
860228 rr fix \n for cp/m 0.28
860311 rr split into two parts 0.29
add type to fopen
860312 rr st stuff
Version number is currently not displayed anywhere
NOTE: The alloc() function does not work on the Atari ST. To simplify
our lives, I don't use it.
The IBM switch is only known to work with the AZTEC compiler.
*/
/* #define IBM */ /* define this for IBM INT 10 screen control */
#define TERMINAL /* define this for TERMINAL.SYS */
/* #define AZTEC */ /* define this for Aztec C compiler */
/* #define C80 */ /* define this for C/80 */
#define DRI /* define this for DRI C */
#define ST /* define this (and DRI?) for Atari ST */
#ifdef C80
#define DOS bdos
#endif
#ifdef AZTEC
#include "stdio.h"
#include "fcntl.h"
#define DOS bdos
#endif
#ifdef DRI
#include "stdio.h"
#define DOS __BDOS
#endif
#ifdef ST
#include "osbind.h"
#endif
#define BUFSIZE 30000
int cnt,i;
char *room[ 256 ]; /* rooms */
char *wlk_msg[ 24 ]; /* points to walker messages */
char inp_buf[ 34 ]; /* input buffer */
int inp_cnt = 0; /* input buffer pointer */
#ifdef TERMINAL
#define BYTE char
#define ESC '\033'
struct { /* terminal file structure */
BYTE width, height, defint, uselst, yfirst, method, addx, addy;
char inistr[ 8 ], clrscn[ 8 ], clreos[ 8 ], clreol[ 8 ];
char curoff[ 8 ], curon[ 8 ], curbeg[ 8 ], curmid[ 8 ];
char curend[ 8 ], hiint[ 8 ], loint[ 8 ], revvid[ 8 ];
char norvid[ 8 ], inslin[ 8 ], dellin[ 8 ];
} trmbuf = {
#ifdef ST
/* Values for ST or Heath terminals */
80, 24, 'H', 'Y', 'Y', '0', 32, 32,
0, 0, 0, 0, 0, 0, 0, 0, /* inistr */
ESC, 'E', 0, 0, 0, 0, 0, 0, /* clrscn */
ESC, 'J', 0, 0, 0, 0, 0, 0, /* clreos */
ESC, 'K', 0, 0, 0, 0, 0, 0, /* clreol */
ESC, 'x', '5', 0, 0, 0, 0, 0, /* curoff */
ESC, 'y', '5', 0, 0, 0, 0, 0, /* curon */
ESC, 'Y', 0, 0, 0, 0, 0, 0, /* curbeg */
0, 0, 0, 0, 0, 0, 0, 0, /* curmid */
0, 0, 0, 0, 0, 0, 0, 0, /* curend */
0, 0, 0, 0, 0, 0, 0, 0, /* hiint */
0, 0, 0, 0, 0, 0, 0, 0, /* loint */
ESC, 'p', 0, 0, 0, 0, 0, 0, /* revvid */
ESC, 'q', 0, 0, 0, 0, 0, 0, /* norvid */
ESC, 'L', 0, 0, 0, 0, 0, 0, /* inslin */
ESC, 'M', 0, 0, 0, 0, 0, 0 /* dellin */
#endif
#ifndef ST
/* Values for Televideoid terminals */
80, 24, 'H', 'Y', 'Y', '0', 32, 32,
0, 0, 0, 0, 0, 0, 0, 0, /* inistr */
'\032', 0, 0, 0, 0, 0, 0, 0, /* clrscn */
ESC, 'Y', 0, 0, 0, 0, 0, 0, /* clreos */
ESC, 'T', 0, 0, 0, 0, 0, 0, /* clreol */
ESC, '.', '0', 0, 0, 0, 0, 0, /* curoff */
ESC, '.', '2', 0, 0, 0, 0, 0, /* curon */
ESC, '=', 0, 0, 0, 0, 0, 0, /* curbeg */
0, 0, 0, 0, 0, 0, 0, 0, /* curmid */
0, 0, 0, 0, 0, 0, 0, 0, /* curend */
ESC, '(', 0, 0, 0, 0, 0, 0, /* hiint */
ESC, ')', 0, 0, 0, 0, 0, 0, /* loint */
ESC, 'G', '4', 0, 0, 0, 0, 0, /* revvid */
ESC, 'G', '0', 0, 0, 0, 0, 0, /* norvid */
ESC, 'R', 0, 0, 0, 0, 0, 0, /* inslin */
ESC, 'E', 0, 0, 0, 0, 0, 0 /* dellin */
#endif
};
#endif
#ifdef IBM
struct {
int width, height;
} trmbuf = {
80, 25
};
#endif
/* Dictionary: words should be strung together,separated by spaces.
Only the unique part should be included.Contained in first line
of TZ.R.Every word including the last one must be followed by spaces.
Incidentally,all lines of TZ.R should be terminated only by
line feeds.*/
char *dic_ptr;
/* Controls used in messages are:
* clear screen
^ position cursor to message line (causes CEOL)
\ carriage return/line feed (causes CEOL)
| position cursor to user input line (HEIGHT-2)
_ include answer here (e.g._4)
*/
/* The following pieces of information must be saved */
int rm_num = 0; /* room number */
int seed; /* random seed */
int wtchct = 0; /* tv watch count */
int beerct = 0; /* drink beer count */
int cratct = 0; /* open crate count */
int pushct = 0; /* push button count */
int pushfl = 0; /* push button error flag */
int answer[ 5 ] = { 0,1,2,3,4 }; /* digits of answer */
struct walker {
int inrm; /* in room flag */
int rsel; /* room pointer */
int dsel; /* description selector */
int locn[ 8 ]; /* rooms walker appears at */
};
/* Woman walker descriptor */
struct walker woman = {
0,0,0,
4,52,64,95,109,185,204,248 };
/* Man walker descriptor */
struct walker man = {
0,0,0,
3,49,97,105,111,144,166,175 };
/* Rod walker descriptor */
struct walker rod = {
0,0,0,
1,27,61,120,165,196,180,254 };
/* The following are not saved */
int nu_fl = 1; /* new room flag */
int curcol = 0; /* cursor column */
int noun, verb; /* word numbers */
char databuf[ BUFSIZE ]; /* statically allocated buffer */
extern hello();
extern exbed(), pool(), echh(), busy(), call7(), call11(), sign(), book();
extern opsafe(), dlcomb(), paper(), form(), blot(), seeslf(), seecow();
extern mirhse(), menu(), drwatr(), excrat(), opcrat(), writing();
extern inst(), buyber(), drbeer(), ridhor(), taktrn(), taknot(), plates();
extern opgrat(), examtv(), wtchtv(), exhand(), push();
char xgetc();
/* Main Program */
main()
{
int junk;
term_init(); /* init terminal */
hello();
/* initialize data */
init_data();
xputs( "\n\n?Dimensions out of range at address 1423" );
junk = 0;
seed = 719;
while( junk == 0 ) {
junk = xgetc();
seed = seed * 13;
}
/* synthesize solution from random number into answer[ 0..4 ] */
if( seed < 0 ) seed = 0 - seed; /* get abs value */
answer[ 0 ] = seed % 5;
answer[ 1 ] = ( seed / 5 ) % 5;
answer[ 2 ] = ( seed / 25 ) % 5;
answer[ 3 ] = ( seed / 125 ) % 5;
answer[ 4 ] = ( seed / 625 ) % 5;
while( 1 ) {
game(); /* process game */
input(); /* get input */
}
}
#ifdef TERMINAL
/* --------TERMINAL FILE LOGIC-------- */
term_init()
{
int t;
#ifdef C80
t = fopen( "TERMINAL.SYS","r" );
#endif
#ifdef AZTEC
t = open( "TERMINAL.SYS", O_RDONLY );
#endif
#ifdef DRI
t = open( "TERMINAL.SYS", 0 );
#endif
if( t == 0 ) return; /* default to televideoid */
read( t, &trmbuf, 128 );
#ifdef C80
fclose( t );
#endif
#ifdef AZTEC
close( t );
#endif
#ifdef DRI
close( t );
#endif
}
/* output a coordinate */
coord( c )
int c;
{
switch( trmbuf.method ) {
case 0 :
case '0' :
case 'B' : /* binary positioning */
xputc( c ); break;
case 1 :
case '1' :
case 'A' : /* ascii positioning */
if( c >= 100 ) {
xputc( '0' + c / 100 );
c %= 100;
}
if( c >= 10 ) {
xputc( '0' + c / 10 );
c %= 10;
}
xputc( '0' + c );
}
}
/* position cursor */
goxy( x, y )
int x, y;
{
xputs( trmbuf.curbeg );
if( trmbuf.yfirst == 'Y' ) coord( y + trmbuf.addy );
else coord( x + trmbuf.addx );
xputs( trmbuf.curmid );
if( trmbuf.yfirst == 'Y' ) coord( x + trmbuf.addx );
else coord( y + trmbuf.addy );
xputs( trmbuf.curend );
}
cls()
{
xputs( trmbuf.clrscn );
}
ceol()
{
xputs( trmbuf.clreol );
}
high()
{
xputs( trmbuf.hiint );
}
low()
{
xputs( trmbuf.loint );
}
reverse()
{
xputs( trmbuf.revvid );
}
normal()
{
xputs( trmbuf.norvid );
}
#endif /* --------END OF TERMINAL FILE LOGIC-------- */
#ifdef IBM
/* --------IBM SCREEN LOGIC-------- */
term_init()
{
}
cls()
{
#asm
mov ah,0 ;subfunction - set display mode
mov al,2 ;set mode to 80x25 bw
int 10H
#endasm
}
goxy(