-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMACH_DEP.C
281 lines (252 loc) · 4.9 KB
/
MACH_DEP.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
* Various installation dependent routines
*
* mach_dep.c 1.4 (A.I. Design) 12/1/84
*/
#include "rogue.h"
#include "curses.h"
#include "keypad.h"
#define ULINE() if(is_color) lmagenta();else uline();
#define TICK_ADDR 0x70
static int clk_vec[2];
static int ocb;
/*
* setup:
* Get starting setup for all games
*/
setup()
{
terse = FALSE;
maxrow = 23;
if (COLS == 40) {
maxrow = 22;
terse = TRUE;
}
expert = terse;
/*
* Vector CTRL-BREAK to call quit()
*/
COFF();
ocb = set_ctrlb(0);
}
clock_on()
{
extern int _csval, clock(), (*cls_)(), no_clock();
int new_vec[2];
new_vec[0] = clock;
new_vec[1] = _csval;
dmain(clk_vec, 2, 0, TICK_ADDR);
dmaout(new_vec, 2, 0, TICK_ADDR);
cls_ = no_clock;
}
no_clock()
{
dmaout(clk_vec, 2, 0, TICK_ADDR);
}
/*
* returns a seed for a random number generator
*/
srand()
{
#ifdef DEBUG
return ++dnum;
#else
/*
* Get Time
*/
bdos(0x2C);
return(regs->cx + regs->dx);
#endif
}
/*
* flush_type:
* Flush typeahead for traps, etc.
*/
flush_type()
{
#ifdef CRASH_MACHINE
regs->ax = 0xc06; /* clear keyboard input */
regs->dx = 0xff; /* set input flag */
swint(SW_DOS, regs);
#endif CRASH_MACHINE
typeahead = "";
}
credits()
{
int i;
char tname[25];
cursor(FALSE);
clear();
if (is_color)
brown();
box(0,0,LINES-1,COLS-1);
bold();
center(2,"ROGUE: The Adventure Game");
ULINE();
center(4,"The game of Rogue was designed by:");
high();
center(6,"Michael Toy and Glenn Wichman");
ULINE();
center(9,"Various implementations by:");
high();
center(11,"Ken Arnold, Jon Lane and Michael Toy");
ULINE();
#ifdef INTL
center(14,"International Versions by:");
#else
center(14,"Adapted for the IBM PC by:");
#endif
high();
#ifdef INTL
center(16,"Mel Sibony");
#else
center(16,"A.I. Design");
#endif
ULINE();
if (is_color)
yellow();
center(19,"(C)Copyright 1985");
high();
#ifdef INTL
center(20,"AI Design");
#else
center(20,"Epyx Incorporated");
#endif
standend();
if (is_color)
yellow();
center(21,"All Rights Reserved");
if (is_color)
brown();
for(i=1;i<(COLS-1);i++) {
move(22,i);
putchr(205);
}
mvaddch(22,0,204);
mvaddch(22,COLS-1,185);
standend();
mvaddstr(23,2,"Rogue's Name? ");
is_saved = TRUE; /* status line hack */
high();
getinfo(tname,23);
if (*tname && *tname != ESCAPE)
strcpy(whoami, tname);
is_saved = FALSE;
blot_out(23,0,24,COLS-1);
if (is_color)
brown();
mvaddch(22,0,0xc8);
mvaddch(22,COLS-1,0xbc);
standend();
}
/*
* Table for IBM extended key translation
*/
static struct xlate {
byte keycode, keyis;
} xtab[] = {
C_HOME, 'y', C_UP, 'k', C_PGUP,'u', C_LEFT, 'h', C_RIGHT, 'l',
C_END, 'b', C_DOWN,'j', C_PGDN,'n', C_INS, '>', C_DEL, 's',
C_F1, '?', C_F2, '/', C_F3, 'a', C_F4, CTRL(R), C_F5, 'c',
C_F6, 'D', C_F7, 'i', C_F8, '^', C_F9, CTRL(F), C_F10, '!',
ALT_F9, 'F'
};
/*
* readchar:
* Return the next input character, from the macro or from the keyboard.
*/
readchar()
{
register struct xlate *x;
register byte ch;
if (*typeahead) {
SIG2();
return(*typeahead++);
}
/*
* while there are no characters in the type ahead buffer
* update the status line at the bottom of the screen
*/
do
SIG2(); /* Rogue spends a lot of time here */
while (no_char());
/*
* Now read a character and translate it if it appears in the
* translation table
*/
for (ch = getch(), x = xtab; x < xtab + (sizeof xtab) / sizeof *xtab; x++)
if (ch == x->keycode) {
ch = x->keyis;
break;
}
if (ch == ESCAPE)
count = 0;
return ch;
}
bdos(fnum, dxval)
int fnum, dxval;
{
register struct sw_regs *saveptr;
regs->ax = fnum << 8;
regs->bx = regs->cx = 0;
regs->dx = dxval;
saveptr = regs;
swint(SW_DOS,regs);
regs = saveptr;
return(0xff & regs->ax);
}
/*
* newmem - memory allocater
* - motto: allocate or die trying
*/
newmem(nbytes,clrflag)
unsigned nbytes;
int clrflag;
{
register char *newaddr;
newaddr = sbrk(nbytes);
if (newaddr == -1)
fatal("No Memory");
end_mem = newaddr + nbytes;
if ((unsigned)end_mem & 1)
end_mem = sbrk(1);
return(newaddr);
}
#define PC 0xff
#define XT 0xfe
#define JR 0xfd
#define AT 0xfc
isjr()
{
static int machine = 0;
if (machine == 0) {
dmain(&machine,1,0xf000,0xfffe);
machine &= 0xff;
}
return machine == JR;
}
swint(intno, rp)
int intno;
struct sw_regs *rp;
{
extern int _dsval;
rp->ds = rp->es = _dsval;
sysint(intno, rp, rp);
return rp->ax;
}
set_ctrlb(state)
{
struct sw_regs rg;
int retcode;
rg.ax = 0x3300;
swint(SW_DOS,&rg);
retcode = rg.dx &0xFF;
rg.ax = 0x3300;
rg.dx = (state) ? 1 : 0;
swint(SW_DOS,&rg);
return retcode;
}
unsetup()
{
set_ctrlb(ocb);
}