# HG changeset patch # User nkeynes # Date 1254902036 -36000 # Node ID 136fc24d17ef17043fdba641d6ac5cbe487d20f8 # Parent 18c164e8aec49be5c1c055b054babccefa8bc065 Create a host attachment for the SCIF serial port. By default, uses /dev/console Add general fd listening to netutil, and rename to ioutil Add SCIF update on port read/write - fixes KOS timing problems but needs to be redone properly. --- a/src/Makefile.am Mon Aug 03 08:41:11 2009 +1000 +++ b/src/Makefile.am Wed Oct 07 17:53:56 2009 +1000 @@ -44,7 +44,7 @@ gettext.h mem.c mem.h sdram.c mmio.h watch.c \ asic.c asic.h clock.h serial.h \ syscall.c syscall.h bios.c dcload.c gdbserver.c \ - netutil.c netutil.h lxpaths.c lxpaths.h \ + ioutil.c ioutil.h lxpaths.c lxpaths.h \ gdrom/ide.c gdrom/ide.h gdrom/packet.h gdrom/gdimage.c \ gdrom/gdrom.c gdrom/gdrom.h gdrom/nrg.c gdrom/cdi.c gdrom/gdi.c \ gdrom/edc_ecc.c gdrom/ecc.h gdrom/edc_crctable.h gdrom/edc_encoder.h \ @@ -69,6 +69,7 @@ display.c display.h dckeysyms.h \ drivers/audio_null.c drivers/video_null.c drivers/cd_mmc.c \ drivers/video_gl.c drivers/video_gl.h drivers/gl_fbo.c \ + drivers/serial_unix.c \ sh4/sh4.def sh4/sh4core.in sh4/sh4x86.in sh4/sh4dasm.in sh4/sh4stat.in \ hotkeys.c hotkeys.h lxdream_CPPFLAGS = @LXDREAMCPPFLAGS@ @@ -101,14 +102,14 @@ gtkui/gtk_win.c gtkui/gtkcb.c gtkui/gtk_cfg.c \ gtkui/gtk_mmio.c gtkui/gtk_debug.c gtkui/gtk_dump.c \ gtkui/gtk_ctrl.c gtkui/gtk_gd.c \ - drivers/net_glib.c drivers/video_gtk.c + drivers/io_glib.c drivers/video_gtk.c endif if GUI_COCOA lxdream_SOURCES += cocoaui/cocoaui.m cocoaui/cocoaui.h cocoaui/cocoa_cfg.m \ cocoaui/cocoa_win.m cocoaui/cocoa_gd.m cocoaui/cocoa_prefs.m \ cocoaui/cocoa_ctrl.m cocoaui/paths_osx.m \ - drivers/net_osx.m drivers/video_osx.m \ + drivers/io_osx.m drivers/video_osx.m \ drivers/mac_keymap.h drivers/mac_keymap.txt else lxdream_SOURCES += paths_unix.c --- a/src/Makefile.in Mon Aug 03 08:41:11 2009 +1000 +++ b/src/Makefile.in Wed Oct 07 17:53:56 2009 +1000 @@ -55,12 +55,12 @@ @GUI_GTK_TRUE@ gtkui/gtk_win.c gtkui/gtkcb.c gtkui/gtk_cfg.c \ @GUI_GTK_TRUE@ gtkui/gtk_mmio.c gtkui/gtk_debug.c gtkui/gtk_dump.c \ @GUI_GTK_TRUE@ gtkui/gtk_ctrl.c gtkui/gtk_gd.c \ -@GUI_GTK_TRUE@ drivers/net_glib.c drivers/video_gtk.c +@GUI_GTK_TRUE@ drivers/io_glib.c drivers/video_gtk.c @GUI_COCOA_TRUE@am__append_5 = cocoaui/cocoaui.m cocoaui/cocoaui.h cocoaui/cocoa_cfg.m \ @GUI_COCOA_TRUE@ cocoaui/cocoa_win.m cocoaui/cocoa_gd.m cocoaui/cocoa_prefs.m \ @GUI_COCOA_TRUE@ cocoaui/cocoa_ctrl.m cocoaui/paths_osx.m \ -@GUI_COCOA_TRUE@ drivers/net_osx.m drivers/video_osx.m \ +@GUI_COCOA_TRUE@ drivers/io_osx.m drivers/video_osx.m \ @GUI_COCOA_TRUE@ drivers/mac_keymap.h drivers/mac_keymap.txt @GUI_COCOA_FALSE@am__append_6 = paths_unix.c @@ -141,8 +141,8 @@ am__lxdream_SOURCES_DIST = main.c version.c config.c config.h \ lxdream.h dream.h gui.h cpu.h hook.h gettext.h mem.c mem.h \ sdram.c mmio.h watch.c asic.c asic.h clock.h serial.h \ - syscall.c syscall.h bios.c dcload.c gdbserver.c netutil.c \ - netutil.h lxpaths.c lxpaths.h gdrom/ide.c gdrom/ide.h \ + syscall.c syscall.h bios.c dcload.c gdbserver.c ioutil.c \ + ioutil.h lxpaths.c lxpaths.h gdrom/ide.c gdrom/ide.h \ gdrom/packet.h gdrom/gdimage.c gdrom/gdrom.c gdrom/gdrom.h \ gdrom/nrg.c gdrom/cdi.c gdrom/gdi.c gdrom/edc_ecc.c \ gdrom/ecc.h gdrom/edc_crctable.h gdrom/edc_encoder.h \ @@ -166,9 +166,9 @@ vmu/vmulist.c vmu/vmulist.h display.c display.h dckeysyms.h \ drivers/audio_null.c drivers/video_null.c drivers/cd_mmc.c \ drivers/video_gl.c drivers/video_gl.h drivers/gl_fbo.c \ - sh4/sh4.def sh4/sh4core.in sh4/sh4x86.in sh4/sh4dasm.in \ - sh4/sh4stat.in hotkeys.c hotkeys.h plugin.c plugin.h \ - sh4/sh4x86.c xlat/x86/x86op.h xlat/x86/ia32abi.h \ + drivers/serial_unix.c sh4/sh4.def sh4/sh4core.in sh4/sh4x86.in \ + sh4/sh4dasm.in sh4/sh4stat.in hotkeys.c hotkeys.h plugin.c \ + plugin.h sh4/sh4x86.c xlat/x86/x86op.h xlat/x86/ia32abi.h \ xlat/x86/amd64abi.h sh4/sh4trans.c sh4/sh4trans.h sh4/mmux86.c \ x86dasm/x86dasm.c x86dasm/x86dasm.h x86dasm/i386-dis.c \ x86dasm/dis-init.c x86dasm/dis-buf.c x86dasm/ansidecl.h \ @@ -176,10 +176,10 @@ x86dasm/sysdep.h gtkui/gtkui.c gtkui/gtkui.h gtkui/gtk_win.c \ gtkui/gtkcb.c gtkui/gtk_cfg.c gtkui/gtk_mmio.c \ gtkui/gtk_debug.c gtkui/gtk_dump.c gtkui/gtk_ctrl.c \ - gtkui/gtk_gd.c drivers/net_glib.c drivers/video_gtk.c \ + gtkui/gtk_gd.c drivers/io_glib.c drivers/video_gtk.c \ cocoaui/cocoaui.m cocoaui/cocoaui.h cocoaui/cocoa_cfg.m \ cocoaui/cocoa_win.m cocoaui/cocoa_gd.m cocoaui/cocoa_prefs.m \ - cocoaui/cocoa_ctrl.m cocoaui/paths_osx.m drivers/net_osx.m \ + cocoaui/cocoa_ctrl.m cocoaui/paths_osx.m drivers/io_osx.m \ drivers/video_osx.m drivers/mac_keymap.h \ drivers/mac_keymap.txt paths_unix.c drivers/video_gdk.c \ drivers/video_glx.c drivers/video_glx.h drivers/video_nsgl.m \ @@ -205,7 +205,7 @@ @GUI_GTK_TRUE@ lxdream-gtk_dump.$(OBJEXT) \ @GUI_GTK_TRUE@ lxdream-gtk_ctrl.$(OBJEXT) \ @GUI_GTK_TRUE@ lxdream-gtk_gd.$(OBJEXT) \ -@GUI_GTK_TRUE@ lxdream-net_glib.$(OBJEXT) \ +@GUI_GTK_TRUE@ lxdream-io_glib.$(OBJEXT) \ @GUI_GTK_TRUE@ lxdream-video_gtk.$(OBJEXT) @GUI_COCOA_TRUE@am__objects_4 = lxdream-cocoaui.$(OBJEXT) \ @GUI_COCOA_TRUE@ lxdream-cocoa_cfg.$(OBJEXT) \ @@ -214,7 +214,7 @@ @GUI_COCOA_TRUE@ lxdream-cocoa_prefs.$(OBJEXT) \ @GUI_COCOA_TRUE@ lxdream-cocoa_ctrl.$(OBJEXT) \ @GUI_COCOA_TRUE@ lxdream-paths_osx.$(OBJEXT) \ -@GUI_COCOA_TRUE@ lxdream-net_osx.$(OBJEXT) \ +@GUI_COCOA_TRUE@ lxdream-io_osx.$(OBJEXT) \ @GUI_COCOA_TRUE@ lxdream-video_osx.$(OBJEXT) @GUI_COCOA_FALSE@am__objects_5 = lxdream-paths_unix.$(OBJEXT) @VIDEO_OSMESA_TRUE@am__objects_6 = lxdream-video_gdk.$(OBJEXT) @@ -236,7 +236,7 @@ lxdream-sdram.$(OBJEXT) lxdream-watch.$(OBJEXT) \ lxdream-asic.$(OBJEXT) lxdream-syscall.$(OBJEXT) \ lxdream-bios.$(OBJEXT) lxdream-dcload.$(OBJEXT) \ - lxdream-gdbserver.$(OBJEXT) lxdream-netutil.$(OBJEXT) \ + lxdream-gdbserver.$(OBJEXT) lxdream-ioutil.$(OBJEXT) \ lxdream-lxpaths.$(OBJEXT) lxdream-ide.$(OBJEXT) \ lxdream-gdimage.$(OBJEXT) lxdream-gdrom.$(OBJEXT) \ lxdream-nrg.$(OBJEXT) lxdream-cdi.$(OBJEXT) \ @@ -266,13 +266,14 @@ lxdream-vmulist.$(OBJEXT) lxdream-display.$(OBJEXT) \ lxdream-audio_null.$(OBJEXT) lxdream-video_null.$(OBJEXT) \ lxdream-cd_mmc.$(OBJEXT) lxdream-video_gl.$(OBJEXT) \ - lxdream-gl_fbo.$(OBJEXT) lxdream-hotkeys.$(OBJEXT) \ - $(am__objects_1) $(am__objects_2) $(am__objects_3) \ - $(am__objects_4) $(am__objects_5) $(am__objects_6) \ - $(am__objects_7) $(am__objects_8) $(am__objects_9) \ - $(am__objects_10) $(am__objects_11) $(am__objects_12) \ - $(am__objects_13) $(am__objects_14) $(am__objects_15) \ - $(am__objects_16) $(am__objects_17) $(am__objects_18) + lxdream-gl_fbo.$(OBJEXT) lxdream-serial_unix.$(OBJEXT) \ + lxdream-hotkeys.$(OBJEXT) $(am__objects_1) $(am__objects_2) \ + $(am__objects_3) $(am__objects_4) $(am__objects_5) \ + $(am__objects_6) $(am__objects_7) $(am__objects_8) \ + $(am__objects_9) $(am__objects_10) $(am__objects_11) \ + $(am__objects_12) $(am__objects_13) $(am__objects_14) \ + $(am__objects_15) $(am__objects_16) $(am__objects_17) \ + $(am__objects_18) lxdream_OBJECTS = $(am_lxdream_OBJECTS) lxdream_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ @@ -542,7 +543,7 @@ lxdream_SOURCES = main.c version.c config.c config.h lxdream.h dream.h \ gui.h cpu.h hook.h gettext.h mem.c mem.h sdram.c mmio.h \ watch.c asic.c asic.h clock.h serial.h syscall.c syscall.h \ - bios.c dcload.c gdbserver.c netutil.c netutil.h lxpaths.c \ + bios.c dcload.c gdbserver.c ioutil.c ioutil.h lxpaths.c \ lxpaths.h gdrom/ide.c gdrom/ide.h gdrom/packet.h \ gdrom/gdimage.c gdrom/gdrom.c gdrom/gdrom.h gdrom/nrg.c \ gdrom/cdi.c gdrom/gdi.c gdrom/edc_ecc.c gdrom/ecc.h \ @@ -567,14 +568,14 @@ vmu/vmulist.c vmu/vmulist.h display.c display.h dckeysyms.h \ drivers/audio_null.c drivers/video_null.c drivers/cd_mmc.c \ drivers/video_gl.c drivers/video_gl.h drivers/gl_fbo.c \ - sh4/sh4.def sh4/sh4core.in sh4/sh4x86.in sh4/sh4dasm.in \ - sh4/sh4stat.in hotkeys.c hotkeys.h $(am__append_1) \ - $(am__append_2) $(am__append_4) $(am__append_5) \ - $(am__append_6) $(am__append_7) $(am__append_8) \ - $(am__append_9) $(am__append_10) $(am__append_17) \ - $(am__append_19) $(am__append_21) $(am__append_23) \ - $(am__append_25) $(am__append_27) $(am__append_28) \ - $(am__append_29) $(am__append_30) + drivers/serial_unix.c sh4/sh4.def sh4/sh4core.in sh4/sh4x86.in \ + sh4/sh4dasm.in sh4/sh4stat.in hotkeys.c hotkeys.h \ + $(am__append_1) $(am__append_2) $(am__append_4) \ + $(am__append_5) $(am__append_6) $(am__append_7) \ + $(am__append_8) $(am__append_9) $(am__append_10) \ + $(am__append_17) $(am__append_19) $(am__append_21) \ + $(am__append_23) $(am__append_25) $(am__append_27) \ + $(am__append_28) $(am__append_29) $(am__append_30) lxdream_CPPFLAGS = @LXDREAMCPPFLAGS@ @BUILD_SH4X86_TRUE@test_testsh4x86_LDADD = @LXDREAM_LIBS@ @GLIB_LIBS@ @GTK_LIBS@ @LIBPNG_LIBS@ @BUILD_SH4X86_TRUE@test_testsh4x86_CPPFLAGS = @LXDREAMCPPFLAGS@ @@ -798,6 +799,9 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-ide.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-input_lirc.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-intc.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-io_glib.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-io_osx.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-ioutil.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-joy_linux.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-kbd.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-lightgun.Po@am__quote@ @@ -809,9 +813,6 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-mmu.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-mmux86.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-mouse.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-net_glib.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-net_osx.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-netutil.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-nrg.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-osx_iokit.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-paths_osx.Po@am__quote@ @@ -825,6 +826,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-scene.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-scif.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-sdram.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-serial_unix.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-sh4.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-sh4core.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-sh4dasm.Po@am__quote@ @@ -1090,19 +1092,19 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-gdbserver.obj `if test -f 'gdbserver.c'; then $(CYGPATH_W) 'gdbserver.c'; else $(CYGPATH_W) '$(srcdir)/gdbserver.c'; fi` -lxdream-netutil.o: netutil.c -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-netutil.o -MD -MP -MF "$(DEPDIR)/lxdream-netutil.Tpo" -c -o lxdream-netutil.o `test -f 'netutil.c' || echo '$(srcdir)/'`netutil.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-netutil.Tpo" "$(DEPDIR)/lxdream-netutil.Po"; else rm -f "$(DEPDIR)/lxdream-netutil.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='netutil.c' object='lxdream-netutil.o' libtool=no @AMDEPBACKSLASH@ +lxdream-ioutil.o: ioutil.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-ioutil.o -MD -MP -MF "$(DEPDIR)/lxdream-ioutil.Tpo" -c -o lxdream-ioutil.o `test -f 'ioutil.c' || echo '$(srcdir)/'`ioutil.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-ioutil.Tpo" "$(DEPDIR)/lxdream-ioutil.Po"; else rm -f "$(DEPDIR)/lxdream-ioutil.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='ioutil.c' object='lxdream-ioutil.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-netutil.o `test -f 'netutil.c' || echo '$(srcdir)/'`netutil.c +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-ioutil.o `test -f 'ioutil.c' || echo '$(srcdir)/'`ioutil.c -lxdream-netutil.obj: netutil.c -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-netutil.obj -MD -MP -MF "$(DEPDIR)/lxdream-netutil.Tpo" -c -o lxdream-netutil.obj `if test -f 'netutil.c'; then $(CYGPATH_W) 'netutil.c'; else $(CYGPATH_W) '$(srcdir)/netutil.c'; fi`; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-netutil.Tpo" "$(DEPDIR)/lxdream-netutil.Po"; else rm -f "$(DEPDIR)/lxdream-netutil.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='netutil.c' object='lxdream-netutil.obj' libtool=no @AMDEPBACKSLASH@ +lxdream-ioutil.obj: ioutil.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-ioutil.obj -MD -MP -MF "$(DEPDIR)/lxdream-ioutil.Tpo" -c -o lxdream-ioutil.obj `if test -f 'ioutil.c'; then $(CYGPATH_W) 'ioutil.c'; else $(CYGPATH_W) '$(srcdir)/ioutil.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-ioutil.Tpo" "$(DEPDIR)/lxdream-ioutil.Po"; else rm -f "$(DEPDIR)/lxdream-ioutil.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='ioutil.c' object='lxdream-ioutil.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-netutil.obj `if test -f 'netutil.c'; then $(CYGPATH_W) 'netutil.c'; else $(CYGPATH_W) '$(srcdir)/netutil.c'; fi` +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-ioutil.obj `if test -f 'ioutil.c'; then $(CYGPATH_W) 'ioutil.c'; else $(CYGPATH_W) '$(srcdir)/ioutil.c'; fi` lxdream-lxpaths.o: lxpaths.c @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-lxpaths.o -MD -MP -MF "$(DEPDIR)/lxdream-lxpaths.Tpo" -c -o lxdream-lxpaths.o `test -f 'lxpaths.c' || echo '$(srcdir)/'`lxpaths.c; \ @@ -1930,6 +1932,20 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-gl_fbo.obj `if test -f 'drivers/gl_fbo.c'; then $(CYGPATH_W) 'drivers/gl_fbo.c'; else $(CYGPATH_W) '$(srcdir)/drivers/gl_fbo.c'; fi` +lxdream-serial_unix.o: drivers/serial_unix.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-serial_unix.o -MD -MP -MF "$(DEPDIR)/lxdream-serial_unix.Tpo" -c -o lxdream-serial_unix.o `test -f 'drivers/serial_unix.c' || echo '$(srcdir)/'`drivers/serial_unix.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-serial_unix.Tpo" "$(DEPDIR)/lxdream-serial_unix.Po"; else rm -f "$(DEPDIR)/lxdream-serial_unix.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/serial_unix.c' object='lxdream-serial_unix.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-serial_unix.o `test -f 'drivers/serial_unix.c' || echo '$(srcdir)/'`drivers/serial_unix.c + +lxdream-serial_unix.obj: drivers/serial_unix.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-serial_unix.obj -MD -MP -MF "$(DEPDIR)/lxdream-serial_unix.Tpo" -c -o lxdream-serial_unix.obj `if test -f 'drivers/serial_unix.c'; then $(CYGPATH_W) 'drivers/serial_unix.c'; else $(CYGPATH_W) '$(srcdir)/drivers/serial_unix.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-serial_unix.Tpo" "$(DEPDIR)/lxdream-serial_unix.Po"; else rm -f "$(DEPDIR)/lxdream-serial_unix.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/serial_unix.c' object='lxdream-serial_unix.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-serial_unix.obj `if test -f 'drivers/serial_unix.c'; then $(CYGPATH_W) 'drivers/serial_unix.c'; else $(CYGPATH_W) '$(srcdir)/drivers/serial_unix.c'; fi` + lxdream-hotkeys.o: hotkeys.c @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-hotkeys.o -MD -MP -MF "$(DEPDIR)/lxdream-hotkeys.Tpo" -c -o lxdream-hotkeys.o `test -f 'hotkeys.c' || echo '$(srcdir)/'`hotkeys.c; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-hotkeys.Tpo" "$(DEPDIR)/lxdream-hotkeys.Po"; else rm -f "$(DEPDIR)/lxdream-hotkeys.Tpo"; exit 1; fi @@ -2182,19 +2198,19 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-gtk_gd.obj `if test -f 'gtkui/gtk_gd.c'; then $(CYGPATH_W) 'gtkui/gtk_gd.c'; else $(CYGPATH_W) '$(srcdir)/gtkui/gtk_gd.c'; fi` -lxdream-net_glib.o: drivers/net_glib.c -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-net_glib.o -MD -MP -MF "$(DEPDIR)/lxdream-net_glib.Tpo" -c -o lxdream-net_glib.o `test -f 'drivers/net_glib.c' || echo '$(srcdir)/'`drivers/net_glib.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-net_glib.Tpo" "$(DEPDIR)/lxdream-net_glib.Po"; else rm -f "$(DEPDIR)/lxdream-net_glib.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/net_glib.c' object='lxdream-net_glib.o' libtool=no @AMDEPBACKSLASH@ +lxdream-io_glib.o: drivers/io_glib.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-io_glib.o -MD -MP -MF "$(DEPDIR)/lxdream-io_glib.Tpo" -c -o lxdream-io_glib.o `test -f 'drivers/io_glib.c' || echo '$(srcdir)/'`drivers/io_glib.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-io_glib.Tpo" "$(DEPDIR)/lxdream-io_glib.Po"; else rm -f "$(DEPDIR)/lxdream-io_glib.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/io_glib.c' object='lxdream-io_glib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-net_glib.o `test -f 'drivers/net_glib.c' || echo '$(srcdir)/'`drivers/net_glib.c +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-io_glib.o `test -f 'drivers/io_glib.c' || echo '$(srcdir)/'`drivers/io_glib.c -lxdream-net_glib.obj: drivers/net_glib.c -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-net_glib.obj -MD -MP -MF "$(DEPDIR)/lxdream-net_glib.Tpo" -c -o lxdream-net_glib.obj `if test -f 'drivers/net_glib.c'; then $(CYGPATH_W) 'drivers/net_glib.c'; else $(CYGPATH_W) '$(srcdir)/drivers/net_glib.c'; fi`; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-net_glib.Tpo" "$(DEPDIR)/lxdream-net_glib.Po"; else rm -f "$(DEPDIR)/lxdream-net_glib.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/net_glib.c' object='lxdream-net_glib.obj' libtool=no @AMDEPBACKSLASH@ +lxdream-io_glib.obj: drivers/io_glib.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-io_glib.obj -MD -MP -MF "$(DEPDIR)/lxdream-io_glib.Tpo" -c -o lxdream-io_glib.obj `if test -f 'drivers/io_glib.c'; then $(CYGPATH_W) 'drivers/io_glib.c'; else $(CYGPATH_W) '$(srcdir)/drivers/io_glib.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-io_glib.Tpo" "$(DEPDIR)/lxdream-io_glib.Po"; else rm -f "$(DEPDIR)/lxdream-io_glib.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/io_glib.c' object='lxdream-io_glib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-net_glib.obj `if test -f 'drivers/net_glib.c'; then $(CYGPATH_W) 'drivers/net_glib.c'; else $(CYGPATH_W) '$(srcdir)/drivers/net_glib.c'; fi` +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-io_glib.obj `if test -f 'drivers/io_glib.c'; then $(CYGPATH_W) 'drivers/io_glib.c'; else $(CYGPATH_W) '$(srcdir)/drivers/io_glib.c'; fi` lxdream-video_gtk.o: drivers/video_gtk.c @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-video_gtk.o -MD -MP -MF "$(DEPDIR)/lxdream-video_gtk.Tpo" -c -o lxdream-video_gtk.o `test -f 'drivers/video_gtk.c' || echo '$(srcdir)/'`drivers/video_gtk.c; \ @@ -2658,19 +2674,19 @@ @AMDEP_TRUE@@am__fastdepOBJC_FALSE@ DEPDIR=$(DEPDIR) $(OBJCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepOBJC_FALSE@ $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) -c -o lxdream-paths_osx.obj `if test -f 'cocoaui/paths_osx.m'; then $(CYGPATH_W) 'cocoaui/paths_osx.m'; else $(CYGPATH_W) '$(srcdir)/cocoaui/paths_osx.m'; fi` -lxdream-net_osx.o: drivers/net_osx.m -@am__fastdepOBJC_TRUE@ if $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) -MT lxdream-net_osx.o -MD -MP -MF "$(DEPDIR)/lxdream-net_osx.Tpo" -c -o lxdream-net_osx.o `test -f 'drivers/net_osx.m' || echo '$(srcdir)/'`drivers/net_osx.m; \ -@am__fastdepOBJC_TRUE@ then mv -f "$(DEPDIR)/lxdream-net_osx.Tpo" "$(DEPDIR)/lxdream-net_osx.Po"; else rm -f "$(DEPDIR)/lxdream-net_osx.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepOBJC_FALSE@ source='drivers/net_osx.m' object='lxdream-net_osx.o' libtool=no @AMDEPBACKSLASH@ +lxdream-io_osx.o: drivers/io_osx.m +@am__fastdepOBJC_TRUE@ if $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) -MT lxdream-io_osx.o -MD -MP -MF "$(DEPDIR)/lxdream-io_osx.Tpo" -c -o lxdream-io_osx.o `test -f 'drivers/io_osx.m' || echo '$(srcdir)/'`drivers/io_osx.m; \ +@am__fastdepOBJC_TRUE@ then mv -f "$(DEPDIR)/lxdream-io_osx.Tpo" "$(DEPDIR)/lxdream-io_osx.Po"; else rm -f "$(DEPDIR)/lxdream-io_osx.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepOBJC_FALSE@ source='drivers/io_osx.m' object='lxdream-io_osx.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepOBJC_FALSE@ DEPDIR=$(DEPDIR) $(OBJCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepOBJC_FALSE@ $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) -c -o lxdream-net_osx.o `test -f 'drivers/net_osx.m' || echo '$(srcdir)/'`drivers/net_osx.m +@am__fastdepOBJC_FALSE@ $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) -c -o lxdream-io_osx.o `test -f 'drivers/io_osx.m' || echo '$(srcdir)/'`drivers/io_osx.m -lxdream-net_osx.obj: drivers/net_osx.m -@am__fastdepOBJC_TRUE@ if $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) -MT lxdream-net_osx.obj -MD -MP -MF "$(DEPDIR)/lxdream-net_osx.Tpo" -c -o lxdream-net_osx.obj `if test -f 'drivers/net_osx.m'; then $(CYGPATH_W) 'drivers/net_osx.m'; else $(CYGPATH_W) '$(srcdir)/drivers/net_osx.m'; fi`; \ -@am__fastdepOBJC_TRUE@ then mv -f "$(DEPDIR)/lxdream-net_osx.Tpo" "$(DEPDIR)/lxdream-net_osx.Po"; else rm -f "$(DEPDIR)/lxdream-net_osx.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepOBJC_FALSE@ source='drivers/net_osx.m' object='lxdream-net_osx.obj' libtool=no @AMDEPBACKSLASH@ +lxdream-io_osx.obj: drivers/io_osx.m +@am__fastdepOBJC_TRUE@ if $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) -MT lxdream-io_osx.obj -MD -MP -MF "$(DEPDIR)/lxdream-io_osx.Tpo" -c -o lxdream-io_osx.obj `if test -f 'drivers/io_osx.m'; then $(CYGPATH_W) 'drivers/io_osx.m'; else $(CYGPATH_W) '$(srcdir)/drivers/io_osx.m'; fi`; \ +@am__fastdepOBJC_TRUE@ then mv -f "$(DEPDIR)/lxdream-io_osx.Tpo" "$(DEPDIR)/lxdream-io_osx.Po"; else rm -f "$(DEPDIR)/lxdream-io_osx.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepOBJC_FALSE@ source='drivers/io_osx.m' object='lxdream-io_osx.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepOBJC_FALSE@ DEPDIR=$(DEPDIR) $(OBJCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepOBJC_FALSE@ $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) -c -o lxdream-net_osx.obj `if test -f 'drivers/net_osx.m'; then $(CYGPATH_W) 'drivers/net_osx.m'; else $(CYGPATH_W) '$(srcdir)/drivers/net_osx.m'; fi` +@am__fastdepOBJC_FALSE@ $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) -c -o lxdream-io_osx.obj `if test -f 'drivers/io_osx.m'; then $(CYGPATH_W) 'drivers/io_osx.m'; else $(CYGPATH_W) '$(srcdir)/drivers/io_osx.m'; fi` lxdream-video_osx.o: drivers/video_osx.m @am__fastdepOBJC_TRUE@ if $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) -MT lxdream-video_osx.o -MD -MP -MF "$(DEPDIR)/lxdream-video_osx.Tpo" -c -o lxdream-video_osx.o `test -f 'drivers/video_osx.m' || echo '$(srcdir)/'`drivers/video_osx.m; \ --- a/src/config.c Mon Aug 03 08:41:11 2009 +1000 +++ b/src/config.c Wed Oct 07 17:53:56 2009 +1000 @@ -33,6 +33,7 @@ #define MAX_ROOT_GROUPS 16 extern struct lxdream_config_group hotkeys_group; +extern struct lxdream_config_group serial_group; gboolean lxdream_load_config_file( const gchar *filename ); gboolean lxdream_save_config_file( const gchar *filename ); @@ -53,11 +54,6 @@ { "quick state", NULL, CONFIG_TYPE_INTEGER, "0" }, { NULL, CONFIG_TYPE_NONE }} }; -static struct lxdream_config_group serial_group = - { "serial", NULL, NULL, NULL, - {{ "device", N_("Serial device"), CONFIG_TYPE_FILE, "/dev/ttyS1" }, - { NULL, CONFIG_TYPE_NONE }} }; - /** * Dummy group for controllers (handled specially) */ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/drivers/io_glib.c Wed Oct 07 17:53:56 2009 +1000 @@ -0,0 +1,85 @@ +/** + * $Id$ + * + * Glib-based networking support functions. Currently this is just for activity callbacks. + * + * Copyright (c) 2009 Nathan Keynes. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include "ioutil.h" + +struct io_glib_cbinfo { + io_callback_t callback; + guint sourceid; + void * cbdata; + void (*cbdealloc)(void *); +}; + +static gboolean io_glib_callback( GIOChannel *source, GIOCondition cond, gpointer data ) +{ + struct io_glib_cbinfo *cbinfo = (struct io_glib_cbinfo *)data; + return cbinfo->callback( g_io_channel_unix_get_fd(source), cbinfo->cbdata); +} + +static void io_glib_release( void *data ) +{ + struct io_glib_cbinfo *cbinfo = (struct io_glib_cbinfo *)data; + if( cbinfo->cbdealloc ) { + cbinfo->cbdealloc( cbinfo->cbdata ); + } + free(cbinfo); +} + +/** + * Register a TCP server socket listener on an already open (and listening) + * socket. The socket must not have been previously registered. + * @return TRUE on success, FALSE on failure. + * + * Defined in netutil.h + */ +io_listener_t io_register_tcp_listener( int fd, io_callback_t callback, void *data, void (*dealloc)(void*) ) +{ + return io_register_listener( fd, callback, data, dealloc ); +} + +io_listener_t io_register_listener( int fd, io_callback_t callback, void *data, void (*dealloc)(void *) ) +{ + struct io_glib_cbinfo *cbinfo = malloc( sizeof(struct io_glib_cbinfo) ); + assert(cbinfo != NULL); + + cbinfo->callback = callback; + cbinfo->cbdata = data; + cbinfo->cbdealloc = dealloc; + + /** + * Note magic here: the watch creates an event source which holds a + * reference to the channel. We unref the channel so that the channel then + * is automatically released when the event source goes away. + */ + GIOChannel *chan = g_io_channel_unix_new(fd); + g_io_channel_set_encoding( chan, NULL, NULL ); + g_io_channel_set_buffered(chan, FALSE); + cbinfo->sourceid = g_io_add_watch_full( chan, 0, G_IO_IN, io_glib_callback, cbinfo, io_glib_release ); + g_io_channel_unref( chan ); + return cbinfo; +} + + +void io_unregister_listener( io_listener_t data ) +{ + struct io_glib_cbinfo *cbinfo = (struct io_glib_cbinfo *)data; + g_source_remove(cbinfo->sourceid); +} --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/drivers/io_osx.m Wed Oct 07 17:53:56 2009 +1000 @@ -0,0 +1,132 @@ +/** + * $Id$ + * + * OS X networking support functions. Currently this is just for activity callbacks. + * + * Copyright (c) 2009 Nathan Keynes. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include "ioutil.h" + +struct io_osx_cbinfo { + int fd; + io_callback_t callback; + void * cbdata; + void (*cbdealloc)(void *); + void *fdRef; + CFRunLoopSourceRef sourceRef; + + struct io_osx_cbinfo *next; +}; + +static struct io_osx_cbinfo *cbinfo_list = NULL; + +void io_unregister_callback( struct io_osx_cbinfo *cbinfo ) +{ + CFRunLoopRemoveSource( CFRunLoopGetCurrent(), cbinfo->sourceRef, kCFRunLoopCommonModes ); + CFRelease(cbinfo->sourceRef); + cbinfo->sourceRef = NULL; + CFRelease(cbinfo->fdRef); /* Note this implicitly releases the cbinfo itself as well */ +} + +static void io_osx_net_callback( CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void *unused, void *data ) +{ + struct io_osx_cbinfo *cbinfo = (struct io_osx_cbinfo *)data; + if(!cbinfo->callback( CFSocketGetNative(s), cbinfo->cbdata) ) { + io_unregister_callback(cbinfo); + } +} + +static void io_osx_fd_callback( CFFileDescriptorRef f, CFOptionFlags type, void *data ) +{ + struct io_osx_cbinfo *cbinfo = (struct io_osx_cbinfo *)data; + if(!cbinfo->callback( CFFileDescriptorGetNativeDescriptor(f), cbinfo->cbdata) ) { + io_unregister_callback(cbinfo); + } +} + +static void io_osx_release( const void *data ) +{ + struct io_osx_cbinfo *cbinfo = (struct io_osx_cbinfo *)data; + if( cbinfo->cbdealloc != NULL ) { + cbinfo->cbdealloc(cbinfo->cbdata); + } + free( cbinfo ); +} + +/** + * Register a TCP server socket listener on an already open (and listening) + * socket. The socket must not have been previously registered. + * @return TRUE on success, FALSE on failure. + * + * Defined in netutil.h + */ +io_listener_t io_register_tcp_listener( int fd, io_callback_t callback, void *data, void (*dealloc)(void*) ) +{ + CFSocketContext socketContext; + struct io_osx_cbinfo *cbinfo = malloc( sizeof(struct io_osx_cbinfo) ); + assert(cbinfo != NULL); + + cbinfo->callback = callback; + cbinfo->cbdata = data; + cbinfo->cbdealloc = dealloc; + socketContext.version = 0; + socketContext.info = cbinfo; + socketContext.retain = NULL; + socketContext.release = io_osx_release; + socketContext.copyDescription = NULL; + + CFSocketRef ref = CFSocketCreateWithNative( kCFAllocatorDefault, fd, kCFSocketReadCallBack, + io_osx_net_callback, &socketContext ); + cbinfo->fdRef = ref; + cbinfo->sourceRef = CFSocketCreateRunLoopSource( kCFAllocatorDefault, ref, 0 ); + CFRunLoopAddSource( CFRunLoopGetCurrent(), cbinfo->sourceRef, kCFRunLoopCommonModes ); + + return cbinfo; +} + +/** + * Register a file descriptor listener on an already open (and listening) + * file descriptor. The file descriptor must not have been previously registered. + * @return TRUE on success, FALSE on failure. + * + */ +io_listener_t io_register_listener( int fd, io_callback_t callback, void *data, void (*dealloc)(void *) ) +{ + CFFileDescriptorContext fdContext; + struct io_osx_cbinfo *cbinfo = malloc( sizeof(struct io_osx_cbinfo) ); + assert(cbinfo != NULL); + + cbinfo->callback = callback; + cbinfo->cbdata = data; + cbinfo->cbdealloc = dealloc; + fdContext.version = 0; + fdContext.retain = NULL; + fdContext.info = cbinfo; + fdContext.release = io_osx_release; + fdContext.copyDescription = NULL; + + CFFileDescriptorRef ref = CFFileDescriptorCreate( kCFAllocatorDefault, fd, FALSE, + io_osx_fd_callback, &fdContext); + cbinfo->fdRef = ref; + cbinfo->sourceRef = CFFileDescriptorCreateRunLoopSource( kCFAllocatorDefault, ref, 0 ); + CFRunLoopAddSource( CFRunLoopGetCurrent(), cbinfo->sourceRef, kCFRunLoopCommonModes ); + return cbinfo; +} + +void io_unregister_listener( io_listener_t data ) +{ + struct io_osx_cbinfo *cbinfo = (struct io_osx_cbinfo *)data; + io_unregister_callback(cbinfo); +} --- a/src/drivers/net_glib.c Mon Aug 03 08:41:11 2009 +1000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/** - * $Id$ - * - * Glib-based networking support functions. Currently this is just for activity callbacks. - * - * Copyright (c) 2009 Nathan Keynes. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include -#include -#include -#include "netutil.h" - -struct net_glib_cbinfo { - net_callback_t callback; - void * cbdata; - void (*cbdealloc)(void *); -}; - -static gboolean net_glib_callback( GIOChannel *source, GIOCondition cond, gpointer data ) -{ - struct net_glib_cbinfo *cbinfo = (struct net_glib_cbinfo *)data; - return cbinfo->callback( g_io_channel_unix_get_fd(source), cbinfo->cbdata); -} - -static void net_glib_release( void *data ) -{ - struct net_glib_cbinfo *cbinfo = (struct net_glib_cbinfo *)data; - if( cbinfo->cbdealloc ) { - cbinfo->cbdealloc( cbinfo->cbdata ); - } - free(cbinfo); -} - -/** - * Register a TCP server socket listener on an already open (and listening) - * socket. The socket must not have been previously registered. - * @return TRUE on success, FALSE on failure. - * - * Defined in netutil.h - */ -gboolean net_register_tcp_listener( int fd, net_callback_t callback, void *data, void (*dealloc)(void*) ) -{ - struct net_glib_cbinfo *cbinfo = malloc( sizeof(struct net_glib_cbinfo) ); - assert(cbinfo != NULL); - - cbinfo->callback = callback; - cbinfo->cbdata = data; - cbinfo->cbdealloc = dealloc; - - /** - * Note magic here: the watch creates an event source which holds a - * reference to the channel. We unref the channel so that the channel then - * is automatically released when the event source goes away. - */ - GIOChannel *chan = g_io_channel_unix_new(fd); - g_io_channel_set_encoding( chan, NULL, NULL ); - g_io_channel_set_buffered(chan, FALSE); - g_io_add_watch_full( chan, 0, G_IO_IN, net_glib_callback, cbinfo, net_glib_release ); - g_io_channel_unref( chan ); - return TRUE; -} --- a/src/drivers/net_osx.m Mon Aug 03 08:41:11 2009 +1000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/** - * $Id$ - * - * OS X networking support functions. Currently this is just for activity callbacks. - * - * Copyright (c) 2009 Nathan Keynes. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include -#include "netutil.h" - -struct net_osx_cbinfo { - net_callback_t callback; - void * cbdata; - void (*cbdealloc)(void *); - CFSocketRef sockRef; - CFRunLoopSourceRef sourceRef; -}; - -static void net_osx_callback( CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void *unused, void *data ) -{ - struct net_osx_cbinfo *cbinfo = (struct net_osx_cbinfo *)data; - if(!cbinfo->callback( CFSocketGetNative(s), cbinfo->cbdata) ) { - CFRunLoopRemoveSource( CFRunLoopGetCurrent(), cbinfo->sourceRef, kCFRunLoopCommonModes ); - CFRelease(cbinfo->sourceRef); - cbinfo->sourceRef = NULL; - CFRelease(cbinfo->sockRef); - } -} - -static void net_osx_release( const void *data ) -{ - struct net_osx_cbinfo *cbinfo = (struct net_osx_cbinfo *)data; - if( cbinfo->cbdealloc != NULL ) { - cbinfo->cbdealloc(cbinfo->cbdata); - } - free( cbinfo ); -} - -/** - * Register a TCP server socket listener on an already open (and listening) - * socket. The socket must not have been previously registered. - * @return TRUE on success, FALSE on failure. - * - * Defined in netutil.h - */ -gboolean net_register_tcp_listener( int fd, net_callback_t callback, void *data, void (*dealloc)(void*) ) -{ - CFSocketContext socketContext; - struct net_osx_cbinfo *cbinfo = malloc( sizeof(struct net_osx_cbinfo) ); - assert(cbinfo != NULL); - - cbinfo->callback = callback; - cbinfo->cbdata = data; - cbinfo->cbdealloc = dealloc; - socketContext.version = 0; - socketContext.info = cbinfo; - socketContext.retain = NULL; - socketContext.release = net_osx_release; - socketContext.copyDescription = NULL; - - cbinfo->sockRef = CFSocketCreateWithNative( kCFAllocatorDefault, fd, kCFSocketReadCallBack, - net_osx_callback, &socketContext ); - cbinfo->sourceRef = CFSocketCreateRunLoopSource( kCFAllocatorDefault, cbinfo->sockRef, 0 ); - CFRunLoopAddSource( CFRunLoopGetCurrent(), cbinfo->sourceRef, kCFRunLoopCommonModes ); - - return TRUE; -} --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/drivers/serial_unix.c Wed Oct 07 17:53:56 2009 +1000 @@ -0,0 +1,188 @@ +/** + * $Id$ + * + * Host driver for a serial port attachment, that can be hooked to a character + * device, fifo or named pipe. + * + * Copyright (c) 2009 Nathan Keynes. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include + +#include "lxdream.h" +#include "config.h" +#include "ioutil.h" +#include "serial.h" + + +typedef struct serial_fd_device { + struct serial_device dev; + FILE *in; + FILE *out; + gboolean closeOnDestroy; + io_listener_t listener; +} *serial_fd_device_t; + +static void serial_fd_device_attach(serial_device_t dev); +static void serial_fd_device_detach(serial_device_t dev); +static void serial_fd_device_destroy(serial_device_t dev); +static void serial_fd_device_set_line_speed(struct serial_device *dev, uint32_t bps); +static void serial_fd_device_set_line_params(struct serial_device *dev, int flags); +static void serial_fd_device_receive_data(struct serial_device *dev, uint8_t value); +static gboolean serial_fd_device_transmit_data( int fd, void *dev); + +static gboolean serial_config_changed(void *data, struct lxdream_config_group *group, unsigned item, + const gchar *oldval, const gchar *newval); + +struct lxdream_config_group serial_group = + { "serial", serial_config_changed, NULL, NULL, + {{ "device", N_("Serial device"), CONFIG_TYPE_FILE, "/dev/console" }, + { NULL, CONFIG_TYPE_NONE }} }; + +void serial_init() +{ + const gchar *name = serial_group.params[0].value; + if( name != NULL ) { + serial_device_t dev = serial_fd_device_new_filename(name); + if( dev != NULL ) { + serial_attach_device( dev ); + } + } +} + +static gboolean serial_config_changed(void *data, struct lxdream_config_group *group, unsigned item, + const gchar *oldval, const gchar *newval) +{ + if( item == 0 ) { + serial_destroy_device(serial_detach_device()); + serial_device_t dev = serial_fd_device_new_filename(newval); + if( dev != NULL ) { + serial_attach_device( dev ); + } + } +} + + + +serial_device_t serial_fd_device_new_filename( const gchar *filename ) +{ + FILE *out = fopen( filename, "w+" ); + FILE *in; + struct stat st; + + if( out == NULL ) { + return NULL; + } + + if( fstat( fileno(out), &st ) != 0 ) { + fclose(out); + return NULL; + } + + if( S_ISCHR(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode) ) { + in = out; + } else { + in = NULL; + } + + return (serial_device_t)serial_fd_device_new_file(in, out, TRUE); +} + +serial_device_t serial_fd_device_new_console() +{ + return serial_fd_device_new_file( stdin, stdout, FALSE ); +} + +serial_device_t serial_fd_device_new_file( FILE *in, FILE *out, gboolean closeOnDestroy ) +{ + if( in != NULL ) + fcntl( fileno(in), F_SETFL, O_NONBLOCK ); + + serial_fd_device_t dev = (serial_fd_device_t)malloc(sizeof(struct serial_fd_device)); + if( dev == NULL ) { + if( closeOnDestroy ) { + if( in != NULL ) + fclose(in); + if( out != NULL && out != in ) + fclose(out); + } + return NULL; + } + + dev->dev.attach = serial_fd_device_attach; + dev->dev.detach = serial_fd_device_detach; + dev->dev.destroy = serial_fd_device_destroy; + dev->dev.set_line_speed = serial_fd_device_set_line_speed; + dev->dev.set_line_params = serial_fd_device_set_line_params; + dev->dev.receive_data = serial_fd_device_receive_data; + dev->in = in; + dev->out = out; + dev->closeOnDestroy = closeOnDestroy; + return (serial_device_t)dev; +} + +static void serial_fd_device_attach(serial_device_t dev) +{ + serial_fd_device_t fddev = (serial_fd_device_t)dev; + if( fddev->in != NULL ) + fddev->listener = io_register_listener( fileno(fddev->in), serial_fd_device_transmit_data, fddev, NULL ); +} + +static void serial_fd_device_detach(serial_device_t dev) +{ + serial_fd_device_t fddev = (serial_fd_device_t)dev; + if( fddev->in != NULL ) + io_unregister_listener( fddev->listener ); +} + +static void serial_fd_device_destroy(serial_device_t dev) +{ + serial_fd_device_t fddev = (serial_fd_device_t)dev; + if( fddev->closeOnDestroy ) { + if( fddev->in != NULL ) + fclose(fddev->in); + if( fddev->out != NULL && fddev->out != fddev->in ) + fclose(fddev->out); + } + fddev->in = NULL; + fddev->out = NULL; + free(fddev); +} +static void serial_fd_device_set_line_speed(struct serial_device *dev, uint32_t bps) +{ + /* Do nothing for now */ +} +static void serial_fd_device_set_line_params(struct serial_device *dev, int flags) +{ + /* Do nothing for now */ +} +static void serial_fd_device_receive_data(struct serial_device *dev, uint8_t value) +{ + serial_fd_device_t fddev = (serial_fd_device_t)dev; + if( fddev->out != NULL ) + fputc( value, fddev->out ); +} + +static gboolean serial_fd_device_transmit_data( int fd, void *dev ) +{ + serial_fd_device_t fddev = (serial_fd_device_t)dev; + char buf[4096]; + size_t len = fread(buf, 1, sizeof(buf), fddev->in); + if( len > 0 ) { + serial_transmit_data(buf, len); + } + return TRUE; +} --- a/src/gdbserver.c Mon Aug 03 08:41:11 2009 +1000 +++ b/src/gdbserver.c Wed Oct 07 17:53:56 2009 +1000 @@ -27,7 +27,7 @@ #include #include "lxdream.h" #include "dreamcast.h" -#include "netutil.h" +#include "ioutil.h" #include "cpu.h" #define DEFAULT_BUFFER_SIZE 1024 @@ -495,7 +495,7 @@ chan_serv->buf = malloc(1024); chan_serv->buf_size = 1024; chan_serv->buf_posn = 0; - net_register_tcp_listener( conn_fd, gdb_server_data_callback, chan_serv, gdb_server_free ); + io_register_tcp_listener( conn_fd, gdb_server_data_callback, chan_serv, gdb_server_free ); INFO( "GDB connected from %s", chan_serv->peer_name ); } return TRUE; @@ -514,7 +514,7 @@ */ gboolean gdb_init_server( const char *interface, int port, cpu_desc_t cpu, gboolean mmu ) { - int fd = net_create_server_socket( interface, port ); + int fd = io_create_server_socket( interface, port ); if( fd == -1 ) { return FALSE; } @@ -523,7 +523,7 @@ server->cpu = cpu; server->mmu = mmu; server->fd = fd; - gboolean result = net_register_tcp_listener( fd, gdb_server_connect_callback, server, gdb_server_free ); + gboolean result = io_register_tcp_listener( fd, gdb_server_connect_callback, server, gdb_server_free ); INFO( "%s GDB server running on port %d", cpu->name, port ); return result; } --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ioutil.c Wed Oct 07 17:53:56 2009 +1000 @@ -0,0 +1,54 @@ +/** + * $Id$ + * + * Network support functions + * + * Copyright (c) 2009 Nathan Keynes. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include "ioutil.h" + +int io_create_server_socket(const char *interface, int port ) +{ + struct sockaddr_in sin; + int fd = socket(AF_INET, SOCK_STREAM, 0); + if( fd == -1 ) { + ERROR( "Failed to create TCP socket!" ); + return -1; + } + + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = 0; + sin.sin_port = htons(port); + + if( interface != NULL ) { + if( !inet_aton(interface, &sin.sin_addr) ) { + /* TODO: hostname lookup */ + } + } + + if( bind( fd, (struct sockaddr *)&sin, sizeof(sin) ) != 0 || + listen(fd, 5) != 0 ) { + close(fd); + ERROR( "Failed to bind port %d (%s)", port, strerror(errno) ); + return -1; + } + return fd; +} + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ioutil.h Wed Oct 07 17:53:56 2009 +1000 @@ -0,0 +1,67 @@ +/** + * $Id$ + * + * GDB RDP server stub - SH4 + ARM + * + * Copyright (c) 2009 Nathan Keynes. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef lxdream_netutil_H +#define lxdream_netutil_H 1 + +#include +#include "lxdream.h" + +typedef void *io_listener_t; + +/** + * Construct a server socket listening on the given interface and port. If port + * is 0, a dynamic port will be bound instead. + * This method does not register a listener. + * @return newly created socket fd, or -1 on failure. + */ +int io_create_server_socket(const char *interface, int port ); + +/** + * Callback invoked when data is available from the remote peer, or when the peer + * connects/disconnects. + * + * @param fd file descriptor of the connected socket + * @param data data supplied when the callback was registered + * @return TRUE to maintain the connection, FALSE to immediately disconnected + close. + */ +typedef gboolean (*io_callback_t)( int fd, void *data ); + +/** + * Register a TCP server socket listener on an already open (and listening) + * socket. The socket must not have been previously registered. + * @return NULL on failure, otherwise an io listener handle. + * + * Note: Implementation is platform specific + */ +io_listener_t io_register_tcp_listener( int fd, io_callback_t callback, void *data, void (*dealloc)(void*) ); + +/** + * Register an I/O listener on an open file descriptor. The fd must not have + * been previously registered. + * @return TRUE on success, FALSE on failure. + */ +io_listener_t io_register_listener( int fd, io_callback_t callback, void *data, void (*dealloc)(void *) ); + +/** + * Unregister a socket that was previously registered with the system. This + * does not close the socket, but will remove any callbacks associated with the socket. + */ +void io_unregister_listener( io_listener_t handle ); + +#endif /* !lxdream_netutil_H */ --- a/src/main.c Mon Aug 03 08:41:11 2009 +1000 +++ b/src/main.c Wed Oct 07 17:53:56 2009 +1000 @@ -249,6 +249,7 @@ } hotkeys_init(); + serial_init(); maple_reattach_all(); INFO( "%s! ready...", APP_NAME ); --- a/src/netutil.c Mon Aug 03 08:41:11 2009 +1000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/** - * $Id$ - * - * Network support functions - * - * Copyright (c) 2009 Nathan Keynes. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include -#include -#include -#include -#include -#include -#include "netutil.h" - -int net_create_server_socket(const char *interface, int port ) -{ - struct sockaddr_in sin; - int fd = socket(AF_INET, SOCK_STREAM, 0); - if( fd == -1 ) { - ERROR( "Failed to create TCP socket!" ); - return -1; - } - - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = 0; - sin.sin_port = htons(port); - - if( interface != NULL ) { - if( !inet_aton(interface, &sin.sin_addr) ) { - /* TODO: hostname lookup */ - } - } - - if( bind( fd, (struct sockaddr *)&sin, sizeof(sin) ) != 0 || - listen(fd, 5) != 0 ) { - close(fd); - ERROR( "Failed to bind port %d (%s)", port, strerror(errno) ); - return -1; - } - return fd; -} - --- a/src/netutil.h Mon Aug 03 08:41:11 2009 +1000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/** - * $Id$ - * - * GDB RDP server stub - SH4 + ARM - * - * Copyright (c) 2009 Nathan Keynes. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef lxdream_netutil_H -#define lxdream_netutil_H 1 - -#include -#include "lxdream.h" - -/** - * Construct a server socket listening on the given interface and port. If port - * is 0, a dynamic port will be bound instead. - * This method does not register a listener. - * @return newly created socket fd, or -1 on failure. - */ -int net_create_server_socket(const char *interface, int port ); - -/** - * Callback invoked when data is available from the remote peer, or when the peer - * connects/disconnects. - * - * @param fd file descriptor of the connected socket - * @param data data supplied when the callback was registered - * @return TRUE to maintain the connection, FALSE to immediately disconnected + close. - */ -typedef gboolean (*net_callback_t)( int fd, void *data ); - -/** - * Register a TCP server socket listener on an already open (and listening) - * socket. The socket must not have been previously registered. - * @return TRUE on success, FALSE on failure. - * - * Note: Implementation is platform specific - */ -gboolean net_register_tcp_listener( int fd, net_callback_t callback, void *data, void (*dealloc)(void*) ); - -/** - * Unregister a socket that was previously registered with the system. This - * does not close the socket, but will remove any callbacks associated with the socket. - */ -gboolean net_unregister_listener( int fd ); - -#endif /* !lxdream_netutil_H */ --- a/src/serial.h Mon Aug 03 08:41:11 2009 +1000 +++ b/src/serial.h Wed Oct 07 17:53:56 2009 +1000 @@ -20,6 +20,8 @@ #include +#include "lxdream.h" + #ifdef __cplusplus extern "C" { #endif @@ -33,17 +35,44 @@ #define SERIAL_2STOPBITS 0x08 typedef struct serial_device { - void (*set_line_speed)(uint32_t bps); - void (*set_line_params)(int flags); - void (*receive_data)(uint8_t value); + void (*attach)(struct serial_device *dev); + void (*detach)(struct serial_device *dev); + void (*destroy)(struct serial_device *dev); + void (*set_line_speed)(struct serial_device *dev, uint32_t bps); + void (*set_line_params)(struct serial_device *dev, int flags); + void (*receive_data)(struct serial_device *dev, uint8_t value); } *serial_device_t; -void serial_attach_device( serial_device_t dev ); -void serial_detach_device( ); +serial_device_t serial_attach_device( serial_device_t dev ); +serial_device_t serial_detach_device( ); +serial_device_t serial_get_device( ); + +/** + * Destroy a serial device. + */ +void serial_destroy_device( serial_device_t dev ); + void serial_transmit_data( char *data, int length ); void serial_transmit_break( void ); +/** + * Create a serial device on a host device identified by the given + * file (ie /dev/tty). If filename identifies a regular file, it is opened + * for output only. + */ +serial_device_t serial_fd_device_new_filename( const gchar *filename ); + +/** + * Create a serial device on the host console (stdin/stdout). + */ +serial_device_t serial_fd_device_new_console(); + +/** + * Create a serial device on a pair of file streams (in and out) + */ +serial_device_t serial_fd_device_new_file( FILE *in, FILE *out, gboolean closeOnDestroy ); + #ifdef __cplusplus } #endif --- a/src/sh4/scif.c Mon Aug 03 08:41:11 2009 +1000 +++ b/src/sh4/scif.c Wed Oct 07 17:53:56 2009 +1000 @@ -28,7 +28,7 @@ #include "serial.h" void SCIF_set_break(void); - +void SCIF_run_to(uint32_t nanosecs); /************************* External serial interface ************************/ /** @@ -55,17 +55,41 @@ serial_data_block_t serial_recvq_head = NULL, serial_recvq_tail = NULL; serial_device_t serial_device = NULL; -void serial_attach_device( serial_device_t dev ) +serial_device_t serial_get_device( ) { + return serial_device; +} + +serial_device_t serial_attach_device( serial_device_t dev ) +{ + serial_device_t olddev = serial_device; if( serial_device != NULL ) serial_detach_device(); serial_device = dev; + if( serial_device != NULL && serial_device->attach != NULL ) + serial_device->attach(serial_device); + return olddev; } -void serial_detach_device( void ) +serial_device_t serial_detach_device( void ) { + serial_device_t dev = serial_device; + if( serial_device != NULL && serial_device->detach != NULL ) { + serial_device->detach(serial_device); + } serial_device = NULL; + return dev; +} + +void serial_destroy_device( serial_device_t dev ) +{ + if( dev != NULL ) { + if( serial_device == dev ) + serial_detach_device(); + if( dev->destroy ) + dev->destroy(dev); + } } /** @@ -174,6 +198,7 @@ uint32_t SCIF_tick_period = 0; uint32_t SCIF_tick_remainder = 0; +uint32_t SCIF_slice_cycle = 0; void SCIF_save_state( FILE *f ) { @@ -445,7 +470,7 @@ int baudrate = sh4_peripheral_freq / (32 * mult * (bbr+1) ); if( serial_device != NULL && serial_device->set_line_speed != NULL ) - serial_device->set_line_speed( baudrate ); + serial_device->set_line_speed( serial_device, baudrate ); SCIF_tick_period = sh4_peripheral_period * (32 * mult * (bbr+1)); @@ -457,6 +482,7 @@ MMIO_REGION_READ_FN( SCIF, reg ) { + SCIF_run_to(sh4r.slice_cycle); reg &= 0xFFF; switch( reg ) { case SCFRDR2: /* Receive data */ @@ -470,6 +496,7 @@ MMIO_REGION_WRITE_FN( SCIF, reg, val ) { + SCIF_run_to(sh4r.slice_cycle); uint32_t tmp; reg &= 0xFFF; switch( reg ) { @@ -482,7 +509,7 @@ */ val &= 0x007B; if( serial_device != NULL ) { - serial_device->set_line_params( val ); + serial_device->set_line_params( serial_device, val ); } tmp = MMIO_READ( SCIF, SCSMR2 ); if( (tmp & 0x03) != (val & 0x03) ) { @@ -597,7 +624,7 @@ int val = SCIF_sendq_dequeue(); if( val != -1 && serial_device != NULL && serial_device->receive_data != NULL ) { - serial_device->receive_data( val ); + serial_device->receive_data( serial_device, val ); } } @@ -632,11 +659,17 @@ SCIF_update_line_speed(); } -void SCIF_run_slice( uint32_t nanosecs ) +void SCIF_run_to( uint32_t nanosecs ) { - SCIF_tick_remainder += nanosecs; + SCIF_tick_remainder += nanosecs - SCIF_slice_cycle; while( SCIF_tick_remainder >= SCIF_tick_period ) { SCIF_tick_remainder -= SCIF_tick_period; SCIF_clock_tick(); } } + +void SCIF_run_slice( uint32_t nanosecs ) +{ + SCIF_run_to(nanosecs); + SCIF_slice_cycle = 0; +}