Mirror of CollapseOS
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

71 lignes
1.2KB

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "sio.h"
  4. void sio_init(SIO *sio)
  5. {
  6. memset(sio->wr, 0, sizeof(sio->wr));
  7. memset(sio->rr, 0, sizeof(sio->rr));
  8. sio->rx = 0;
  9. sio->tx = 0;
  10. sio->in_int = false;
  11. }
  12. bool sio_has_irq(SIO *sio)
  13. {
  14. bool res = sio->in_int;
  15. sio->in_int = false;
  16. return res;
  17. }
  18. bool sio_hasrx(SIO *sio)
  19. {
  20. return sio->rr[0] & 0x01; // Receive Character Available
  21. }
  22. bool sio_hastx(SIO *sio)
  23. {
  24. return !(sio->rr[0] & 0x04); // Transmit Buffer Empty
  25. }
  26. uint8_t sio_read(SIO *sio)
  27. {
  28. sio->rr[0] |= 0x04; // Transmit Buffer Empty high
  29. return sio->tx;
  30. }
  31. void sio_write(SIO *sio, uint8_t val)
  32. {
  33. sio->rr[0] |= 0x01; // Receive Character Available high
  34. sio->rx = val;
  35. sio->in_int = true;
  36. }
  37. uint8_t sio_actl_rd(SIO *sio)
  38. {
  39. uint8_t target = sio->wr[0] & 0x3; // PTR
  40. return sio->rr[target];
  41. }
  42. void sio_actl_wr(SIO *sio, uint8_t val)
  43. {
  44. uint8_t target = sio->wr[0] & 0x7; // PTR
  45. sio->wr[target] = val;
  46. if (target != 0) {
  47. sio->wr[0] &= ~0x7;
  48. }
  49. }
  50. uint8_t sio_adata_rd(SIO *sio)
  51. {
  52. sio->rr[0] &= ~0x01; // Receive Character Available low
  53. return sio->rx;
  54. }
  55. void sio_adata_wr(SIO *sio, uint8_t val)
  56. {
  57. sio->tx = val;
  58. sio->rr[0] &= ~0x04; // Transmit Buffer Empty low
  59. }