blob: 95f8f9db4629f43130ea9dcda8c569b1e287a750 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
* ========================================================
*
* hCore
* Copyright XPX Corp, all rights reserved.
*
* ========================================================
*/
#pragma once
#include <NewKit/Defines.hpp>
#include <ArchKit/Arch.hpp>
#include <NewKit/Array.hpp>
#include <NewKit/Ref.hpp>
namespace hCore
{
template<SizeT Sz>
class IOArray final
{
public:
IOArray() = delete;
IOArray(nullPtr) = delete;
explicit IOArray(Array <UShort, Sz> &ports) : m_Ports(ports) {}
~IOArray() {}
IOArray &operator=(const IOArray &) = default;
IOArray(const IOArray &) = default;
operator bool() {
return !m_Ports.Empty();
}
public:
template<typename T>
T In(SizeT index) {
switch (sizeof(T)) {
#ifdef __x86_64__
case 4:
return HAL::in32(m_Ports[index].Leak());
case 2:
return HAL::in16(m_Ports[index].Leak());
case 1:
return HAL::in8(m_Ports[index].Leak());
#endif
default:
return 0xFFFF;
}
}
template<typename T>
void Out(SizeT index, T value) {
switch (sizeof(T)) {
#ifdef __x86_64__
case 4:
HAL::out32(m_Ports[index].Leak(), value);
case 2:
HAL::out16(m_Ports[index].Leak(), value);
case 1:
HAL::out8(m_Ports[index].Leak(), value);
#endif
default:
break;
}
}
private:
Array <UShort, Sz> m_Ports;
};
using IOArray16 = IOArray<16>;
} // namespace hCore
|