delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/23/18:30:24

From: Shane <ssbs AT netinc DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Saving Joystick cfg with ALLEGRO
Date: Tue, 23 Dec 1997 18:14:45 -0500
Organization: All USENET -- http://www.Supernews.com
Lines: 87
Message-ID: <34A045E5.397864A6@netinc.ca>
NNTP-Posting-Host: 15133 AT 205 DOT 211 DOT 8 DOT 77
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019