2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
49 // Extra control stuff
51 // #include "cyberimp.h"
54 //##int joydefs_calibrate_flag = 0;
55 int joydefs_max_joysticks = 0;
56 int joydefs_num_joysticks = 0;
57 int Joystick_calibrating = 0;
60 extern int WriteConfigFile();
61 extern void kconfig_set_fcs_button(int btn, int button);
64 WinJoystickDesc WinJoyDesc;
67 // Calibration and Menus because of automatic joystick detection
68 // and 6 axis' (XYZ-RUV)
70 extern ubyte default_kconfig_settings[][MAX_CONTROLS];
73 void win95_autodetect_joystick()
77 // Set default windows joystick settings.
79 joyGetDevCaps(JOYSTICKID1, &jc, sizeof(jc));
82 default_kconfig_settings[CONTROL_WINJOYSTICK][1] = 0xff;
83 default_kconfig_settings[CONTROL_WINJOYSTICK][4] = 0xff;
84 default_kconfig_settings[CONTROL_WINJOYSTICK][26] = 0xff;
86 default_kconfig_settings[CONTROL_WINJOYSTICK][0] = 0x0;
87 if (jc.wMaxButtons > 1)
88 default_kconfig_settings[CONTROL_WINJOYSTICK][1] = 0x1;
89 if (jc.wMaxButtons > 2)
90 default_kconfig_settings[CONTROL_WINJOYSTICK][4] = 0x2;
91 if (jc.wMaxButtons > 3)
92 default_kconfig_settings[CONTROL_WINJOYSTICK][26] = 0x3;
95 default_kconfig_settings[CONTROL_WINJOYSTICK][6] = 0xff;
96 default_kconfig_settings[CONTROL_WINJOYSTICK][7] = 0xff;
97 default_kconfig_settings[CONTROL_WINJOYSTICK][8] = 0xff;
98 default_kconfig_settings[CONTROL_WINJOYSTICK][9] = 0xff;
100 if (jc.wCaps & JOYCAPS_HASPOV) {
101 default_kconfig_settings[CONTROL_WINJOYSTICK][6] = 0x10;
102 default_kconfig_settings[CONTROL_WINJOYSTICK][7] = 0x12;
103 default_kconfig_settings[CONTROL_WINJOYSTICK][8] = 0x13;
104 default_kconfig_settings[CONTROL_WINJOYSTICK][9] = 0x11;
107 // Do Z-Axis (Throttle)
109 // Do rudder? (R-AXIS)
114 int win95_controls_init()
119 if (FindArg("-SpecialDevice")) spjoy = 1;
121 joydefs_max_joysticks = joy_init(0,spjoy);
122 if (!joy95_init_stick(1, spjoy)) return 0;
124 //@@ for (i = 2; i <= joydefs_max_joysticks; i++)
125 //@@ if (!joy95_init_stick(i,0)) {
126 //@@ joydefs_max_joysticks = i-1;
130 joy_handler_win(0,0,0,0);
131 win95_autodetect_joystick();
145 void dump_axis_vals(int *t_vals)
147 mprintf_at((0, 2, 32, "X:%6d\n", t_vals[0]));
148 mprintf_at((0, 3, 32, "Y:%6d\n", t_vals[1]));
149 mprintf_at((0, 4, 32, "Z:%6d\n", t_vals[2]));
150 mprintf_at((0, 5, 32, "R:%6d\n", t_vals[4]));
151 mprintf_at((0, 6, 32, "U:%6d\n", t_vals[5]));
152 mprintf_at((0, 7, 32, "V:%6d\n", t_vals[6]));
156 // MAIN CALIBRATION ROUTINES
157 // ----------------------------------------------------------------------------
159 void joydefs_calibrate(void)
164 PROCESS_INFORMATION pi;
170 Joystick_calibrating = 1;
172 if (GRMODEINFO(modex)) {
173 old_mode = Screen_mode;
174 set_screen_mode(SCREEN_MENU);
177 apply_modified_palette();
180 gr_palette_load(gr_palette);
182 // Call calibration Applet
183 joy95_get_name(JOYSTICKID1, oldname, 79);
185 logentry("Closing joystick for control panel init.\n");
186 joy_close(); // Close down joystick polling
188 memset(&si, 0, sizeof(si));
190 si.dwFlags = STARTF_USESHOWWINDOW;
191 si.wShowWindow = SW_SHOW;
193 flag = CreateProcess(
195 "rundll32.exe shell32.dll,Control_RunDLL joy.cpl",
197 FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL,
200 nm_messagebox( NULL, 1, TXT_OK, "UNABLE TO INITIATE\nJOYSTICK CONTROL PANEL");
203 dwval = WaitForInputIdle(pi.hProcess, INFINITE);
204 mprintf((1, "JOY.CPL initiated?\n"));
205 WinDelayIdle(); // Clear out messages.
207 while (WaitForSingleObject(pi.hProcess, 0) != WAIT_OBJECT_0)
209 if (multi_menu_poll()==-1) {
210 TerminateProcess(pi.hProcess,0);
212 CloseHandle(pi.hThread);
213 CloseHandle(pi.hProcess);
218 mprintf((1, "JOY.CPL process finished?\n"));
219 ShowWindow(_hAppWnd, SW_MAXIMIZE);
221 SetForegroundWindow(_hAppWnd);
223 _RedrawScreen = FALSE;
226 if (win95_controls_init()) // Reinitializing joystick polling.
227 logentry("Reinitialized joystick with new settings.\n");
229 logentry("Failed to reinitialize joystick.\n");
231 // Set kconfig settings to updated vals.
232 joy95_get_name(JOYSTICKID1, name, 79);
234 if (Config_control_type == CONTROL_WINJOYSTICK) {
235 if (strcmp(name, oldname)) {
236 for (j=0; j<MAX_CONTROLS; j++ )
237 kconfig_settings[CONTROL_WINJOYSTICK][j] = default_kconfig_settings[CONTROL_WINJOYSTICK][j];
242 //@@ joydefs_calibrate2();
248 if (old_mode != -1) {
249 set_screen_mode(old_mode);
252 Joystick_calibrating = 0;
256 //@@// We should make our own windowed calibrator
257 //@@void joydefs_calibrate2()
260 //@@ char calmsg[6][32];
262 //@@ int org_axis_min[7];
263 //@@ int org_axis_center[7];
264 //@@ int org_axis_max[7];
266 //@@ int axis_min[7] = { 0, 0, 0, 0, 0, 0, 0 };
267 //@@ int axis_cen[7] = { 0, 0, 0, 0, 0, 0, 0 };
268 //@@ int axis_max[7] = { 0, 0, 0, 0, 0, 0, 0 };
275 //@@ int nsticks = 0;
277 //@@// Get Current Calibration stuff
278 //@@ joydefs_calibrate_flag = 0;
280 //@@ joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max);
284 //@@ masks = joystick_read_raw_axis( JOY_ALL_AXIS+JOY_EXT_AXIS, t_vals );
286 //@@ if (!joy_present) {
287 //@@ nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
291 //@@ masks = joy_get_present_mask();
295 //@@ res = joy_calibrate_xy(&axis_min[0], &axis_cen[0], &axis_max[0],
296 //@@ &axis_min[1], &axis_cen[1], &axis_max[1]);
299 //@@ joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
303 //@@ strcpy(calmsg[0], "MOVE JOYSTICK UNTIL BAR REACHES");
304 //@@ strcpy(calmsg[1], "TOP AND PRESS BUTTON");
305 //@@ strcpy(calmsg[2], "MOVE JOYSTICK UNTIL BAR REACHES");
306 //@@ strcpy(calmsg[3], "BOTTOM AND PRESS BUTTON");
307 //@@ strcpy(calmsg[4], "RELEASE JOYSTICK");
308 //@@ strcpy(calmsg[5], "AND PRESS BUTTON");
310 //@@ mprintf((0, "Masks: %x\n", masks));
312 //@@ if (masks&JOY_1_Z_AXIS) {
313 //@@ res = joy_calibrate_bar(2, "CALIBRATE Z-AXIS", calmsg,
314 //@@ &axis_min[2], &axis_cen[2], &axis_max[2]);
316 //@@ joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
321 //@@ if (masks&JOY_1_R_AXIS) {
322 //@@ res = joy_calibrate_bar(4, "CALIBRATE RUDDER", calmsg,
323 //@@ &axis_min[4], &axis_cen[4], &axis_max[4]);
325 //@@ joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
330 //@@ if (masks&JOY_1_U_AXIS) {
331 //@@ res = joy_calibrate_bar(5, "CALIBRATE U-AXIS", calmsg,
332 //@@ &axis_min[5], &axis_cen[5], &axis_max[5]);
334 //@@ joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
339 //@@ if (masks&JOY_1_V_AXIS) {
340 //@@ res = joy_calibrate_bar(6, "CALIBRATE V-AXIS", calmsg,
341 //@@ &axis_min[6], &axis_cen[6], &axis_max[6]);
343 //@@ joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
349 //@@ joy_set_cal_vals(axis_min, axis_cen, axis_max);
351 //@@ WriteConfigFile();
355 // Joydefs button detection
356 // This function will do Windows Joystick Button stuff
357 // may emulate Thrustmaster FCS, Flightstick Pro, etc.
359 int joydefsw_do_button()
365 joystick_read_raw_axis(JOY_ALL_AXIS, axis);
367 switch (Config_control_type)
369 case CONTROL_WINJOYSTICK:
370 code = joydefsw_do_winjoybutton(axis);
374 // Get standard buttons
375 for (i=0; i<16; i++ ) {
376 if ( joy_get_button_state(i) )
384 int joydefsw_do_winjoybutton(int *axis)
386 // Do POV detection first. We should use the same
387 // procedure as the DOS version so that we can emulate the
388 // Thrustmaster selections (to keep Player files the same between
389 // versions. (19,15,11,7,0)
392 if (axis[3] == JOY_POVBACKWARD)
394 else if (axis[3] == JOY_POVFORWARD)
396 else if (axis[3] == JOY_POVLEFT)
398 else if (axis[3] == JOY_POVRIGHT)
400 else if (axis[3] == JOY_POVCENTERED)
403 kconfig_set_fcs_button(19,button);
404 kconfig_set_fcs_button(18,button);
405 kconfig_set_fcs_button(17,button);
406 kconfig_set_fcs_button(16, button);
408 if (button == 0) button = 255;
416 // We want to keep the config files the same for the Windows/DOS
417 // versions. But we also autodetect joystick stuff.
418 // Find some way to keep this easier than the DOS version without screwing
419 // up configuration files.
421 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
424 int oc_type = Config_control_type;
430 if (items[0].value) Config_control_type = CONTROL_NONE;
431 else if (items[1].value) Config_control_type = CONTROL_MOUSE;
432 else if (items[2].value) Config_control_type = CONTROL_WINJOYSTICK;
434 //@@ if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) ) {
435 //@@ nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
438 if (oc_type != Config_control_type) {
439 //##switch (Config_control_type) {
440 //## case CONTROL_WINJOYSTICK:
441 //## joydefs_calibrate_flag = 1;
448 extern ubyte kc_use_external_control;
449 extern ubyte kc_enable_external_control;
450 extern ubyte *kc_external_name;
452 void joydefs_config()
454 int i, old_masks, masks,nitems;
459 int no_joystick_option = 0;
461 //##joydefs_calibrate_flag = 0;
463 joy95_get_name(JOYSTICKID1, xtext, 127);
464 if (!strcmpi(xtext, "NO JOYSTICK DETECTED") && (Config_control_type == CONTROL_WINJOYSTICK)) {
465 Config_control_type = CONTROL_NONE;
466 no_joystick_option = 1;
468 else no_joystick_option = 0;
469 nm_wrap_text(joytext, xtext, 20);
473 m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
474 m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(5); m[1].value = 0; m[1].group = 0;
476 if (no_joystick_option) {
477 m[2].type = NM_TYPE_TEXT; m[2].text = joytext; m[2].value = 0; m[2].group = 0;
479 m[2].type = NM_TYPE_RADIO; m[2].text = joytext; m[2].value = 0; m[2].group = 0;
482 m[3].type = NM_TYPE_TEXT; m[3].text="";
483 m[4].type = NM_TYPE_MENU; m[4].text=TXT_CUST_ABOVE;
484 m[5].type = NM_TYPE_TEXT; m[5].text="";
485 m[6].type = NM_TYPE_SLIDER; m[6].text=TXT_JOYS_SENSITIVITY; m[6].value=Config_joystick_sensitivity; m[6].min_value =0; m[6].max_value = 8;
486 m[7].type = NM_TYPE_TEXT; m[7].text="";
487 m[8].type = NM_TYPE_TEXT; m[8].text="";
488 m[9].type = NM_TYPE_MENU; m[9].text=TXT_CUST_KEYBOARD;
490 if (Config_control_type == CONTROL_WINJOYSTICK) m[2].value = 1;
491 else if (Config_control_type == CONTROL_MOUSE) m[1].value = 1;
492 else if (Config_control_type == CONTROL_NONE) m[0].value = 1;
495 i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
496 Config_joystick_sensitivity = m[6].value;
501 for (i=0; i<4; i++ ) {
502 if (kconfig_is_axes_used(i))
505 if ( Config_control_type==0 )
506 Config_control_type=0;
507 else if ( Config_control_type < CONTROL_MOUSE )
508 kconfig(1, CONTROL_TEXT(Config_control_type) );
509 else if ( Config_control_type == CONTROL_WINJOYSTICK)
510 kconfig(3, CONTROL_TEXT(Config_control_type) );
512 kconfig(2, CONTROL_TEXT(Config_control_type) );
515 for (i=0; i<4; i++ ) {
516 if (kconfig_is_axes_used(i))
520 //##switch (Config_control_type) {
521 //##case CONTROL_WINJOYSTICK:
523 //## for (i=0; i<4; i++ ) {
524 //## if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
525 //## joydefs_calibrate_flag = 1;
533 kconfig(0, TXT_KEYBOARD);
539 // No calibration under new system where control panel does this.
540 // switch (Config_control_type) {
541 // case CONTROL_WINJOYSTICK:
542 // if ( joydefs_calibrate_flag )
543 // joydefs_calibrate();
549 // Extended joystick menu
550 // ----------------------------------------------------------------------------
551 void joydefsw_win_joyselect(char *title)
558 if (newmenu_filelist("Windows 95 Controls", "*.joy", filename)) {
559 fp = fopen(filename, "rb");
561 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Unable to find control file");
562 strcpy(title, "Windows 95 Custom");
567 if (!fread(&axis, sizeof(ubyte), 1, fp)) {
568 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Illegal or corrupt control file");
569 strcpy(title, "Windows 95 Custom");
575 if (fread(kconfig_settings[CONTROL_WINJOYSTICK],
576 sizeof(kconfig_settings[CONTROL_WINJOYSTICK]),
578 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Illegal or corrupt control file");
579 strcpy(title, "Windows 95 Custom");
585 token = strtok(filename, ".");
586 strcpy(title, token);
588 else strcpy(title, "Windows 95 Custom");