An emulator, assembler, and disassembler for the Sega Game Gear
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.

io.c 2.1 KiB

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)
  8. {
  9. io->vdp = vdp;
  10. }
  11. /*
  12. "Power on" the IO object.
  13. */
  14. void io_power(IO *io)
  15. {
  16. io->except = false;
  17. }
  18. /*
  19. Return whether the IRQ line is currently active.
  20. */
  21. bool io_check_irq(IO *io)
  22. {
  23. return vdp_assert_irq(io->vdp);
  24. }
  25. /*
  26. Read and return a byte from the given port.
  27. */
  28. uint8_t io_port_read(IO *io, uint8_t port)
  29. {
  30. if (port <= 0x06) {
  31. // TODO: GG specific registers; initial state: C0 7F FF 00 FF 00 FF
  32. } else if (port <= 0x3F) {
  33. return 0xFF;
  34. } else if (port <= 0x7F && !(port % 2)) {
  35. return io->vdp->v_counter;
  36. } else if (port <= 0x7F) {
  37. return io->vdp->h_counter;
  38. } else if (port <= 0xBF && !(port % 2)) {
  39. return vdp_read_data(io->vdp);
  40. } else if (port <= 0xBF) {
  41. return vdp_read_control(io->vdp);
  42. } else if (port == 0xCD || port == 0xDC) {
  43. // TODO: Return the I/O port A/B register
  44. } else if (port == 0xC1 || port == 0xDD) {
  45. // TODO: Return the I/O port B/misc. register
  46. } else {
  47. return 0xFF;
  48. }
  49. io->except = true;
  50. io->exc_port = port;
  51. return 0;
  52. }
  53. /*
  54. Write a byte to the given port.
  55. */
  56. void io_port_write(IO *io, uint8_t port, uint8_t value)
  57. {
  58. if (port <= 0x06) {
  59. // TODO: GG specific registers; initial state: C0 7F FF 00 FF 00 FF
  60. goto except;
  61. } else if (port <= 0x3F && !(port % 2)) {
  62. // TODO: Write to memory control register
  63. goto except;
  64. } else if (port <= 0x3F) {
  65. // TODO: Write to I/O control register
  66. goto except;
  67. } else if (port <= 0x7F) {
  68. // TODO: Write to the SN76489 PSG
  69. goto except;
  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. }