1 /* aNetHack 0.0.1 mhinput.c $ANH-Date: 1432512810 2015/05/25 00:13:30 $ $ANH-Branch: master $:$ANH-Revision: 1.11 $ */
2 /* Copyright (C) 2001 by Alex Kompel */
3 /* aNetHack may be freely redistributed. See license for details. */
9 /* anethack input queue functions */
11 #define NH_INPUT_BUFFER_SIZE 64
13 /* as it stands right now we need only one slot
14 since events are processed almost the same time as
15 they occur but I like large round numbers */
17 static MSNHEvent nhi_input_buffer
[NH_INPUT_BUFFER_SIZE
];
18 static int nhi_init_input
= 0;
19 static int nhi_read_pos
= 0;
20 static int nhi_write_pos
= 0;
22 /* initialize input queue */
24 mswin_nh_input_init(void)
26 if (!nhi_init_input
) {
29 ZeroMemory(nhi_input_buffer
, sizeof(nhi_input_buffer
));
41 /* we always have input (ESC) if hangup was requested */
42 program_state
.done_hup
||
44 (nhi_read_pos
!= nhi_write_pos
);
47 /* add event to the queue */
49 mswin_input_push(PMSNHEvent event
)
54 mswin_nh_input_init();
56 new_write_pos
= (nhi_write_pos
+ 1) % NH_INPUT_BUFFER_SIZE
;
58 if (new_write_pos
!= nhi_read_pos
) {
59 memcpy(nhi_input_buffer
+ nhi_write_pos
, event
, sizeof(*event
));
60 nhi_write_pos
= new_write_pos
;
64 /* get event from the queue and delete it */
71 /* always return ESC when hangup was requested */
72 if (program_state
.done_hup
) {
73 static MSNHEvent hangup_event
;
74 hangup_event
.type
= NHEVENT_CHAR
;
75 hangup_event
.kbd
.ch
= '\033';
81 mswin_nh_input_init();
83 if (nhi_read_pos
!= nhi_write_pos
) {
84 retval
= &nhi_input_buffer
[nhi_read_pos
];
85 nhi_read_pos
= (nhi_read_pos
+ 1) % NH_INPUT_BUFFER_SIZE
;
93 /* get event from the queue but leave it there */
100 /* always return ESC when hangup was requested */
101 if (program_state
.done_hup
) {
102 static MSNHEvent hangup_event
;
103 hangup_event
.type
= NHEVENT_CHAR
;
104 hangup_event
.kbd
.ch
= '\033';
105 return &hangup_event
;
110 mswin_nh_input_init();
112 if (nhi_read_pos
!= nhi_write_pos
) {
113 retval
= &nhi_input_buffer
[nhi_read_pos
];