home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / sound / midi / k1ed_v5_.lha / src / k1.c < prev    next >
C/C++ Source or Header  |  1992-10-31  |  28KB  |  1,119 lines

  1. #include <libraries/arpbase.h>
  2. #include <arpfunctions.h>
  3. #include <arp_prag.h>
  4.  
  5. #include "inc.h"
  6. #include "defs.h"
  7. #include "gad.h"
  8. #include "zz_pointer.h"
  9. #include <exec/ports.h>
  10. #include <exec/execbase.h>
  11.  
  12. #include <devicetoolkits/input.h>
  13. #include <deviceToolKits/proto/Input.h>
  14. #include <deviceToolKits/InputBase.h>
  15.  
  16. typedef  void  (*VoidFunc)();
  17.  
  18. DTInput_t             Unit0;
  19. struct   Interrupt  handler_setup;
  20. struct   InputEvent event_copy;
  21. int                 found_key;
  22. int                 event_count;
  23. long                 col[4];
  24.  
  25. APTR                GetA4();
  26. void                ManxHandler();
  27.  
  28. #asm
  29.     xdef    _ManxHandler
  30.     xdef    _GetA4
  31.     xref    _ehandler
  32.  
  33. _GetA4:
  34.     move.l    a4,d0
  35.     rts
  36.  
  37. _ManxHandler:
  38.     movem.l    d2-d7/a2-a6,-(sp)
  39.     move.l    a1,a4
  40.     move.l    a0,-(sp)
  41.     jsr        _ehandler
  42.     addq.l    #4,sp
  43.     movem.l    (sp)+,d2-d7/a2-a6
  44.     rts
  45. #endasm
  46.  
  47. APTR  ehandler(struct InputEvent *events)
  48. {
  49.     struct   InputEvent  *ep, *laste;
  50.  
  51.     event_count++;
  52.     for (ep = events, laste = NULL; ep != NULL; ep = ep->ie_NextEvent) 
  53.     {
  54.         if ((ep->ie_Class == IECLASS_RAWKEY) && (ep->ie_Code == 0x41) && (ep->ie_Qualifier & IEQUALIFIER_RSHIFT)) 
  55.         {
  56.             if (laste == NULL) events = ep->ie_NextEvent;
  57.                         else   laste->ie_NextEvent = ep->ie_NextEvent;
  58.  
  59.             if (SCREEN==NULL)
  60.             {
  61.                 struct Screen *sr=IntuitionBase->FirstScreen;
  62.  
  63.                 MoveScreen(sr,-(sr->LeftEdge),-(sr->TopEdge));
  64.                 WBenchToFront();
  65.                 WindowToFront(win);
  66.                 Forbid();
  67.                 BeginRefresh(win);
  68.                 RefreshWindowFrame(win);
  69.                 EndRefresh(win,code);
  70.                 Permit();
  71.             }
  72.             else
  73.             {
  74.                 MoveScreen(scr,-(scr->LeftEdge),-(scr->TopEdge));
  75.                 ScreenToFront(scr);    
  76.             }
  77.             event_copy = *ep;
  78.             goto Ende;
  79.         }
  80.         else  laste = ep;
  81.         Ende: ;
  82.     }
  83.     return ((APTR) events);
  84. }
  85.  
  86.  
  87. struct ExtendedColorRequester colstruct;
  88. extern struct ExecBase *SysBase;
  89.  
  90. void main(int argc, char **argv);
  91. void DisplayBank(void);
  92. void DisplayMulti(void);
  93. void CheckWbCall(int argc, char **argv);
  94. void Colours();
  95. void InitializeAll(int);
  96. void SingleCopyTo(int);
  97. void SingleSwapWith(int);
  98. void MultiCopyTo(int);
  99. void MultiSwapWith(int);
  100. void Quit(void);
  101. void SaveOldColours(void);
  102. void SetColours(void);
  103. void SetOldColours(void);
  104. void GetColours(void);
  105. void Help(void);
  106.  
  107. int initsing[88]=
  108. { 83, 105, 110, 103, 108, 101, 32, 75, 45, 49, 40, 0, 80, 50, 62, 2, 50,
  109.  0, 50, 0, 50, 50, 12, 50, 50, 50, 50, 84, 84, 84, 84, 28, 29, 28, 29, 14,
  110.  14, 14, 14, 100, 100, 100, 100, 0, 0, 0, 0, 10, 10, 10, 10, 20, 20, 20,
  111.  20, 100, 100, 100, 100, 20, 20, 20, 20, 50, 50, 50, 50, 50, 50, 50, 50,
  112.  50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 104 };
  113.  
  114. int initmul[76]=
  115. { 77, 85, 76, 84, 73, 32, 75, 45, 49, 32, 99, 0, 1, 2, 3, 4, 5, 6, 7, 0, 0,
  116.  0, 0, 0, 0, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 16, 16, 16, 16,
  117.  16, 16, 16, 16, 64, 64, 64, 64, 64, 64, 64, 64, 24, 24, 24, 24, 24, 24, 24,
  118.  24, 50, 50, 50, 50, 50, 50, 50, 50, 100, 100, 100, 100, 100, 100, 100, 100, 0 };
  119.  
  120.  
  121. /**********************************************************************************/
  122. /***                                                                            ***/
  123. /**********************************************************************************/
  124.  
  125. void main(int argc,char **argv) 
  126. {
  127.     int i;
  128.     long code,volume; 
  129.     struct ArpBase *ArpBase;
  130.     struct Gadget *gad;
  131.  
  132.     long status;
  133.  
  134.     multi=0;
  135.     strcpy(bankdir,"kawai:banks");
  136.     strcpy(sounddir,"kawai:sounds");
  137.     strcpy(multidir,"kawai:multi");
  138.     strcpy(dumpdir,"kawai:dump");
  139.  
  140.  
  141.     if (!strcmp(getenv("K1-LIB"),"TRUE"))
  142.     {
  143.         BOOL ergeb;
  144.  
  145.         IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
  146.         ergeb=BoolRequest("K1 Librarian is already running","Go on","Leave");
  147.         if (ergeb==FALSE)
  148.         {
  149.             CloseLibrary(IntuitionBase);
  150.             exit(5);
  151.         }
  152.     }
  153.  
  154.     OpenStuff();
  155.     SaveOldColours();
  156.     GetColours();
  157.  
  158.     setenv("K1-LIB","TRUE");
  159.  
  160.     CheckWbCall(argc,argv); 
  161.     Gadget1SInfo.VertPot=65535/2;
  162.     if (SysBase->VBlankFrequency != 0x32)        /* auf PAL testen */
  163.     {
  164.         WBLACE=1;    
  165.         SCREEN=1;
  166.     }
  167.  
  168.     if (SCREEN == NULL) SetColours();
  169.     else                Make_Screen();
  170.  
  171.     ReqStruct.numlines=23;
  172.     ReqStruct.numcolumns=30;
  173.     ReqStruct.Flags = FRQCACHINGM+(SCREEN != NULL ? FRQNODRAGM : NULL);
  174.     ReqStruct.dirnamescolor = 2;
  175.     ReqStruct.devicenamescolor = 2;
  176.  
  177.     ArpBase=(struct ArpBase *) OpenLibrary("arp.library",0);
  178.     if (ArpBase != NULL)
  179.     {
  180.         Assign("K1_Sounds",sounddir);
  181.         Assign("K1_Banks",bankdir);
  182.         Assign("K1_Multis",multidir);
  183.         Assign("K1_Dumps",dumpdir);
  184.         CloseLibrary(ArpBase);
  185.     }
  186.  
  187.     strcpy(bankdir,"K1_Banks:");
  188.     strcpy(sounddir,"K1_Sounds:");
  189.     strcpy(multidir,"K1_Multis:");
  190.     strcpy(dumpdir,"K1_Dumps:");
  191.  
  192.     Make_Window();
  193.  
  194.     MASTERCHANNEL=WaitForK1();
  195.     if (MASTERCHANNEL == -1)
  196.     {
  197.         if (!MyReq("Can't find Kawai K1, where is it ?","Go on","Leave")) CloseStuff();        
  198.     }
  199.  
  200.     if(DEFAULTDUMP == 0 && GETDUMP != 0) GetDump();
  201.     if(DEFAULTDUMP != 0)                 LoadDump(DEFDUMPNAME);
  202.     if(INITIALIZE != 0)                     InitializeAll(0);
  203.     Display();
  204.  
  205.     if ((Unit0 = DTInputCreate(&status)) == NULL) Error("Can't create input enviroment");
  206.  
  207.     event_count = 0;
  208.     handler_setup.is_Node.ln_Pri = 127;
  209.     handler_setup.is_Node.ln_Name=(char *)"YET K1-II's Input Handler";
  210.     handler_setup.is_Code = (VoidFunc) ManxHandler;
  211.     handler_setup.is_Data = (APTR) GetA4();
  212.  
  213.     if ((status = DTInputAddHandler(Unit0,&handler_setup)) != 0) Error("Can't install input handler");
  214.  
  215. start:     
  216.     MODWIN
  217.     SetTitle("KAWAI K1-II Librarian V "VERSION"  Written by Andreas Jung in 1990-92");
  218.  
  219.     WaitPort(win->UserPort);
  220.     while(mesg = (struct IntuiMessage *) GetMsg(win->UserPort))
  221.     {
  222.  
  223.         switch(mesg->Class)
  224.         {
  225.             case ACTIVEWINDOW:
  226.             {
  227.                 ReplyMsg((struct Message *)mesg);
  228.     
  229.                 if (SCREEN==NULL) SetColours();
  230.                 break;
  231.             }
  232.  
  233.             case INACTIVEWINDOW:
  234.             {
  235.                 ReplyMsg((struct Message *)mesg);
  236.  
  237.                 if (SCREEN==NULL) SetOldColours();
  238.                 break;
  239.             }
  240.  
  241.             case GADGETDOWN:
  242.             {
  243.                 ReplyMsg((struct Message *)mesg);
  244.     
  245.                 while(Gadget1.Activation & SELECTED || Gadget1.Flags & SELECTED)
  246.                 {
  247.                     volume=Gadget1SInfo.VertPot;
  248.                     TransmitVolume((65535-volume)*127/65535);
  249.                 }
  250.                 break;
  251.             }
  252.     
  253.             case GADGETUP:
  254.             {
  255.                 ReplyMsg((struct Message *)mesg);
  256.     
  257.                 volume=Gadget1SInfo.VertPot;
  258.                 TransmitVolume((65535-volume)*127/65535);
  259.                 break;
  260.             }
  261.     
  262.             case CLOSEWINDOW:
  263.             {   
  264.                 ReplyMsg((struct Message *) mesg);
  265.  
  266.                 Quit();
  267.                 break;
  268.             }
  269.     
  270.             case NEWSIZE:
  271.             {
  272.                 ReplyMsg((struct Message *) mesg);
  273.     
  274.                 Forbid();
  275.                 BeginRefresh(win);
  276.                 Display();
  277.                 RefreshWindowFrame(win);
  278.                 EndRefresh(win,code);
  279.                 Permit();
  280.     
  281.                 break;
  282.             }
  283.     
  284.             case MOUSEBUTTONS:
  285.             {
  286.                 int x,y,select=-1,soundnr;
  287.     
  288.                 code=mesg->Code;
  289.     
  290.                 x=mesg->MouseX;
  291.                 y=mesg->MouseY;
  292.                 ReplyMsg((struct Message *) mesg);
  293.     
  294.                 if (code==SELECTDOWN)
  295.                 {
  296.                     if (Check(x,y,15,615,28,189) && multi==0)     /* Openrequester */
  297.                      {
  298.                         if (x>15 && x<315)    soundnr=(y-28)/10*2+((x<165) ? 0 : 1);
  299.                         if (x>315 && x<615)    soundnr=32+(y-28)/10*2+((x<465) ? 0: 1);
  300.                         select=OpenSingleRequester(x,y);
  301.                         if (select==0) SingleEd(soundnr);
  302.                         if (select==1) { LoadSound(soundnr); 
  303.                                          TransmitSingleSound(soundnr); }
  304.                         if (select==2) SaveSound(soundnr);
  305.                         if (select==3) TransmitSingleSound(soundnr);
  306.                         if (select==4) SingleCopyTo(soundnr);
  307.                         if (select==5) SingleSwapWith(soundnr);
  308.                         if (select==6) TransmitSingleSound(soundnr);
  309.                         goto Ende;
  310.                     }
  311.     
  312.                     if (Check(x,y,15,315,28,189) && multi==1)     
  313.                      {
  314.                         soundnr=(y-28)/10*2+((x<165) ? 0 : 1);
  315.                         select=OpenMultiRequester(x,y);
  316.                         if (select==0) MultiEd(soundnr);
  317.                         if (select==1) TransmitSingleMulti(soundnr);
  318.                         if (select==2) MultiCopyTo(soundnr);
  319.                         if (select==3) MultiSwapWith(soundnr);
  320.                         goto Ende;
  321.                     }
  322.     
  323.                     if (Check(x,y,15,615,190,235) && multi==0)
  324.                     {
  325.                         int xp=-1,yp=-1;
  326.     
  327.                         xp=(x-15)/120;
  328.                         yp=(y-190)/15;
  329.     
  330.                         if (xp==0 && yp==0) LoadBank(0);
  331.                         if (xp==1 && yp==0) LoadBank(1);
  332.                         if (xp==2 && yp==0) SaveBank(0);
  333.                         if (xp==3 && yp==0) SaveBank(1);
  334.                         if (xp==4 && yp==0) About();
  335.     
  336.                         if (xp==0 && yp==1) GetBank(0);
  337.                         if (xp==1 && yp==1) GetBank(1);
  338.                         if (xp==2 && yp==1) TransmitCurrentBank(0);
  339.                         if (xp==3 && yp==1) TransmitCurrentBank(1);
  340.                         if (xp==4 && yp==1) Iconify();
  341.     
  342.                         if (xp==0 && yp==2) SaveAllSounds(0);
  343.                         if (xp==1 && yp==2) SaveAllSounds(1);
  344.                         if (xp==2 && yp==2) TransmitBank(0);
  345.                         if (xp==3 && yp==2) TransmitBank(1);
  346.                         if (xp==4 && yp==2) Quit();
  347.                         Display();
  348.                         goto Ende;
  349.                     }
  350.                     
  351.                     if (Check(x,y,15,615,190,235) && multi==1)
  352.                     {
  353.                         int xp=-1,yp=-1;
  354.     
  355.                         xp=(x-15)/120;
  356.                         yp=(y-190)/15;
  357.     
  358.                         if (xp==0 && yp==0) LoadMulti();
  359.                         if (xp==1 && yp==0) SaveMulti();
  360.                         if (xp==2 && yp==0) LoadDump(0);
  361.                         if (xp==3 && yp==0) SaveDump();
  362.                         if (xp==4 && yp==0) About();
  363.     
  364.                         if (xp==0 && yp==1) GetMulti();
  365.                         if (xp==1 && yp==1) SendMulti();
  366.                         if (xp==2 && yp==1) GetDump();
  367.                         if (xp==3 && yp==1) SendDump();
  368.                         if (xp==4 && yp==1) Iconify();
  369.     
  370.                         if (xp==0 && yp==2) Colours();
  371.                         if (xp==1 && yp==2) InitializeAll(1);
  372.                         if (xp==2 && yp==2)   /* Change Screen */
  373.                         {
  374.                             if (SCREEN==0)
  375.                             {
  376.                                 SCREEN=1;
  377.                                 Forbid();
  378.                                 SetOldColours();
  379.                                 CloseWindow(win);
  380.                                 Make_Screen();
  381.                                 Make_Window();
  382.                                 Permit();
  383.                                 Display();    
  384.                                 goto start;
  385.                             }
  386.                             else
  387.                             {
  388.                                 struct Screen *sr=IntuitionBase->FirstScreen;
  389.     
  390.                                 SCREEN=0;
  391.                                 Forbid();
  392.                                 CloseWindow(win);
  393.                                 CloseScreen(scr);
  394.                                 Make_Window();
  395.                                 SetColours();
  396.                                 Display();
  397.                                 MoveScreen(sr,-(sr->LeftEdge),-(sr->TopEdge));
  398.                                 WBenchToFront();
  399.                                 WindowToFront(win);
  400.                                 Permit();
  401.                                 goto start;
  402.                             }    
  403.                         }
  404.                         if (xp==3 && yp==2) Controllers();
  405.                         if (xp==4 && yp==2) Quit();
  406.                         Display();
  407.                         goto Ende;
  408.                     }    
  409.     
  410.                     if (Check(x,y,380,530,28,38) && multi==1)        /* Masterchannel */
  411.                     {
  412.                         struct GetLongStruct longstruct;
  413.     
  414.                         longstruct.titlebar = "Masterchannel";
  415.                         longstruct.defaultval = MASTERCHANNEL+1;
  416.                         longstruct.minlimit = 0;
  417.                         longstruct.maxlimit = 16;
  418.                         longstruct.window = win;
  419.                         longstruct.versionnumber = REQVERSION;
  420.                         longstruct.flags = 0;
  421.                         longstruct.rfu2 = 0;
  422.                         if (GetLong(&longstruct)) MASTERCHANNEL=longstruct.result - 1;
  423.     
  424.                         Display();
  425.                         goto Ende;
  426.                     }
  427.     
  428.                     if (Check(x,y,380,530,38,48) && multi==1)        /* Scan Masterchannel */
  429.                     {
  430.                         MASTERCHANNEL=WaitForK1();
  431.                         Display();
  432.                         goto Ende;
  433.                     }
  434.     
  435.                     if (Check(x,y,380,530,48,58) && multi==1)        /* Extern -> Intern */
  436.                     {
  437.                         ExternToIntern();
  438.                         goto Ende;
  439.                     }
  440.     
  441.                     if (Check(x,y,380,530,58,68) && multi==1)        /* Intern -> Extern */
  442.                     {
  443.                         InternToExtern();
  444.                         goto Ende;
  445.                     }
  446.     
  447.                     if (Check(x,y,380,530,68,78) && multi==1)        /* Intern -> Extern */
  448.                     {
  449.                         SwapInternExtern();
  450.                         goto Ende;
  451.                     }
  452.     
  453.                     if (Check(x,y,380,530,98,108)  && multi==1)        /*  Taskpriority */
  454.                     {
  455.                         struct GetLongStruct longstruct;
  456.                         long pri;
  457.             
  458.                         pri=SetTaskPri(FindTask(0),0);
  459.                         if (pri>128) pri=pri-256;
  460.                         SetTaskPri(FindTask(0),pri);
  461.     
  462.                         longstruct.titlebar = "K1-Editor priority";
  463.                         longstruct.defaultval = pri;
  464.                         longstruct.minlimit = -127;
  465.                         longstruct.maxlimit = 128;
  466.                         longstruct.window = win;
  467.                         longstruct.versionnumber = REQVERSION;
  468.                         longstruct.flags = 0;
  469.                         longstruct.rfu2 = 0;
  470.                         if (GetLong(&longstruct)) SetTaskPri(FindTask(NULL),longstruct.result);
  471.                         Display();
  472.                         goto Ende;
  473.                     }
  474.     
  475.                     if (Check(x,y,15,615,235,250))   /* Effektesection */
  476.                     {
  477.                         ProgChange(96+(x-15)/(600/16));
  478.                         goto Ende;
  479.                     }
  480.                     
  481.                     if (Check(x,y,563,613,14,24))    /* Multi */
  482.                     {
  483.                         if (multi==0) multi=1;
  484.                                 else  multi=0;
  485.                         SetAPen(win->RPort,0);
  486.                         SetBPen(win->RPort,0);    
  487.                         SetOPen(win->RPort,0);
  488.                         RectFill(win->RPort,10,11,616,250);
  489.                         Display();
  490.                     }
  491.     
  492.                     Ende:   break;
  493.                 } /* of if SELECTDOWN */
  494.     
  495.                 if (code == MENUDOWN)
  496.                 {
  497.                     if (Check(x,y,15,615,28,189) && multi==0)
  498.                     {
  499.                         if (x>15 && x<315)    soundnr=(y-28)/10*2+((x<165)?0:1);
  500.                         if (x>315 && x<615)    soundnr=32+(y-28)/10*2+((x<465)?0:1);
  501.                         TransmitSingleSound(soundnr);
  502.                     }
  503.     
  504.                     if (Check(x,y,15,315,28,189) && multi==1)
  505.                     {
  506.                         if (x>15 && x<315)    soundnr=(y-28)/10*2+((x<165)?0:1);
  507.                         TransmitSingleMulti(soundnr);
  508.                     }
  509.                     break;
  510.                 } /* of if MENUDOWN */
  511.             }     /* of case MOUSEBUTTONS */
  512.             default: break;    
  513.         }
  514.     }
  515.     goto start;
  516. }
  517.  
  518. /**********************************************************************************/
  519. /***                                                                            ***/
  520. /**********************************************************************************/
  521.  
  522. void DisplayBank(void)
  523. {
  524.     int i,n;    
  525.     char name[11],string[80];
  526.  
  527.     SetAPen(win->RPort,1);
  528.     for (n=0;n<=31;n+=2)
  529.     {
  530.         Line(win,15,28+n*5,615,28+n*5);
  531.         for (i=0;i<=9;i++) name[i]=s[0][n][i] != 0 ? s[0][n][i] : 32;
  532.         name[10]='\0';
  533.         sprintf(string,"(%c %d) %s ",65+n/8,n%8+1,name);
  534.         Print(win,20,36+n*5,string);
  535.  
  536.         for (i=0;i<=9;i++) name[i]=s[0][n+1][i] !=0 ? s[0][n+1][i] : 32;
  537.         name[10]='\0';
  538.         sprintf(string,"(%c %d) %s ",65+n/8,n%8+2,name);
  539.         Print(win,170,36+n*5,string);
  540.  
  541.         for (i=0;i<=9;i++) name[i]=s[1][n][i] != 0 ? s[1][n][i] : 32;
  542.         name[10]='\0';
  543.         sprintf(string,"(%c %d) %s ",32+65+n/8,n%8+1,name);
  544.         Print(win,320,36+n*5,string);
  545.  
  546.         for (i=0;i<=9;i++) name[i]=s[1][n+1][i] != 0 ? s[1][n+1][i] : 32;
  547.         name[10]='\0';
  548.         sprintf(string,"(%c %d) %s ",32+65+n/8,n%8+2,name);
  549.         Print(win,470,36+n*5,string);
  550.     }
  551.  
  552.     Line(win,15,28+n*5,615,28+n*5);
  553.     Line(win,15,28,15,28+n*5);
  554.     Line(win,165,28,165,28+n*5);
  555.     Line(win,315,28,315,28+n*5);
  556.     Line(win,465,28,465,28+n*5);
  557.     Line(win,615,28,615,28+n*5);
  558.  
  559.     for (n=0;n<=3;n++) Line(win,15,190+n*15,615,190+n*15);
  560.     
  561.     for (n=15;n<=615;n+=(615-15)/5)    Line(win,n,190,n,235);    
  562.  
  563.     i=1;
  564.     for (n=0;n<=16;n++)
  565.     {
  566.         Line(win,15+n*600/16,235,15+n*600/16,250);
  567.         if (i<=16)
  568.         {
  569.             sprintf(name,"%d",i++);
  570.             Print(win,15+11+n*600/16+(i<10 ? 5 : 0) ,245,name);
  571.         }
  572.     }    
  573.     Line(win,15,250,615,250); 
  574.  
  575.     Print(win,20+120*0,200,"Load bank 1");
  576.     Print(win,20+120*1,200,"Load bank 2");
  577.     Print(win,20+120*2,200,"Save bank 1");
  578.     Print(win,20+120*3,200,"Save bank 2");
  579.     Print(win,20+120*4,200,"About");
  580.  
  581.     Print(win,20+120*0,215,"Get bank 1");
  582.     Print(win,20+120*1,215,"Get bank 2");
  583.     Print(win,20+120*2,215,"Send bank 1");
  584.     Print(win,20+120*3,215,"Send bank 2");
  585.     Print(win,20+120*4,215,"Iconify");
  586.  
  587.     Print(win,20+120*0,230,"Save sounds 1");
  588.     Print(win,20+120*1,230,"Save sounds 2");
  589.     Print(win,20+120*2,230,"Load/Send as 1");
  590.     Print(win,20+120*3,230,"Load/Send as 2");
  591.     Print(win,20+120*4,230,"Quit");
  592.  
  593.     Print(win,569,22,"MULTI");
  594.     MakeDBox(win,563,14,613,24);
  595. }
  596.  
  597. /**********************************************************************************/
  598. /***                                                                            ***/
  599. /**********************************************************************************/
  600.  
  601. void DisplayMulti(void)
  602. {
  603.     int i,n;
  604.     char name[15],string[80];
  605.  
  606.     SetAPen(win->RPort,1);
  607.     
  608.     for (n=0;n<=31;n+=2)
  609.     {
  610.         Line(win,15,28+n*5,315,28+n*5);
  611.         for (i=0;i<=9;i++) name[i]=m[n][i] != 0 ? m[n][i] : 32;
  612.         name[10]='\0';
  613.         sprintf(string,"(%c %d) %s ",65+n/8,n%8+1,name);
  614.         Print(win,20,36+n*5,string);
  615.  
  616.         Line(win,15,28+n*5,315,28+n*5);
  617.         for (i=0;i<=9;i++) name[i]=m[n+1][i] != 0 ? m[n+1][i] : 32;
  618.         name[10]='\0';
  619.         sprintf(string,"(%c %d) %s ",65+n/8,n%8+2,name);
  620.         Print(win,170,36+n*5,string);
  621.     }
  622.  
  623.     Line(win,15,28+n*5,315,28+n*5);
  624.     Line(win,15,28,15,28+n*5);
  625.     Line(win,165,28,165,28+n*5);
  626.     Line(win,315,28,315,28+n*5);
  627.  
  628.     for (n=0;n<=3;n++)    Line(win,15,190+n*15,615,190+n*15);
  629.     
  630.     for (n=15;n<=615;n+=(615-15)/5)    Line(win,n,190,n,235);    
  631.  
  632.     i=1;
  633.     for (n=0;n<=16;n++)
  634.     {
  635.         Line(win,15+n*600/16,235,15+n*600/16,250);
  636.         if (i<=16)
  637.         {
  638.             sprintf(string,"%d",i++);
  639.             Print(win,15+11+n*600/16+(i<10 ? 5 : 0) ,245,string);
  640.         }
  641.     }    
  642.     Line(win,15,250,615,250); 
  643.  
  644.     Print(win,20+120*0,200,"Load multi");
  645.     Print(win,20+120*1,200,"Save multi");
  646.     Print(win,20+120*2,200,"Load dump");
  647.     Print(win,20+120*3,200,"Save dump");
  648.     Print(win,20+120*4,200,"About");
  649.  
  650.     Print(win,20+120*0,215,"Get multi");
  651.     Print(win,20+120*1,215,"Send multi");
  652.     Print(win,20+120*2,215,"Get dump");
  653.     Print(win,20+120*3,215,"Send dump");
  654.     Print(win,20+120*4,215,"Iconify");
  655.  
  656.     Print(win,20+120*0,230,"Colours");
  657.     Print(win,20+120*1,230,"Init all");
  658.     Print(win,20+120*2,230,SCREEN==0 ? "Use screen" : "Use workbench");
  659.     Print(win,20+120*3,230,"Controllers");
  660.     Print(win,20+120*4,230,"Quit");
  661.  
  662.     Print(win,569,22,"BANKS");
  663.     MakeDBox(win,563,14,613,24);
  664.  
  665.     NumBox(380,28,150,"Masterchannel:",MASTERCHANNEL+1);
  666.     MakeBox(win,380,38,530,48);    
  667.     Print(win,392,46,"Scan Masterchan.");
  668.     MakeBox(win,380,48,530,58);    
  669.     Print(win,392,56,"Extern -> Intern");
  670.     DrawBox(win->RPort,380,58,530,68);    
  671.     Print(win,392,66,"Intern -> Extern");
  672.     DrawBox(win->RPort,380,68,530,78);    
  673.     Print(win,388,76,"Intern <-> Extern");
  674.  
  675.     {
  676.         long pri;
  677.         char str[5];        
  678.  
  679.         pri=SetTaskPri(FindTask(0),0);
  680.         if (pri>128) pri=pri-256;
  681.         SetTaskPri(FindTask(0),pri);
  682.         DrawBox(win->RPort,380,98,530,108);
  683.          Print(win,392,106,"Priority:");
  684.          sprintf(str,"%4d",pri);
  685.         Print(win,495,106,str);
  686.     }
  687. }
  688.  
  689. /**********************************************************************************/
  690. /***                                                                            ***/
  691. /**********************************************************************************/
  692.  
  693. void CheckWbCall(int argc, char **argv)
  694. {
  695.     struct DiskObject *pdo = NULL;
  696.     char *cp = NULL;
  697.  
  698.     SCREEN=0;
  699.     WBLACE=0;
  700.  
  701.     if (argc==0)
  702.     {
  703.         if(pdo = GetDiskObject( ((struct WBStartup *)argv)->sm_ArgList->wa_Name) )
  704.         {
  705.             if(cp = FindToolType(pdo->do_ToolTypes, "SCREEN"))
  706.                 if(MatchToolValue(cp, "ON")) SCREEN = 1;
  707.  
  708.             if(cp = FindToolType(pdo->do_ToolTypes, "LACE"))
  709.                 if(MatchToolValue(cp, "ON")) WBLACE = 1;
  710.  
  711.             if(cp = FindToolType(pdo->do_ToolTypes, "GETDUMP"))
  712.                 if(MatchToolValue(cp, "ON")) GETDUMP = 1;
  713.  
  714.             if(cp = FindToolType(pdo->do_ToolTypes, "INITIALIZE"))
  715.                 if(MatchToolValue(cp, "ON")) INITIALIZE= 1;
  716.  
  717.             if(cp = FindToolType(pdo->do_ToolTypes, "BANKDIR"))
  718.                 strcpy(bankdir,cp);
  719.  
  720.             if(cp = FindToolType(pdo->do_ToolTypes, "SOUNDDIR"))
  721.                 strcpy(sounddir,cp);
  722.  
  723.             if(cp = FindToolType(pdo->do_ToolTypes, "MULTIDIR"))
  724.                 strcpy(multidir,cp);
  725.  
  726.             if(cp = FindToolType(pdo->do_ToolTypes, "DUMPDIR"))
  727.                 strcpy(dumpdir,cp);
  728.  
  729.             if(cp = FindToolType(pdo->do_ToolTypes, "DEFAULTDUMP"))
  730.             {
  731.                 strcpy(DEFDUMPNAME,cp);
  732.                 DEFAULTDUMP=1;
  733.             }    
  734.         }
  735.         if(pdo) FreeDiskObject(pdo);
  736.     }
  737.  
  738.     if (argc==2 && argv[1][0]=='?')
  739.     {
  740.         MyReq(    
  741.             "              K1-II - Librarian V "VERSION"\n"
  742.             "\n"   
  743.             "                  (C) in 1990-92 by\n"
  744.             "                     Andreas Jung\n"
  745.             "                   Klosterstraße 21\n"
  746.             "                   D-6602 Dudweiler\n"
  747.             "             Federal Republic of Germany\n"
  748.             "\n"
  749.             "Available options   'S' - Use custom screen\n"
  750.             "from CLI:           'L' - Use interlace screen\n"
  751.             "                    'G' - Get single- and multipatch dump \n"
  752.             "                    'I' - Initialize all patches\n",NULL,"Leave");          
  753.         CloseStuff();
  754.     }
  755.     else
  756.     {
  757.         int i;
  758.  
  759.         for (i=1;i<argc;i++)
  760.         {
  761.  
  762.             if (tolower(argv[i][0])=='s') { SCREEN=1; }
  763.  
  764.             if (tolower(argv[i][0])=='l') { WBLACE=1; SCREEN=1; }
  765.  
  766.             if (tolower(argv[i][0])=='g') { GETDUMP=1;}
  767.  
  768.             if (tolower(argv[i][0])=='i') { INITIALIZE=1;}
  769.         }
  770.     }
  771. }
  772.  
  773. /**********************************************************************************/
  774. /***                                                                            ***/
  775. /**********************************************************************************/
  776.  
  777. void Colours(void)
  778. {
  779.     FILE *fp,*fopen();
  780.  
  781.     if (SCREEN==0) scr=IntuitionBase->ActiveScreen;
  782.  
  783.     colstruct.defcolor=0;
  784.     colstruct.window=win;
  785.  
  786.     if (ExtendedColorRequester(&colstruct) != 65535)
  787.     {
  788.         fp=fopen("DEVS:K1-LibColours","w");
  789.         if (fp!=NULL)
  790.         {
  791.             fprintf(fp, "%ld %ld %ld %ld\n",
  792.                 GetRGB4(scr->ViewPort.ColorMap, 0),
  793.                 GetRGB4(scr->ViewPort.ColorMap, 1),
  794.                 GetRGB4(scr->ViewPort.ColorMap, 2),
  795.                 GetRGB4(scr->ViewPort.ColorMap, 3) );
  796.             fclose(fp);
  797.         }
  798.         GetColours();
  799.     }
  800. }
  801.  
  802. /**********************************************************************************/
  803. /***                                                                            ***/
  804. /**********************************************************************************/
  805.  
  806. void InitializeAll(int bool)
  807. {
  808.     int i,j,k;
  809.  
  810.     SetTitle("Initialize all patches");
  811.  
  812.     if (bool==1)
  813.     {
  814.         if (MyReq("  Are you really shure ???\nEverything will be erased !"," Yes ","Oh no"))
  815.         {
  816.             ZZ_POINTER(win);
  817.  
  818.             for (k=0;k<=1;k++)
  819.                 for (i=0;i<=31;i++)
  820.                     for(j=0;j<=87;j++) s[k][i][j]=initsing[j];
  821.  
  822.             for (i=0;i<=31;i++)
  823.                 for(j=0;j<=75;j++) m[i][j]=initmul[j];
  824.  
  825.             CLEAR_POINTER(win);
  826.         }
  827.         Display();
  828.     }
  829.     else
  830.     {
  831.         ZZ_POINTER(win);
  832.  
  833.         for (k=0;k<=1;k++)
  834.             for (i=0;i<=31;i++)
  835.                 for(j=0;j<=87;j++) s[k][i][j]=initsing[j];
  836.  
  837.         for (i=0;i<=31;i++)
  838.             for(j=0;j<=75;j++) m[i][j]=initmul[j];
  839.         CLEAR_POINTER(win);
  840.     }
  841.     bankname[0][0]=NULL;
  842.     bankname[1][0]=NULL;
  843.     multiname[0]=NULL;
  844.     Display();
  845. }
  846.  
  847. /**********************************************************************************/
  848. /***                                                                            ***/
  849. /**********************************************************************************/
  850.  
  851. void SingleCopyTo(int nr)
  852. {
  853.     int i,x,y,soundnr;
  854.  
  855.     SetTitle("Select position to copy to");
  856.  
  857.     MODWIN
  858.     Loop: ;
  859.     WaitPort(win->UserPort);
  860.     mesg=(struct IntuiMessage *) GetMsg(win->UserPort);
  861.     x=mesg->MouseX;
  862.     y=mesg->MouseY;
  863.  
  864.     if (mesg->Class==MOUSEBUTTONS && mesg->Code==SELECTDOWN)
  865.     {
  866.         ReplyMsg((struct Message *)mesg);
  867.  
  868.         if (Check(x,y,15,615,28,189) && multi==0)
  869.         {
  870.             if (x>15 && x<315)    soundnr=(y-28)/10*2+((x<165)?0:1);
  871.             if (x>315 && x<615)    soundnr=32+(y-28)/10*2+((x<465)?0:1);
  872.  
  873.             for (i=0;i<=87;i++) s[soundnr/32][soundnr%32][i]=s[nr/32][nr%32][i];
  874.             TransmitSingleSound(soundnr);
  875.             multi=0;
  876.             Display();
  877.         }
  878.         else goto Loop;
  879.     }
  880.     else
  881.     {
  882.         ReplyMsg((struct Message *)mesg);
  883.         goto Loop;
  884.     }
  885. }
  886.  
  887. /**********************************************************************************/
  888. /***                                                                            ***/
  889. /**********************************************************************************/
  890.  
  891. void SingleSwapWith(int nr)
  892. {
  893.     int i,x,y,soundnr;
  894.  
  895.     SetTitle("Select position to swap with");
  896.  
  897.     MODWIN
  898. Loop: ;
  899.     WaitPort(win->UserPort);
  900.     mesg=(struct IntuiMessage *) GetMsg(win->UserPort);
  901.     x=mesg->MouseX;
  902.     y=mesg->MouseY;
  903.  
  904.     if (mesg->Class==MOUSEBUTTONS && mesg->Code==SELECTDOWN)
  905.     {
  906.         ReplyMsg((struct Message *)mesg);
  907.  
  908.         if (Check(x,y,15,615,28,189) && multi==0)
  909.         {
  910.             if (x>15 && x<315)    soundnr=(y-28)/10*2+((x<165)?0:1);
  911.             if (x>315 && x<615)    soundnr=32+(y-28)/10*2+((x<465)?0:1);
  912.  
  913.         for (i=0;i<=87;i++)
  914.         {
  915.                 int h;
  916.  
  917.                 h=s[soundnr/32][soundnr%32][i];
  918.                 s[soundnr/32][soundnr%32][i]=s[nr/32][nr%32][i];
  919.                 s[nr/32][nr%32][i]=h;
  920.             }
  921.             TransmitSingleSound(soundnr);
  922.             TransmitSingleSound(nr);
  923.             multi=0;
  924.             Display();
  925.         }
  926.         else goto Loop;
  927.     }
  928.     else
  929.     {
  930.         ReplyMsg((struct Message *)mesg);
  931.         goto Loop;
  932.     }
  933. }
  934.  
  935. /**********************************************************************************/
  936. /***                                                                            ***/
  937. /**********************************************************************************/
  938.  
  939. void MultiCopyTo(int nr)
  940. {
  941.     int i,x,y,soundnr;
  942.  
  943.     SetTitle("Select position to copy to");
  944.  
  945.     MODWIN
  946. Loop: ;
  947.     WaitPort(win->UserPort);
  948.     mesg=(struct IntuiMessage *) GetMsg(win->UserPort);
  949.     x=mesg->MouseX;
  950.     y=mesg->MouseY;
  951.  
  952.     if (mesg->Class==MOUSEBUTTONS && mesg->Code==SELECTDOWN)
  953.     {
  954.         ReplyMsg((struct Message *)mesg);
  955.  
  956.         if (Check(x,y,15,315,28,189) && multi==1)
  957.         {
  958.             if (x>15 && x<315)    soundnr=(y-28)/10*2+((x<165)?0:1);
  959.  
  960.             for (i=0;i<=75;i++) m[soundnr][i]=m[nr][i];
  961.             TransmitSingleMulti(soundnr);
  962.             multi=1;
  963.             Display();
  964.         }
  965.         else goto Loop;
  966.     }
  967.     else
  968.     {
  969.         ReplyMsg((struct Message *)mesg);
  970.         goto Loop;
  971.     }
  972. }
  973.  
  974.  
  975. /**********************************************************************************/
  976. /***                                                                            ***/
  977. /**********************************************************************************/
  978.  
  979. void MultiSwapWith(int nr)
  980. {
  981.     int i,x,y,soundnr;
  982.  
  983.     SetTitle("Select position to swap with");
  984.  
  985.     MODWIN
  986. Loop: ;
  987.     WaitPort(win->UserPort);
  988.     mesg=(struct IntuiMessage *) GetMsg(win->UserPort);
  989.     x=mesg->MouseX;
  990.     y=mesg->MouseY;
  991.  
  992.     if (mesg->Class==MOUSEBUTTONS && mesg->Code==SELECTDOWN)
  993.     {
  994.         ReplyMsg((struct Message *)mesg);
  995.  
  996.         if (Check(x,y,15,315,28,189) && multi==1)
  997.         {
  998.             if (x>15 && x<315)    soundnr=(y-28)/10*2+((x<165)?0:1);
  999.  
  1000.             for (i=0;i<=75;i++)
  1001.             {
  1002.                 int h;
  1003.  
  1004.                 h=m[soundnr][i];
  1005.                 m[soundnr][i]=m[nr][i];
  1006.                 m[nr][i]=h;
  1007.             }
  1008.             TransmitSingleMulti(soundnr);
  1009.             TransmitSingleMulti(nr);
  1010.             multi=1;
  1011.             Display();
  1012.         }
  1013.         else goto Loop;
  1014.     }
  1015.     else
  1016.     {
  1017.         ReplyMsg((struct Message *)mesg);
  1018.         goto Loop;
  1019.     }
  1020. }
  1021.  
  1022. /**********************************************************************************/
  1023. /***                                                                            ***/
  1024. /**********************************************************************************/
  1025.  
  1026. void Quit(void)
  1027. {
  1028.     if (MyReq("Do really want to quit ?"," Yes ","Oh no")==TRUE)    CloseStuff();
  1029. }
  1030.  
  1031. /**********************************************************************************/
  1032. /***                                                                            ***/
  1033. /**********************************************************************************/
  1034.  
  1035. void GetColours(void)
  1036. {
  1037.     struct Screen *scr;
  1038.     FILE *fp,*fopen();
  1039.     long a,b,c,d;
  1040.     struct IntuitionBase *IntuitionBase;
  1041.     
  1042.     IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
  1043.  
  1044.     scr=IntuitionBase->ActiveScreen;
  1045.  
  1046.     fp=fopen("DEVS:K1-LibColours","r");
  1047.     if (fp != NULL)
  1048.     {
  1049.         fscanf(fp, "%ld%ld%ld%ld", &col[0], &col[1], &col[2], &col[3]);
  1050.         fclose(fp);
  1051.     }
  1052.     else Colours();
  1053.     CloseLibrary(IntuitionBase);
  1054. }
  1055.  
  1056.  
  1057. /**********************************************************************************/
  1058. /***                                                                            ***/
  1059. /**********************************************************************************/
  1060.  
  1061. void SaveOldColours(void)
  1062. {
  1063.     struct Screen *scr;
  1064.  
  1065.     IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
  1066.     GfxBase=(struct GfxBase *)     OpenLibrary("graphics.library",0);
  1067.     
  1068.     scr=IntuitionBase->ActiveScreen;
  1069.     oldcol[0]=GetRGB4(scr->ViewPort.ColorMap, 0);
  1070.     oldcol[1]=GetRGB4(scr->ViewPort.ColorMap, 1);
  1071.     oldcol[2]=GetRGB4(scr->ViewPort.ColorMap, 2);
  1072.     oldcol[3]=GetRGB4(scr->ViewPort.ColorMap, 3);
  1073.  
  1074.     CloseLibrary(IntuitionBase);
  1075.     CloseLibrary(GfxBase);    
  1076. }
  1077.  
  1078. /**********************************************************************************/
  1079. /***                                                                            ***/
  1080. /**********************************************************************************/
  1081.  
  1082. void SetColours(void)
  1083. {
  1084.     struct Screen *scr;
  1085.     struct IntuitionBase *IntuitionBase;
  1086.     
  1087.     IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
  1088.  
  1089.     scr=IntuitionBase->ActiveScreen;
  1090.  
  1091.     SetRGB4(&scr->ViewPort, 0, (col[0] & 0xf00) >> 8, (col[0] & 0x0f0) >> 4, col[0] & 0x00f );
  1092.     SetRGB4(&scr->ViewPort, 1, (col[1] & 0xf00) >> 8, (col[1] & 0x0f0) >> 4, col[1] & 0x00f );
  1093.     SetRGB4(&scr->ViewPort, 2, (col[2] & 0xf00) >> 8, (col[2] & 0x0f0) >> 4, col[2] & 0x00f );
  1094.     SetRGB4(&scr->ViewPort, 3, (col[3] & 0xf00) >> 8, (col[3] & 0x0f0) >> 4, col[3] & 0x00f );
  1095.     CloseLibrary(IntuitionBase);
  1096. }
  1097.  
  1098. /**********************************************************************************/
  1099. /***                                                                            ***/
  1100. /**********************************************************************************/
  1101.  
  1102. void SetOldColours(void)
  1103. {
  1104.     struct Screen *scr;
  1105.     long a,b,c,d;
  1106.  
  1107.     a=oldcol[0];
  1108.     b=oldcol[1];
  1109.     c=oldcol[2];
  1110.     d=oldcol[3];
  1111.  
  1112.     scr=IntuitionBase->FirstScreen;
  1113.  
  1114.     SetRGB4(&scr->ViewPort, 0, (a & 0xf00) >> 8, (a & 0x0f0) >> 4, a & 0x00f );
  1115.     SetRGB4(&scr->ViewPort, 1, (b & 0xf00) >> 8, (b & 0x0f0) >> 4, b & 0x00f );
  1116.     SetRGB4(&scr->ViewPort, 2, (c & 0xf00) >> 8, (c & 0x0f0) >> 4, c & 0x00f );
  1117.     SetRGB4(&scr->ViewPort, 3, (d & 0xf00) >> 8, (d & 0x0f0) >> 4, d & 0x00f );
  1118. }
  1119.