summaryrefslogtreecommitdiffstats
path: root/osdep/getch2-os2.c
blob: c309a22bceed09eeecbae08310cce297d27a015d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
 * 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"
#include "getch2.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(struct mp_fifo *fifo)
{
    int key;

    key = getch2_internal();
    if( key != -1 )
        mplayer_put_key(fifo, 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