paddle.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Paddle manager - The peTI-NESulator Project
  3. * paddle.c
  4. *
  5. * Created by Manoel TRAPIER.
  6. * Copyright (c) 2003-2018 986-Studio. All rights reserved.
  7. *
  8. * $LastChangedDate$
  9. * $Author$
  10. * $HeadURL$
  11. * $Revision$
  12. *
  13. */
  14. #include <os_dependent.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 ( getKeyStatus('O') )
  33. return 0x41;
  34. break;
  35. case 2:
  36. if ( getKeyStatus('P') )
  37. return 0x41;
  38. break;
  39. case 3:
  40. if ( getKeyStatus('I') )
  41. return 0x41;
  42. break;
  43. case 4:
  44. if ( getKeyStatus('U') )
  45. return 0x41;
  46. break;
  47. case 5:
  48. if ( getKeyStatus('W') )
  49. return 0x41;
  50. break;
  51. case 6:
  52. if ( getKeyStatus('S') )
  53. return 0x41;
  54. break;
  55. case 7:
  56. if ( getKeyStatus('A') )
  57. return 0x41;
  58. break;
  59. case 8:
  60. if ( getKeyStatus('D') )
  61. return 0x41;
  62. break;
  63. case 20:
  64. return 0x40;
  65. break;
  66. case 24:
  67. pdl->Bit = 1;
  68. return 0x40;
  69. default:
  70. return 0x40;
  71. break;
  72. }
  73. return 0x40;
  74. }