OXYGENHUB
◆ main openmsx / src / MSXDeviceSwitch.hh
2.3 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef MSXDEVICESWITCH_HH
2
#define MSXDEVICESWITCH_HH
3
4
#include "MSXDevice.hh"
5
#include <array>
6
7
namespace openmsx {
8
9
/**
10
 * The MSX2 Hardware Specification says ports 0x41-0x4F are Switched I/O ports.
11
 * Output of a ID value to port 0x40 selects a specific I/O device and connects
12
 * it to the CPU.
13
 *
14
 * It is possible to give numbers between 0 and 255 as a device number.
15
 * However, when reading the device number, the complement is given, so 0 and
16
 * 255 are not used. ID numbers between 1 and 127 are manufacturers ID number
17
 * as in expanded BIOS call. 128 to 254 are device numbers. As a basic rule,
18
 * those device which are designed specifically for one machine should contain
19
 * the manufacturers company ID while peripheral device which can be used for
20
 * all MSX should have device ID number. Also, Z80 CPU has 16 bit address in
21
 * I/O space so it is recommended to access in 16 bit by decoding the upper 8
22
 * bit for those ID which might be expanded in the future. Especially for
23
 * device which are connected with make ID can expand the address space by 256
24
 * times so it is future proofed.
25
 *
26
 * Maker ID
27
 *    1 ASCII/Microsoft
28
 *    2 Canon
29
 *    3 Casio
30
 *    4 Fujitsu
31
 *    5 General
32
 *    6 Hitachi
33
 *    7 Kyocera
34
 *    8 Matsushita
35
 *    9 Mitsubishi
36
 *   10 NEC
37
 *   11 Nippon Gakki
38
 *   12 JVC
39
 *   13 Philips
40
 *   14 Pioneer
41
 *   15 Sanyo
42
 *   16 Sharp
43
 *   17 SONY
44
 *   18 Spectravideo
45
 *   19 Toshiba
46
 *   20 Mitsumi
47
 *
48
 * Device ID
49
 *  128 Image Scanner (Matsushita)
50
 *  247 Kanji 12x12
51
 *  254 MPS2 (ASCII)
52
 */
53
54
class MSXSwitchedDevice;
55
56
class MSXDeviceSwitch final : public MSXDevice
57
{
58
public:
59
	explicit MSXDeviceSwitch(const DeviceConfig& config);
60
	~MSXDeviceSwitch() override;
61
62
	// (un)register methods for devices
63
	void registerDevice(byte id, MSXSwitchedDevice* device);
64
	void unregisterDevice(byte id);
65
	[[nodiscard]] bool hasRegisteredDevices() const { return count != 0; }
66
67
	void reset(EmuTime time) override;
68
	[[nodiscard]] byte readIO(uint16_t port, EmuTime time) override;
69
	[[nodiscard]] byte peekIO(uint16_t port, EmuTime time) const override;
70
	void writeIO(uint16_t port, byte value, EmuTime time) override;
71
72
	template<typename Archive>
73
	void serialize(Archive& ar, unsigned version);
74
75
private:
76
	std::array<MSXSwitchedDevice*, 256> devices;
77
	unsigned count = 0;
78
	byte selected = 0;
79
};
80
81
} // namespace openmsx
82
83
#endif