6c05361d13d2208eef26c6ce8a5109e19e1829ce
[vlp.git] / src / int / nonstand.c
1 #include "depend.h"
2 #include "genint.h" 
3 #include "int.h"
4 #include "process.h"
5 #include "intproto.h"
6
7 #include "nonstand.h"
8
9
10 /* Call (non)standard procedures.
11  * Almost totaly implementation dependent.
12  */
13
14 /** TRUE if graphics mode active */
15 bool graphmode = FALSE;
16 param_struct par;
17
18 char *s;
19 char ss[255];
20 char ii[50], ff[50];
21 int scc, lastmsg;
22
23 int wait_for_key()
24 {
25         G_MESSAGE msg;
26
27         bzero(&msg,sizeof(G_MESSAGE));
28         while ((msg.msg_type != MSG_GRAPH) &&
29                                 (msg.param.pword[0] != GRAPH_INKEY_RESPONSE)) {
30                 read_from_graph(&msg);
31         }
32         return(msg.param.pword[3]);
33 }
34
35 /**
36  * Call (non)standard procedure
37  */
38 void nonstandard(word nrproc)
39 {
40         word am;
41         int cnt = 0;
42         float r1, r2;
43         word ax, bx, cx, dx, i, t1, t2;
44         unsigned int v, p, h, l, r, c, sc;
45         unsigned int Res_graph_X,Res_graph_Y;
46         G_MESSAGE msg;
47         MESSAGE msg1;
48
49         switch ((int) nrproc) {
50         case GRON:
51         case GROFF:
52                 break;
53
54         case CLS: msg.msg_type = MSG_GRAPH;
55                 msg.param.pword[0] = GRAPH_CLEAR;
56                 msg.param.pword[1] = GraphRes;
57                 send_to_graph(&msg);
58                 break;
59
60         case POINT:
61                 msg.msg_type = MSG_GRAPH;
62                 msg.param.pword[0] = GRAPH_POINT;
63                 msg.param.pword[1] = GraphRes;
64                 msg.param.pword[3] = param[0].xword;
65                 msg.param.pword[4] = param[1].xword;
66                 send_to_graph(&msg);
67                 break;
68
69         case MOVE:
70                 msg.msg_type = MSG_GRAPH;
71                 msg.param.pword[0] = GRAPH_MOVE;
72                 msg.param.pword[1] = GraphRes;
73                 msg.param.pword[2] = param[0].xword;
74                 msg.param.pword[3] = param[1].xword;
75                 send_to_graph(&msg);
76                 break;
77
78         case DRAW:
79                 msg.msg_type = MSG_GRAPH;
80                 msg.param.pword[0] = GRAPH_LINETO;
81                 msg.param.pword[1] = GraphRes;
82                 msg.param.pword[3] = param[0].xword;
83                 msg.param.pword[4] = param[1].xword;
84                 send_to_graph(&msg);
85                 break;
86
87         case INXPOS:
88                 msg.msg_type = MSG_GRAPH;
89                 msg.param.pword[0] = GRAPH_CURPOS;
90                 msg.param.pword[1] = GraphRes;
91                 send_to_graph(&msg);
92                 while ((msg.msg_type != MSG_GRAPH) && 
93                                 (msg.param.pword[0] != GRAPH_CURPOS_RESPONSE))
94                         read_from_graph(&msg);
95
96                 param[0].xword = msg.param.pword[3];
97                 break;
98         
99         case INYPOS:
100                 msg.msg_type = MSG_GRAPH;
101                 msg.param.pword[0] = GRAPH_CURPOS;
102                 msg.param.pword[1] = GraphRes;
103                 send_to_graph(&msg);
104                 while ((msg.msg_type != MSG_GRAPH) ||
105                                 (msg.param.pword[0] != GRAPH_CURPOS_RESPONSE))
106                         read_from_graph(&msg);
107
108                 param[0].xword = msg.param.pword[4];
109                 break;
110         
111         case HFILL:
112                 break;
113         case VFILL:
114                 break;
115
116         case HASCII:
117                 msg.msg_type = MSG_GRAPH;
118                 msg.param.pword[0] = GRAPH_HASCII;
119                 msg.param.pword[1] = param[0].xword;
120                 send_to_graph(&msg);
121                 break;
122
123         case COLOR:
124                 msg.msg_type = MSG_GRAPH;
125                 msg.param.pword[0] = GRAPH_FOREGROUND;
126                 msg.param.pword[1] = GraphRes;
127                 msg.param.pword[3] = param[0].xword;
128                 send_to_graph(&msg);
129                 break;
130
131         case BORDER:
132                 msg.msg_type = MSG_GRAPH;
133                 msg.param.pword[0] = GRAPH_BACKGROUND;
134                 msg.param.pword[1] = GraphRes;
135                 msg.param.pword[3] = param[0].xword;
136                 send_to_graph(&msg);
137                 break;
138
139         case STYLE:
140                 break;
141
142         case INPIX:
143                 break;
144
145         case OUTSTRING:
146                 msg.msg_type = MSG_GRAPH;
147                 msg.param.pword[0] = GRAPH_OUTSTRING;
148                 msg.param.pword[1] = GraphRes;
149                 msg.param.pword[2] = param[0].xword;
150                 msg.param.pword[3] = param[1].xword;
151                 msg.param.pword[4] = param[3].xword;
152                 msg.param.pword[5] = param[4].xword; 
153                 {
154                         s= (char *)(M + strings + param[ 2 ].xword + 1);
155                         strcpy(msg.param.pstr,s);
156                         send_to_graph(&msg);
157                 }
158                 break;
159
160         case GETMAP:
161                 msg.msg_type = MSG_GRAPH;
162                 msg.param.pword[0] = GRAPH_GETMAP;
163                 msg.param.pword[1] = GraphRes;
164                 msg.param.pword[2] = param[0].xword;
165                 msg.param.pword[3] = param[1].xword;
166                 send_to_graph(&msg);
167                 while ((msg.msg_type != MSG_GRAPH) || 
168                                 (msg.param.pword[0] != GRAPH_GETMAP_RESPONSE))
169                         read_from_graph(&msg);
170                 {
171                         int map;
172
173                         map = msg.param.pword[2]; 
174                         newarry((word) 1, 3, (word)AINT, &param[2].xvirt, &am);
175                         M[am + 3] = map;
176                         M[am + 4] = msg.param.pword[3];
177                         M[am + 5] = msg.param.pword[4];
178                 }
179                 break;
180
181         case PUTMAP:
182                 if (member(&param[0].xvirt, &am)) {
183                         msg.msg_type = MSG_GRAPH;
184                         msg.param.pword[0] = GRAPH_PUTMAP;
185                         msg.param.pword[1] = GraphRes;
186                         msg.param.pword[2] = M[am + 3];
187                         msg.param.pword[4] = M[am + 4];
188                         msg.param.pword[5] = M[am + 5];
189                         send_to_graph(&msg);
190                 }
191                 break;
192
193         case ORMAP:
194         case XORMAP:
195                 break;
196
197         case PATERN:
198                 msg.msg_type = MSG_GRAPH;
199                 msg.param.pword[0] = GRAPH_RECT;
200                 msg.param.pword[1] = GraphRes;
201                 msg.param.pword[3] = param[0].xword;
202                 msg.param.pword[4] = param[1].xword;
203                 msg.param.pword[5] = param[2].xword;
204                 msg.param.pword[6] = param[3].xword;
205                 msg.param.pword[7] = param[4].xword; 
206                 msg.param.pword[8] = param[5].xword;
207                 send_to_graph(&msg);
208                 break;
209         case PALLET:
210                 break;
211
212         case TRACK:
213                 msg.msg_type = MSG_GRAPH;
214                 msg.param.pword[0] = GRAPH_WRITEINTXY;
215                 msg.param.pword[1] = GraphRes;
216                 msg.param.pword[2] = param[0].xword;
217                 msg.param.pword[3] = param[1].xword;
218                 msg.param.pword[4] = param[4].xword;
219                 msg.param.pword[5] = param[2].xword; 
220                 send_to_graph(&msg);
221                 break;
222
223         case INKEY:
224                 msg.msg_type = MSG_GRAPH;
225                 msg.param.pword[0] = GRAPH_INKEY;
226                 msg.param.pword[1] = GraphRes;
227                 send_to_graph(&msg);
228                 param[0].xword = wait_for_key();
229                 break;
230
231         case CIRB:
232                 msg.msg_type = MSG_GRAPH;
233                 msg.param.pword[0] = GRAPH_ELLIPSE;
234                 msg.param.pword[1] = GraphRes;
235                 msg.param.pword[3] = param[0].xword;
236                 msg.param.pword[4] = param[1].xword;
237                 msg.param.pword[5] = param[2].xword;
238                 msg.param.pword[6] = param[3].xword;
239                 msg.param.pword[7] = (double)param[4].xword;
240                 msg.param.pword[8] = (double)param[5].xword;
241                 msg.param.pword[9] = param[7].xword;
242                 send_to_graph(&msg);
243                 break;
244
245         /* ___________ magic library ____________ */
246         case HFONT8:
247                 if (param[0].xword == 1000) {
248                         strcpy(ss, "");
249                 }
250                 else if (param[0].xword == 1001) {
251                         sprintf(ss, "%s%c", ss, (char)(param[1].xword));
252                 }
253                 else if (param[0].xword == 303) {
254                         msg.msg_type = MSG_GRAPH;
255                         msg.param.pword[0] = GRAPH_MAGIC;
256                         msg.param.pword[1] = param[0].xword; /* Lookout! */
257                         msg.param.pword[2] = param[1].xword;
258                         msg.param.pword[3] = param[2].xword;
259                         msg.param.pword[4] = param[3].xword;
260                         msg.param.pword[5] = param[5].xword;
261
262                         strcpy(msg.param.pstr, ss);
263                         send_to_graph(&msg);
264                 }
265                 else if (param[0].xword > 500) {
266                         msg1.param.pword[1] = param[0].xword;
267                         msg1.param.pword[2] = param[1].xword;
268                         msg1.param.pword[3] = param[2].xword;
269                         msg1.param.pword[4] = param[3].xword;
270                         msg1.param.pword[5] = param[5].xword;
271                         msg1.param.pword[6] = param[6].xword;
272                         msg1.param.pword[7] = param[7].xword;
273                         s = (char *)(M + strings + param[4].xword + 1);
274                         strcpy(msg1.param.pstr, s);
275
276                         /* Machine class */
277                         switch(msg1.param.pword[1]) {
278                         /* get local node */
279                         case 501:
280                                 newarry((word)0, 2, (word)AINT, &param[8].xvirt,
281                                                                         &ax);
282                                 ax += 3;
283                                 M[ax++] = my_ctx.node;
284                                 break;
285                         /* number of nodes */
286                         case 502:
287                                 msg1.msg_type = MSG_NET;
288                                 msg1.param.pword[0] = NET_NODES_NUM;
289                                 write(net_sock,&msg1,sizeof(MESSAGE));
290                                 while ((msg1.msg_type != MSG_NET) ||
291                                         (msg1.param.pword[0] != NET_NODES_NUM_RESPONSE))
292                                         read_from_net(&msg1);
293
294                                 newarry((word)0, 2, (word)AINT, &param[8].xvirt, &ax);
295                                 ax += 3;
296                                 M[ax++] = msg1.param.pword[1];
297                                 break;
298                         /* node exists */
299                         case 503:
300                                 msg1.msg_type = MSG_NET;
301                                 msg1.param.pword[0] = NET_NODE_EXIST;
302                                 msg1.param.pword[1] = msg1.param.pword[2];
303                                 write(net_sock, &msg1, sizeof(MESSAGE));
304                                 bzero(&msg1, sizeof(msg1));
305                                 while ((msg1.msg_type != MSG_NET) ||
306                                         (msg1.param.pword[0] != NET_NODE_EXIST))
307                                         read_from_net(&msg1);
308
309                                 newarry((word)0, 2, (word)AINT, &param[8].xvirt, &ax);
310                                 ax += 3;
311                                 M[ax++] = msg1.param.pword[1];
312                                 break;
313                         /* get nodes info */
314                         case 504:
315                                 {
316                                 char ss[1024];
317                                 strcpy(ss, "");
318                                 msg1.msg_type = MSG_NET;
319                                 msg1.param.pword[0] = NET_GET_INFO;
320                                 write(net_sock, &msg1, sizeof(MESSAGE));
321                                 while ((msg1.msg_type != MSG_NET) ||
322                                         (msg1.param.pword[0] != NET_INFO_END)) {
323                                         read_from_net(&msg1);
324
325                                         if (msg1.param.pword[0] == NET_INFO)
326                                                 strcat(ss,msg1.param.pstr);
327                                 }
328                                 newarry((word)0, strlen(ss), (word)AINT, &param[8].xvirt, &ax);
329                                 ax += 3;
330                                 s = ss;
331                                 while(*s!='\0')
332                                         M[ax++]=*(s++);
333
334                                 };
335                                 break;
336
337                         }
338                 }
339                 /* graphic */
340                 else {
341                         msg.msg_type = MSG_GRAPH;
342                         msg.param.pword[0] = GRAPH_MAGIC;
343                         msg.param.pword[1] = param[0].xword;
344                         msg.param.pword[2] = param[1].xword;
345                         msg.param.pword[3] = param[2].xword;
346                         msg.param.pword[4] = param[3].xword;
347                         msg.param.pword[5] = param[5].xword;
348                         msg.param.pword[6] = param[6].xword;
349                         msg.param.pword[7] = param[7].xword;
350                         s= (char *)(M + strings + param[ 4 ].xword + 1);
351                         strcpy(msg.param.pstr,s);
352
353
354                         send_to_graph(&msg);
355
356                         if (msg.param.pword[1] < 0) {
357                                 lastmsg = msg.param.pword[1];
358                                 bzero(&msg,sizeof(G_MESSAGE));
359                                 while (msg.param.pword[0] != GRAPH_MAGIC_RESPONSE)
360                                         read_from_graph(&msg);
361
362                                  // Read integer
363                                 if (lastmsg == -305) {
364                                         newarry((word)0, 10, (word)AINT, &param[8].xvirt, &ax);
365                                         ax += 3;
366                                         M[ax++] = atoi(msg.param.pstr);
367                                 }
368                                 // Read char
369                                 else if (lastmsg == -306) {
370                                         newarry((word)0, 10, (word)AINT, &param[8].xvirt, &ax);
371                                         ax += 3;
372                                         M[ax++] = msg.param.pchar;
373                                 }
374                                 // Read real
375                                 else if (lastmsg == -307) {
376                                         newarry((word)0, 10, (word)AINT, &param[8].xvirt, &ax);
377                                         ax += 3;
378                                         strcpy(ii, "");
379                                         strcpy(ff, "");
380                                         sc = 0;
381                                         while ((sc < strlen(msg.param.pstr)) &&
382                                                 (msg.param.pstr[sc] != '.')) {
383                                                 ii[sc]=msg.param.pstr[sc];
384                                                 sc++;
385                                         }
386                                         ii[sc++] = '\0';
387                                         scc = sc;
388                                         sc = 0;
389                                         while (scc<strlen(msg.param.pstr)) {
390                                                 ff[sc++] = msg.param.pstr[scc++];
391                                         }
392                                         ff[sc] = '\0';
393                                         M[ax++] = atoi(ii);
394                                         M[ax++] = atoi(ff);
395                                 }
396                                 else if (msg.param.pword[1] == 1) {
397                                         newarry((word)0, 10, (word)AINT, &param[8].xvirt, &ax);
398                                         ax += 3;
399                                         for(l = 2; l < 7; l++)
400                                                 M[ax++] = msg.param.pword[l];
401                                 }
402                                 else {
403                                         newarry((word)0, strlen(msg.param.pstr) + 2, (word)AINT, &param[8].xvirt, &ax);
404                                         ax += 3;
405                                         s = msg.param.pstr;
406                                         while(*s != '\0')
407                                                 M[ax++] = *(s++);
408                                 }
409                         }
410                 }
411                 break;
412
413         case INIT:
414                 break;
415
416         case STATUS:
417                 break;
418
419         case GETPRESS :
420                 msg.msg_type = MSG_GRAPH;
421                 msg.param.pword[0] = GRAPH_MGETPRESS;
422                 msg.param.pword[1] = GraphRes;
423                 send_to_graph(&msg);
424                 while (1) {
425                         read_from_graph(&msg);
426                         if ((msg.msg_type == MSG_GRAPH) &&
427                                 (msg.param.pword[0] == GRAPH_MGETPRESS_RESPONSE))
428                                 break;
429                 }
430                 param[0].xword = msg.param.pword[2];
431                 param[1].xword = msg.param.pword[3];
432                 param[2].xword = msg.param.pword[4];
433                 param[3].xword = msg.param.pword[5];
434                 param[4].xword = msg.param.pword[6];
435                 param[5].xword = msg.param.pword[7];
436                 break;
437
438         case GETRELEASE:
439                 break;
440
441         case SHOWCURSOR:
442         case HIDECURSOR:
443         case SETPOSITION:
444         case SETWINDOW:
445         case DEFCURSOR:
446         case SETSPEED:
447         case SETMARGINS:
448         case SETTHRESHOLD:
449                 break;
450
451         case GETMOVEMENT:
452                 break;
453
454         default:
455                 errsignal(RTEUNSTP);
456         }
457 }
458