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