forked from b-dmitry1/e86r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ioports.h
72 lines (61 loc) · 1.24 KB
/
ioports.h
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
#ifndef IOPORTS_H
#define IOPORTS_H
#include "stdafx.h"
class SmallBuffer
{
private:
unsigned char m_data[16];
int m_rp, m_wp, m_count;
mutex m_mtx;
public:
SmallBuffer()
{
m_rp = m_wp = m_count = 0;
memset(m_data, 0, sizeof(m_data));
}
int count() const
{
return m_count;
}
int peek()
{
return m_data[m_rp];
}
int get()
{
int res;
if (m_count <= 0)
return -1;
m_mtx.lock();
res = m_data[m_rp++];
m_rp %= sizeof(m_data);
m_count--;
m_mtx.unlock();
return res;
}
void put(unsigned char value)
{
while (m_count > sizeof(m_data))
{
m_wp++;
m_wp %= sizeof(m_data);
m_count--;
}
m_mtx.lock();
m_data[m_wp++] = value;
m_wp %= sizeof(m_data);
m_count++;
m_mtx.unlock();
}
};
extern unsigned char ports[1024];
extern SmallBuffer keybuf;
extern SmallBuffer mousebuf;
void mouseevent(int x, int y, int buttons);
unsigned char portread8(unsigned short port);
unsigned short portread16(unsigned short port);
unsigned int portread32(unsigned short port);
void portwrite8(unsigned short port, unsigned char v);
void portwrite16(unsigned short port, unsigned short v);
void portwrite32(unsigned short port, unsigned int v);
#endif