aboutsummaryrefslogtreecommitdiff
path: root/src/parsec_server/inp_main_sv.cpp
blob: f670eede738a0d3bdf7fa7085c6310a2294cc511 (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
/*
 * PARSEC - CURSES Input Code
 *
 * $Author: uberlinuxguy $ - $Date: 2004/09/26 03:43:48 $
 *
 * Orginally written by:
 *   Copyright (c) Clemens Beer        <cbx@parsec.org>   2001-2002
 *
 *  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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */ 

// C library
#include <stdio.h>
#include <string.h>

// compilation flags/debug support
#include "config.h"
#include "debug.h"

// general definitions
#include "general.h"

// subsystem headers
#include "inp_defs_sv.h"

// local module header
#include "inp_main_sv.h"

// proprietary module headers
#include "con_main_sv.h"

// keyboard mapping -----------------------------------------------------------
//
#include "inp_keybmap_sv.h"

// Keyboard buffer ------------------------------------------------------------
//
PRIVATE dword INPS_KeybBuffer[ 2 + KEYB_BUFF_SIZ ];	

// global pointer to the keyboard buffer ( for console input ) ----------------
//
keybbuffer_s* KeybBuffer;


// init the input subsystem ---------------------------------------------------
//
PUBLIC
void INP_Init()
{
	memset( INPS_KeybBuffer, 0, sizeof( INPS_KeybBuffer ) );
	KeybBuffer = (keybbuffer_s*) &INPS_KeybBuffer;
}

// kill the input subsystem ---------------------------------------------------
//
PUBLIC
void INP_Kill()
{
}

// stuff key in internal keyboard buffer using repeatcount --------------------
//
PRIVATE
void _INP_HandleBufferedKey( int key, int nRepcount )
{
	dword *pos;
	
	for ( int nCount = 0; nCount < nRepcount; nCount++ ) {
		dword wpos = KeybBuffer->WritePos + 1;
		wpos = wpos % (KEYB_BUFF_SIZ);
		
		pos = &KeybBuffer->Data + wpos;
		
		// prevent overwrite
		if ( *pos == 0 ) {
			
			// map into KeybMap
			ASSERT( (dword)key < sizeof( INP_KeybMap ) );
			dword dwKey = INP_KeybMap[ key ];
			
			// write into keyboard buffer
			if ( dwKey != CKC_NIL ) {
				*(dword*)(&KeybBuffer->Data + KeybBuffer->WritePos) = dwKey;
				KeybBuffer->WritePos = wpos;
			}
		}
	}
}


// handle the input from CURSES -----------------------------------------------
//
PUBLIC
void INP_HandleInput()
{
	ASSERT( g_curses_in_win != NULL );
	int c = wgetch( g_curses_in_win );

	if ( c != ERR ) {
		_INP_HandleBufferedKey( c, 1 );		
	}
}