openMSX
MSXE6Timer.cc
Go to the documentation of this file.
1#include "MSXE6Timer.hh"
2#include "serialize.hh"
3
4namespace openmsx {
5
7 : MSXDevice(config)
8 , reference(getCurrentTime())
9{
10}
11
12void MSXE6Timer::reset(EmuTime::param time)
13{
14 reference.reset(time);
15}
16
17void 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
37byte MSXE6Timer::readIO(word port, EmuTime::param time)
38{
39 return peekIO(port, time);
40}
41
42byte MSXE6Timer::peekIO(word port, EmuTime::param time) const
43{
44 auto counter = reference.getTicksTill(time);
45 return (port & 1) ? ((counter >> 8) & 0xFF) : (counter & 0xFF);
46}
47
48template<typename Archive>
49void MSXE6Timer::serialize(Archive& ar, unsigned /*version*/)
50{
51 ar.template serializeBase<MSXDevice>(*this);
52 ar.serialize("reference", reference);
53}
56
57} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:356
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:36
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition MSXE6Timer.cc:42
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
MSXE6Timer(const DeviceConfig &config)
Definition MSXE6Timer.cc:6
void serialize(Archive &ar, unsigned version)
Definition MSXE6Timer.cc:49
void reset(EmuTime::param time) override
This method is called on reset.
Definition MSXE6Timer.cc:12
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
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)