MSXDeviceSwitch.hh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef MSXDEVICESWITCH_HH
  2. #define MSXDEVICESWITCH_HH
  3. #include "MSXDevice.hh"
  4. namespace openmsx {
  5. /**
  6. * The MSX2 Hardware Specification says ports 0x41-0x4F are Switched I/O ports.
  7. * Output of a ID value to port 0x40 selects a specific I/O device and connects
  8. * it to the CPU.
  9. *
  10. * It is possible to give numbers between 0 and 255 as a device number.
  11. * However, when reading the device number, the complement is given, so 0 and
  12. * 255 are not used. ID numbers between 1 and 127 are manufacturers ID number
  13. * as in expanded BIOS call. 128 to 254 are device numbers. As a basic rule,
  14. * those device which are designed specifically for one machine should contain
  15. * the manufacturers company ID while peripheral device which can be used for
  16. * all MSX should have device ID number. Also, Z80 CPU has 16 bit address in
  17. * I/O space so it is recommended to access in 16 bit by decoding the upper 8
  18. * bit for those ID which might be expanded in the future. Especially for
  19. * device which are connected with make ID can expand the address space by 256
  20. * times so it is future proofed.
  21. *
  22. * Maker ID
  23. * 1 ASCII/Microsoft
  24. * 2 Canon
  25. * 3 Casio
  26. * 4 Fujitsu
  27. * 5 General
  28. * 6 Hitachi
  29. * 7 Kyocera
  30. * 8 Matsushita
  31. * 9 Mitsubishi
  32. * 10 NEC
  33. * 11 Nippon Gakki
  34. * 12 JVC
  35. * 13 Philips
  36. * 14 Pioneer
  37. * 15 Sanyo
  38. * 16 Sharp
  39. * 17 SONY
  40. * 18 Spectravideo
  41. * 19 Toshiba
  42. * 20 Mitsumi
  43. *
  44. * Device ID
  45. * 128 Image Scanner (Matsushita)
  46. * 247 Kanji 12x12
  47. * 254 MPS2 (ASCII)
  48. */
  49. class MSXSwitchedDevice;
  50. class MSXDeviceSwitch final : public MSXDevice
  51. {
  52. public:
  53. explicit MSXDeviceSwitch(const DeviceConfig& config);
  54. ~MSXDeviceSwitch() override;
  55. // (un)register methods for devices
  56. void registerDevice(byte id, MSXSwitchedDevice* device);
  57. void unregisterDevice(byte id);
  58. bool hasRegisteredDevices() const { return count != 0; }
  59. void reset(EmuTime::param time) override;
  60. byte readIO(word port, EmuTime::param time) override;
  61. byte peekIO(word port, EmuTime::param time) const override;
  62. void writeIO(word port, byte value, EmuTime::param time) override;
  63. template<typename Archive>
  64. void serialize(Archive& ar, unsigned version);
  65. private:
  66. MSXSwitchedDevice* devices[256];
  67. unsigned count;
  68. byte selected;
  69. };
  70. } // namespace openmsx
  71. #endif