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.
 
 
 
 
 

80 lignes
1.9 KiB

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