MSXS1990.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "MSXS1990.hh"
  2. #include "MSXCPU.hh"
  3. #include "MSXMotherBoard.hh"
  4. #include "PanasonicMemory.hh"
  5. #include "outer.hh"
  6. #include "serialize.hh"
  7. #include "unreachable.hh"
  8. namespace openmsx {
  9. MSXS1990::MSXS1990(const DeviceConfig& config)
  10. : MSXDevice(config)
  11. , debuggable(getMotherBoard(), getName())
  12. , firmwareSwitch(config)
  13. {
  14. reset(EmuTime::dummy());
  15. }
  16. void MSXS1990::reset(EmuTime::param /*time*/)
  17. {
  18. registerSelect = 0; // TODO check this
  19. setCPUStatus(96);
  20. }
  21. byte MSXS1990::readIO(word port, EmuTime::param time)
  22. {
  23. return peekIO(port, time);
  24. }
  25. byte MSXS1990::peekIO(word port, EmuTime::param /*time*/) const
  26. {
  27. switch (port & 0x01) {
  28. case 0:
  29. return registerSelect;
  30. case 1:
  31. return readRegister(registerSelect);
  32. default: // unreachable, avoid warning
  33. UNREACHABLE;
  34. return 0;
  35. }
  36. }
  37. void MSXS1990::writeIO(word port, byte value, EmuTime::param /*time*/)
  38. {
  39. switch (port & 0x01) {
  40. case 0:
  41. registerSelect = value;
  42. break;
  43. case 1:
  44. writeRegister(registerSelect, value);
  45. break;
  46. default:
  47. UNREACHABLE;
  48. }
  49. }
  50. byte MSXS1990::readRegister(byte reg) const
  51. {
  52. switch (reg) {
  53. case 5:
  54. return firmwareSwitch.getStatus() ? 0x40 : 0x00;
  55. case 6:
  56. return cpuStatus;
  57. case 13:
  58. return 0x03; // TODO
  59. case 14:
  60. return 0x2F; // TODO
  61. case 15:
  62. return 0x8B; // TODO
  63. default:
  64. return 0xFF;
  65. }
  66. }
  67. void MSXS1990::writeRegister(byte reg, byte value)
  68. {
  69. switch (reg) {
  70. case 6:
  71. setCPUStatus(value);
  72. break;
  73. }
  74. }
  75. void MSXS1990::setCPUStatus(byte value)
  76. {
  77. cpuStatus = value & 0x60;
  78. getCPU().setActiveCPU((cpuStatus & 0x20) ? MSXCPU::CPU_Z80 :
  79. MSXCPU::CPU_R800);
  80. bool dram = (cpuStatus & 0x40) == 0;
  81. getCPU().setDRAMmode(dram);
  82. getMotherBoard().getPanasonicMemory().setDRAM(dram);
  83. // TODO bit 7 -> reset MSX ?????
  84. }
  85. MSXS1990::Debuggable::Debuggable(MSXMotherBoard& motherBoard_, const std::string& name_)
  86. : SimpleDebuggable(motherBoard_, name_ + " regs", "S1990 registers", 16)
  87. {
  88. }
  89. byte MSXS1990::Debuggable::read(unsigned address)
  90. {
  91. auto& s1990 = OUTER(MSXS1990, debuggable);
  92. return s1990.readRegister(address);
  93. }
  94. void MSXS1990::Debuggable::write(unsigned address, byte value)
  95. {
  96. auto& s1990 = OUTER(MSXS1990, debuggable);
  97. s1990.writeRegister(address, value);
  98. }
  99. template<typename Archive>
  100. void MSXS1990::serialize(Archive& ar, unsigned /*version*/)
  101. {
  102. ar.template serializeBase<MSXDevice>(*this);
  103. ar.serialize("registerSelect", registerSelect,
  104. "cpuStatus", cpuStatus);
  105. if (ar.isLoader()) {
  106. setCPUStatus(cpuStatus);
  107. }
  108. }
  109. INSTANTIATE_SERIALIZE_METHODS(MSXS1990);
  110. REGISTER_MSXDEVICE(MSXS1990, "S1990");
  111. } // namespace openmsx