From b25d481e660d9c32b76d2a41cd12126742b20f81 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Thu, 24 Mar 2011 10:46:56 +0000 Subject: [PATCH] Fix startup detection of numlock and capslock. Improve behaviour with SDL 1.2.14 with respect to lock keys. What works: - dosbox compiled against SDL < 1.2.14 used with SDL < 1.2.14 - dosbox compiled against SDL < 1.2.14 used with SDL >= 1.2.14 - dosbox compiled against SDL >=1.2.14 used with SDL >= 1.2.14 What doesn't work: - dosbox compiled against SDL >=1.2.14 used with SDL < 1.2.14 - debian/ubuntu SDL < 1.2.14. (Check comment in src/gui/sdlmain.cpp on how to fix it.) Untested: - debian/ubuntu SDL >=1.2.14. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3689 --- src/gui/sdl_mapper.cpp | 8 ++++++-- src/gui/sdlmain.cpp | 4 ++++ src/ints/bios_keyboard.cpp | 13 ++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/gui/sdl_mapper.cpp b/src/gui/sdl_mapper.cpp index 54ab6da8..9d83a770 100644 --- a/src/gui/sdl_mapper.cpp +++ b/src/gui/sdl_mapper.cpp @@ -2362,17 +2362,21 @@ void MAPPER_Init(void) { if (!MAPPER_LoadBinds()) CreateDefaultBinds(); if (SDL_GetModState()&KMOD_CAPS) { for (CBindList_it bit=caps_lock_event->bindlist.begin();bit!=caps_lock_event->bindlist.end();bit++) { - (*bit)->ActivateBind(32767,true,true); #if SDL_VERSION_ATLEAST(1, 2, 14) + (*bit)->ActivateBind(32767,true,false); (*bit)->DeActivateBind(false); +#else + (*bit)->ActivateBind(32767,true,true); //Skip the action itself as bios_keyboard.cpp handles the startup state. #endif } } if (SDL_GetModState()&KMOD_NUM) { for (CBindList_it bit=num_lock_event->bindlist.begin();bit!=num_lock_event->bindlist.end();bit++) { - (*bit)->ActivateBind(32767,true,true); #if SDL_VERSION_ATLEAST(1, 2, 14) + (*bit)->ActivateBind(32767,true,false); (*bit)->DeActivateBind(false); +#else + (*bit)->ActivateBind(32767,true,true); #endif } } diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index b5cdd332..33cd4c21 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -1770,6 +1770,10 @@ int main(int argc, char* argv[]) { /* Init SDL */ #if SDL_VERSION_ATLEAST(1, 2, 14) + /* Or debian/ubuntu with older libsdl version as they have done this themselves, but then differently. + * with this variable they will work correctly. I've only tested the 1.2.14 behaviour against the windows version + * of libsdl + */ putenv(const_cast("SDL_DISABLE_LOCK_KEYS=1")); #endif if ( SDL_Init( SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_CDROM diff --git a/src/ints/bios_keyboard.cpp b/src/ints/bios_keyboard.cpp index 272e69cc..f4e8fc20 100644 --- a/src/ints/bios_keyboard.cpp +++ b/src/ints/bios_keyboard.cpp @@ -33,6 +33,8 @@ * Define the following if this is the case */ #if SDL_VERSION_ATLEAST(1, 2, 14) #define CAN_USE_LOCK 1 +/* For lower versions of SDL we also use a slight hack to get the startup states of numclock and capslock right. + * The proper way is in the mapper, but the repeating key is an unwanted side effect for lower versions of SDL */ #endif static Bitu call_int16,call_irq1,call_irq6; @@ -592,9 +594,14 @@ static void InitBiosSegment(void) { mem_writew(BIOS_KEYBOARD_BUFFER_TAIL,0x1e); Bit8u flag1 = 0; Bit8u leds = 16; /* Ack recieved */ -//MAPPER_Init takes care of this now ? -// if(startup_state_capslock) { flag1|=0x40; leds|=0x04;} -// if(startup_state_numlock){ flag1|=0x20; leds|=0x02;} + +#if SDL_VERSION_ATLEAST(1, 2, 14) +//Nothing, mapper handles all. +#else + if (startup_state_capslock) { flag1|=0x40; leds|=0x04;} + if (startup_state_numlock) { flag1|=0x20; leds|=0x02;} +#endif + mem_writeb(BIOS_KEYBOARD_FLAGS1,flag1); mem_writeb(BIOS_KEYBOARD_FLAGS2,0); mem_writeb(BIOS_KEYBOARD_FLAGS3,16); /* Enhanced keyboard installed */