Unified joystick controls.
Both gtk and gtk-glade UIs use src/ctrlssdl.{h,x} for joystick support.
This commit is contained in:
parent
9a6a3a36f7
commit
1d9b17bd18
|
@ -3,7 +3,7 @@ desmume_glade_SOURCES = \
|
||||||
callbacks.c callbacks.h callbacks_IO.c callbacks_IO.h desmume.c desmume.h \
|
callbacks.c callbacks.h callbacks_IO.c callbacks_IO.h desmume.c desmume.h \
|
||||||
globals.h keyval_names.c main.c printscreen.c \
|
globals.h keyval_names.c main.c printscreen.c \
|
||||||
dTools/callbacks_1_ioregs.c dTools/callbacks_dtools.h \
|
dTools/callbacks_1_ioregs.c dTools/callbacks_dtools.h \
|
||||||
../sndsdl.h ../sndsdl.c joysdl.h joysdl.c
|
../sndsdl.h ../sndsdl.c ../ctrlssdl.h ../ctrlssdl.c
|
||||||
desmume_glade_LDADD = ../libdesmume.a $(SDL_LIBS) $(LIBGLADE_LIBS)
|
desmume_glade_LDADD = ../libdesmume.a $(SDL_LIBS) $(LIBGLADE_LIBS)
|
||||||
desmume_glade_CFLAGS = $(SDL_CFLAGS) $(LIBGLADE_CFLAGS)
|
desmume_glade_CFLAGS = $(SDL_CFLAGS) $(LIBGLADE_CFLAGS)
|
||||||
desmume_glade_LDFLAGS = -rdynamic
|
desmume_glade_LDFLAGS = -rdynamic
|
||||||
|
|
|
@ -86,9 +86,19 @@ BOOL desmume_running()
|
||||||
|
|
||||||
void desmume_cycle()
|
void desmume_cycle()
|
||||||
{
|
{
|
||||||
process_joy_events();
|
u16 keypad;
|
||||||
desmume_last_cycle = NDS_exec((560190 << 1) - desmume_last_cycle, FALSE);
|
/* Joystick events */
|
||||||
SPU_Emulate();
|
/* Retrieve old value: can use joysticks w/ another device (from our side) */
|
||||||
|
keypad = ~((unsigned short *)MMU.ARM7_REG)[0x130>>1];
|
||||||
|
keypad = (keypad & 0x3) << 10;
|
||||||
|
keypad |= ~((unsigned short *)ARM9Mem.ARM9_REG)[0x130>>1] & 0x3FF;
|
||||||
|
/* Look for queued events */
|
||||||
|
keypad = process_ctrls_events(keypad);
|
||||||
|
/* Update keypad value */
|
||||||
|
desmume_keypad(keypad);
|
||||||
|
|
||||||
|
desmume_last_cycle = NDS_exec((560190 << 1) - desmume_last_cycle, FALSE);
|
||||||
|
SPU_Emulate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void desmume_keypad(u16 k)
|
void desmume_keypad(u16 k)
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#ifndef __DESMUME_H__
|
#ifndef __DESMUME_H__
|
||||||
#define __DESMUME_H__
|
#define __DESMUME_H__
|
||||||
|
|
||||||
|
|
||||||
#define DESMUME_NB_KEYS 14
|
#define DESMUME_NB_KEYS 14
|
||||||
|
|
||||||
#define DESMUME_KEYMASK_(k) (1 << k)
|
#define DESMUME_KEYMASK_(k) (1 << k)
|
||||||
|
@ -42,7 +41,7 @@
|
||||||
#define DESMUME_KEY_DEBUG 13
|
#define DESMUME_KEY_DEBUG 13
|
||||||
#define DESMUME_KEY_BOOST 14
|
#define DESMUME_KEY_BOOST 14
|
||||||
|
|
||||||
#include "joysdl.h"
|
#include "globals.h"
|
||||||
|
|
||||||
extern void desmume_init();
|
extern void desmume_init();
|
||||||
extern void desmume_free();
|
extern void desmume_free();
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#ifndef __GLOBALS_H__
|
#ifndef __GLOBALS_H__
|
||||||
#define __GLOBALS_H__
|
#define __GLOBALS_H__
|
||||||
|
|
||||||
|
#define GTK
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -39,13 +41,13 @@
|
||||||
#include "../NDSSystem.h"
|
#include "../NDSSystem.h"
|
||||||
#include "../cflash.h"
|
#include "../cflash.h"
|
||||||
#include "../sndsdl.h"
|
#include "../sndsdl.h"
|
||||||
|
#include "../ctrlssdl.h"
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
#include "desmume.h"
|
#include "desmume.h"
|
||||||
|
|
||||||
uint Frameskip;
|
uint Frameskip;
|
||||||
gint Keypad_Config[DESMUME_NB_KEYS];
|
gint Keypad_Config[DESMUME_NB_KEYS];
|
||||||
gint Keypad_Temp[DESMUME_NB_KEYS];
|
gint Keypad_Temp[DESMUME_NB_KEYS];
|
||||||
u16 Joypad_Config[DESMUME_NB_KEYS];
|
|
||||||
|
|
||||||
/* main.c */
|
/* main.c */
|
||||||
GtkWidget * pWindow;
|
GtkWidget * pWindow;
|
||||||
|
|
|
@ -164,8 +164,6 @@ int WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgumen
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
const char *commandLine_File = NULL;
|
const char *commandLine_File = NULL;
|
||||||
int nbJoysticks;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if(argc == 2) commandLine_File = argv[1];
|
if(argc == 2) commandLine_File = argv[1];
|
||||||
|
|
||||||
|
@ -174,34 +172,20 @@ int main(int argc, char *argv[]) {
|
||||||
#endif
|
#endif
|
||||||
init_keyvals();
|
init_keyvals();
|
||||||
|
|
||||||
memcpy(Joypad_Config, Default_Joypad_Config, sizeof(Joypad_Config));
|
|
||||||
|
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) == -1)
|
if(SDL_Init(SDL_INIT_VIDEO) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error trying to initialize SDL: %s\n",
|
fprintf(stderr, "Error trying to initialize SDL: %s\n",
|
||||||
SDL_GetError());
|
SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
desmume_init();
|
desmume_init();
|
||||||
|
/* Initialize joysticks */
|
||||||
|
if(!init_joy(Default_Joypad_Config)) return 1;
|
||||||
|
|
||||||
CONFIG_FILE = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL);
|
CONFIG_FILE = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL);
|
||||||
Read_ConfigFile();
|
Read_ConfigFile();
|
||||||
|
|
||||||
/* Initialize joysticks */
|
|
||||||
nbJoysticks = SDL_NumJoysticks();
|
|
||||||
printf("Nbr of joysticks: %d\n\n", nbJoysticks);
|
|
||||||
|
|
||||||
for (i = 0; i < nbJoysticks; i++)
|
|
||||||
{
|
|
||||||
SDL_Joystick * joy = SDL_JoystickOpen(i);
|
|
||||||
printf("Joystick %s\n", i, SDL_JoystickName(i));
|
|
||||||
printf("Axes: %d\n", SDL_JoystickNumAxes(joy));
|
|
||||||
printf("Buttons: %d\n", SDL_JoystickNumButtons(joy));
|
|
||||||
printf("Trackballs: %d\n", SDL_JoystickNumBalls(joy));
|
|
||||||
printf("Hats: %d\n\n", SDL_JoystickNumHats(joy));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* load the interface */
|
/* load the interface */
|
||||||
xml = glade_xml_new("glade/DeSmuMe.glade", NULL, NULL);
|
xml = glade_xml_new("glade/DeSmuMe.glade", NULL, NULL);
|
||||||
xml_tools = glade_xml_new("glade/DeSmuMe_Dtools.glade", NULL, NULL);
|
xml_tools = glade_xml_new("glade/DeSmuMe_Dtools.glade", NULL, NULL);
|
||||||
|
@ -236,6 +220,8 @@ int main(int argc, char *argv[]) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
LogStop();
|
LogStop();
|
||||||
#endif
|
#endif
|
||||||
|
/* Unload joystick */
|
||||||
|
uninit_joy();
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
Write_ConfigFile();
|
Write_ConfigFile();
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
bin_PROGRAMS = desmume
|
bin_PROGRAMS = desmume
|
||||||
desmume_SOURCES = gtk-compat.c gtk-compat.h desmume.h desmume.c dToolsList.c tools/ioregsView.c globals.h ../sndsdl.c joysdl.h joysdl.c main.c
|
desmume_SOURCES = \
|
||||||
|
gtk-compat.c gtk-compat.h \
|
||||||
|
desmume.h desmume.c \
|
||||||
|
dToolsList.c \
|
||||||
|
tools/ioregsView.c \
|
||||||
|
globals.h \
|
||||||
|
../sndsdl.c \
|
||||||
|
../ctrlssdl.h ../ctrlssdl.c \
|
||||||
|
main.c
|
||||||
desmume_LDADD = ../libdesmume.a $(SDL_LIBS) $(GTK_LIBS)
|
desmume_LDADD = ../libdesmume.a $(SDL_LIBS) $(GTK_LIBS)
|
||||||
desmume_CFLAGS = $(SDL_CFLAGS) $(GTK_CFLAGS)
|
desmume_CFLAGS = $(SDL_CFLAGS) $(GTK_CFLAGS)
|
||||||
#desmume_LDFLAGS = -rdynamic
|
#desmume_LDFLAGS = -rdynamic
|
||||||
|
|
|
@ -62,16 +62,25 @@ BOOL desmume_running()
|
||||||
|
|
||||||
void desmume_cycle()
|
void desmume_cycle()
|
||||||
{
|
{
|
||||||
process_joy_events();
|
u16 keypad;
|
||||||
desmume_last_cycle = NDS_exec((560190 << 1) - desmume_last_cycle, FALSE);
|
/* Joystick events */
|
||||||
SPU_Emulate();
|
/* Retrieve old value: can use joysticks w/ another device (from our side) */
|
||||||
|
keypad = ~((unsigned short *)MMU.ARM7_REG)[0x130>>1];
|
||||||
|
keypad = (keypad & 0x3) << 10;
|
||||||
|
keypad |= ~((unsigned short *)ARM9Mem.ARM9_REG)[0x130>>1] & 0x3FF;
|
||||||
|
/* Look for queued events */
|
||||||
|
keypad = process_ctrls_events(keypad);
|
||||||
|
/* Update keypad value */
|
||||||
|
desmume_keypad(keypad);
|
||||||
|
|
||||||
|
desmume_last_cycle = NDS_exec((560190 << 1) - desmume_last_cycle, FALSE);
|
||||||
|
SPU_Emulate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void desmume_keypad(u16 k)
|
void desmume_keypad(u16 k)
|
||||||
{
|
{
|
||||||
printf("Update keypad...%x\n", k);
|
unsigned short k_ext = (~k >> 10) & 0x3;
|
||||||
unsigned short k_ext = (k >> 10) & 0x3;
|
unsigned short k_pad = ~k & 0x3FF;
|
||||||
unsigned short k_pad = k & 0x3FF;
|
|
||||||
((unsigned short *)ARM9Mem.ARM9_REG)[0x130>>1] = k_pad;
|
((unsigned short *)ARM9Mem.ARM9_REG)[0x130>>1] = k_pad;
|
||||||
((unsigned short *)MMU.ARM7_REG)[0x130>>1] = k_pad;
|
((unsigned short *)MMU.ARM7_REG)[0x130>>1] = k_pad;
|
||||||
MMU.ARM7_REG[0x136] = (k_ext & 0x3) | (MMU.ARM7_REG[0x136] & ~0x3);
|
MMU.ARM7_REG[0x136] = (k_ext & 0x3) | (MMU.ARM7_REG[0x136] & ~0x3);
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#define DESMUME_KEY_Y 12
|
#define DESMUME_KEY_Y 12
|
||||||
#define DESMUME_KEY_DEBUG 13
|
#define DESMUME_KEY_DEBUG 13
|
||||||
|
|
||||||
#include "joysdl.h"
|
#include "globals.h"
|
||||||
|
|
||||||
extern void desmume_init();
|
extern void desmume_init();
|
||||||
extern void desmume_free();
|
extern void desmume_free();
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#ifndef GLOBALS_H
|
#ifndef GLOBALS_H
|
||||||
#define GLOBALS_H
|
#define GLOBALS_H
|
||||||
|
|
||||||
|
#define GTK
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -39,9 +41,8 @@
|
||||||
#include "../NDSSystem.h"
|
#include "../NDSSystem.h"
|
||||||
#include "../cflash.h"
|
#include "../cflash.h"
|
||||||
#include "../sndsdl.h"
|
#include "../sndsdl.h"
|
||||||
|
#include "../ctrlssdl.h"
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
#include "desmume.h"
|
#include "desmume.h"
|
||||||
|
|
||||||
u16 Joypad_Config[DESMUME_NB_KEYS];
|
|
||||||
|
|
||||||
#endif /* GLOBALS_H */
|
#endif /* GLOBALS_H */
|
||||||
|
|
|
@ -421,7 +421,7 @@ static gint Key_Press(GtkWidget *w, GdkEventKey *e)
|
||||||
{
|
{
|
||||||
Key = DESMUME_KEYMASK_(i);
|
Key = DESMUME_KEYMASK_(i);
|
||||||
Cur_Keypad &= ~Key;
|
Cur_Keypad &= ~Key;
|
||||||
if(desmume_running()) desmume_keypad(Cur_Keypad);
|
if(desmume_running()) desmume_keypad(~Cur_Keypad);
|
||||||
}
|
}
|
||||||
|
|
||||||
//fprintf(stderr,"P:%d(%d)->%X => [%X]\n", e->keyval, e->hardware_keycode, Key, Cur_Keypad);
|
//fprintf(stderr,"P:%d(%d)->%X => [%X]\n", e->keyval, e->hardware_keycode, Key, Cur_Keypad);
|
||||||
|
@ -439,7 +439,7 @@ static gint Key_Release(GtkWidget *w, GdkEventKey *e)
|
||||||
{
|
{
|
||||||
Key = DESMUME_KEYMASK_(i);
|
Key = DESMUME_KEYMASK_(i);
|
||||||
Cur_Keypad |= Key;
|
Cur_Keypad |= Key;
|
||||||
if(desmume_running()) desmume_keypad(Cur_Keypad);
|
if(desmume_running()) desmume_keypad(~Cur_Keypad);
|
||||||
}
|
}
|
||||||
|
|
||||||
//fprintf(stderr,"R:%d(%d)->%X => [%X]\n", e->keyval, e->hardware_keycode, Key, Cur_Keypad);
|
//fprintf(stderr,"R:%d(%d)->%X => [%X]\n", e->keyval, e->hardware_keycode, Key, Cur_Keypad);
|
||||||
|
@ -993,7 +993,6 @@ static void dui_set_accel_group(gpointer action, gpointer group) {
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int nbJoysticks;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
const char *commandLine_File = NULL;
|
const char *commandLine_File = NULL;
|
||||||
|
@ -1008,34 +1007,20 @@ int main (int argc, char *argv[])
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
LogStart();
|
LogStart();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memcpy(Joypad_Config, Default_Joypad_Config, sizeof(Joypad_Config));
|
|
||||||
|
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) == -1)
|
if(SDL_Init(SDL_INIT_VIDEO) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error trying to initialize SDL: %s\n",
|
fprintf(stderr, "Error trying to initialize SDL: %s\n",
|
||||||
SDL_GetError());
|
SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
desmume_init();
|
desmume_init();
|
||||||
|
/* Initialize joysticks */
|
||||||
|
if(!init_joy(Default_Joypad_Config)) return 1;
|
||||||
|
|
||||||
dTools_running = (BOOL*)malloc(sizeof(BOOL) * dTools_list_size);
|
dTools_running = (BOOL*)malloc(sizeof(BOOL) * dTools_list_size);
|
||||||
for(i=0; i<dTools_list_size; i++) dTools_running[i]=FALSE;
|
for(i=0; i<dTools_list_size; i++) dTools_running[i]=FALSE;
|
||||||
|
|
||||||
/* Initialize joysticks */
|
|
||||||
nbJoysticks = SDL_NumJoysticks();
|
|
||||||
printf("Nbr of joysticks: %d\n\n", nbJoysticks);
|
|
||||||
|
|
||||||
for (i = 0; i < nbJoysticks; i++)
|
|
||||||
{
|
|
||||||
SDL_Joystick * joy = SDL_JoystickOpen(i);
|
|
||||||
printf("Joystick %s\n", i, SDL_JoystickName(i));
|
|
||||||
printf("Axes: %d\n", SDL_JoystickNumAxes(joy));
|
|
||||||
printf("Buttons: %d\n", SDL_JoystickNumButtons(joy));
|
|
||||||
printf("Trackballs: %d\n", SDL_JoystickNumBalls(joy));
|
|
||||||
printf("Hats: %d\n\n", SDL_JoystickNumHats(joy));
|
|
||||||
}
|
|
||||||
|
|
||||||
CONFIG_FILE = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL);
|
CONFIG_FILE = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL);
|
||||||
Read_ConfigFile();
|
Read_ConfigFile();
|
||||||
|
@ -1291,6 +1276,8 @@ int main (int argc, char *argv[])
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
LogStop();
|
LogStop();
|
||||||
#endif
|
#endif
|
||||||
|
/* Unload joystick */
|
||||||
|
uninit_joy();
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue