| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include "PasswordCart.hh" |
| 11 |
#include "narrow.hh" |
| 12 |
#include "serialize.hh" |
| 13 |
#include <algorithm> |
| 14 |
|
| 15 |
namespace openmsx { |
| 16 |
|
| 17 |
PasswordCart::PasswordCart(const DeviceConfig& config) |
| 18 |
: MSXDevice(config) |
| 19 |
, password(narrow_cast<uint16_t>(config.getChildDataAsInt("password", 0))) |
| 20 |
{ |
| 21 |
reset(EmuTime::dummy()); |
| 22 |
} |
| 23 |
|
| 24 |
void PasswordCart::reset(EmuTime ) |
| 25 |
{ |
| 26 |
pointer = 3; |
| 27 |
} |
| 28 |
|
| 29 |
void PasswordCart::writeIO(uint16_t , byte value, EmuTime ) |
| 30 |
{ |
| 31 |
pointer = (value == 0) ? 0 : 3; |
| 32 |
} |
| 33 |
|
| 34 |
byte PasswordCart::readIO(uint16_t port, EmuTime time) |
| 35 |
{ |
| 36 |
byte result = peekIO(port, time); |
| 37 |
pointer = byte(std::min(3, pointer + 1)); |
| 38 |
return result; |
| 39 |
} |
| 40 |
|
| 41 |
byte PasswordCart::peekIO(uint16_t , EmuTime ) 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 |
|
| 55 |
template<typename Archive> |
| 56 |
void PasswordCart::serialize(Archive& ar, unsigned ) |
| 57 |
{ |
| 58 |
ar.template serializeBase<MSXDevice>(*this); |
| 59 |
ar.serialize("pointer", pointer); |
| 60 |
} |
| 61 |
INSTANTIATE_SERIALIZE_METHODS(PasswordCart); |
| 62 |
REGISTER_MSXDEVICE(PasswordCart, "PasswordCart"); |
| 63 |
|
| 64 |
} |