Advertisement
jacknpoe

DROPS 2 (parte de som)

Nov 1st, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.03 KB | None | 0 0
  1. // PARTE DE SOM
  2.  
  3. #include <fcntl.h>
  4. #include <dos.h>
  5.  
  6. char troquei_ints = 0;
  7.  
  8. char estado_som = 0;
  9. char estado_antigo;
  10. int  contador_efeito, tam_efeito, contador_musica, tam_musica;
  11. int *pt_efeito, *pt_musica;
  12.  
  13. int  efect[] = { 440, 880, 440, 880, 1760}; // EXEMPLO DE SOM (NOTAS EM HERTZ, TEMPO = 1 TICK)
  14.  
  15. void interrupt (*velha_int_1ch)();
  16.  
  17. void interrupt nova_int_1ch()
  18. {
  19.     hora_real++;
  20.     if( estado_som == 0)
  21.         nosound();
  22.     else
  23.     {
  24.         if( estado_som == 2)
  25.         {
  26.             if( pt_efeito[ contador_efeito] > 0)
  27.                 sound( pt_efeito[ contador_efeito]);
  28.             else
  29.                 nosound();
  30.             contador_efeito++;
  31.             if( contador_efeito == tam_efeito)
  32.                 estado_som = estado_antigo;
  33.         }
  34.         else
  35.             if( pt_musica[ contador_musica] > 0)
  36.                 sound( pt_musica[ contador_musica]);
  37.             else
  38.                 nosound();
  39.         contador_musica++;
  40.         if( contador_musica == tam_musica)
  41.             contador_musica = 0;
  42.     }
  43.  
  44.     (*velha_int_1ch)();
  45. }
  46.  
  47. void seta_som_mudo( void)
  48. {
  49.     estado_som = 0;
  50. }
  51.  
  52. void seta_musica( int *nova_musica, int novo_tam)
  53. {
  54.     contador_musica = 0;
  55.     tam_musica = novo_tam;
  56.     pt_musica = nova_musica;
  57.     estado_som = 1;
  58. }
  59.  
  60. void seta_efeito( int *novo_efeito, int novo_tam)
  61. {
  62.     if( estado_som != 2) estado_antigo = estado_som;
  63.     contador_efeito = 0;
  64.     tam_efeito = novo_tam;
  65.     pt_efeito = novo_efeito;
  66.     estado_som = 2;
  67. }
  68.  
  69. void seta_18( void) // PROVAVELMENTE NÃO FUNCIONA MAIS, ERA PRO CLOCK EXECUTAR 18x POR SEGUNDO
  70. {
  71.     outportb( 0x41, 0xB6);
  72.     outportb( 0x40, 0xFF);
  73.     outportb( 0x40, 0xFF);
  74. }
  75.  
  76. void seta_64( void) // PROVAVELMENTE NÃO FUNCIONA MAIS, ERA PRO CLOCK EXECUTAR 64x POR SEGUNDO
  77. {
  78.     outportb( 0x41, 0xB6);
  79.     outportb( 0x40, 0xD3);
  80.     outportb( 0x40, 0x48);
  81. }
  82.  
  83. void inicializa( void)
  84. {
  85.     seta_64();
  86.     velha_int_1ch = getvect( 0x1c);
  87.     troquei_ints = 1;
  88.     setvect( 0x1c, nova_int_1ch);
  89. }
  90.  
  91.  
  92. void fim_do_programa( void )
  93. {
  94.     seta_som_mudo();
  95.     nosound();
  96.     seta_18();
  97.     if( troquei_ints != 0 ) setvect( 0x1c, velha_int_1ch);
  98. }
  99.  
  100. void main()
  101. {
  102. // SUAS VARIÁVEIS AQUI
  103.     atexit( fim_do_programa);
  104.     inicializa();
  105.  
  106. // SEU CÓDIGO AQUI
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement