From 60c5866729ebcbe1d42e1981cb00b91ded0e1c66 Mon Sep 17 00:00:00 2001 From: Maurilio Longo Date: Tue, 27 Feb 2001 08:14:55 +0000 Subject: [PATCH] 2001-02-27 09:09 GMT+1 Maurilio Longo * source/rtl/gtos2/gtos2.c ! fixed (sort of) changing used variables to statics so that I don't have to alloc them on every call to hb_gt_ReadKey(). Now as fast as it was. --- harbour/ChangeLog | 5 +++ harbour/source/rtl/gtos2/gtos2.c | 59 ++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f4bf5bb443..b1f36e8b4c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,8 @@ +2001-02-27 09:09 GMT+1 Maurilio Longo + * source/rtl/gtos2/gtos2.c + ! fixed (sort of) changing used variables to statics so that I don't have to alloc them + on every call to hb_gt_ReadKey(). Now as fast as it was. + 2001-02-26 22:59 GMT+1 Maurilio Longo * source/rtl/gtos2/gtos2.c ! hb_gt_ReadKey() uses KBD subsystem of OS/2 instead of any compiler runtime diff --git a/harbour/source/rtl/gtos2/gtos2.c b/harbour/source/rtl/gtos2/gtos2.c index 303ce14e97..095ec69848 100644 --- a/harbour/source/rtl/gtos2/gtos2.c +++ b/harbour/source/rtl/gtos2/gtos2.c @@ -109,9 +109,17 @@ static ULONG s_ulLVBptr; /* length of video buffer */ static USHORT s_usLVBlength; +/* keyboard event record */ +static PKBDKEYINFO s_key; + +/* keyboard handle, 0 == default */ +static PHKBD s_hk; + void hb_gt_Init( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr ) { + APIRET rc; /* return code from DosXXX api call */ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_Init()")); s_uiDispCount = 0; @@ -123,6 +131,19 @@ void hb_gt_Init( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr ) s_ulLVBptr = (ULONG) NULL; } + /* Alloc tileable memory for calling a 16 subsystem */ + rc = DosAllocMem((void *) &s_hk, sizeof(HKBD), PAG_COMMIT | OBJ_TILE | PAG_WRITE); + if (rc != NO_ERROR) { + hb_errInternal( HB_EI_XGRABALLOC, "hb_gt_ReadKey() memory allocation failure", NULL, NULL); + } + /* it is a long after all, so I set it to zero only one time since it never changes */ + memset(s_hk, 0, sizeof(HKBD)); + + rc = DosAllocMem((void *) &s_key, sizeof(KBDKEYINFO), PAG_COMMIT | OBJ_TILE | PAG_WRITE); + if (rc != NO_ERROR) { + hb_errInternal( HB_EI_XGRABALLOC, "hb_gt_ReadKey() memory allocation failure", NULL, NULL); + } + hb_mouse_Init(); /* TODO: Is anything else required to initialize the video subsystem? @@ -144,6 +165,9 @@ void hb_gt_Exit( void ) { HB_TRACE(HB_TR_DEBUG, ("hb_gt_Exit()")); + DosFreeMem(s_key); + DosFreeMem(s_hk); + hb_mouse_Exit(); /* TODO: */ } @@ -168,52 +192,35 @@ int hb_gt_ReadKey( HB_inkey_enum eventmask ) { int ch; /* next char if any */ - PKBDKEYINFO key; /* keyboard event record */ - PHKBD hk; /* keyboard handle, 0 == default */ - APIRET rc; /* return code from DosXXX api call */ - HB_TRACE(HB_TR_DEBUG, ("hb_gt_ReadKey(%d)", (int) eventmask)); - /* Alloc tileable memory for calling a 16 subsystem */ - rc = DosAllocMem((void *) &hk, sizeof(HKBD), PAG_COMMIT | OBJ_TILE | PAG_WRITE); - if (rc != NO_ERROR) { - hb_errInternal( HB_EI_XGRABALLOC, "hb_gt_ReadKey() memory allocation failure", NULL, NULL); - } - memset(hk, 0, sizeof(HKBD)); - - rc = DosAllocMem((void *) &key, sizeof(KBDKEYINFO), PAG_COMMIT | OBJ_TILE | PAG_WRITE); - if (rc != NO_ERROR) { - hb_errInternal( HB_EI_XGRABALLOC, "hb_gt_ReadKey() memory allocation failure", NULL, NULL); - } - memset(key, 0, sizeof(KBDKEYINFO)); + /* zero out keyboard event record */ + memset(s_key, 0, sizeof(KBDKEYINFO)); /* Get next character without wait */ - KbdCharIn(key, IO_NOWAIT, (HKBD) * hk); + KbdCharIn(s_key, IO_NOWAIT, (HKBD) * s_hk); /* extended key codes have 00h or E0h as chChar */ - if ((key->fbStatus & KBDTRF_EXTENDED_CODE) && (key->chChar == 0x00 || key->chChar == 0xE0)) { + if ((s_key->fbStatus & KBDTRF_EXTENDED_CODE) && (s_key->chChar == 0x00 || s_key->chChar == 0xE0)) { /* It was an extended function key lead-in code, so read the actual function key and then offset it by 256, unless extended keyboard events are allowed, in which case offset it by 512 */ - if ((key->chChar == 0xE0) && (eventmask & INKEY_RAW)) { - ch = (int) key->chScan + 512; + if ((s_key->chChar == 0xE0) && (eventmask & INKEY_RAW)) { + ch = (int) s_key->chScan + 512; } else { - ch = (int) key->chScan + 256; + ch = (int) s_key->chScan + 256; } - } else if (key->fbStatus & KBDTRF_FINAL_CHAR_IN) { - ch = (int) key->chChar; + } else if (s_key->fbStatus & KBDTRF_FINAL_CHAR_IN) { + ch = (int) s_key->chChar; } else { ch = 0; } - DosFreeMem(key); - DosFreeMem(hk); - /* Perform key translations */ switch( ch ) {