Skip to content

Commit 5cef359

Browse files
committed
#877: fix SLEEP behaviour in linux console
- wait for key presses - do not affect input buffer - match linux SLEEP to behaviour on Windows.
1 parent 1e66df8 commit 5cef359

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Version 1.06.0
5353
- #844: Fix bug in -gen gcc due to duplicated type (struct) names in the main module and global namespace
5454
- #875: Fix bug where boolean variable to single/double conversion gives wrong sign on -gen gas -fpu x87 & sse
5555
- #872: Fix broken boolean bitfield runtime assignments from unsigned values
56+
- #877: fix SLEEP behaviour in linux console and wait for key presses, and do not affect input buffer. Match linux SLEEP to behaviour on Windows.
5657
- Fixed inline asm procedure name mangling bug (missing underscore prefix) with -gen gcc -asm intel on dos/win32
5758

5859

src/rtlib/unix/io_inkey.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static const KEY_DATA key_data[] = {
5555
{ NULL, 0 }
5656
};
5757

58-
static int key_buffer[KEY_BUFFER_LEN], key_head = 0, key_tail = 0;
58+
static int key_buffer[KEY_BUFFER_LEN], key_head = 0, key_tail = 0, key_buffer_changed = FALSE;
5959
static NODE *root_node = NULL;
6060

6161
static void add_key(NODE **node, char *key, short code)
@@ -205,6 +205,7 @@ void fb_hAddCh( int k )
205205
if (((key_tail + 1) & (KEY_BUFFER_LEN - 1)) == key_head)
206206
key_head = (key_head + 1) & (KEY_BUFFER_LEN - 1);
207207
key_tail = (key_tail + 1) & (KEY_BUFFER_LEN - 1);
208+
key_buffer_changed = TRUE;
208209
}
209210

210211
int fb_hGetCh(int remove)
@@ -274,8 +275,13 @@ int fb_ConsoleGetkey( void )
274275
/* Caller is expected to hold FB_LOCK() */
275276
int fb_ConsoleKeyHit( void )
276277
{
278+
int result;
279+
277280
if (!__fb_con.inited)
278281
return feof(stdin) ? FALSE : TRUE;
279282

280-
return (fb_hGetCh(FALSE) < 0) ? 0 : 1;
283+
fb_hGetCh(FALSE);
284+
result = key_buffer_changed;
285+
key_buffer_changed = FALSE;
286+
return result;
281287
}

src/rtlib/unix/io_input.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,5 @@
55

66
int fb_hConsoleInputBufferChanged( void )
77
{
8-
/* FIXME: We need to find a method to set a flag whenver a NEW character
9-
* was passed to the input buffer. Maybe we can use something
10-
* like ftell( stdin ) + some modifications of key input functions?
11-
*
12-
* INFO: Don't clear the input buffer in any case because this will
13-
* cause more trouble than not clearing the input buffer.
14-
*
15-
* mjs, 2005-10-13
16-
*/
178
return fb_KeyHit();
189
}

0 commit comments

Comments
 (0)