1 /*
2 TiMidity++ -- MIDI to WAVE converter and player
3 Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
4 Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 */
21
22 /*
23 * WRD Tracer for vt100 control terminal
24 * Written by Takanori Watanabe <takawata@shidahara1.planet.kobe-u.ac.jp>
25 */
26 /*
27 * WRD Tracer for Windows console control terminal
28 * modified for Windows console by Daisuke Aoki <dai@y7.net>
29 */
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif /* HAVE_CONFIG_H */
34 #include <stdio.h>
35 #include <stdlib.h>
36 #ifndef NO_STRING_H
37 #include <string.h>
38 #else
39 #include <strings.h>
40 #endif
41 #ifndef __CYGWIN32__
42 #include <conio.h>
43 #endif
44
45 #include "timidity.h"
46 #include "common.h"
47 #include "instrum.h"
48 #include "playmidi.h"
49 #include "readmidi.h"
50 #include "controls.h"
51 #include "wrd.h"
52
53 // #define DEBUG1
54 #ifndef __OLD_BORLANDC__
55 #define USE_ESC
56 #define NULL_STMT do ; while(0)
57 #define gotoxy(x, y) NULL_STMT
58 #define wherex() 1
59 #define wherey() 1
60 #define putch putchar
61 #define cputs puts
62 #define delline() NULL_STMT
63 #define clrscr() NULL_STMT
64 #define clreol() NULL_STMT
65 #endif /* __OLD_BORLANDC__ */
66
67 static int wrdt_open(char *dummy);
68 static void wrdt_apply(int cmd, int wrd_argc, int wrd_args[]);
69 static void wrdt_update_events(void);
70 static void wrdt_end(void);
71 static void wrdt_close(void);
72 #define NO_GRAPHIC_SUPPORT
73 #define wrdt wcon_wrdt_mode
74 #define COLOR_REMAP(k) ((k)>16)&&((k)<30)?(k)+14:k
75
76 WRDTracer wrdt =
77 {
78 "Windows Console WRD tracer", 'w',
79 0,
80 wrdt_open,
81 wrdt_apply,
82 NULL,
83 wrdt_update_events,
84 NULL,
85 wrdt_end,
86 wrdt_close
87 };
88
89 static int wrd_argc;
90 static int wrd_args[WRD_MAXPARAM];
91 static int inkey_flag;
92
93 #ifdef __OLD_BORLANDC__
94 static struct text_info text_info;
95 static struct conattr {
96 int attr;
97 int bc;
98 int fc;
99 } iniattr, curattr, saveattr;
100
borlandc_con_set_attr(struct conattr * attr)101 static void borlandc_con_set_attr(struct conattr *attr)
102 {
103 if(attr->attr & REVERSE)
104 textattr((attr->attr & ~REVERSE) + (attr->bc >> 4) + (attr->fc << 4));
105 else
106 textattr((attr->attr & ~REVERSE) + attr->bc + attr->fc);
107 }
108
borlandc_con_save_attr(void)109 static void borlandc_con_save_attr(void)
110 {
111 saveattr.attr = curattr.attr;
112 saveattr.bc = curattr.bc;
113 saveattr.fc = curattr.fc;
114 }
115
borlandc_con_restore_attr(void)116 static void borlandc_con_restore_attr(void)
117 {
118 curattr.attr = saveattr.attr;
119 curattr.bc = saveattr.bc;
120 curattr.fc = saveattr.fc;
121 borlandc_con_set_attr(&curattr);
122 }
123
borlandc_con_reset_attr(void)124 static void borlandc_con_reset_attr(void)
125 {
126 borlandc_con_set_attr(&iniattr);
127 }
128
borlandc_con_init(void)129 static void borlandc_con_init(void)
130 {
131 gettextinfo(&text_info);
132 iniattr.attr = text_info.attribute & 0xff00;
133 iniattr.bc = text_info.attribute & 0xf0;
134 iniattr.fc = text_info.attribute & 0x0f;
135 curattr.attr = text_info.attribute & 0xff00;
136 curattr.bc = text_info.attribute & 0xf0;
137 curattr.fc = text_info.attribute & 0x0f;
138 borlandc_con_save_attr();
139 }
140
borlandc_con_reset(void)141 static void borlandc_con_reset(void)
142 {
143 borlandc_con_reset_attr();
144 }
145 #else
146 struct {
147 int winleft, winright;
148 int wintop, winbottom;
149 } text_info = {
150 1,25,
151 1,80,
152 };
153 #endif
154
155 #define CANNOC_X(x) \
156 {\
157 if(x < text_info.winleft) x = text_info.winleft;\
158 else if(x > text_info.winright) x = text_info.winright;\
159 }
160 #define CANNOC_Y(y) \
161 {\
162 if(y < text_info.wintop) y = text_info.wintop;\
163 else if(y > text_info.winbottom) y = text_info.winbottom;\
164 }
165
putstring(char * str)166 static void putstring(char *str)
167 {
168 cputs(str);
169 }
170
putstringn(char * str,int n)171 static void putstringn(char *str, int n)
172 {
173 while(n--)
174 putch(*(str++));
175 }
176
177 #ifdef __OLD_BORLANDC__
borlandc_con_color(int color)178 static void borlandc_con_color(int color)
179 {
180 switch(color){
181 case 0:
182 borlandc_con_reset_attr();
183 break;
184 case 2:
185 curattr.attr |= VERTICALLINE;
186 borlandc_con_set_attr(&curattr);
187 break;
188 case 4:
189 curattr.attr |= UNDERLINE;
190 borlandc_con_set_attr(&curattr);
191 break;
192 case 5:
193 curattr.attr |= BLINK;
194 borlandc_con_set_attr(&curattr);
195 break;
196 case 8: case 16: case 30:
197 curattr.attr &= ~REVERSE;
198 curattr.fc = BLACK;
199 borlandc_con_set_attr(&curattr);
200 break;
201 case 17: case 31:
202 curattr.attr &= ~REVERSE;
203 curattr.fc = LIGHTRED;
204 borlandc_con_set_attr(&curattr);
205 break;
206 case 18: case 34:
207 curattr.attr &= ~REVERSE;
208 curattr.fc = LIGHTBLUE;
209 borlandc_con_set_attr(&curattr);
210 break;
211 case 19: case 35:
212 curattr.attr &= ~REVERSE;
213 curattr.fc = LIGHTMAGENTA;
214 borlandc_con_set_attr(&curattr);
215 break;
216 case 20: case 32:
217 curattr.attr &= ~REVERSE;
218 curattr.fc = LIGHTGREEN;
219 borlandc_con_set_attr(&curattr);
220 break;
221 case 21: case 33:
222 curattr.attr &= ~REVERSE;
223 curattr.fc = YELLOW;
224 borlandc_con_set_attr(&curattr);
225 break;
226 case 22: case 36:
227 curattr.attr &= ~REVERSE;
228 curattr.fc = LIGHTCYAN;
229 borlandc_con_set_attr(&curattr);
230 break;
231 case 23: case 37:
232 curattr.attr &= ~REVERSE;
233 curattr.fc = WHITE;
234 borlandc_con_set_attr(&curattr);
235 break;
236 /*
237 case 40:
238 attr = REVERSE + (bc << 4) + BLACK;
239 textattr(attr);
240 break;
241 case 41:
242 attr = REVERSE + (bc << 4) + LIGHTRED;
243 textattr(attr);
244 break;
245 case 42:
246 attr = REVERSE + (bc << 4) + LIGHTGREEN;
247 textattr(attr);
248 break;
249 case 43:
250 attr = REVERSE + (bc << 4) + YELLOW;
251 textattr(attr);
252 break;
253 case 44:
254 attr = REVERSE + (bc << 4) + LIGHTBLUE;
255 textattr(attr);
256 break;
257 case 45:
258 attr = REVERSE + (bc << 4) + LIGHTMAGENTA;
259 textattr(attr);
260 break;
261 case 46:
262 attr = REVERSE + (bc << 4) + LIGHTCYAN;
263 textattr(attr);
264 break;
265 case 47:
266 attr = REVERSE + (bc << 4) + WHITE;
267 textattr(attr);
268 break;
269 */
270 case 40:
271 curattr.attr |= REVERSE;
272 curattr.fc = BLACK;
273 borlandc_con_set_attr(&curattr);
274 break;
275 case 41:
276 curattr.attr |= REVERSE;
277 curattr.fc = LIGHTRED;
278 borlandc_con_set_attr(&curattr);
279 break;
280 case 42:
281 curattr.attr |= REVERSE;
282 curattr.fc = LIGHTGREEN;
283 borlandc_con_set_attr(&curattr);
284 break;
285 case 43:
286 curattr.attr |= REVERSE;
287 curattr.fc = YELLOW;
288 borlandc_con_set_attr(&curattr);
289 break;
290 case 44:
291 curattr.attr |= REVERSE;
292 curattr.fc = LIGHTBLUE;
293 borlandc_con_set_attr(&curattr);
294 break;
295 case 45:
296 curattr.attr |= REVERSE;
297 curattr.fc = LIGHTMAGENTA;
298 borlandc_con_set_attr(&curattr);
299 break;
300 case 46:
301 curattr.attr |= REVERSE;
302 curattr.fc = LIGHTCYAN;
303 borlandc_con_set_attr(&curattr);
304 break;
305 case 47:
306 curattr.attr |= REVERSE;
307 curattr.fc = WHITE;
308 borlandc_con_set_attr(&curattr);
309 break;
310 default:
311 break;
312 }
313 return;
314 }
315 #endif
316
317 /* Escape sequence */
318
esc_index(void)319 static void esc_index(void)
320 {
321 int x = wherex(), y = wherey();
322 if(y<text_info.winbottom)
323 gotoxy(x,y+1);
324 else {
325 putstring("\n");
326 gotoxy(x,y);
327 }
328 }
329
esc_nextline(void)330 void esc_nextline(void)
331 {
332 int y = wherey();
333 if(y<text_info.winbottom)
334 gotoxy(text_info.winleft,y+1);
335 else {
336 putstring("\n");
337 }
338 }
339
esc_reverseindex(void)340 void esc_reverseindex(void)
341 {
342 int x = wherex(), y = wherey();
343 if(y <= text_info.wintop)
344 delline();
345 else
346 y--;
347 gotoxy(x,y);
348 }
349
esc_clearscreen(void)350 void esc_clearscreen(void)
351 {
352 clrscr();
353 }
354
esc_directcursoraddressing(int x,int y)355 void esc_directcursoraddressing(int x, int y)
356 {
357 CANNOC_X(x);
358 CANNOC_Y(y);
359 gotoxy(x,y);
360 }
361
esc_cursorup(int n)362 void esc_cursorup(int n)
363 {
364 int y;
365 if(n < 1) n = 1;
366 y = wherey() - n;
367 CANNOC_Y(y);
368 gotoxy(wherex(),y);
369 }
370
esc_cursordown(int n)371 void esc_cursordown(int n)
372 {
373 int y;
374 if(n < 1) n = 1;
375 y = wherey() + n;
376 CANNOC_Y(y);
377 gotoxy(wherex(),y);
378 }
379
esc_cursorforward(int n)380 void esc_cursorforward(int n)
381 {
382 int x;
383 if(n < 1) n = 1;
384 x = wherex() - n;
385 CANNOC_X(x);
386 gotoxy(x,wherey());
387 }
388
esc_cursorbackward(int n)389 void esc_cursorbackward(int n)
390 {
391 int x;
392 if(n < 1) n = 1;
393 x = wherex() + n;
394 CANNOC_X(x);
395 gotoxy(x,wherey());
396 }
397
esc_clearfromcursortoendofscreen(void)398 void esc_clearfromcursortoendofscreen(void)
399 {
400 int oldx = wherex(), oldy = wherey();
401 int y;
402 clreol();
403 for(y=oldy+1;y<=text_info.winbottom;y++){
404 gotoxy(text_info.winleft,y);
405 clreol();
406 }
407 gotoxy(oldx,oldy);
408 }
409
esc_clearfrombeginningofscreentocursor(void)410 void esc_clearfrombeginningofscreentocursor(void)
411 {
412 int oldx = wherex(), oldy = wherey();
413 int y;
414 for(y=oldy;y<=text_info.winbottom;y++){
415 gotoxy(text_info.winleft,y);
416 clreol();
417 }
418 gotoxy(oldx,oldy);
419 }
420
esc_clearfromcursortoendofline(void)421 void esc_clearfromcursortoendofline(void)
422 {
423 int oldx = wherex(), oldy = wherey();
424 int x;
425 for(x=oldx;x<=text_info.winright;x++)
426 putstringn(" ",1);
427 gotoxy(oldx,oldy);
428 }
429
esc_clearfrombeginningoflinetocursor(void)430 void esc_clearfrombeginningoflinetocursor(void)
431 {
432 int oldx = wherex(), oldy = wherey();
433 int x;
434 for(x=oldx;x>=text_info.winright;x--)
435 putstringn(" ",1);
436 gotoxy(oldx,oldy);
437 }
438
esc_clearentirelinecontainingcursor(void)439 void esc_clearentirelinecontainingcursor(void)
440 {
441 int oldx = wherex(), oldy = wherey();
442 int x;
443 for(x=text_info.winleft;x<=text_info.winright;x++)
444 putstringn(" ",1);
445 gotoxy(oldx,oldy);
446 }
447
esc_deleteline(int n)448 void esc_deleteline(int n)
449 {
450 int i, n_max;
451 if(n < 1) n = 1;
452 n_max = text_info.winbottom - wherey() + 1;
453 if(n > n_max) n = n_max;
454 for(i=1;i<=n;i++)
455 delline();
456 gotoxy(text_info.winleft,wherey());
457 }
458
esc_insertline(int n)459 void esc_insertline(int n)
460 {
461 int i;
462 if(n < 1) n = 1;
463 for(i=1;i<=n;i++)
464 delline();
465 gotoxy(text_info.winleft,wherey());
466 }
467
esc_savecursorposition(void)468 void esc_savecursorposition(void)
469 {
470 return;
471 }
472
esc_setcursorposition(void)473 void esc_setcursorposition(void)
474 {
475 return;
476 }
477
esc_enablecursordisplay(void)478 void esc_enablecursordisplay(void)
479 {
480 #ifdef __OLD_BORLANDC__
481 _setcursortype(_NORMALCURSOR);
482 #endif /* __OLD_BORLANDC__ */
483 }
484
esc_disablecursordisplay(void)485 void esc_disablecursordisplay(void)
486 {
487 #ifdef __OLD_BORLANDC__
488 _setcursortype(_NOCURSOR);
489 #endif /* __OLD_BORLANDC__ */
490 }
491
esc_characterattribute(int n)492 void esc_characterattribute(int n)
493 {
494 #ifdef __OLD_BORLANDC__
495 borlandc_con_color(n);
496 #endif
497 }
498
499 /* return figures */
getdigit(char * str,int * num)500 static int getdigit(char *str,int *num)
501 {
502 int i;
503 char local[20];
504 for(i=0;i<=10;i++)
505 if(str[i] < '0' || str[i] > '9'){
506 if(i<1)
507 return 0;
508 else
509 break;
510 }
511 strncpy(local,str,i);
512 local[i] = '\0';
513 *num = atoi(local);
514 return i;
515 }
516
putstring_with_esc(char * str)517 static void putstring_with_esc(char *str)
518 {
519 char *p;
520 while(*str)
521 {
522 p = str;
523 for(;;)
524 {
525 if((unsigned char)*p >= 0x20){
526 p++;
527 continue;
528 }
529 if(p-str > 0){
530 putstringn(str,p-str);
531 str = p;
532 break;
533 }
534 if(*p == '\0')
535 break;
536 if(*p == 0x1b){
537 int res, n[1024], n_max = 0;
538 char *oldp = p;
539 p++;
540 if(*p == '['){
541 p++;
542 for(;;){
543 res = getdigit(p,&(n[n_max+1]));
544 if(res>0){
545 n_max++;
546 p += res;
547 }
548 if(*p != ';')
549 break;
550 }
551 } else if(*p == 'D'){
552 esc_index();
553 p++;
554 str = p;
555 break;
556 } else if(*p == 'E'){
557 esc_nextline();
558 p++;
559 str = p;
560 break;
561 } else if(*p == 'M'){
562 esc_reverseindex();
563 p++;
564 str = p;
565 break;
566 } else if(*p == '*'){
567 esc_clearscreen();
568 p++;
569 str = p;
570 break;
571 } else {
572 p = oldp;
573 if(p-str > 0){
574 putstringn(str,p-str);
575 str = p;
576 break;
577 }
578 }
579
580 if(n_max == 2 && (*p == 'H' || *p == 'f')){
581 esc_directcursoraddressing(n[1],n[2]);
582 p++;
583 str = p;
584 break;
585 }
586 if((n_max == 1 && *p == 'A') || (n_max == 0 && *p == 'A')){
587 if(n_max == 0)
588 n[1] = 1;
589 esc_cursorup(n[1]);
590 p++;
591 str = p;
592 break;
593 }
594 if((n_max == 1 && *p == 'B') || (n_max == 0 && *p == 'B')){
595 if(n_max == 0)
596 n[1] = 1;
597 esc_cursordown(n[1]);
598 p++;
599 str = p;
600 break;
601 }
602 if((n_max == 1 && *p == 'C') || (n_max == 0 && *p == 'C')){
603 if(n_max == 0)
604 n[1] = 1;
605 esc_cursorforward(n[1]);
606 p++;
607 str = p;
608 break;
609 }
610 if((n_max == 1 && *p == 'D') || (n_max == 0 && *p == 'D')){
611 if(n_max == 0)
612 n[1] = 1;
613 esc_cursorbackward(n[1]);
614 p++;
615 str = p;
616 break;
617 }
618 if((n_max == 1 && *p == 'J') || (n_max == 0 && *p == 'J')){
619 if(n_max == 0 || n[1] == 0)
620 esc_clearfromcursortoendofscreen();
621 else if(n[1] == 1)
622 esc_clearfrombeginningofscreentocursor();
623 else if(n[1] == 2)
624 esc_clearscreen();
625 p++;
626 str = p;
627 break;
628 }
629 if((n_max == 1 && *p == 'K') || (n_max == 0 && *p == 'K')){
630 if(n_max == 0 || n[1] == 0)
631 esc_clearfromcursortoendofline();
632 else if(n[1] == 1)
633 esc_clearfrombeginningoflinetocursor();
634 else if(n[1] == 2)
635 esc_clearentirelinecontainingcursor();
636 p++;
637 str = p;
638 break;
639 }
640 if((n_max == 1 && *p == 'M') || (n_max == 0 && *p == 'M')){
641 if(n_max == 0)
642 n[1] = 1;
643 esc_deleteline(n[1]);
644 p++;
645 str = p;
646 break;
647 }
648 if((n_max == 1 && *p == 'L') || (n_max == 0 && *p == 'L')){
649 if(n_max == 0)
650 n[1] = 1;
651 esc_insertline(n[1]);
652 p++;
653 str = p;
654 break;
655 }
656 if(n_max == 0 && *p == 's'){
657 esc_savecursorposition();
658 p++;
659 str = p;
660 break;
661 }
662 if(n_max == 0 && *p == 'u'){
663 esc_setcursorposition();
664 p++;
665 str = p;
666 break;
667 }
668 if(!strncmp(p,">5l",3)){
669 esc_enablecursordisplay();
670 p += 3;
671 str = p;
672 break;
673 }
674 if(!strncmp(p,">5h",3)){
675 esc_disablecursordisplay();
676 p += 3;
677 str = p;
678 break;
679 }
680 if(!strncmp(p,">1h",3)){
681 /* Enabel bottom line */
682 p += 3;
683 str = p;
684 break;
685 }
686 if(!strncmp(p,">1l",3)){
687 /* Disabel bottom line */
688 p += 3;
689 str = p;
690 break;
691 }
692 if(!strncmp(p,">3h",3)){
693 /* Select 31 line mode */
694 p += 3;
695 str = p;
696 break;
697 }
698 if(!strncmp(p,">3l",3)){
699 /* Select 25 line mode */
700 p += 3;
701 str = p;
702 break;
703 }
704 if(*p == 'm'){
705 int i;
706 for(i=1;i<=n_max;i++)
707 esc_characterattribute(n[i]);
708 p++;
709 str = p;
710 break;
711 }
712 p = oldp;
713 putstringn(p,1);
714 p++;
715 str = p;
716 break;
717 }
718 }
719 }
720 }
721
722 /*
723 static void borlandc_esc(char *str)
724 {
725 if(!strncmp(str,"0J",2)){
726 int oldx = wherex(), oldy = wherey();
727 int y;
728 clreol();
729 for(y=oldy+1;y<=text_info.winbottom;y++){
730 gotoxy(1,y);
731 clreol();
732 }
733 gotoxy(oldx,oldy);
734 return;
735 }
736 if(!strncmp(str,"1J",2)){
737 int oldx = wherex(), oldy = wherey();
738 int y;
739 for(y=oldy;y<=text_info.winbottom;y++){
740 gotoxy(1,y);
741 clreol();
742 }
743 gotoxy(oldx,oldy);
744 return;
745 }
746 if(!strncmp(str,"2J",2)){
747 clrscr();
748 return;
749 }
750 }
751 */
752
753 #ifdef __OLD_BORLANDC__
borlandc_esc(char * str)754 static void borlandc_esc(char *str)
755 {
756 char local[201];
757 local[0] = '\033';
758 local[1] = '[';
759 strncpy(local+2,str,sizeof(local)-3);
760 local[200] = '\0';
761 putstring_with_esc(local);
762 }
763 #endif /* __OLD_BORLANDC__ */
764
wrdt_open(char * dummy)765 static int wrdt_open(char *dummy)
766 {
767
768 wrdt.opened = 1;
769 inkey_flag = 0;
770 #ifdef __OLD_BORLANDC__
771 // highvideo();
772 borlandc_con_init();
773 esc_disablecursordisplay();
774 #endif
775 return 0;
776 }
777
wrdt_update_events(void)778 static void wrdt_update_events(void)
779 {
780 }
781
wrdt_end(void)782 static void wrdt_end(void)
783 {
784 #ifdef USE_ESC
785 printf("\033[0m\n");/*Restore Attributes*/
786 #else
787 borlandc_con_reset();
788 esc_enablecursordisplay();
789 #endif
790 #ifdef DEBUG1
791 printf("[wrdt_end]");
792 #endif
793 inkey_flag = 0;
794 }
795
wrdt_close(void)796 static void wrdt_close(void)
797 {
798 wrdt.opened = 0;
799 inkey_flag = 0;
800 }
801
wrd_event2string(int id)802 static char *wrd_event2string(int id)
803 {
804 char *name;
805
806 name = event2string(id);
807 if(name != NULL)
808 return name + 1;
809 return "";
810 }
811
wrdt_apply(int cmd,int wrd_argc,int wrd_args[])812 static void wrdt_apply(int cmd, int wrd_argc, int wrd_args[])
813 {
814 char *p;
815 char *text;
816 int i, len;
817 static txtclr_preserve=0;
818
819 switch(cmd)
820 {
821 case WRD_LYRIC:
822 p = wrd_event2string(wrd_args[0]);
823 len = strlen(p);
824 text = (char *)new_segment(&tmpbuffer, SAFE_CONVERT_LENGTH(len));
825
826 /*This must be not good thing,but as far as I know no wrd file
827 written in EUC-JP code found*/
828
829 // code_convert(p, text, SAFE_CONVERT_LENGTH(len), "SJIS", "JISK");
830 // code_convert(p, text, SAFE_CONVERT_LENGTH(len), "SJIS", "NOCV");
831 strcpy(text,p);
832 // printf("%s",text);
833 // cprintf("%s",text);
834 putstring_with_esc(text);
835 fflush(stdout);
836 reuse_mblock(&tmpbuffer);
837 break;
838 case WRD_NL: /* Newline (Ignored) */
839 putchar('\n');
840 break;
841 case WRD_COLOR:
842 /*Compatibility Hack,This remaps color(17-29 color seems
843 to be ignored in kterm)*/
844 #ifdef USE_ESC
845 txtclr_preserve=COLOR_REMAP(wrd_args[0]);
846 printf("\033[%dm", txtclr_preserve);
847 #else
848 esc_characterattribute(wrd_args[0]);
849 #endif
850 #ifdef DEBUG1
851 printf("[wrd_color]");
852 #endif
853 break;
854 case WRD_END: /* Never call */
855 break;
856 case WRD_ESC:
857 #ifdef USE_ESC
858 printf("\033[%s", wrd_event2string(wrd_args[0]));
859 #else
860 borlandc_esc(wrd_event2string(wrd_args[0]));
861 #endif
862 #ifdef DEBUG1
863 printf("[wrd_esc]");
864 #endif
865 break;
866 case WRD_EXEC:
867 /*I don't spaun another program*/
868 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
869 "@EXEC(%s)", wrd_event2string(wrd_args[0]));
870 break;
871 case WRD_FADE:
872 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
873 "@FADE(%d,%d,%d)", wrd_args[0], wrd_args[1], wrd_args[2]);
874 break;
875 case WRD_FADESTEP:
876 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
877 "@FADESTEP(%d/%d)", wrd_args[0], WRD_MAXFADESTEP);
878 break;
879 case WRD_GCIRCLE:
880 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
881 "@GCIRCLE(%d,%d,%d,%d,%d,%d)",
882 wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3],
883 wrd_args[4], wrd_args[5]);
884 break;
885 case WRD_GCLS:
886 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
887 "@GCLS(%d)", wrd_args[0]);
888 break;
889 case WRD_GINIT:
890 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "@GINIT()");
891 break;
892 case WRD_GLINE:
893 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
894 "@GLINE(%d,%d,%d,%d,%d,%d,%d)",
895 wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3], wrd_args[4],
896 wrd_args[5], wrd_args[6]);
897 fflush(stdout);
898 break;
899 case WRD_GMODE:
900 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
901 "@GMODE(%d)", wrd_args[0]);
902 break;
903 case WRD_GMOVE:
904 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
905 "@GMOVE(%d,%d,%d,%d,%d,%d,%d)",
906 wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3], wrd_args[4],
907 wrd_args[5], wrd_args[6], wrd_args[7], wrd_args[8]);
908 break;
909 case WRD_GON:
910 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
911 "@GON(%d)", wrd_args[0]);
912 break;
913 case WRD_GSCREEN:
914 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
915 "@GSCREEN(%d,%d)", wrd_args[0], wrd_args[1]);
916 break;
917 case WRD_INKEY:
918 inkey_flag = 1;
919 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "@INKEY - begin");
920 break;
921 case WRD_OUTKEY:
922 inkey_flag = 0;
923 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "@INKEY - end");
924 break;
925 case WRD_LOCATE:
926 #ifdef USE_ESC
927 printf("\033[%d;%dH", wrd_args[1], wrd_args[0]);
928 #else
929 {
930 int x = wrd_args[0], y = wrd_args[1];
931 if(x<1) x = 1;
932 if(y<1) y = 1;
933 gotoxy(x, y);
934 }
935 #endif
936 #ifdef DEBUG1
937 printf("[wrd_locate]");
938 #endif
939 break;
940 case WRD_LOOP: /* Never call */
941 break;
942 case WRD_MAG:
943 p = (char *)new_segment(&tmpbuffer, MIN_MBLOCK_SIZE);
944 strcpy(p, "@MAG(");
945 strcat(p, wrd_event2string(wrd_args[0]));
946 strcat(p, ",");
947 for(i = 1; i < 3; i++)
948 {
949 if(wrd_args[i] == WRD_NOARG)
950 strcat(p, "*,");
951 else
952 sprintf(p + strlen(p), "%d,", wrd_args[i]);
953 }
954 sprintf(p + strlen(p), "%d,%d)", wrd_args[3], wrd_args[4]);
955 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "%s", p);
956 reuse_mblock(&tmpbuffer);
957 break;
958 case WRD_MIDI: /* Never call */
959 break;
960 case WRD_OFFSET: /* Never call */
961 break;
962 case WRD_PAL:
963 p = (char *)new_segment(&tmpbuffer, MIN_MBLOCK_SIZE);
964 sprintf(p, "@PAL(%03x", wrd_args[0]);
965 for(i = 1; i < 17; i++)
966 sprintf(p + strlen(p), ",%03x", wrd_args[i]);
967 strcat(p, ")");
968 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "%s", p);
969 reuse_mblock(&tmpbuffer);
970 break;
971 case WRD_PALCHG:
972 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
973 "@PALCHG(%s)", wrd_event2string(wrd_args[0]));
974 break;
975 case WRD_PALREV:
976 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
977 "@PALREV(%d)", wrd_args[0]);
978 break;
979 case WRD_PATH:
980 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
981 "@PATH(%s)", wrd_event2string(wrd_args[0]));
982 break;
983 case WRD_PLOAD:
984 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
985 "@PLOAD(%s)", wrd_event2string(wrd_args[0]));
986 break;
987 case WRD_REM:
988 p = wrd_event2string(wrd_args[0]);
989 len = strlen(p);
990 text = (char *)new_segment(&tmpbuffer, SAFE_CONVERT_LENGTH(len));
991 code_convert(p, text, SAFE_CONVERT_LENGTH(len), NULL, NULL);
992 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "@REM %s", text);
993 reuse_mblock(&tmpbuffer);
994 break;
995 case WRD_REMARK:
996 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
997 "@REMARK(%s)", wrd_event2string(wrd_args[0]));
998 break;
999 case WRD_REST: /* Never call */
1000 break;
1001 case WRD_SCREEN: /* Not supported */
1002 break;
1003 case WRD_SCROLL:
1004 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
1005 "@SCROLL(%d,%d,%d,%d,%d,%d,%d)",
1006 wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3],
1007 wrd_args[4], wrd_args[5], wrd_args[6]);
1008 break;
1009 case WRD_STARTUP:
1010 inkey_flag = 0;
1011 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
1012 "@STARTUP(%d)", wrd_args[0]);
1013 #ifdef USE_ESC
1014 printf("\033[0m\033[H\033[J");
1015 #else
1016 esc_clearscreen();
1017 #endif
1018 #ifdef DEBUG1
1019 printf("[wrd_startup]");
1020 #endif
1021 fflush(stdout);
1022 break;
1023 case WRD_STOP: /* Never call */
1024 break;
1025
1026 case WRD_TCLS:
1027 {
1028 char fillbuf[1024];
1029 #ifdef USE_ESC
1030 fillbuf[0]=0x1b;
1031 fillbuf[1]='7';
1032 fillbuf[2]=0;
1033 printf(fillbuf);
1034 i=COLOR_REMAP(wrd_args[4]);
1035 printf("\033[%dm",i);
1036 #ifdef DEBUG1
1037 printf("[wrd_tcls_1]");
1038 #endif
1039 memset(fillbuf,wrd_args[5],wrd_args[2]-wrd_args[0]);/*X2-X1*/
1040 fillbuf[wrd_args[2]-wrd_args[0]]=0;
1041 for(i=wrd_args[1];i<=wrd_args[3];i++)/*Y1 to Y2*/
1042 printf("\033[%d;%dH%s",i,wrd_args[0],fillbuf);/*X1to....*/
1043 #ifdef DEBUG1
1044 printf("[wrd_tcls_2]");
1045 #endif
1046 fillbuf[0]=0x1b;
1047 fillbuf[1]='8';
1048 fillbuf[2]=0;
1049 printf(fillbuf);
1050 printf("\033[%dm",txtclr_preserve);
1051 #ifdef DEBUG1
1052 printf("[wrd_tcls_3]");
1053 #endif
1054 #else
1055 {
1056 int left = wrd_args[0], right = wrd_args[2];
1057 int top = wrd_args[1], bottom = wrd_args[3];
1058 CANNOC_X(left);
1059 CANNOC_X(right);
1060 CANNOC_Y(top);
1061 CANNOC_Y(bottom);
1062 if(left>right) right = left;
1063 if(top>bottom) bottom = top;
1064 memset(fillbuf,wrd_args[5],right-left);/*X2-X1*/
1065 fillbuf[right-left]=0;
1066 borlandc_con_save_attr();
1067 esc_characterattribute(wrd_args[4]);
1068 for(i=top;i<=bottom;i++)/*Y1 to Y2*/ {
1069 gotoxy(left,i);
1070 putstring(fillbuf);
1071 }
1072 borlandc_con_restore_attr();
1073 }
1074 #ifdef DEBUG1
1075 printf("[wrd_tcls]");
1076 #endif
1077 #endif
1078 fflush(stdout);
1079 }
1080 #if 0
1081 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
1082 "@TCLS(%d,%d,%d,%d,%d,%d,%d)",
1083 wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3],
1084 wrd_args[4], wrd_args[5]);
1085 #endif
1086 break;
1087 case WRD_TON:
1088 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
1089 "@TON(%d)", wrd_args[0]);
1090 break;
1091 case WRD_WAIT: /* Never call */
1092 break;
1093 case WRD_WMODE: /* Never call */
1094 break;
1095
1096 /* Ensyutsukun */
1097 case WRD_eFONTM:
1098 print_ecmd("FONTM", wrd_args, 1);
1099 break;
1100 case WRD_eFONTP:
1101 print_ecmd("FONTP", wrd_args, 4);
1102 break;
1103 case WRD_eFONTR:
1104 print_ecmd("FONTR", wrd_args, 17);
1105 break;
1106 case WRD_eGSC:
1107 print_ecmd("GSC", wrd_args, 1);
1108 break;
1109 case WRD_eLINE:
1110 print_ecmd("LINE", wrd_args, 1);
1111 break;
1112 case WRD_ePAL:
1113 print_ecmd("PAL", wrd_args, 2);
1114 break;
1115 case WRD_eREGSAVE:
1116 print_ecmd("REGSAVE", wrd_args, 17);
1117 break;
1118 case WRD_eSCROLL:
1119 print_ecmd("SCROLL",wrd_args, 2);
1120 break;
1121 case WRD_eTEXTDOT:
1122 print_ecmd("TEXTDOT", wrd_args, 1);
1123 break;
1124 case WRD_eTMODE:
1125 print_ecmd("TMODE", wrd_args, 1);
1126 break;
1127 case WRD_eTSCRL:
1128 print_ecmd("TSCRL", wrd_args, 0);
1129 break;
1130 case WRD_eVCOPY:
1131 print_ecmd("VCOPY", wrd_args, 9);
1132 break;
1133 case WRD_eVSGET:
1134 print_ecmd("VSGE", wrd_args, 4);
1135 break;
1136 case WRD_eVSRES:
1137 print_ecmd("VSRES", wrd_args, 0);
1138 break;
1139 case WRD_eXCOPY:
1140 print_ecmd("XCOPY", wrd_args, 14);
1141 break;
1142
1143 /* Extensionals */
1144 }
1145 }
1146