PasswordCart.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Password Cartridge
  3. *
  4. * Access: write 0x00 to I/O port 0x7e
  5. * provide 0xaa, <char1>, <char2>, continuous 0xff sequence reading I/O port 0x7e
  6. * write any non-zero to I/O port 0x7e
  7. * provide 0xff at all time reading I/O port 0x7e
  8. */
  9. #include "PasswordCart.hh"
  10. #include "serialize.hh"
  11. #include <algorithm>
  12. namespace openmsx {
  13. PasswordCart::PasswordCart(const DeviceConfig& config)
  14. : MSXDevice(config)
  15. , password(config.getChildDataAsInt("password", 0))
  16. {
  17. reset(EmuTime::dummy());
  18. }
  19. void PasswordCart::reset(EmuTime::param /*time*/)
  20. {
  21. pointer = 3;
  22. }
  23. void PasswordCart::writeIO(word /*port*/, byte value, EmuTime::param /*time*/)
  24. {
  25. pointer = (value == 0) ? 0 : 3;
  26. }
  27. byte PasswordCart::readIO(word port, EmuTime::param time)
  28. {
  29. byte result = peekIO(port, time);
  30. pointer = std::min(3, pointer + 1);
  31. return result;
  32. }
  33. byte PasswordCart::peekIO(word /*port*/, EmuTime::param /*time*/) const
  34. {
  35. switch (pointer) {
  36. case 0:
  37. return 0xAA;
  38. case 1:
  39. return password >> 8;
  40. case 2:
  41. return password & 0xFF;
  42. default:
  43. return 0xFF;
  44. }
  45. }
  46. template<typename Archive>
  47. void PasswordCart::serialize(Archive& ar, unsigned /*version*/)
  48. {
  49. ar.template serializeBase<MSXDevice>(*this);
  50. ar.serialize("pointer", pointer);
  51. }
  52. INSTANTIATE_SERIALIZE_METHODS(PasswordCart);
  53. REGISTER_MSXDEVICE(PasswordCart, "PasswordCart");
  54. } // namespace openmsx