-
Notifications
You must be signed in to change notification settings - Fork 3
/
prmachine.c
297 lines (256 loc) · 6.79 KB
/
prmachine.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/* pribmpc.c */
/* machine dependent code for pc and clones */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "prtypes.h"
#include "prmachine.h"
#define CANTALLOCATE "cant allocate "
#define CRPLEASE "Carriage return please"
#define NOCONFIGFILE "sprolog.inf missing using default configuration"
#define CONFIG_FILE "sprolog.inf"
#define YESUPPER 'Y'
#define YESLOWER 'y'
extern FILE *Log_file, *Curr_outfile;
extern void exit_term();
/**************************** os_alloc() *********************************/
/* This is the function you use to get memory from the system. */
/* Why not use malloc? Because malloc will only allocate up to 64K on */
/* some systems when there is another function around for larger */
/* allocations. */
char *os_alloc(zone_size_t how_much)
{
char *ret; //, *malloc();
#ifdef DEBUG
printf("trying to allocate %zu\n",how_much);
#endif
if((ret = malloc(how_much)) == NULL)
{
errmsg(CANTALLOCATE);
exit_term();
exit(1);
return(NULL);/* for stupid finicky compilers and lint */
}
else
#ifdef DEBUG
printf("successful\n");
#endif
return(ret);
}
/******************************************************************************
Initialise terminal
This is the function you use to set up your terminal for interaction with
sprolog. It would change if you wanted to incorporate a line editor for example
******************************************************************************/
void ini_term()
{
}
/******************************************************************************
function exit_term
This restores the terminal characteristics.
******************************************************************************/
void exit_term()
{
}
/***************************** errmsg() *********************************
Output error message.
On some systems you might want to output a box-surrounded message.
******************************************************************************/
void errmsg(char *s)
{
#if LOGGING_CAPABILITY
if(Log_file){
fprintf(Log_file, "%s", s);
fflush(Log_file);
}
#endif
fprintf(stdout, "%s\n", s);
}
/************************** tty_getc() *********************************
Read a char from terminal, no matter what the other flags are.
******************************************************************************/
int tty_getc()
{
int c;
c = getchar();
#ifdef LOGGING_CAPABILITY
if(Log_file!=NULL)
{
fputc(c,Log_file);
}
#endif
return(c);
}
/* raw read one char , with echo */
int tty_getche()
{
//#ifdef MARK_WILLIAMS
//return getcnb(); /* may not be on your machine */
//#else
//return getche(); /* may not be on your machine */
//#endif
return getchar();
}
/************************** tty_pr_string() *********************************
Output string to the terminal no matter what the other flags are.
******************************************************************************/
int tty_pr_string(s)
char *s;
{
int len;
#ifdef LOGGING_CAPABILITY
if(Log_file != NULL)
{
fprintf(Log_file,"%s",s);
fflush(Log_file);
}
#endif
len = printf("%s",s);
fflush(stdout);
return (len);
}
/*******************************************************************
pr_string()
This will output a string to the current output file.
It also returns the number of chars output.
It should be the only way your functions can output a string.
*******************************************************************/
int pr_string(s)
char *s;
{
int len;
#if LOGGING_CAPABILITY
extern FILE *Log_file;
if (Log_file != NULL)
{
fprintf(Log_file, "%s", s);
fflush(Log_file);
}
#endif
len = fprintf(Curr_outfile, "%s", s);
fflush(stdout);
return(len);
}
/**************************** read_config() **********************************
this reads the file SPROLOG.INF so that the sizes of the various
memory zones can be set.
************************************************************************/
int read_config(hsp, strsp, dsp, tsp, sbsp, tmpsp, rsp, psp)
zone_size_t *hsp, *strsp, *dsp, *tsp, *sbsp, *tmpsp;
int *rsp, *psp;
{
return 0; // we don't read any files.
/*
#ifdef MARK_WILLIAMS
long hs, strs, ds, ts, sbs, tmps;
#endif
FILE *ifp;
if((ifp = fopen(CONFIG_FILE, "r")) == NULL)
{
errmsg(NOCONFIGFILE);
return(0);
}
#ifdef MARK_WILLIAMS
fscanf(ifp, "%D %D %D %D %D %D %d %d", &hs, &strs, &ds, &ts, &sbs, &tmps, rsp, psp);
*hsp = hs;
*strsp = strs;
*dsp = ds;
*tsp = ts;
*sbsp = sbs;
*tmpsp = tmps;
#else
fscanf(ifp, "%u %u %u %u %u %u %u %u", hsp, strsp, dsp, tsp, sbsp, tmpsp, rsp, psp);
#endif
#ifdef DEBUG
printf("%u %u %u %u %u %u %u %u", *hsp, *strsp, *dsp, *tsp, *sbsp, *tmpsp, *rsp, *psp);
getchar();
#endif
return(1);
*/
}
/**************************** more_y_n() **********************************
Ask for confirmation.
************************************************************************/
/* a bit crude ... */
int more_y_n()
{
tty_pr_string("More ?");
return(read_yes());
}
/**************************** read_yes() *********************************
Return 1 iff user types y
Ignores characters after first non blank.
You could use a dialogue box in a windowing environment.
**************************************************************************/
int read_yes()
{
int c;
do
{
c = tty_getc();
}while(isspace(c));
while(tty_getc() != '\n');/* read rest of line */
if(c == YESLOWER || c == YESUPPER )
return(1);
else
return(0);
}
#ifdef LINE_EDITOR /* some day ... */
/* this function returns the x and y position of the cursor.
It's not used but you might want to make use of it to extend
the input.
*/
#ifdef __TURBOC__
getxy(px, py)
int *px, *py;
{
*px = wherex();
*py = wherey();
}
#else
#include <dos.h>
void gotoxy(X, Y)
short X, Y;
{
union REGS inregs;
union REGS outregs;
/*
inregs.h.ah = 0x0F;
int86(16, &inregs, &outregs);
*/
inregs.h.ah = 0x02;
inregs.h.bh = 0 ;/* outregs.h.bh; the active page */
inregs.h.dh = Y;
inregs.h.dl = X;
int86(16/* video */, &inregs, &outregs);
}
void getxy(px, py)/* get cursor position */
short *px, *py;
{
union REGS inregs, outregs;
inregs.h.ah = 0x0F;
int86(16, &inregs, &outregs);
inregs.h.bh = outregs.h.bh;
inregs.h.ah = 0x03;
int86(16, &inregs, &outregs);
*py = outregs.h.dh;
*px = outregs.h.dl;
}
#endif
#endif
#ifdef __TURBOC__
#include <time.h>
/* in hundreths of a second */
long clock()
{
return (100* clock()) /CLK_TCK;
}
#else
//long clock()
//{
//errmsg(" Clock not implemented on PC");
/* some recent C User Journal article has a version, I think. */
//return(0L);
//}
#endif
/* end of file */