|
|
1.1 root 1: /*
2: * IEvent mouse hack
3: *
4: * Compile with DCC
5: *
6: * Copyright 1997 Bernd Schmidt
7: */
8:
9: #include <stdio.h>
10:
11: #include <exec/devices.h>
12: #include <exec/interrupts.h>
13: #include <exec/nodes.h>
14: #include <exec/io.h>
15: #include <exec/memory.h>
16: #include <intuition/intuitionbase.h>
17: #include <intuition/preferences.h>
18: #include <devices/input.h>
19: #include <devices/inputevent.h>
20: #include <devices/timer.h>
21: #include <hardware/intbits.h>
22: #include <clib/alib_protos.h>
23: #include <clib/exec_protos.h>
24:
25: int (*calltrap)(__d0 int) = 0xF0FF70;
26:
27: extern void mousehackint(void);
28:
29: struct {
30: ULONG mx;
31: ULONG my;
32: ULONG sigbit;
33: struct Task *mt;
34: } foo;
35:
36: struct Interrupt myint = {
37: { 0, 0, NT_INTERRUPT, 5, "UAE mouse hack" },
38: &foo,
39: mousehackint
40: };
41:
42: int main(int argc, char **argv)
43: {
44: struct IntuitionBase *ibase;
45: struct InputEvent *iev;
46: struct IOStdReq *ioreq = 0;
47: struct MsgPort *port;
48:
49: struct timerequest *timereq = 0;
50: struct MsgPort *timeport;
51: int oldx = 0, oldy = 0;
52: int i;
53:
54: i = (*calltrap) (0);
55: if (i == 0) {
56: fprintf(stderr, "mousehack not needed for this version of UAE.\n");
57: exit (0);
58: }
59: if (i == -1) {
60: fprintf(stderr, "mousehack already running.\n");
61: exit (5);
62: }
63:
64: i = AllocSignal (-1);
65: if (i < 0)
66: goto fail;
67: foo.sigbit = 1 << i;
68:
69: port = CreatePort(0, 0);
70: timeport = CreatePort (0, 0);
71: if (port)
72: ioreq = CreateStdIO(port);
73:
74: if (timeport)
75: timereq = CreateStdIO(timeport);
76:
77: if (ioreq == 0)
78: goto fail;
79: if (timereq == 0)
80: goto fail;
81:
82: iev = AllocMem (sizeof (struct InputEvent), MEMF_CLEAR + MEMF_PUBLIC);
83: if (iev == 0)
84: goto fail;
85: if (OpenDevice ("input.device", 0, ioreq, 0) != 0)
86: goto fail;
87: if (OpenDevice ("timer.device", 0, timereq, 0) != 0)
88: goto fail;
89:
90: foo.mx = (ULONG)-1;
91: foo.my = (ULONG)-1;
92: foo.mt = FindTask (0);
93: AddIntServer(INTB_VERTB, &myint);
94:
95: ibase = OpenLibrary ("intuition.library", 0);
96: SetTaskPri (foo.mt, 20); /* same as input.device */
97: for (;;) {
98: int newx, newy;
99:
100: Wait (foo.sigbit);
101: ioreq->io_Command = IND_WRITEEVENT;
102: ioreq->io_Length = sizeof (struct InputEvent);
103: ioreq->io_Data = iev;
104: ioreq->io_Flags = IOF_QUICK;
105: iev->ie_Class = IECLASS_POINTERPOS;
106: iev->ie_SubClass = 0;
107: iev->ie_Code = 0;
108: iev->ie_Qualifier = 0;
109: #if 0
110: newx = (*calltrap) (1);
111: newy = (*calltrap) (2);
112:
113: if (oldy != newy || oldx != newx)
114: #endif
115: {
116: timereq->tr_node.io_Flags = IOF_QUICK;
117: timereq->tr_node.io_Command = TR_GETSYSTIME;
118: DoIO (timereq);
119: iev->ie_TimeStamp = timereq->tr_time;
120: /* Those are signed, so I hope negative values are OK... */
121: /* I wonder why I have to multiply those by 2... but it works,
122: * at least for me. */
123: iev->ie_position.ie_xy.ie_x = foo.mx - ibase->ViewLord.DxOffset*2;
124: iev->ie_position.ie_xy.ie_y = foo.my - ibase->ViewLord.DyOffset*2;
125:
126: oldx = newx;
127: oldy = newy;
128: DoIO(ioreq);
129: }
130: #if 0
131: timereq->tr_node.io_Flags = IOF_QUICK;
132: timereq->tr_time.tv_secs = 0;
133: timereq->tr_time.tv_micro = 20000;
134: timereq->tr_node.io_Command = TR_ADDREQUEST;
135: DoIO(timereq);
136: #endif
137: }
138: fail:
139: fprintf (stderr, "Couldn't start mousehack (that's bad!)\n");
140: exit (5);
141: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.