paddle.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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: 2007-05-02 18:37:41 +0200 (mer, 02 mai 2007) $
  9. * $Author: mtrapier $
  10. * $HeadURL: file:///media/HD6G/SVNROOT/trunk/TI-NESulator/src/paddle.c $
  11. * $Revision: 50 $
  12. *
  13. */
  14. #include <allegro.h>
  15. #include "paddle.h"
  16. void InitPaddle(Paddle * pdl)
  17. {
  18. pdl->Bit = 1;
  19. pdl->LastWrite = 0;
  20. }
  21. void WritePaddle(Paddle *pdl, unsigned char val)
  22. {
  23. if ((pdl->LastWrite == 1) && (val == 0))
  24. InitPaddle(pdl);
  25. pdl->LastWrite = val;
  26. }
  27. unsigned char ReadPaddle(Paddle * pdl)
  28. {
  29. switch (pdl->Bit++)
  30. {
  31. case 1:
  32. if (key[KEY_Z])
  33. return 0x41;
  34. break;
  35. case 2:
  36. if (key[KEY_X])
  37. return 0x41;
  38. break;
  39. case 3:
  40. if (key[KEY_P])
  41. return 0x41;
  42. break;
  43. case 4:
  44. if (key[KEY_ENTER])
  45. return 0x41;
  46. break;
  47. case 5:
  48. if (key[KEY_UP])
  49. return 0x41;
  50. break;
  51. case 6:
  52. if (key[KEY_DOWN])
  53. return 0x41;
  54. break;
  55. case 7:
  56. if (key[KEY_LEFT])
  57. return 0x41;
  58. break;
  59. case 8:
  60. if (key[KEY_RIGHT])
  61. return 0x41;
  62. break;
  63. case 20:
  64. return 0x41;
  65. break;
  66. case 24:
  67. pdl->Bit = 1;
  68. return 0x40;
  69. default:
  70. return 0x40;
  71. break;
  72. }
  73. return 0x40;
  74. }