paddle.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Paddle manager - The TI-NESulator Project
  3. * paddle.c
  4. *
  5. * Created by Manoel TRAPIER.
  6. * Copyright (c) 2003-2008 986Corp. All rights reserved.
  7. *
  8. * $LastChangedDate$
  9. * $Author$
  10. * $HeadURL$
  11. * $Revision$
  12. *
  13. */
  14. /* Allegro includes */
  15. #ifdef __APPLE__
  16. #define USE_CONSOLE
  17. #include <Allegro/allegro.h>
  18. #else
  19. #define USE_CONSOLE
  20. #include <allegro.h>
  21. #endif
  22. #include "paddle.h"
  23. void InitPaddle(Paddle * pdl)
  24. {
  25. pdl->Bit = 1;
  26. pdl->LastWrite = 0;
  27. }
  28. void WritePaddle(Paddle *pdl, unsigned char val)
  29. {
  30. if ((pdl->LastWrite == 1) && (val == 0))
  31. InitPaddle(pdl);
  32. pdl->LastWrite = val;
  33. }
  34. unsigned char ReadPaddle(Paddle * pdl)
  35. {
  36. switch (pdl->Bit++)
  37. {
  38. case 1:
  39. if (key[KEY_Z])
  40. return 0x41;
  41. break;
  42. case 2:
  43. if (key[KEY_X])
  44. return 0x41;
  45. break;
  46. case 3:
  47. if (key[KEY_P])
  48. return 0x41;
  49. break;
  50. case 4:
  51. if (key[KEY_ENTER])
  52. return 0x41;
  53. break;
  54. case 5:
  55. if (key[KEY_UP])
  56. return 0x41;
  57. break;
  58. case 6:
  59. if (key[KEY_DOWN])
  60. return 0x41;
  61. break;
  62. case 7:
  63. if (key[KEY_LEFT])
  64. return 0x41;
  65. break;
  66. case 8:
  67. if (key[KEY_RIGHT])
  68. return 0x41;
  69. break;
  70. case 20:
  71. return 0x40;
  72. break;
  73. case 24:
  74. pdl->Bit = 1;
  75. return 0x40;
  76. default:
  77. return 0x40;
  78. break;
  79. }
  80. return 0x40;
  81. }