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