openMSX
MSXE6Timer.cc
Go to the documentation of this file.
1 #include "MSXE6Timer.hh"
2 #include "serialize.hh"
3 
4 namespace openmsx {
5 
7  : MSXDevice(config)
8  , reference(getCurrentTime())
9 {
10 }
11 
12 void MSXE6Timer::reset(EmuTime::param time)
13 {
14  reference.reset(time);
15 }
16 
17 void MSXE6Timer::writeIO(word /*port*/, byte /*value*/, EmuTime::param time)
18 {
19  /*
20  The Clock class rounds down time to its clock resolution.
21  This is correct for the E6 timer, verified by running the following
22  program in R800 mode:
23  org &HC000
24  di
25  ld c,&HE6
26  loop:
27  out (&HE6),a
28  in d,(c)
29  jp z,loop
30  ei
31  ret
32  It returns with D=1.
33  */
34  reference.advance(time);
35 }
36 
37 byte MSXE6Timer::readIO(word port, EmuTime::param time)
38 {
39  return peekIO(port, time);
40 }
41 
42 byte MSXE6Timer::peekIO(word port, EmuTime::param time) const
43 {
44  int counter = reference.getTicksTill(time);
45  return (port & 1) ? ((counter >> 8) & 0xFF) : (counter & 0xFF);
46 }
47 
48 template<typename Archive>
49 void MSXE6Timer::serialize(Archive& ar, unsigned /*version*/)
50 {
51  ar.template serializeBase<MSXDevice>(*this);
52  ar.serialize("reference", reference);
53 }
56 
57 } // namespace openmsx
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
openmsx::Clock::getTicksTill
constexpr unsigned getTicksTill(EmuTime::param e) const
Calculate the number of ticks for this clock until the given time.
Definition: Clock.hh:58
openmsx::MSXE6Timer::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: MSXE6Timer.cc:17
serialize.hh
openmsx::MSXE6Timer::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXE6Timer.cc:12
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::MSXE6Timer::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXE6Timer.cc:42
openmsx::MSXE6Timer::MSXE6Timer
MSXE6Timer(const DeviceConfig &config)
Definition: MSXE6Timer.cc:6
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::MSXE6Timer
Definition: MSXE6Timer.hh:19
openmsx::MSXE6Timer::serialize
void serialize(Archive &ar, unsigned version)
Definition: MSXE6Timer.cc:49
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::Clock::reset
constexpr void reset(EmuTime::param e)
Reset the clock to start ticking at the given time.
Definition: Clock.hh:102
openmsx::Clock::advance
constexpr void advance(EmuTime::param e)
Advance this clock in time until the last tick which is not past the given time.
Definition: Clock.hh:110
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::MSXE6Timer::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: MSXE6Timer.cc:37
MSXE6Timer.hh