openMSX
I8254.hh
Go to the documentation of this file.
1// This class implements the Intel 8254 chip (and 8253)
2//
3// * Only the 8254 is emulated, no surrounding hardware.
4// Use the class I8254Interface to do that.
5
6#ifndef I8254_HH
7#define I8254_HH
8
9#include "ClockPin.hh"
10#include "EmuTime.hh"
11#include <array>
12#include <cstdint>
13
14namespace openmsx {
15
16class Scheduler;
17class ClockPinListener;
18
19class Counter {
20public:
21 Counter(Scheduler& scheduler, ClockPinListener* listener,
22 EmuTime::param time);
23 void reset(EmuTime::param time);
24 [[nodiscard]] uint8_t readIO(EmuTime::param time);
25 [[nodiscard]] uint8_t peekIO(EmuTime::param time) const;
26 void writeIO(uint8_t value, EmuTime::param time);
27 void setGateStatus(bool status, EmuTime::param time);
28 void writeControlWord(uint8_t value, EmuTime::param time);
29 void latchStatus(EmuTime::param time);
30 void latchCounter(EmuTime::param time);
31
32 template<typename Archive>
33 void serialize(Archive& ar, unsigned version);
34
35//private:
36 enum class ByteOrder {LOW, HIGH};
37
38private:
39 static constexpr uint8_t WRT_FRMT = 0x30;
40 static constexpr uint8_t WF_LATCH = 0x00;
41 static constexpr uint8_t WF_LOW = 0x10;
42 static constexpr uint8_t WF_HIGH = 0x20;
43 static constexpr uint8_t WF_BOTH = 0x30;
44 static constexpr uint8_t CNTR_MODE = 0x0E;
45 static constexpr uint8_t CNTR_M0 = 0x00;
46 static constexpr uint8_t CNTR_M1 = 0x02;
47 static constexpr uint8_t CNTR_M2 = 0x04;
48 static constexpr uint8_t CNTR_M3 = 0x06;
49 static constexpr uint8_t CNTR_M4 = 0x08;
50 static constexpr uint8_t CNTR_M5 = 0x0A;
51 static constexpr uint8_t CNTR_M2_ = 0x0C;
52 static constexpr uint8_t CNTR_M3_ = 0x0E;
53
54 void writeLoad(uint16_t value, EmuTime::param time);
55 void advance(EmuTime::param time);
56
57private:
58 ClockPin clock;
59 ClockPin output;
60 EmuTime currentTime;
61 int counter = 0;
62 uint16_t latchedCounter;
63 uint16_t counterLoad = 0;
64 uint8_t control, latchedControl;
65 bool ltchCtrl, ltchCntr;
66 ByteOrder readOrder, writeOrder;
67 uint8_t writeLatch;
68 bool gate = true;
69 bool active, triggered, counting;
70
71 friend class I8254;
72};
73
74class I8254
75{
76public:
77 I8254(Scheduler& scheduler, ClockPinListener* output0,
78 ClockPinListener* output1, ClockPinListener* output2,
79 EmuTime::param time);
80
81 void reset(EmuTime::param time);
82 [[nodiscard]] uint8_t readIO(uint16_t port, EmuTime::param time);
83 [[nodiscard]] uint8_t peekIO(uint16_t port, EmuTime::param time) const;
84 void writeIO(uint16_t port, uint8_t value, EmuTime::param time);
85
86 void setGate(unsigned cntr, bool status, EmuTime::param time);
87 [[nodiscard]] ClockPin& getClockPin(unsigned cntr);
88 [[nodiscard]] ClockPin& getOutputPin(unsigned cntr);
89
90 template<typename Archive>
91 void serialize(Archive& ar, unsigned version);
92
93private:
94 void readBackHelper(uint8_t value, unsigned cntr, EmuTime::param time);
95
96private:
97 std::array<Counter, 3> counter;
98};
99
100} // namespace openmsx
101
102#endif
void latchStatus(EmuTime::param time)
Definition I8254.cc:310
uint8_t peekIO(EmuTime::param time) const
Definition I8254.cc:187
void serialize(Archive &ar, unsigned version)
Definition I8254.cc:471
void reset(EmuTime::param time)
Definition I8254.cc:138
void writeIO(uint8_t value, EmuTime::param time)
Definition I8254.cc:214
uint8_t readIO(EmuTime::param time)
Definition I8254.cc:156
void latchCounter(EmuTime::param time)
Definition I8254.cc:320
void writeControlWord(uint8_t value, EmuTime::param time)
Definition I8254.cc:279
void setGateStatus(bool status, EmuTime::param time)
Definition I8254.cc:330
void reset(EmuTime::param time)
Definition I8254.cc:34
uint8_t peekIO(uint16_t port, EmuTime::param time) const
Definition I8254.cc:54
void writeIO(uint16_t port, uint8_t value, EmuTime::param time)
Definition I8254.cc:67
uint8_t readIO(uint16_t port, EmuTime::param time)
Definition I8254.cc:41
ClockPin & getClockPin(unsigned cntr)
Definition I8254.cc:115
void serialize(Archive &ar, unsigned version)
Definition I8254.cc:493
void setGate(unsigned cntr, bool status, EmuTime::param time)
Definition I8254.cc:109
ClockPin & getOutputPin(unsigned cntr)
Definition I8254.cc:121
This file implemented 3 utility functions:
Definition Autofire.cc:11