summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authordiego <diego@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-02-21 16:20:33 +0000
committerdiego <diego@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-02-21 16:20:33 +0000
commitfebce72028665803466d24a80086d6e836a09b31 (patch)
tree2a1a1bb1cb2c38a51d18ef8c9c88a901d18315b7 /osdep
parent895fc255537eda5e9f7aef9119b22607dbc39eee (diff)
downloadmpv-febce72028665803466d24a80086d6e836a09b31.tar.bz2
mpv-febce72028665803466d24a80086d6e836a09b31.tar.xz
OS/2 getch2() support
patch by KO Myung-Hun, komh chollian net git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@26048 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'osdep')
-rw-r--r--osdep/Makefile3
-rw-r--r--osdep/getch2-os2.c199
-rw-r--r--osdep/getch2.h9
3 files changed, 211 insertions, 0 deletions
diff --git a/osdep/Makefile b/osdep/Makefile
index 3f22bcacad..43f3e08d59 100644
--- a/osdep/Makefile
+++ b/osdep/Makefile
@@ -24,6 +24,9 @@ endif
ifeq ($(TARGET_OS),MINGW32)
getch = getch2-win.c
endif
+ifeq ($(TARGET_OS),OS/2)
+getch = getch2-os2.c
+endif
SRCS_COMMON += $(timer)
SRCS_COMMON += $(getch)
diff --git a/osdep/getch2-os2.c b/osdep/getch2-os2.c
new file mode 100644
index 0000000000..41e498d20d
--- /dev/null
+++ b/osdep/getch2-os2.c
@@ -0,0 +1,199 @@
+/*
+ * getch2-os2.c : OS/2 TermIO for MPlayer
+ *
+ * Copyright (c) 2007 KO Myung-Hun (komh@chollian.net)
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define INCL_KBD
+#define INCL_VIO
+#define INCL_DOS
+#include <os2.h>
+
+#include <stdio.h>
+
+#include "config.h"
+#include "keycodes.h"
+#include "input/input.h"
+#include "mp_fifo.h"
+
+#if defined( USE_LANGINFO ) && defined( USE_ICONV )
+#include <locale.h>
+#include <langinfo.h>
+#endif
+
+int mp_input_slave_cmd_func( int fd, char *dest, int size )
+{
+ PPIB ppib;
+ CHAR szPipeName[ 100 ];
+ HFILE hpipe;
+ ULONG ulAction;
+ ULONG cbActual;
+ ULONG rc;
+
+ DosGetInfoBlocks( NULL, &ppib );
+
+ sprintf( szPipeName, "\\PIPE\\MPLAYER\\%lx", ppib->pib_ulpid );
+
+ rc = DosOpen( szPipeName, &hpipe, &ulAction, 0, FILE_NORMAL,
+ OPEN_ACTION_OPEN_IF_EXISTS,
+ OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE,
+ NULL );
+ if( rc )
+ return MP_INPUT_NOTHING;
+
+ rc = DosRead( hpipe, dest, size, &cbActual );
+ if( rc )
+ return MP_INPUT_NOTHING;
+
+ rc = cbActual;
+
+ // Send ACK
+ DosWrite( hpipe, &rc, sizeof( ULONG ), &cbActual );
+
+ DosClose( hpipe );
+
+ return rc;
+}
+
+
+int screen_width = 80;
+int screen_height = 24;
+char *erase_to_end_of_line = NULL;
+
+void get_screen_size( void )
+{
+ VIOMODEINFO vmi;
+
+ vmi.cb = sizeof( VIOMODEINFO );
+
+ VioGetMode( &vmi, 0 );
+
+ screen_width = vmi.col;
+ screen_height = vmi.row;
+}
+
+static int getch2_status = 0;
+
+static int getch2_internal( void )
+{
+ KBDKEYINFO kki;
+
+ if( !getch2_status )
+ return -1;
+
+ if( KbdCharIn( &kki, IO_NOWAIT, 0 ))
+ return -1;
+
+ // key pressed ?
+ if( kki.fbStatus )
+ {
+ // extended key ?
+ if(( kki.chChar == 0x00 ) || ( kki.chChar == 0xE0 ))
+ {
+ switch( kki.chScan )
+ {
+ case 0x4B : // Left
+ return KEY_LEFT;
+
+ case 0x48 : // Up
+ return KEY_UP;
+
+ case 0x4D : // Right
+ return KEY_RIGHT;
+
+ case 0x50 : // Down
+ return KEY_DOWN;
+
+ case 0x53 : // Delete
+ return KEY_DELETE;
+
+ case 0x52 : // Insert
+ return KEY_INSERT;
+
+ case 0x47 : // Home
+ return KEY_HOME;
+
+ case 0x4F : // End
+ return KEY_END;
+
+ case 0x49 : // Page Up
+ return KEY_PAGE_UP;
+
+ case 0x51 : // Page Down
+ return KEY_PAGE_DOWN;
+ }
+ }
+ else
+ {
+ switch( kki.chChar )
+ {
+ case 0x08 : // Backspace
+ return KEY_BS;
+
+ case 0x1B : // Esc
+ return KEY_ESC;
+
+ case 0x0D : // Enter
+ // Keypad Enter ?
+ if( kki.chScan == 0xE0 )
+ return KEY_KPENTER;
+ break;
+ }
+
+ return kki.chChar;
+ }
+ }
+
+ return -1;
+}
+
+void getch2( void )
+{
+ int key;
+
+ key = getch2_internal();
+ if( key != -1 )
+ mplayer_put_key( key );
+}
+
+void getch2_enable( void )
+{
+ getch2_status = 1;
+}
+
+void getch2_disable( void )
+{
+ getch2_status = 0;
+}
+
+#ifdef USE_ICONV
+char *get_term_charset( void )
+{
+ char *charset = NULL;
+
+#ifdef USE_LANGINFO
+ setlocale( LC_CTYPE, "");
+ charset = nl_langinfo( CODESET );
+ setlocale( LC_CTYPE, "C");
+#endif
+
+ return charset;
+}
+#endif
+
diff --git a/osdep/getch2.h b/osdep/getch2.h
index 3c015ba9bb..c2e14aa5ee 100644
--- a/osdep/getch2.h
+++ b/osdep/getch2.h
@@ -24,6 +24,15 @@ extern void getch2_disable(void);
/* Read a character or a special key code (see keycodes.h) */
extern void getch2(void);
+/* slave cmd function for Windows and OS/2 */
extern int mp_input_slave_cmd_func(int fd,char* dest,int size);
+#if defined(__MINGW32__) || defined(__OS2__)
+#define USE_SELECT 0
+#define MP_INPUT_SLAVE_CMD_FUNC mp_input_slave_cmd_func
+#else
+#define USE_SELECT 1
+#define MP_INPUT_SLAVE_CMD_FUNC NULL
+#endif
+
#endif /* GETCH2_H */