home *** CD-ROM | disk | FTP | other *** search
/ PC Interdit / pc-interdit.iso / sound / gusmod / tcp.pas < prev    next >
Pascal/Delphi Source File  |  1994-10-21  |  13KB  |  541 lines

  1. {$A+,B-,D+,E+,F+,G+,I+,L+,N-,O-,P-,Q-,R-,S+,T-,V+,X+,Y+}
  2. {$M 16384,0,250000}
  3.  
  4. program gusdemo;
  5.  
  6. uses crt,dos,design,fselect,gus_mod;
  7.  
  8. type
  9.   Pphun = ^TPhun;
  10.   TPhun = array[0..799] of string[80];
  11.  
  12. const mod_chem = '';
  13.  
  14. const Programm_quitter : boolean = false;
  15.  
  16. var phun : Pphun;
  17.     phuncount : integer;
  18.     modify_voice : integer;
  19.     i : integer;
  20.     Les_files : Pfileselect_struct;
  21.     curr_modnr : integer;
  22.  
  23. {
  24.   Intégration des écrans ANSI
  25. }
  26.  
  27. {$L c:\edition\prog\fr\asm\tcpans}
  28. procedure tcpans; external;
  29. {$L c:\edition\prog\fr\asm\we_are}
  30. procedure we_are; external;
  31. {$L c:\edition\prog\fr\asm\buy_it}
  32. procedure buy_it; external;
  33. {$L c:\edition\prog\fr\asm\call}
  34. procedure call; external;
  35. {$L c:\edition\prog\fr\asm\helptxt}
  36. procedure helptxt; external;
  37.  
  38.  
  39. function fichier_exists(dname : string) : boolean;
  40. {
  41.  Vérifie si le fichier transmis existe
  42. }
  43. var dumf : file;
  44. begin;
  45.   {$I-}
  46.   assign(dumf,dname);
  47.   reset(dumf,1);
  48.   {$I+}
  49.   if IOResult <> 0 then
  50.     fichier_exists := false
  51.   else begin;
  52.     fichier_exists := true;
  53.     close(dumf);
  54.   end;
  55. end;
  56.  
  57. procedure color_writeln(s : string);
  58. {
  59.  Pour sortir une chaîne dans la combinaison de couleurs TC
  60. }
  61. var colpos,li : integer;
  62. begin;
  63.   colpos := 1;
  64.   for li := 1 to length(s) do begin;
  65.     if s[li] = ' ' then colpos := 0;
  66.     inc(colpos);
  67.     case colpos of
  68.         1..2 : begin;
  69.                  textcolor(8);
  70.                end;
  71.         3..4 : begin;
  72.                 textcolor(2);
  73.                end;
  74.       5..$ff : begin;
  75.                  textcolor(10);
  76.                end;
  77.     end;
  78.     write(s[li]);
  79.   end;
  80. end;
  81.  
  82. procedure write_nomfichier(s : string);
  83. {
  84.  Affiche le nom de fichier de la chanson, centré
  85. }
  86. var li,slen : integer;
  87. begin;
  88.   gotoxy(33,13);
  89.   while pos('\',s) <> 0 do begin;
  90.     delete(s,1,pos('\',s));
  91.   end;
  92.   slen := length(s);
  93.   slen := (15 - slen) div 2;
  94.   for li := 1 to slen do s := ' '+s;
  95.   write(s);
  96. end;
  97.  
  98. procedure write_phunliners;
  99. {
  100.  Lit trois lignes dans le fichier "Phun.txt" et les affiche
  101.  à l'écran. Le fichier "Phun.txt" est un fichier texte
  102.  que l'on peut éditer librement !
  103. }
  104. var tf : text;
  105. begin;
  106.   randomize;
  107.   if not fichier_exists('phun.txt') then exit;
  108.   assign(tf,'phun.txt');
  109.   reset(tf);
  110.   phuncount := 0;
  111.   {$I+}
  112.   if ioresult = 0 then begin;
  113.     while not eof(tf) do begin;
  114.       readln(tf,phun^[phuncount]);
  115.       inc(phuncount);
  116.     end;
  117.     close(tf);
  118.     gotoxy(3,43);
  119.     color_writeln(phun^[random(phuncount)]);
  120.     gotoxy(3,44);
  121.     color_writeln(phun^[random(phuncount)]);
  122.     gotoxy(3,45);
  123.     color_writeln(phun^[random(phuncount)]);
  124.   end;
  125.   {$I-}
  126. end;
  127.  
  128. procedure display_modinfos;
  129. {
  130.  Affiche le nom des instruments dans le module actuel
  131. }
  132. var li : integer;
  133. begin;
  134.   textcolor(14);
  135.   textbackground(black);
  136.   for li := 1 to 16 do begin;
  137.     gotoxy(6,17+li);
  138.     color_writeln(Instruments[li]^.nom);
  139.     gotoxy(50,17+li);
  140.     color_writeln(Instruments[li+16]^.nom);
  141.   end;
  142. end;
  143.  
  144. procedure exit_program;
  145. {
  146.  Avant de quitter le programme, vite une dernière indication sur le TC WHQ,
  147.  la "Farpoint Station" (04202 76145)...
  148. }
  149. begin;
  150.   display_ansi(@call,co80+font8x8);
  151.   cursor_off;
  152.   repeat until keypressed;
  153.   while keypressed do readkey;
  154.   cursor_on;
  155.   asm mov ax,03; int 10h; end;
  156.   halt;
  157. end;
  158.  
  159. procedure prochain_mod;
  160. {
  161.  Lance la sortie du MOD sélectionné suivant
  162. }
  163. begin;
  164.   _gus_mod_quitter;
  165.   inc(curr_modnr);
  166.   if curr_modnr > Les_Files^.nofiles then
  167.     curr_modnr := 1;
  168.   if not _gus_modload(Les_Files^.fn[curr_modnr]) then begin;
  169.     clrscr;
  170.     gotoxy(10,10);
  171.     write('Sorry dude, Cant''t handle this MOD-File');
  172.     delay(1200);
  173.     exit_program;
  174.   end;
  175.   display_ansi(@tcpans,co80+font8x8);
  176.   cursor_off;
  177.   write_phunliners;
  178.   write_nomfichier(Les_Files^.fn[curr_modnr]);
  179.   display_modinfos;
  180.   fillchar(Play_Chanel,14,1);
  181.   _gus_modstart;
  182. end;
  183.  
  184. procedure display_we_are;
  185. {
  186.  Sortir un ANSI avec Infos par le groupe THE COEXISTENCE
  187. }
  188. begin;
  189.   display_ansi(@we_are,co80+font8x8);
  190.   cursor_off;
  191.   repeat until keypressed;
  192.   while keypressed do readkey;
  193.   display_ansi(@tcpans,co80+font8x8);
  194.   cursor_off;
  195.   write_phunliners;
  196.   write_nomfichier(Les_Files^.fn[curr_modnr]);
  197.   display_modinfos;
  198. end;
  199.  
  200. procedure display_buy_it;
  201. {
  202.  Affiche une réclame pour le livre PC Underground 
  203. }
  204. begin;
  205.   display_ansi(@buy_it,co80+font8x8);
  206.   cursor_off;
  207.   repeat until keypressed;
  208.   while keypressed do readkey;
  209.   display_ansi(@tcpans,co80+font8x8);
  210.   cursor_off;
  211.   write_phunliners;
  212.   write_nomfichier(Les_Files^.fn[curr_modnr]);
  213.   display_modinfos;
  214. end;
  215.  
  216. procedure handle_keys(key1,key2 : char);
  217. {
  218.  Réagit aux saisies de l'utilisateur
  219. }
  220. var pchan : byte;
  221. begin;
  222.   case key1 of
  223.     #00 : begin;
  224.             case key2 of
  225.               #45 : begin;
  226.                       Programm_quitter := true;
  227.                     end;
  228.               #72 : begin;
  229.                       if modify_voice > 1 then
  230.                         dec(modify_voice);
  231.                     end;
  232.               #80 : begin;
  233.                       if modify_voice < Modinf.Voix then
  234.                         inc(modify_voice);
  235.                     end;
  236.               #75 : begin; { cursor left  }
  237.                       runinf.Ligne := 64;
  238.                       dec(runinf.Pattnr,2);
  239.                       if runinf.Pattnr < -1 then runinf.Pattnr := -1;
  240.                     end;
  241.               #77 : begin; { cursor right  }
  242.                       runinf.Ligne := 64;
  243.                       inc(runinf.Pattnr);
  244.                     end;
  245.             end;
  246.           end;
  247.     #27 : begin;
  248.             Programm_quitter := true;
  249.           end;
  250.     #32,
  251.     'W',
  252.     'w',
  253.     'I',
  254.     'i' : begin;
  255.             display_we_are;
  256.           end;
  257.     'D',
  258.     'd',
  259.     'b',
  260.     'B' : begin;
  261.             display_buy_it;
  262.           end;
  263.     'L',
  264.     'l' : begin;
  265.             chpos[modify_voice] := 1;
  266.             _gus_set_chanelpos;
  267.           end;
  268.     'R',
  269.     'r' : begin;
  270.             chpos[modify_voice] := 15;
  271.             _gus_set_chanelpos;
  272.           end;
  273.     'M',
  274.     'm' : begin;
  275.             chpos[modify_voice] := 7;
  276.             _gus_set_chanelpos;
  277.           end;
  278.     'U',
  279.     'u' : begin;
  280.             if Modinf.Voix = 4 then
  281.             begin
  282.               chpos[1] := 2;
  283.               chpos[2] := 5;
  284.               chpos[3] := 9;
  285.               chpos[4] := 12;
  286.             end;
  287.             if Modinf.Voix = 8 then
  288.             begin
  289.               chpos[1] := 1;
  290.               chpos[2] := 3;
  291.               chpos[3] := 5;
  292.               chpos[4] := 7;
  293.               chpos[5] := 7;
  294.               chpos[6] := 9;
  295.               chpos[7] := 11;
  296.               chpos[8] := 13;
  297.             end;
  298.             _gus_set_chanelpos;
  299.           end;
  300.     ',' : begin; { vers la gauche }
  301.             if chpos[modify_voice] > 1 then
  302.               dec(chpos[modify_voice]);
  303.             _gus_set_chanelpos;
  304.           end;
  305.     '.' : begin; { vers la droite !!! }
  306.             if chpos[modify_voice] < 15 then
  307.               inc(chpos[modify_voice]);
  308.             _gus_set_chanelpos;
  309.           end;
  310.     '1'..
  311.     '8' : begin;
  312.             pchan := ord(key1)-48;
  313.             if Play_Chanel[pchan] = 1 then begin;
  314.               Play_Chanel[pchan] := 0;
  315.               textcolor(10);   gotoxy(77,2+pchan);
  316.               write('M');      textcolor(2);
  317.               write('UTE');
  318.             end else begin;
  319.               Play_Chanel[pchan] := 1;
  320.               textcolor(10);   gotoxy(77,2+pchan);
  321.               write('C');      textcolor(2);
  322.               write('H  ');
  323.             end;
  324.           end;
  325.     'n',
  326.     'N' : begin;
  327.             prochain_mod;
  328.           end;
  329.   end;
  330. end;
  331.  
  332. procedure screen_update;
  333. const colvals : array[1..35] of byte =
  334.    (08,08,08,08,08,02,02,02,02,10,10,10,10,10,10,10,10,
  335.     10,10,10,10,10,10,10,10,10,10,10,10,10,05,05,05,05,05);
  336. var volstr : string[66];
  337.     li : integer;
  338.     auss : integer;
  339. begin;
  340.   { Remettre à jour les barres indiquant le volume }
  341.   for li := 1 to Modinf.Voix do begin;
  342.     for auss := 1 to round(Runinf.Volumes[li] / 1.78) do begin;
  343.       screen[li+2,37+auss].a := colvals[auss];
  344.     end;
  345.     for auss := round(Runinf.Volumes[li] / 1.78)  to 36 do begin;
  346.       screen[li+2,38+auss].a := 7;
  347.     end;
  348.   end;
  349.  
  350.   { Définir l'arrière-plan en couleurs pour la flèche }
  351.   for li := 1 to 8 do begin;
  352.     if li = modify_voice then begin;
  353.       screen[2+li,34].a := 05;
  354.       screen[2+li,35].a := 05;
  355.       screen[2+li,36].a := 05;
  356.       screen[2+li,37].a := 05;
  357.     end else begin;
  358.       screen[2+li,34].a := 07;
  359.       screen[2+li,35].a := 07;
  360.       screen[2+li,36].a := 07;
  361.       screen[2+li,37].a := 07;
  362.     end;
  363.   end;
  364.  
  365.   { Afficher des informations en temps réel sur le MOD }
  366.   gotoxy(18,14);
  367.   color_writeln(Modinf.Titre);
  368.  
  369.   textcolor(7);
  370.   gotoxy(18,16);
  371.   write(runinf.pattnr:3);
  372.  
  373.   gotoxy(64,16);
  374.   write(runinf.ligne:3);
  375.  
  376.   gotoxy(64,15);
  377.   write(64:3);
  378.  
  379.   gotoxy(18,15);
  380.   write(modinf.Nb_Patt:3);
  381.  
  382.   gotoxy(60,14);
  383.   write(runinf.speed,' / ',runinf.bpm);
  384. end;
  385.  
  386. procedure user;
  387. {
  388.  Vérifie les saisies aux claviers et remet à jour l'écran
  389. }
  390. var ch1,ch2 : char;
  391. begin;
  392.   repeat
  393.     ch1 := #255;
  394.     ch2 := #255;
  395.     if keypressed then begin;
  396.       ch1 := readkey;
  397.       if keypressed then ch2 := readkey;
  398.       handle_keys(ch1,ch2);
  399.     end;
  400.    screen_update;
  401.   until Programm_quitter;
  402. end;
  403.  
  404.  
  405. procedure display_help;
  406. {
  407.  Affiche l'aide Ansi, même quand aucune carte GUS n'a été trouvée
  408. }
  409. begin;
  410.   display_ansi(@helptxt,co80+font8x8);
  411.   cursor_off;
  412.   repeat until keypressed;
  413.   while keypressed do readkey;
  414.   exit_program;
  415. end;
  416.  
  417.  
  418. function check_commandline : boolean;
  419. {
  420.  retourne true, lorsqu'un nom de module a été donné
  421. }
  422. var pst : string;
  423.     ist_mod : boolean;
  424.     li : integer;
  425.     retval : boolean;
  426. begin;
  427.   retval := false;
  428.   for li := 1 to 9 do begin;
  429.     pst := paramstr(li);
  430.     ist_mod := true;
  431.  
  432.     if (pos('-h',pst) <> 0) or (pos('-H',pst) <> 0) or
  433.        (pos('-?',pst) <> 0) then
  434.     begin;
  435.       ist_mod := false;
  436.       display_help;
  437.     end;
  438.  
  439.     if (pst <> '') and ist_mod then begin;
  440.       if pos('.',pst) = 0 then pst := pst + '.mod';
  441.       if fichier_exists(pst) then  { mode valide }
  442.       begin
  443.         inc(Les_Files^.nofiles);
  444.         Les_Files^.fn[Les_Files^.nofiles] := pst;
  445.         retval := true;
  446.       end;
  447.     end;
  448.   end;
  449.   check_commandline := retval;
  450. end;
  451.  
  452. begin;
  453.   cursor_off;
  454.   clrscr;
  455.   if not _gus_init_env then display_help;
  456.  
  457.   new(Les_Files);
  458.   new(phun);
  459.   Les_Files^.path := mod_chem;
  460.   Les_Files^.Mask := '*.mod';
  461.   Les_Files^.sx   := 24;
  462.   Les_Files^.sy   := 10;
  463.   Les_Files^.nofiles := 0;
  464.  
  465.   Les_Files^.Titre := 'Choisir un fichier MOD!!!';
  466.   modify_voice := 1;
  467.  
  468.   for i := 1 to 30 do
  469.     Les_Files^.fn[i] := '---';
  470.   save_screen;
  471.   if not check_commandline then begin;
  472.     select_packfichiers(Les_Files);
  473.     repeat
  474.       restore_screen;
  475.  
  476.       if Les_Files^.fn[1] = '---' then exit_program;
  477.  
  478.         _gus_initialiser;
  479.  
  480.       display_ansi(@tcpans,co80+font8x8);
  481.       cursor_off;
  482.       write_phunliners;
  483.  
  484.       curr_modnr := 1;
  485.       if not _gus_modload(Les_Files^.fn[1]) then begin;
  486.         clrscr;
  487.         gotoxy(10,10);
  488.         write('Sorry dude, Cant''t handle this MOD-File');
  489.         delay(1200);
  490.         exit_program;
  491.       end;
  492.       write_nomfichier(Les_Files^.fn[1]);
  493.       display_modinfos;
  494.       fillchar(Play_Chanel,14,1);
  495.       _gus_modstart;
  496.  
  497.       user;
  498.       _gus_mod_quitter;
  499.       dispose(Les_Files);
  500.       new(Les_Files);
  501.       Les_Files^.path := Mod_chem;
  502.       Les_Files^.Mask := '*.mod';
  503.       Les_Files^.sx   := 24;
  504.       Les_Files^.sy   := 10;
  505.       Les_Files^.nofiles := 0;
  506.       for i := 1 to 30 do
  507.         Les_Files^.fn[i] := '---';
  508.       Programm_quitter := false;
  509.       select_packfichiers(Les_Files);
  510.     until Les_Files^.fn[1] = '---';
  511.  
  512.       dispose(Les_Files);
  513.     dispose(phun);
  514.     exit_program;
  515.   end else begin;
  516.   restore_screen;
  517.  
  518.   if Les_Files^.fn[1] = '---' then exit_program;
  519.  
  520.   _gus_initialiser;
  521.  
  522.   display_ansi(@tcpans,co80+font8x8);
  523.   cursor_off;
  524.   write_phunliners;
  525.  
  526.   curr_modnr := 1;
  527.   _gus_modload(Les_Files^.fn[1]);
  528.   write_nomfichier(Les_Files^.fn[1]);
  529.   display_modinfos;
  530.   fillchar(Play_Chanel,14,1);
  531.   _gus_modstart;
  532.  
  533.   user;
  534.  
  535.   _gus_mod_quitter;
  536.   dispose(Les_Files);
  537.   dispose(phun);
  538.   exit_program;
  539.  
  540.   end;
  541. end.