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 "openmsx.hh"
12 #include <array>
13 
14 namespace openmsx {
15 
16 class Scheduler;
17 class ClockPinListener;
18 
19 class Counter {
20 public:
21  Counter(Scheduler& scheduler, ClockPinListener* listener,
22  EmuTime::param time);
23  void reset(EmuTime::param time);
24  [[nodiscard]] byte readIO(EmuTime::param time);
25  [[nodiscard]] byte peekIO(EmuTime::param time) const;
26  void writeIO(byte value, EmuTime::param time);
27  void setGateStatus(bool status, EmuTime::param time);
28  void writeControlWord(byte 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 ByteOrder {LOW, HIGH};
37 
38 private:
39  static constexpr byte WRT_FRMT = 0x30;
40  static constexpr byte WF_LATCH = 0x00;
41  static constexpr byte WF_LOW = 0x10;
42  static constexpr byte WF_HIGH = 0x20;
43  static constexpr byte WF_BOTH = 0x30;
44  static constexpr byte CNTR_MODE = 0x0E;
45  static constexpr byte CNTR_M0 = 0x00;
46  static constexpr byte CNTR_M1 = 0x02;
47  static constexpr byte CNTR_M2 = 0x04;
48  static constexpr byte CNTR_M3 = 0x06;
49  static constexpr byte CNTR_M4 = 0x08;
50  static constexpr byte CNTR_M5 = 0x0A;
51  static constexpr byte CNTR_M2_ = 0x0C;
52  static constexpr byte CNTR_M3_ = 0x0E;
53 
54  void writeLoad(word value, EmuTime::param time);
55  void advance(EmuTime::param time);
56 
57 private:
58  ClockPin clock;
59  ClockPin output;
60  EmuTime currentTime;
61  int counter;
62  word latchedCounter, counterLoad;
63  byte control, latchedControl;
64  bool ltchCtrl, ltchCntr;
65  ByteOrder readOrder, writeOrder;
66  byte writeLatch;
67  bool gate;
68  bool active, triggered, counting;
69 
70  friend class I8254;
71 };
72 
73 class I8254
74 {
75 public:
76  I8254(Scheduler& scheduler, ClockPinListener* output0,
77  ClockPinListener* output1, ClockPinListener* output2,
78  EmuTime::param time);
79 
80  void reset(EmuTime::param time);
81  [[nodiscard]] byte readIO(word port, EmuTime::param time);
82  [[nodiscard]] byte peekIO(word port, EmuTime::param time) const;
83  void writeIO(word port, byte value, EmuTime::param time);
84 
85  void setGate(unsigned cntr, bool status, EmuTime::param time);
86  [[nodiscard]] ClockPin& getClockPin(unsigned cntr);
87  [[nodiscard]] ClockPin& getOutputPin(unsigned cntr);
88 
89  template<typename Archive>
90  void serialize(Archive& ar, unsigned version);
91 
92 private:
93  void readBackHelper(byte value, unsigned cntr, EmuTime::param time);
94 
95 private:
96  std::array<Counter, 3> counter;
97 };
98 
99 } // namespace openmsx
100 
101 #endif
void latchStatus(EmuTime::param time)
Definition: I8254.cc:300
void serialize(Archive &ar, unsigned version)
Definition: I8254.cc:463
void reset(EmuTime::param time)
Definition: I8254.cc:141
void latchCounter(EmuTime::param time)
Definition: I8254.cc:310
byte peekIO(EmuTime::param time) const
Definition: I8254.cc:190
byte readIO(EmuTime::param time)
Definition: I8254.cc:159
void writeIO(byte value, EmuTime::param time)
Definition: I8254.cc:217
void writeControlWord(byte value, EmuTime::param time)
Definition: I8254.cc:269
void setGateStatus(bool status, EmuTime::param time)
Definition: I8254.cc:320
Counter(Scheduler &scheduler, ClockPinListener *listener, EmuTime::param time)
Definition: I8254.cc:130
void reset(EmuTime::param time)
Definition: I8254.cc:34
byte peekIO(word port, EmuTime::param time) const
Definition: I8254.cc:54
byte readIO(word port, EmuTime::param time)
Definition: I8254.cc:41
ClockPin & getClockPin(unsigned cntr)
Definition: I8254.cc:115
I8254(Scheduler &scheduler, ClockPinListener *output0, ClockPinListener *output1, ClockPinListener *output2, EmuTime::param time)
Definition: I8254.cc:22
void serialize(Archive &ar, unsigned version)
Definition: I8254.cc:485
void setGate(unsigned cntr, bool status, EmuTime::param time)
Definition: I8254.cc:109
void writeIO(word port, byte value, EmuTime::param time)
Definition: I8254.cc:67
ClockPin & getOutputPin(unsigned cntr)
Definition: I8254.cc:121
This file implemented 3 utility functions:
Definition: Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29