2 *----------------------------------------------------------------------------
3 * Rocket Launcher Tool for Poseidon
4 *----------------------------------------------------------------------------
5 * By Chris Hodges <chrisly@platon42.de>
10 #include <proto/dos.h>
11 #include <proto/exec.h>
12 #include <proto/poseidon.h>
13 #include <proto/intuition.h>
14 #include <proto/graphics.h>
15 #include <proto/diskfont.h>
16 #include <proto/lowlevel.h>
18 #include <libraries/lowlevel.h>
19 #include <devices/usb_hid.h>
21 #include "RocketTool.h"
30 #define ARGS_JOYPORT 6
34 const char RocketTool_prgname
[] = "RocketTool";
35 static const char *template = "LEFT/S,RIGHT/S,UP/S,DOWN/S,FIRE/S,TIME/N/K,JOYPORT/N/K,UNIT/N/K";
36 const char RocketTool_version
[] = "$VER: RocketTool 1.1 (12.06.09) by Chris Hodges <chrisly@platon42.de>";
37 static IPTR ArgsArray
[ARGS_SIZEOF
];
38 static struct RDArgs
*ArgsHook
= NULL
;
41 struct Library
*LowLevelBase
;
43 AROS_UFP3(void, releasehook
,
44 AROS_UFPA(struct Hook
*, hook
, A0
),
45 AROS_UFPA(APTR
, pab
, A2
),
46 AROS_UFPA(struct NepClassRocket
*, nch
, A1
));
48 struct NepClassRocket
* SetupRocket(void);
49 struct NepClassRocket
* AllocRocket(struct NepClassRocket
*nch
);
50 void FreeRocket(struct NepClassRocket
*nch
);
52 AROS_UFH3(void, releasehook
,
53 AROS_UFHA(struct Hook
*, hook
, A0
),
54 AROS_UFHA(APTR
, pab
, A2
),
55 AROS_UFHA(struct NepClassRocket
*, nch
, A1
))
58 /*psdAddErrorMsg(RETURN_WARN, (STRPTR) prgname,
60 Signal(nch
->nch_Task
, SIGBREAKF_CTRL_C
);
64 struct NepClassRocket
* SetupRocket(void)
66 struct NepClassRocket
*nch
;
67 struct PsdDevice
*pd
= NULL
;
68 struct PsdAppBinding
*pab
;
71 if(ArgsArray
[ARGS_UNIT
])
73 unit
= *((ULONG
*) ArgsArray
[ARGS_UNIT
]);
81 pd
= psdFindDevice(pd
,
85 } while(pd
&& (unit
--));
89 PutStr("No USB Rocket Launcher found!\n");
92 if((nch
= psdAllocVec(sizeof(struct NepClassRocket
))))
95 nch
->nch_ReleaseHook
.h_Entry
= (APTR
) releasehook
;
97 pab
= psdClaimAppBinding(ABA_Device
, pd
,
98 ABA_ReleaseHook
, &nch
->nch_ReleaseHook
,
100 ABA_ForceRelease
, TRUE
,
108 PutStr("Couldn't allocate Rocket Laucher...\n");
110 psdReleaseAppBinding(pab
);
112 PutStr("Couldn't claim binding!\n");
116 PutStr("Hohum...\n");
121 struct NepClassRocket
* AllocRocket(struct NepClassRocket
*nch
)
123 nch
->nch_Task
= FindTask(NULL
);
125 if((nch
->nch_TaskMsgPort
= CreateMsgPort()))
127 nch
->nch_IF0
= psdFindInterface(nch
->nch_Device
, NULL
,
130 nch
->nch_IF1
= psdFindInterface(nch
->nch_Device
, NULL
,
133 if(nch
->nch_IF0
&& nch
->nch_IF1
)
135 if((nch
->nch_EP0Pipe
= psdAllocPipe(nch
->nch_Device
, nch
->nch_TaskMsgPort
, NULL
)))
139 PutStr("Couldn't allocate default pipe\n");
142 PutStr("Couldn't find interfaces\n");
144 DeleteMsgPort(nch
->nch_TaskMsgPort
);
150 void FreeRocket(struct NepClassRocket
*nch
)
154 psdGetAttrs(PGA_DEVICE
, nch
->nch_Device
,
157 psdReleaseAppBinding(pab
);
158 psdFreePipe(nch
->nch_EP0Pipe
);
159 DeleteMsgPort(nch
->nch_TaskMsgPort
);
163 BOOL
SendInit(struct NepClassRocket
*nch
)
165 UBYTE cmd0
[8] = { 0x55, 0x53, 0x42, 0x43, 0x00, 0x00, 0x04, 0x00 };
166 UBYTE cmd1
[8] = { 0x55, 0x53, 0x42, 0x43, 0x00, 0x40, 0x02, 0x00 };
169 psdPipeSetup(nch
->nch_EP0Pipe
, URTF_OUT
|URTF_CLASS
|URTF_INTERFACE
, UHR_SET_REPORT
, 0x0200, 1);
170 ioerr
= psdDoPipe(nch
->nch_EP0Pipe
, cmd0
, 8);
173 Printf("Error sending init cmd 0: %s (%ld)\n",
174 psdNumToStr(NTS_IOERR
, ioerr
, "unknown"), ioerr
);
177 psdPipeSetup(nch
->nch_EP0Pipe
, URTF_OUT
|URTF_CLASS
|URTF_INTERFACE
, UHR_SET_REPORT
, 0x0200, 1);
178 ioerr
= psdDoPipe(nch
->nch_EP0Pipe
, cmd1
, 8);
181 Printf("Error sending init cmd 1: %s (%ld)\n",
182 psdNumToStr(NTS_IOERR
, ioerr
, "unknown"), ioerr
);
188 BOOL
SendCommand(struct NepClassRocket
*nch
)
192 psdPipeSetup(nch
->nch_EP0Pipe
, URTF_OUT
|URTF_CLASS
|URTF_INTERFACE
, UHR_SET_REPORT
, 0x0200, 0);
193 ioerr
= psdDoPipe(nch
->nch_EP0Pipe
, nch
->nch_Buf
, 64);
196 Printf("Error sending command: %s (%ld)\n",
197 psdNumToStr(NTS_IOERR
, ioerr
, "unknown"), ioerr
);
203 /**************************************************************************/
205 int main(int argc
, char *argv
[])
207 struct NepClassRocket
*nch
;
208 ULONG ret
= RETURN_OK
;
211 if(!(ArgsHook
= ReadArgs(template, ArgsArray
, NULL
)))
213 PutStr("Wrong arguments!\n");
216 ps
= OpenLibrary("poseidon.library", 4);
222 if(!(nch
= SetupRocket()))
226 return(RETURN_ERROR
);
228 if(ArgsArray
[ARGS_JOYPORT
])
231 joyport
= *((ULONG
*) ArgsArray
[ARGS_JOYPORT
]);
232 if((LowLevelBase
= OpenLibrary("lowlevel.library", 1)))
235 Printf("Interactive mode using joyport %ld. Press Ctrl-C to abort.\n", joyport
);
237 // FIXME this seems to be not implemented in AROS yet
238 //SetJoyPortAttrs(joyport, SJA_Reinitialize, TRUE, TAG_END);
239 //SetJoyPortAttrs(joyport, SJA_Type, SJA_TYPE_AUTOSENSE, TAG_END);
242 if(SetSignal(0,0) & SIGBREAKF_CTRL_C
)
246 val
= ReadJoyPort(joyport
);
247 if(((val
& JP_TYPE_MASK
) == JP_TYPE_JOYSTK
) || ((val
& JP_TYPE_MASK
) == JP_TYPE_GAMECTLR
))
249 nch
->nch_Buf
[1] = (val
& JPF_JOY_LEFT
) ? 1 : 0;
250 nch
->nch_Buf
[2] = (val
& JPF_JOY_RIGHT
) ? 1 : 0;
251 nch
->nch_Buf
[3] = (val
& JPF_JOY_UP
) ? 1 : 0;
252 nch
->nch_Buf
[4] = (val
& JPF_JOY_DOWN
) ? 1 : 0;
253 nch
->nch_Buf
[5] = (val
& JPF_BUTTON_RED
) ? 1 : 0;
264 //SetJoyPortAttrs(1, SJA_Reinitialize, TRUE, TAG_END);
266 CloseLibrary(LowLevelBase
);
271 if(ArgsArray
[ARGS_LEFT
])
275 if(ArgsArray
[ARGS_RIGHT
])
279 if(ArgsArray
[ARGS_UP
])
283 if(ArgsArray
[ARGS_DOWN
])
287 if(ArgsArray
[ARGS_FIRE
])
291 nch
->nch_Buf
[6] = 0x08;
292 nch
->nch_Buf
[7] = 0x08;
296 if(ArgsArray
[ARGS_TIME
])
298 Delay(*((ULONG
*) ArgsArray
[ARGS_TIME
]));
299 memset(nch
->nch_Buf
, 0x00, 6);