An emulator, assembler, and disassembler for the Sega Game Gear
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright (C) 2014-2016 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. Released under the terms of the MIT License. See LICENSE for details. */
  3. #include "io.h"
  4. /*
  5. Initialize an IO object.
  6. */
  7. void io_init(IO *io, VDP *vdp, PSG *psg)
  8. {
  9. io->vdp = vdp;
  10. io->psg = psg;
  11. }
  12. /*
  13. "Power on" the IO object.
  14. */
  15. void io_power(IO *io)
  16. {
  17. io->except = false;
  18. }
  19. /*
  20. Return whether the IRQ line is currently active.
  21. */
  22. bool io_check_irq(IO *io)
  23. {
  24. return vdp_assert_irq(io->vdp);
  25. }
  26. /*
  27. Read and return a byte from the given port.
  28. */
  29. uint8_t io_port_read(IO *io, uint8_t port)
  30. {
  31. if (port <= 0x06) {
  32. // TODO: GG specific registers; initial state: C0 7F FF 00 FF 00 FF
  33. } else if (port <= 0x3F) {
  34. return 0xFF;
  35. } else if (port <= 0x7F && !(port % 2)) {
  36. return io->vdp->v_counter;
  37. } else if (port <= 0x7F) {
  38. return io->vdp->h_counter;
  39. } else if (port <= 0xBF && !(port % 2)) {
  40. return vdp_read_data(io->vdp);
  41. } else if (port <= 0xBF) {
  42. return vdp_read_control(io->vdp);
  43. } else if (port == 0xCD || port == 0xDC) {
  44. // TODO: Return the I/O port A/B register
  45. } else if (port == 0xC1 || port == 0xDD) {
  46. // TODO: Return the I/O port B/misc. register
  47. } else {
  48. return 0xFF;
  49. }
  50. io->except = true;
  51. io->exc_port = port;
  52. return 0;
  53. }
  54. /*
  55. Write a byte to the given port.
  56. */
  57. void io_port_write(IO *io, uint8_t port, uint8_t value)
  58. {
  59. if (port <= 0x06) {
  60. // TODO: GG specific registers; initial state: C0 7F FF 00 FF 00 FF
  61. goto except;
  62. } else if (port <= 0x3F && !(port % 2)) {
  63. // TODO: Write to memory control register
  64. goto except;
  65. } else if (port <= 0x3F) {
  66. // TODO: Write to I/O control register
  67. goto except;
  68. } else if (port <= 0x7F) {
  69. psg_write(io->psg, value);
  70. } else if (port <= 0xBF && !(port % 2)) {
  71. vdp_write_data(io->vdp, value);
  72. } else if (port <= 0xBF) {
  73. vdp_write_control(io->vdp, value);
  74. } else {
  75. return;
  76. }
  77. return;
  78. except:
  79. io->except = true;
  80. io->exc_port = port;
  81. }