Advertisement
jacknpoe

Teclas para jogos via BIOS

Oct 17th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.42 KB | None | 0 0
  1. // (código completo em http://pastebin.com/QDKRaefq)
  2. //
  3. // CÓDIGOS <SCANCODE> DE PRESSIONAR E SOLTAR DE ALGUMAS TECLAS
  4. // 72 / 200 = para cima
  5. // 75 / 203 = para esquerda
  6. // 77 / 205 = para direita
  7. // 80 / 208 = para baixo
  8. // 01 / 129 = esc
  9. // 57 / 185 = espaço
  10. // 28 / 156 = enter
  11.  
  12. // mais (em hexa, para o segundo número, acrescentar 0x80 ou 128 decimal):
  13. //  http://www.ee.bgu.ac.il/~microlab/MicroLab/Labs/ScanCodes.htm
  14.  
  15. #include <dos.h>    // AQUI SE SEMEIA A DISCÓRDIA
  16.  
  17. char troquei_ints = 0;
  18.  
  19. // ------- inportb para dev c++ ---------------------------
  20. unsigned char inportb(unsigned int port) {
  21. unsigned char ret;
  22. asm volatile("inb %%dx,%%al":"=a" (ret):"d"(port));
  23. return ret;
  24. }
  25.  
  26. // -------- outportb para dev c++ ----------------------------
  27. inline void outportb(unsigned int port, unsigned char value) {
  28. asm volatile("outb %%al,%%dx": :"d"(port),"a" (value));
  29. }
  30.  
  31. unsigned int  estado_tecla[4];
  32. unsigned int  tempo_tecla[4];
  33. unsigned int  press_tecla[4];
  34. unsigned int  hora_real = 0;
  35. unsigned char auxiliar;
  36. unsigned char scancode;
  37.  
  38. void interrupt (*velha_int_09h)();
  39. void interrupt (*velha_int_1ch)();
  40. void interrupt (*velha_int_1bh)();
  41.  
  42. void interrupt nova_int_1bh()
  43. {
  44. }
  45.  
  46. void interrupt nova_int_09h()
  47. {
  48.     scancode = inportb( 0x60);
  49.     switch (scancode)
  50.     {
  51.         case  72: { if( estado_tecla[0] == 0) press_tecla[0] = 1;   // PRA CIMA
  52.                     estado_tecla[0] = 1; }
  53.                     break;
  54.         case 200: { estado_tecla[0] = 0;
  55.                     tempo_tecla[0] = 0; }
  56.                     break;
  57.         case  77: { if( estado_tecla[1] == 0) press_tecla[1] = 1;   // DIREITA
  58.                     estado_tecla[1] = 1; }
  59.                     break;
  60.         case 205: { estado_tecla[1] = 0;
  61.                     tempo_tecla[1] = 0; }
  62.                     break;
  63.         case  80: { if( estado_tecla[2] == 0) press_tecla[2] = 1;   // PRA BAIXO
  64.                     estado_tecla[2] = 1; }
  65.                     break;
  66.         case 208: { estado_tecla[2] = 0;
  67.                     tempo_tecla[2] = 0; }
  68.                     break;
  69.         case  75: { if( estado_tecla[3] == 0) press_tecla[3] = 1;   // ESQUERDA
  70.                     estado_tecla[3] = 1; }
  71.                     break;
  72.         case 203: { estado_tecla[3] = 0;
  73.                     tempo_tecla[3] = 0; }
  74.                     break;
  75.     }
  76.     if( ( ( ( scancode > 70) & ( scancode < 82)) | ( ( scancode > 198) & ( scancode < 210))) | scancode == 225)
  77.     {
  78.         auxiliar = inportb( 0x61);
  79.         outportb( 0x61, auxiliar | 0x80);
  80.         outportb( 0x61, auxiliar);
  81.         outportb( 0x20, 0x20);
  82.     }
  83.     else (*velha_int_09h)();
  84. }
  85.  
  86. void interrupt nova_int_1ch()
  87. {
  88.     hora_real++;
  89.  
  90.     if( estado_tecla[0] == 1)
  91.     {
  92.         tempo_tecla[0] += 1;
  93.         if( tempo_tecla[0] > 11)
  94.         {
  95.             tempo_tecla[0] -= 12;
  96.             press_tecla[0] = 1;
  97.         }
  98.     }
  99.     if( estado_tecla[1] == 1)
  100.     {
  101.         tempo_tecla[1] += 1;
  102.         if( tempo_tecla[1] > 8)
  103.         {
  104.             tempo_tecla[1] -= 9;
  105.             press_tecla[1] = 1;
  106.         }
  107.     }
  108.     if( estado_tecla[2] == 1)
  109.     {
  110.         tempo_tecla[2] += 1;
  111.         if( tempo_tecla[2] > 11)
  112.         {
  113.             tempo_tecla[2] -= 12;
  114.             press_tecla[2] = 1;
  115.         }
  116.     }
  117.     if( estado_tecla[3] == 1)
  118.     {
  119.         tempo_tecla[3] += 1;
  120.         if( tempo_tecla[3] > 8)
  121.         {
  122.             tempo_tecla[3] -= 9;
  123.             press_tecla[3] = 1;
  124.         }
  125.     }
  126.  
  127.     (*velha_int_1ch)();
  128. }
  129.  
  130.  
  131. NO ENTRADA DO JOGO, COLOCAR:
  132.     seta_64();
  133.     if( troquei_ints == 0 )
  134.     {
  135.         velha_int_09h = getvect( 0x09);
  136.         velha_int_1ch = getvect( 0x1c);
  137.         velha_int_1bh = getvect( 0x1b);
  138.         troquei_ints = 1;
  139.     }
  140.     setvect( 0x1c, nova_int_1ch);
  141.     setvect( 0x09, nova_int_09h);
  142.     setvect( 0x1b, nova_int_1bh);
  143.  
  144. NA SAÍDA DO JOGO, COLOCAR:
  145.  
  146.     if( troquei_ints != 0 )
  147.     {
  148.         setvect( 0x09, velha_int_09h);
  149.         setvect( 0x1c, velha_int_1ch);
  150.         setvect( 0x1b, velha_int_1bh);
  151.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement