home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / goattracker_2.71.zip / src / goattrk2.c < prev    next >
C/C++ Source or Header  |  2010-10-21  |  36KB  |  1,398 lines

  1. //
  2. // GOATTRACKER v2.71
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17. //
  18.  
  19. #define GOATTRK2_C
  20.  
  21. #ifdef __WIN32__
  22. #include <windows.h>
  23. #endif
  24.  
  25. #include "goattrk2.h"
  26. #include "bme.h"
  27.  
  28. int menu = 0;
  29. int editmode = EDIT_PATTERN;
  30. int recordmode = 1;
  31. int followplay = 0;
  32. int hexnybble = -1;
  33. int stepsize = 4;
  34. int autoadvance = 0;
  35. int defaultpatternlength = 64;
  36. int cursorflash = 0;
  37. int cursorcolortable[] = {1,2,7,2};
  38. int exitprogram = 0;
  39. int eacolumn = 0;
  40. int eamode = 0;
  41.  
  42. unsigned keypreset = KEY_TRACKER;
  43. unsigned playerversion = 0;
  44. int fileformat = FORMAT_PRG;
  45. int zeropageadr = 0xfc;
  46. int playeradr = 0x1000;
  47. unsigned sidmodel = 0;
  48. unsigned multiplier = 1;
  49. unsigned adparam = 0x0f00;
  50. unsigned ntsc = 0;
  51. unsigned patternhex = 0;
  52. unsigned sidaddress = 0xd400;
  53. unsigned finevibrato = 1;
  54. unsigned optimizepulse = 1;
  55. unsigned optimizerealtime = 1;
  56. unsigned customclockrate = 0;
  57. unsigned usefinevib = 0;
  58. unsigned b = DEFAULTBUF;
  59. unsigned mr = DEFAULTMIXRATE;
  60. unsigned writer = 0;
  61. unsigned hardsid = 0;
  62. unsigned catweasel = 0;
  63. unsigned interpolate = 0;
  64. unsigned residdelay = 0;
  65. unsigned hardsidbufinteractive = 20;
  66. unsigned hardsidbufplayback = 400;
  67. float basepitch = 0.0f;
  68.  
  69. char configbuf[MAX_PATHNAME];
  70. char loadedsongfilename[MAX_FILENAME];
  71. char songfilename[MAX_FILENAME];
  72. char songfilter[MAX_FILENAME];
  73. char songpath[MAX_PATHNAME];
  74. char instrfilename[MAX_FILENAME];
  75. char instrfilter[MAX_FILENAME];
  76. char instrpath[MAX_PATHNAME];
  77. char packedpath[MAX_PATHNAME];
  78.  
  79. char *programname = "$VER: GoatTracker v2.71";
  80.                                       
  81. char textbuffer[MAX_PATHNAME];
  82.  
  83. unsigned char hexkeytbl[] = {'0', '1', '2', '3', '4', '5', '6', '7',
  84.   '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  85.  
  86. extern unsigned char datafile[];
  87.  
  88. int main(int argc, char **argv)
  89. {
  90.   char filename[MAX_PATHNAME];
  91.   FILE *configfile;
  92.   int c,d;
  93.  
  94.   programname += sizeof "$VER:";
  95.   // Open datafile
  96.   io_openlinkeddatafile(datafile);
  97.  
  98.   // Load configuration
  99.   #ifdef __WIN32__
  100.   GetModuleFileName(NULL, filename, MAX_PATHNAME);
  101.   filename[strlen(filename)-3] = 'c';
  102.   filename[strlen(filename)-2] = 'f';
  103.   filename[strlen(filename)-1] = 'g';
  104.   #elif __amigaos__
  105.   strcpy(filename, "PROGDIR:goattrk2.cfg");
  106.   #else
  107.   strcpy(filename, getenv("HOME"));
  108.   strcat(filename, "/.goattrk/goattrk2.cfg");
  109.   #endif
  110.   configfile = fopen(filename, "rt");
  111.   if (configfile)
  112.   {
  113.     getparam(configfile, &b);
  114.     getparam(configfile, &mr);
  115.     getparam(configfile, &hardsid);
  116.     getparam(configfile, &sidmodel);
  117.     getparam(configfile, &ntsc);
  118.     getparam(configfile, (unsigned *)&fileformat);
  119.     getparam(configfile, (unsigned *)&playeradr);
  120.     getparam(configfile, (unsigned *)&zeropageadr);
  121.     getparam(configfile, &playerversion);
  122.     getparam(configfile, &keypreset);
  123.     getparam(configfile, (unsigned *)&stepsize);
  124.     getparam(configfile, &multiplier);
  125.     getparam(configfile, &catweasel);
  126.     getparam(configfile, &adparam);
  127.     getparam(configfile, &interpolate);
  128.     getparam(configfile, &patternhex);
  129.     getparam(configfile, &sidaddress);
  130.     getparam(configfile, &finevibrato);
  131.     getparam(configfile, &optimizepulse);
  132.     getparam(configfile, &optimizerealtime);
  133.     getparam(configfile, &residdelay);
  134.     getparam(configfile, &customclockrate);
  135.     getparam(configfile, &hardsidbufinteractive);
  136.     getparam(configfile, &hardsidbufplayback);
  137.     getfloatparam(configfile, &filterparams.distortionrate);
  138.     getfloatparam(configfile, &filterparams.distortionpoint);
  139.     getfloatparam(configfile, &filterparams.distortioncfthreshold);
  140.     getfloatparam(configfile, &filterparams.type3baseresistance);
  141.     getfloatparam(configfile, &filterparams.type3offset);
  142.     getfloatparam(configfile, &filterparams.type3steepness);
  143.     getfloatparam(configfile, &filterparams.type3minimumfetresistance);
  144.     getfloatparam(configfile, &filterparams.type4k);
  145.     getfloatparam(configfile, &filterparams.type4b);
  146.     getfloatparam(configfile, &filterparams.voicenonlinearity);
  147.     getparam(configfile, &win_fullscreen);
  148.     getfloatparam(configfile, &basepitch);
  149.     fclose(configfile);
  150.   }
  151.  
  152.   // Init pathnames
  153.   initpaths();
  154.  
  155.   // Scan command line
  156.   for (c = 1; c < argc; c++)
  157.   {
  158.     #ifdef __WIN32__
  159.     if ((argv[c][0] == '-') || (argv[c][0] == '/'))
  160.     #else
  161.     if (argv[c][0] == '-')
  162.     #endif
  163.     {
  164.       int y = 0;
  165.       switch(toupper(argv[c][1]))
  166.       {
  167.         case '?':
  168.         if (!initscreen())
  169.           return 1;
  170.         if(argv[c][2]=='?') 
  171.         {
  172.           onlinehelp(1,0);
  173.           return 0;
  174.         }
  175.         printtext(0,y++,15,"Usage: GOATTRK2 [songname] [options]");
  176.         printtext(0,y++,15,"Options:");
  177.         printtext(0,y++,15,"-Axx Set ADSR parameter for hardrestart in hex. DEFAULT=0F00");
  178.         printtext(0,y++,15,"-Bxx Set sound buffer length in milliseconds DEFAULT=100");
  179.         printtext(0,y++,15,"-Cxx Use CatWeasel MK3 PCI SID (0 = off, 1 = on)");
  180.         printtext(0,y++,15,"-Dxx Pattern row display (0 = decimal, 1 = hexadecimal)");
  181.         printtext(0,y++,15,"-Exx Set emulated SID model (0 = 6581 1 = 8580) DEFAULT=6581");
  182.         printtext(0,y++,15,"-Fxx Set custom SID clock cycles per second (0 = use PAL/NTSC default)");
  183.         printtext(0,y++,15,"-Gxx Set pitch of A-4 in Hz (0 = use default frequencytable, close to 440Hz)");
  184.         printtext(0,y++,15,"-Hxx Use HardSID (0 = off, 1 = HardSID ID0 2 = HardSID ID1 etc.)");
  185.         printtext(0,y++,15,"-Ixx Set reSID interpolation (0 = off, 1 = on, 2 = distortion, 3 = distortion & on) DEFAULT=off");
  186.         printtext(0,y++,15,"-Kxx Note-entry mode (0 = PROTRACKER 1 = DMC) DEFAULT=PROTRK.");
  187.         printtext(0,y++,15,"-Lxx SID memory location in hex. DEFAULT=D400");
  188.         printtext(0,y++,15,"-Mxx Set sound mixing rate DEFAULT=44100");
  189.         printtext(0,y++,15,"-Oxx Set pulseoptimization/skipping (0 = off, 1 = on) DEFAULT=on");
  190.         printtext(0,y++,15,"-Rxx Set realtime-effect optimization/skipping (0 = off, 1 = on) DEFAULT=on");
  191.         printtext(0,y++,15,"-Sxx Set speed multiplier (0 for 25Hz, 1 for 1x, 2 for 2x etc.)");
  192.         printtext(0,y++,15,"-Txx Set HardSID interactive mode sound buffer length in milliseconds DEFAULT=20, max.buffering=0");
  193.         printtext(0,y++,15,"-Uxx Set HardSID playback mode sound buffer length in milliseconds DEFAULT=400, max.buffering=0");
  194.         printtext(0,y++,15,"-Vxx Set finevibrato conversion (0 = off, 1 = on) DEFAULT=on");
  195.         printtext(0,y++,15,"-Xxx Set window type (0 = window, 1 = fullscreen) DEFAULT=window");
  196.         printtext(0,y++,15,"-Zxx Set random reSID write delay in cycles (0 = off) DEFAULT=off");
  197.         printtext(0,y++,15,"-N   Use NTSC timing");
  198.         printtext(0,y++,15,"-P   Use PAL timing (DEFAULT)");
  199.         printtext(0,y++,15,"-W   Write sound output to a file SIDAUDIO.RAW");
  200.         printtext(0,y++,15,"-?   Show this info again");
  201.         printtext(0,y++,15,"-??  Standalone online help window");    
  202.         waitkeynoupdate();
  203.         return 0;
  204.  
  205.         case 'Z':
  206.         sscanf(&argv[c][2], "%u", &residdelay);
  207.         break;
  208.  
  209.         case 'A':
  210.         sscanf(&argv[c][2], "%x", &adparam);
  211.         break;
  212.  
  213.         case 'S':
  214.         sscanf(&argv[c][2], "%u", &multiplier);
  215.         break;
  216.  
  217.         case 'B':
  218.         sscanf(&argv[c][2], "%u", &b);
  219.         break;
  220.  
  221.         case 'D':
  222.         sscanf(&argv[c][2], "%u", &patternhex);
  223.         break;
  224.  
  225.         case 'E':
  226.         sscanf(&argv[c][2], "%u", &sidmodel);
  227.         break;
  228.  
  229.         case 'I':
  230.         sscanf(&argv[c][2], "%u", &interpolate);
  231.         break;
  232.  
  233.         case 'K':
  234.         sscanf(&argv[c][2], "%u", &keypreset);
  235.         break;
  236.  
  237.         case 'L':
  238.         sscanf(&argv[c][2], "%x", &sidaddress);
  239.         break;
  240.  
  241.         case 'N':
  242.         ntsc = 1;
  243.         customclockrate = 0;
  244.         break;
  245.  
  246.         case 'P':
  247.         ntsc = 0;
  248.         customclockrate = 0;
  249.         break;
  250.  
  251.         case 'F':
  252.         sscanf(&argv[c][2], "%u", &customclockrate);
  253.         break;
  254.  
  255.         case 'M':
  256.         sscanf(&argv[c][2], "%u", &mr);
  257.         break;
  258.  
  259.         case 'O':
  260.         sscanf(&argv[c][2], "%u", &optimizepulse);
  261.         break;
  262.  
  263.         case 'R':
  264.         sscanf(&argv[c][2], "%u", &optimizerealtime);
  265.         break;
  266.  
  267.         case 'H':
  268.         sscanf(&argv[c][2], "%u", &hardsid);
  269.         break;
  270.  
  271.         case 'V':
  272.         sscanf(&argv[c][2], "%u", &finevibrato);
  273.         break;
  274.  
  275.         case 'T':
  276.         sscanf(&argv[c][2], "%u", &hardsidbufinteractive);
  277.         break;
  278.  
  279.         case 'U':
  280.         sscanf(&argv[c][2], "%u", &hardsidbufplayback);
  281.         break;
  282.  
  283.         case 'W':
  284.         writer = 1;
  285.         break;
  286.  
  287.         case 'X':
  288.         sscanf(&argv[c][2], "%u", &win_fullscreen);
  289.         break;
  290.  
  291.         case 'C':
  292.         sscanf(&argv[c][2], "%u", &catweasel);
  293.         break;
  294.  
  295.         case 'G':
  296.         sscanf(&argv[c][2], "%f", &basepitch);
  297.         break;
  298.       }
  299.     }
  300.     else
  301.     {
  302.       char startpath[MAX_PATHNAME];
  303.  
  304.       strcpy(songfilename, argv[c]);
  305.       for (d = strlen(argv[c])-1; d >= 0; d--)
  306.       {
  307.         if ((argv[c][d] == '/') || (argv[c][d] == '\\'))
  308.         {
  309.           strcpy(startpath, argv[c]);
  310.           startpath[d+1] = 0;
  311.           chdir(startpath);
  312.           initpaths();
  313.           strcpy(songfilename, &argv[c][d+1]);
  314.           break;
  315.         }
  316.       }
  317.     }
  318.   }
  319.  
  320.   // Validate parameters
  321.   sidmodel &= 1;
  322.   adparam &= 0xffff;
  323.   zeropageadr &= 0xff;
  324.   playeradr &= 0xff00;
  325.   sidaddress &= 0xffff;
  326.   if (!stepsize) stepsize = 4;
  327.   if (multiplier > 16) multiplier = 16;
  328.   if (keypreset > 2) keypreset = 0;
  329.   if ((finevibrato == 1) && (multiplier < 2)) usefinevib = 1;
  330.   if (finevibrato > 1) usefinevib = 1;
  331.   if (optimizepulse > 1) optimizepulse = 1;
  332.   if (optimizerealtime > 1) optimizerealtime = 1;
  333.   if (residdelay > 63) residdelay = 63;
  334.   if (customclockrate < 100) customclockrate = 0;
  335.  
  336.   // Calculate frequencytable if necessary
  337.   if (basepitch < 0.0f)
  338.     basepitch = 0.0f;
  339.   if (basepitch > 0.0f)
  340.     calculatefreqtable();
  341.  
  342.   // Set screenmode
  343.   if (!initscreen())
  344.     return 1;
  345.  
  346.   // Reset channels/song
  347.   initchannels();
  348.   clearsong(1,1,1,1,1);
  349.  
  350.   // Init sound
  351.   if (!sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate))
  352.   {
  353.     printtextc(MAX_ROWS/2-1,15,"Sound init failed. Press any key to run without sound (notice that song timer won't start)");
  354.     waitkeynoupdate();
  355.   }
  356.  
  357.   // Load song if applicable
  358.   if (strlen(songfilename)) loadsong();
  359.  
  360.   // Start editor mainloop
  361.   printmainscreen();
  362.   while (!exitprogram)
  363.   {
  364.     waitkeymouse();
  365.     docommand();
  366.   }
  367.  
  368.   // Shutdown sound output now
  369.   sound_uninit();
  370.  
  371.   // Save configuration
  372.   #ifndef __WIN32__
  373.   #ifdef __amigaos__
  374.   strcpy(filename, "PROGDIR:goattrk2.cfg");
  375.   #else
  376.   strcpy(filename, getenv("HOME"));
  377.   strcat(filename, "/.goattrk");
  378.   mkdir(filename, S_IRUSR | S_IWUSR | S_IXUSR);
  379.   strcat(filename, "/goattrk2.cfg");
  380.   #endif
  381.   #endif
  382.   configfile = fopen(filename, "wt");
  383.   if (configfile)
  384.   {
  385.     fprintf(configfile, ";------------------------------------------------------------------------------\n"
  386.                         ";GT2 config file. Rows starting with ; are comments. Hexadecimal parameters are\n"
  387.                         ";to be preceded with $ and decimal parameters with nothing.                    \n"
  388.                         ";------------------------------------------------------------------------------\n"
  389.                         "\n"
  390.                         ";reSID buffer length (in milliseconds)\n%d\n\n"
  391.                         ";reSID mixing rate (in Hz)\n%d\n\n"
  392.                         ";Hardsid device number (0 = off)\n%d\n\n"
  393.                         ";reSID model (0 = 6581, 1 = 8580)\n%d\n\n"
  394.                         ";Timing mode (0 = PAL, 1 = NTSC)\n%d\n\n"
  395.                         ";Packer/relocator fileformat (0 = SID, 1 = PRG, 2 = BIN)\n%d\n\n"
  396.                         ";Packer/relocator player address\n$%04x\n\n"
  397.                         ";Packer/relocator zeropage baseaddress\n$%02x\n\n"
  398.                         ";Packer/relocator player type (0 = standard ... 3 = minimal)\n%d\n\n"
  399.                         ";Key entry mode (0 = Protracker, 1 = DMC)\n%d\n\n"
  400.                         ";Pattern highlight step size\n%d\n\n"
  401.                         ";Speed multiplier (0 = 25Hz, 1 = 1X, 2 = 2X etc.)\n%d\n\n"
  402.                         ";Use CatWeasel SID (0 = off, 1 = on)\n%d\n\n"
  403.                         ";Hardrestart ADSR parameter\n$%04x\n\n"
  404.                         ";reSID interpolation (0 = off, 1 = on, 2 = distortion, 3 = distortion & on)\n%d\n\n"
  405.                         ";Hexadecimal pattern display (0 = off, 1 = on)\n%d\n\n"
  406.                         ";SID baseaddress\n$%04x\n\n"
  407.                         ";Finevibrato mode (0 = off, 1 = on)\n%d\n\n"
  408.                         ";Pulseskipping (0 = off, 1 = on)\n%d\n\n"
  409.                         ";Realtime effect skipping (0 = off, 1 = on)\n%d\n\n"
  410.                         ";Random reSID write delay in cycles (0 = off)\n%d\n\n"
  411.                         ";Custom SID clock cycles per second (0 = use PAL/NTSC default)\n%d\n\n"
  412.                         ";HardSID interactive mode buffer size (in milliseconds, 0 = maximum/no flush)\n%d\n\n"
  413.                         ";HardSID playback mode buffer size (in milliseconds, 0 = maximum/no flush)\n%d\n\n"
  414.                         ";reSID-fp distortion rate\n%f\n\n"
  415.                         ";reSID-fp distortion point\n%f\n\n"
  416.                         ";reSID-fp distortion CF threshold\n%f\n\n"
  417.                         ";reSID-fp type 3 base resistance\n%f\n\n"
  418.                         ";reSID-fp type 3 base offset\n%f\n\n"
  419.                         ";reSID-fp type 3 base steepness\n%f\n\n"
  420.                         ";reSID-fp type 3 minimum FET resistance\n%f\n\n"
  421.                         ";reSID-fp type 4 k\n%f\n\n"
  422.                         ";reSID-fp type 4 b\n%f\n\n"
  423.                         ";reSID-fp voice nonlinearity\n%f\n\n"
  424.                         ";Window type (0 = window, 1 = fullscreen)\n%d\n\n"
  425.                         ";Base pitch of A-4 in Hz (0 = use default frequencytable)\n%f\n\n",
  426.     b,
  427.     mr,
  428.     hardsid,
  429.     sidmodel,
  430.     ntsc,
  431.     fileformat,
  432.     playeradr,
  433.     zeropageadr,
  434.     playerversion,
  435.     keypreset,
  436.     stepsize,
  437.     multiplier,
  438.     catweasel,
  439.     adparam,
  440.     interpolate,
  441.     patternhex,
  442.     sidaddress,
  443.     finevibrato,
  444.     optimizepulse,
  445.     optimizerealtime,
  446.     residdelay,
  447.     customclockrate,
  448.     hardsidbufinteractive,
  449.     hardsidbufplayback,
  450.     filterparams.distortionrate,
  451.     filterparams.distortionpoint,
  452.     filterparams.distortioncfthreshold,
  453.     filterparams.type3baseresistance,
  454.     filterparams.type3offset,
  455.     filterparams.type3steepness,
  456.     filterparams.type3minimumfetresistance,
  457.     filterparams.type4k,
  458.     filterparams.type4b,
  459.     filterparams.voicenonlinearity,
  460.     win_fullscreen,
  461.     basepitch);
  462.     fclose(configfile);
  463.   }
  464.  
  465.   // Exit
  466.   return 0;
  467. }
  468.  
  469. void waitkey(void)
  470. {
  471.   for (;;)
  472.   {
  473.     displayupdate();
  474.     getkey();
  475.     if ((rawkey) || (key)) break;
  476.     if (win_quitted) break;
  477.   }
  478.  
  479.   converthex();
  480. }
  481.  
  482. void waitkeymouse(void)
  483. {
  484.   for (;;)
  485.   {
  486.     displayupdate();
  487.     getkey();
  488.     if ((rawkey) || (key)) break;
  489.     if (win_quitted) break;
  490.     if (mouseb) break;
  491.   }
  492.  
  493.   converthex();
  494. }
  495.  
  496. void waitkeymousenoupdate(void)
  497. {
  498.   for (;;)
  499.   {
  500.       fliptoscreen();
  501.     getkey();
  502.     if ((rawkey) || (key)) break;
  503.     if (win_quitted) break;
  504.     if (mouseb) break;
  505.   }
  506.  
  507.   converthex();
  508. }
  509.  
  510. void waitkeynoupdate(void)
  511. {
  512.   for (;;)
  513.   {
  514.       fliptoscreen();
  515.     getkey();
  516.     if ((rawkey) || (key)) break;
  517.     if ((mouseb) && (!prevmouseb)) break;
  518.     if (win_quitted) break;
  519.   }
  520. }
  521.  
  522. void converthex()
  523. {
  524.   int c;
  525.  
  526.   hexnybble = -1;
  527.   for (c = 0; c < 16; c++)
  528.   {
  529.     if (tolower(key) == hexkeytbl[c])
  530.     {
  531.       if (c >= 10)
  532.       {
  533.         if (!shiftpressed) hexnybble = c;
  534.       }
  535.       else
  536.       {
  537.         hexnybble = c;
  538.       }
  539.     }
  540.   }
  541. }
  542.  
  543.  
  544. void docommand(void)
  545. {
  546.   // "GUI" operation :)
  547.   mousecommands();
  548.  
  549.   // Mode-specific commands
  550.   switch(editmode)
  551.   {
  552.     case EDIT_ORDERLIST:
  553.     orderlistcommands();
  554.     break;
  555.  
  556.     case EDIT_INSTRUMENT:
  557.     instrumentcommands();
  558.     break;
  559.  
  560.     case EDIT_TABLES:
  561.     tablecommands();
  562.     break;
  563.  
  564.     case EDIT_PATTERN:
  565.     patterncommands();
  566.     break;
  567.  
  568.     case EDIT_NAMES:
  569.     namecommands();
  570.     break;
  571.   }
  572.  
  573.   // General commands
  574.   generalcommands();
  575. }
  576.  
  577. void mousecommands(void)
  578. {
  579.   int c;
  580.  
  581.   if (!mouseb) return;
  582.  
  583.   // Pattern editpos & pattern number selection
  584.   for (c = 0; c < MAX_CHN; c++)
  585.   {
  586.     if ((mousey == 2) && (mousex >= 13 + c*15) && (mousex <= 14 + c*15))
  587.     {
  588.         if ((!prevmouseb) || (mouseheld > HOLDDELAY))
  589.         {
  590.         if (mouseb & MOUSEB_LEFT) 
  591.         {
  592.           epchn = c;
  593.           nextpattern();
  594.         }
  595.         if (mouseb & MOUSEB_RIGHT)
  596.         {
  597.           epchn = c;
  598.           prevpattern();
  599.         }
  600.       }
  601.     }
  602.     else
  603.     {
  604.       if ((mousey >= 2) && (mousey <= 34) && (mousex >= 6 + c*15) && (mousex <= 14 + c*15))
  605.       {
  606.         int x = mousex-6-c*15;
  607.         int newpos = mousey-3+epview;
  608.         if (newpos < 0) newpos = 0;
  609.         if (newpos > pattlen[epnum[epchn]]) newpos = pattlen[epnum[epchn]];
  610.  
  611.         editmode = EDIT_PATTERN;
  612.  
  613.         if ((mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) && (!prevmouseb))
  614.         {
  615.           if ((epmarkchn != c) || (newpos != epmarkend))
  616.           {
  617.             epmarkchn = c;
  618.             epmarkstart = epmarkend = newpos;
  619.           }
  620.         }
  621.  
  622.         if (mouseb & MOUSEB_LEFT)
  623.         {
  624.           epchn = c;
  625.           if (x < 4) epcolumn = 0;
  626.           if (x >= 4) epcolumn = x-3;
  627.         }
  628.  
  629.         if (!prevmouseb)
  630.         {
  631.           if (mouseb & MOUSEB_LEFT)
  632.             eppos = newpos;
  633.         }
  634.         else
  635.         {
  636.             if (mouseb & MOUSEB_LEFT)
  637.             {
  638.             if (mousey == 2) eppos--;
  639.             if (mousey == 34) eppos++;
  640.           }
  641.         }
  642.         if (eppos < 0) eppos = 0;
  643.         if (eppos > pattlen[epnum[epchn]]) eppos = pattlen[epnum[epchn]];
  644.  
  645.         if (mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) epmarkend = newpos;
  646.       }
  647.     }
  648.   }
  649.  
  650.   // Song editpos & songnumber selection
  651.   if ((mousey >= 3) && (mousey <= 8) && (mousex >= 40+10))
  652.   {
  653.     int newpos = esview + (mousex-44-10) / 3;
  654.     int newcolumn = (mousex-44-10) % 3;
  655.     int newchn = mousey - 3;
  656.     if (newcolumn < 0) newcolumn = 0;
  657.     if (newcolumn > 1) newcolumn = 1;
  658.     if (newpos < 0)
  659.     {
  660.       newpos = 0;
  661.       newcolumn = 0;
  662.     }
  663.     if (newpos == songlen[esnum][eschn])
  664.     {
  665.       newpos++;
  666.       newcolumn = 0;
  667.     }
  668.     if (newpos > songlen[esnum][eschn]+1)
  669.     {
  670.       newpos = songlen[esnum][eschn] + 1;
  671.       newcolumn = 1;
  672.     }
  673.  
  674.     editmode = EDIT_ORDERLIST;
  675.  
  676.     if ((mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) && (!prevmouseb) && (newpos < songlen[esnum][eschn]))
  677.     {
  678.       if ((esmarkchn != newchn) || (newpos != esmarkend))
  679.       {
  680.         esmarkchn = newchn;
  681.         esmarkstart = esmarkend = newpos;
  682.       }
  683.     }
  684.  
  685.     if (mouseb & MOUSEB_LEFT)
  686.     {
  687.       eschn = newchn;
  688.       eseditpos = newpos;
  689.       escolumn = newcolumn;
  690.     }
  691.  
  692.     if ((mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) && (newpos < songlen[esnum][eschn])) esmarkend = newpos;
  693.   }
  694.   if (((!prevmouseb) || (mouseheld > HOLDDELAY)) && (mousey == 2) && (mousex >= 63+10) && (mousex <= 64+10))
  695.   {
  696.     if (mouseb & MOUSEB_LEFT) nextsong();
  697.     if (mouseb & MOUSEB_RIGHT) prevsong();
  698.   }
  699.  
  700.   // Instrument editpos & instrument number selection
  701.   if ((mousey >= 8) && (mousey <= 12) && (mousex >= 56+10) && (mousex <= 57+10))
  702.   {
  703.     editmode = EDIT_INSTRUMENT;
  704.     eipos = mousey-8;
  705.     eicolumn = mousex-56-10;
  706.   }
  707.   if ((mousey >= 8) && (mousey <= 11) && (mousex >= 76+10) && (mousex <= 77+10))
  708.   {
  709.     editmode = EDIT_INSTRUMENT;
  710.     eipos = mousey-8+5;
  711.     eicolumn = mousex-76-10;
  712.   }
  713.   if ((mousey == 7) && (mousex >= 60+10))
  714.   {
  715.     editmode = EDIT_INSTRUMENT;
  716.     eipos = 9;
  717.   }
  718.   if (((!prevmouseb) || (mouseheld > HOLDDELAY)) && (mousey == 7) && (mousex >= 56+10) && (mousex <= 57+10))
  719.   {
  720.     if (mouseb & MOUSEB_LEFT) nextinstr();
  721.     if (mouseb & MOUSEB_RIGHT) previnstr();
  722.   }
  723.  
  724.  
  725.   // Table editpos
  726.   for (c = 0; c < MAX_TABLES; c++)
  727.   {
  728.     if ((mousey >= 14) && (mousey <= 30) && (mousex >= 43+10+c*10) && (mousex <= 47+10+c*10))
  729.     {
  730.       int newpos = mousey-15+etview[etnum];
  731.       if (newpos < 0) newpos = 0;
  732.       if (newpos >= MAX_TABLELEN) newpos = MAX_TABLELEN-1;
  733.  
  734.       editmode = EDIT_TABLES;
  735.  
  736.       if ((mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) && (!prevmouseb))
  737.       {
  738.         if ((etmarknum != etnum) || (newpos != etmarkend))
  739.         {
  740.           etmarknum = c;
  741.           etmarkstart = etmarkend = newpos;
  742.         }
  743.       }
  744.       if (mouseb & MOUSEB_LEFT)
  745.       {
  746.         etnum = c;
  747.         etpos = mousey-15+etview[etnum];
  748.         etcolumn = mousex-43-10-c*10;
  749.       }
  750.       if (etcolumn >= 2) etcolumn--;
  751.       if (etpos < 0) etpos = 0;
  752.       if (etpos > MAX_TABLELEN-1) etpos = MAX_TABLELEN-1;
  753.  
  754.       if (mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) etmarkend = newpos;
  755.     }
  756.   }
  757.  
  758.   // Name editpos
  759.   if ((mousey >= 31) && (mousey <= 33) && (mousex >= 47+10))
  760.   {
  761.     editmode = EDIT_NAMES;
  762.     enpos = mousey - 31;
  763.   }
  764.  
  765.   // Status panel
  766.   if ((!prevmouseb) && (mousex == 7) && (mousey == 23+3+9))
  767.   {
  768.     if (mouseb & (MOUSEB_LEFT))
  769.       if (epoctave < 7) epoctave++;
  770.     if (mouseb & (MOUSEB_RIGHT))
  771.       if (epoctave > 0) epoctave--;
  772.   }
  773.   if ((!prevmouseb) && (mousex <= 7) && (mousey == 24+3+9))
  774.   {
  775.     recordmode ^= 1;
  776.   }
  777.   for (c = 0; c < MAX_CHN; c++)
  778.   {
  779.     if ((!prevmouseb) && (mousey >= 23+3+9) && (mousex >= 80 + 7*c) && (mousex <= 85 + 7*c))
  780.       mutechannel(c);
  781.   }
  782.  
  783.   // Titlebar actions
  784.   if (!menu)
  785.   {
  786.     if ((mousey == 0) && (!prevmouseb) && (mouseb == MOUSEB_LEFT))
  787.     {
  788.       if ((mousex >= 40+10) && (mousex <= 41+10))
  789.       {
  790.         usefinevib ^= 1;
  791.       }
  792.       if ((mousex >= 43+10) && (mousex <= 44+10))
  793.       {
  794.         optimizepulse ^= 1;
  795.       }
  796.       if ((mousex >= 46+10) && (mousex <= 47+10))
  797.       {
  798.         optimizerealtime ^= 1;
  799.       }
  800.       if ((mousex >= 49+10) && (mousex <= 52+10))
  801.       {
  802.         ntsc ^= 1;
  803.         sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate);
  804.       }
  805.       if ((mousex >= 54+10) && (mousex <= 57+10))
  806.       {
  807.         sidmodel ^= 1;
  808.         sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate);
  809.       }
  810.       if ((mousex >= 62+10) && (mousex <= 65+10)) editadsr();
  811.       if ((mousex >= 67+10) && (mousex <= 68+10)) prevmultiplier();
  812.       if ((mousex >= 69+10) && (mousex <= 70+10)) nextmultiplier();
  813.     }
  814.   }
  815.   else
  816.   {
  817.     if ((!mousey) && (mouseb & MOUSEB_LEFT) && (!(prevmouseb & MOUSEB_LEFT)))
  818.     {
  819.       if ((mousex >= 0) && (mousex <= 5))
  820.       {
  821.         initsong(esnum, PLAY_BEGINNING);
  822.         followplay = shiftpressed;
  823.       }
  824.       if ((mousex >= 7) && (mousex <= 15))
  825.       {
  826.         initsong(esnum, PLAY_POS);
  827.         followplay = shiftpressed;
  828.       }
  829.       if ((mousex >= 17) && (mousex <= 26))
  830.       {
  831.         initsong(esnum, PLAY_PATTERN);
  832.         followplay = shiftpressed;
  833.       }
  834.       if ((mousex >= 28) && (mousex <= 33))
  835.         stopsong();
  836.       if ((mousex >= 35) && (mousex <= 40))
  837.         load();
  838.       if ((mousex >= 42) && (mousex <= 47))
  839.         save();
  840.       if ((mousex >= 49) && (mousex <= 57))
  841.         relocator();
  842.       if ((mousex >= 59) && (mousex <= 64))
  843.         onlinehelp(0,0);
  844.       if ((mousex >= 66) && (mousex <= 72))
  845.         clear();
  846.       if ((mousex >= 74) && (mousex <= 79))
  847.         quit();
  848.     }
  849.   }
  850. }
  851.  
  852. void generalcommands(void)
  853. {
  854.   int c;
  855.  
  856.   switch(key)
  857.   {
  858.     case '?':
  859.     case '-':
  860.     if ((editmode != EDIT_NAMES) && (editmode != EDIT_ORDERLIST))
  861.     {
  862.       if (!((editmode == EDIT_INSTRUMENT) && (eipos == 9))) previnstr();
  863.     }
  864.     break;
  865.  
  866.     case '+':
  867.     case '_':
  868.     if ((editmode != EDIT_NAMES) && (editmode != EDIT_ORDERLIST))
  869.     {
  870.       if (!((editmode == EDIT_INSTRUMENT) && (eipos >= 9))) nextinstr();
  871.  
  872.     }
  873.     break;
  874.  
  875.     case '*':
  876.     if (editmode != EDIT_NAMES)
  877.     {
  878.       if (!((editmode == EDIT_INSTRUMENT) && (eipos >= 9)))
  879.       {
  880.         if (epoctave < 7) epoctave++;
  881.       }
  882.     }
  883.     break;
  884.  
  885.     case '/':
  886.     case '\'':
  887.     if (editmode != EDIT_NAMES)
  888.     {
  889.       if (!((editmode == EDIT_INSTRUMENT) && (eipos >= 9)))
  890.       {
  891.         if (epoctave > 0) epoctave--;
  892.       }
  893.     }
  894.     break;
  895.  
  896.     case '<':
  897.     if (((editmode == EDIT_INSTRUMENT) && (eipos != 9)) || (editmode == EDIT_TABLES))
  898.       previnstr();
  899.     break;
  900.  
  901.     case '>':
  902.     if (((editmode == EDIT_INSTRUMENT) && (eipos != 9)) || (editmode == EDIT_TABLES))
  903.       nextinstr();
  904.     break;
  905.  
  906.     case ';':
  907.     for (c = 0; c < MAX_CHN; c++)
  908.     {
  909.       if (espos[c]) espos[c]--;
  910.       if (espos[c] < esview)
  911.       {
  912.         esview = espos[c];
  913.         eseditpos = espos[c];
  914.       }
  915.     }
  916.     updateviewtopos();
  917.     rewindsong();
  918.     break;
  919.  
  920.     case ':':
  921.     for (c = 0; c < MAX_CHN; c++)
  922.     {
  923.       if (espos[c] < songlen[esnum][c]-1)
  924.         espos[c]++;
  925.       if (espos[c] - esview >= VISIBLEORDERLIST)
  926.       {
  927.         esview = espos[c] - VISIBLEORDERLIST + 1;
  928.         eseditpos = espos[c];
  929.       }
  930.     }
  931.     updateviewtopos();
  932.     rewindsong();
  933.     break;
  934.  
  935.   }
  936.   if (win_quitted) exitprogram = 1;
  937.   switch(rawkey)
  938.   {
  939.     case KEY_ESC:
  940.     if (!shiftpressed)
  941.       quit();
  942.     else
  943.       clear();
  944.     break;
  945.  
  946.     case KEY_KPMULTIPLY:
  947.     if ((editmode != EDIT_NAMES) && (!key))
  948.     {
  949.       if (!((editmode == EDIT_INSTRUMENT) && (eipos >= 9)))
  950.       {
  951.         if (epoctave < 7) epoctave++;
  952.       }
  953.     }
  954.     break;
  955.  
  956.     case KEY_KPDIVIDE:
  957.     if ((editmode != EDIT_NAMES) && (!key))
  958.     {
  959.       if (!((editmode == EDIT_INSTRUMENT) && (eipos >= 9)))
  960.       {
  961.         if (epoctave > 0) epoctave--;
  962.       }
  963.     }
  964.     break;
  965.  
  966.     case KEY_F12:
  967.       onlinehelp(0, shiftpressed);
  968.     break;
  969.  
  970.     case KEY_TAB:
  971.     if (!shiftpressed) editmode++;
  972.     else editmode--;
  973.     if (editmode > EDIT_NAMES) editmode = EDIT_PATTERN;
  974.     if (editmode < EDIT_PATTERN) editmode = EDIT_NAMES;
  975.     break;
  976.  
  977.     case KEY_F1:
  978.     initsong(esnum, PLAY_BEGINNING);
  979.     followplay = shiftpressed;
  980.     break;
  981.  
  982.     case KEY_F2:
  983.     initsong(esnum, PLAY_POS);
  984.     followplay = shiftpressed;
  985.     break;
  986.  
  987.     case KEY_F3:
  988.     initsong(esnum, PLAY_PATTERN);
  989.     followplay = shiftpressed;
  990.     break;
  991.  
  992.     case KEY_F4:
  993.     if (shiftpressed)
  994.       mutechannel(epchn);
  995.     else
  996.     stopsong();
  997.     break;
  998.  
  999.     case KEY_F5:
  1000.     if (!shiftpressed)
  1001.       editmode = EDIT_PATTERN;
  1002.     else prevmultiplier();
  1003.     break;
  1004.  
  1005.     case KEY_F6:
  1006.     if (!shiftpressed)
  1007.       editmode = EDIT_ORDERLIST;
  1008.     else nextmultiplier();
  1009.     break;
  1010.  
  1011.     case KEY_F7:
  1012.     if (!shiftpressed)
  1013.     {
  1014.       if (editmode == EDIT_INSTRUMENT)
  1015.         editmode = EDIT_TABLES;
  1016.       else
  1017.         editmode = EDIT_INSTRUMENT;
  1018.     }
  1019.     else editadsr();
  1020.     break;
  1021.  
  1022.     case KEY_F8:
  1023.     if (!shiftpressed)
  1024.       editmode = EDIT_NAMES;
  1025.     else
  1026.     {
  1027.       sidmodel ^= 1;
  1028.       sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate);
  1029.     }
  1030.     break;
  1031.  
  1032.     case KEY_F9:
  1033.     relocator();
  1034.     break;
  1035.  
  1036.     case KEY_F10:
  1037.     load();
  1038.     break;
  1039.  
  1040.     case KEY_F11:
  1041.     save();
  1042.     break;
  1043.   }
  1044. }
  1045.  
  1046. void load(void)
  1047. {
  1048.   if ((editmode != EDIT_INSTRUMENT) && (editmode != EDIT_TABLES))
  1049.   {
  1050.     if (fileselector(songfilename, songpath, songfilter, "LOAD SONG", 0))
  1051.       loadsong();
  1052.   }
  1053.   else
  1054.   {
  1055.     if (einum)
  1056.     {
  1057.       if (fileselector(instrfilename, instrpath, instrfilter, "LOAD INSTRUMENT", 0))
  1058.         loadinstrument();
  1059.     }
  1060.   }
  1061.   key = 0;
  1062.   rawkey = 0;
  1063. }
  1064.  
  1065. void save(void)
  1066. {
  1067.   if ((editmode != EDIT_INSTRUMENT) && (editmode != EDIT_TABLES))
  1068.   {
  1069.     int done = 0;
  1070.  
  1071.     // Repeat until quit or save successful
  1072.     while (!done)
  1073.     {
  1074.       if (strlen(loadedsongfilename)) strcpy(songfilename, loadedsongfilename);
  1075.       if (fileselector(songfilename, songpath, songfilter, "SAVE SONG", 3))
  1076.         done = savesong();
  1077.       else done = 1;
  1078.     }
  1079.   }
  1080.   else
  1081.   {
  1082.     if (einum)
  1083.     {
  1084.       int done = 0;
  1085.       int useinstrname = 0;
  1086.       char tempfilename[MAX_FILENAME];
  1087.  
  1088.       // Repeat until quit or save successful
  1089.       while (!done)
  1090.       {
  1091.         if ((!strlen(instrfilename)) && (strlen(instr[einum].name)))
  1092.         {
  1093.           useinstrname = 1;
  1094.           strcpy(instrfilename, instr[einum].name);
  1095.           strcat(instrfilename, ".ins");
  1096.           strcpy(tempfilename, instrfilename);
  1097.         }
  1098.  
  1099.         if (fileselector(instrfilename, instrpath, instrfilter, "SAVE INSTRUMENT", 3))
  1100.           done = saveinstrument();
  1101.         else done = 1;
  1102.  
  1103.         if (useinstrname)
  1104.         {
  1105.           if (!strcmp(tempfilename, instrfilename))
  1106.             memset(instrfilename, 0, sizeof instrfilename);
  1107.         }
  1108.       }
  1109.     }
  1110.   }
  1111.   key = 0;
  1112.   rawkey = 0;
  1113. }
  1114.  
  1115. void quit(void)
  1116. {
  1117.   if ((!shiftpressed) || (mouseb))
  1118.   {
  1119.     printtextcp(49, 36, 15, "Really Quit (y/n)?");
  1120.     waitkey();
  1121.     printblank(20, 36, 58);
  1122.     if ((key == 'y') || (key == 'Y')) exitprogram = 1;
  1123.   }
  1124.   key = 0;
  1125.   rawkey = 0;
  1126. }
  1127.  
  1128. void clear(void)
  1129. {
  1130.   int cs = 0;
  1131.   int cp = 0;
  1132.   int ci = 0;
  1133.   int ct = 0;
  1134.   int cn = 0;
  1135.  
  1136.   printtextcp(49, 36, 15, "Optimize everything (y/n)?");
  1137.   waitkey();
  1138.   printblank(20, 36, 58);
  1139.   if ((key == 'y') || (key == 'Y'))
  1140.   {
  1141.     optimizeeverything(1, 1);
  1142.     key = 0;
  1143.     rawkey = 0;
  1144.     return;
  1145.   }
  1146.  
  1147.   printtextcp(49, 36, 15, "Clear orderlists (y/n)?");
  1148.   waitkey();
  1149.   printblank(20, 36, 58);
  1150.   if ((key == 'y') || (key == 'Y')) cs = 1;
  1151.  
  1152.   printtextcp(49, 36, 15, "Clear patterns (y/n)?");
  1153.   waitkey();
  1154.   printblank(20, 36, 58);
  1155.   if ((key == 'y') || (key == 'Y')) cp = 1;
  1156.  
  1157.   printtextcp(49, 36, 15, "Clear instruments (y/n)?");
  1158.   waitkey();
  1159.   printblank(20, 36, 58);
  1160.   if ((key == 'y') || (key == 'Y')) ci = 1;
  1161.  
  1162.   printtextcp(49, 36, 15, "Clear tables (y/n)?");
  1163.   waitkey();
  1164.   printblank(20, 36, 58);
  1165.   if ((key == 'y') || (key == 'Y')) ct = 1;
  1166.  
  1167.   printtextcp(49, 36, 15, "Clear songname (y/n)?");
  1168.   waitkey();
  1169.   printblank(20, 36, 58);
  1170.   if ((key == 'y') || (key == 'Y')) cn = 1;
  1171.  
  1172.   if (cp == 1)
  1173.   {
  1174.     int selectdone = 0;
  1175.     int olddpl = defaultpatternlength;
  1176.  
  1177.     printtext(40, 36, 15,"Pattern length:");
  1178.     while (!selectdone)
  1179.     {
  1180.       sprintf(textbuffer, "%02d ", defaultpatternlength);
  1181.       printtext(55, 36, 15, textbuffer);
  1182.       waitkey();
  1183.       switch(rawkey)
  1184.       {
  1185.         case KEY_LEFT:
  1186.         defaultpatternlength -= 7;
  1187.         case KEY_DOWN:
  1188.         defaultpatternlength--;
  1189.         if (defaultpatternlength < 1) defaultpatternlength = 1;
  1190.         break;
  1191.  
  1192.         case KEY_RIGHT:
  1193.         defaultpatternlength += 7;
  1194.         case KEY_UP:
  1195.         defaultpatternlength++;
  1196.         if (defaultpatternlength > MAX_PATTROWS) defaultpatternlength = MAX_PATTROWS;
  1197.         break;
  1198.  
  1199.         case KEY_ESC:
  1200.         defaultpatternlength = olddpl;
  1201.         selectdone = 1;
  1202.         break;
  1203.  
  1204.         case KEY_ENTER:
  1205.         selectdone = 1;
  1206.         break;
  1207.       }
  1208.     }
  1209.     printblank(20, 36, 58);
  1210.   }
  1211.  
  1212.   if (cs | cp | ci | ct | cn)
  1213.     memset(songfilename, 0, sizeof songfilename);
  1214.   clearsong(cs, cp, ci, ct, cn);
  1215.  
  1216.   key = 0;
  1217.   rawkey = 0;
  1218. }
  1219.  
  1220. void editadsr(void)
  1221. {
  1222.   eamode = 1;
  1223.   eacolumn = 0;
  1224.  
  1225.   for (;;)
  1226.   {
  1227.     waitkeymouse();
  1228.  
  1229.     if (win_quitted)
  1230.     {
  1231.       exitprogram = 1;
  1232.       key = 0;
  1233.       rawkey = 0;
  1234.       return;
  1235.     }
  1236.  
  1237.     if (hexnybble >= 0)
  1238.     {
  1239.       switch(eacolumn)
  1240.       {
  1241.         case 0:
  1242.         adparam &= 0x0fff;
  1243.         adparam |= hexnybble << 12;
  1244.         break;
  1245.  
  1246.         case 1:
  1247.         adparam &= 0xf0ff;
  1248.         adparam |= hexnybble << 8;
  1249.         break;
  1250.  
  1251.         case 2:
  1252.         adparam &= 0xff0f;
  1253.         adparam |= hexnybble << 4;
  1254.         break;
  1255.  
  1256.         case 3:
  1257.         adparam &= 0xfff0;
  1258.         adparam |= hexnybble;
  1259.         break;
  1260.       }
  1261.       eacolumn++;
  1262.     }
  1263.  
  1264.     switch(rawkey)
  1265.     {
  1266.       case KEY_F7:
  1267.       if (!shiftpressed) break;
  1268.  
  1269.       case KEY_ESC:
  1270.       case KEY_ENTER:
  1271.       case KEY_TAB:
  1272.       eamode = 0;
  1273.       key = 0;
  1274.       rawkey = 0;
  1275.       return;
  1276.  
  1277.       case KEY_BACKSPACE:
  1278.       if (!eacolumn) break;
  1279.       case KEY_LEFT:
  1280.       eacolumn--;
  1281.       break;
  1282.  
  1283.       case KEY_RIGHT:
  1284.       eacolumn++;
  1285.     }
  1286.     eacolumn &= 3;
  1287.  
  1288.     if ((mouseb) && (!prevmouseb))
  1289.     {
  1290.       eamode = 0;
  1291.       return;
  1292.     }
  1293.   }
  1294. }
  1295.  
  1296. void getparam(FILE *handle, unsigned *value)
  1297. {
  1298.   char *configptr;
  1299.  
  1300.   for (;;)
  1301.   {
  1302.     if (feof(handle)) return;
  1303.     fgets(configbuf, MAX_PATHNAME, handle);
  1304.     if ((configbuf[0]) && (configbuf[0] != ';') && (configbuf[0] != ' ') && (configbuf[0] != 13) && (configbuf[0] != 10)) break;
  1305.   }
  1306.  
  1307.   configptr = configbuf;
  1308.   if (*configptr == '$')
  1309.   {
  1310.     *value = 0;
  1311.     configptr++;
  1312.     for (;;)
  1313.     {
  1314.       char c = tolower(*configptr++);
  1315.       int h = -1;
  1316.  
  1317.       if ((c >= 'a') && (c <= 'f')) h = c - 'a' + 10;
  1318.       if ((c >= '0') && (c <= '9')) h = c - '0';
  1319.  
  1320.       if (h >= 0)
  1321.       {
  1322.         *value *= 16;
  1323.         *value += h;
  1324.       }
  1325.       else break;
  1326.     }
  1327.   }
  1328.   else
  1329.   {
  1330.     *value = 0;
  1331.     for (;;)
  1332.     {
  1333.       char c = tolower(*configptr++);
  1334.       int d = -1;
  1335.  
  1336.       if ((c >= '0') && (c <= '9')) d = c - '0';
  1337.  
  1338.       if (d >= 0)
  1339.       {
  1340.         *value *= 10;
  1341.         *value += d;
  1342.       }
  1343.       else break;
  1344.     }
  1345.   }
  1346. }
  1347.  
  1348. void getfloatparam(FILE *handle, float *value)
  1349. {
  1350.   char *configptr;
  1351.  
  1352.   for (;;)
  1353.   {
  1354.     if (feof(handle)) return;
  1355.     fgets(configbuf, MAX_PATHNAME, handle);
  1356.     if ((configbuf[0]) && (configbuf[0] != ';') && (configbuf[0] != ' ') && (configbuf[0] != 13) && (configbuf[0] != 10)) break;
  1357.   }
  1358.  
  1359.   configptr = configbuf;
  1360.   *value = 0.0f;
  1361.   sscanf(configptr, "%f", value);
  1362. }
  1363.  
  1364. void prevmultiplier(void)
  1365. {
  1366.   if (multiplier > 0)
  1367.   {
  1368.     multiplier--;
  1369.     sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate);
  1370.   }
  1371. }
  1372.  
  1373. void nextmultiplier(void)
  1374. {
  1375.   if (multiplier < 16)
  1376.   {
  1377.     multiplier++;
  1378.     sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate);
  1379.   }
  1380. }
  1381.  
  1382. void calculatefreqtable()
  1383. {
  1384.   double basefreq = (double)basepitch * (16777216.0 / 985248.0) * pow(2.0, 0.25) / 32.0;
  1385.   int c;
  1386.  
  1387.   for (c = 0; c < 8*12 ; c++)
  1388.   {
  1389.     double note = c;
  1390.     double freq = basefreq * pow(2.0, note/12.0);
  1391.     int intfreq = freq + 0.5;
  1392.     if (intfreq > 0xffff)
  1393.         intfreq = 0xffff;
  1394.     freqtbllo[c] = intfreq & 0xff;
  1395.     freqtblhi[c] = intfreq >> 8;
  1396.   }
  1397. }
  1398.