Mail Archives: djgpp/1997/12/23/18:30:24
Hi,
I have altered the example joystick routines that came with allegro
(example 27 I think) to be the following code. I was wondering how I
save my config. The function is:
int save_joystick_data(char *filename);
What I want to do is save the configuration as joy.cfg.
Here is my CODE: (search for the WHAT THE HELL DO I DO... part)
/* joystick.c - Joystick Routine Setup
* A slight alteration to the Allegro example 27 joystick routine.
** Shane Smalldon Dec.23, 1997
*/
#include <stdio.h> /* Need this for keypresses */
#include <allegro.h> /* Allegro libraries are used */
int main()
{
allegro_init(); /* You NEED this to init allegro */
install_keyboard(); /* Loads keyboard routines from allegro */
printf("Joystick Setup Utility.\n");
printf("Press a key to continue. Press ESC to exit now.\n");
clear_keybuf(); /* Simply waits for a keypress or esc.
*/
do {
} while (!keypressed());
if ((readkey()&0xFF) == 27)
exit(0);
printf("\nPlease center the Joystick and press a key.\n");
clear_keybuf(); /* Simply waits for keypress */
do {
} while (!keypressed());
if ((readkey()&0xFF) == 27)
exit(0);
/* We have pleased the user to center the joystick. Now we can
initialise
* all the Joystick routines. You ALWAYS need to call this function
first
*/
joy_type = JOY_TYPE_4BUTTON; /* This is cheating, hehehe. We declare
* the user has a 4 button joy to read
* the 3rd and 4th button. Maybe the
* user doesn't have one, but hey, then
* he won't notice we are cheating ;)
*/
initialise_joystick();
printf("Pull your Joystick to the top left and press a key.\n");
clear_keybuf();
do {
} while (!keypressed());
if ((readkey()&0xFF) == 27)
exit(0);
calibrate_joystick_tl(); /* We calibrate the top left corner */
printf("\nNow take it to the bottom right and press a key again.\n");
clear_keybuf();
do {
} while (!keypressed());
if ((readkey()&0xFF) == 27)
exit(0);
calibrate_joystick_br(); /* We calibrate the bottom right corner */
}
save_joystick_data(char joy*) /*WHAT THE HELL DO I DO...want the file
to
be saved to joy.cfg*/
printf("Calibration is complete. Config files is saved to joy.cfg");
while (!keypressed());
/* If you press a key, you will be again in the peaceful DOS. */
clear(bmp);
set_gfx_mode(GFX_TEXT,80,25,0,0);
return 0;
}
- Raw text -