| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include <stdlib.h> |
| 16 |
#include <stdio.h> |
| 17 |
|
| 18 |
#include <time.h> |
| 19 |
#include <ctype.h> |
| 20 |
#include <limits.h> |
| 21 |
|
| 22 |
#include "agility.h" |
| 23 |
#include "interp.h" |
| 24 |
|
| 25 |
|
| 26 |
int scroll_count; |
| 27 |
|
| 28 |
void print_statline(void); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
void agt_delay(int n) |
| 34 |
|
| 35 |
{ |
| 36 |
if (fast_replay || BATCH_MODE) return; |
| 37 |
print_statline(); |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
void agt_tone(int hz,int ms) |
| 43 |
|
| 44 |
{ |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
int agt_rand(int a,int b) |
| 49 |
|
| 50 |
{ |
| 51 |
return a+(rand()>>2)%(b-a+1); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
char *agt_input(int in_type) |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
{ |
| 62 |
static int input_error=0; |
| 63 |
char *s; |
| 64 |
|
| 65 |
scroll_count=0; |
| 66 |
print_statline(); |
| 67 |
s=rmalloc(1000); |
| 68 |
|
| 69 |
if (fgets(s,1000,stdin)==NULL) { |
| 70 |
if (++input_error>25) { |
| 71 |
printf("Read error on input\n"); |
| 72 |
exit(EXIT_FAILURE); |
| 73 |
} |
| 74 |
s[0]=0; |
| 75 |
clearerr(stdin); |
| 76 |
} else input_error=0; |
| 77 |
|
| 78 |
if (DEBUG_OUT) |
| 79 |
fprintf(debugfile,"%s\n",s); |
| 80 |
if (script_on) textputs(scriptfile,s); |
| 81 |
return s; |
| 82 |
} |
| 83 |
|
| 84 |
char agt_getkey(rbool echo_char) |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
{ |
| 90 |
char *t, *s, c; |
| 91 |
|
| 92 |
print_statline(); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
t=agt_input(-1); |
| 98 |
for(s=t;isspace(*s);s++); |
| 99 |
c=*s; |
| 100 |
rfree(t); |
| 101 |
|
| 102 |
return c; |
| 103 |
} |
| 104 |
|
| 105 |
void agt_textcolor(int c) |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
{ |
| 121 |
#if 0 |
| 122 |
if (c==-1) writestr("<<"); |
| 123 |
if (c==-2) writestr(">>"); |
| 124 |
#endif |
| 125 |
return; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
void agt_statline(const char *s) |
| 131 |
|
| 132 |
{ |
| 133 |
return; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
void agt_clrscr(void) |
| 138 |
|
| 139 |
|
| 140 |
{ |
| 141 |
int i; |
| 142 |
|
| 143 |
for(i=0;i<screen_height;i++) |
| 144 |
printf("\n"); |
| 145 |
if (DEBUG_OUT) fprintf(debugfile,"\n\n<CLRSCR>\n\n"); |
| 146 |
if (script_on) textputs(scriptfile,"\n\n\n\n"); |
| 147 |
scroll_count=0; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
void agt_puts(const char *s) |
| 152 |
{ |
| 153 |
printf("%s",s); |
| 154 |
curr_x+=strlen(s); |
| 155 |
if (DEBUG_OUT) fprintf(debugfile,"%s",s); |
| 156 |
if (script_on) textputs(scriptfile,s); |
| 157 |
} |
| 158 |
|
| 159 |
void agt_newline(void) |
| 160 |
{ |
| 161 |
printf("\n"); |
| 162 |
curr_x=0; |
| 163 |
if (DEBUG_OUT) fprintf(debugfile,"\n"); |
| 164 |
if (script_on) textputs(scriptfile,"\n"); |
| 165 |
scroll_count++; |
| 166 |
if (scroll_count>=screen_height-2) { |
| 167 |
printf(" --MORE--"); |
| 168 |
|
| 169 |
agt_waitkey(); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
static unsigned long boxflags; |
| 175 |
static int box_startx; |
| 176 |
static int box_width; |
| 177 |
static int delta_scroll; |
| 178 |
|
| 179 |
static void boxrule(void) |
| 180 |
|
| 181 |
{ |
| 182 |
int i; |
| 183 |
|
| 184 |
agt_puts("+"); |
| 185 |
for(i=0;i<box_width;i++) agt_puts("-"); |
| 186 |
agt_puts("+"); |
| 187 |
} |
| 188 |
|
| 189 |
static void boxpos(void) |
| 190 |
{ |
| 191 |
int i; |
| 192 |
|
| 193 |
agt_newline(); |
| 194 |
for(i=0;i<box_startx;i++) agt_puts(" "); |
| 195 |
} |
| 196 |
|
| 197 |
void agt_makebox(int width,int height,unsigned long flags) |
| 198 |
|
| 199 |
{ |
| 200 |
boxflags=flags; |
| 201 |
box_width=width; |
| 202 |
if (boxflags&TB_BORDER) width+=2; |
| 203 |
box_startx=(screen_width-width)/2; |
| 204 |
delta_scroll=height; |
| 205 |
boxpos(); |
| 206 |
if (boxflags&TB_BORDER) { |
| 207 |
boxrule(); |
| 208 |
boxpos(); |
| 209 |
agt_puts("|"); |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
void agt_qnewline(void) |
| 214 |
{ |
| 215 |
if (boxflags&TB_BORDER) agt_puts("|"); |
| 216 |
boxpos(); |
| 217 |
if (boxflags&TB_BORDER) agt_puts("|"); |
| 218 |
} |
| 219 |
|
| 220 |
void agt_endbox(void) |
| 221 |
{ |
| 222 |
if (boxflags&TB_BORDER) { |
| 223 |
agt_puts("|"); |
| 224 |
boxpos(); |
| 225 |
boxrule(); |
| 226 |
} |
| 227 |
scroll_count+=delta_scroll; |
| 228 |
agt_newline(); |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
#define opt(s) (!strcmp(optstr[0],s)) |
| 233 |
|
| 234 |
rbool agt_option(int optnum,char *optstr[],rbool setflag) |
| 235 |
|
| 236 |
{ |
| 237 |
|
| 238 |
return 0; |
| 239 |
} |
| 240 |
|
| 241 |
#undef opt |
| 242 |
|
| 243 |
genfile agt_globalfile(int fid) |
| 244 |
{ |
| 245 |
if (fid==0) |
| 246 |
return badfile(fCFG); |
| 247 |
|
| 248 |
else return badfile(fCFG); |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
void init_interface(int argc,char *argv[]) |
| 253 |
{ |
| 254 |
script_on=0;scriptfile=badfile(fSCR); |
| 255 |
scroll_count=0; |
| 256 |
center_on=par_fill_on=0; |
| 257 |
debugfile=stderr; |
| 258 |
DEBUG_OUT=0; |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
screen_height=25; |
| 263 |
status_width=screen_width=80; |
| 264 |
agt_clrscr(); |
| 265 |
} |
| 266 |
|
| 267 |
void start_interface(fc_type fc) |
| 268 |
{ |
| 269 |
if (stable_random) |
| 270 |
srand(6); |
| 271 |
else |
| 272 |
srand(time(0)); |
| 273 |
} |
| 274 |
|
| 275 |
void close_interface(void) |
| 276 |
{ |
| 277 |
if (filevalid(scriptfile,fSCR)) |
| 278 |
close_pfile(scriptfile,0); |
| 279 |
} |