-
Notifications
You must be signed in to change notification settings - Fork 3
/
mousedriver.c
172 lines (156 loc) · 3.91 KB
/
mousedriver.c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <exec/interrupts.h>
#include <hardware/intbits.h>
#include <devices/input.h>
#include <devices/inputevent.h>
#include <clib/exec_protos.h>
#include <clib/input_protos.h>
#include <clib/dos_protos.h>
#include <dos/dos.h>
#include <stdio.h>
#define NM_WHEEL_UP 0x7A
#define NM_WHEEL_DOWN 0x7B
#define MM_NOTHING 0
#define MM_WHEEL_DOWN 1
#define MM_WHEEL_UP 2
#define MM_MIDDLEMOUSE_DOWN 3
#define MM_MIDDLEMOUSE_UP 4
extern void VertBServer(); /* proto for asm interrupt server */
struct {
UWORD potgo; // 0 0xdff016
UWORD joy0dat; // 2
UBYTE pra; // 4 0xbfe001
UBYTE pad; // 5
ULONG sigbit; // 6
struct Task *task; // 10
APTR potgoResource; // 14
} mousedata;
struct Interrupt vertblankint = {
{ 0, 0, NT_INTERRUPT, 10-10, "Arduino PS/2 mouse adapter" },
&mousedata,
VertBServer
};
void CreateMouseEvents(int t);
int AllocResources();
void FreeResources();
extern struct CIA ciaa, ciab;
struct IOStdReq *InputIO;
struct MsgPort *InputMP;
struct InputEvent *MouseEvent;
struct InputBase *InputBase;
BYTE intsignal;
void main(void)
{
if (AllocResources())
{
mousedata.task = FindTask(0);
mousedata.sigbit = 1 << intsignal;
AddIntServer(INTB_VERTB, &vertblankint);
SetTaskPri(mousedata.task, 20); /* same as input.device */
while (1)
{
ULONG signals = Wait (mousedata.sigbit | SIGBREAKF_CTRL_C);
if (signals & SIGBREAKF_CTRL_C)
{
PutStr("Exiting\n");
break;
}
if (signals & mousedata.sigbit)
{
int code = MM_NOTHING
if (!(mousedata.potgo & 0x400)) code |= MM_WHEEL_DOWN;
if (mousedata.potgo & 0x100) code |= MM_WHEEL_UP;
if (!(mousedata.pra & 0x40)) code |= MM_MIDDLEMOUSE_UP;
CreateMouseEvents(code);
}
}
}
FreeResources();
}
int AllocResources()
{
if (intsignal = AllocSignal (-1))
{
if (InputMP = CreateMsgPort())
{
if (MouseEvent = AllocMem(sizeof(struct InputEvent),MEMF_PUBLIC))
{
if (InputIO = CreateIORequest(InputMP,sizeof(struct IOStdReq)))
{
if (!OpenDevice("input.device",NULL,
(struct IORequest *)InputIO,NULL))
{
InputBase = (struct InputBase *)InputIO->io_Device;
if (mousedata.potgoResource = OpenResource("potgo.resource"))
{
return 1;
}
else
PutStr("Error: Could not open potgo.resource\n");
}
else
PutStr("Error: Could not open input.device\n");
}
else
PutStr("Error: Could not create IORequest\n");
}
else
PutStr("Error: Could not allocate memory for MouseEvent\n");
}
else
PutStr("Error: Could not create message port\n");
}
else
PutStr("Error: Could not allocate signal\n");
return 0;
}
void FreeResources()
{
if (InputIO)
{
CloseDevice((struct IORequest *)InputIO);
DeleteIORequest(InputIO);
}
if (MouseEvent) FreeMem(MouseEvent, sizeof(struct InputEvent));
if (InputMP) DeleteMsgPort(InputMP);
if (intsignal) FreeSignal(intsignal);
RemIntServer(INTB_VERTB, &vertblankint);
}
int down=0;
void CreateMouseEvents(int t)
{
if (t == 0)
{
return;
}
MouseEvent->ie_EventAddress = NULL;
MouseEvent->ie_NextEvent = NULL;
MouseEvent->ie_Class = IECLASS_RAWKEY;
MouseEvent->ie_SubClass = 0;
MouseEvent->ie_Qualifier = PeekQualifier(); //???
switch (t)
{
case MM_WHEEL_DOWN:
MouseEvent->ie_Code = NM_WHEEL_DOWN;
break;
case MM_WHEEL_UP:
MouseEvent->ie_Code = NM_WHEEL_UP;
break;
case MM_MIDDLEMOUSE_DOWN:
MouseEvent->ie_Code = IECODE_MBUTTON;
MouseEvent->ie_Class = IECLASS_RAWMOUSE;
MouseEvent->ie_X = 0;
MouseEvent->ie_Y = 0;
break;
case MM_MIDDLEMOUSE_UP:
MouseEvent->ie_Code = IECODE_LBUTTON|IECODE_UP_PREFIX; // fixme!!!!!
MouseEvent->ie_Class = IECLASS_RAWMOUSE;
MouseEvent->ie_X = 0;
MouseEvent->ie_Y = 0;
break;
}
InputIO->io_Data = (APTR)MouseEvent;
InputIO->io_Length = sizeof(struct InputEvent);
InputIO->io_Command = IND_WRITEEVENT;
// InputIO->io_Flags = IOF_QUICK;
DoIO((struct IORequest *)InputIO);
}