Skip to content
Snippets Groups Projects
Commit 0ff1fb61 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Implement kbhit() and getch() so we can exit.

parent 6436bcd5
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
HBITMAP bmp; HBITMAP bmp;
HWND win; HWND win;
FILE *debug; FILE *debug;
HANDLE rch;
HANDLE wch;
#define LCS_WINDOWS_COLOR_SPACE 0x57696E20 #define LCS_WINDOWS_COLOR_SPACE 0x57696E20
...@@ -37,6 +39,20 @@ static int bitmap_width,bitmap_height; ...@@ -37,6 +39,20 @@ static int bitmap_width,bitmap_height;
// Internal implementation // Internal implementation
static void
add_key(uint16_t key)
{
uint8_t buf[2];
DWORD added;
DWORD remain = sizeof(buf);
buf[0] = key & 0xff;
buf[1] = key >> 8;
do {
WriteFile(wch, buf, remain, &added, NULL);
remain -= added;
} while (remain > 0);
}
static LRESULT CALLBACK static LRESULT CALLBACK
gdi_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { gdi_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps; PAINTSTRUCT ps;
...@@ -121,6 +137,7 @@ gdi_thread(void *arg) ...@@ -121,6 +137,7 @@ gdi_thread(void *arg)
// This may not be necessary... // This may not be necessary...
DestroyWindow(win); DestroyWindow(win);
UnregisterClassW(wc.lpszClassName, NULL); UnregisterClassW(wc.lpszClassName, NULL);
add_key(CIO_KEY_QUIT);
} }
// Public API // Public API
...@@ -128,13 +145,22 @@ gdi_thread(void *arg) ...@@ -128,13 +145,22 @@ gdi_thread(void *arg)
int int
gdi_kbhit(void) gdi_kbhit(void)
{ {
return 0; DWORD avail;
PeekNamedPipe(rch, NULL, 0, NULL, &avail, NULL);
return (avail > 0);
} }
int int
gdi_getch(void) gdi_getch(void)
{ {
return 0; uint8_t ch;
DWORD got;
do {
ReadFile(rch, &ch, 1, &got, NULL);
} while (got == 0);
return ch;
} }
void void
...@@ -230,6 +256,7 @@ gdi_init(int mode) ...@@ -230,6 +256,7 @@ gdi_init(int mode)
{ {
pthread_mutex_init(&gdi_headlock, NULL); pthread_mutex_init(&gdi_headlock, NULL);
pthread_mutex_init(&bmp_lock, NULL); pthread_mutex_init(&bmp_lock, NULL);
CreatePipe(&rch, &wch, NULL, 0);
bitmap_drv_init(gdi_drawrect, gdi_flush); bitmap_drv_init(gdi_drawrect, gdi_flush);
gdi_textmode(mode); gdi_textmode(mode);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment