Annotation of uae/src/od-win32/joystick.c, revision 1.1.1.2

1.1       root        1: /* 
                      2:  * UAE - The Un*x Amiga Emulator
                      3:  *
                      4:  * Win32 interface
                      5:  *
                      6:  * Copyright 1997 Mathias Ortmann
                      7:  */
                      8: 
                      9: #include <windows.h>
                     10: #include <ddraw.h>
                     11: #include <stdlib.h>
                     12: #include <stdarg.h>
1.1.1.2 ! root       13: #include <mmsystem.h>
1.1       root       14: #include <stdio.h>
                     15: #include <fcntl.h>
                     16: #include <sys/stat.h>
                     17: #include <io.h>
                     18: 
                     19: #include "config.h"
                     20: #include "sysconfig.h"
                     21: #include "sysdeps.h"
                     22: #include "options.h"
                     23: #include "osdep/win32gui.h"
                     24: #include "include/memory.h"
1.1.1.2 ! root       25: #include "osdep/resource.h"
1.1       root       26: 
                     27: /* Joystick emulation, Win32 interface */
1.1.1.2 ! root       28: int nr_joysticks;
1.1       root       29: 
1.1.1.2 ! root       30: int joystickspresent[MAXJOYSTICKS];
1.1       root       31: static int unplugged[MAXJOYSTICKS];
                     32: static int warned[MAXJOYSTICKS];
                     33: static JOYCAPS jc[MAXJOYSTICKS];
                     34: static JOYINFOEX ji =
                     35: {sizeof (ji), JOY_RETURNBUTTONS | JOY_RETURNX | JOY_RETURNY};
                     36: 
                     37: void read_joystick (int nr, short *dir, int *button)
                     38: {
                     39:     int left = 0, right = 0, top = 0, bot = 0;
                     40:     int joyerr;
                     41: 
                     42:     *dir = *button = 0;
1.1.1.2 ! root       43:     if (!joystickspresent[nr])
1.1       root       44:        return;
                     45: 
                     46:     if (unplugged[nr]) {
                     47:        unplugged[nr]--;
                     48:        return;
                     49:     }
                     50:     switch (joyerr = joyGetPosEx (JOYSTICKID1 + nr, &ji)) {
                     51:     case JOYERR_NOERROR:
                     52:        warned[nr] = 0;
                     53:        break;
                     54:     case JOYERR_UNPLUGGED:
                     55:        if (!warned[nr]) {
1.1.1.2 ! root       56:            write_log( "Joystick %d seems to be unplugged.\n", nr );
1.1       root       57:            warned[nr] = 1;
                     58:        }
                     59:        unplugged[nr] = 200;
                     60:        return;
                     61:     default:
1.1.1.2 ! root       62:        write_log( "Error reading joystick %d: %d.\n", nr, joyerr );
1.1       root       63:        unplugged[nr] = 100;
                     64:        return;
                     65:     }
                     66: 
                     67:     if (ji.dwXpos < (jc[nr].wXmin + 2 * (jc[nr].wXmax - jc[nr].wXmin) / 5))
                     68:        left = 1;
                     69:     else if (ji.dwXpos > (jc[nr].wXmin + 3 * (jc[nr].wXmax - jc[nr].wXmin) / 5))
                     70:        right = 1;
                     71: 
                     72:     if (ji.dwYpos < (jc[nr].wYmin + 2 * (jc[nr].wYmax - jc[nr].wYmin) / 5))
                     73:        top = 1;
                     74:     else if (ji.dwYpos > (jc[nr].wYmin + 3 * (jc[nr].wYmax - jc[nr].wYmin) / 5))
                     75:        bot = 1;
                     76: 
                     77:     if (left)
                     78:        top = !top;
                     79:     if (right)
                     80:        bot = !bot;
                     81:     *dir = bot | (right << 1) | (top << 8) | (left << 9);
                     82:     *button = ji.dwButtons;
                     83: }
                     84: 
                     85: void init_joystick (void)
                     86: {
                     87:     int nr;
                     88:     int found = 0;
                     89: 
                     90:     for (nr = 0; nr < MAXJOYSTICKS; nr++) {
                     91:        if (joyGetDevCaps (JOYSTICKID1 + nr, jc + nr, sizeof (jc)) == JOYERR_NOERROR) {
1.1.1.2 ! root       92:            write_log( "Joystick %d: %s with %d buttons\n", nr, jc[nr].szPname, jc[nr].wNumButtons );
        !            93:            joystickspresent[nr] = 1;
1.1       root       94:            found++;
                     95:        }
                     96:     }
1.1.1.2 ! root       97:     nr_joysticks = found;
        !            98:     write_log( "%d joystick(s) found.\n", found );
1.1       root       99: }
                    100: 
                    101: void close_joystick (void)
                    102: {
                    103: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.