paddle.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. */
  9. #include <os_dependent.h>
  10. #include "paddle.h"
  11. void InitPaddle(Paddle *pdl)
  12. {
  13. pdl->Bit = 1;
  14. pdl->LastWrite = 0;
  15. }
  16. void WritePaddle(Paddle *pdl, uint8_t val)
  17. {
  18. if ( ( pdl->LastWrite == 1 ) && ( val == 0 ) )
  19. InitPaddle(pdl);
  20. pdl->LastWrite = val;
  21. }
  22. uint8_t ReadPaddle(Paddle *pdl)
  23. {
  24. switch(pdl->Bit++)
  25. {
  26. case 1:
  27. if ( getKeyStatus('O') )
  28. return 0x41;
  29. break;
  30. case 2:
  31. if ( getKeyStatus('P') )
  32. return 0x41;
  33. break;
  34. case 3:
  35. if ( getKeyStatus('I') )
  36. return 0x41;
  37. break;
  38. case 4:
  39. if ( getKeyStatus('U') )
  40. return 0x41;
  41. break;
  42. case 5:
  43. if ( getKeyStatus('W') )
  44. return 0x41;
  45. break;
  46. case 6:
  47. if ( getKeyStatus('S') )
  48. return 0x41;
  49. break;
  50. case 7:
  51. if ( getKeyStatus('A') )
  52. return 0x41;
  53. break;
  54. case 8:
  55. if ( getKeyStatus('D') )
  56. return 0x41;
  57. break;
  58. case 20:
  59. return 0x40;
  60. break;
  61. case 24:
  62. pdl->Bit = 1;
  63. return 0x40;
  64. default:
  65. return 0x40;
  66. break;
  67. }
  68. return 0x40;
  69. }