revision 850:28782ebbd01d
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 850:28782ebbd01d |
parent | 849:bbe26d798fc2 |
child | 851:41e8ae2c114b |
author | nkeynes |
date | Mon Sep 08 07:56:33 2008 +0000 (15 years ago) |
Add lightgun support
src/Makefile.am | view | annotate | diff | log | ||
src/Makefile.in | view | annotate | diff | log | ||
src/display.h | view | annotate | diff | log | ||
src/drivers/video_osx.c | view | annotate | diff | log | ||
src/eventq.h | view | annotate | diff | log | ||
src/gtkui/gtk_win.c | view | annotate | diff | log | ||
src/maple/controller.c | view | annotate | diff | log | ||
src/maple/lightgun.c | view | annotate | diff | log | ||
src/maple/maple.c | view | annotate | diff | log | ||
src/maple/maple.h | view | annotate | diff | log | ||
src/maple/mouse.c | view | annotate | diff | log | ||
src/pvr2/pvr2.c | view | annotate | diff | log | ||
src/pvr2/pvr2.h | view | annotate | diff | log |
1.1 --- a/src/Makefile.am Mon Sep 08 05:13:51 2008 +00001.2 +++ b/src/Makefile.am Mon Sep 08 07:56:33 2008 +00001.3 @@ -55,6 +55,7 @@1.4 pvr2/vertex.glsl pvr2/fragment.glsl \1.5 maple/maple.c maple/maple.h \1.6 maple/controller.c maple/controller.h maple/kbd.c maple/mouse.c \1.7 + maple/lightgun.c \1.8 loader.c loader.h elf.h bootstrap.c bootstrap.h util.c gdlist.c gdlist.h \1.9 display.c display.h dckeysyms.h \1.10 drivers/audio_null.c drivers/video_null.c \
2.1 --- a/src/Makefile.in Mon Sep 08 05:13:51 2008 +00002.2 +++ b/src/Makefile.in Mon Sep 08 07:56:33 2008 +00002.3 @@ -113,29 +113,29 @@2.4 pvr2/glutil.h pvr2/glrender.c pvr2/vertex.glsl \2.5 pvr2/fragment.glsl maple/maple.c maple/maple.h \2.6 maple/controller.c maple/controller.h maple/kbd.c \2.7 - maple/mouse.c loader.c loader.h elf.h bootstrap.c bootstrap.h \2.8 - util.c gdlist.c gdlist.h display.c display.h dckeysyms.h \2.9 - drivers/audio_null.c drivers/video_null.c drivers/video_gl.c \2.10 - drivers/video_gl.h drivers/gl_fbo.c sh4/sh4.def sh4/sh4core.in \2.11 - sh4/sh4x86.in sh4/sh4dasm.in sh4/sh4stat.in sh4/sh4x86.c \2.12 - sh4/x86op.h sh4/ia32abi.h sh4/ia32mac.h sh4/ia64abi.h \2.13 - sh4/sh4trans.c sh4/sh4trans.h x86dasm/x86dasm.c \2.14 - x86dasm/x86dasm.h x86dasm/i386-dis.c x86dasm/dis-init.c \2.15 - x86dasm/dis-buf.c x86dasm/ansidecl.h x86dasm/bfd.h \2.16 - x86dasm/dis-asm.h x86dasm/symcat.h x86dasm/sysdep.h \2.17 - gtkui/gtkui.c gtkui/gtkui.h gtkui/gtk_win.c gtkui/gtkcb.c \2.18 - gtkui/gtk_mmio.c gtkui/gtk_debug.c gtkui/gtk_dump.c \2.19 - gtkui/gtk_ctrl.c gtkui/gtk_path.c gtkui/gtk_gd.c \2.20 - drivers/video_gtk.c cocoaui/cocoaui.c cocoaui/cocoaui.h \2.21 - cocoaui/cocoa_win.c cocoaui/cocoa_gd.c cocoaui/cocoa_prefs.c \2.22 - cocoaui/cocoa_path.c cocoaui/cocoa_ctrl.c drivers/video_osx.c \2.23 - drivers/mac_keymap.h drivers/mac_keymap.txt \2.24 - drivers/video_gdk.c drivers/video_glx.c drivers/video_glx.h \2.25 - drivers/video_nsgl.c drivers/video_nsgl.h drivers/audio_osx.c \2.26 - drivers/audio_pulse.c drivers/audio_esd.c drivers/audio_alsa.c \2.27 - drivers/cd_linux.c drivers/cd_osx.c drivers/osx_iokit.c \2.28 - drivers/osx_iokit.h drivers/cd_none.c drivers/joy_linux.c \2.29 - drivers/joy_linux.h2.30 + maple/mouse.c maple/lightgun.c loader.c loader.h elf.h \2.31 + bootstrap.c bootstrap.h util.c gdlist.c gdlist.h display.c \2.32 + display.h dckeysyms.h drivers/audio_null.c \2.33 + drivers/video_null.c drivers/video_gl.c drivers/video_gl.h \2.34 + drivers/gl_fbo.c sh4/sh4.def sh4/sh4core.in sh4/sh4x86.in \2.35 + sh4/sh4dasm.in sh4/sh4stat.in sh4/sh4x86.c sh4/x86op.h \2.36 + sh4/ia32abi.h sh4/ia32mac.h sh4/ia64abi.h sh4/sh4trans.c \2.37 + sh4/sh4trans.h x86dasm/x86dasm.c x86dasm/x86dasm.h \2.38 + x86dasm/i386-dis.c x86dasm/dis-init.c x86dasm/dis-buf.c \2.39 + x86dasm/ansidecl.h x86dasm/bfd.h x86dasm/dis-asm.h \2.40 + x86dasm/symcat.h x86dasm/sysdep.h gtkui/gtkui.c gtkui/gtkui.h \2.41 + gtkui/gtk_win.c gtkui/gtkcb.c gtkui/gtk_mmio.c \2.42 + gtkui/gtk_debug.c gtkui/gtk_dump.c gtkui/gtk_ctrl.c \2.43 + gtkui/gtk_path.c gtkui/gtk_gd.c drivers/video_gtk.c \2.44 + cocoaui/cocoaui.c cocoaui/cocoaui.h cocoaui/cocoa_win.c \2.45 + cocoaui/cocoa_gd.c cocoaui/cocoa_prefs.c cocoaui/cocoa_path.c \2.46 + cocoaui/cocoa_ctrl.c drivers/video_osx.c drivers/mac_keymap.h \2.47 + drivers/mac_keymap.txt drivers/video_gdk.c drivers/video_glx.c \2.48 + drivers/video_glx.h drivers/video_nsgl.c drivers/video_nsgl.h \2.49 + drivers/audio_osx.c drivers/audio_pulse.c drivers/audio_esd.c \2.50 + drivers/audio_alsa.c drivers/cd_linux.c drivers/cd_osx.c \2.51 + drivers/osx_iokit.c drivers/osx_iokit.h drivers/cd_none.c \2.52 + drivers/joy_linux.c drivers/joy_linux.h2.53 @BUILD_SH4X86_TRUE@am__objects_1 = sh4x86.$(OBJEXT) sh4trans.$(OBJEXT) \2.54 @BUILD_SH4X86_TRUE@ x86dasm.$(OBJEXT) i386-dis.$(OBJEXT) \2.55 @BUILD_SH4X86_TRUE@ dis-init.$(OBJEXT) dis-buf.$(OBJEXT)2.56 @@ -175,15 +175,15 @@2.57 yuv.$(OBJEXT) rendsave.$(OBJEXT) scene.$(OBJEXT) \2.58 gl_sl.$(OBJEXT) gl_slsrc.$(OBJEXT) glutil.$(OBJEXT) \2.59 glrender.$(OBJEXT) maple.$(OBJEXT) controller.$(OBJEXT) \2.60 - kbd.$(OBJEXT) mouse.$(OBJEXT) loader.$(OBJEXT) \2.61 - bootstrap.$(OBJEXT) util.$(OBJEXT) gdlist.$(OBJEXT) \2.62 - display.$(OBJEXT) audio_null.$(OBJEXT) video_null.$(OBJEXT) \2.63 - video_gl.$(OBJEXT) gl_fbo.$(OBJEXT) $(am__objects_1) \2.64 - $(am__objects_2) $(am__objects_3) $(am__objects_4) \2.65 - $(am__objects_5) $(am__objects_6) $(am__objects_7) \2.66 - $(am__objects_8) $(am__objects_9) $(am__objects_10) \2.67 - $(am__objects_11) $(am__objects_12) $(am__objects_13) \2.68 - $(am__objects_14)2.69 + kbd.$(OBJEXT) mouse.$(OBJEXT) lightgun.$(OBJEXT) \2.70 + loader.$(OBJEXT) bootstrap.$(OBJEXT) util.$(OBJEXT) \2.71 + gdlist.$(OBJEXT) display.$(OBJEXT) audio_null.$(OBJEXT) \2.72 + video_null.$(OBJEXT) video_gl.$(OBJEXT) gl_fbo.$(OBJEXT) \2.73 + $(am__objects_1) $(am__objects_2) $(am__objects_3) \2.74 + $(am__objects_4) $(am__objects_5) $(am__objects_6) \2.75 + $(am__objects_7) $(am__objects_8) $(am__objects_9) \2.76 + $(am__objects_10) $(am__objects_11) $(am__objects_12) \2.77 + $(am__objects_13) $(am__objects_14)2.78 lxdream_OBJECTS = $(am_lxdream_OBJECTS)2.79 lxdream_DEPENDENCIES = $(am__DEPENDENCIES_1)2.80 am__test_testsh4x86_SOURCES_DIST = test/testsh4x86.c x86dasm/x86dasm.c \2.81 @@ -420,16 +420,16 @@2.82 pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c pvr2/vertex.glsl \2.83 pvr2/fragment.glsl maple/maple.c maple/maple.h \2.84 maple/controller.c maple/controller.h maple/kbd.c \2.85 - maple/mouse.c loader.c loader.h elf.h bootstrap.c bootstrap.h \2.86 - util.c gdlist.c gdlist.h display.c display.h dckeysyms.h \2.87 - drivers/audio_null.c drivers/video_null.c drivers/video_gl.c \2.88 - drivers/video_gl.h drivers/gl_fbo.c sh4/sh4.def sh4/sh4core.in \2.89 - sh4/sh4x86.in sh4/sh4dasm.in sh4/sh4stat.in $(am__append_1) \2.90 - $(am__append_3) $(am__append_4) $(am__append_5) \2.91 - $(am__append_6) $(am__append_7) $(am__append_8) \2.92 - $(am__append_9) $(am__append_10) $(am__append_11) \2.93 - $(am__append_12) $(am__append_13) $(am__append_14) \2.94 - $(am__append_15)2.95 + maple/mouse.c maple/lightgun.c loader.c loader.h elf.h \2.96 + bootstrap.c bootstrap.h util.c gdlist.c gdlist.h display.c \2.97 + display.h dckeysyms.h drivers/audio_null.c \2.98 + drivers/video_null.c drivers/video_gl.c drivers/video_gl.h \2.99 + drivers/gl_fbo.c sh4/sh4.def sh4/sh4core.in sh4/sh4x86.in \2.100 + sh4/sh4dasm.in sh4/sh4stat.in $(am__append_1) $(am__append_3) \2.101 + $(am__append_4) $(am__append_5) $(am__append_6) \2.102 + $(am__append_7) $(am__append_8) $(am__append_9) \2.103 + $(am__append_10) $(am__append_11) $(am__append_12) \2.104 + $(am__append_13) $(am__append_14) $(am__append_15)2.105 @BUILD_SH4X86_TRUE@test_testsh4x86_LDADD = @GLIB_LIBS@ @GTK_LIBS@ @LIBPNG_LIBS@2.106 @BUILD_SH4X86_TRUE@test_testsh4x86_SOURCES = test/testsh4x86.c x86dasm/x86dasm.c \2.107 @BUILD_SH4X86_TRUE@ x86dasm/x86dasm.h x86dasm/i386-dis.c x86dasm/dis-init.c \2.108 @@ -589,6 +589,7 @@2.109 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intc.Po@am__quote@2.110 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/joy_linux.Po@am__quote@2.111 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kbd.Po@am__quote@2.112 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lightgun.Po@am__quote@2.113 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loader.Po@am__quote@2.114 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@2.115 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/maple.Po@am__quote@2.116 @@ -1291,6 +1292,20 @@2.117 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@2.118 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mouse.obj `if test -f 'maple/mouse.c'; then $(CYGPATH_W) 'maple/mouse.c'; else $(CYGPATH_W) '$(srcdir)/maple/mouse.c'; fi`2.120 +lightgun.o: maple/lightgun.c2.121 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lightgun.o -MD -MP -MF "$(DEPDIR)/lightgun.Tpo" -c -o lightgun.o `test -f 'maple/lightgun.c' || echo '$(srcdir)/'`maple/lightgun.c; \2.122 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lightgun.Tpo" "$(DEPDIR)/lightgun.Po"; else rm -f "$(DEPDIR)/lightgun.Tpo"; exit 1; fi2.123 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='maple/lightgun.c' object='lightgun.o' libtool=no @AMDEPBACKSLASH@2.124 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@2.125 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lightgun.o `test -f 'maple/lightgun.c' || echo '$(srcdir)/'`maple/lightgun.c2.126 +2.127 +lightgun.obj: maple/lightgun.c2.128 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lightgun.obj -MD -MP -MF "$(DEPDIR)/lightgun.Tpo" -c -o lightgun.obj `if test -f 'maple/lightgun.c'; then $(CYGPATH_W) 'maple/lightgun.c'; else $(CYGPATH_W) '$(srcdir)/maple/lightgun.c'; fi`; \2.129 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lightgun.Tpo" "$(DEPDIR)/lightgun.Po"; else rm -f "$(DEPDIR)/lightgun.Tpo"; exit 1; fi2.130 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='maple/lightgun.c' object='lightgun.obj' libtool=no @AMDEPBACKSLASH@2.131 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@2.132 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lightgun.obj `if test -f 'maple/lightgun.c'; then $(CYGPATH_W) 'maple/lightgun.c'; else $(CYGPATH_W) '$(srcdir)/maple/lightgun.c'; fi`2.133 +2.134 audio_null.o: drivers/audio_null.c2.135 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT audio_null.o -MD -MP -MF "$(DEPDIR)/audio_null.Tpo" -c -o audio_null.o `test -f 'drivers/audio_null.c' || echo '$(srcdir)/'`drivers/audio_null.c; \2.136 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/audio_null.Tpo" "$(DEPDIR)/audio_null.Po"; else rm -f "$(DEPDIR)/audio_null.Tpo"; exit 1; fi
3.1 --- a/src/display.h Mon Sep 08 05:13:51 2008 +00003.2 +++ b/src/display.h Mon Sep 08 07:56:33 2008 +00003.3 @@ -54,6 +54,13 @@3.4 #define COLFMT_BGR0888 8 /* 32-bit BGR */3.5 #define COLFMT_RGB888 9 /* 24-bit RGB (ie GL native) */3.7 +/**3.8 + * The standard display size (for the purposes of mouse inputs, etc, is 640x480 -3.9 + * events should be adjusted accordingly if this is not the actual window size.3.10 + */3.11 +#define DISPLAY_WIDTH 6403.12 +#define DISPLAY_HEIGHT 4803.13 +3.14 struct colour_format {3.15 GLint type, format, int_format;3.16 int bpp;
4.1 --- a/src/drivers/video_osx.c Mon Sep 08 05:13:51 2008 +00004.2 +++ b/src/drivers/video_osx.c Mon Sep 08 07:56:33 2008 +00004.3 @@ -60,7 +60,6 @@4.5 @interface LxdreamOSXView : LxdreamVideoView4.6 {4.7 - int buttonMask;4.8 int flagsMask[MAX_MASK_KEYCODE];4.9 }4.10 @end4.11 @@ -87,7 +86,6 @@4.12 if( [super initWithFrame: contentRect] != nil ) {4.13 int i;4.14 isGrabbed = NO;4.15 - buttonMask = 0;4.16 for( i=0; i<MAX_MASK_KEYCODE; i++ ) {4.17 flagsMask[i] = 0;4.18 }4.19 @@ -155,74 +153,87 @@4.20 flagsMask[keycode] = 0;4.21 }4.22 }4.23 -- (void)emitButtonEvent: (NSEvent *)event buttons: (int)buttons4.24 +- (void)emitMouseDownEvent: (NSEvent *)event button: (int)button4.25 {4.26 if( isGrabbed ) {4.27 - input_event_mouse( buttons, 0, 0, FALSE );4.28 + input_event_mousedown( button, 0, 0, FALSE );4.29 } else {4.30 NSPoint pt = [event locationInWindow];4.31 - input_event_mouse( buttonMask, (int)pt.x, (int)pt.y, TRUE );4.32 + input_event_mousedown( button, (int)(pt.x * DISPLAY_WIDTH) / video_width,4.33 + DISPLAY_HEIGHT - ((int)(pt.y * DISPLAY_HEIGHT) / video_height), TRUE );4.34 + }4.35 +}4.36 +- (void)emitMouseUpEvent: (NSEvent *)event button: (int)button4.37 +{4.38 + if( isGrabbed ) {4.39 + input_event_mouseup( button, 0, 0, FALSE );4.40 + } else {4.41 + NSPoint pt = [event locationInWindow];4.42 + input_event_mouseup( button, (int)(pt.x * DISPLAY_WIDTH) / video_width,4.43 + DISPLAY_HEIGHT - ((int)(pt.y * DISPLAY_HEIGHT) / video_height), TRUE );4.44 + }4.45 +}4.46 +- (void)emitMouseMoveEvent: (NSEvent *)event4.47 +{4.48 + if( isGrabbed ) {4.49 + input_event_mousemove( [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE, FALSE );4.50 + } else {4.51 + NSPoint pt = [event locationInWindow];4.52 + input_event_mousemove( (int)(pt.x * DISPLAY_WIDTH) / video_width,4.53 + DISPLAY_HEIGHT - ((int)(pt.y * DISPLAY_HEIGHT) / video_height), TRUE );4.54 + }4.55 +}4.56 +- (void)mouseExited: (NSEvent *)event4.57 +{4.58 + if( !isGrabbed ) {4.59 + input_event_mousemove( -1, -1, TRUE );4.60 }4.61 }4.63 - (void)mouseDown: (NSEvent *) event4.64 {4.65 - buttonMask |= 1;4.66 // If using grab but not grabbed yet, the first click should be consumed4.67 // by the grabber. In all other circumstances we process normally.4.68 if( isGrabbed || ![self requestGrab] ) {4.69 - [self emitButtonEvent: event buttons: buttonMask];4.70 + [self emitMouseDownEvent: event button: 0];4.71 }4.72 }4.73 - (void)mouseUp: (NSEvent *)event4.74 {4.75 - buttonMask &= ~1;4.76 - [self emitButtonEvent: event buttons: buttonMask];4.77 + [self emitMouseUpEvent: event button: 0];4.78 }4.80 - (void)rightMouseDown: (NSEvent *) event4.81 {4.82 - buttonMask |= 2;4.83 - [self emitButtonEvent: event buttons: buttonMask];4.84 + [self emitMouseDownEvent: event button: 1];4.85 }4.86 - (void)rightMouseUp: (NSEvent *)event4.87 {4.88 - buttonMask &= ~2;4.89 - [self emitButtonEvent: event buttons: buttonMask];4.90 + [self emitMouseUpEvent: event button: 1];4.91 }4.92 - (void)otherMouseDown: (NSEvent *) event4.93 {4.94 - buttonMask |= (1<< [event buttonNumber] );4.95 - [self emitButtonEvent: event buttons: buttonMask];4.96 + [self emitMouseDownEvent: event button: [event buttonNumber]];4.97 }4.98 - (void)otherMouseUp: (NSEvent *) event4.99 {4.100 - buttonMask &= ~(1<< [event buttonNumber] );4.101 - [self emitButtonEvent: event buttons: buttonMask];4.102 + [self emitMouseUpEvent: event button: [event buttonNumber]];4.103 }4.104 - (void)mouseMoved: (NSEvent *) event4.105 {4.106 - if( isGrabbed ) {4.107 - input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE, FALSE );4.108 - }4.109 + [self emitMouseMoveEvent: event];4.110 }4.111 - (void)mouseDragged: (NSEvent *) event4.112 {4.113 - if( isGrabbed ) {4.114 - input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE, FALSE );4.115 - }4.116 + [self emitMouseMoveEvent: event];4.117 }4.118 - (void)rightMouseDragged: (NSEvent *) event4.119 {4.120 - if( isGrabbed ) {4.121 - input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE, FALSE );4.122 - }4.123 + [self emitMouseMoveEvent: event];4.124 }4.125 - (void)otherMouseDragged: (NSEvent *) event4.126 {4.127 - if( isGrabbed ) {4.128 - input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE, FALSE );4.129 - }4.130 + [self emitMouseMoveEvent: event];4.131 }4.133 @end
5.1 --- a/src/eventq.h Mon Sep 08 05:13:51 2008 +00005.2 +++ b/src/eventq.h Mon Sep 08 07:56:33 2008 +00005.3 @@ -78,6 +78,7 @@5.4 #define EVENT_TMU0 975.5 #define EVENT_TMU1 985.6 #define EVENT_TMU2 995.7 +#define EVENT_GUNPOS 1005.9 #ifdef __cplusplus5.10 }
6.1 --- a/src/gtkui/gtk_win.c Mon Sep 08 05:13:51 2008 +00006.2 +++ b/src/gtkui/gtk_win.c Mon Sep 08 07:56:33 2008 +00006.3 @@ -135,11 +135,23 @@6.4 input_event_mousemove( x - win->mouse_x, y - win->mouse_y, FALSE );6.5 video_window_center_pointer(win);6.6 } else {6.7 - input_event_mousemove( x, y, TRUE );6.8 + int width, height;6.9 + gdk_drawable_get_size(GDK_DRAWABLE(widget->window), &width, &height);6.10 + input_event_mousemove( x * DISPLAY_WIDTH /width , y * DISPLAY_HEIGHT / height, TRUE );6.11 }6.12 return TRUE;6.13 }6.15 +static gboolean on_video_window_mouse_exited( GtkWidget *widget, GdkEventCrossing *event,6.16 + gpointer user_data )6.17 +{6.18 + main_window_t win = (main_window_t)user_data;6.19 + if( !win->is_grabbed ) {6.20 + input_event_mousemove( -1, -1, TRUE );6.21 + }6.22 + return TRUE;6.23 +}6.24 +6.25 static gboolean on_video_window_mouse_pressed( GtkWidget *widget, GdkEventButton *event,6.26 gpointer user_data )6.27 {6.28 @@ -147,7 +159,10 @@6.29 if( win->is_grabbed ) {6.30 input_event_mousedown( event->button-1, 0, 0, FALSE );6.31 } else {6.32 - input_event_mousedown( event->button-1, (int32_t)event->x, (int32_t)event->y, TRUE );6.33 + int width, height;6.34 + gdk_drawable_get_size(GDK_DRAWABLE(widget->window), &width, &height);6.35 + input_event_mousedown( event->button-1, (int32_t)event->x * DISPLAY_WIDTH / width,6.36 + (int32_t)event->y * DISPLAY_HEIGHT / height, TRUE );6.37 }6.38 return TRUE;6.39 }6.40 @@ -161,7 +176,10 @@6.41 } else if( win->use_grab) {6.42 video_window_grab_display(win);6.43 } else {6.44 - input_event_mouseup( event->button-1, (int32_t)event->x, (int32_t)event->y, TRUE );6.45 + int width, height;6.46 + gdk_drawable_get_size(GDK_DRAWABLE(widget->window), &width, &height);6.47 + input_event_mouseup( event->button-1, (int32_t)event->x * DISPLAY_WIDTH / width,6.48 + (int32_t)event->y * DISPLAY_HEIGHT / height, TRUE );6.49 }6.50 return TRUE;6.51 }6.52 @@ -298,6 +316,8 @@6.53 G_CALLBACK(on_video_window_key_released), win );6.54 g_signal_connect( win->video, "motion-notify-event",6.55 G_CALLBACK(on_video_window_mouse_motion), win );6.56 + g_signal_connect( win->video, "leave-notify-event",6.57 + G_CALLBACK(on_video_window_mouse_exited), win );6.58 g_signal_connect( win->video, "button-press-event",6.59 G_CALLBACK(on_video_window_mouse_pressed), win );6.60 g_signal_connect( win->video, "button-release-event",6.61 @@ -310,7 +330,8 @@6.62 gtk_widget_add_events( win->video,6.63 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |6.64 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |6.65 - GDK_POINTER_MOTION_MASK | GDK_FOCUS_CHANGE_MASK );6.66 + GDK_POINTER_MOTION_MASK | GDK_FOCUS_CHANGE_MASK |6.67 + GDK_LEAVE_NOTIFY_MASK );6.69 return win;6.70 }
7.1 --- a/src/maple/controller.c Mon Sep 08 05:13:51 2008 +00007.2 +++ b/src/maple/controller.c Mon Sep 08 07:56:33 2008 +00007.3 @@ -97,7 +97,7 @@7.4 CONTROLLER_IDENT, CONTROLLER_VERSION,7.5 controller_get_config, controller_set_config_value,7.6 controller_attach, controller_detach, controller_destroy,7.7 - controller_clone, NULL, NULL, controller_get_cond, NULL, NULL, NULL },7.8 + controller_clone, NULL, NULL, controller_get_cond, NULL, NULL, NULL, NULL, NULL },7.9 {0x0000FFFF, 0x80808080},7.10 {{ "dpad left", N_("Dpad left"), CONFIG_TYPE_KEY },7.11 { "dpad right", N_("Dpad right"), CONFIG_TYPE_KEY },
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00008.2 +++ b/src/maple/lightgun.c Mon Sep 08 07:56:33 2008 +00008.3 @@ -0,0 +1,220 @@8.4 +/**8.5 + * $Id: lightgun.c 858 2008-09-02 03:34:00Z nkeynes $8.6 + *8.7 + * Implementation of the SEGA lightgun device8.8 + * Part No. HKT-78008.9 + *8.10 + * Copyright (c) 2008 Nathan Keynes.8.11 + *8.12 + * This program is free software; you can redistribute it and/or modify8.13 + * it under the terms of the GNU General Public License as published by8.14 + * the Free Software Foundation; either version 2 of the License, or8.15 + * (at your option) any later version.8.16 + *8.17 + * This program is distributed in the hope that it will be useful,8.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of8.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the8.20 + * GNU General Public License for more details.8.21 + */8.22 +8.23 +#include <stdlib.h>8.24 +#include <stdio.h>8.25 +#include <string.h>8.26 +#include <assert.h>8.27 +#include "display.h"8.28 +#include "eventq.h"8.29 +#include "pvr2/pvr2.h"8.30 +#include "maple/maple.h"8.31 +8.32 +#define BUTTON_B 0x000000028.33 +#define BUTTON_A 0x000000048.34 +#define BUTTON_START 0x000000088.35 +#define BUTTON_DPAD_UP 0x000000108.36 +#define BUTTON_DPAD_DOWN 0x000000208.37 +#define BUTTON_DPAD_LEFT 0x000000408.38 +#define BUTTON_DPAD_RIGHT 0x000000808.39 +8.40 +#define LIGHTGUN_IDENT { 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, \8.41 + 0x00, 0x00, 0x00, 0x00, 0xFF, 0x01, 0x44, 0x72, 0x65, 0x61, 0x6D, 0x63, 0x61, 0x73, 0x74, 0x20, \8.42 + 0x47, 0x75, 0x6E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \8.43 + 0x20, 0x20, 0x20, 0x20, 0x50, 0x72, 0x6F, 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x42, 0x79, 0x20, \8.44 + 0x6F, 0x72, 0x20, 0x55, 0x6E, 0x64, 0x65, 0x72, 0x20, 0x4C, 0x69, 0x63, 0x65, 0x6E, 0x73, 0x65, \8.45 + 0x20, 0x46, 0x72, 0x6F, 0x6D, 0x20, 0x53, 0x45, 0x47, 0x41, 0x20, 0x45, 0x4E, 0x54, 0x45, 0x52, \8.46 + 0x50, 0x52, 0x49, 0x53, 0x45, 0x53, 0x2C, 0x4C, 0x54, 0x44, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, \8.47 + 0xDC, 0x00, 0x2C, 0x01 }8.48 +#define LIGHTGUN_VERSION { 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x20, 0x31, 0x2E, 0x30, 0x30, \8.49 + 0x30, 0x2C, 0x31, 0x39, 0x39, 0x38, 0x2F, 0x30, 0x39, 0x2F, 0x31, 0x36, 0x2C, 0x33, 0x31, 0x35, \8.50 + 0x2D, 0x36, 0x31, 0x32, 0x35, 0x2D, 0x41, 0x47, 0x20, 0x20, 0x20, 0x2C, 0x55, 0x2C, 0x44, 0x2C, \8.51 + 0x4C, 0x2C, 0x52, 0x2C, 0x53, 0x2C, 0x41, 0x2C, 0x42, 0x20, 0x4B, 0x65, 0x79, 0x20, 0x26, 0x20, \8.52 + 0x53, 0x63, 0x61, 0x6E, 0x6E, 0x69, 0x6E, 0x67, 0x20, 0x4C, 0x69, 0x6E, 0x65, 0x20, 0x41, 0x6D, \8.53 + 0x70, 0x2E, 0x20, 0x20 }8.54 +8.55 +8.56 +#define LIGHTGUN_CONFIG_ENTRIES 78.57 +8.58 +static void lightgun_attach( maple_device_t dev );8.59 +static void lightgun_detach( maple_device_t dev );8.60 +static void lightgun_destroy( maple_device_t dev );8.61 +static maple_device_t lightgun_clone( maple_device_t dev );8.62 +static maple_device_t lightgun_new();8.63 +static lxdream_config_entry_t lightgun_get_config( maple_device_t dev );8.64 +static void lightgun_set_config_value( maple_device_t dev, unsigned int key, const gchar *value );8.65 +static int lightgun_get_cond( maple_device_t dev, int function, unsigned char *outbuf,8.66 + unsigned int *outlen );8.67 +static void lightgun_start_gun( maple_device_t dev );8.68 +static void lightgun_stop_gun( maple_device_t dev );8.69 +8.70 +typedef struct lightgun_device {8.71 + struct maple_device dev;8.72 + uint32_t condition[2];8.73 + int gun_active;8.74 + int mouse_x, mouse_y;8.75 + struct lxdream_config_entry config[LIGHTGUN_CONFIG_ENTRIES+1];8.76 +} *lightgun_device_t;8.77 +8.78 +struct maple_device_class lightgun_class = { "Sega Lightgun", lightgun_new };8.79 +8.80 +static struct lightgun_device base_lightgun = {8.81 + { MAPLE_DEVICE_TAG, &lightgun_class, MAPLE_GRAB_NO,8.82 + LIGHTGUN_IDENT, LIGHTGUN_VERSION,8.83 + lightgun_get_config, lightgun_set_config_value,8.84 + lightgun_attach, lightgun_detach, lightgun_destroy,8.85 + lightgun_clone, NULL, NULL, lightgun_get_cond, NULL, NULL, NULL,8.86 + lightgun_start_gun, lightgun_stop_gun},8.87 + {0x0000FFFF, 0x80808080}, 0, -1, -1,8.88 + {{ "dpad left", N_("Dpad left"), CONFIG_TYPE_KEY },8.89 + { "dpad right", N_("Dpad right"), CONFIG_TYPE_KEY },8.90 + { "dpad up", N_("Dpad up"), CONFIG_TYPE_KEY },8.91 + { "dpad down", N_("Dpad down"), CONFIG_TYPE_KEY },8.92 + { "button A", N_("Button A"), CONFIG_TYPE_KEY },8.93 + { "button B", N_("Button B"), CONFIG_TYPE_KEY },8.94 + { "start", N_("Start button"), CONFIG_TYPE_KEY },8.95 + { NULL, CONFIG_TYPE_NONE }} };8.96 +8.97 +static int config_button_map[] = {8.98 + BUTTON_DPAD_LEFT, BUTTON_DPAD_RIGHT, BUTTON_DPAD_UP, BUTTON_DPAD_DOWN,8.99 + BUTTON_A, BUTTON_B, BUTTON_START };8.100 +8.101 +#define lightgun(x) ((lightgun_device_t)(x))8.102 +8.103 +static maple_device_t lightgun_new( )8.104 +{8.105 + lightgun_device_t dev = malloc( sizeof(struct lightgun_device) );8.106 + memcpy( dev, &base_lightgun, sizeof(base_lightgun) );8.107 + return MAPLE_DEVICE(dev);8.108 +}8.109 +8.110 +static maple_device_t lightgun_clone( maple_device_t srcdevice )8.111 +{8.112 + lightgun_device_t src = (lightgun_device_t)srcdevice;8.113 + lightgun_device_t dev = (lightgun_device_t)lightgun_new();8.114 + lxdream_copy_config_list( dev->config, src->config );8.115 + memcpy( dev->condition, src->condition, sizeof(src->condition) );8.116 + return MAPLE_DEVICE(dev);8.117 +}8.118 +8.119 +/**8.120 + * Input callback8.121 + */8.122 +static void lightgun_key_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )8.123 +{8.124 + lightgun_device_t dev = (lightgun_device_t)mdev;8.125 + if( isKeyDown ) {8.126 + dev->condition[0] &= ~value;8.127 + } else {8.128 + dev->condition[0] |= value;8.129 + }8.130 +}8.131 +8.132 +static lxdream_config_entry_t lightgun_get_config( maple_device_t mdev )8.133 +{8.134 + lightgun_device_t dev = (lightgun_device_t)mdev;8.135 + return dev->config;8.136 +}8.137 +8.138 +static void lightgun_set_config_value( maple_device_t mdev, unsigned int key, const gchar *value )8.139 +{8.140 + lightgun_device_t dev = (lightgun_device_t)mdev;8.141 + assert( key < LIGHTGUN_CONFIG_ENTRIES );8.142 +8.143 + input_unregister_key( dev->config[key].value, lightgun_key_callback, dev, config_button_map[key] );8.144 + lxdream_set_config_value( &dev->config[key], value );8.145 + input_register_key( dev->config[key].value, lightgun_key_callback, dev, config_button_map[key] );8.146 +}8.147 +8.148 +static void lightgun_destroy( maple_device_t mdev )8.149 +{8.150 + free( mdev );8.151 +}8.152 +8.153 +8.154 +static void lightgun_mouse_callback( void *mdev, uint32_t buttons, int32_t x, int32_t y, gboolean absolute )8.155 +{8.156 + lightgun_device_t dev = (lightgun_device_t)mdev;8.157 + if( absolute ) {8.158 + dev->mouse_x = x;8.159 + dev->mouse_y = y;8.160 + if( dev->gun_active ) {8.161 + pvr2_queue_gun_event( x, y );8.162 + dev->gun_active = FALSE;8.163 + }8.164 + }8.165 +}8.166 +8.167 +/**8.168 + * Device is being attached to the bus. Go through the config and reserve the8.169 + * keys we need.8.170 + */8.171 +static void lightgun_attach( maple_device_t mdev )8.172 +{8.173 + lightgun_device_t dev = (lightgun_device_t)mdev;8.174 + int i;8.175 + for( i=0; i<LIGHTGUN_CONFIG_ENTRIES; i++ ) {8.176 + input_register_key( dev->config[i].value, lightgun_key_callback, dev, config_button_map[i] );8.177 + }8.178 + input_register_mouse_hook( TRUE, lightgun_mouse_callback, dev );8.179 +8.180 +}8.181 +8.182 +static void lightgun_detach( maple_device_t mdev )8.183 +{8.184 + lightgun_device_t dev = (lightgun_device_t)mdev;8.185 + int i;8.186 + for( i=0; i<LIGHTGUN_CONFIG_ENTRIES; i++ ) {8.187 + input_unregister_key( dev->config[i].value, lightgun_key_callback, dev, config_button_map[i] );8.188 + }8.189 + input_unregister_mouse_hook( lightgun_mouse_callback, dev );8.190 +8.191 +}8.192 +8.193 +8.194 +static int lightgun_get_cond( maple_device_t mdev, int function, unsigned char *outbuf,8.195 + unsigned int *outlen )8.196 +{8.197 + lightgun_device_t dev = (lightgun_device_t)mdev;8.198 + if( function == MAPLE_FUNC_CONTROLLER ) {8.199 + *outlen = 2;8.200 + memcpy( outbuf, dev->condition, 8 );8.201 + return 0;8.202 + } else {8.203 + return MAPLE_ERR_FUNC_UNSUP;8.204 + }8.205 +}8.206 +8.207 +static void lightgun_start_gun( maple_device_t mdev )8.208 +{8.209 + lightgun_device_t dev = (lightgun_device_t)mdev;8.210 + if( dev->mouse_x != -1 && dev->mouse_y != -1 ) {8.211 + pvr2_queue_gun_event( dev->mouse_x, dev->mouse_y );8.212 + } else {8.213 + // Wait for a mouse event8.214 + dev->gun_active = 1;8.215 + }8.216 +}8.217 +8.218 +static void lightgun_stop_gun( maple_device_t mdev )8.219 +{8.220 + lightgun_device_t dev = (lightgun_device_t)mdev;8.221 + dev->gun_active = 0;8.222 + event_cancel( EVENT_GUNPOS );8.223 +}
9.1 --- a/src/maple/maple.c Mon Sep 08 05:13:51 2008 +00009.2 +++ b/src/maple/maple.c Mon Sep 08 07:56:33 2008 +00009.3 @@ -30,7 +30,7 @@9.4 NULL, NULL, NULL };9.6 struct maple_device_class *maple_device_classes[] = {9.7 - &controller_class, &keyboard_class, &mouse_class, NULL };9.8 + &controller_class, &keyboard_class, &lightgun_class, &mouse_class, NULL };9.10 void maple_init( void )9.11 {9.12 @@ -115,6 +115,7 @@9.13 unsigned int cmd, recv_addr, send_addr;9.14 uint32_t return_addr;9.15 unsigned char *return_buf;9.16 + maple_device_t dev;9.18 last = GETBYTE(3) & 0x80; /* indicates last packet */9.19 port = GETBYTE(2) & 0x03;9.20 @@ -122,9 +123,19 @@9.21 length = GETBYTE(0) & 0xFF;9.22 return_addr = GETWORD(4);9.24 - if( mode == 0x07 ) {9.25 + switch( mode ) {9.26 + case 2: /* lightgun */9.27 + dev = maple_devices[port][0];9.28 + if( dev != NULL && dev->start_gun != NULL ) {9.29 + dev->start_gun(dev);9.30 + return; // Pending9.31 + } else {9.32 + asic_event( EVENT_MAPLE_DMA );9.33 + return;9.34 + }9.35 + case 7: /* skip */9.36 buf += 4;9.37 - address +=4; /* skip? */9.38 + address +=4;9.39 continue;9.40 }9.41 if( (return_addr & 0x1C000000) != 0x0C000000 ) {9.42 @@ -159,7 +170,7 @@9.43 }9.44 }9.46 - maple_device_t dev = maple_devices[port][periph];9.47 + dev = maple_devices[port][periph];9.48 if( dev == NULL ) {9.49 /* no device attached */9.50 *((uint32_t *)return_buf) = -1;
10.1 --- a/src/maple/maple.h Mon Sep 08 05:13:51 2008 +000010.2 +++ b/src/maple/maple.h Mon Sep 08 07:56:33 2008 +000010.3 @@ -96,10 +96,13 @@10.4 int function, uint32_t block, unsigned char *outbuf, unsigned int *buflen);10.5 int (*write_block)(struct maple_device *dev,10.6 int function, uint32_t block, unsigned char *inbuf, unsigned int buflen);10.7 + void (*start_gun)(struct maple_device *dev);10.8 + void (*stop_gun)(struct maple_device *dev);10.9 };10.11 extern struct maple_device_class controller_class;10.12 extern struct maple_device_class keyboard_class;10.13 +extern struct maple_device_class lightgun_class;10.14 extern struct maple_device_class mouse_class;10.16 maple_device_t maple_new_device( const gchar *name );
11.1 --- a/src/maple/mouse.c Mon Sep 08 05:13:51 2008 +000011.2 +++ b/src/maple/mouse.c Mon Sep 08 07:56:33 2008 +000011.3 @@ -61,7 +61,7 @@11.4 { MAPLE_DEVICE_TAG, &mouse_class, MAPLE_GRAB_YES,11.5 MOUSE_IDENT, MOUSE_VERSION,11.6 NULL, NULL, mouse_attach, mouse_detach, maple_default_destroy,11.7 - mouse_clone, NULL, NULL, mouse_get_cond, NULL, NULL, NULL },11.8 + mouse_clone, NULL, NULL, mouse_get_cond, NULL, NULL, NULL, NULL, NULL },11.9 0, {0,0,0,0,0,0,0,0},11.10 };
12.1 --- a/src/pvr2/pvr2.c Mon Sep 08 05:13:51 2008 +000012.2 +++ b/src/pvr2/pvr2.c Mon Sep 08 07:56:33 2008 +000012.3 @@ -115,7 +115,8 @@12.4 * Event handler for the scanline callbacks. Fires the corresponding12.5 * ASIC event, and resets the timer for the next field.12.6 */12.7 -static void pvr2_scanline_callback( int eventid ) {12.8 +static void pvr2_scanline_callback( int eventid )12.9 +{12.10 asic_event( eventid );12.11 pvr2_update_raster_posn(sh4r.slice_cycle);12.12 if( eventid == EVENT_SCANLINE1 ) {12.13 @@ -125,6 +126,14 @@12.14 }12.15 }12.17 +static void pvr2_gunpos_callback( int eventid )12.18 +{12.19 + pvr2_update_raster_posn(sh4r.slice_cycle);12.20 + int hpos = pvr2_state.line_remainder * pvr2_state.dot_clock / 1000000;12.21 + MMIO_WRITE( PVR2, GUNPOS, ((pvr2_state.line_count<<16)|(hpos&0x3FF)) );12.22 + asic_event( EVENT_MAPLE_DMA );12.23 +}12.24 +12.25 static void pvr2_init( void )12.26 {12.27 int i;12.28 @@ -134,6 +143,7 @@12.29 register_event_callback( EVENT_HPOS, pvr2_hpos_callback );12.30 register_event_callback( EVENT_SCANLINE1, pvr2_scanline_callback );12.31 register_event_callback( EVENT_SCANLINE2, pvr2_scanline_callback );12.32 + register_event_callback( EVENT_GUNPOS, pvr2_gunpos_callback );12.33 video_base = mem_get_region_by_name( MEM_REGION_VIDEO );12.34 texcache_init();12.35 pvr2_reset();12.36 @@ -789,6 +799,13 @@12.37 }12.38 }12.40 +void pvr2_queue_gun_event( int xpos, int ypos )12.41 +{12.42 + pvr2_update_raster_posn(sh4r.slice_cycle);12.43 + pvr2_schedule_scanline_event( EVENT_GUNPOS, (ypos >> 1) + pvr2_state.vsync_lines, 0,12.44 + (1000000 * xpos / pvr2_state.dot_clock) + pvr2_state.hsync_width_ns );12.45 +}12.46 +12.47 MMIO_REGION_READ_FN( PVR2, reg )12.48 {12.49 switch( reg ) {
13.1 --- a/src/pvr2/pvr2.h Mon Sep 08 05:13:51 2008 +000013.2 +++ b/src/pvr2/pvr2.h Mon Sep 08 07:56:33 2008 +000013.3 @@ -334,6 +334,13 @@13.5 int pvr2_render_save_scene( const gchar *filename );13.7 +/**13.8 + * Queue a gun position event to occur at the specified position. Unless13.9 + * cancelled, when the display reaches the position:13.10 + * GUNPOS is updated with the position, and13.11 + * EVENT_MAPLE_DMA is fired.13.12 + */13.13 +void pvr2_queue_gun_event( int xpos, int ypos );13.15 /************************* Rendering support macros **************************/13.16 #define POLY1_DEPTH_MODE(poly1) ( pvr2_poly_depthmode[(poly1)>>29] )
.