openMSX
PasswordCart.cc
Go to the documentation of this file.
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 
10 #include "PasswordCart.hh"
11 #include "serialize.hh"
12 #include <algorithm>
13 
14 namespace openmsx {
15 
17  : MSXDevice(config)
18  , password(config.getChildDataAsInt("password", 0))
19 {
20  reset(EmuTime::dummy());
21 }
22 
23 void PasswordCart::reset(EmuTime::param /*time*/)
24 {
25  pointer = 3;
26 }
27 
28 void PasswordCart::writeIO(word /*port*/, byte value, EmuTime::param /*time*/)
29 {
30  pointer = (value == 0) ? 0 : 3;
31 }
32 
33 byte PasswordCart::readIO(word port, EmuTime::param time)
34 {
35  byte result = peekIO(port, time);
36  pointer = std::min(3, pointer + 1);
37  return result;
38 }
39 
40 byte PasswordCart::peekIO(word /*port*/, EmuTime::param /*time*/) const
41 {
42  switch (pointer) {
43  case 0:
44  return 0xAA;
45  case 1:
46  return password >> 8;
47  case 2:
48  return password & 0xFF;
49  default:
50  return 0xFF;
51  }
52 }
53 
54 template<typename Archive>
55 void PasswordCart::serialize(Archive& ar, unsigned /*version*/)
56 {
57  ar.template serializeBase<MSXDevice>(*this);
58  ar.serialize("pointer", pointer);
59 }
62 
63 } // namespace openmsx
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
gl::min
vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:274
serialize.hh
openmsx::PasswordCart::PasswordCart
PasswordCart(const DeviceConfig &config)
Definition: PasswordCart.cc:16
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::PasswordCart::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: PasswordCart.cc:23
openmsx::PasswordCart::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: PasswordCart.cc:33
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::PasswordCart::serialize
void serialize(Archive &ar, unsigned version)
Definition: PasswordCart.cc:55
openmsx::PasswordCart::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: PasswordCart.cc:40
openmsx::PasswordCart::writeIO
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
Definition: PasswordCart.cc:28
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::PasswordCart
Definition: PasswordCart.hh:9
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
PasswordCart.hh
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5