home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / goattracker_2.70.zip / src / gdisplay.c < prev    next >
C/C++ Source or Header  |  2008-04-01  |  15KB  |  539 lines

  1. //
  2. // GOATTRACKER v2 screen display routines
  3. //
  4.  
  5. #define GDISPLAY_C
  6.  
  7. #include "goattrk2.h"
  8.  
  9. char *notename[] =
  10.  {"C-0", "C#0", "D-0", "D#0", "E-0", "F-0", "F#0", "G-0", "G#0", "A-0", "A#0", "B-0",
  11.   "C-1", "C#1", "D-1", "D#1", "E-1", "F-1", "F#1", "G-1", "G#1", "A-1", "A#1", "B-1",
  12.   "C-2", "C#2", "D-2", "D#2", "E-2", "F-2", "F#2", "G-2", "G#2", "A-2", "A#2", "B-2",
  13.   "C-3", "C#3", "D-3", "D#3", "E-3", "F-3", "F#3", "G-3", "G#3", "A-3", "A#3", "B-3",
  14.   "C-4", "C#4", "D-4", "D#4", "E-4", "F-4", "F#4", "G-4", "G#4", "A-4", "A#4", "B-4",
  15.   "C-5", "C#5", "D-5", "D#5", "E-5", "F-5", "F#5", "G-5", "G#5", "A-5", "A#5", "B-5",
  16.   "C-6", "C#6", "D-6", "D#6", "E-6", "F-6", "F#6", "G-6", "G#6", "A-6", "A#6", "B-6",
  17.   "C-7", "C#7", "D-7", "D#7", "E-7", "F-7", "F#7", "G-7", "G#7", "...", "---", "+++"};
  18.   
  19. char timechar[] = {':', ' '};
  20.  
  21. int timemin = 0;
  22. int timesec = 0;
  23. int timeframe = 0;
  24.  
  25. void printmainscreen(void)
  26. {
  27.   clearscreen();
  28.   printstatus();
  29.   fliptoscreen();
  30. }
  31.  
  32. void displayupdate(void)
  33. {
  34.   if (cursorflashdelay >= 6)
  35.   {
  36.     cursorflashdelay %= 6;
  37.     cursorflash++;
  38.     cursorflash &= 3;
  39.   }
  40.   printstatus();
  41.   fliptoscreen();
  42. }
  43.  
  44. void printstatus(void)
  45. {
  46.   int c, d, color;
  47.   int cc = cursorcolortable[cursorflash];
  48.   menu = 0;
  49.  
  50.   if ((mouseb > MOUSEB_LEFT) && (mousey <= 1) && (!eamode)) menu = 1;
  51.  
  52.   printblankc(0, 0, 15+16, MAX_COLUMNS);
  53.  
  54.   if (!menu)
  55.   {
  56.     if (!strlen(loadedsongfilename))
  57.       sprintf(textbuffer, "%s", programname);
  58.     else
  59.       sprintf(textbuffer, "%s - %s", programname, loadedsongfilename);
  60.     textbuffer[49] = 0;
  61.     printtext(0, 0, 15+16, textbuffer);
  62.  
  63.     if (usefinevib)
  64.       printtext(40+10, 0, 15+16, "FV");
  65.  
  66.     if (optimizepulse)
  67.       printtext(43+10, 0, 15+16, "PO");
  68.  
  69.     if (optimizerealtime)
  70.       printtext(46+10, 0, 15+16, "RO");
  71.  
  72.     if (ntsc)
  73.       printtext(49+10, 0, 15+16, "NTSC");
  74.     else
  75.       printtext(49+10, 0, 15+16, " PAL");
  76.  
  77.     if (!sidmodel)
  78.       printtext(54+10, 0, 15+16, "6581");
  79.     else
  80.       printtext(54+10, 0, 15+16, "8580");
  81.  
  82.     sprintf(textbuffer, "HR:%04X", adparam);
  83.     printtext(59+10, 0, 15+16, textbuffer);
  84.     if (eamode) printbg(62+10+eacolumn, 0, cc, 1);
  85.  
  86.     if (multiplier)
  87.     {
  88.       sprintf(textbuffer, "%2dX", multiplier);
  89.       printtext(67+10, 0, 15+16, textbuffer);
  90.     }
  91.     else printtext(67+10, 0, 15+16, "25Hz");
  92.  
  93.     printtext(72+20, 0, 15+16, "F12=HELP");
  94.   }
  95.   else
  96.   {
  97.     printtext(0, 0, 15+16, " PLAY | PLAYPOS | PLAYPATT | STOP | LOAD | SAVE | PACK/RL | HELP | CLEAR | QUIT |");
  98.   }
  99.  
  100.   if ((followplay) && (isplaying()))
  101.   {
  102.     for (c = 0; c < MAX_CHN; c++)
  103.     {
  104.       int newpos = chn[c].pattptr / 4;
  105.       if (chn[c].advance) epnum[c] = chn[c].pattnum;
  106.  
  107.       if (newpos > pattlen[epnum[c]]) newpos = pattlen[epnum[c]];
  108.  
  109.       if (c == epchn)
  110.       {
  111.         eppos = newpos;
  112.         epview = newpos-VISIBLEPATTROWS/2;
  113.       }
  114.  
  115.       newpos = chn[c].songptr;
  116.       newpos--;
  117.       if (newpos < 0) newpos = 0;
  118.       if (newpos > songlen[esnum][c]) newpos = songlen[esnum][c];
  119.  
  120.       if ((c == eschn) && (chn[c].advance))
  121.       {
  122.         eseditpos = newpos;
  123.         if (newpos - esview < 0)
  124.         {
  125.           esview = newpos;
  126.         }
  127.         if (newpos - esview >= VISIBLEORDERLIST)
  128.         {
  129.           esview = newpos - VISIBLEORDERLIST + 1;
  130.         }
  131.       }
  132.     }
  133.   }
  134.  
  135.   for (c = 0; c < MAX_CHN; c++)
  136.   {
  137.     sprintf(textbuffer, "CHN %d PATT.%02X", c+1, epnum[c]);
  138.     printtext(2+c*15, 2, CTITLE, textbuffer);
  139.  
  140.     for (d = 0; d < VISIBLEPATTROWS; d++)
  141.     {
  142.       int p = epview+d;
  143.       color = CNORMAL;
  144.       if ((epnum[c] == chn[c].pattnum) && (isplaying()))
  145.       {
  146.         int chnrow = chn[c].pattptr / 4;
  147.         if (chnrow > pattlen[chn[c].pattnum]) chnrow = pattlen[chn[c].pattnum];
  148.         if (chnrow == p) color = CPLAYING;
  149.       }
  150.  
  151.       if (chn[c].mute) color = CMUTE;
  152.       if (p == eppos) color = CEDIT;
  153.       if ((p < 0) || (p > pattlen[epnum[c]]))
  154.       {
  155.         sprintf(textbuffer, "             ");
  156.       }
  157.       else
  158.       {
  159.         if (!patternhex)
  160.         {
  161.           if (p < 100)
  162.             sprintf(textbuffer, " %02d", p);
  163.           else
  164.             sprintf(textbuffer, "%03d", p);
  165.         }
  166.         else
  167.           sprintf(textbuffer, " %02X", p);
  168.  
  169.         if (pattern[epnum[c]][p*4] == ENDPATT)
  170.         {
  171.           sprintf(&textbuffer[3], " PATT. END");
  172.           if (color == CNORMAL) color = CCOMMAND;
  173.         }
  174.         else
  175.         {
  176.           sprintf(&textbuffer[3], " %s %02X%01X%02X",
  177.             notename[pattern[epnum[c]][p*4]-FIRSTNOTE],
  178.             pattern[epnum[c]][p*4+1],
  179.             pattern[epnum[c]][p*4+2],
  180.             pattern[epnum[c]][p*4+3]);
  181.         }
  182.       }
  183.       textbuffer[3] = 0;
  184.       if (p%stepsize)
  185.       {
  186.         printtext(2+c*15, 3+d, CNORMAL, textbuffer);
  187.       }
  188.       else
  189.       {
  190.         printtext(2+c*15, 3+d, CCOMMAND, textbuffer);
  191.       }
  192.       printtext(6+c*15, 3+d, color, &textbuffer[4]);
  193.       if (c == epmarkchn)
  194.       {
  195.         if (epmarkstart <= epmarkend)
  196.         {
  197.           if ((p >= epmarkstart) && (p <= epmarkend))
  198.             printbg(2+c*15+4, 3+d, 1, 9);
  199.         }
  200.         else
  201.         {
  202.           if ((p <= epmarkstart) && (p >= epmarkend))
  203.             printbg(2+c*15+4, 3+d, 1, 9);
  204.         }
  205.       }
  206.       if ((color == CEDIT) && (editmode == EDIT_PATTERN) && (epchn == c))
  207.       {
  208.         switch(epcolumn)
  209.         {
  210.           case 0:
  211.           if (!eamode) printbg(2+c*15+4, 3+d, cc, 3);
  212.           break;
  213.  
  214.           default:
  215.           if (!eamode) printbg(2+c*15+7+epcolumn, 3+d, cc, 1);
  216.           break;
  217.         }
  218.       }
  219.     }
  220.   }
  221.  
  222.   sprintf(textbuffer, "CHN ORDERLIST (SUBTUNE %02X, POS %02X)", esnum, eseditpos);
  223.   printtext(40+10, 2, CTITLE, textbuffer);
  224.   for (c = 0; c < MAX_CHN; c++)
  225.   {
  226.     sprintf(textbuffer, " %d ", c+1);
  227.     printtext(40+10, 3+c, 15, textbuffer);
  228.     for (d = 0; d < VISIBLEORDERLIST; d++)
  229.     {
  230.       int p = esview+d;
  231.       color = CNORMAL;
  232.       if (isplaying())
  233.       {
  234.         int chnpos = chn[c].songptr;
  235.         chnpos--;
  236.         if (chnpos < 0) chnpos = 0;
  237.         if ((p == chnpos) && (chn[c].advance)) color = CPLAYING;
  238.       }
  239.       if (p == espos[c]) color = CEDIT;
  240.       if ((esend[c]) && (p == esend[c])) color = CEDIT;
  241.  
  242.       if ((p < 0) || (p > (songlen[esnum][c]+1)) || (p > MAX_SONGLEN+1))
  243.       {
  244.         sprintf(textbuffer, "   ");
  245.       }
  246.       else
  247.       {
  248.         if (songorder[esnum][c][p] < LOOPSONG)
  249.         {
  250.           if ((songorder[esnum][c][p] < REPEAT) || (p >= songlen[esnum][c]))
  251.           {
  252.             sprintf(textbuffer, "%02X ", songorder[esnum][c][p]);
  253.             if ((p >= songlen[esnum][c]) && (color == CNORMAL)) color = CCOMMAND;
  254.           }
  255.           else
  256.           {
  257.             if (songorder[esnum][c][p] >= TRANSUP)
  258.             {
  259.               sprintf(textbuffer, "+%01X ", songorder[esnum][c][p]&0xf);
  260.               if (color == CNORMAL) color = CCOMMAND;
  261.             }
  262.             else
  263.             {
  264.               if (songorder[esnum][c][p] >= TRANSDOWN)
  265.               {
  266.                 sprintf(textbuffer, "-%01X ", 16-(songorder[esnum][c][p] & 0x0f));
  267.                 if (color == CNORMAL) color = CCOMMAND;
  268.               }
  269.               else
  270.               {
  271.                 sprintf(textbuffer, "R%01X ", (songorder[esnum][c][p]+1) & 0x0f);
  272.                 if (color == CNORMAL) color = CCOMMAND;
  273.               }
  274.             }
  275.           }
  276.         }
  277.         if (songorder[esnum][c][p] == LOOPSONG)
  278.         {
  279.           sprintf(textbuffer, "RST");
  280.           if (color == CNORMAL) color = CCOMMAND;
  281.         }
  282.       }
  283.       printtext(44+10+d*3, 3+c, color, textbuffer);
  284.       if (c == esmarkchn)
  285.       {
  286.         if (esmarkstart <= esmarkend)
  287.         {
  288.           if ((p >= esmarkstart) && (p <= esmarkend))
  289.           {
  290.             if (p != esmarkend)
  291.               printbg(44+10+d*3, 3+c, 1, 3);
  292.             else
  293.               printbg(44+10+d*3, 3+c, 1, 2);
  294.           }
  295.         }
  296.         else
  297.         {
  298.           if ((p <= esmarkstart) && (p >= esmarkend))
  299.           {
  300.             if (p != esmarkstart)
  301.               printbg(44+10+d*3, 3+c, 1, 3);
  302.             else
  303.               printbg(44+10+d*3, 3+c, 1, 2);
  304.           }
  305.         }
  306.       }
  307.       if ((p == eseditpos) && (editmode == EDIT_ORDERLIST) && (eschn == c))
  308.       {
  309.         if (!eamode) printbg(44+10+d*3+escolumn, 3+c, cc, 1);
  310.       }
  311.     }
  312.   }
  313.  
  314.   sprintf(textbuffer, "INSTRUMENT NUM. %02X  %-16s", einum, instr[einum].name);
  315.   printtext(40+10, 7, CTITLE, textbuffer);
  316.  
  317.   sprintf(textbuffer, "Attack/Decay    %02X", instr[einum].ad);
  318.   if (eipos == 0) color = CEDIT; else color = CNORMAL;
  319.   printtext(40+10, 8, color, textbuffer);
  320.  
  321.   sprintf(textbuffer, "Sustain/Release %02X", instr[einum].sr);
  322.   if (eipos == 1) color = CEDIT; else color = CNORMAL;
  323.   printtext(40+10, 9, color, textbuffer);
  324.  
  325.   sprintf(textbuffer, "Wavetable Pos   %02X", instr[einum].ptr[WTBL]);
  326.   if (eipos == 2) color = CEDIT; else color = CNORMAL;
  327.   printtext(40+10, 10, color, textbuffer);
  328.  
  329.   sprintf(textbuffer, "Pulsetable Pos  %02X", instr[einum].ptr[PTBL]);
  330.   if (eipos == 3) color = CEDIT; else color = CNORMAL;
  331.   printtext(40+10, 11, color, textbuffer);
  332.  
  333.   sprintf(textbuffer, "Filtertable Pos %02X", instr[einum].ptr[FTBL]);
  334.   if (eipos == 4) color = CEDIT; else color = CNORMAL;
  335.   printtext(40+10, 12, color, textbuffer);
  336.  
  337.   sprintf(textbuffer, "Vibrato Param   %02X", instr[einum].ptr[STBL]);
  338.   if (eipos == 5) color = CEDIT; else color = CNORMAL;
  339.   printtext(60+10, 8, color, textbuffer);
  340.  
  341.   sprintf(textbuffer, "Vibrato Delay   %02X", instr[einum].vibdelay);
  342.   if (eipos == 6) color = CEDIT; else color = CNORMAL;
  343.   printtext(60+10, 9, color, textbuffer);
  344.  
  345.   sprintf(textbuffer, "HR/Gate Timer   %02X", instr[einum].gatetimer);
  346.   if (eipos == 7) color = CEDIT; else color = CNORMAL;
  347.   printtext(60+10, 10, color, textbuffer);
  348.  
  349.   sprintf(textbuffer, "1stFrame Wave   %02X", instr[einum].firstwave);
  350.   if (eipos == 8) color = CEDIT; else color = CNORMAL;
  351.   printtext(60+10, 11, color, textbuffer);
  352.  
  353.   if (editmode == EDIT_INSTRUMENT)
  354.   {
  355.     if (eipos < 9)
  356.     {
  357.       if (!eamode) printbg(56+10+eicolumn+20*(eipos/5), 8+(eipos%5), cc, 1);
  358.     }
  359.     else
  360.     {
  361.       if (!eamode) printbg(60+10+strlen(instr[einum].name), 7, cc, 1);
  362.     }
  363.   }
  364.  
  365.   sprintf(textbuffer, "WAVE TBL  PULSETBL  FILT.TBL  SPEEDTBL");
  366.   printtext(40+10, 14, CTITLE, textbuffer);
  367.  
  368.   for (c = 0; c < MAX_TABLES; c++)
  369.   {
  370.     for (d = 0; d < VISIBLETABLEROWS; d++)
  371.     {
  372.       int p = etview[c]+d;
  373.  
  374.       color = CNORMAL;
  375.       switch (c)
  376.       {
  377.         case WTBL:
  378.         if (ltable[c][p] >= WAVECMD) color = CCOMMAND;
  379.         break;
  380.  
  381.         case PTBL:
  382.         if (ltable[c][p] >= 0x80) color = CCOMMAND;
  383.         break;
  384.  
  385.         case FTBL:
  386.         if ((ltable[c][p] >= 0x80) || ((!ltable[c][p]) && (rtable[c][p]))) color = CCOMMAND;
  387.         break;
  388.       }
  389.       if ((p == etpos) && (etnum == c)) color = CEDIT;
  390.       sprintf(textbuffer, "%02X:%02X %02X", p+1, ltable[c][p], rtable[c][p]);
  391.       printtext(40+10+10*c, 15+d, color, textbuffer);
  392.  
  393.       if (etmarknum == c)
  394.       {
  395.         if (etmarkstart <= etmarkend)
  396.         {
  397.           if ((p >= etmarkstart) && (p <= etmarkend))
  398.             printbg(40+10+10*c+3, 15+d, 1, 5);
  399.         }
  400.         else
  401.         {
  402.           if ((p <= etmarkstart) && (p >= etmarkend))
  403.             printbg(40+10+10*c+3, 15+d, 1, 5);
  404.         }
  405.       }
  406.     }
  407.   }
  408.  
  409.   if (editmode == EDIT_TABLES)
  410.   {
  411.     if (!eamode) printbg(43+10+etnum*10+(etcolumn & 1)+(etcolumn/2)*3, 15+etpos-etview[etnum], cc, 1);
  412.   }
  413.  
  414.   printtext(40+10, 31, CTITLE, "NAME   ");
  415.   sprintf(textbuffer, "%-32s", songname);
  416.   printtext(47+10, 31, CEDIT, textbuffer);
  417.  
  418.   printtext(40+10, 32, CTITLE, "AUTHOR ");
  419.   sprintf(textbuffer, "%-32s", authorname);
  420.   printtext(47+10, 32, CEDIT, textbuffer);
  421.  
  422.   printtext(40+10, 33, CTITLE, "COPYR. ");
  423.   sprintf(textbuffer, "%-32s", copyrightname);
  424.   printtext(47+10, 33, CEDIT, textbuffer);
  425.  
  426.   if ((editmode == EDIT_NAMES) && (!eamode))
  427.   {
  428.     switch(enpos)
  429.     {
  430.       case 0:
  431.       printbg(47+10+strlen(songname), 31, cc, 1);
  432.       break;
  433.       case 1:
  434.       printbg(47+10+strlen(authorname), 32, cc, 1);
  435.       break;
  436.       case 2:
  437.       printbg(47+10+strlen(copyrightname), 33, cc, 1);
  438.       break;
  439.     }
  440.   }
  441.   sprintf(textbuffer, "OCTAVE %d", epoctave);
  442.   printtext(0, 35, CTITLE, textbuffer);
  443.  
  444.   switch(autoadvance)
  445.   {
  446.     case 0:
  447.     color = 10;
  448.     break;
  449.  
  450.     case 1:
  451.     color = 14;
  452.     break;
  453.  
  454.     case 2:
  455.     color = 12;
  456.     break;
  457.   }
  458.  
  459.   if (recordmode) printtext(0, 36, color, "EDITMODE");
  460.   else printtext(0, 36, color, "JAM MODE");
  461.  
  462.   if (isplaying()) printtext(10, 35, CTITLE, "PLAYING");
  463.   else printtext(10, 35, CTITLE, "STOPPED");
  464.   if (multiplier)
  465.   {
  466.     if (!ntsc)
  467.       sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[timeframe/(25*multiplier) & 1], timesec);
  468.     else
  469.       sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[timeframe/(30*multiplier) & 1], timesec);
  470.   }
  471.   else
  472.   {
  473.     if (!ntsc)
  474.       sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[(timeframe/13) & 1], timesec);
  475.     else
  476.       sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[(timeframe/15) & 1], timesec);
  477.   }
  478.  
  479.   printtext(10, 36, CEDIT, textbuffer);
  480.  
  481.   printtext(80, 35, CTITLE, " CHN1   CHN2   CHN3 ");
  482.   for (c = 0; c < MAX_CHN; c++)
  483.   {
  484.     int chnpos = chn[c].songptr;
  485.     int chnrow = chn[c].pattptr/4;
  486.     chnpos--;
  487.     if (chnpos < 0) chnpos = 0;
  488.     if (chnrow > pattlen[chn[c].pattnum]) chnrow = pattlen[chn[c].pattnum];
  489.     if (chnrow >= 100) chnrow -= 100;
  490.  
  491.     sprintf(textbuffer, "%03d/%02d",
  492.       chnpos,chnrow);
  493.     printtext(80+7*c, 36, CEDIT, textbuffer);
  494.   }
  495.  
  496.   if (etlock) printtext(78, 36, CTITLE, " ");
  497.     else printtext(78, 36, CTITLE, "U");
  498. }
  499.  
  500.  
  501. void resettime(void)
  502. {
  503.   timemin = 0;
  504.   timesec = 0;
  505.   timeframe = 0;
  506. }
  507.  
  508. void incrementtime(void)
  509. {
  510.   {
  511.     timeframe++;
  512.     if (!ntsc)
  513.     {
  514.       if (((multiplier) && (timeframe >= PALFRAMERATE*multiplier))
  515.           || ((!multiplier) && (timeframe >= PALFRAMERATE/2)))
  516.       {
  517.         timeframe = 0;
  518.         timesec++;
  519.       }
  520.     }
  521.     else
  522.     {
  523.       if (((multiplier) && (timeframe >= NTSCFRAMERATE*multiplier))
  524.           || ((!multiplier) && (timeframe >= NTSCFRAMERATE/2)))
  525.       {
  526.         timeframe = 0;
  527.         timesec++;
  528.       }
  529.     }
  530.     if (timesec == 60)
  531.     {
  532.       timesec = 0;
  533.       timemin++;
  534.       timemin %= 60;
  535.     }
  536.   }
  537. }
  538.  
  539.