openMSX
MSXHiResTimer.cc
Go to the documentation of this file.
1#include "MSXHiResTimer.hh"
2#include "serialize.hh"
3
4namespace openmsx {
5
7 : MSXDevice(config)
8 , reference(getCurrentTime())
9{
11}
12
13void MSXHiResTimer::reset(EmuTime::param time)
14{
15 reference.reset(time);
16 latchedValue = 0;
17}
18
19void MSXHiResTimer::writeIO(word /*port*/, byte /*value*/, EmuTime::param time)
20{
21 // write to any port will reset the counter
22 reference.advance(time);
23}
24
25byte MSXHiResTimer::readIO(word port, EmuTime::param time)
26{
27 if ((port & 3) == 0) {
28 // reading port 0 will latch the current counter value
29 latchedValue = reference.getTicksTill(time);
30 }
31 // reading port {0, 1, 2, 3} will read bits {0-7, 8-15, 16-23, 24-32}
32 // of the counter
33 return latchedValue >> (8 * (port & 3));
34}
35
36byte MSXHiResTimer::peekIO(word port, EmuTime::param time) const
37{
38 unsigned tmp = (port & 3) ? latchedValue : reference.getTicksTill(time);
39 return tmp >> (8 * (port & 3));
40}
41
42template<typename Archive>
43void MSXHiResTimer::serialize(Archive& ar, unsigned /*version*/)
44{
45 ar.template serializeBase<MSXDevice>(*this);
46 ar.serialize("reference", reference,
47 "latchedValue", latchedValue);
48}
51
52} // namespace openmsx
constexpr void reset(EmuTime::param e)
Reset the clock to start ticking at the given time.
Definition: Clock.hh:102
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
constexpr unsigned getTicksTill(EmuTime::param e) const
Calculate the number of ticks for this clock until the given time.
Definition: Clock.hh:58
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:34
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:125
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
MSXHiResTimer(const DeviceConfig &config)
Definition: MSXHiResTimer.cc:6
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.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
void serialize(Archive &ar, unsigned version)
void reset(EmuTime::param time) override
This method is called on reset.
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1021