OXYGENHUB
◆ main openmsx / src / MSXPPI.hh
2.5 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
// This class implements the PPI (8255)
2
//
3
//   PPI    MSX-I/O  Direction  MSX-Function
4
//  PortA    0xA8      Out     Memory primary slot register
5
//  PortB    0xA9      In      Keyboard column inputs
6
//  PortC    0xAA      Out     Keyboard row select / CAPS / CASo / CASm / SND
7
//  Control  0xAB     In/Out   Mode select for PPI
8
//
9
//  Direction indicates the direction normally used on MSX.
10
//  Reading from an output port returns the last written byte.
11
//  Writing to an input port has no immediate effect.
12
//
13
//  PortA combined with upper half of PortC form groupA
14
//  PortB               lower                    groupB
15
//  GroupA can be in programmed in 3 modes
16
//   - basic input/output
17
//   - strobed input/output
18
//   - bidirectional
19
//  GroupB can only use the first two modes.
20
//  Only the first mode is used on MSX, only this mode is implemented yet.
21
//
22
//  for more detail see
23
//    http://w3.qahwah.net/joost/openMSX/8255.pdf
24
25
#ifndef MSXPPI_HH
26
#define MSXPPI_HH
27
28
#include "I8255.hh"
29
#include "I8255Interface.hh"
30
#include "KeyClick.hh"
31
#include "Keyboard.hh"
32
#include "MSXDevice.hh"
33
34
namespace openmsx {
35
36
class CassettePortInterface;
37
class RenShaTurbo;
38
39
class MSXPPI final : public MSXDevice, public I8255Interface
40
{
41
public:
42
	explicit MSXPPI(const DeviceConfig& config);
43
	~MSXPPI() override;
44
45
	void reset(EmuTime time) override;
46
	void powerDown(EmuTime time) override;
47
	[[nodiscard]] uint8_t readIO(uint16_t port, EmuTime time) override;
48
	[[nodiscard]] uint8_t peekIO(uint16_t port, EmuTime time) const override;
49
	void writeIO(uint16_t port, uint8_t value, EmuTime time) override;
50
51
	template<typename Archive>
52
	void serialize(Archive& ar, unsigned version);
53
54
private:
55
	// I8255Interface
56
	[[nodiscard]] uint8_t readA (EmuTime time) override;
57
	[[nodiscard]] uint8_t readB (EmuTime time) override;
58
	[[nodiscard]] uint4_t readC0(EmuTime time) override;
59
	[[nodiscard]] uint4_t readC1(EmuTime time) override;
60
	[[nodiscard]] uint8_t peekA (EmuTime time) const override;
61
	[[nodiscard]] uint8_t peekB (EmuTime time) const override;
62
	[[nodiscard]] uint4_t peekC0(EmuTime time) const override;
63
	[[nodiscard]] uint4_t peekC1(EmuTime time) const override;
64
	void writeA (uint8_t value, EmuTime time) override;
65
	void writeB (uint8_t value, EmuTime time) override;
66
	void writeC0(uint4_t value, EmuTime time) override;
67
	void writeC1(uint4_t value, EmuTime time) override;
68
69
private:
70
	CassettePortInterface& cassettePort;
71
	RenShaTurbo& renshaTurbo;
72
	I8255 i8255;
73
	KeyClick click;
74
	Keyboard keyboard;
75
	uint4_t prevBits = 15;
76
	uint4_t selectedRow = 0;
77
};
78
79
} // namespace openmsx
80
81
#endif