2 TiMidity++ -- MIDI to WAVE converter and player
3 Copyright (C) 1999-2018 Masanao Izumo <iz@onicos.co.jp>
4 Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
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.
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.
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
23 * WRD Tracer for vt100 control terminal
24 * Written by Takanori Watanabe <takawata@shidahara1.planet.kobe-u.ac.jp>
27 * WRD Tracer for Win32GUI
28 * modified for Windows console by Daisuke Aoki <dai@y7.net>
33 #endif /* HAVE_CONFIG_H */
37 #endif /* HAVE_STDLIB_H */
63 static int wrdt_open(char *dummy);
64 static void wrdt_apply(int cmd, int wrd_argc, int wrd_args[]);
65 static void wrdt_update_events(void);
66 static void wrdt_end(void);
67 static void wrdt_close(void);
68 #define NO_GRAPHIC_SUPPORT
69 #define wrdt w32g_wrdt_mode
70 #define COLOR_REMAP(k) ((k)>16) &&((k)<30)?(k)+14:k
74 "Windows Console WRD tracer", 'w',
86 static int wrd_args[WRD_MAXPARAM];
87 static int inkey_flag;
89 static void putstring(char *str)
91 WrdWndPutString(str,TRUE);
94 static void putstringn(char *str, int n)
96 WrdWndPutStringN(str,n,TRUE);
101 static void esc_index(void)
103 w32g_wrd_wnd.curposy++;
104 if ( w32g_wrd_wnd.curposy >= w32g_wrd_wnd.col ) {
105 WrdWndScrollUp(TRUE);
106 w32g_wrd_wnd.curposy = w32g_wrd_wnd.col - 1;
110 void esc_nextline(void)
112 w32g_wrd_wnd.curposx = 0;
113 w32g_wrd_wnd.curposy++;
114 if ( w32g_wrd_wnd.curposy >= w32g_wrd_wnd.col ) {
115 WrdWndScrollUp(TRUE);
116 w32g_wrd_wnd.curposy = w32g_wrd_wnd.col - 1;
120 void esc_reverseindex(void)
122 w32g_wrd_wnd.curposy--;
123 if ( w32g_wrd_wnd.curposy < 0 ) {
124 WrdWndScrollDown(TRUE);
128 void esc_clearscreen(void)
133 void esc_directcursoraddressing(int x, int y)
135 WrdWndGoto( x-1, y-1 );
138 void esc_cursorup(int n)
141 WrdWndGoto( w32g_wrd_wnd.curposx, w32g_wrd_wnd.curposy - n );
144 void esc_cursordown(int n)
147 WrdWndGoto( w32g_wrd_wnd.curposx, w32g_wrd_wnd.curposy + n );
150 void esc_cursorforward(int n)
153 WrdWndGoto( w32g_wrd_wnd.curposx - n , w32g_wrd_wnd.curposy );
156 void esc_cursorbackward(int n)
159 WrdWndGoto( w32g_wrd_wnd.curposx + n , w32g_wrd_wnd.curposy );
162 void esc_clearfromcursortoendofscreen(void)
164 WrdWndLineClearFrom(FALSE, TRUE);
165 WrdWndClearLineFromTo(w32g_wrd_wnd.curposy + 1, w32g_wrd_wnd.col - 1, TRUE);
168 void esc_clearfrombeginningofscreentocursor(void)
170 WrdWndClearLineFromTo(0,w32g_wrd_wnd.curposy - 1, TRUE);
171 WrdWndLineClearFrom(TRUE, TRUE);
174 void esc_clearfromcursortoendofline(void)
176 WrdWndLineClearFrom(FALSE, TRUE);
179 void esc_clearfrombeginningoflinetocursor(void)
181 WrdWndLineClearFrom(TRUE, TRUE);
184 void esc_clearentirelinecontainingcursor(void)
186 WrdWndClearLineFromTo( w32g_wrd_wnd.curposy, w32g_wrd_wnd.curposy, TRUE );
189 void esc_deleteline(int n)
193 if ( w32g_wrd_wnd.curposy + n >= w32g_wrd_wnd.col )
194 n = w32g_wrd_wnd.col - 1 - w32g_wrd_wnd.curposy;
196 for ( i = w32g_wrd_wnd.curposy; i < w32g_wrd_wnd.curposy + n; i++ ) {
197 WrdWndMoveLine(i+n,i,TRUE);
199 WrdWndClearLineFromTo(w32g_wrd_wnd.col - n, w32g_wrd_wnd.col - 1, TRUE);
200 w32g_wrd_wnd.curposx = 0;
203 void esc_insertline(int n)
207 if ( w32g_wrd_wnd.curposy + n >= w32g_wrd_wnd.col )
208 n = w32g_wrd_wnd.col - 1 - w32g_wrd_wnd.curposy;
210 for ( i = w32g_wrd_wnd.col - n - 1; i >= w32g_wrd_wnd.curposy; i-- ) {
211 WrdWndMoveLine(i,i+n,TRUE);
213 w32g_wrd_wnd.curposx = 0;
216 static volatile int saved_x;
217 static volatile int saved_y;
218 static volatile int saved_attr;
219 void esc_savecursorposition(void)
221 WrdWndCurStateSaveAndRestore(1);
225 void esc_setcursorposition(void)
227 WrdWndCurStateSaveAndRestore(0);
231 void esc_enablecursordisplay(void)
236 void esc_disablecursordisplay(void)
241 void esc_characterattribute(int n)
247 static int getdigit(char *str,int *num)
252 if (str[i] < '0' || str[i] > '9') {
258 strncpy(local,str,i);
264 extern int gdi_lock(void);
265 extern int gdi_unlock(void);
266 static void putstring_with_esc(char *str)
274 if ((unsigned char) *p >= 0x20) {
279 WrdWndPutStringN(str,p-str,TRUE);
290 if (*p == '\r' && *(p+1) == '\n') {
296 WrdWndPutStringN ( " ", 8, TRUE );
305 int res, n[1024], n_max = 0;
311 res = getdigit(p,&(n[n_max+1]));
321 } else if (*p == 'D') {
326 } else if (*p == 'E') {
331 } else if (*p == 'M') {
336 } else if (*p == '*') {
344 WrdWndPutStringN(str,p-str,TRUE);
350 if (n_max == 2 && (*p == 'H' || *p == 'f')) {
351 esc_directcursoraddressing(n[2],n[1]);
356 if ((n_max == 1 && *p == 'A') || (n_max == 0 && *p == 'A')) {
364 if ((n_max == 1 && *p == 'B') || (n_max == 0 && *p == 'B')) {
367 esc_cursordown(n[1]);
372 if ((n_max == 1 && *p == 'C') || (n_max == 0 && *p == 'C')) {
375 esc_cursorforward(n[1]);
380 if ((n_max == 1 && *p == 'D') || (n_max == 0 && *p == 'D')) {
383 esc_cursorbackward(n[1]);
388 if ((n_max == 1 && *p == 'J') || (n_max == 0 && *p == 'J')) {
389 if (n_max == 0 || n[1] == 0)
390 esc_clearfromcursortoendofscreen();
392 esc_clearfrombeginningofscreentocursor();
399 if ((n_max == 1 && *p == 'K') || (n_max == 0 && *p == 'K')) {
400 if (n_max == 0 || n[1] == 0)
401 esc_clearfromcursortoendofline();
403 esc_clearfrombeginningoflinetocursor();
405 esc_clearentirelinecontainingcursor();
410 if ((n_max == 1 && *p == 'M') || (n_max == 0 && *p == 'M')) {
413 esc_deleteline(n[1]);
418 if ((n_max == 1 && *p == 'L') || (n_max == 0 && *p == 'L')) {
421 esc_insertline(n[1]);
426 if (n_max == 0 && *p == 's') {
427 esc_savecursorposition();
432 if (n_max == 0 && *p == 'u') {
433 esc_setcursorposition();
438 if (!strncmp(p,">5l",3)) {
439 esc_enablecursordisplay();
444 if (!strncmp(p,">5h",3)) {
445 esc_disablecursordisplay();
450 if (!strncmp(p,">1h",3)) {
451 /* Enabel bottom line */
456 if (!strncmp(p,">1l",3)) {
457 /* Disabel bottom line */
462 if (!strncmp(p,">3h",3)) {
463 /* Select 31 line mode */
468 if (!strncmp(p,">3l",3)) {
469 /* Select 25 line mode */
476 for (i=1;i<=n_max;i++)
477 esc_characterattribute(n[i]);
483 WrdWndPutStringN(p,1,TRUE);
493 static int wrdt_open(char *dummy)
501 static void wrdt_update_events(void)
505 static void wrdt_end(void)
507 esc_enablecursordisplay();
512 static void wrdt_close(void)
518 static const char *wrd_event2string(int id)
522 name = event2string(id);
528 #define SEIKIX(x) { \
529 if ( x < 1 ) x = 1; \
530 if ( x > w32g_wrd_wnd.row ) x = w32g_wrd_wnd.row; \
532 #define SEIKIY(y) { \
533 if ( y < 1 ) y = 1; \
534 if ( y > w32g_wrd_wnd.col ) y = w32g_wrd_wnd.col; \
537 static void borlandc_esc(char *str)
542 strncpy(local+2,str,sizeof(local) -3);
544 putstring_with_esc(local);
547 extern void wrd_graphic_ginit ( void );
548 extern void wrd_graphic_gcls ( int sw );
549 extern void wrd_graphic_gscreen ( int active, int display );
550 extern void wrd_graphic_gon ( int sw );
551 extern void wrd_graphic_gline ( int x1, int y1, int x2, int y2, int p1, int sw, int p2 );
552 extern void wrd_graphic_gcircle ( int x, int y, int r, int p1, int sw, int p2 );
553 extern void wrd_graphic_pload ( char *path );
554 extern void wrd_graphic_pal_g4r4b4 ( int p, int *g4r4b4, int max );
555 extern void wrd_graphic_palrev ( int p );
556 extern void wrd_graphic_apply_pal ( int p );
557 extern void wrd_graphic_fade ( int p1, int p2, int speed );
558 extern void wrd_graphic_fadestep ( int v );
559 extern void wrd_graphic_gmode ( int sw );
560 extern void wrd_graphic_gmove ( int x1, int y1, int x2, int y2, int xd, int yd, int vs, int vd, int sw );
561 extern void wrd_graphic_mag ( char *path, int x, int y, int s, int p );
562 extern void wrd_text_ton ( int sw );
563 extern void wrd_text_scroll ( int x1, int y1, int x2, int y2, int mode, int color, int c );
564 extern void wrd_start_skip ( void );
565 extern void wrd_end_skip ( void );
566 extern void wrd_graphic_xcopy ( int sx1, int sy1, int sx2, int sy2, int tx, int ty, int ss, int ts, int method,
567 int opt1, int opt2, int opt3, int opt4, int opt5 );
569 // #define WRD_VERBOSE
570 static void wrdt_apply(int cmd, int wrd_argc, int wrd_args[])
575 static txtclr_preserve = 0;
577 if ( !w32g_wrd_wnd.active ) return;
582 p = strdup_mblock(&tmpbuffer, wrd_event2string(wrd_args[0]));
584 text = (char*) new_segment(&tmpbuffer, SAFE_CONVERT_LENGTH(len));
586 /*This must be not good thing,but as far as I know no wrd file
587 written in EUC-JP code found*/
591 // ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
592 // "[WRD_LYRIC]\n%s", text );
594 putstring_with_esc(text);
595 reuse_mblock(&tmpbuffer);
597 case WRD_NL: /* Newline (Ignored) */
602 /*Compatibility Hack,This remaps color(17-29 color seems
603 to be ignored in kterm) */
604 esc_characterattribute(wrd_args[0]);
606 case WRD_END: /* Never call */
609 borlandc_esc(wrd_event2string(wrd_args[0]));
612 /*I don't spaun another program*/
613 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
614 "@EXEC(%s)", wrd_event2string(wrd_args[0]));
617 wrd_graphic_fade ( wrd_args[0], wrd_args[1], wrd_args[2] );
619 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
620 "@FADE(%d,%d,%d)", wrd_args[0], wrd_args[1], wrd_args[2]);
624 wrd_graphic_fadestep ( wrd_args[0] );
626 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
627 "@FADESTEP(%d/%d)", wrd_args[0], WRD_MAXFADESTEP);
631 wrd_graphic_gcircle ( wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3],
632 wrd_args[4], wrd_args[5] );
633 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
634 "@GCIRCLE(%d,%d,%d,%d,%d,%d)",
635 wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3],
636 wrd_args[4], wrd_args[5]);
639 wrd_graphic_gcls ( wrd_args[0] );
641 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
642 "@GCLS(%d)", wrd_args[0]);
646 wrd_graphic_ginit ();
648 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "@GINIT()");
652 wrd_graphic_gline ( wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3], wrd_args[4],
653 wrd_args[5], wrd_args[6] );
655 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
656 "@GLINE(%d,%d,%d,%d,%d,%d,%d)",
657 wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3], wrd_args[4],
658 wrd_args[5], wrd_args[6]);
662 wrd_graphic_gmode ( wrd_args[0] );
664 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
665 "@GMODE(%d)", wrd_args[0]);
669 wrd_graphic_gmove ( wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3], wrd_args[4],
670 wrd_args[5], wrd_args[6], wrd_args[7], wrd_args[8] );
672 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
673 "@GMOVE(%d,%d,%d,%d,%d,%d,%d)",
674 wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3], wrd_args[4],
675 wrd_args[5], wrd_args[6], wrd_args[7], wrd_args[8]);
679 wrd_graphic_gon ( wrd_args[0] );
681 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
682 "@GON(%d)", wrd_args[0]);
686 wrd_graphic_gscreen ( wrd_args[0], wrd_args[1] );
688 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
689 "@GSCREEN(%d,%d)", wrd_args[0], wrd_args[1]);
694 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "@INKEY - begin");
698 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "@INKEY - end");
702 int x = wrd_args[0], y = wrd_args[1];
703 WrdWndGoto(x-1, y-1);
706 case WRD_LOOP: /* Never call */
709 wrd_graphic_mag ( wrd_event2string(wrd_args[0]), wrd_args[1], wrd_args[2], wrd_args[3], wrd_args[4]);
711 p = (char*) new_segment(&tmpbuffer, MIN_MBLOCK_SIZE);
712 snprintf(p, MIN_MBLOCK_SIZE-1, "@MAG(%s", wrd_event2string(wrd_args[0]));
713 p[MIN_MBLOCK_SIZE-1] = '\0'; /* fail safe */
714 for (i = 1; i < 5; i++)
716 if (wrd_args[i] == WRD_NOARG)
717 strncat(p, ",*", MIN_MBLOCK_SIZE - strlen(p) - 1);
719 char q[CHAR_BIT*sizeof(int)];
720 snprintf(q, sizeof(q) -1, ",%d", wrd_args[i]);
721 strncat(p, q, MIN_MBLOCK_SIZE - strlen(p) - 1);
724 strncat(p, ")", MIN_MBLOCK_SIZE - strlen(p) - 1);
725 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "%s", p);
726 reuse_mblock(&tmpbuffer);
729 case WRD_MIDI: /* Never call */
731 case WRD_OFFSET: /* Never call */
734 wrd_graphic_pal_g4r4b4 (wrd_args[0], wrd_args + 1, 16 );
736 p = (char*) new_segment(&tmpbuffer, MIN_MBLOCK_SIZE);
737 snprintf(p, MIN_MBLOCK_SIZE, "@PAL(%03x", wrd_args[0]);
738 for (i = 1; i < 17; i++) {
740 snprintf(q, sizeof(q) -1, ",%03x", wrd_args[i]);
741 strncat(p, q, MIN_MBLOCK_SIZE - strlen(p) - 1);
743 strncat(p, ")", MIN_MBLOCK_SIZE - strlen(p) - 1);
744 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "%s", p);
745 reuse_mblock(&tmpbuffer);
749 wrd_graphic_apply_pal ( wrd_args[0] );
751 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
752 "@PALCHG(%s)", wrd_event2string(wrd_args[0]));
756 wrd_graphic_palrev ( wrd_args[0] );
758 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
759 "@PALREV(%d)", wrd_args[0]);
763 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
764 "@PATH(%s)", wrd_event2string(wrd_args[0]));
767 wrd_graphic_pload ( wrd_event2string(wrd_args[0]) );
769 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
770 "@PLOAD(%s)", wrd_event2string(wrd_args[0]));
774 p = strdup_mblock(&tmpbuffer, wrd_event2string(wrd_args[0]));
776 text = (char*) new_segment(&tmpbuffer, SAFE_CONVERT_LENGTH(len));
777 code_convert(p, text, SAFE_CONVERT_LENGTH(len), NULL, NULL);
778 ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "@REM %s", text);
779 reuse_mblock(&tmpbuffer);
782 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
783 "@REMARK(%s)", wrd_event2string(wrd_args[0]));
785 case WRD_REST: /* Never call */
787 case WRD_SCREEN: /* Not supported */
790 wrd_text_scroll (wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3],
791 wrd_args[4], wrd_args[5], wrd_args[6]);
793 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
794 "@SCROLL(%d,%d,%d,%d,%d,%d,%d)",
795 wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3],
796 wrd_args[4], wrd_args[5], wrd_args[6]);
803 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
804 "@STARTUP(%d)", wrd_args[0]);
808 case WRD_STOP: /* Never call */
815 int left = wrd_args[0], right = wrd_args[2];
816 int top = wrd_args[1], bottom = wrd_args[3];
822 if (left>right) right = left;
823 if (top>bottom) bottom = top;
824 memset(fillbuf,wrd_args[5],right-left);/*X2-X1*/
825 fillbuf[right-left]=0;
826 // borlandc_con_save_attr();
827 esc_characterattribute(wrd_args[4]);
828 for (i=top;i<=bottom;i++)/*Y1 to Y2*/ {
829 WrdWndGoto(left-1,i-1);
832 // borlandc_con_restore_attr();
837 wrd_text_ton ( wrd_args[0] );
838 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
839 "@TON(%d)", wrd_args[0]);
841 case WRD_WAIT: /* Never call */
843 case WRD_WMODE: /* Never call */
848 print_ecmd("FONTM", wrd_args, 1);
851 print_ecmd("FONTP", wrd_args, 4);
854 print_ecmd("FONTR", wrd_args, 17);
857 print_ecmd("GSC", wrd_args, 1);
860 print_ecmd("LINE", wrd_args, 1);
863 print_ecmd("PAL", wrd_args, 2);
866 print_ecmd("REGSAVE", wrd_args, 17);
869 print_ecmd("SCROLL",wrd_args, 2);
872 print_ecmd("TEXTDOT", wrd_args, 1);
875 print_ecmd("TMODE", wrd_args, 1);
878 print_ecmd("TSCRL", wrd_args, 0);
881 print_ecmd("VCOPY", wrd_args, 9);
884 print_ecmd("VSGE", wrd_args, 4);
887 print_ecmd("VSRES", wrd_args, 0);
890 wrd_graphic_xcopy ( wrd_args[0], wrd_args[1], wrd_args[2], wrd_args[3], wrd_args[4], wrd_args[5], wrd_args[6],
891 wrd_args[7], wrd_args[8], wrd_args[9], wrd_args[10], wrd_args[11], wrd_args[12], wrd_args[13] );
892 print_ecmd("XCOPY", wrd_args, 14);
897 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
904 ctl->cmsg(CMSG_INFO, VERB_VERBOSE,