OSDN Git Service

最初のコミット
[winaudioj/stedx.git] / exclu.cpp
1 /*
2  * STed: exclu.c (selecter)
3  */
4
5 #include        "sted.h"
6
7 static  char    uxcc[5][3]={"gt","ve","ch","cs","ss"};
8 static  char    dotp[4][3]={"・","・","・","・"};
9
10 static unsigned char    dotpat[32][32];
11 /***************************/
12 void    user_exc_as(int no)
13 {
14   int   gy,ke,kc,sh,i,x=0,y=no*2,yy,nn,mm,a,cc;
15
16   gy=scyp;
17 top:
18   fill(0,512+32,767,1023,0);
19   box(47,47+512,688+24,458+512,14,65535);
20   fill(47,63+512,73,458+512,14);
21   sdis(6,48+512," USER DEFINE EXCLUSIVE",80+3,15,14);
22   home2(512);fnc_dis(4+3);
23   /*
24     [F1] gt : SEND GATE POSITION DATA   [F4] cs : CLEAR CHECK SUM
25     [F2] ve : SEND VELO POSITION DATA   [F5] ss : SEND CHECK SUM
26     [F3] ch : SEND CHANNLE No.          [F6] F7 : END OF EXCLUSIVE
27     */
28
29   for(i=0;i<7;i++){line(47,520+7*16+i*48,688+24,520+7*16+i*48,14,65535);}
30 redis:
31   for(i=0;i<8;i++){
32     B_LOCATE(6,5+i*3);B_PRINT(fstr(i,2));
33     B_PRINT("  MEMO:");B_PRINT(user_exc_memo[i]);
34     B_LOCATE(39,5+i*3);B_PRINT("|");
35     user_exc_dis(i);
36   }
37
38   while( 1){
39     nn=y>>1;mm=y&1;yy=nn*3+mm+5;cc=3;
40     B_LOCATE(50,3);
41     if(mm==0){
42       B_PRINT("---");
43       tcur(15,yy,24,3);
44     }else{
45       a=user_exc_data[nn][x];
46       if(a>0x7f){cc=1;B_PRINT("---");}else{B_PRINT(fstr(a,3));}
47       tcur(13+x*3,yy,4,cc);
48     }
49
50     /*while(B_KEYSNS()==0){}*/ /* Jun.28.1998 Daisuke Nagano */
51     key_wait();
52     ke=B_KEYINP();kc=ke & 0xff;ke=ke>>8;sh=B_SFTSNS();
53     if(kc>='a' && kc<='z'){kc-=32;}
54     if(mm==0){tcur(15,yy,24,3);}else{tcur(13+x*3,yy,4,cc);}
55
56
57     if( (ke>=0x40 && ke<=0x51) && (sh&4)!=0 ){
58       int       j;
59
60       static char tk[18]={13,14,15,7,8,9,16,4,5,6,17,1,2,3,18,10,11,12};
61
62       j=tk[ke-0x40];
63       if( j>0 && j<=7){y=j*2;kc=0;ke=0;}
64     }
65
66
67     if( ke==1 ){break;}
68     if( ke==0x3f ){
69       msg(_("Init all exclusive data"));
70       if(yn_sel()>0){msg_clr();user_exc_init();C_CLS_AL();goto redis;}
71     }
72     if( kc==32 ){
73       user_exc_init2(nn);C_CLS_AL();goto redis;
74     }
75     if( kc==13 ){
76       if(sh&1){
77         if(mm!=0){
78           excins(user_exc_data[nn],23,x);
79           user_exc_data[nn][x]=0;
80           user_exc_dis(nn);
81         }
82       }else{
83         if(mm==0){
84           B_LOCATE(15,yy);sinput(user_exc_memo[nn],24);
85           fnc_dis(4+3);
86         }else{
87           int   c;
88           B_LOCATE(14+x*3,yy);
89           c=vinput(0,0x2003);
90           if(es==0 && c>=0 && c<128){
91             excins(user_exc_data[nn],23,x);
92             user_exc_data[nn][x]=c;
93           }
94           user_exc_dis(nn);ke=0x3d;kc=0;
95         }
96       }
97     }
98
99     if(mm!=0){
100       if((kc>='0'&& kc<='9')||(kc>='A'&& kc<='F')){
101         int     c,cc;
102         B_LOCATE(14+x*3,yy);
103         if(kc<'A'){cc=kc-'0';}else{cc=kc-'A'+10;}
104         c=vinput(cc,0x2003);
105
106         if(es==0 && c>=0 && c<128){
107           if( (B_SFTSNS()&4096)!=0 || user_exc_data[nn][x]==0xf7){
108             excins(user_exc_data[nn],23,x);
109           }
110           user_exc_data[nn][x]=c;
111           ke=0x3d;kc=0;
112         }
113         user_exc_dis(nn);
114       }
115       if((kc=='+' || kc=='.' || kc=='>') && a<128){
116         if( kc=='>' ){a+=16;}else{a++;}
117         user_exc_data[nn][x]=a&127;
118         user_exc_dis(nn);ke=0;kc=0;
119       }
120       if((kc=='-' || kc==',' || kc=='<') && a<128 ){
121         if( kc=='<' ){a+=112;}else{a+=127;}
122         user_exc_data[nn][x]=a&127;
123         user_exc_dis(nn);ke=0;kc=0;
124       }
125
126       if( ke==0x37 || kc==7 ){
127         excdel(user_exc_data[nn],23,x);
128         user_exc_data[nn][23]=0xf7;
129         user_exc_dis(nn);
130       }
131       if( x>0 &&(ke==0x0f ||kc==8)){
132         x--;
133         excdel(user_exc_data[nn],23,x);
134         user_exc_data[nn][23]=0xf7;
135         user_exc_dis(nn);
136       }
137       if( ke>=0x63 && ke<=0x67){
138         excins(user_exc_data[nn],23,x);
139         user_exc_data[nn][x]=ke-0x63+0x80;
140         user_exc_dis(nn);
141       }
142       if( ke==0x68){
143         user_exc_data[nn][x]=0xf7;
144         user_exc_dis(nn);
145       }
146
147       if( ke==0x6a && x>5){
148         excins(user_exc_data[nn],23,x);
149         excsum(user_exc_data[nn],x);
150         user_exc_dis(nn);
151       }
152
153       if( ke==0x10 /*|| ke==0x35*/ ){
154         unsigned char c=user_exc_data[nn][x];
155         excins(user_exc_data[nn],23,x);
156         user_exc_data[nn][x]=c;
157         user_exc_dis(nn);
158       }
159
160     }
161
162     if( kc=='U' || kc=='u' ){
163       int       c,i;
164       msg("User Exc. No.=");
165       c=vinput(0,0x803);msg_clr();
166       if(es==0 && c>=0 && c<8){
167         for(i=0;i<24;i++){
168           user_exc_data[nn][i]=user_exc_data[c][i];
169           user_exc_memo[nn][i]=user_exc_memo[c][i];
170         }
171         goto redis;
172       }
173     }
174
175     if( ke==0x6b ){
176       char      tmp0[256],tmp1[256],path2[256];
177
178       C_CLS_AL();
179
180       strcpy(path2,prt_path);tmp1[0]=0;
181       fsel(tmp1,path2,0x009+(sh&1));
182       if( es==0 && tmp1[0]!=0){
183         int ec;
184         strcpy(tmp0,path2);strcat(tmp0,tmp1);
185
186         msg(_("Loading Usr.Exc. file."));
187         if((sh&1)==0){
188           ec=rex_load(tmp0,-1);
189         }else{
190           ec=rex_load(tmp0,nn);
191         }
192         if(ec==0 ){msg_clr();
193         if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
194         }
195       }
196       goto top;
197     }
198     if( ke==0x6c ){
199       char      tmp0[256],tmp1[256],path2[256];
200
201       C_CLS_AL();
202
203       strcpy(path2,prt_path);tmp1[0]=0;
204       fsel(tmp1,path2,0x109+(sh&1));
205       if( es==0 && tmp1[0]!=0){
206         int     ec;
207         strcpy(tmp0,path2);strcat(tmp0,tmp1);
208
209         msg(_("Saving Usr.Exc. file."));
210         if((sh&1)==0){
211           ec=rex_save(tmp0,-1);
212         }else{
213           ec=rex_save(tmp0,nn);
214         }
215         if(ec==0 ){msg_clr();
216         if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
217         }
218       }
219       goto top;
220     }
221
222     if( kc==0x13 || ke==0x3b){x--;if(x<0){x=23;}}
223     if( kc==0x04 || ke==0x3d){x++;if(x>23){x=0;}}
224     if( kc==0x05 || ke==0x3c){y--;if(y<0){y=15;}}
225     if( kc==0x18 || ke==0x3e){y++;if(y>15){y=0;}}
226
227   }
228   fnc_dis(-1);C_CLS_AL();home2(gy);
229 }
230
231 /***************************/
232 void    user_exc_dis(int no)
233 {
234   int   i,a;
235
236   B_LOCATE(11,6+no*3);
237   B_COLOR(9);B_PRINT("F0");B_COLOR(3);
238
239   i=0;
240   while(i<24 && user_exc_data[no][i]!=0xf7){
241     B_PRINT(" ");
242     a=user_exc_data[no][i++];
243
244     if(a>=0x80 && a<=0x84){
245       B_COLOR(1);B_PRINT(uxcc[a-0x80]);
246     }else{
247       B_COLOR(3);B_PRINT(hex_s(a,2));
248     }
249
250   }
251   B_PRINT(" ");B_COLOR(9);B_PRINT("F7");B_COLOR(1);
252   while(i<24 ){user_exc_data[no][i++]=0xf7;B_PRINT(" ..");}
253   B_COLOR(3);snsclr();
254 }
255
256 /***************************/
257 void    exc_edit(int ad,int cy,int sw)
258 {
259   int   ke,sh,kc,i,x=0,y=0,cx,gx,a,cc,co,po,nn;
260   int   e=edit_scr;
261   unsigned char *buf;buf=dat+(16*1024);
262
263   trk_dis(cy+6,ad,24-cy);
264
265   if(edit_scr==0){cx=41;gx=328;}else{cx=1;gx=8;}
266   cons_md(0);noed_cls();edit_scr=0;
267
268 top0:
269   for(i=0;i<32*1024;i++){dat[i]=0xf7;}
270
271   po=ad;co=0;
272   while(trk[track][po+4]==0xf7){po+=4;
273   dat[co]=trk[track][po+2];if(dat[co]==0xf7){break;}
274   co++;
275   dat[co]=trk[track][po+3];if(dat[co]==0xf7){break;}
276   co++;
277   }
278
279 top:
280   box(gx-1,624-48,gx+417+16,997,14,65535);
281   fill(gx,639-32,gx+15,996,8);
282   fill(gx,639-40,gx+416+16,639-16-8,8);
283   sdis(cx,624-48," TRACK EXCLUSIVE EDIT",54,15,14);
284   for(i=0;i<22;i++){tdis(cx,7+i,hex_s(i,2),2,3);}
285   for(i=0;i<16;i++){sdis(cx+i*3+7,512+6*16-8,hex_s(i,1),1,3,8);}
286   fnc_dis(4);
287
288   if(sw&6){co=dot_ed(cx,co);ke=0;goto ext;}
289
290   exc_dis(i,cx,co,0);
291
292   while( 1){
293     cc=3;nn=y*16+x;
294     a=dat[nn];
295
296     B_LOCATE(cx+29,4);if(a>0x7f){cc=1;B_PRINT("---");}else{B_PRINT(fstr(a,3));}
297
298     tcur(cx+5+x*3,y+7,4,cc);
299     /*while(B_KEYSNS()==0){}*/ /* Jun.28.1998 Daisuke Nagano */
300     key_wait();
301     ke=B_KEYINP();kc=ke & 0xff;ke=ke>>8;sh=B_SFTSNS();
302     if(kc>='a' && kc<='z'){kc-=32;}
303     tcur(cx+5+x*3,y+7,4,cc);
304
305     if( ke==1 ){break;}
306
307     if( kc==13 ){
308       if(sh&1){
309         excins(dat,co,nn);
310         dat[nn]=0;co++;
311         exc_dis(y,cx,co,1);ke=0x3d;kc=0;
312       }else{
313         if( co<256+96 && nn<=co ){
314           int   c;
315           B_LOCATE(cx+5+x*3,y+7);
316           c=vinput(0,0x2003);
317           if(es==0 && c>=0 && c<128){
318             excins(dat,co,nn);
319             dat[nn]=c;co++;
320           }
321           exc_dis(y,cx,co,1);ke=0x3d;kc=0;
322         }
323       }
324     }
325
326     if(((kc>='0'&& kc<='9')||(kc>='A'&& kc<='F'))&& co<256+96 && nn<=co){
327       int       c,cc;
328       B_LOCATE(cx+5+x*3,y+7);
329       if(kc<'A'){cc=kc-'0';}else{cc=kc-'A'+10;}
330       c=vinput(cc,0x2003);
331
332       if(es==0 && c>=0 && c<128){
333         if( (B_SFTSNS()&4096)!=0 || dat[nn]==0xf7){
334           excins(dat,co,nn);co++;
335         }
336         dat[nn]=c;
337         ke=0x3d;kc=0;
338       }
339       exc_dis(y,cx,co,1);
340     }
341
342     if((kc=='+' || kc=='.' || kc=='>') && a<128){
343       if( kc=='>' ){a+=10;}else{a++;}
344       dat[nn]=a&127;
345       exc_dis(y,cx,co,2);ke=0;kc=0;
346     }
347     if((kc=='-' || kc==',' || kc=='<') && a<128){
348       if( kc=='<' ){a+=118;}else{a+=127;}
349       dat[nn]=a&127;
350       exc_dis(y,cx,co,2);ke=0;kc=0;
351     }
352
353     if( ke==0x37 || kc==7 ){
354       excdel(dat,co,nn);
355       if(nn<co){co--;dat[co]=0xf7;}
356       exc_dis(y,cx,co,1);
357     }
358     if( nn>0 && (ke==0x0f || kc==8)){
359       nn--;
360       excdel(dat,co,nn);
361       if(nn<co){co--;dat[co]=0xf7;}
362       exc_dis(y,cx,co,1);ke=0x3b;
363     }
364     if( ke>=0x63 && ke<=0x67 && co<256+96){
365       excins(dat,co,nn);
366       dat[nn]=ke-0x63+0x80;
367
368       if(nn<co+1){co++;}
369       exc_dis(y,cx,co,1);
370     }
371     if( ke==0x68){
372       dat[y*16+x]=0xf7;exc_dis(y,cx,co,0);
373     }
374     if( ke==0x6a && co<256+96 && nn>5){
375       excins(dat,co,nn);
376       excsum(dat,nn);
377       if(nn<co+1){co++;}
378       exc_dis(y,cx,co,1);
379     }
380
381     if( ke==0x10 && co<256+96){
382       unsigned char c=dat[nn];
383       excins(dat,co,nn);
384       dat[nn]=c;
385       if(nn<co+1){co++;}
386       exc_dis(y,cx,co,1);
387     }
388
389     if( kc=='$' && co<256+96){
390       char      tmp0[64];
391       int       i=0;
392
393       tmp0[0]=0;
394       msg("strings:");sinput(tmp0,0x8000+32);
395       if( es==0 && tmp0[0]!=0){
396         while(tmp0[i]!=0 && co<256+96){
397           excins(dat,co,nn);
398           if(tmp0[i]<32){dat[nn]=32;}else{dat[nn]=tmp0[i];}
399
400           if(nn<co+1){co++;}
401           i++;
402           exc_dis(y,cx,co,1);
403
404           x++;
405           if(x>15){if(y<21){x=0;y++;}else{x=15;}}
406           nn=y*16+x;
407         }
408       }
409     }
410
411     if( kc=='^' || ke==0x34 ){co=dot_ed(cx,co);x=0;y=0;goto top;}
412
413     if( kc=='U' || kc=='u' ){
414       int       c,i;
415       msg("User Exc. No.=");
416       c=vinput(0,0x803);msg_clr();
417       if(es==0 && c>=0 && c<8){
418         for(i=0;i<24;i++){
419           dat[i]=user_exc_data[c][i];
420         }
421         dat[24]=0xf7;
422
423         co=0;
424         while( dat[co] != 0xf7 && co<24) {co++;}
425         dat[co++]=0xf7;
426
427         goto top;
428       }
429     }
430
431     if( ke==0x6b ){
432       char      tmp0[256],tmp1[256],path2[256];
433
434       txerase(cx*8,4*16,53*8,26*16);
435
436       strcpy(path2,prt_path);tmp1[0]=0;
437       fsel(tmp1,path2,0x008+e*0x200);
438       if( es==0 && tmp1[0]!=0){
439         int ec;
440         strcpy(tmp0,path2);strcat(tmp0,tmp1);
441
442         msg(_("Loading Exclusive file."));
443         ec=exc_load(tmp0);
444         if(ec>=0 ){msg_clr();
445         if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
446         co=ec;ke=0xff;break;}
447       }
448       goto top;
449     }
450     if( ke==0x6c ){
451       char      tmp0[256],tmp1[256],path2[256];
452
453       txerase(cx*8,4*16,53*8,26*16);
454
455       strcpy(path2,prt_path);tmp1[0]=0;
456       fsel(tmp1,path2,0x108+e*0x200);
457       if( es==0 && tmp1[0]!=0){
458         int ec;
459         strcpy(tmp0,path2);strcat(tmp0,tmp1);
460
461         msg(_("Saving Exclusive."));
462         ec=exc_save(tmp0,co);
463         if(ec>=0 ){msg_clr();
464         if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
465         }
466       }
467       goto top;
468     }
469     /*
470       if( kc=='R' || kc=='r' ){
471       int ec;
472
473       msg("MIDI IN Exclusive INPUT");
474
475       ec=exc_rec();
476       if(ec>=0 ){msg_clr();
477       co=ec;ke=0xff;break;}
478
479       goto top;
480       }
481       */
482
483     if( ke==0x3a && co>0){break;}
484
485     if( ke==0x36){x=0;y=0;}
486
487
488
489     if(kc=='@'){
490       /*
491         0x10 0x01~5 0x00 / 0x10 0x01~5 0x40
492         */
493       if( dat[0]==0x41 && dat[1]==0x10 && dat[2]==0x45 && dat[3]==0x12 &&
494           dat[4]==0x83 && dat[5]==0x10 ){
495         if(dat[7]==0x00){
496           if(dat[6]>0){
497             prn_gspanel(cx);scpanel_dsp(cx+13,18,&dat[8]);
498           }else{
499             prn_gspanel(cx);scinst_dsp(cx+13,16,&dat[8]);
500           }
501           while(inkey2()==0){}
502           goto top;
503         }
504       }
505     }
506
507
508
509     if( kc==0x13 || ke==0x3b){x--;
510     if(x<0){if(y>0){x=15;ke=0x3c;}else{x=0;}}
511     }
512     if( kc==0x04 || ke==0x3d){x++;
513     if(x>15){if(y<21){x=0;ke=0x3e;}else{x=15;}}
514     }
515     if( kc==0x05 || ke==0x3c){y--;if(y<0){y=21;}}
516     if( kc==0x18 || ke==0x3e){y++;if(y>21){y=0;}}
517   }
518 ext:
519
520   dat[co]=0xf7;co++;if(co&1){dat[co]=0xf7;co++;}
521   if(dat[0]==0xf7){co=0;}
522   po=ad;cc=0;while(trk[track][po+4]==0xf7){po+=4;cc+=4;}
523
524   {
525     unsigned char       c1,c2;
526     int bc=0,i=0;
527
528     while(i<co){
529       c1=dat[i];c2=dat[i+1];
530       buf[bc]=0xf7;buf[bc+1]=0;buf[bc+2]=c1;buf[bc+3]=c2;
531
532       if(c1==0xf7){buf[bc+3]=0xf7;}
533
534       if(c1==0xf0 || c2==0xf0){
535         if(c1==0xf0){
536           buf[bc+2]=0xf7;buf[bc+3]=0xf7;
537           i-=1;
538         }else{
539           buf[bc+3]=0xf7;
540         }
541         bc+=4;
542         buf[bc]=0x98;buf[bc+1]=0;
543         buf[bc+2]=0;buf[bc+3]=0;
544       }
545       bc+=4;i+=2;
546     }
547
548     if(bc<=cc || trk_check(bc-cc)==0){
549       int       po=ad+4,i;
550
551       trk_delete(po,cc);trk_shift(po,bc);
552       for(i=0;i<bc;i++){trk[track][po+i]=buf[i];}
553
554       if( ke==0x3a ){poplay(ad,8);
555       if( (sh&1)!=0 ){
556         twait(50);
557         if( rcd->flg_gsinfo || rcd->flg_gsinst || rcd->flg_gspanel ) {
558           prn_gspanel(cx);
559           if( rcd->flg_gsinfo) {
560             rcd->flg_gsinfo=0;
561             scinst_dsp(cx+13,16,(uint8 *)rcd->gs_info);
562           }
563           if( rcd->flg_gsinst) {
564             rcd->flg_gsinst=0;
565             scinst_dsp(cx+13,16,(uint8 *)rcd->gs_inst);
566           }
567           if( rcd->flg_gspanel ) {
568             rcd->flg_gspanel=0;
569             scpanel_dsp(cx+13,18,(uint8 *)rcd->gs_panel);
570           }
571           while(inkey2()==0){}
572         }
573       }
574       }
575     }
576   }
577
578   if( ke==0x3a || ke==0xff ){goto top0;}
579
580   edit_scr=e;
581   fnc_dis(0);/*txerase(cx*8,4*16,53*8,26*16);*/
582   noed_cls_t();
583   noed_cls();
584   cons_md(1);
585
586
587 }
588
589 void    excsum(unsigned char *da,int nn)
590 {
591   int   top=4,i,sum=0;
592
593   if(da[0]==0x43){top--;}
594   for(i=top;i<nn;i++){sum+=da[i];}
595   da[nn]=(128-(sum & 0x7f))&0x7f;
596 }
597
598 void    excins(unsigned char *da,int co,int nn)
599 {
600   int   i;
601
602   for(i=co;i>nn;i--){da[i]=da[i-1];}
603 }
604
605 void    excdel(unsigned char *da,int co,int nn)
606 {
607   int   i;
608
609   for(i=nn;i<co;i++){da[i]=da[i+1];}
610 }
611
612 /************************** RCM2  MAX=263 +9+1  272*/
613 void    exc_dis(int no,int cx,int co,int m)
614 {
615   int   i,a=0;
616
617   B_LOCATE(cx+3,7);B_COLOR(9);B_PRINT("F0");B_COLOR(3);
618
619   if(m==0){no=0;}
620
621   while(no<=16+6){
622     int nn=no*16;
623
624     if(m!=0 && nn!=co+1 && a==0xf7){break;}
625
626     B_LOCATE(cx+5,7+no);
627
628     i=0;
629     while(i<16 && nn<=co){
630       B_PRINT(" ");
631       a=dat[nn++];i++;
632
633       if(a>=0x80 && a<=0x84){
634         B_COLOR(1);B_PRINT(uxcc[a-0x80]);
635       }else{
636         if(a<0x80){B_COLOR(3);}else{B_COLOR(9);}
637         B_PRINT(hex_s(a,2));if(a>=0x80){B_COLOR(3);}
638       }
639
640       if(a==0xf7){break;}
641     }
642     B_COLOR(1);
643     while(i<16 && nn<=256+96){dat[nn++]=0xf7;B_PRINT(" ..");i++;}
644     if(m==2){break;}
645     no++;
646   }
647   B_COLOR(3);snsclr();
648 }
649
650 /**************************19971028/29/30*/
651 /*
652   int   exc_rec()
653   {
654   unsigned char buf[8*1024];
655   int   ad,ln,pp,cc,a,bpo,i,fl;
656
657   all_note_off(1);hedset(36);bpo=rcp_buf_put(hed,0,1414);
658   for(i=0;i<36;i++){thedset(i,48);hed[44]=0xfe;bpo=rcp_buf_put(hed,bpo,48);}}
659   rcd->fmt=2;rcd->totalcount=bpo;
660   rcd->data_valid=1;rcd->word_valid=0;rcd->tone_valid=0;rcd->gsd_valid=0;
661
662   (*rcd->init)();midi_clr();
663
664   ln=0;
665
666   while(1){
667   a=(*rcd->md_get)();
668   if(a>=0 && a<0xf8){
669   if( INPOUT(0xfe)!=0 ){if(INPOUT(0xff)==27){break;}}
670
671   if(a==0xf0){fl=1;}
672   if(fl){dat[ln++]=a;}
673   if(a==0xf7){fl=0;}
674
675   if(ln>=32*1024+512){msg("バッファが一杯になりました");break;}
676   }
677   }
678
679   strcpy(buf,dat,ln);
680   pp=0;cc=0;
681
682   while( buf[pp]==0xf0 && pp<ln) {
683   if(cc==0){pp++;}
684   while( buf[pp] != 0xf7 && pp<ln) {dat[cc++]=buf[pp++];}
685   pp++;
686   }
687   dat[cc]=0xf7;
688
689   return(cc);
690   }
691   */
692 /***************************/
693 int     exc_load(char *fna)
694 {
695   char  tmp0[2048],li[1024];
696   unsigned char buf[8*1024];
697
698   int   ad,ln,n,j,pp,cc;
699   unsigned char a;
700   FILE  *fp;
701
702   if(!(fp= fopen2(fna,"rb"))){msg(_("File not found."));return(-1);}
703   ln=fread(dat,1,32*1024,fp);fclose(fp);
704   j=0;ad=0;
705
706   while(ln>0){
707     n=0;
708     while(1){
709       a=dat[ad++];
710       if(ad>=ln){ln=fread(dat,1,32*1024,fp);ad=0;if(ln==0){break;}}
711       if(a<32){
712         if(a==13){break;}
713         a=32;
714       }else{
715         if(a=='*'){a=0;}
716       }
717       li[n++]=a;
718     }
719     li[n]=0;li[1023]=0;
720     if(dat[ad]==0x0a){ad++;
721     if(ad>=ln){ln=fread(dat,1,32*1024,fp);ad=0;}
722     }
723
724     spcut(li);
725     if( li[0]!=0 ){
726       char      tmp9[128];
727       int       i=0;
728
729       strcpy(tmp0,li);jstrupr(tmp0);
730       spcut(tmp0);
731
732       while(i<strlen(tmp0)){
733         int     a;
734         if(tmp0[i]==32){i++;}else{
735           strcpy(tmp9,&tmp0[i]);
736           if(tmp9[1]==0){
737             tmp9[1]='H';tmp9[2]=0;
738           }else{
739             tmp9[2]='H';tmp9[3]=0;
740           }
741           a = str_val(tmp9);
742     tmp9[2]=0;
743           if(strcmp(tmp9,"GT")==0){a=0x80;}
744           if(strcmp(tmp9,"VE")==0){a=0x81;}
745           if(strcmp(tmp9,"CH")==0){a=0x82;}
746           if(strcmp(tmp9,"CS")==0){a=0x83;}
747           if(strcmp(tmp9,"SS")==0){a=0x84;}
748
749           buf[j++]=a;if(j>=8*1024){goto skip;}
750           i=i+2;
751         }
752       }
753     }
754   }
755 skip:
756   fclose(fp);
757
758   pp=0;cc=0;
759
760   while( buf[pp]==0xf0 && pp<j) {
761     if(cc==0){pp++;}
762     while( buf[pp] != 0xf7 && pp<j) {dat[cc++]=buf[pp++];}
763     pp++;
764   }
765   dat[cc]=0xf7;
766
767   return(cc);
768 }
769
770 /***************************/
771 int     exc_save(char *fna,int co)
772 {
773   int   sz,i;
774   unsigned char buf[4096];
775   FILE  *fp;
776
777   if(!(fp= fopen2(fna,"wb"))){msg(_("Cannot open file."));return(-1);}
778
779   strcpy((char *)buf,"F0 ");
780   dat[co++] = 0xf7;
781
782   for(i=0;i<co;i++){
783     unsigned char a=dat[i];
784
785     if(a>=0x80 && a!=0xf7){
786       if(a>=0x80 && a<=0x84){strcat((char *)buf,uxcc[a-0x80]);strcat((char *)buf," ");}
787
788       if(a==0xf0){
789         strcat((char *)buf,"F7\r\n\r\n");
790         fwrite(buf,1,strlen((char *)buf),fp);
791   buf[0]=0;
792         strcat((char *)buf,"F0 ");
793       }
794     }else{
795       strcat((char *)buf,hex_s(dat[i],2));
796       strcat((char *)buf," ");
797     }
798
799     sz=strlen((char *)buf);
800     if(sz>=16*3){
801       buf[sz-1]=0;strcat((char *)buf,"\r\n");
802       fwrite(buf,1,sz+1,fp);
803       buf[0]=0;
804     }
805   }
806   strcat((char *)buf,"\r\n");
807   fwrite(buf,1,strlen((char *)buf),fp);
808   fclose(fp);
809
810   return(0);
811 }
812
813 /***************************/
814 void prn_gspanel( int cx )
815 {
816   struct        X68_TXFILLPTR   *t,buf;
817
818   t=&buf;
819
820   t->x = (cx+11)*8  ;t->y = 15*16+8;t->x1 = 36*8;t->y1 = 9*16;
821   t->vram_page = 0;t->fill_patn = 0xffff;TXFILL( t );
822   t->vram_page = 1;t->fill_patn = 0x0000;TXFILL( t );
823
824   t->x = (cx+11)*8+2;t->y = 15*16+8+2;t->x1 = 36*8-4;t->y1 = 9*16-4;
825   t->vram_page = 0;t->fill_patn = 0x0000;TXBOX( t );
826
827   t->x = (cx+13)*8  ;t->y = 18*16;t->x1 = 32*8;t->y1 = 6*16;
828   t->vram_page = 0;t->fill_patn = 0x0;TXFILL( t );
829   t->vram_page = 1;t->fill_patn = 0xffff;TXFILL( t );
830
831   /*t->x = (cx+13)*8*/  ;t->y = 16*16;t->x1 = 32*8;t->y1 = 16;
832   t->vram_page = 0;t->fill_patn = 0x0;TXFILL( t );
833   t->vram_page = 1;t->fill_patn = 0xffff;TXFILL( t );
834
835 }
836
837 /***************************/
838
839 /***************************/
840 /*970112 bar display edit*/
841 int     dot_ed(int dx,int co)
842 {
843   int   ke,kc,sh,cx,cy,i,j,gx,pmode=1;
844   int   msf=-1;
845
846   for(i=0;i<16;i++){for(j=0;j<16;j++){dotpat[i][j]=0;}}
847
848   /*            0x10 0x01~5 0x00 / 0x10 0x01~5 0x40 */
849
850   if( dat[0]==0x41 && dat[1]==0x10 && dat[2]==0x45 && dat[3]==0x12 &&
851       dat[4]==0x83 && dat[5]==0x10 && dat[6]>0 && dat[7]==0x00){
852     dattopat(0);
853   }else{
854     if(co==0){
855       dat[0]=0x41;dat[1]=0x10;dat[2]=0x45;dat[3]=0x12;
856       dat[4]=0x83;dat[5]=0x10;dat[6]=1;dat[7]=0x00;
857     }else{
858       msg(_("Not a GS BAR DISPLAY DATA."));return co;
859     }
860   }
861
862   gx=dx*8;
863   cx=0;cy=0;
864
865   txerase(dx*8,15*16,53*8,15*16);
866   fill(gx+31-8,512+240,gx+360+32,995,0);
867
868   box(gx+31-8,512+240+8,gx+360+64,995-6,14,65535);
869   sdis(dx+4-1,512+240+8," GS BAR DISPLAY EDIT",48+2,15,14);
870
871   if(cnfflag&0x8000){
872     fill(gx+64-16,512+288-16,gx+63+16*16+16,512+287+8*16+16,14);
873     fill(gx+64   ,512+288   ,gx+63+16*16   ,512+287+8*16   ,0);
874
875     for(i=0;i<17;i++){
876       line(gx+64,512+287+i*8, gx+63+16*16,512+287+i*8, 4,65535);
877       line(gx+63+i*16,512+288, gx+63+i*16,512+287+8*16, 4,65535);
878     }
879     B_COLOR(3);
880   }else{
881     /*          GPALET(2,0x97c0);
882                 TPALET(2,0x7700);*/
883
884     GPALET(2,0x7700);
885     TPALET(2,0x4400);
886
887     fill(gx+64-16,512+288-16,gx+63+16*16+16,512+287+8*16+16,14-12);
888     fill(gx+64   ,512+288   ,gx+63+16*16   ,512+287+8*16   ,0);
889
890     for(i=0;i<17;i++){
891       line(gx+64,512+287+i*8, gx+63+16*16,512+287+i*8, 4-2,65535);
892       line(gx+63+i*16,512+288, gx+63+i*16,512+287+8*16, 4-2,65535);
893     }
894     B_COLOR(2);
895   }
896
897   fnc_dis(-1);
898
899   dot_dis(dx);
900   if((cmdflag&0x200)==0){
901     MS_INIT();MS_LIMIT(gx,80,gx+432,511-16-8);MS_CURON();
902   }
903
904   while( 1){
905     int ma=0,mx,my;
906     /*top:*/
907     box(gx+cx*16+63,cy*8+287+512,gx+63+cx*16+16,cy*8+287+512+8,6,65535);
908     /*
909       B_LOCATE(dx+8,26);B_PRINT("X=");B_PRINT(fstr(cx,2));
910       B_LOCATE(dx+8,27);B_PRINT("Y=");B_PRINT(fstr(cy,2));
911       */
912     while(B_KEYSNS()==0){
913       /*ma=MS_GETDT()&0xff00;mx=MS_CURGT();my=mx&0xffff;mx=mx>>16;*/
914       ma=MS_GETDT()&0xff00;mspos(&mx,&my);
915       if(ma==0){msf=-1;}
916       if(ma /*&& msf!=0*/){break;}
917       if(BITSNS(14)&12){break;}
918     }
919
920     ke=0;kc=0;sh=B_SFTSNS();
921     if(B_KEYSNS()!=0){
922       ke=B_KEYINP();kc=ke & 0xff;ke=ke>>8;
923     }
924
925     if(cnfflag&0x8000){
926       box(gx+cx*16+63,cy*8+287+512,gx+63+cx*16+16,cy*8+287+512+8,4,65535);
927     }else{
928       box(gx+cx*16+63,cy*8+287+512,gx+63+cx*16+16,cy*8+287+512+8,4-2,65535);
929     }
930
931     if(ma!=0 && msf!=0){
932       ke=0;kc=0;msf=0;mx-=gx;
933       if(mx>=8*8 && mx<8*8+16*16 && my>=18*16 && my<18*16+8*16 ){
934         cx=(mx-8*8)>>4;cy=(my-18*16)>>3;
935         pmode=1-dotpat[cx][cy];goto skip;
936       }
937     }
938     if(ma!=0 && msf==0){
939       int a;
940       ke=0;kc=0;msf=0;mx-=gx;
941       if(mx>=8*8 && mx<8*8+16*16 && my>=18*16 && my<18*16+8*16 ){
942         cx=(mx-8*8)>>4;cy=(my-18*16)>>3;
943       skip:
944         dotpat[cx][cy]=pmode;
945         B_LOCATE(dx+8+cx*2,(cy>>1)+18);
946         /*                              B_PRINT(dotp[dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2]);*/
947         a=dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2;
948         if(cnfflag&0x8000){a=3-a;}
949         B_PRINT(dotp[a]);
950
951       }
952     }
953
954     if( ke==1 || ke==0x34 ){
955       pattodat(0);
956       break;
957     }
958
959     if( ke==0x3a ){
960       char buf[128];
961       int sum=0;
962       pattodat(0);
963       buf[0]=0xf0;
964
965       for(i=0;i<4;i++){buf[i+1]=dat[i];}
966       for(i=5;i<72;i++){buf[i]=dat[i];sum=sum+dat[i];}
967       buf[72]=(128-(sum&0x7f))&0x7f;
968       buf[73]=0xf7;buf[74]=0xff;
969
970       (*rcd->mix_out)(buf);
971     }
972
973     if( kc==0x13||ke==0x3b ||ke==0x43||ke==0x47||ke==0x4B ){cx--;if(cx<0){cx=15;}}
974     if( kc==0x04||ke==0x3d ||ke==0x45||ke==0x49||ke==0x4D ){cx++;if(cx>15){cx=0;}}
975     if( kc==0x05||ke==0x3c ||ke==0x43||ke==0x44||ke==0x45 ){cy--;if(cy<0){cy=15;}}
976     if( kc==0x18||ke==0x3e ||ke==0x4B||ke==0x4C||ke==0x4D ){cy++;if(cy>15){cy=0;}}
977     /*
978       if( ke==0x36 ){cx=0;cy=0;}
979       */
980     if( (sh&4)!=0 ){
981       int a;
982       dotpat[cx][cy]=1;
983       B_LOCATE(dx+8+cx*2,(cy>>1)+18);
984       /*B_PRINT(dotp[dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2]);*/
985       a=dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2;
986       if(cnfflag&0x8000){a=3-a;}
987       B_PRINT(dotp[a]);
988     }
989     if( (sh&8)!=0 ){
990       int a;
991       dotpat[cx][cy]=0;
992       B_LOCATE(dx+8+cx*2,(cy>>1)+18);
993       /*B_PRINT(dotp[dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2]);*/
994       a=dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2;
995       if(cnfflag&0x8000){a=3-a;}
996       B_PRINT(dotp[a]);
997     }
998
999     if( kc==' ' ){
1000       int a;
1001       dotpat[cx][cy]=1-dotpat[cx][cy];
1002       B_LOCATE(dx+8+cx*2,(cy>>1)+18);
1003       /*B_PRINT(dotp[dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2]);*/
1004       a=dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2;
1005       if(cnfflag&0x8000){a=3-a;}
1006       B_PRINT(dotp[a]);
1007     }
1008
1009     if( kc=='G' || kc=='g' ){
1010       dattopat(0);dot_dis(dx);
1011     }
1012
1013     if( ke==0x3f ){
1014       for(i=0;i<16;i++){for(j=0;j<16;j++){dotpat[i][j]=0;}}
1015       dot_dis(dx);
1016     }
1017
1018     if( kc=='R' || kc=='r'){
1019       for(i=0;i<16;i++){for(j=0;j<16;j++){dotpat[i][j]=1-dotpat[i][j];}}
1020       dot_dis(dx);
1021     }
1022
1023
1024     if( sh&2 ){
1025       if( ke==0x3b ){
1026         for(j=0;j<16;j++){
1027           int a=dotpat[0][j];
1028           for(i=0;i<15;i++){dotpat[i][j]=dotpat[i+1][j];}
1029           dotpat[15][j]=a;
1030         }
1031         dot_dis(dx);ke=0;
1032       }
1033       if( ke==0x3d ){
1034         for(j=0;j<16;j++){
1035           int a=dotpat[15][j];
1036           for(i=15;i>0;i--){dotpat[i][j]=dotpat[i-1][j];}
1037           dotpat[0][j]=a;
1038         }
1039         dot_dis(dx);ke=0;
1040       }
1041       if( ke==0x3c ){
1042         for(j=0;j<16;j++){
1043           int a=dotpat[j][0];
1044           for(i=0;i<15;i++){dotpat[j][i]=dotpat[j][i+1];}
1045           dotpat[j][15]=a;
1046         }
1047         dot_dis(dx);ke=0;
1048       }
1049       if( ke==0x3e ){
1050         for(j=0;j<16;j++){
1051           int a=dotpat[j][15];
1052           for(i=15;i>0;i--){dotpat[j][i]=dotpat[j][i-1];}
1053           dotpat[j][0]=a;
1054         }
1055         dot_dis(dx);ke=0;
1056       }
1057     }
1058
1059
1060     if( ke>=0x63 && ke<=0x67 ){
1061       dot_ctrl(ke-0x63);
1062       dot_dis(dx);
1063     }
1064
1065   }
1066
1067   B_COLOR(3);
1068   txerase(dx*8+8,15*16,42*8,15*16);
1069   fill(gx+31-8,512+240,gx+360+64,995,0);
1070   dpl(1);
1071   tpl(1);
1072   fnc_dis(4);
1073
1074   if((cmdflag&0x200)==0){
1075     MS_LIMIT(0,0,767,511);MS_CUROF();
1076   }
1077   return 66+8;
1078 }
1079
1080 /***************************/
1081 void    dot_ctrl(int m)
1082 {
1083   int i,j;
1084   int dot2[16][16];
1085
1086   if( m==0 ){
1087     for(j=0;j<16;j++){
1088       for(i=0;i<8;i++){
1089         int a;
1090         a=dotpat[j][i];
1091         dotpat[j][i]=dotpat[j][15-i];
1092         dotpat[j][15-i]=a;
1093       }
1094     }
1095   }
1096   if( m==1 ){
1097     for(j=0;j<16;j++){
1098       for(i=0;i<8;i++){
1099         int a;
1100         a=dotpat[i][j];
1101         dotpat[i][j]=dotpat[15-i][j];
1102         dotpat[15-i][j]=a;
1103       }
1104     }
1105   }
1106   /*
1107     if(m==2){
1108     for(j=0;j<16;j++){
1109     for(i=0;i<16;i++){
1110     dot2[j][i]=dotpat[15-i][j];
1111     }
1112     }
1113     for(j=0;j<16;j++){
1114     for(i=0;i<16;i++){
1115     dotpat[j][i]=dot2[j][i];
1116     }
1117     }
1118     }*/
1119   /*    if(m==3){*/
1120   if(m==2){
1121     for(j=0;j<16;j++){
1122       for(i=0;i<16;i++){
1123         dot2[j][i]=dotpat[i][15-j];
1124       }
1125     }
1126     for(j=0;j<16;j++){
1127       for(i=0;i<16;i++){
1128         dotpat[j][i]=dot2[j][i];
1129       }
1130     }
1131   }
1132 }
1133
1134 /***************************/
1135 void    dot_dis(int cx)
1136 {
1137   int   i,j,a;
1138
1139   for(i=0;i<16;i+=2){
1140     B_LOCATE(cx+8,(i>>1)+18);
1141     for(j=0;j<16;j++){
1142       /*        B_PRINT(dotp[dotpat[j][i]+dotpat[j][i+1]*2]);*/
1143       a=dotpat[j][i]+dotpat[j][i+1]*2;
1144       if(cnfflag&0x8000){a=3-a;}
1145       B_PRINT(dotp[a]);
1146     }
1147   }
1148 }
1149
1150 /***************************/
1151 void    dattopat(int me)
1152 {
1153   int   ad=8,i,j,a;
1154
1155   for(j=0;j<16;j++){
1156     /*          a=dat[ad]&31;a=a*32+(dat[ad+16]&31);
1157                 a=a*32+(dat[ad+32]&31);a=a*32+(dat[ad+48]&31);*/
1158
1159     a=((((((dat[ad]*32)|dat[ad+16])*32)|dat[ad+32])*32)|dat[ad+48]);
1160
1161     a=a>>4;
1162     ad++;
1163
1164     for(i=0;i<16;i++){dotpat[15-i][j]=a&1;a=a>>1;}
1165   }
1166 }
1167
1168 /***************************/
1169 void    pattodat(int me)
1170 {
1171   int   ad=8,i,j,a;
1172
1173   for(j=0;j<16;j++){
1174     a=0;
1175     for(i=0;i<16;i++){a=a<<1;if(dotpat[i][j]==1){a|=1;}}
1176     a=a<<4;
1177
1178     dat[ad   ]=(a>>15)&31;dat[ad+16]=(a>>10)&31;
1179     dat[ad+32]=(a>>5 )&31;dat[ad+48]=(a    )&31;
1180     ad++;
1181   }
1182   dat[72]=0x84;dat[73]=0xf7;
1183 }
1184
1185 /***************************/
1186
1187 /***************************/
1188 /*                      0x10 0x01~5 0x00 / 0x10 0x01~5 0x40*/
1189 void    exc_view(int ad)
1190 {
1191   int   i,cx,gx,co,po,excmd=0;
1192   int   e=edit_scr;
1193   char  tmp0[128];
1194   unsigned char *buf;buf=dat+(16*1024);
1195
1196   if(edit_scr==0){cx=41;gx=328;}else{cx=1;gx=8;}
1197   cons_md(0);/*noed_cls();*/edit_scr=0;
1198
1199   if(trk[track][ad]<0x90 || trk[track][ad]>0x98){goto ext;}
1200   noed_cls();
1201
1202   if(trk[track][ad]==0x98){
1203     po=ad;co=0;
1204     while(trk[track][po+4]==0xf7){po+=4;
1205     dat[co]=trk[track][po+2];if(dat[co]==0xf7){break;}
1206     co++;
1207     dat[co]=trk[track][po+3];if(dat[co]==0xf7){break;}
1208     co++;
1209     }
1210   }else{
1211     excmd=trk[track][ad]-0x90+1;po=0;co=0;
1212     while(user_exc_data[excmd-1][po]!=0xf7 && po<24){
1213       dat[co++]=user_exc_data[excmd-1][po++];
1214     }
1215     dat[co++]=0xf7;
1216   }
1217
1218   box(gx-1,624-48,gx+417+16,997,14,65535);
1219   fill(gx,639-32,gx+15,996,8);
1220   fill(gx,639-40,gx+416+16,639-16-8,8);
1221
1222   if(excmd==0){strcpy(tmp0," Track");}else{strcpy(tmp0," User");}
1223   strcat(tmp0," Exclusive View");
1224
1225   if(excmd){strcat(tmp0," [ ] ");tmp0[22]=excmd+'0'-1;
1226   strcat(tmp0,user_exc_memo[excmd-1]);}
1227
1228   sdis(cx,624-48,tmp0,54,15,14);
1229
1230   /*
1231     strcpy(tmp0," Tr:");strcat(tmp0,fstr(track+1,2));
1232     strcat(tmp0," Meas:");strcat(tmp0,fstr(meas_no(ad),4));
1233
1234     sdis(cx,624-48+16,tmp0,54,15,14);
1235     */
1236
1237   for(i=0;i<22;i++){tdis(cx,7+i,hex_s(i,2),2,3);}
1238   /*    for(i=0;i<22;i++){sdis(cx,512+(7+i)*16,hex_s(i,2),2,3,8);}*/
1239   for(i=0;i<16;i++){sdis(cx+i*3+7,512+6*16-8,hex_s(i,1),1,3,8);}
1240
1241   exc_dis2(cx,co);
1242
1243   if( dat[0]==0x41 && dat[1]==0x10 && dat[2]==0x45 && dat[3]==0x12 &&
1244       dat[4]==0x83 && dat[5]==0x10 ){
1245     if(dat[7]==0x00){
1246       if(dat[6]>0){
1247         prn_gspanel(cx);scpanel_dsp(cx+13,18,&dat[8]);
1248       }else{
1249         prn_gspanel(cx);scinst_dsp(cx+13,16,&dat[8]);
1250       }
1251     }
1252   }
1253   tg_copy2(1-e);
1254   edit_scr=e;
1255   /*    txerase(cx*8,4*16,53*8,26*16);*/
1256   noed_cls_t();
1257 ext:
1258   edit_scr=e;
1259   cons_md(1);
1260
1261 }
1262
1263 void    exc_dis2(int cx,int co)
1264 {
1265   int   i,a=0,no=0;
1266
1267   B_LOCATE(cx+3,7);B_COLOR(9);B_PRINT("F0");B_COLOR(3);
1268
1269   while(no<=16+6){
1270     int nn=no*16;
1271
1272     B_LOCATE(cx+5,7+no);
1273
1274     i=0;
1275     while(i<16 && nn<=co){
1276       B_PRINT(" ");
1277       a=dat[nn++];i++;
1278
1279       if(a>=0x80 && a<=0x84){
1280         B_COLOR(1);B_PRINT(uxcc[a-0x80]);
1281       }else{
1282         if(a<0x80){B_COLOR(3);}else{B_COLOR(9);}
1283         B_PRINT(hex_s(a,2));if(a>=0x80){B_COLOR(3);}
1284       }
1285
1286       if(a==0xf7){break;}
1287     }
1288     B_COLOR(1);
1289
1290     no++;
1291   }
1292   B_COLOR(3);snsclr();
1293 }