paddle.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Paddle manager - The peTI-NESulator Project
  3. * paddle.c
  4. *
  5. * Created by Manoël Trapier.
  6. * Copyright (c) 2002-2019 986-Studio.
  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. {
  20. InitPaddle(pdl);
  21. }
  22. pdl->LastWrite = val;
  23. }
  24. uint8_t ReadPaddle(Paddle *pdl)
  25. {
  26. switch (pdl->Bit++)
  27. {
  28. case 1:
  29. if (getKeyStatus('O'))
  30. {
  31. return 0x41;
  32. }
  33. break;
  34. case 2:
  35. if (getKeyStatus('P'))
  36. {
  37. return 0x41;
  38. }
  39. break;
  40. case 3:
  41. if (getKeyStatus('I'))
  42. {
  43. return 0x41;
  44. }
  45. break;
  46. case 4:
  47. if (getKeyStatus('U'))
  48. {
  49. return 0x41;
  50. }
  51. break;
  52. case 5:
  53. if (getKeyStatus('W'))
  54. {
  55. return 0x41;
  56. }
  57. break;
  58. case 6:
  59. if (getKeyStatus('S'))
  60. {
  61. return 0x41;
  62. }
  63. break;
  64. case 7:
  65. if (getKeyStatus('A'))
  66. {
  67. return 0x41;
  68. }
  69. break;
  70. case 8:
  71. if (getKeyStatus('D'))
  72. {
  73. return 0x41;
  74. }
  75. break;
  76. case 20:
  77. return 0x40;
  78. case 24:
  79. pdl->Bit = 1;
  80. return 0x40;
  81. default:
  82. return 0x40;
  83. }
  84. return 0x40;
  85. }