home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / goattracker_2.74_stereo.zip / src / gt2stereo.c < prev    next >
C/C++ Source or Header  |  2014-07-23  |  36KB  |  1,404 lines

  1. //
  2. // GOATTRACKER v2.74 Stereo
  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 = 0xd500d400;
  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.74 Stereo";
  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/gt2stereo.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.           onlinehelp(1,0);
  172.           return 0;
  173.         }
  174.  
  175.         printtext(0,y++,15,"Usage: GT2STEREO [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,"     Use high nybble (it's hexadecimal) to specify right HardSID ID");
  186.         printtext(0,y++,15,"-Ixx Set reSID interpolation (0 = off, 1 = on, 2 = distortion, 3 = distortion & on) DEFAULT=off");
  187.         printtext(0,y++,15,"-Kxx Note-entry mode (0 = PROTRACKER 1 = DMC) DEFAULT=PROTRK.");
  188.         printtext(0,y++,15,"-Lxx SID memory locations in hex. DEFAULT=D500D400");
  189.         printtext(0,y++,15,"-Mxx Set sound mixing rate DEFAULT=44100");
  190.         printtext(0,y++,15,"-Oxx Set pulseoptimization/skipping (0 = off, 1 = on) DEFAULT=on");
  191.         printtext(0,y++,15,"-Rxx Set realtime-effect optimization/skipping (0 = off, 1 = on) DEFAULT=on");
  192.         printtext(0,y++,15,"-Sxx Set speed multiplier (0 for 25Hz, 1 for 1x, 2 for 2x etc.)");
  193.         printtext(0,y++,15,"-Txx Set HardSID interactive mode sound buffer length in milliseconds DEFAULT=20, max.buffering=0");
  194.         printtext(0,y++,15,"-Uxx Set HardSID playback mode sound buffer length in milliseconds DEFAULT=400, max.buffering=0");
  195.         printtext(0,y++,15,"-Vxx Set finevibrato conversion (0 = off, 1 = on) DEFAULT=on");
  196.         printtext(0,y++,15,"-Xxx Set window type (0 = window, 1 = fullscreen) DEFAULT=window");
  197.         printtext(0,y++,15,"-Zxx Set random reSID write delay in cycles (0 = off) DEFAULT=off");
  198.         printtext(0,y++,15,"-N   Use NTSC timing");
  199.         printtext(0,y++,15,"-P   Use PAL timing (DEFAULT)");
  200.         printtext(0,y++,15,"-W   Write sound output to a file SIDAUDIO.RAW");
  201.         printtext(0,y++,15,"-?   Show this info again");
  202.         printtext(0,y++,15,"-??  Standalone online help window");
  203.         waitkeynoupdate();
  204.         return 0;
  205.  
  206.         case 'Z':
  207.         sscanf(&argv[c][2], "%u", &residdelay);
  208.         break;
  209.  
  210.         case 'A':
  211.         sscanf(&argv[c][2], "%x", &adparam);
  212.         break;
  213.  
  214.         case 'S':
  215.         sscanf(&argv[c][2], "%u", &multiplier);
  216.         break;
  217.  
  218.         case 'B':
  219.         sscanf(&argv[c][2], "%u", &b);
  220.         break;
  221.  
  222.         case 'D':
  223.         sscanf(&argv[c][2], "%u", &patternhex);
  224.         break;
  225.  
  226.         case 'E':
  227.         sscanf(&argv[c][2], "%u", &sidmodel);
  228.         break;
  229.  
  230.         case 'I':
  231.         sscanf(&argv[c][2], "%u", &interpolate);
  232.         break;
  233.  
  234.         case 'K':
  235.         sscanf(&argv[c][2], "%u", &keypreset);
  236.         break;
  237.  
  238.         case 'L':
  239.         sscanf(&argv[c][2], "%x", &sidaddress);
  240.         break;
  241.  
  242.         case 'N':
  243.         ntsc = 1;
  244.         customclockrate = 0;
  245.         break;
  246.  
  247.         case 'P':
  248.         ntsc = 0;
  249.         customclockrate = 0;
  250.         break;
  251.  
  252.         case 'F':
  253.         sscanf(&argv[c][2], "%u", &customclockrate);
  254.         break;
  255.  
  256.         case 'M':
  257.         sscanf(&argv[c][2], "%u", &mr);
  258.         break;
  259.  
  260.         case 'O':
  261.         sscanf(&argv[c][2], "%u", &optimizepulse);
  262.         break;
  263.  
  264.         case 'R':
  265.         sscanf(&argv[c][2], "%u", &optimizerealtime);
  266.         break;
  267.  
  268.         case 'H':
  269.         sscanf(&argv[c][2], "%x", &hardsid);
  270.         break;
  271.  
  272.         case 'V':
  273.         sscanf(&argv[c][2], "%u", &finevibrato);
  274.         break;
  275.  
  276.         case 'T':
  277.         sscanf(&argv[c][2], "%u", &hardsidbufinteractive);
  278.         break;
  279.  
  280.         case 'U':
  281.         sscanf(&argv[c][2], "%u", &hardsidbufplayback);
  282.         break;
  283.  
  284.         case 'W':
  285.         writer = 1;
  286.         break;
  287.  
  288.         case 'X':
  289.         sscanf(&argv[c][2], "%u", &win_fullscreen);
  290.         break;
  291.  
  292.         case 'C':
  293.         sscanf(&argv[c][2], "%u", &catweasel);
  294.         break;
  295.  
  296.         case 'G':
  297.         sscanf(&argv[c][2], "%f", &basepitch);
  298.         break;
  299.       }
  300.     }
  301.     else
  302.     {
  303.       char startpath[MAX_PATHNAME];
  304.  
  305.       strcpy(songfilename, argv[c]);
  306.       for (d = strlen(argv[c])-1; d >= 0; d--)
  307.       {
  308.         if ((argv[c][d] == '/') || (argv[c][d] == '\\'))
  309.         {
  310.           strcpy(startpath, argv[c]);
  311.           startpath[d+1] = 0;
  312.           chdir(startpath);
  313.           initpaths();
  314.           strcpy(songfilename, &argv[c][d+1]);
  315.           break;
  316.         }
  317.       }
  318.     }
  319.   }
  320.  
  321.   // Validate parameters
  322.   sidmodel &= 1;
  323.   adparam &= 0xffff;
  324.   zeropageadr &= 0xff;
  325.   playeradr &= 0xff00;
  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, "/gt2stereo.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 baseaddresses\n$%08x\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 >= 11 + c*9) && (mousex <= 12 + c*9))
  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 >= 5 + c*9) && (mousex <= 12 + c*9))
  605.       {
  606.         int x = mousex - 5 - c*9;
  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 < 3) epcolumn = 0;
  626.           if (x >= 3) epcolumn = x - 2;
  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.  
  651.   // Song editpos & songnumber selection
  652.   if ((mousey >= 3) && (mousey <= 8) && (mousex >= 40+20))
  653.   {
  654.     int newpos = esview + (mousex - 44 - 20) / 3;
  655.     int newcolumn = (mousex - 44 - 20) % 3;
  656.     int newchn = mousey - 3;
  657.     if (newcolumn < 0) newcolumn = 0;
  658.     if (newcolumn > 1) newcolumn = 1;
  659.     if (newpos < 0)
  660.     {
  661.       newpos = 0;
  662.       newcolumn = 0;
  663.     }
  664.     if (newpos == songlen[esnum][eschn])
  665.     {
  666.       newpos++;
  667.       newcolumn = 0;
  668.     }
  669.     if (newpos > songlen[esnum][eschn]+1)
  670.     {
  671.       newpos = songlen[esnum][eschn] + 1;
  672.       newcolumn = 1;
  673.     }
  674.  
  675.     editmode = EDIT_ORDERLIST;
  676.  
  677.     if ((mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) && (!prevmouseb) && (newpos < songlen[esnum][eschn]))
  678.     {
  679.       if ((esmarkchn != newchn) || (newpos != esmarkend))
  680.       {
  681.         esmarkchn = newchn;
  682.         esmarkstart = esmarkend = newpos;
  683.       }
  684.     }
  685.  
  686.     if (mouseb & MOUSEB_LEFT)
  687.     {
  688.       eschn = newchn;
  689.       eseditpos = newpos;
  690.       escolumn = newcolumn;
  691.     }
  692.  
  693.     if ((mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) && (newpos < songlen[esnum][eschn])) esmarkend = newpos;
  694.   }
  695.   if (((!prevmouseb) || (mouseheld > HOLDDELAY)) && (mousey == 2) && (mousex >= 63+20) && (mousex <= 64+20))
  696.   {
  697.     if (mouseb & MOUSEB_LEFT) nextsong();
  698.     if (mouseb & MOUSEB_RIGHT) prevsong();
  699.   }
  700.  
  701.   // Instrument editpos & instrument number selection
  702.   if ((mousey >= 8+3) && (mousey <= 12+3) && (mousex >= 56+20) && (mousex <= 57+20))
  703.   {
  704.     editmode = EDIT_INSTRUMENT;
  705.     eipos = mousey - 8 - 3;
  706.     eicolumn = mousex - 56 - 20;
  707.   }
  708.   if ((mousey >= 8+3) && (mousey <= 11+3) && (mousex >= 76+20) && (mousex <= 77+20))
  709.   {
  710.     editmode = EDIT_INSTRUMENT;
  711.     eipos = mousey - 8 - 3 + 5;
  712.     eicolumn = mousex - 76 - 20;
  713.   }
  714.   if ((mousey == 7+3) && (mousex >= 60+20))
  715.   {
  716.     editmode = EDIT_INSTRUMENT;
  717.     eipos = 9;
  718.   }
  719.   if (((!prevmouseb) || (mouseheld > HOLDDELAY)) && (mousey == 7+3) && (mousex >= 56+20) && (mousex <= 57+20))
  720.   {
  721.     if (mouseb & MOUSEB_LEFT) nextinstr();
  722.     if (mouseb & MOUSEB_RIGHT) previnstr();
  723.   }
  724.  
  725.   // Table editpos
  726.   for (c = 0; c < MAX_TABLES; c++)
  727.   {
  728.     if ((mousey >= 14+3) && (mousey <= 20+3+9) && (mousex >= 43 + 20 + c*10) && (mousex <= 47 + 20 + c*10))
  729.     {
  730.       int newpos = mousey - 15 - 3 + 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 - 3 + etview[etnum];
  748.         etcolumn = mousex - 43 - 20 - 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 == 21+3+9) && (mousex >= 47+20))
  760.   {
  761.     editmode = EDIT_NAMES;
  762.     if ((!prevmouseb) && (mouseb & MOUSEB_RIGHT))
  763.     {
  764.       enpos++;
  765.       if (enpos > 2) enpos = 0;
  766.     }
  767.   }
  768.  
  769.   // Status panel
  770.   if ((!prevmouseb) && (mousex == 7) && (mousey == 23+3+9))
  771.   {
  772.     if (mouseb & (MOUSEB_LEFT))
  773.       if (epoctave < 7) epoctave++;
  774.     if (mouseb & (MOUSEB_RIGHT))
  775.       if (epoctave > 0) epoctave--;
  776.   }
  777.   if ((!prevmouseb) && (mousex <= 7) && (mousey == 24+3+9))
  778.   {
  779.     recordmode ^= 1;
  780.   }
  781.   for (c = 0; c < MAX_CHN; c++)
  782.   {
  783.     if ((!prevmouseb) && (mousey >= 23+3+9) && (mousex >= 59 + 7*c) && (mousex <= 64 + 7*c))
  784.       mutechannel(c);
  785.   }
  786.  
  787.   // Titlebar actions
  788.   if (!menu)
  789.   {
  790.     if ((mousey == 0) && (!prevmouseb) && (mouseb == MOUSEB_LEFT))
  791.     {
  792.       if ((mousex >= 40+20) && (mousex <= 41+20))
  793.       {
  794.         usefinevib ^= 1;
  795.       }
  796.       if ((mousex >= 43+20) && (mousex <= 44+20))
  797.       {
  798.         optimizepulse ^= 1;
  799.       }
  800.       if ((mousex >= 46+20) && (mousex <= 47+20))
  801.       {
  802.         optimizerealtime ^= 1;
  803.       }
  804.       if ((mousex >= 49+20) && (mousex <= 52+20))
  805.       {
  806.         ntsc ^= 1;
  807.         sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate);
  808.       }
  809.       if ((mousex >= 54+20) && (mousex <= 57+20))
  810.       {
  811.         sidmodel ^= 1;
  812.         sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate);
  813.       }
  814.       if ((mousex >= 62+20) && (mousex <= 65+20)) editadsr();
  815.       if ((mousex >= 67+20) && (mousex <= 68+20)) prevmultiplier();
  816.       if ((mousex >= 69+20) && (mousex <= 70+20)) nextmultiplier();
  817.     }
  818.   }
  819.   else
  820.   {
  821.     if ((!mousey) && (mouseb & MOUSEB_LEFT) && (!(prevmouseb & MOUSEB_LEFT)))
  822.     {
  823.       if ((mousex >= 0) && (mousex <= 5))
  824.       {
  825.         initsong(esnum, PLAY_BEGINNING);
  826.         followplay = shiftpressed;
  827.       }
  828.       if ((mousex >= 7) && (mousex <= 15))
  829.       {
  830.         initsong(esnum, PLAY_POS);
  831.         followplay = shiftpressed;
  832.       }
  833.       if ((mousex >= 17) && (mousex <= 26))
  834.       {
  835.         initsong(esnum, PLAY_PATTERN);
  836.         followplay = shiftpressed;
  837.       }
  838.       if ((mousex >= 28) && (mousex <= 33))
  839.         stopsong();
  840.       if ((mousex >= 35) && (mousex <= 40))
  841.         load();
  842.       if ((mousex >= 42) && (mousex <= 47))
  843.         save();
  844.       if ((mousex >= 49) && (mousex <= 57))
  845.         relocator();
  846.       if ((mousex >= 59) && (mousex <= 64))
  847.         onlinehelp(0,0);
  848.       if ((mousex >= 66) && (mousex <= 72))
  849.         clear();
  850.       if ((mousex >= 74) && (mousex <= 79))
  851.         quit();
  852.     }
  853.   }
  854. }
  855.  
  856. void generalcommands(void)
  857. {
  858.   int c;
  859.  
  860.   switch(key)
  861.   {
  862.     case '?':
  863.     case '-':
  864.     if ((editmode != EDIT_NAMES) && (editmode != EDIT_ORDERLIST))
  865.     {
  866.       if (!((editmode == EDIT_INSTRUMENT) && (eipos == 9))) previnstr();
  867.     }
  868.     break;
  869.  
  870.     case '+':
  871.     case '_':
  872.     if ((editmode != EDIT_NAMES) && (editmode != EDIT_ORDERLIST))
  873.     {
  874.       if (!((editmode == EDIT_INSTRUMENT) && (eipos >= 9))) nextinstr();
  875.  
  876.     }
  877.     break;
  878.  
  879.     case '*':
  880.     if (editmode != EDIT_NAMES)
  881.     {
  882.       if (!((editmode == EDIT_INSTRUMENT) && (eipos >= 9)))
  883.       {
  884.         if (epoctave < 7) epoctave++;
  885.       }
  886.     }
  887.     break;
  888.  
  889.     case '/':
  890.     case '\'':
  891.     if (editmode != EDIT_NAMES)
  892.     {
  893.       if (!((editmode == EDIT_INSTRUMENT) && (eipos >= 9)))
  894.       {
  895.         if (epoctave > 0) epoctave--;
  896.       }
  897.     }
  898.     break;
  899.  
  900.     case '<':
  901.     if (((editmode == EDIT_INSTRUMENT) && (eipos != 9)) || (editmode == EDIT_TABLES))
  902.       previnstr();
  903.     break;
  904.  
  905.     case '>':
  906.     if (((editmode == EDIT_INSTRUMENT) && (eipos != 9)) || (editmode == EDIT_TABLES))
  907.       nextinstr();
  908.     break;
  909.  
  910.     case ';':
  911.     for (c = 0; c < MAX_CHN; c++)
  912.     {
  913.       if (espos[c]) espos[c]--;
  914.       if (espos[c] < esview)
  915.       {
  916.         esview = espos[c];
  917.         eseditpos = espos[c];
  918.       }
  919.     }
  920.     updateviewtopos();
  921.     rewindsong();
  922.     break;
  923.  
  924.     case ':':
  925.     for (c = 0; c < MAX_CHN; c++)
  926.     {
  927.       if (espos[c] < songlen[esnum][c]-1)
  928.         espos[c]++;
  929.       if (espos[c] - esview >= VISIBLEORDERLIST)
  930.       {
  931.         esview = espos[c] - VISIBLEORDERLIST + 1;
  932.         eseditpos = espos[c];
  933.       }
  934.     }
  935.     updateviewtopos();
  936.     rewindsong();
  937.     break;
  938.  
  939.   }
  940.   if (win_quitted) exitprogram = 1;
  941.   switch(rawkey)
  942.   {
  943.     case KEY_ESC:
  944.     if (!shiftpressed)
  945.       quit();
  946.     else
  947.       clear();
  948.     break;
  949.  
  950.     case KEY_KPMULTIPLY:
  951.     if ((editmode != EDIT_NAMES) && (!key))
  952.     {
  953.       if (!((editmode == EDIT_INSTRUMENT) && (eipos >= 9)))
  954.       {
  955.         if (epoctave < 7) epoctave++;
  956.       }
  957.     }
  958.     break;
  959.  
  960.     case KEY_KPDIVIDE:
  961.     if ((editmode != EDIT_NAMES) && (!key))
  962.     {
  963.       if (!((editmode == EDIT_INSTRUMENT) && (eipos >= 9)))
  964.       {
  965.         if (epoctave > 0) epoctave--;
  966.       }
  967.     }
  968.     break;
  969.  
  970.     case KEY_F12:
  971.     case SDLK_HELP:
  972.       onlinehelp(0,shiftpressed);
  973.     break;
  974.  
  975.     case KEY_TAB:
  976.     if (!shiftpressed) editmode++;
  977.     else editmode--;
  978.     if (editmode > EDIT_NAMES) editmode = EDIT_PATTERN;
  979.     if (editmode < EDIT_PATTERN) editmode = EDIT_NAMES;
  980.     break;
  981.  
  982.     case KEY_F1:
  983.     initsong(esnum, PLAY_BEGINNING);
  984.     followplay = shiftpressed;
  985.     break;
  986.  
  987.     case KEY_F2:
  988.     initsong(esnum, PLAY_POS);
  989.     followplay = shiftpressed;
  990.     break;
  991.  
  992.     case KEY_F3:
  993.     initsong(esnum, PLAY_PATTERN);
  994.     followplay = shiftpressed;
  995.     break;
  996.  
  997.     case KEY_F4:
  998.     if (shiftpressed)
  999.       mutechannel(epchn);
  1000.     else
  1001.     stopsong();
  1002.     break;
  1003.  
  1004.     case KEY_F5:
  1005.     if (!shiftpressed)
  1006.       editmode = EDIT_PATTERN;
  1007.     else prevmultiplier();
  1008.     break;
  1009.  
  1010.     case KEY_F6:
  1011.     if (!shiftpressed)
  1012.       editmode = EDIT_ORDERLIST;
  1013.     else nextmultiplier();
  1014.     break;
  1015.  
  1016.     case KEY_F7:
  1017.     if (!shiftpressed)
  1018.     {
  1019.       if (editmode == EDIT_INSTRUMENT)
  1020.         editmode = EDIT_TABLES;
  1021.       else
  1022.         editmode = EDIT_INSTRUMENT;
  1023.     }
  1024.     else editadsr();
  1025.     break;
  1026.  
  1027.     case KEY_F8:
  1028.     if (!shiftpressed)
  1029.       editmode = EDIT_NAMES;
  1030.     else
  1031.     {
  1032.       sidmodel ^= 1;
  1033.       sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate);
  1034.     }
  1035.     break;
  1036.  
  1037.     case KEY_F9:
  1038.     relocator();
  1039.     break;
  1040.  
  1041.     case KEY_F10:
  1042.     load();
  1043.     break;
  1044.  
  1045.     case KEY_F11:
  1046.     save();
  1047.     break;
  1048.   }
  1049. }
  1050.  
  1051. void load(void)
  1052. {
  1053.   if ((editmode != EDIT_INSTRUMENT) && (editmode != EDIT_TABLES))
  1054.   {
  1055.     if (fileselector(songfilename, songpath, songfilter, "LOAD SONG", 0))
  1056.       loadsong();
  1057.   }
  1058.   else
  1059.   {
  1060.     if (einum)
  1061.     {
  1062.       if (fileselector(instrfilename, instrpath, instrfilter, "LOAD INSTRUMENT", 0))
  1063.         loadinstrument();
  1064.     }
  1065.   }
  1066.   key = 0;
  1067.   rawkey = 0;
  1068. }
  1069.  
  1070. void save(void)
  1071. {
  1072.   if ((editmode != EDIT_INSTRUMENT) && (editmode != EDIT_TABLES))
  1073.   {
  1074.     int done = 0;
  1075.  
  1076.     // Repeat until quit or save successful
  1077.     while (!done)
  1078.     {
  1079.       if (strlen(loadedsongfilename)) strcpy(songfilename, loadedsongfilename);
  1080.       if (fileselector(songfilename, songpath, songfilter, "SAVE SONG", 3))
  1081.         done = savesong();
  1082.       else done = 1;
  1083.     }
  1084.   }
  1085.   else
  1086.   {
  1087.     if (einum)
  1088.     {
  1089.       int done = 0;
  1090.       int useinstrname = 0;
  1091.       char tempfilename[MAX_FILENAME];
  1092.  
  1093.       // Repeat until quit or save successful
  1094.       while (!done)
  1095.       {
  1096.         if ((!strlen(instrfilename)) && (strlen(instr[einum].name)))
  1097.         {
  1098.           useinstrname = 1;
  1099.           strcpy(instrfilename, instr[einum].name);
  1100.           strcat(instrfilename, ".ins");
  1101.           strcpy(tempfilename, instrfilename);
  1102.         }
  1103.  
  1104.         if (fileselector(instrfilename, instrpath, instrfilter, "SAVE INSTRUMENT", 3))
  1105.           done = saveinstrument();
  1106.         else done = 1;
  1107.  
  1108.         if (useinstrname)
  1109.         {
  1110.           if (!strcmp(tempfilename, instrfilename))
  1111.             memset(instrfilename, 0, sizeof instrfilename);
  1112.         }
  1113.       }
  1114.     }
  1115.   }
  1116.   key = 0;
  1117.   rawkey = 0;
  1118. }
  1119.  
  1120. void quit(void)
  1121. {
  1122.   if ((!shiftpressed) || (mouseb))
  1123.   {
  1124.     printtextcp(38, 36, 15, "Really Quit (y/n)?");
  1125.     waitkey();
  1126.     printblank(20, 36, 39);
  1127.     if ((key == 'y') || (key == 'Y')) exitprogram = 1;
  1128.   }
  1129.   key = 0;
  1130.   rawkey = 0;
  1131. }
  1132.  
  1133. void clear(void)
  1134. {
  1135.   int cs = 0;
  1136.   int cp = 0;
  1137.   int ci = 0;
  1138.   int ct = 0;
  1139.   int cn = 0;
  1140.  
  1141.   printtextcp(38, 36, 15, "Optimize everything (y/n)?");
  1142.   waitkey();
  1143.   printblank(20, 36, 39);
  1144.   if ((key == 'y') || (key == 'Y'))
  1145.   {
  1146.     optimizeeverything(1, 1);
  1147.     key = 0;
  1148.     rawkey = 0;
  1149.     return;
  1150.   }
  1151.  
  1152.   printtextcp(38, 36, 15, "Clear orderlists (y/n)?");
  1153.   waitkey();
  1154.   printblank(20, 36, 39);
  1155.   if ((key == 'y') || (key == 'Y')) cs = 1;
  1156.  
  1157.   printtextcp(38, 36, 15, "Clear patterns (y/n)?");
  1158.   waitkey();
  1159.   printblank(20, 36, 39);
  1160.   if ((key == 'y') || (key == 'Y')) cp = 1;
  1161.  
  1162.   printtextcp(38, 36, 15, "Clear instruments (y/n)?");
  1163.   waitkey();
  1164.   printblank(20, 36, 39);
  1165.   if ((key == 'y') || (key == 'Y')) ci = 1;
  1166.  
  1167.   printtextcp(38, 36, 15, "Clear tables (y/n)?");
  1168.   waitkey();
  1169.   printblank(20, 36, 39);
  1170.   if ((key == 'y') || (key == 'Y')) ct = 1;
  1171.  
  1172.   printtextcp(38, 36, 15, "Clear songname (y/n)?");
  1173.   waitkey();
  1174.   printblank(20, 36, 39);
  1175.   if ((key == 'y') || (key == 'Y')) cn = 1;
  1176.  
  1177.   if (cp == 1)
  1178.   {
  1179.     int selectdone = 0;
  1180.     int olddpl = defaultpatternlength;
  1181.  
  1182.     printtext(29, 36, 15,"Pattern length:");
  1183.     while (!selectdone)
  1184.     {
  1185.       sprintf(textbuffer, "%02d ", defaultpatternlength);
  1186.       printtext(44, 36, 15, textbuffer);
  1187.       waitkey();
  1188.       switch(rawkey)
  1189.       {
  1190.         case KEY_LEFT:
  1191.         defaultpatternlength -= 7;
  1192.         case KEY_DOWN:
  1193.         defaultpatternlength--;
  1194.         if (defaultpatternlength < 1) defaultpatternlength = 1;
  1195.         break;
  1196.  
  1197.         case KEY_RIGHT:
  1198.         defaultpatternlength += 7;
  1199.         case KEY_UP:
  1200.         defaultpatternlength++;
  1201.         if (defaultpatternlength > MAX_PATTROWS) defaultpatternlength = MAX_PATTROWS;
  1202.         break;
  1203.  
  1204.         case KEY_ESC:
  1205.         defaultpatternlength = olddpl;
  1206.         selectdone = 1;
  1207.         break;
  1208.  
  1209.         case KEY_ENTER:
  1210.         selectdone = 1;
  1211.         break;
  1212.       }
  1213.     }
  1214.     printblank(20, 36, 39);
  1215.   }
  1216.  
  1217.   if (cs | cp | ci | ct | cn)
  1218.     memset(songfilename, 0, sizeof songfilename);
  1219.   clearsong(cs, cp, ci, ct, cn);
  1220.  
  1221.   key = 0;
  1222.   rawkey = 0;
  1223. }
  1224.  
  1225.  
  1226. void editadsr(void)
  1227. {
  1228.   eamode = 1;
  1229.   eacolumn = 0;
  1230.  
  1231.   for (;;)
  1232.   {
  1233.     waitkeymouse();
  1234.  
  1235.     if (win_quitted)
  1236.     {
  1237.       exitprogram = 1;
  1238.       key = 0;
  1239.       rawkey = 0;
  1240.       return;
  1241.     }
  1242.  
  1243.     if (hexnybble >= 0)
  1244.     {
  1245.       switch(eacolumn)
  1246.       {
  1247.         case 0:
  1248.         adparam &= 0x0fff;
  1249.         adparam |= hexnybble << 12;
  1250.         break;
  1251.  
  1252.         case 1:
  1253.         adparam &= 0xf0ff;
  1254.         adparam |= hexnybble << 8;
  1255.         break;
  1256.  
  1257.         case 2:
  1258.         adparam &= 0xff0f;
  1259.         adparam |= hexnybble << 4;
  1260.         break;
  1261.  
  1262.         case 3:
  1263.         adparam &= 0xfff0;
  1264.         adparam |= hexnybble;
  1265.         break;
  1266.       }
  1267.       eacolumn++;
  1268.     }
  1269.  
  1270.     switch(rawkey)
  1271.     {
  1272.       case KEY_F7:
  1273.       if (!shiftpressed) break;
  1274.  
  1275.       case KEY_ESC:
  1276.       case KEY_ENTER:
  1277.       case KEY_TAB:
  1278.       eamode = 0;
  1279.       key = 0;
  1280.       rawkey = 0;
  1281.       return;
  1282.  
  1283.       case KEY_BACKSPACE:
  1284.       if (!eacolumn) break;
  1285.       case KEY_LEFT:
  1286.       eacolumn--;
  1287.       break;
  1288.  
  1289.       case KEY_RIGHT:
  1290.       eacolumn++;
  1291.     }
  1292.     eacolumn &= 3;
  1293.  
  1294.     if ((mouseb) && (!prevmouseb))
  1295.     {
  1296.       eamode = 0;
  1297.       return;
  1298.     }
  1299.   }
  1300. }
  1301.  
  1302. void getparam(FILE *handle, unsigned *value)
  1303. {
  1304.   char *configptr;
  1305.  
  1306.   for (;;)
  1307.   {
  1308.     if (feof(handle)) return;
  1309.     fgets(configbuf, MAX_PATHNAME, handle);
  1310.     if ((configbuf[0]) && (configbuf[0] != ';') && (configbuf[0] != ' ') && (configbuf[0] != 13) && (configbuf[0] != 10)) break;
  1311.   }
  1312.  
  1313.   configptr = configbuf;
  1314.   if (*configptr == '$')
  1315.   {
  1316.     *value = 0;
  1317.     configptr++;
  1318.     for (;;)
  1319.     {
  1320.       char c = tolower(*configptr++);
  1321.       int h = -1;
  1322.  
  1323.       if ((c >= 'a') && (c <= 'f')) h = c - 'a' + 10;
  1324.       if ((c >= '0') && (c <= '9')) h = c - '0';
  1325.  
  1326.       if (h >= 0)
  1327.       {
  1328.         *value *= 16;
  1329.         *value += h;
  1330.       }
  1331.       else break;
  1332.     }
  1333.   }
  1334.   else
  1335.   {
  1336.     *value = 0;
  1337.     for (;;)
  1338.     {
  1339.       char c = tolower(*configptr++);
  1340.       int d = -1;
  1341.  
  1342.       if ((c >= '0') && (c <= '9')) d = c - '0';
  1343.  
  1344.       if (d >= 0)
  1345.       {
  1346.         *value *= 10;
  1347.         *value += d;
  1348.       }
  1349.       else break;
  1350.     }
  1351.   }
  1352. }
  1353.  
  1354. void getfloatparam(FILE *handle, float *value)
  1355. {
  1356.   char *configptr;
  1357.  
  1358.   for (;;)
  1359.   {
  1360.     if (feof(handle)) return;
  1361.     fgets(configbuf, MAX_PATHNAME, handle);
  1362.     if ((configbuf[0]) && (configbuf[0] != ';') && (configbuf[0] != ' ') && (configbuf[0] != 13) && (configbuf[0] != 10)) break;
  1363.   }
  1364.  
  1365.   configptr = configbuf;
  1366.   *value = 0.0f;
  1367.   sscanf(configptr, "%f", value);
  1368. }
  1369.  
  1370. void prevmultiplier(void)
  1371. {
  1372.   if (multiplier > 0)
  1373.   {
  1374.     multiplier--;
  1375.     sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate);
  1376.   }
  1377. }
  1378.  
  1379. void nextmultiplier(void)
  1380. {
  1381.   if (multiplier < 16)
  1382.   {
  1383.     multiplier++;
  1384.     sound_init(b, mr, writer, hardsid, sidmodel, ntsc, multiplier, catweasel, interpolate, customclockrate);
  1385.   }
  1386. }
  1387.  
  1388. void calculatefreqtable()
  1389. {
  1390.   double basefreq = (double)basepitch * (16777216.0 / 985248.0) * pow(2.0, 0.25) / 32.0;
  1391.   int c;
  1392.  
  1393.   for (c = 0; c < 8*12 ; c++)
  1394.   {
  1395.     double note = c;
  1396.     double freq = basefreq * pow(2.0, note/12.0);
  1397.     int intfreq = freq + 0.5;
  1398.     if (intfreq > 0xffff)
  1399.         intfreq = 0xffff;
  1400.     freqtbllo[c] = intfreq & 0xff;
  1401.     freqtblhi[c] = intfreq >> 8;
  1402.   }
  1403. }
  1404.