1 /* Copyright (C) 2001 by Alex Kompel <shurikk@pacbell.net> */
2 /* NetHack may be freely redistributed. See license for details. */
8 /* nethack input queue functions */
10 #define NH_INPUT_BUFFER_SIZE 64
12 /* as it stands right now we need only one slot
13 since events are processed almost the same time as
14 they occur but I like large round numbers */
16 static MSNHEvent nhi_input_buffer[NH_INPUT_BUFFER_SIZE];
17 static int nhi_init_input = 0;
18 static int nhi_read_pos = 0;
19 static int nhi_write_pos = 0;
21 /* initialize input queue */
22 void mswin_nh_input_init(void)
24 if( !nhi_init_input ) {
27 ZeroMemory( nhi_input_buffer, sizeof(nhi_input_buffer) );
34 int mswin_have_input()
36 return (nhi_read_pos!=nhi_write_pos);
39 /* add event to the queue */
40 void mswin_input_push(PMSNHEvent event)
44 if( !nhi_init_input ) mswin_nh_input_init();
46 new_write_pos = (nhi_write_pos+1) % NH_INPUT_BUFFER_SIZE;
48 if(new_write_pos!=nhi_read_pos) {
49 memcpy(nhi_input_buffer+nhi_write_pos, event, sizeof(*event));
50 nhi_write_pos = new_write_pos;
55 /* get event from the queue and delete it */
56 PMSNHEvent mswin_input_pop()
60 if( !nhi_init_input ) mswin_nh_input_init();
62 if( nhi_read_pos!=nhi_write_pos ) {
63 retval = &nhi_input_buffer[nhi_read_pos];
64 nhi_read_pos = (nhi_read_pos+1) % NH_INPUT_BUFFER_SIZE;
72 /* get event from the queue but leave it there */
73 PMSNHEvent mswin_input_peek()
77 if( !nhi_init_input ) mswin_nh_input_init();
79 if( nhi_read_pos!=nhi_write_pos ) {
80 retval = &nhi_input_buffer[nhi_read_pos];